From 5038042bf72a4812b8de7b0726acb2727e0ca809 Mon Sep 17 00:00:00 2001 From: LHagfoss Date: Sun, 22 Nov 2026 20:15:40 +0100 Subject: [PATCH] refactor(engine): name core types from rustcode-core outside the agent SmartUi moves to rustcode-core. Engine code outside the built-in agent names ChatMessage, TurnOutcome and SmartUi from the core crate rather than through crate::app. --- rustcode/core/rustcode-core/src/lib.rs | 12 +++ rustcode/engine/src/acp.rs | 10 +-- rustcode/engine/src/acp/clients.rs | 2 +- rustcode/engine/src/acp/harnesses.rs | 8 +- rustcode/engine/src/acp/project_relocate.rs | 2 +- rustcode/engine/src/acp/session_load.rs | 6 +- rustcode/engine/src/acp/session_move.rs | 12 +-- rustcode/engine/src/acp/session_repair.rs | 4 +- rustcode/engine/src/acp/session_transfer.rs | 2 +- rustcode/engine/src/acp_tests.rs | 86 ++++++++++--------- rustcode/engine/src/app/state.rs | 12 +-- rustcode/engine/src/checkpoints.rs | 2 +- rustcode/engine/src/evidence.rs | 2 +- .../engine/src/harness/acp_child_tests.rs | 4 +- rustcode/engine/src/harness/codex_tests.rs | 8 +- rustcode/engine/src/harness/handoff.rs | 2 +- rustcode/engine/src/harness/mod.rs | 2 +- rustcode/engine/src/harness/session.rs | 6 +- rustcode/engine/src/harness/transcript.rs | 2 +- rustcode/engine/src/message_origin.rs | 2 +- rustcode/engine/src/remote/contract.rs | 9 +- rustcode/engine/src/remote/harness.rs | 2 +- rustcode/engine/src/remote/ops.rs | 8 +- rustcode/engine/src/remote/projection.rs | 10 +-- rustcode/engine/src/remote/publisher.rs | 32 +++---- .../engine/src/remote_gateway/e2e_tests.rs | 4 +- .../engine/src/remote_gateway/workspace.rs | 4 +- rustcode/engine/src/sessions/store.rs | 2 +- rustcode/engine/src/thread_parent.rs | 2 +- rustcode/engine/src/thread_status.rs | 2 +- rustcode/engine/src/worktrees.rs | 4 +- 31 files changed, 135 insertions(+), 130 deletions(-) diff --git a/rustcode/core/rustcode-core/src/lib.rs b/rustcode/core/rustcode-core/src/lib.rs index 9d82b40b7..5ea0fed5d 100644 --- a/rustcode/core/rustcode-core/src/lib.rs +++ b/rustcode/core/rustcode-core/src/lib.rs @@ -971,3 +971,15 @@ mod tests { assert_eq!(ToolErrorKind::Deferred.as_str(), "Deferred"); } } + +/// What the frontend can do with `rustcode-ui v1` blocks (#2484). +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +pub enum SmartUi { + /// The client never advertised Smart UI: say nothing about it. + #[default] + Unsupported, + /// The client can run blocks, but the user has the setting off. + Off, + /// The client runs blocks. + On, +} diff --git a/rustcode/engine/src/acp.rs b/rustcode/engine/src/acp.rs index 76637e934..57d94f2bc 100644 --- a/rustcode/engine/src/acp.rs +++ b/rustcode/engine/src/acp.rs @@ -118,7 +118,7 @@ const SMART_UI_CAPABILITY_VERSION: u64 = 1; fn client_smart_ui( capabilities: &agent_client_protocol::schema::v1::ClientCapabilities, -) -> crate::app::SmartUi { +) -> rustcode_core::SmartUi { let version = capabilities .meta .as_ref() @@ -126,9 +126,9 @@ fn client_smart_ui( .and_then(|rustcode| rustcode.get("smartUi")) .and_then(serde_json::Value::as_u64); match version { - Some(version) if version >= SMART_UI_CAPABILITY_VERSION => crate::app::SmartUi::On, - Some(0) => crate::app::SmartUi::Off, - _ => crate::app::SmartUi::Unsupported, + Some(version) if version >= SMART_UI_CAPABILITY_VERSION => rustcode_core::SmartUi::On, + Some(0) => rustcode_core::SmartUi::Off, + _ => rustcode_core::SmartUi::Unsupported, } } @@ -3397,7 +3397,7 @@ async fn dispatch_request( if crate::sessions::load_session_title(&session_id).is_none() && crate::app::actions::wants_generated_title(&prompt_text) { - let history = [crate::app::ChatMessage::new("user", prompt_text.clone())]; + let history = [rustcode_core::ChatMessage::new("user", prompt_text.clone())]; crate::sessions::save_session_title_if_absent(&session_id, &history[..]); let fallback = crate::sessions::session_title(&history); let title_clients = server.clients.session(&session_id); diff --git a/rustcode/engine/src/acp/clients.rs b/rustcode/engine/src/acp/clients.rs index 1ff99bab1..82abb7245 100644 --- a/rustcode/engine/src/acp/clients.rs +++ b/rustcode/engine/src/acp/clients.rs @@ -49,7 +49,7 @@ pub(crate) struct ClientInfo { /// The `rustcode-viz` level it renders (`_meta.rustcode.visualizations`). pub(crate) visualization_level: u8, /// `_meta.rustcode.smartUi` (#2484). - pub(crate) smart_ui: crate::app::SmartUi, + pub(crate) smart_ui: rustcode_core::SmartUi, /// `_meta.rustcode.preview` (#2138): its sessions get `localhost_preview`. pub(crate) preview: bool, /// It answers desktop control. diff --git a/rustcode/engine/src/acp/harnesses.rs b/rustcode/engine/src/acp/harnesses.rs index d31d4fb7b..de97aa4ab 100644 --- a/rustcode/engine/src/acp/harnesses.rs +++ b/rustcode/engine/src/acp/harnesses.rs @@ -750,7 +750,7 @@ fn switch_origin( /// Refuse a damaged file before changing the harness record or closing a thread. fn handoff_history( session_id: &str, -) -> Result, agent_client_protocol::Error> { +) -> Result, agent_client_protocol::Error> { crate::sessions::flush_history(); let directory = crate::sessions::get_active_session_dir(session_id) .ok_or_else(|| failure("session storage is unavailable".into()))?; @@ -988,7 +988,7 @@ mod tests { #[test] fn handoff_preserves_an_interrupted_transcript_and_refuses_corruption() { let id = crate::sessions::create_detached_session(); - let history = vec![crate::app::ChatMessage::new("user", "Still working")]; + let history = vec![rustcode_core::ChatMessage::new("user", "Still working")]; crate::sessions::save_session_history(&id, &history); crate::sessions::flush_history(); let loaded = handoff_history(&id).unwrap(); @@ -1038,8 +1038,8 @@ mod tests { // The history the load replays, with no harness started. let history = vec![ - crate::app::ChatMessage::new("user", "hello"), - crate::app::ChatMessage::new("assistant", "hi"), + rustcode_core::ChatMessage::new("user", "hello"), + rustcode_core::ChatMessage::new("assistant", "hi"), ]; let updates = harness::transcript::replay(&history, None); assert!(updates.len() >= 2, "the recorded conversation replays"); diff --git a/rustcode/engine/src/acp/project_relocate.rs b/rustcode/engine/src/acp/project_relocate.rs index b22231cb0..bad9800d7 100644 --- a/rustcode/engine/src/acp/project_relocate.rs +++ b/rustcode/engine/src/acp/project_relocate.rs @@ -313,7 +313,7 @@ mod tests { let history_path = crate::sessions::get_active_session_dir(&id) .unwrap() .join("history.json"); - let history = serde_json::to_vec(&vec![crate::app::ChatMessage::new( + let history = serde_json::to_vec(&vec![rustcode_core::ChatMessage::new( "user", "Keep this history", )]) diff --git a/rustcode/engine/src/acp/session_load.rs b/rustcode/engine/src/acp/session_load.rs index 8a53f875b..c4df42ddb 100644 --- a/rustcode/engine/src/acp/session_load.rs +++ b/rustcode/engine/src/acp/session_load.rs @@ -213,7 +213,7 @@ pub(super) fn acp_list_sessions( } pub(crate) fn replay_history_updates( - history: &[crate::app::ChatMessage], + history: &[rustcode_core::ChatMessage], cwd: Option<&std::path::Path>, ) -> Vec { replay_history_updates_with_compaction(history, cwd, None) @@ -223,7 +223,7 @@ pub(crate) fn replay_history_updates( /// left its summary. `compaction` is the session's recorded last /// compaction; it describes the latest summary only. pub(super) fn replay_history_updates_with_compaction( - history: &[crate::app::ChatMessage], + history: &[rustcode_core::ChatMessage], cwd: Option<&std::path::Path>, compaction: Option<&crate::app::CompactionStats>, ) -> Vec { @@ -797,7 +797,7 @@ pub(crate) async fn attach_with_replay( session_id: &str, resume: Option, history: impl Fn() -> F, - replay: impl Fn(&[crate::app::ChatMessage]) -> Vec, + replay: impl Fn(&[rustcode_core::ChatMessage]) -> Vec, ) -> Result where F: std::future::Future, diff --git a/rustcode/engine/src/acp/session_move.rs b/rustcode/engine/src/acp/session_move.rs index c8122bf82..950a6f107 100644 --- a/rustcode/engine/src/acp/session_move.rs +++ b/rustcode/engine/src/acp/session_move.rs @@ -63,8 +63,8 @@ mod tests { let (_dir, repo) = crate::worktrees::tests::repo(); let id = "acp-move-repo"; let history = vec![ - crate::app::ChatMessage::new("user", "Move me"), - crate::app::ChatMessage::new("assistant", "Moved"), + rustcode_core::ChatMessage::new("user", "Move me"), + rustcode_core::ChatMessage::new("assistant", "Moved"), ]; store.ensure_session(id); store.save_session_history(id, &history); @@ -80,8 +80,8 @@ mod tests { let (old, new) = (tempfile::tempdir().unwrap(), tempfile::tempdir().unwrap()); let extra = std::path::PathBuf::from("/tmp/extra"); let history = vec![ - crate::app::ChatMessage::new("user", "Move me"), - crate::app::ChatMessage::new("assistant", "Moved"), + rustcode_core::ChatMessage::new("user", "Move me"), + rustcode_core::ChatMessage::new("assistant", "Moved"), ]; for id in ["acp-move-a", "acp-move-b"] { store.save_session_history(id, &history); @@ -120,8 +120,8 @@ mod tests { store.save_session_history( id, &vec![ - crate::app::ChatMessage::new("user", "Move me"), - crate::app::ChatMessage::new("assistant", "Moved"), + rustcode_core::ChatMessage::new("user", "Move me"), + rustcode_core::ChatMessage::new("assistant", "Moved"), ], ); rustcode_session::flush_history(); diff --git a/rustcode/engine/src/acp/session_repair.rs b/rustcode/engine/src/acp/session_repair.rs index 77e8a8abb..3b79d71d5 100644 --- a/rustcode/engine/src/acp/session_repair.rs +++ b/rustcode/engine/src/acp/session_repair.rs @@ -79,8 +79,8 @@ mod tests { store.save_session_history( id, &vec![ - crate::app::ChatMessage::new("user", "Fix me"), - crate::app::ChatMessage::new("assistant", "Fixed"), + rustcode_core::ChatMessage::new("user", "Fix me"), + rustcode_core::ChatMessage::new("assistant", "Fixed"), ], ); rustcode_session::flush_history(); diff --git a/rustcode/engine/src/acp/session_transfer.rs b/rustcode/engine/src/acp/session_transfer.rs index 3aed543da..f62835ac2 100644 --- a/rustcode/engine/src/acp/session_transfer.rs +++ b/rustcode/engine/src/acp/session_transfer.rs @@ -18,9 +18,9 @@ use std::path::{Path, PathBuf}; use std::sync::{Mutex, OnceLock}; use std::time::{Duration, Instant}; -use crate::app::ChatMessage; use crate::harness::{self, store as harness_store}; use crate::sessions::MachineOrigin; +use rustcode_core::ChatMessage; /// Raw bytes per export/import chunk (384 KiB raw -> 512 KiB base64, well below /// `remote_gateway::gateway::MAX_FRAME_BYTES` = 1 MiB). diff --git a/rustcode/engine/src/acp_tests.rs b/rustcode/engine/src/acp_tests.rs index 061b0009b..0cea2997d 100644 --- a/rustcode/engine/src/acp_tests.rs +++ b/rustcode/engine/src/acp_tests.rs @@ -149,7 +149,7 @@ fn visualization_support_comes_only_from_the_client_capability() { #[test] fn smart_ui_comes_only_from_the_client_capability() { - use crate::app::SmartUi; + use rustcode_core::SmartUi; let parse = |value: serde_json::Value| { client_smart_ui( &serde_json::from_value::(value) @@ -278,8 +278,8 @@ fn session_list_filters_and_paginates_with_standard_titles() { let store = rustcode_session::SessionStore::new(config_dir); let cwd = tempfile::tempdir().unwrap(); let history = vec![ - crate::app::ChatMessage::new("user", "Listable session title"), - crate::app::ChatMessage::new("assistant", "answer"), + rustcode_core::ChatMessage::new("user", "Listable session title"), + rustcode_core::ChatMessage::new("assistant", "answer"), ]; for index in 0..51 { let id = format!("acp-list-{index:03}"); @@ -332,8 +332,8 @@ fn session_list_skips_legacy_ids_that_cannot_be_loaded_or_used_as_cursors() { let config_dir = crate::config::get_config_dir().unwrap(); let store = rustcode_session::SessionStore::new(config_dir); let history = vec![ - crate::app::ChatMessage::new("user", "legacy pagination prompt"), - crate::app::ChatMessage::new("assistant", "answer"), + rustcode_core::ChatMessage::new("user", "legacy pagination prompt"), + rustcode_core::ChatMessage::new("assistant", "answer"), ]; let mut ids = Vec::new(); for index in 0..49 { @@ -393,13 +393,13 @@ fn session_workspace_preserves_client_additional_directories() { #[test] fn loaded_session_history_replays_user_assistant_and_tool_events_in_order() { - let mut assistant = crate::app::ChatMessage::new("assistant", "Checking the file."); + let mut assistant = rustcode_core::ChatMessage::new("assistant", "Checking the file."); assistant.tool_calls.push(crate::app::ToolCallRef { id: "call-1".into(), name: "read_file".into(), arguments: r#"{"path":"src/main.rs"}"#.into(), }); - let mut result = crate::app::ChatMessage::new("tool", "file contents"); + let mut result = rustcode_core::ChatMessage::new("tool", "file contents"); result.tool_call_id = Some("call-1".into()); result.tool_result = Some(crate::app::ToolResultRecord { workspace_generation: None, @@ -411,10 +411,10 @@ fn loaded_session_history_replays_user_assistant_and_tool_events_in_order() { }); let updates = replay_history_updates( &[ - crate::app::ChatMessage::new("user", "inspect the file"), + rustcode_core::ChatMessage::new("user", "inspect the file"), assistant, result, - crate::app::ChatMessage::new("assistant", "It defines main."), + rustcode_core::ChatMessage::new("assistant", "It defines main."), ], None, ); @@ -467,7 +467,7 @@ fn edit_tool_updates_carry_diff_content_live_and_on_replay() { assert_eq!(content[0]["newText"], "new\n"); let mut result = - crate::app::ChatMessage::new("tool", format!("replace_file_content: {receipt}")); + rustcode_core::ChatMessage::new("tool", format!("replace_file_content: {receipt}")); result.tool_call_id = Some("call-edit".into()); result.tool_result = Some(crate::app::ToolResultRecord { tool_name: "replace_file_content".into(), @@ -522,8 +522,8 @@ fn replayed_background_completion_updates_its_card_without_prose() { fn loaded_session_state_keeps_transcript_and_uses_its_own_identity() { let cwd = tempfile::tempdir().unwrap(); let history = vec![ - crate::app::ChatMessage::new("user", "earlier task"), - crate::app::ChatMessage::new("assistant", "earlier answer"), + rustcode_core::ChatMessage::new("user", "earlier task"), + rustcode_core::ChatMessage::new("assistant", "earlier answer"), ]; let state = build_loaded_app_state("session-loaded", cwd.path(), history.clone()); assert_eq!(state.active_session_id, "session-loaded"); @@ -569,14 +569,14 @@ async fn a_loaded_session_persists_only_to_its_own_history() { crate::sessions::set_active_session_id(&created); let loaded = rustcode_session::next_session_id(); let earlier = vec![ - crate::app::ChatMessage::new("user", "check my daily dev feed"), - crate::app::ChatMessage::new("assistant", "Here is your feed."), + rustcode_core::ChatMessage::new("user", "check my daily dev feed"), + rustcode_core::ChatMessage::new("assistant", "Here is your feed."), ]; store.save_session_history(&loaded, &earlier); crate::sessions::flush_history(); let mut state = build_loaded_app_state(&loaded, cwd.path(), earlier); - state.history.push(crate::app::ChatMessage::new( + state.history.push(rustcode_core::ChatMessage::new( "user", "follow-up in the loaded session", )); @@ -1468,11 +1468,12 @@ fn replayed_system_cancel_marker_is_a_timed_empty_reply() { started_at: Some("2026-10-30T12:42:27Z".into()), ended_at: Some("2026-10-30T12:42:37Z".into()), elapsed_work_ms: Some(9_770), - outcome: Some(crate::app::TurnOutcome::Cancelled), + outcome: Some(rustcode_core::TurnOutcome::Cancelled), }; - let mut note = crate::app::ChatMessage::new("system", "Request cancelled by user"); + let mut note = rustcode_core::ChatMessage::new("system", "Request cancelled by user"); note.turn = Some(turn.clone()); - let mut marker = crate::app::ChatMessage::new("system", "[harness: turn stopped — cancelled]"); + let mut marker = + rustcode_core::ChatMessage::new("system", "[harness: turn stopped — cancelled]"); marker.turn = Some(turn); let updates = replay_history_updates(&[note, marker], None); let [SessionUpdate::AgentMessageChunk(chunk)] = updates.as_slice() else { @@ -1488,16 +1489,16 @@ fn replayed_system_cancel_marker_is_a_timed_empty_reply() { #[test] fn replayed_stop_marker_is_a_timed_empty_reply_or_its_notice() { let mut cancelled = - crate::app::ChatMessage::new("assistant", "[harness: turn stopped — cancelled]"); + rustcode_core::ChatMessage::new("assistant", "[harness: turn stopped — cancelled]"); cancelled.turn = Some(crate::app::TurnTiming { turn_id: "t1".into(), started_at: Some("2026-10-30T13:42:27Z".into()), ended_at: Some("2026-10-30T13:42:37Z".into()), elapsed_work_ms: Some(9_700), - outcome: Some(crate::app::TurnOutcome::Cancelled), + outcome: Some(rustcode_core::TurnOutcome::Cancelled), }); let stopped = - crate::app::ChatMessage::new("assistant", "[harness: turn stopped — loop_escalation]"); + rustcode_core::ChatMessage::new("assistant", "[harness: turn stopped — loop_escalation]"); let updates = replay_history_updates(&[cancelled, stopped], None); let texts: Vec<(String, Option)> = updates .iter() @@ -1532,11 +1533,11 @@ fn replayed_reply_carries_its_finished_turn_timing() { started_at: Some("2026-10-22T20:58:02+00:00".into()), ended_at: Some("2026-10-22T20:59:52+00:00".into()), elapsed_work_ms: Some(109_582), - outcome: Some(crate::app::TurnOutcome::Completed), + outcome: Some(rustcode_core::TurnOutcome::Completed), }; - let mut reply = crate::app::ChatMessage::new("assistant", "Hm.Done."); + let mut reply = rustcode_core::ChatMessage::new("assistant", "Hm.Done."); reply.turn = Some(turn.clone()); - let mut open = crate::app::ChatMessage::new("assistant", "Still going."); + let mut open = rustcode_core::ChatMessage::new("assistant", "Still going."); open.timestamp = String::new(); open.turn = Some(crate::app::TurnTiming { ended_at: None, @@ -1570,9 +1571,9 @@ fn replayed_reply_carries_its_finished_turn_timing() { // #2461, #2463: replayed messages say when they were sent and written. #[test] fn replayed_messages_carry_their_time() { - let mut question = crate::app::ChatMessage::new("user", "Why?"); + let mut question = rustcode_core::ChatMessage::new("user", "Why?"); question.timestamp = "2026-10-27T09:16:01.473007+01:00".into(); - let mut answer = crate::app::ChatMessage::new("assistant", "Hm.Because."); + let mut answer = rustcode_core::ChatMessage::new("assistant", "Hm.Because."); answer.timestamp = "2026-10-27T09:16:16.043688+01:00".into(); let updates = replay_history_updates(&[question, answer], None); @@ -1602,17 +1603,17 @@ fn replayed_messages_carry_their_time() { // a tool's result in the user role says nothing. #[test] fn replayed_user_messages_carry_their_origin() { - let mut task = crate::app::ChatMessage::new( + let mut task = rustcode_core::ChatMessage::new( "user", "From thread “Ship the tree” (agent):\n\nReview the rules.", ); task.timestamp = "2026-11-11T09:16:01+01:00".into(); - let wake = crate::app::ChatMessage::new( + let wake = rustcode_core::ChatMessage::new( "user", "Delegate finished: Review the rows\n\nFinished:\n\n- link_id parent-1/2 · done · “Review the rows” · session child-7\n answer: Done.\n\n", ); - let typed = crate::app::ChatMessage::new("user", "thanks"); - let result = crate::app::ChatMessage::new("user", "ok"); + let typed = rustcode_core::ChatMessage::new("user", "thanks"); + let result = rustcode_core::ChatMessage::new("user", "ok"); let updates = replay_history_updates(&[task, wake, typed, result], None); @@ -1657,14 +1658,14 @@ fn replayed_user_messages_carry_their_origin() { // label and duration it had live, not as `` inside message text. #[test] fn replayed_reasoning_is_sent_as_labelled_thoughts() { - let mut summarized = crate::app::ChatMessage::new( + let mut summarized = rustcode_core::ChatMessage::new( "assistant", "\n**Inspecting site**\n\n\nDone.", ); summarized.reasoning_summary = true; summarized.thought_time_ms = Some(4000); let mut reasoned = - crate::app::ChatMessage::new("assistant", "Let me check.Fine."); + rustcode_core::ChatMessage::new("assistant", "Let me check.Fine."); reasoned.thought_time_ms = Some(0); let updates = replay_history_updates(&[summarized, reasoned], None); @@ -1703,7 +1704,7 @@ fn replay_shows_the_compaction_card_where_the_summary_is() { &[], "/tmp/archive.jsonl", ); - let notice = crate::app::ChatMessage::new( + let notice = rustcode_core::ChatMessage::new( "system", "🧹 History compacted: reduced context from 161495 to 4200 tokens.", ); @@ -1717,7 +1718,7 @@ fn replay_shows_the_compaction_card_where_the_summary_is() { ); let history = [ summary, - crate::app::ChatMessage::new("user", "next"), + rustcode_core::ChatMessage::new("user", "next"), notice, ]; @@ -2331,7 +2332,7 @@ async fn two_connections() { let state = a_state.lock().await; assert_eq!(state.orchestration_version, 3); assert_eq!(state.visualization_level, 2); - assert_eq!(state.smart_ui, crate::app::SmartUi::On); + assert_eq!(state.smart_ui, rustcode_core::SmartUi::On); assert!(state.orchestration_client.is_some()); assert!(!state.local_orchestration); state @@ -2343,7 +2344,7 @@ async fn two_connections() { let state = b_state.lock().await; assert_eq!(state.orchestration_version, 0); assert_eq!(state.visualization_level, 0); - assert_eq!(state.smart_ui, crate::app::SmartUi::Unsupported); + assert_eq!(state.smart_ui, rustcode_core::SmartUi::Unsupported); assert!(state.orchestration_client.is_none()); // No app has this session, so the engine serves its reads // itself (#3422), even though the other client is an app. @@ -2543,10 +2544,11 @@ async fn use_provider(server: &AcpServer, session_id: &str, endpoint: &str) { ..ModelProfile::default() }]; state.record_function_calling_support(endpoint, false); - state - .history - .push(crate::app::ChatMessage::new("user", "an earlier question")); - state.history.push(crate::app::ChatMessage::new( + state.history.push(rustcode_core::ChatMessage::new( + "user", + "an earlier question", + )); + state.history.push(rustcode_core::ChatMessage::new( "assistant", "an earlier answer", )); @@ -3635,8 +3637,8 @@ async fn closed_load_with_a_second_client() { crate::sessions::save_session_history( &session_id, &[ - crate::app::ChatMessage::new("user", "an earlier question"), - crate::app::ChatMessage::new("assistant", "an earlier answer"), + rustcode_core::ChatMessage::new("user", "an earlier question"), + rustcode_core::ChatMessage::new("assistant", "an earlier answer"), ][..], ); // The history is written in the background. diff --git a/rustcode/engine/src/app/state.rs b/rustcode/engine/src/app/state.rs index 870294e0c..6d97104a6 100644 --- a/rustcode/engine/src/app/state.rs +++ b/rustcode/engine/src/app/state.rs @@ -3135,14 +3135,4 @@ fn live_call_summary(arguments: &serde_json::Value) -> Option { .map(|summary| rustcode_core::activity::sanitize_tool_parameter(summary, 120)) } -/// What the frontend can do with `rustcode-ui v1` blocks (#2484). -#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] -pub enum SmartUi { - /// The client never advertised Smart UI: say nothing about it. - #[default] - Unsupported, - /// The client can run blocks, but the user has the setting off. - Off, - /// The client runs blocks. - On, -} +pub use rustcode_core::SmartUi; diff --git a/rustcode/engine/src/checkpoints.rs b/rustcode/engine/src/checkpoints.rs index cb942f363..0ebe71ba5 100644 --- a/rustcode/engine/src/checkpoints.rs +++ b/rustcode/engine/src/checkpoints.rs @@ -313,7 +313,7 @@ pub(crate) async fn before_turn( /// How many user messages of `history` a replay shows: the index the next /// prompt's message gets, which `_rustcode/rewind` takes. -pub(crate) fn next_user_index(history: &[crate::app::ChatMessage]) -> usize { +pub(crate) fn next_user_index(history: &[rustcode_core::ChatMessage]) -> usize { history .iter() .filter(|message| message.role == "user" && !message.content.is_empty()) diff --git a/rustcode/engine/src/evidence.rs b/rustcode/engine/src/evidence.rs index f02245b0e..c6ebda9c0 100644 --- a/rustcode/engine/src/evidence.rs +++ b/rustcode/engine/src/evidence.rs @@ -1,5 +1,5 @@ //! Request-only evidence lifecycle. Stored transcripts remain immutable. -use crate::app::ChatMessage; +use rustcode_core::ChatMessage; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum EvidenceClass { diff --git a/rustcode/engine/src/harness/acp_child_tests.rs b/rustcode/engine/src/harness/acp_child_tests.rs index 504585dd6..8bc67eb19 100644 --- a/rustcode/engine/src/harness/acp_child_tests.rs +++ b/rustcode/engine/src/harness/acp_child_tests.rs @@ -1321,7 +1321,7 @@ async fn the_threads_skills_note_rides_in_the_client_system_prompt() { skills_note: Some(note.to_owned()), client_display: crate::harness::ClientDisplay { visualization_level: 2, - smart_ui: crate::app::SmartUi::On, + smart_ui: rustcode_core::SmartUi::On, }, ..StartOptions::default() }, @@ -1338,7 +1338,7 @@ async fn the_threads_skills_note_rides_in_the_client_system_prompt() { assert!(prompt.contains(note), "{prompt}"); assert!( prompt.ends_with(&crate::tools::schema::harness_output_style( - crate::app::SmartUi::On + rustcode_core::SmartUi::On )), "the note comes before the reply style" ); diff --git a/rustcode/engine/src/harness/codex_tests.rs b/rustcode/engine/src/harness/codex_tests.rs index 019be387a..aaede20c8 100644 --- a/rustcode/engine/src/harness/codex_tests.rs +++ b/rustcode/engine/src/harness/codex_tests.rs @@ -671,7 +671,7 @@ async fn the_workspaces_mcp_servers_are_thread_config() { StartOptions { client_display: crate::harness::ClientDisplay { visualization_level: 2, - smart_ui: crate::app::SmartUi::On, + smart_ui: rustcode_core::SmartUi::On, }, mcp: vec![ crate::config::McpServerConfig { @@ -734,7 +734,7 @@ async fn the_workspaces_mcp_servers_are_thread_config() { ); assert!( instructions.ends_with(&crate::tools::schema::harness_output_style( - crate::app::SmartUi::On + rustcode_core::SmartUi::On )) ); } @@ -752,7 +752,7 @@ async fn the_threads_skills_note_rides_in_the_developer_instructions() { skills_note: Some(note.to_owned()), client_display: crate::harness::ClientDisplay { visualization_level: 1, - smart_ui: crate::app::SmartUi::Off, + smart_ui: rustcode_core::SmartUi::Off, }, ..StartOptions::default() }, @@ -767,7 +767,7 @@ async fn the_threads_skills_note_rides_in_the_developer_instructions() { assert!(instructions.contains(note), "{instructions}"); assert!( instructions.ends_with(&crate::tools::schema::harness_output_style( - crate::app::SmartUi::Off + rustcode_core::SmartUi::Off )), "the note comes before the reply style" ); diff --git a/rustcode/engine/src/harness/handoff.rs b/rustcode/engine/src/harness/handoff.rs index de870381b..1d7a6fe22 100644 --- a/rustcode/engine/src/harness/handoff.rs +++ b/rustcode/engine/src/harness/handoff.rs @@ -5,8 +5,8 @@ //! is a `handoff` message in the thread's history, so a reload shows it too, //! and nothing replays it to a model. -use crate::app::ChatMessage; use agent_client_protocol::schema::v1::{ContentBlock, ContentChunk, SessionUpdate, TextContent}; +use rustcode_core::ChatMessage; use serde_json::{Value, json}; /// The history role of a switch. diff --git a/rustcode/engine/src/harness/mod.rs b/rustcode/engine/src/harness/mod.rs index e1efc8e10..1395a1edc 100644 --- a/rustcode/engine/src/harness/mod.rs +++ b/rustcode/engine/src/harness/mod.rs @@ -42,7 +42,7 @@ pub(crate) const BUILTIN_ID: &str = "rustcode"; #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] pub(crate) struct ClientDisplay { pub(crate) visualization_level: u8, - pub(crate) smart_ui: crate::app::SmartUi, + pub(crate) smart_ui: rustcode_core::SmartUi, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/rustcode/engine/src/harness/session.rs b/rustcode/engine/src/harness/session.rs index 23a6ed1f3..e50c6ffb0 100644 --- a/rustcode/engine/src/harness/session.rs +++ b/rustcode/engine/src/harness/session.rs @@ -1054,7 +1054,7 @@ impl ExternalSession { id: String, harness: ResolvedHarness, record: HarnessRecord, - history: Vec, + history: Vec, sink: Arc, persist: bool, ) -> Arc { @@ -1356,7 +1356,7 @@ impl ExternalSession { /// The transcript recorded so far. A share of this thread starts its /// mirror from it, so nothing recorded before the share is missing. - pub(crate) fn recorded_history(&self) -> Vec { + pub(crate) fn recorded_history(&self) -> Vec { self.transcript .lock() .unwrap_or_else(|error| error.into_inner()) @@ -1366,7 +1366,7 @@ impl ExternalSession { /// The transcript recorded so far (tests). #[cfg(test)] - pub(crate) fn history(&self) -> Vec { + pub(crate) fn history(&self) -> Vec { self.transcript .lock() .unwrap_or_else(|error| error.into_inner()) diff --git a/rustcode/engine/src/harness/transcript.rs b/rustcode/engine/src/harness/transcript.rs index 8c5a374dd..4d3535ad7 100644 --- a/rustcode/engine/src/harness/transcript.rs +++ b/rustcode/engine/src/harness/transcript.rs @@ -19,12 +19,12 @@ //! `tool_output/` when it does not fit — so a replay or a post-mortem has the //! same evidence as a native turn. Images and other binary payloads stay out. -use crate::app::ChatMessage; use agent_client_protocol::schema::v1::{ ContentBlock, Meta, Plan, PlanEntry, PlanEntryPriority, PlanEntryStatus, SessionUpdate, TextContent, ToolCall, ToolCallContent, ToolCallLocation, ToolCallStatus, ToolCallUpdate, ToolCallUpdateFields, ToolKind, }; +use rustcode_core::ChatMessage; use rustcode_core::{ToolCallRef, ToolResultRecord}; use serde_json::Value; use std::collections::HashMap; diff --git a/rustcode/engine/src/message_origin.rs b/rustcode/engine/src/message_origin.rs index 9b03333cd..a0dce59d3 100644 --- a/rustcode/engine/src/message_origin.rs +++ b/rustcode/engine/src/message_origin.rs @@ -18,7 +18,7 @@ use serde_json::{Value, json}; -use crate::app::ChatMessage; +use rustcode_core::ChatMessage; /// The heading every agent-delivered message starts with (`delivered` in the app). pub(crate) const AGENT_HEADING: &str = "From thread “"; diff --git a/rustcode/engine/src/remote/contract.rs b/rustcode/engine/src/remote/contract.rs index 25ce91027..44a52a773 100644 --- a/rustcode/engine/src/remote/contract.rs +++ b/rustcode/engine/src/remote/contract.rs @@ -1928,10 +1928,11 @@ mod tests { fn the_golden_origins_are_what_the_host_derives_from_the_text() { let messages = golden_messages(); for message in &messages { - let derived = super::super::projection::project_origin(&crate::app::ChatMessage::new( - message.role.clone(), - message.content.text.clone(), - )); + let derived = + super::super::projection::project_origin(&rustcode_core::ChatMessage::new( + message.role.clone(), + message.content.text.clone(), + )); assert_eq!(message.origin, derived, "{}", message.message_id); } let kinds = messages diff --git a/rustcode/engine/src/remote/harness.rs b/rustcode/engine/src/remote/harness.rs index 729dc1231..2b67dd695 100644 --- a/rustcode/engine/src/remote/harness.rs +++ b/rustcode/engine/src/remote/harness.rs @@ -28,8 +28,8 @@ use agent_client_protocol::schema::v1::{ use serde_json::Value; use tokio::sync::oneshot; -use crate::app::ChatMessage; use crate::controller::QuestionPrompt; +use rustcode_core::ChatMessage; use rustcode_core::{ToolCallRef, ToolResultRecord}; use super::ops::SessionRegistration; diff --git a/rustcode/engine/src/remote/ops.rs b/rustcode/engine/src/remote/ops.rs index 98a4087db..0b72c0361 100644 --- a/rustcode/engine/src/remote/ops.rs +++ b/rustcode/engine/src/remote/ops.rs @@ -1253,7 +1253,7 @@ mod tests { let mut state = shared_state(); state .history - .push(crate::app::ChatMessage::new("user", "x".repeat(800))); + .push(rustcode_core::ChatMessage::new("user", "x".repeat(800))); let report = output(execute_command(&mut state, "/context")); assert!( report.contains("| Category | Tokens | % of window |"), @@ -1285,10 +1285,10 @@ mod tests { let mut state = shared_state(); state .history - .push(crate::app::ChatMessage::new("user", "hi")); + .push(rustcode_core::ChatMessage::new("user", "hi")); state .history - .push(crate::app::ChatMessage::new("assistant", "hello")); + .push(rustcode_core::ChatMessage::new("assistant", "hello")); state.current_token_usage = Some(crate::app::TokenUsage { prompt_tokens: 12, completion_tokens: 3, @@ -2170,7 +2170,7 @@ mod tests { let mut state = shared_state(); state .history - .push(crate::app::ChatMessage::new("user", "hello")); + .push(rustcode_core::ChatMessage::new("user", "hello")); let limits = crate::remote::ProjectionLimits::default(); let history = request(RemoteOperation::GetHistory { cursor: None, diff --git a/rustcode/engine/src/remote/projection.rs b/rustcode/engine/src/remote/projection.rs index adfa6ce54..9e2fa109d 100644 --- a/rustcode/engine/src/remote/projection.rs +++ b/rustcode/engine/src/remote/projection.rs @@ -518,7 +518,7 @@ fn project_messages( } /// Who sent `message`, for a user request; see [`crate::message_origin`]. -pub(super) fn project_origin(message: &crate::app::ChatMessage) -> Option { +pub(super) fn project_origin(message: &rustcode_core::ChatMessage) -> Option { crate::message_origin::of_message(message).map(wire_origin) } @@ -550,9 +550,9 @@ pub(super) fn project_turn_timing(turn: &crate::app::TurnTiming) -> RemoteTurnTi ended_at: turn.ended_at.clone(), elapsed_work_ms: turn.elapsed_work_ms, outcome: turn.outcome.map(|outcome| match outcome { - crate::app::TurnOutcome::Completed => RemoteTurnOutcome::Completed, - crate::app::TurnOutcome::Cancelled => RemoteTurnOutcome::Cancelled, - crate::app::TurnOutcome::Failed => RemoteTurnOutcome::Failed, + rustcode_core::TurnOutcome::Completed => RemoteTurnOutcome::Completed, + rustcode_core::TurnOutcome::Cancelled => RemoteTurnOutcome::Cancelled, + rustcode_core::TurnOutcome::Failed => RemoteTurnOutcome::Failed, }), } } @@ -1069,7 +1069,7 @@ mod tests { assert!(project_session_info(&state, &context).title.is_empty()); state .history - .push(crate::app::ChatMessage::new("user", "fresh prompt")); + .push(rustcode_core::ChatMessage::new("user", "fresh prompt")); let page = project_history_page(&state, &ProjectionLimits::default(), None, 10).unwrap(); assert!( chrono::DateTime::parse_from_rfc3339(page.messages[0].timestamp.as_deref().unwrap()) diff --git a/rustcode/engine/src/remote/publisher.rs b/rustcode/engine/src/remote/publisher.rs index 01dcfca52..c1425c18c 100644 --- a/rustcode/engine/src/remote/publisher.rs +++ b/rustcode/engine/src/remote/publisher.rs @@ -709,9 +709,9 @@ mod tests { #[test] fn terminal_timing_is_retained_for_live_events_late_attach_and_history() { for outcome in [ - crate::app::TurnOutcome::Completed, - crate::app::TurnOutcome::Cancelled, - crate::app::TurnOutcome::Failed, + rustcode_core::TurnOutcome::Completed, + rustcode_core::TurnOutcome::Cancelled, + rustcode_core::TurnOutcome::Failed, ] { let mut state = shared_state(); let (mut publisher, _) = register(&state); @@ -727,7 +727,7 @@ mod tests { let timing = state.freeze_turn_timing(Some(outcome)).unwrap(); state.enter_idle(); state.end_turn_identity(&id); - let event = if outcome == crate::app::TurnOutcome::Cancelled { + let event = if outcome == rustcode_core::TurnOutcome::Cancelled { AgentUiEvent::Cancelled { completed_tool_ids: Vec::new(), timing: Some(timing.clone()), @@ -735,7 +735,7 @@ mod tests { } else { AgentUiEvent::TurnFinished { content: String::new(), - completed: outcome == crate::app::TurnOutcome::Completed, + completed: outcome == rustcode_core::TurnOutcome::Completed, timing: Some(timing.clone()), } }; @@ -803,7 +803,7 @@ mod tests { }; assert!(texts(&publisher.publish(&state, true)).is_empty()); let timing = state - .freeze_turn_timing(Some(crate::app::TurnOutcome::Completed)) + .freeze_turn_timing(Some(rustcode_core::TurnOutcome::Completed)) .unwrap(); state.enter_idle(); state.end_turn_identity(&id); @@ -1096,7 +1096,7 @@ mod tests { let mut state = shared_state(); state .history - .push(crate::app::ChatMessage::new("user", "do it")); + .push(rustcode_core::ChatMessage::new("user", "do it")); let (mut publisher, _) = register(&state); let turn_id = start_turn(&mut state, &mut publisher); state.append_current_response("hello from provider"); @@ -1105,12 +1105,12 @@ mod tests { // The turn ends while a device is attached: the engine writes the // answer to history, which changes the transcript, and empties the // live buffer, all before the turn's end event is observed. - state.history.push(crate::app::ChatMessage::new( + state.history.push(rustcode_core::ChatMessage::new( "assistant", "hello from provider", )); let timing = state - .freeze_turn_timing(Some(crate::app::TurnOutcome::Completed)) + .freeze_turn_timing(Some(rustcode_core::TurnOutcome::Completed)) .expect("the turn's timing"); state.clear_current_response(); state.enter_idle(); @@ -1168,7 +1168,7 @@ mod tests { let mut state = shared_state(); state .history - .push(crate::app::ChatMessage::new("user", "do it")); + .push(rustcode_core::ChatMessage::new("user", "do it")); state.current_turn_started_at = Some(std::time::Instant::now()); let (mut publisher, _) = register(&state); let turn_id = start_turn(&mut state, &mut publisher); @@ -1177,7 +1177,7 @@ mod tests { // Between tool rounds the engine writes the tool-call segment to // history and empties the live buffer, so a snapshot here carries // that segment only in its transcript. - state.history.push(crate::app::ChatMessage::new( + state.history.push(rustcode_core::ChatMessage::new( "assistant", "checking the logs", )); @@ -1203,9 +1203,9 @@ mod tests { // first place it is published, and it arrives in full. state .history - .push(crate::app::ChatMessage::new("assistant", "the answer")); + .push(rustcode_core::ChatMessage::new("assistant", "the answer")); let timing = state - .freeze_turn_timing(Some(crate::app::TurnOutcome::Completed)) + .freeze_turn_timing(Some(rustcode_core::TurnOutcome::Completed)) .expect("the turn's timing"); state.enter_idle(); state.end_turn_identity(&turn_id); @@ -1231,7 +1231,7 @@ mod tests { let mut state = shared_state(); state .history - .push(crate::app::ChatMessage::new("user", "do it")); + .push(rustcode_core::ChatMessage::new("user", "do it")); state.current_turn_started_at = Some(std::time::Instant::now()); let (mut publisher, _) = register(&state); let turn_id = start_turn(&mut state, &mut publisher); @@ -1242,9 +1242,9 @@ mod tests { let answer = format!("{}{}", "cut ".repeat(1200), "the end"); state .history - .push(crate::app::ChatMessage::new("assistant", answer.clone())); + .push(rustcode_core::ChatMessage::new("assistant", answer.clone())); let timing = state - .freeze_turn_timing(Some(crate::app::TurnOutcome::Completed)) + .freeze_turn_timing(Some(rustcode_core::TurnOutcome::Completed)) .expect("the turn's timing"); state.enter_idle(); let sent = publisher.publish(&state, true); diff --git a/rustcode/engine/src/remote_gateway/e2e_tests.rs b/rustcode/engine/src/remote_gateway/e2e_tests.rs index 6ff369700..cc0e9bd04 100644 --- a/rustcode/engine/src/remote_gateway/e2e_tests.rs +++ b/rustcode/engine/src/remote_gateway/e2e_tests.rs @@ -559,7 +559,7 @@ async fn gateway_resumes_the_current_snapshot_and_exposes_machine_readable_histo .lock() .await .history - .push(crate::app::ChatMessage::new("user", "Fresh timestamp")); + .push(rustcode_core::ChatMessage::new("user", "Fresh timestamp")); let history = phone .request( Some(&terminal.registration), @@ -1140,7 +1140,7 @@ async fn large_output_stays_within_frame_limits_and_rebuilds_completely() { { let mut state = terminal.state.lock().await; for index in 0..400 { - state.history.push(crate::app::ChatMessage::new( + state.history.push(rustcode_core::ChatMessage::new( if index % 2 == 0 { "user" } else { "assistant" }, format!("message {index}: {}", "lorem ipsum ".repeat(500)), )); diff --git a/rustcode/engine/src/remote_gateway/workspace.rs b/rustcode/engine/src/remote_gateway/workspace.rs index c892f8633..9d5528507 100644 --- a/rustcode/engine/src/remote_gateway/workspace.rs +++ b/rustcode/engine/src/remote_gateway/workspace.rs @@ -2348,8 +2348,8 @@ mod tests { .map(|(title, workspace)| { let id = rustcode_session::next_session_id(); let history = vec![ - crate::app::ChatMessage::new("user", *title), - crate::app::ChatMessage::new("assistant", "answer"), + rustcode_core::ChatMessage::new("user", *title), + rustcode_core::ChatMessage::new("assistant", "answer"), ]; store.save_session_history(&id, &history); store.save_session_title(&id, title); diff --git a/rustcode/engine/src/sessions/store.rs b/rustcode/engine/src/sessions/store.rs index f0ab7d024..47674e3ac 100644 --- a/rustcode/engine/src/sessions/store.rs +++ b/rustcode/engine/src/sessions/store.rs @@ -1,6 +1,6 @@ use super::{SessionHolder, hold_primary_session, hold_session_open}; -use crate::app::ChatMessage; use crate::config::*; +use rustcode_core::ChatMessage; use rustcode_session::SessionStore; pub use rustcode_session::{ HistorySnapshot, MachineOrigin, SessionMeta, SessionMigrationReport, SessionScope, diff --git a/rustcode/engine/src/thread_parent.rs b/rustcode/engine/src/thread_parent.rs index 7313261f6..1599d38c7 100644 --- a/rustcode/engine/src/thread_parent.rs +++ b/rustcode/engine/src/thread_parent.rs @@ -17,7 +17,7 @@ use rustcode_session::SessionRelationship; use serde_json::Value; -use crate::app::ChatMessage; +use rustcode_core::ChatMessage; // The heading every agent-delivered task starts with, and the title in it. use crate::message_origin::{AGENT_HEADING as HEADING, delivered_title}; diff --git a/rustcode/engine/src/thread_status.rs b/rustcode/engine/src/thread_status.rs index a7f284c4b..37d05bbe3 100644 --- a/rustcode/engine/src/thread_status.rs +++ b/rustcode/engine/src/thread_status.rs @@ -204,7 +204,7 @@ fn unanswered_first_prompt(session_id: &str) -> bool { && has_only_first_prompt(&crate::sessions::load_session_history_direct(session_id)) } -pub(crate) fn has_only_first_prompt(history: &[crate::app::ChatMessage]) -> bool { +pub(crate) fn has_only_first_prompt(history: &[rustcode_core::ChatMessage]) -> bool { matches!(history, [message] if message.role == "user" && !message.content.trim().is_empty()) } diff --git a/rustcode/engine/src/worktrees.rs b/rustcode/engine/src/worktrees.rs index 494c78c10..4dd168e82 100644 --- a/rustcode/engine/src/worktrees.rs +++ b/rustcode/engine/src/worktrees.rs @@ -3283,8 +3283,8 @@ pub(crate) mod tests { store.save_session_history( id, &vec![ - crate::app::ChatMessage::new("user", "Run in a worktree"), - crate::app::ChatMessage::new("assistant", "Done"), + rustcode_core::ChatMessage::new("user", "Run in a worktree"), + rustcode_core::ChatMessage::new("assistant", "Done"), ], ); rustcode_session::flush_history();