diff --git a/crates/agent/src/antigravity.rs b/crates/agent/src/antigravity.rs index ba0b45590..ce87ca255 100644 --- a/crates/agent/src/antigravity.rs +++ b/crates/agent/src/antigravity.rs @@ -472,6 +472,10 @@ struct Antigravity { /// so their immediate spawn-ack `completed` updates do not prematurely /// close the subagent item. spawned_subagents: Mutex>, + /// In-flight `exit_plan_mode` / `enter_plan_mode` calls observed on the ACP + /// wire, keyed by `toolCallId`, so their `tool_call_update` frames stay on + /// `ItemContent::Plan` / `ItemContent::PlanModeEntered`. + plan_mode_calls: Mutex>, /// Control channel for the session's background subagent/proactive watcher. watcher: Mutex>>, /// When the agent was last heard from in the open turn ([`watchdog`]), @@ -489,6 +493,90 @@ struct SessionRecord { path: PathBuf, } +#[derive(Clone)] +enum PlanModeCall { + Exit { plan: String }, + Enter { reason: Option }, +} + +impl PlanModeCall { + fn from_tool_call(call: &acp::ToolCall) -> Option { + match call.title.as_str() { + "Run exit_plan_mode" => { + let plan = plan_input(call.raw_input.as_ref())?; + Some(Self::Exit { plan }) + } + "Run enter_plan_mode" => Some(Self::Enter { + reason: reason_input(call.raw_input.as_ref()), + }), + _ => None, + } + } + + fn apply_raw_input(&mut self, raw_input: Option<&Value>) { + match self { + Self::Exit { plan } => { + if let Some(updated) = plan_input(raw_input) { + *plan = updated; + } + } + Self::Enter { reason } => { + if let Some(updated) = reason_input(raw_input) { + *reason = Some(updated); + } + } + } + } + + fn item_content(&self) -> ItemContent { + match self { + Self::Exit { plan } => ItemContent::Plan { + markdown: plan.clone(), + }, + Self::Enter { reason } => ItemContent::PlanModeEntered { + reason: reason.clone(), + }, + } + } + + fn failed_tool_call(&self, output: Option) -> ItemContent { + let (name, input) = match self { + Self::Exit { plan } => ("exit_plan_mode", json!({ "plan": plan })), + Self::Enter { reason } => ( + "enter_plan_mode", + reason + .as_ref() + .map_or_else(|| json!({}), |reason| json!({ "reason": reason })), + ), + }; + ItemContent::ToolCall { + image_reads: Vec::new(), + name: name.to_owned(), + input, + output, + status: ItemStatus::Failed, + family: None, + } + } +} + +fn plan_input(raw_input: Option<&Value>) -> Option { + raw_input? + .get("plan") + .and_then(Value::as_str) + .filter(|plan| !plan.trim().is_empty()) + .map(str::to_owned) +} + +fn reason_input(raw_input: Option<&Value>) -> Option { + raw_input? + .get("reason") + .and_then(Value::as_str) + .map(str::trim) + .filter(|reason| !reason.is_empty()) + .map(str::to_owned) +} + impl Antigravity { fn send_watcher(&self, command: subagents::WatcherCommand) { if let Some(tx) = self @@ -526,6 +614,11 @@ impl Antigravity { .lock() .unwrap_or_else(|held| held.into_inner()) .contains_key(call.tool_call_id.0.as_ref()) + && !self + .plan_mode_calls + .lock() + .unwrap_or_else(|held| held.into_inner()) + .contains_key(call.tool_call_id.0.as_ref()) } acp::SessionUpdate::ToolCallUpdate(update) => { !state.has_tool(&update.tool_call_id.0) @@ -534,6 +627,11 @@ impl Antigravity { .lock() .unwrap_or_else(|held| held.into_inner()) .contains_key(update.tool_call_id.0.as_ref()) + && !self + .plan_mode_calls + .lock() + .unwrap_or_else(|held| held.into_inner()) + .contains_key(update.tool_call_id.0.as_ref()) } _ => false, } @@ -946,6 +1044,27 @@ impl Dialect for Antigravity { { active.usage_seen = false; } + if call.status != acp::ToolCallStatus::Failed + && let Some(plan_call) = PlanModeCall::from_tool_call(call) + { + events.extend(state.flush_text()); + let id = call.tool_call_id.0.to_string(); + let item = ThreadItem { + id: id.clone(), + parent_item_id: None, + content: plan_call.item_content(), + }; + if call.status == acp::ToolCallStatus::Completed { + events.push(AgentEvent::ItemCompleted(item)); + } else { + self.plan_mode_calls + .lock() + .unwrap_or_else(|held| held.into_inner()) + .insert(id, plan_call); + events.push(AgentEvent::ItemStarted(item)); + } + return events; + } if let Some((recipient, message)) = subagents::parse_send_message(call) { self.send_watcher(subagents::WatcherCommand::MessageSent { recipient, @@ -992,6 +1111,57 @@ impl Dialect for Antigravity { // the subagent item from its on-disk trajectory. return events; } + let plan_update = { + let mut calls = self + .plan_mode_calls + .lock() + .unwrap_or_else(|held| held.into_inner()); + if let Some(plan_call) = calls.get_mut(id) { + plan_call.apply_raw_input(update.fields.raw_input.as_ref()); + let snapshot = plan_call.clone(); + if matches!( + update.fields.status, + Some(acp::ToolCallStatus::Completed | acp::ToolCallStatus::Failed) + ) { + calls.remove(id); + } + Some(snapshot) + } else { + None + } + }; + if let Some(plan_call) = plan_update { + events.extend(state.flush_text()); + let item_id = id.to_owned(); + match update.fields.status { + Some(acp::ToolCallStatus::Failed) => { + let summary = tool_error_summary( + update.fields.content.as_deref(), + update.fields.raw_output.as_ref(), + ); + events.push(AgentEvent::ItemCompleted(ThreadItem { + id: item_id, + parent_item_id: None, + content: plan_call.failed_tool_call(summary), + })); + } + Some(acp::ToolCallStatus::Completed) => { + events.push(AgentEvent::ItemCompleted(ThreadItem { + id: item_id, + parent_item_id: None, + content: plan_call.item_content(), + })); + } + _ => { + events.push(AgentEvent::ItemUpdated(ThreadItem { + id: item_id, + parent_item_id: None, + content: plan_call.item_content(), + })); + } + } + return events; + } if state.tool_title(id) == Some("Run manage_subagents") { self.send_watcher(subagents::WatcherCommand::Wake); } @@ -1773,6 +1943,153 @@ mod tests { assert_eq!(normalize_mcp_tool_name("read_file", &servers), None); } + /// `exit_plan_mode` and `enter_plan_mode` map to canonical `Plan` and + /// `PlanModeEntered` items across `tool_call` -> `tool_call_update` + /// (observed in `agy acp` 1.5.20 orchestrator turns), while failures keep + /// their error visible as a failed `ToolCall` and empty plans fall through. + #[test] + fn plan_mode_tools_map_to_plan_and_plan_mode_entered() { + let dialect = Antigravity::default(); + let mut state = State::new(ProviderKind::Antigravity, PathBuf::from("/repo")); + let _ = state.begin_agent_turn("turn-1"); + + let plan = "# Batch 1\n\n1. Update parser\n2. Run tests"; + let started_exit = dialect.session_update( + &mut state, + notification(json!({ + "sessionUpdate": "tool_call", + "toolCallId": "call_exit", + "title": "Run exit_plan_mode", + "kind": "other", + "status": "in_progress", + "rawInput": { "plan": plan } + })), + ); + assert!(matches!( + started_exit.as_slice(), + [AgentEvent::ItemStarted(ThreadItem { + id, + parent_item_id: None, + content: ItemContent::Plan { markdown }, + })] if id == "call_exit" && markdown == plan + )); + + let completed_exit = dialect.session_update( + &mut state, + notification(json!({ + "sessionUpdate": "tool_call_update", + "toolCallId": "call_exit", + "status": "completed", + "rawOutput": "Plan mode is off." + })), + ); + assert!(matches!( + completed_exit.as_slice(), + [AgentEvent::ItemCompleted(ThreadItem { + id, + parent_item_id: None, + content: ItemContent::Plan { markdown }, + })] if id == "call_exit" && markdown == plan + )); + + let reason = "Tests failed twice.\n1. Foo failed\n2. Bar panicked"; + let started_enter = dialect.session_update( + &mut state, + notification(json!({ + "sessionUpdate": "tool_call", + "toolCallId": "call_enter", + "title": "Run enter_plan_mode", + "kind": "other", + "status": "in_progress", + "rawInput": { "reason": reason } + })), + ); + assert!(matches!( + started_enter.as_slice(), + [AgentEvent::ItemStarted(ThreadItem { + id, + parent_item_id: None, + content: ItemContent::PlanModeEntered { reason: Some(text) }, + })] if id == "call_enter" && text == reason + )); + + let completed_enter = dialect.session_update( + &mut state, + notification(json!({ + "sessionUpdate": "tool_call_update", + "toolCallId": "call_enter", + "status": "completed", + "rawOutput": "Plan mode is on." + })), + ); + assert!(matches!( + completed_enter.as_slice(), + [AgentEvent::ItemCompleted(ThreadItem { + id, + parent_item_id: None, + content: ItemContent::PlanModeEntered { reason: Some(text) }, + })] if id == "call_enter" && text == reason + )); + + // A failed update reverts to a failed ToolCall so the error stays visible. + let _ = dialect.session_update( + &mut state, + notification(json!({ + "sessionUpdate": "tool_call", + "toolCallId": "call_enter_fail", + "title": "Run enter_plan_mode", + "kind": "other", + "status": "in_progress", + "rawInput": { "reason": "Re-plan" } + })), + ); + let failed_enter = dialect.session_update( + &mut state, + notification(json!({ + "sessionUpdate": "tool_call_update", + "toolCallId": "call_enter_fail", + "status": "failed", + "rawOutput": "Already in plan mode" + })), + ); + assert!(matches!( + failed_enter.as_slice(), + [AgentEvent::ItemCompleted(ThreadItem { + id, + content: ItemContent::ToolCall { + name, + status: ItemStatus::Failed, + output: Some(output), + .. + }, + .. + })] if id == "call_enter_fail" + && name == "enter_plan_mode" + && output == "Already in plan mode" + )); + + // An exit_plan_mode call with no plan text falls through as a regular ToolCall. + let empty_exit = dialect.session_update( + &mut state, + notification(json!({ + "sessionUpdate": "tool_call", + "toolCallId": "call_exit_empty", + "title": "Run exit_plan_mode", + "kind": "other", + "status": "completed", + "rawInput": { "plan": " " } + })), + ); + assert!(matches!( + empty_exit.as_slice(), + [AgentEvent::ItemCompleted(ThreadItem { + id, + content: ItemContent::ToolCall { .. }, + .. + })] if id == "call_exit_empty" + )); + } + /// `read_file` on an image over `agy acp` 1.5.23 sends only the text /// placeholder `"Showing binary file of type image/..."` with no inline /// image block; `enrich_events` captures the file from disk, skips diff --git a/crates/agent/src/claude.rs b/crates/agent/src/claude.rs index 8e300d3e8..9149d6e54 100644 --- a/crates/agent/src/claude.rs +++ b/crates/agent/src/claude.rs @@ -1798,6 +1798,9 @@ pub(crate) enum ToolItem { Plan { markdown: String, }, + PlanModeEntered { + input: Value, + }, Subagent { agent_type: String, description: String, @@ -1823,6 +1826,11 @@ impl ToolItem { }, ItemContent::Plan { markdown }, ) + } else if name == ENTER_PLAN_MODE { + ( + ToolItem::PlanModeEntered { input }, + ItemContent::PlanModeEntered { reason: None }, + ) } else if is_command_tool(&name) { let command = input .get("command") @@ -1936,6 +1944,20 @@ impl ToolItem { } } ToolItem::Plan { markdown } => ItemContent::Plan { markdown }, + ToolItem::PlanModeEntered { input } => { + if is_error { + ItemContent::ToolCall { + image_reads: images, + name: ENTER_PLAN_MODE.to_owned(), + input, + output: (!text.is_empty()).then_some(text), + status, + family: None, + } + } else { + ItemContent::PlanModeEntered { reason: None } + } + } ToolItem::Subagent { agent_type, description, diff --git a/crates/agent/src/claude/parse.rs b/crates/agent/src/claude/parse.rs index 0b438701e..35dcfdada 100644 --- a/crates/agent/src/claude/parse.rs +++ b/crates/agent/src/claude/parse.rs @@ -51,6 +51,9 @@ pub(super) fn subagent_description(input: &Value) -> String { }) } +/// The tool Claude Code calls to enter plan mode. +pub(super) const ENTER_PLAN_MODE: &str = "EnterPlanMode"; + /// The tool Claude Code calls to present its plan and leave plan mode. pub(super) const EXIT_PLAN_MODE: &str = "ExitPlanMode"; diff --git a/crates/agent/src/claude/stream.rs b/crates/agent/src/claude/stream.rs index 3efefd5bc..802a8fcbb 100644 --- a/crates/agent/src/claude/stream.rs +++ b/crates/agent/src/claude/stream.rs @@ -471,7 +471,10 @@ impl Mapper { item @ (ToolItem::Command { .. } | ToolItem::File { .. } | ToolItem::Tool { .. } - | ToolItem::Plan { .. }) => item.finished(block, msg.get("tool_use_result")), + | ToolItem::Plan { .. } + | ToolItem::PlanModeEntered { .. }) => { + item.finished(block, msg.get("tool_use_result")) + } ToolItem::Subagent { agent_type, description, diff --git a/crates/agent/src/claude/tests.rs b/crates/agent/src/claude/tests.rs index 435dc6ce0..70e13da66 100644 --- a/crates/agent/src/claude/tests.rs +++ b/crates/agent/src/claude/tests.rs @@ -2760,6 +2760,58 @@ fn exit_plan_mode_shows_its_plan_and_takes_the_decision_natively() { ); } +#[test] +fn enter_plan_mode_maps_to_plan_mode_entered_and_keeps_errors_visible() { + let mut mapper = Mapper::new(); + let started = mapper.on_message(json!({"type":"assistant", "message": { + "content":[{"type":"tool_use", "id":"toolu_enter_ok", "name":"EnterPlanMode", "input":{}}]}})); + assert!( + started.iter().any(|event| matches!( + event, + AgentEvent::ItemStarted(ThreadItem { + id, + content: ItemContent::PlanModeEntered { reason: None }, + .. + }) if id == "toolu_enter_ok" + )), + "{started:?}" + ); + let completed = mapper.on_message(json!({"type":"user", "message": {"content":[ + {"type":"tool_result", "tool_use_id":"toolu_enter_ok", "content":"Entered plan mode."}]}})); + assert!( + completed.iter().any(|event| matches!( + event, + AgentEvent::ItemCompleted(ThreadItem { + id, + content: ItemContent::PlanModeEntered { reason: None }, + .. + }) if id == "toolu_enter_ok" + )), + "{completed:?}" + ); + + let _ = mapper.on_message(json!({"type":"assistant", "message": { + "content":[{"type":"tool_use", "id":"toolu_enter_err", "name":"EnterPlanMode", "input":{}}]}})); + let errored = mapper.on_message(json!({"type":"user", "message": {"content":[ + {"type":"tool_result", "tool_use_id":"toolu_enter_err", "is_error": true, "content":"User declined."}]}})); + assert!( + errored.iter().any(|event| matches!( + event, + AgentEvent::ItemCompleted(ThreadItem { + id, + content: ItemContent::ToolCall { + name, + status: ItemStatus::Failed | ItemStatus::Declined, + output: Some(output), + .. + }, + .. + }) if id == "toolu_enter_err" && name == "EnterPlanMode" && output == "User declined." + )), + "{errored:?}" + ); +} + /// `control_cancel_request {request_id}` as Claude Code 2.1.322's SDK /// schema describes it: the sender no longer needs the answer to its own /// request, "for example a pending can_use_tool prompt after the turn was diff --git a/crates/agent/src/lib.rs b/crates/agent/src/lib.rs index 664acc29e..be1ca34ad 100644 --- a/crates/agent/src/lib.rs +++ b/crates/agent/src/lib.rs @@ -3543,11 +3543,20 @@ pub enum ItemContent { }, /// A plan the harness proposed on its way out of its own plan mode /// (Claude Code's `ExitPlanMode`, Grok's `exit_plan_mode`, Cursor's - /// `create_plan`, Codex's plan item). When the harness waits on a decision - /// it also asks an [`ApprovalKind::Plan`] naming this item. + /// `create_plan`, Codex's plan item, Antigravity's `exit_plan_mode`). + /// When the harness waits on a decision it also asks an + /// [`ApprovalKind::Plan`] naming this item. Plan { markdown: String, }, + /// The harness entered its own plan mode (Antigravity's `enter_plan_mode` + /// when its orchestrator hands control back to the planning model, Claude + /// Code's `EnterPlanMode`). `reason` carries what the harness gave for + /// entering plan mode, when it gave one. + PlanModeEntered { + #[serde(default, skip_serializing_if = "Option::is_none")] + reason: Option, + }, CommandExecution { command: String, /// The lines written to the command's stdin while it ran, in order. diff --git a/crates/core/src/relay.rs b/crates/core/src/relay.rs index 7e813ad26..25ab15d25 100644 --- a/crates/core/src/relay.rs +++ b/crates/core/src/relay.rs @@ -36,6 +36,7 @@ fn is_provider_work(content: &EntryContent) -> bool { | ItemContent::Subagent { .. } | ItemContent::ImageRead { .. } | ItemContent::WebSearch { .. } + | ItemContent::PlanModeEntered { .. } | ItemContent::Other { .. }, ) => true, EntryContent::Item(ItemContent::UserMessage { .. } | ItemContent::Reasoning { .. }) @@ -234,6 +235,10 @@ fn render_turn(number: usize, entries: &[&TimelineEntry]) -> String { body.push_str(markdown); body.push_str("\n\n"); } + EntryContent::Item(ItemContent::PlanModeEntered { reason }) => { + let outcome = reason.as_deref().map(one_line).unwrap_or_default(); + activity(&mut body, "plan_mode", "entered", &outcome); + } EntryContent::Feedback { .. } | EntryContent::Item(ItemContent::Plan { .. }) => {} EntryContent::Item(ItemContent::CommandExecution { command, diff --git a/crates/core/src/session.rs b/crates/core/src/session.rs index ef8807209..60edb4dc0 100644 --- a/crates/core/src/session.rs +++ b/crates/core/src/session.rs @@ -465,6 +465,7 @@ fn tool_item_state(content: &ItemContent) -> Option { ItemContent::UserMessage { .. } | ItemContent::AssistantMessage { .. } | ItemContent::Plan { .. } + | ItemContent::PlanModeEntered { .. } | ItemContent::Reasoning { .. } => return None, }; Some(match status { @@ -784,7 +785,7 @@ impl LatestActivity { let clip = |text: &str| truncate_chars(&one_line(text), Self::MAX_CHARS); Some(match item { ItemContent::UserMessage { .. } => return None, - ItemContent::Reasoning { .. } => Self::Thinking, + ItemContent::Reasoning { .. } | ItemContent::PlanModeEntered { .. } => Self::Thinking, ItemContent::AssistantMessage { .. } | ItemContent::Plan { .. } => Self::Writing, ItemContent::CommandExecution { command, .. } => Self::Command { text: clip(command), @@ -2483,6 +2484,12 @@ fn merge_content(existing: EntryContent, incoming: EntryContent) -> EntryContent ) => EntryContent::Item(ItemContent::Plan { markdown: merge_text(old, new), }), + ( + EntryContent::Item(ItemContent::PlanModeEntered { reason: old }), + EntryContent::Item(ItemContent::PlanModeEntered { reason: new }), + ) => EntryContent::Item(ItemContent::PlanModeEntered { + reason: new.or(old), + }), ( EntryContent::Item(ItemContent::CommandExecution { output: old_output, .. diff --git a/crates/protocol/src/lib.rs b/crates/protocol/src/lib.rs index aee7419e4..748fb0317 100644 --- a/crates/protocol/src/lib.rs +++ b/crates/protocol/src/lib.rs @@ -443,6 +443,9 @@ pub use wire::{ // from no settled thread. IndexSummary gains settled_counts and // outside_updated_at. SettledSessions, FindSettledSessions and ThreadFamily // return the remaining threads as a SessionPage. +// +// Unreleased: ItemContent gains PlanModeEntered (`plan_mode_entered`) with an +// optional `reason` for harnesses entering plan mode. pub const PROTOCOL_VERSION: u32 = 35; #[cfg(test)] diff --git a/crates/services/src/export.rs b/crates/services/src/export.rs index c9f8d0e8a..7242271f8 100644 --- a/crates/services/src/export.rs +++ b/crates/services/src/export.rs @@ -172,6 +172,13 @@ fn render_incomplete_timeline(output: &mut String, timeline: &Timeline) { output.push_str(markdown); output.push_str("\n\n"); } + EntryContent::Item(ItemContent::PlanModeEntered { reason }) => { + output.push_str("#### Entered plan mode\n\n"); + if let Some(reason) = reason { + output.push_str(reason); + output.push_str("\n\n"); + } + } EntryContent::Item(ItemContent::Reasoning { .. }) => {} activity => output.push_str(&format!("- Activity: `{activity:?}`\n")), } diff --git a/crates/services/src/session_search.rs b/crates/services/src/session_search.rs index 40e67138a..c5b85b3e7 100644 --- a/crates/services/src/session_search.rs +++ b/crates/services/src/session_search.rs @@ -391,6 +391,9 @@ fn searchable_text(content: &EntryContent) -> Option<(SearchKind, String)> { ItemContent::AssistantMessage { text, .. } | ItemContent::Plan { markdown: text } => { (SearchKind::AssistantMessage, text.clone()) } + ItemContent::PlanModeEntered { + reason: Some(reason), + } => (SearchKind::Other, reason.clone()), ItemContent::CommandExecution { command, .. } => { (SearchKind::CommandExecution, command.clone()) } @@ -420,7 +423,9 @@ fn searchable_text(content: &EntryContent) -> Option<(SearchKind, String)> { provider_kind, summary, } => (SearchKind::Other, format!("{provider_kind} {summary}")), - ItemContent::Reasoning { .. } => return None, + ItemContent::Reasoning { .. } | ItemContent::PlanModeEntered { reason: None } => { + return None; + } }) } diff --git a/crates/services/src/thread_index.rs b/crates/services/src/thread_index.rs index 19c1452a1..451b7067c 100644 --- a/crates/services/src/thread_index.rs +++ b/crates/services/src/thread_index.rs @@ -468,6 +468,11 @@ impl Activity { | ItemContent::UserMessage { text, .. } => { collect_references(text, &mut self.references); } + ItemContent::PlanModeEntered { reason } => { + if let Some(reason) = reason { + collect_references(reason, &mut self.references); + } + } ItemContent::Reasoning { .. } | ItemContent::Other { .. } => {} }, EntryContent::Steer { text, .. } | EntryContent::Feedback { text } => { @@ -1194,6 +1199,12 @@ pub fn entry_text(content: &EntryContent) -> (&'static str, String) { } ItemContent::AssistantMessage { text, .. } => ("assistant_message", text.clone()), ItemContent::Plan { markdown } => ("plan", markdown.clone()), + ItemContent::PlanModeEntered { reason } => ( + "plan_mode_entered", + reason + .clone() + .unwrap_or_else(|| "Entered plan mode".to_owned()), + ), ItemContent::Reasoning { text } => ("reasoning", text.clone()), ItemContent::CommandExecution { command, diff --git a/crates/ui/src/chat/components/notices.rs b/crates/ui/src/chat/components/notices.rs index 3156e65f1..062a3cc6b 100644 --- a/crates/ui/src/chat/components/notices.rs +++ b/crates/ui/src/chat/components/notices.rs @@ -578,21 +578,24 @@ pub(crate) fn rewind_failure(key: &str, label: String, cx: &App) -> AnyElement { .into_any_element() } -/// What the harness said in the flow of a turn: a warning, or the request -/// it tries again. +/// What the harness said in the flow of a turn: a warning, the request it +/// tries again, or entering plan mode. pub(crate) struct Said<'a> { pub(crate) key: &'a str, pub(crate) icon: IconName, pub(crate) tint: gpui::Hsla, - /// The harness's words, as said. + /// The one-line summary shown in the centred row. pub(crate) message: &'a str, + /// Full body shown when expanded; defaults to `message` when `None`. + pub(crate) body: Option<&'a str>, pub(crate) expanded: bool, } /// [`Said`] as a centred line of `tint`: the icon, then the words on one -/// line. A line the column cuts short fades where it is cut and, pressed, -/// opens on the words whole; one that fits shows them all and takes no -/// press. A message that changes cross-fades to the next. +/// line. A line the column cuts short (or whose full body has multiple lines) +/// fades where it is cut and, pressed, opens on the words whole; one that fits +/// on a single line shows them all and takes no press. A message that changes +/// cross-fades to the next. pub(crate) fn said_line( said: Said<'_>, on_toggle: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, @@ -603,10 +606,13 @@ pub(crate) fn said_line( icon, tint, message, + body, expanded, } = said; let key = key.to_owned(); let message = message.to_owned(); + let detail = body.unwrap_or(&message).to_owned(); + let multiline = detail.contains('\n'); let motion = motion.clone(); let on_toggle = std::rc::Rc::new(on_toggle); crate::motion::Sampled::new(move |window, cx| { @@ -638,7 +644,7 @@ pub(crate) fn said_line( .into_any_element(), ]; let line_id = SharedString::from(format!("{key}-line")); - let line = if *cut.read(cx) || expanded { + let line = if *cut.read(cx) || multiline || expanded { let on_toggle = on_toggle.clone(); crate::material::accessible_clickable( h_flex(), @@ -674,7 +680,7 @@ pub(crate) fn said_line( window, cx, ) - .map(|fold| fold.fold(super::disclosure::disclosure_body(&key, &message, cx))); + .map(|fold| fold.fold(super::disclosure::disclosure_body(&key, &detail, cx))); v_flex() .id(SharedString::from(key.clone())) .debug_selector(selector(key.clone())) diff --git a/crates/ui/src/chat/components/rewind.rs b/crates/ui/src/chat/components/rewind.rs index 9f2e56d79..cdb2474f5 100644 --- a/crates/ui/src/chat/components/rewind.rs +++ b/crates/ui/src/chat/components/rewind.rs @@ -760,6 +760,7 @@ fn removed_turns(key: &str, rewound: &Rewound, harness: &str, cx: &App) -> AnyEl } EntryContent::Item(ItemContent::AssistantMessage { text, .. }) | EntryContent::Item(ItemContent::Plan { markdown: text }) + | EntryContent::Item(ItemContent::PlanModeEntered { reason: Some(text) }) if !text.trim().is_empty() => { flush(&mut work, &mut rows); diff --git a/crates/ui/src/chat/model.rs b/crates/ui/src/chat/model.rs index 7afaee3e3..8953f369e 100644 --- a/crates/ui/src/chat/model.rs +++ b/crates/ui/src/chat/model.rs @@ -50,6 +50,7 @@ pub(crate) enum Segment<'a> { User(&'a TimelineEntry), Assistant(&'a TimelineEntry), Plan(&'a TimelineEntry), + PlanModeEntered(&'a TimelineEntry), Visualize(&'a TimelineEntry), /// A call that linked a pull request to the thread, as its record. PullRequest(&'a TimelineEntry), @@ -274,6 +275,9 @@ pub(crate) fn segment_entries<'a>( EntryContent::Item(ItemContent::Plan { .. }) => { single(&mut segments, &mut ranges, Segment::Plan(entry)); } + EntryContent::Item(ItemContent::PlanModeEntered { .. }) => { + single(&mut segments, &mut ranges, Segment::PlanModeEntered(entry)); + } EntryContent::ProviderRelay { .. } => { single(&mut segments, &mut ranges, Segment::Relay(entry)); } @@ -1078,6 +1082,12 @@ pub(crate) fn notice_keys(notice: &HostNotice, entry_id: &str) -> Vec { /// row its notice renders as. Empty for an ordinary user message, which stays /// a plain bubble. pub(crate) fn disclosure_keys(content: &EntryContent, entry_id: &str) -> Vec { + if matches!( + content, + EntryContent::Item(ItemContent::PlanModeEntered { reason: Some(_) }) + ) { + return vec![format!("plan-mode-entered-{entry_id}")]; + } user_notice(content).map_or_else(Vec::new, |notice| notice_keys(¬ice, entry_id)) } @@ -1344,6 +1354,44 @@ pub(in crate::chat) mod tests { )); assert!(matches!(segments[4], Segment::Assistant(entry) if entry.id == "assistant-2")); assert!(matches!(segments[5], Segment::Error(entry) if entry.id == "error")); + + let plan_flow = [ + command("plan-read"), + entry( + "exit-plan", + EntryContent::Item(ItemContent::Plan { + markdown: "1. Edit\n2. Test".into(), + }), + ), + command("exec-edit"), + entry( + "enter-plan", + EntryContent::Item(ItemContent::PlanModeEntered { + reason: Some("Batch 1 complete".into()), + }), + ), + command("review-read"), + ]; + let plan_segments = segment_entries(&plan_flow, false).flow; + assert!(matches!( + plan_segments.as_slice(), + [ + Segment::ActivityRun(before_plan), + Segment::Plan(plan), + Segment::ActivityRun(during_exec), + Segment::PlanModeEntered(entered), + Segment::ActivityRun(after_enter), + ] if before_plan.len() == 1 && before_plan[0].id == "plan-read" + && plan.id == "exit-plan" + && during_exec.len() == 1 && during_exec[0].id == "exec-edit" + && entered.id == "enter-plan" + && after_enter.len() == 1 && after_enter[0].id == "review-read" + )); + assert_eq!( + disclosure_keys(&plan_flow[3].content, "enter-plan"), + vec!["plan-mode-entered-enter-plan"] + ); + let entries = [ command("cmd"), entry( diff --git a/crates/ui/src/chat/timeline/render.rs b/crates/ui/src/chat/timeline/render.rs index ca3852aeb..1358ed0ba 100644 --- a/crates/ui/src/chat/timeline/render.rs +++ b/crates/ui/src/chat/timeline/render.rs @@ -256,6 +256,31 @@ impl TimelineView { Segment::Plan(entry) => { column = column.child(self.compose_plan(entry, cwd, cx)); } + Segment::PlanModeEntered(entry) => { + let EntryContent::Item(ItemContent::PlanModeEntered { reason }) = + &entry.content + else { + unreachable!(); + }; + let label = match reason.as_deref() { + Some(reason) => crate::tr!( + "chat.plan_mode_entered_reason", + reason = crate::chat::model::one_line(reason) + ) + .into_owned(), + None => crate::tr!("chat.plan_mode_entered").into_owned(), + }; + let key = format!("plan-mode-entered-{}", entry.id); + let said = components::notices::Said { + key: &key, + icon: IconName::Map, + tint: cx.theme().muted_foreground, + message: &label, + body: reason.as_deref(), + expanded: false, + }; + column = column.child(self.compose_said(index, said, cx)); + } Segment::Visualize(entry) => { column = column.child(self.compose_visualize(entry, cx)); } @@ -283,6 +308,7 @@ impl TimelineView { icon: IconName::RefreshCw, tint: cx.theme().muted_foreground, message, + body: None, expanded: false, }; column = column.child(self.compose_said(index, said, cx)); @@ -299,6 +325,7 @@ impl TimelineView { icon: IconName::TriangleAlert, tint, message, + body: None, expanded: false, }, cx, diff --git a/crates/ui/src/chat/timeline/render/tests.rs b/crates/ui/src/chat/timeline/render/tests.rs index 75995d14a..2d351e304 100644 --- a/crates/ui/src/chat/timeline/render/tests.rs +++ b/crates/ui/src/chat/timeline/render/tests.rs @@ -1258,4 +1258,54 @@ fn a_rewind_divider_offers_what_its_harness_keeps(cx: &mut TestAppContext) { "completing the command clears the folded work log spinner" ); } + + #[gpui::test] + fn plan_mode_entered_discloses_multiline_reason_on_click(cx: &mut TestAppContext) { + use gpui::{Modifiers, VisualTestContext, px, size}; + + let mut timeline = Timeline::default(); + timeline.turns = vec![TurnMeta::default()]; + timeline.entries.extend([ + entry("user-0", user_item("Run the roadmap")), + entry( + "plan-0", + EntryContent::Item(ItemContent::Plan { + markdown: "# Step 1\n\nImplement parser.".into(), + }), + ), + entry( + "enter-0", + EntryContent::Item(ItemContent::PlanModeEntered { + reason: Some("Verification failed twice:\n1. Foo failed\n2. Bar failed".into()), + }), + ), + entry("assistant-0", assistant("Re-planning now.")), + ]); + + let thread = ScriptedThread::new(cx, log_of(&timeline), 0, false); + cx.update(|cx| cx.set_reduce_motion(true)); + let (_view, cx) = thread.open(cx); + let cx: &mut VisualTestContext = cx; + cx.simulate_resize(size(px(900.), px(900.))); + thread.deliver(cx); + draw_settled(cx); + + assert!( + cx.debug_bounds("plan-card-plan-0").is_some(), + "plan card renders outside the work log" + ); + let collapsed = cx + .debug_bounds("plan-mode-entered-enter-0") + .expect("plan mode entered line renders in the timeline"); + + cx.simulate_click(collapsed.center(), Modifiers::default()); + draw_settled(cx); + let expanded = cx + .debug_bounds("plan-mode-entered-enter-0") + .expect("plan mode entered line stays visible after clicking"); + assert!( + expanded.size.height > collapsed.size.height, + "clicking a multi-line plan mode handback opens its disclosure body ({collapsed:?} -> {expanded:?})" + ); + } } diff --git a/crates/ui/src/chat/timeline/rows.rs b/crates/ui/src/chat/timeline/rows.rs index 9a28c4c4e..611a96a1e 100644 --- a/crates/ui/src/chat/timeline/rows.rs +++ b/crates/ui/src/chat/timeline/rows.rs @@ -512,6 +512,9 @@ fn hash_entry_shape(content: &EntryContent, hash: &mut DefaultHasher) { | EntryContent::Feedback { text } => { text.len().hash(hash); } + EntryContent::Item(ItemContent::PlanModeEntered { reason }) => { + reason.as_ref().map(String::len).hash(hash); + } EntryContent::Item(ItemContent::CommandExecution { command, input, diff --git a/crates/ui/src/chat/tools/mod.rs b/crates/ui/src/chat/tools/mod.rs index d70671814..3f632158e 100644 --- a/crates/ui/src/chat/tools/mod.rs +++ b/crates/ui/src/chat/tools/mod.rs @@ -211,7 +211,8 @@ pub(in crate::chat) fn family(entry: &TimelineEntry) -> Option { | ItemContent::UserMessage { .. } | ItemContent::AssistantMessage { .. } | ItemContent::Reasoning { .. } - | ItemContent::Plan { .. } => return None, + | ItemContent::Plan { .. } + | ItemContent::PlanModeEntered { .. } => return None, }) } diff --git a/locales/en.yml b/locales/en.yml index ddfbb5de8..646a9e1bd 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -129,6 +129,8 @@ chat: steered: "Steered" plan_title: "Plan" plan_feedback_hint: "Approve the plan, or reply below to keep planning." + plan_mode_entered: "Entered plan mode" + plan_mode_entered_reason: "Entered plan mode · %{reason}" orchestrate_state_completed: "completed" orchestrate_state_failed: "failed" orchestrate_state_reported: "reported" diff --git a/locales/ja.yml b/locales/ja.yml index f4806c03e..bf3e0bbd3 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -129,6 +129,8 @@ chat: steered: "追加指示済み" plan_title: "計画" plan_feedback_hint: "計画を承認するか、下に返信して計画を続けてください。" + plan_mode_entered: "プランモードに入りました" + plan_mode_entered_reason: "プランモードに入りました · %{reason}" orchestrate_state_completed: "完了" orchestrate_state_failed: "失敗" orchestrate_state_reported: "報告済み" diff --git a/locales/zh-CN.yml b/locales/zh-CN.yml index 834d7187f..9ba0edc79 100644 --- a/locales/zh-CN.yml +++ b/locales/zh-CN.yml @@ -129,6 +129,8 @@ chat: steered: "已追加提示" plan_title: "计划" plan_feedback_hint: "批准这份计划,或在下方回复让它继续规划。" + plan_mode_entered: "进入规划模式" + plan_mode_entered_reason: "进入规划模式 · %{reason}" orchestrate_state_completed: "已完成" orchestrate_state_failed: "已失败" orchestrate_state_reported: "已汇报"