diff --git a/design/hide-screens.pen b/design/hide-screens.pen index ac168468ff..2659894a4a 100644 --- a/design/hide-screens.pen +++ b/design/hide-screens.pen @@ -77573,6 +77573,188 @@ "layout": "vertical", "gap": 8 }, + { + "type": "frame", + "id": "sfu-ph-board-l-sec-fork", + "name": "Forked pane: the fork mark after the title, whose tooltip says which pane it was forked from (issue 916)", + "children": [ + { + "type": "text", + "id": "sfu-ph-board-l-sec-fork-label", + "name": "Forked pane: the fork mark a", + "content": "Forked pane: the fork mark after the title, whose tooltip says which pane it was forked from (issue 916)", + "fill": "$--subtle-foreground", + "fontFamily": "$--font-ui", + "fontSize": "$--text-caption", + "fontWeight": "600" + }, + { + "type": "frame", + "id": "sfu-ph-board-l-fork", + "name": "Pane", + "children": [ + { + "type": "frame", + "id": "sfu-ph-board-l-fork-header", + "name": "Header", + "children": [ + { + "type": "text", + "id": "sfu-ph-board-l-fork-path-0", + "name": "hide 에이전트 지원 PR 묶…", + "content": "hide 에이전트 지원 PR 묶…", + "fill": "$--muted-foreground", + "fontFamily": "$--font-ui", + "fontSize": "$--text-caption", + "fontWeight": "400" + }, + { + "type": "text", + "id": "sfu-ph-board-l-fork-sep-0", + "name": "›", + "content": "›", + "fill": "$--muted-foreground", + "fontFamily": "$--font-ui", + "fontSize": "$--text-caption", + "fontWeight": "400" + }, + { + "type": "text", + "id": "sfu-ph-board-l-fork-mark", + "name": "○", + "content": "○", + "fill": "$--agent-working", + "fontFamily": "$--font-mono", + "fontSize": "$--text-caption", + "fontWeight": "600" + }, + { + "type": "frame", + "id": "sfu-ph-board-l-fork-provider", + "name": "Provider", + "children": [], + "width": 14, + "height": 14, + "fill": { + "type": "image", + "enabled": true, + "url": "../web/src/assets/agent-claude.png", + "mode": "contain" + } + }, + { + "type": "text", + "id": "sfu-ph-board-l-fork-title", + "name": "P8 읽기 전용 준비", + "content": "P8 읽기 전용 준비", + "fill": "$--foreground", + "fontFamily": "$--font-ui", + "fontSize": "$--text-caption", + "fontWeight": "400" + }, + { + "type": "icon", + "id": "sfu-ph-board-l-fork-fork", + "name": "Glyph", + "enabled": true, + "width": 12, + "height": 12, + "icon": "git-fork", + "library": "lucide", + "fill": "$--subtle-foreground" + }, + { + "type": "frame", + "id": "sfu-ph-board-l-fork-sp", + "name": "Spacer", + "children": [], + "width": "fill_container", + "height": 1 + }, + { + "type": "icon", + "id": "sfu-ph-board-l-fork-zoom", + "name": "Glyph", + "enabled": true, + "width": 12, + "height": 12, + "icon": "maximize-2", + "library": "lucide", + "fill": "$--subtle-foreground" + }, + { + "type": "icon", + "id": "sfu-ph-board-l-fork-menu", + "name": "Glyph", + "enabled": true, + "width": 14, + "height": 14, + "icon": "ellipsis", + "library": "lucide", + "fill": "$--subtle-foreground" + }, + { + "type": "icon", + "id": "sfu-ph-board-l-fork-close", + "name": "Glyph", + "enabled": true, + "width": 14, + "height": 14, + "icon": "x", + "library": "lucide", + "fill": "$--subtle-foreground" + } + ], + "width": "fill_container", + "height": 28, + "layout": "horizontal", + "gap": 6, + "alignItems": "center", + "padding": [ + 0, + 8 + ], + "fill": "$--card" + }, + { + "type": "frame", + "id": "sfu-ph-board-l-fork-terminal", + "name": "Terminal", + "children": [ + { + "type": "text", + "id": "sfu-ph-board-l-fork-terminal-text", + "name": "› 테스트 작성 결과를 기다리는 중", + "content": "› 테스트 작성 결과를 기다리는 중", + "fill": "$--muted-foreground", + "fontFamily": "$--font-mono", + "fontSize": "$--text-caption", + "fontWeight": "400" + } + ], + "width": "fill_container", + "height": "fill_container", + "padding": [ + 8, + 12 + ] + } + ], + "width": "fill_container", + "height": 120, + "layout": "vertical", + "gap": 0, + "clip": true, + "fill": "$--background", + "stroke": "$--border", + "strokeWidth": 1, + "strokeAlignment": "inner" + } + ], + "width": "fill_container", + "layout": "vertical", + "gap": 8 + }, { "type": "frame", "id": "sfu-ph-board-l-sec-two", @@ -97248,6 +97430,188 @@ "layout": "vertical", "gap": 8 }, + { + "type": "frame", + "id": "sfu-ph-board-d-sec-fork", + "name": "Forked pane: the fork mark after the title, whose tooltip says which pane it was forked from (issue 916)", + "children": [ + { + "type": "text", + "id": "sfu-ph-board-d-sec-fork-label", + "name": "Forked pane: the fork mark a", + "content": "Forked pane: the fork mark after the title, whose tooltip says which pane it was forked from (issue 916)", + "fill": "$--subtle-foreground", + "fontFamily": "$--font-ui", + "fontSize": "$--text-caption", + "fontWeight": "600" + }, + { + "type": "frame", + "id": "sfu-ph-board-d-fork", + "name": "Pane", + "children": [ + { + "type": "frame", + "id": "sfu-ph-board-d-fork-header", + "name": "Header", + "children": [ + { + "type": "text", + "id": "sfu-ph-board-d-fork-path-0", + "name": "hide 에이전트 지원 PR 묶…", + "content": "hide 에이전트 지원 PR 묶…", + "fill": "$--muted-foreground", + "fontFamily": "$--font-ui", + "fontSize": "$--text-caption", + "fontWeight": "400" + }, + { + "type": "text", + "id": "sfu-ph-board-d-fork-sep-0", + "name": "›", + "content": "›", + "fill": "$--muted-foreground", + "fontFamily": "$--font-ui", + "fontSize": "$--text-caption", + "fontWeight": "400" + }, + { + "type": "text", + "id": "sfu-ph-board-d-fork-mark", + "name": "○", + "content": "○", + "fill": "$--agent-working", + "fontFamily": "$--font-mono", + "fontSize": "$--text-caption", + "fontWeight": "600" + }, + { + "type": "frame", + "id": "sfu-ph-board-d-fork-provider", + "name": "Provider", + "children": [], + "width": 14, + "height": 14, + "fill": { + "type": "image", + "enabled": true, + "url": "../web/src/assets/agent-claude.png", + "mode": "contain" + } + }, + { + "type": "text", + "id": "sfu-ph-board-d-fork-title", + "name": "P8 읽기 전용 준비", + "content": "P8 읽기 전용 준비", + "fill": "$--foreground", + "fontFamily": "$--font-ui", + "fontSize": "$--text-caption", + "fontWeight": "400" + }, + { + "type": "icon", + "id": "sfu-ph-board-d-fork-fork", + "name": "Glyph", + "enabled": true, + "width": 12, + "height": 12, + "icon": "git-fork", + "library": "lucide", + "fill": "$--subtle-foreground" + }, + { + "type": "frame", + "id": "sfu-ph-board-d-fork-sp", + "name": "Spacer", + "children": [], + "width": "fill_container", + "height": 1 + }, + { + "type": "icon", + "id": "sfu-ph-board-d-fork-zoom", + "name": "Glyph", + "enabled": true, + "width": 12, + "height": 12, + "icon": "maximize-2", + "library": "lucide", + "fill": "$--subtle-foreground" + }, + { + "type": "icon", + "id": "sfu-ph-board-d-fork-menu", + "name": "Glyph", + "enabled": true, + "width": 14, + "height": 14, + "icon": "ellipsis", + "library": "lucide", + "fill": "$--subtle-foreground" + }, + { + "type": "icon", + "id": "sfu-ph-board-d-fork-close", + "name": "Glyph", + "enabled": true, + "width": 14, + "height": 14, + "icon": "x", + "library": "lucide", + "fill": "$--subtle-foreground" + } + ], + "width": "fill_container", + "height": 28, + "layout": "horizontal", + "gap": 6, + "alignItems": "center", + "padding": [ + 0, + 8 + ], + "fill": "$--card" + }, + { + "type": "frame", + "id": "sfu-ph-board-d-fork-terminal", + "name": "Terminal", + "children": [ + { + "type": "text", + "id": "sfu-ph-board-d-fork-terminal-text", + "name": "› 테스트 작성 결과를 기다리는 중", + "content": "› 테스트 작성 결과를 기다리는 중", + "fill": "$--muted-foreground", + "fontFamily": "$--font-mono", + "fontSize": "$--text-caption", + "fontWeight": "400" + } + ], + "width": "fill_container", + "height": "fill_container", + "padding": [ + 8, + 12 + ] + } + ], + "width": "fill_container", + "height": 120, + "layout": "vertical", + "gap": 0, + "clip": true, + "fill": "$--background", + "stroke": "$--border", + "strokeWidth": 1, + "strokeAlignment": "inner" + } + ], + "width": "fill_container", + "layout": "vertical", + "gap": 8 + }, { "type": "frame", "id": "sfu-ph-board-d-sec-two", diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 568bc8bcc1..599a6112b2 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -437,6 +437,7 @@ A count Hide cannot read is reported as unknown, never as zero. A pane's parent travels the same channel, and it is the only lineage there is: Herdr records none. hided is the sole writer of `parent_pane`, optional `parent_machine`, `child_session` and `parent_session` through `pane.report_metadata`; the unchanged value and lifetime contract is described in [status-model.md](status-model.md#where-a-parent-comes-from). +Fork agent adds one more, `fork`, on the pane it made, so the pane header can say a pane is a fork and a delegated child is not drawn as one. Those tokens die with the pane, not with the agent, so a relationship holds only while both panes still report the sessions it was written for: `wire.rs` compares the child's, `agent_state::apply_lineage` the parent's, and an agent that took over a pane is a root. A spawn without `--parent` is an operator handoff: `AgentRecord.parent` is empty and its separate optional `origin` records the spawner. Delegated origin is derived from parent, and all CLI agent answers include nullable origin. diff --git a/docs/DESIGN_WORKFLOW.md b/docs/DESIGN_WORKFLOW.md index 5c9983cf8c..f9a2bd51e2 100644 --- a/docs/DESIGN_WORKFLOW.md +++ b/docs/DESIGN_WORKFLOW.md @@ -174,7 +174,7 @@ Workspace is `Screen / Workspace`. It draws docked Agent Views, File Views and Tools beneath one full-width toolbar, using the Workspace columns, toolbar, toggle and divider masters in the library. The toolbar's right edge carries Open server, File Views and Tools, with independent pressed states, a count when open File Views are hidden, and per-control tooltip and keyboard-focus states. The columns start with their own tab strips; File Views carries its document header and Tools carries Sessions, Explorer and History, with Sessions first and the selection saved per Workspace. -The pane header's ancestor path, own PR mark, tree button and ask band follow the approved agent-hierarchy round 2 reference, the pane header board on this sheet, in both themes, and `design/review-targets.json` names it as the `pane-header` target. +The pane header's ancestor path, fork mark, own PR mark, tree button and ask band follow the approved agent-hierarchy round 2 reference, the pane header board on this sheet, in both themes (the fork mark is the issue 916 addition, chosen by the operator as a small icon after the title and drawn in the board's Forked pane section), and `design/review-targets.json` names it as the `pane-header` target. The reference includes the full layout, both narrow-window fallbacks and explicit column calls, Tools without File Views, saved widths, and the divider at rest, under the pointer, focused and being dragged. Light and Dark frames carry Korean text and long paths, including the one-line shortened document path and its full-path tooltip. The server-picker comparison retains its distinct reachable endpoints, and the area-focus comparison retains two View areas with one keyboard owner and independently readable selections. diff --git a/docs/UI_BEHAVIOR.md b/docs/UI_BEHAVIOR.md index d49c1de418..b96ea28fbf 100644 --- a/docs/UI_BEHAVIOR.md +++ b/docs/UI_BEHAVIOR.md @@ -309,11 +309,12 @@ The browser display's toolbar and its loading, load failed, and plain browser ta ### Agent panes and the Agents explorer -A pane header is a quiet identity row: the ancestor path, provider, title, the pane's own PR mark, the tree button, the Not connected chip, and the retained overflow, zoom and close controls at the right end. +A pane header is a quiet identity row: the ancestor path, provider, title, the fork mark, the pane's own PR mark, the tree button, the Not connected chip, and the retained overflow, zoom and close controls at the right end. A plain shell keeps its terminal mark. A child pane's ancestor path names each ancestor from the root to its parent, `›` between them, and each name opens that pane; a root has none. The names drop before current identity or actions when the pane narrows, leaving `›` with its accessible name. The PR mark shows the pane's own PRs only, as Sessions draws them (below); a descendant's PRs stay on its own rows. +The fork mark, a small fork icon after the title, is drawn only on a pane Fork agent made; its tooltip and accessible name read `Forked from `, or `Forked from another pane` when that pane is no longer in the lineage, and a delegated child that was not forked has none (`web/src/PaneHeaderBand.tsx`, `PaneForkMark`; the fact is the core's, `PaneForkSnapshot.forked_from_pane_id`). The tree button, a tree icon and the direct child count with `자식 에이전트 N` as its tooltip, opens the tree popover (docs/status-model.md, The descendant mark and the tree popover). There is no status sentence, child-chip row or relationship sheet. The zoom control names the panes it hides and unzooms the tab; the existing pane keyboard outline and focused-header wash remain. @@ -340,6 +341,7 @@ A pane whose agent sleeps (PRD agent-sleep) shows its state in place of the term The core band reads Sleeping, Waking or the resume failure, and typed input to the pane goes nowhere. Opening the pane's tab by a committed move (a row, a tab, a checkout, a relation) wakes it in the same pane with its conversation; a Recent Panels preview does not, and neither does a click inside the tab already on screen. The pane menu offers Sleep agent on an agent pane that is awake on this machine, or on the machine the window runs on when that machine's core runs on another machine, disabled with the core's reason when the agent is working, waiting for the operator, of another kind, or has no conversation Herdr reported; a device's pane offers none. +Fork agent follows it in the same group: it is offered on a local agent pane whose conversation Herdr reported (`fork.available`) and sends `fork_pane`, which starts that conversation again as a new session in a pane of its own; on an agent that has a fork command but has not reported its conversation yet it is drawn disabled with the core's reason, and on a shell or an agent with no fork command there is no item. On such a window's own machine, bringing a tab forward wakes what sleeps there once that machine's Herdr has it in front. Web owner: `web/src/PaneView.tsx` (`SleepBody`), `web/src/sleep.ts`, `web/src/PaneRelations.tsx`. diff --git a/docs/status-model.md b/docs/status-model.md index f4ccdbdaa4..1013031e75 100644 --- a/docs/status-model.md +++ b/docs/status-model.md @@ -198,6 +198,7 @@ The CLI's required `origin` field records the spawner in both modes (null for or PR and issue panels still find the independent session through its own branch records without a delegated-by line. Herdr records no lineage, so hided writes the four pane tokens through `pane.report_metadata`: `parent_pane` names the parent's pane id, `parent_machine` names its machine when the parent is remote, and `child_session` and `parent_session` are the original session digests. The value and lifetime contract is unchanged. +A pane Hide's Fork agent made carries a fifth token, `fork` set to `1`, which the lineage writer writes with the other four from the registration's `forked` fact (`AgentRecord::forked`), so a wake that continues the registration in another pane writes it there too, and which is read only while the row still declares its parent, so a pane that hosts another agent later is not a fork and a delegated child never is (`SidebarAgentSnapshot.started_as_fork`, `PaneForkSnapshot.forked_from_pane_id`). The session tokens are lowercase hexadecimal SHA-256 digests of each original `agent_session.value`; this keeps even a path-valued session inside Herdr's 80-character token limit. A same-server relationship omits `parent_machine`. A changed child session clears all four tokens, while an absent session proves neither a valid relationship nor a session change. diff --git a/herdr-core/src/agent_sleep.rs b/herdr-core/src/agent_sleep.rs index 1d8e668cf0..2dba1a58eb 100644 --- a/herdr-core/src/agent_sleep.rs +++ b/herdr-core/src/agent_sleep.rs @@ -617,6 +617,7 @@ mod tests { descendant_line: None, id: pane_id.to_owned(), herdr_name: None, + started_as_fork: false, pane_id: pane_id.to_owned(), workspace_label: "Fixture".to_owned(), identity_label: "Refactor the parser".to_owned(), diff --git a/herdr-core/src/coordination/executor.rs b/herdr-core/src/coordination/executor.rs index 06e7901a28..db69116650 100644 --- a/herdr-core/src/coordination/executor.rs +++ b/herdr-core/src/coordination/executor.rs @@ -161,6 +161,7 @@ fn record( project, actor: actor_for(agent, host.machine, host.on_node)?, ended: false, + forked: false, }) } @@ -336,6 +337,7 @@ pub(crate) fn register_code_owned( project: None, actor: actor.clone(), ended: false, + forked: false, }; let registered = mutate( client, @@ -996,7 +998,7 @@ pub(crate) fn link_fork( None, native_parent.agent.as_deref().ok_or("parent_unavailable")?, )?; - let child_record = record( + let mut child_record = record( &native_child, HostIdentity { machine: &actor.device_id, @@ -1009,6 +1011,7 @@ pub(crate) fn link_fork( Some(parent_id), native_child.cwd.clone(), )?; + child_record.forked = true; let value = mutate( &client, &authority, @@ -1141,6 +1144,7 @@ mod tests { origin: None, project: None, ended: false, + forked: false, actor: actor.clone(), }, check: false, @@ -1365,6 +1369,7 @@ mod tests { origin: None, project: None, ended: false, + forked: false, actor: Actor { pane_id: "sender".into(), name: "sender".into(), @@ -1461,6 +1466,7 @@ mod tests { project: Some("/fixture/topic".into()), actor: child_actor.clone(), ended: false, + forked: false, }; let child_id = super::super::apply( &mut state, diff --git a/herdr-core/src/coordination/lineage.rs b/herdr-core/src/coordination/lineage.rs index 7e5ec28c5c..15ccdc0093 100644 --- a/herdr-core/src/coordination/lineage.rs +++ b/herdr-core/src/coordination/lineage.rs @@ -231,10 +231,24 @@ fn desired( } else { [Value::Null, Value::Null, Value::Null, Value::Null] }; - KEYS.into_iter() + let mut tokens = KEYS + .into_iter() .zip(values) .map(|(key, value)| (key.into(), value)) - .collect() + .collect::>(); + // A fork carries its mark on the pane that hosts its registration, for as + // long as the lineage holds; it is cleared with it (`wire::FORK_TOKEN`). + if record.forked { + tokens.insert( + crate::wire::FORK_TOKEN.into(), + if live.is_some() { + Value::String("1".into()) + } else { + Value::Null + }, + ); + } + tokens } fn plan(ledger: &Ledger, device: &str, agents: &[ProjectedAgent]) -> Vec { if ledger.agents.is_empty() { @@ -350,6 +364,7 @@ mod tests { session: crate::wire::session_digest(session), }, ended: false, + forked: false, } } #[test] @@ -379,6 +394,38 @@ mod tests { ); } #[test] + fn a_forks_registration_carries_the_mark_only_while_its_lineage_holds() { + let parent = record("agent-1", "w1:p1", "parent", None); + let mut child = record("agent-2", "w2:p1", "child", Some(&parent.id)); + let delegated = desired(&child, Some(&parent), child.actor.session.as_deref()); + assert!(!delegated.contains_key("fork")); + child.forked = true; + let live = desired(&child, Some(&parent), child.actor.session.as_deref()); + assert_eq!(live["fork"], "1"); + assert!(desired(&child, Some(&parent), Some("replacement"))["fork"].is_null()); + } + #[test] + fn a_fork_that_is_woken_in_another_pane_wears_the_mark_there() { + let parent = record("agent-1", "w1:p1", "parent", None); + let mut child = record("agent-2", "w2:p1", "child", Some(&parent.id)); + child.forked = true; + // The wake continues the registration in a pane Herdr just made, which + // carries none of the tokens the closed pane held. + child.pane = "w3:p1".into(); + child.actor.pane_id = "w3:p1".into(); + let woken = agent(&child, BTreeMap::new()); + let ledger = Ledger { + next_id: 3, + agents: vec![parent, child], + ..Default::default() + }; + let patches = plan(&ledger, crate::node::TEST_NODE, &[woken]); + assert_eq!(patches.len(), 1); + assert_eq!(patches[0].pane, "w3:p1"); + assert_eq!(patches[0].tokens["fork"], "1"); + assert_eq!(patches[0].tokens["parent_pane"], "w1:p1"); + } + #[test] fn an_ended_registration_keeps_lineage_and_same_server_omits_machine() { let mut parent = record("agent-1", "w1:p1", "parent", None); let mut child = record("agent-2", "w2:p1", "child", Some(&parent.id)); diff --git a/herdr-core/src/coordination/mod.rs b/herdr-core/src/coordination/mod.rs index 588fedacf4..9e8647971f 100644 --- a/herdr-core/src/coordination/mod.rs +++ b/herdr-core/src/coordination/mod.rs @@ -89,6 +89,11 @@ pub struct AgentRecord { pub project: Option, pub actor: Actor, pub ended: bool, + /// Made by Fork agent: the conversation is another execution's, resumed + /// as a new session. The registration owns the fact, so it follows the + /// registration to the pane that wakes it. + #[serde(default)] + pub forked: bool, } #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] @@ -943,6 +948,7 @@ mod tests { session: crate::wire::session_digest(session), }, ended: false, + forked: false, } } fn register(ledger: &mut Ledger, record: AgentRecord, caller: &Actor) -> String { diff --git a/herdr-core/src/delivery/doorbell.rs b/herdr-core/src/delivery/doorbell.rs index 731e9258b2..e364668bdc 100644 --- a/herdr-core/src/delivery/doorbell.rs +++ b/herdr-core/src/delivery/doorbell.rs @@ -1141,6 +1141,7 @@ mod tests { project: None, actor: sender.clone(), ended: false, + forked: false, }); assert_eq!( line(&ledger, &letter), diff --git a/herdr-core/src/factory.rs b/herdr-core/src/factory.rs index 4c360886d1..57177288d6 100644 --- a/herdr-core/src/factory.rs +++ b/herdr-core/src/factory.rs @@ -3468,6 +3468,7 @@ mod tests { project: Some(owned.worktree.clone()), actor, ended: false, + forked: false, }); } ledger.next_id = 3; diff --git a/herdr-core/src/fork.rs b/herdr-core/src/fork.rs index 379a265041..300d554605 100644 --- a/herdr-core/src/fork.rs +++ b/herdr-core/src/fork.rs @@ -238,6 +238,72 @@ pub fn is_forkable(agent_kind: Option<&str>, session_id: Option<&str>) -> bool { mod tests { use super::*; + /// A row Herdr lists running `kind` with `session`, under the lineage + /// tokens Hide writes for a child of `parent` and, for a fork, the fork mark. + fn listed( + kind: &str, + session: Option<&str>, + parent: Option<&str>, + fork_mark: bool, + ) -> crate::model::SidebarAgentSnapshot { + let mut agent = serde_json::json!({ + "id": "w1:p2", "pane_id": "w1:p2", "agent": kind, "agent_status": "idle", "state_change_seq": 1, + "spawned_from_pane_id": parent, + "tokens": if fork_mark { serde_json::json!({"fork": "1"}) } else { serde_json::json!({}) }, + }); + agent["spawned_from_pane_id"] = parent.map_or(serde_json::Value::Null, Into::into); + let mut row = crate::sidebar::project_agents( + crate::sidebar::owned_label_fixture(serde_json::json!({"agents": [agent]})).unwrap(), + ) + .agents + .remove(0); + row.session_id = session.map(str::to_owned); + row + } + + #[test] + fn a_forkable_agent_with_a_session_offers_fork_and_one_without_says_why() { + let fork = |kind, session| { + crate::runtime::pane_fork_snapshot(Some(&listed(kind, session, None, false))) + }; + let ready = fork("claude", Some("s-1")); + assert!(ready.available && ready.reason.is_none()); + let waiting = fork("claude", None); + assert!(!waiting.available); + assert!(waiting.reason.is_some()); + // An agent that has no fork command, and a pane with no agent, offer + // nothing and owe no reason. + let never = fork("cursor", Some("s-1")); + assert!(!never.available && never.reason.is_none()); + assert_eq!( + crate::runtime::pane_fork_snapshot(None), + crate::model::PaneForkSnapshot::default() + ); + } + + #[test] + fn only_a_pane_the_fork_marked_says_which_pane_it_was_forked_from() { + let forked = listed("claude", Some("s-2"), Some("w1:p1"), true); + assert_eq!( + crate::runtime::pane_fork_snapshot(Some(&forked)) + .forked_from_pane_id + .as_deref(), + Some("w1:p1") + ); + // A delegated child has a parent too, and is not a fork of it. + let delegated = listed("claude", Some("s-3"), Some("w1:p1"), false); + assert_eq!( + crate::runtime::pane_fork_snapshot(Some(&delegated)).forked_from_pane_id, + None + ); + // The mark counts only while the pane still declares its parent. + let orphan = listed("claude", Some("s-4"), None, true); + assert_eq!( + crate::runtime::pane_fork_snapshot(Some(&orphan)).forked_from_pane_id, + None + ); + } + fn request(agent: ForkableAgent) -> ForkRequest { ForkRequest { source_reference: None, diff --git a/herdr-core/src/model.rs b/herdr-core/src/model.rs index d36ddf1c62..812c9df4ca 100644 --- a/herdr-core/src/model.rs +++ b/herdr-core/src/model.rs @@ -967,6 +967,11 @@ pub struct SidebarAgentSnapshot { /// cannot stand in for this. #[serde(skip_serializing_if = "Option::is_none")] pub herdr_name: Option, + /// Whether this agent is the pane Hide's Fork made from its declared + /// parent (`wire::FORK_TOKEN`). Any child has a parent; only a fork is a + /// fork of it, and a name cannot tell them apart once the agent is woken. + #[serde(skip_serializing)] + pub started_as_fork: bool, pub pane_id: String, pub workspace_label: String, /// The checkout the agent's pane is in, once the navigator has placed it. @@ -2089,9 +2094,14 @@ pub struct ServerEndpointSnapshot { /// Both facts come from Herdr: whether the pane runs an agent whose own fork /// command can take its recorded session, and whether this pane is itself the /// result of such a fork. +/// +/// `reason` is set only on a pane whose agent can be forked in principle but +/// not yet, so the menu item that is drawn disabled can say why; an agent that +/// cannot be forked at all, and a pane with no agent, carry neither. #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)] pub struct PaneForkSnapshot { pub available: bool, + pub reason: Option, pub forked_from_pane_id: Option, } diff --git a/herdr-core/src/pet.rs b/herdr-core/src/pet.rs index 662b859bec..3fb40513d1 100644 --- a/herdr-core/src/pet.rs +++ b/herdr-core/src/pet.rs @@ -156,6 +156,7 @@ mod tests { descendant_line: None, id: pane_id.to_owned(), herdr_name: None, + started_as_fork: false, pane_id: pane_id.to_owned(), workspace_label: "Fixture".to_owned(), identity_label: "Fixture".to_owned(), diff --git a/herdr-core/src/runtime.rs b/herdr-core/src/runtime.rs index 0b5d523962..a4a0fb9a02 100644 --- a/herdr-core/src/runtime.rs +++ b/herdr-core/src/runtime.rs @@ -2571,9 +2571,17 @@ pub fn pane_fork_snapshot(agent: Option<&SidebarAgentSnapshot>) -> PaneForkSnaps let Some(agent) = agent else { return PaneForkSnapshot::default(); }; + let available = is_forkable(Some(agent.agent_kind.as_str()), agent.session_id.as_deref()); PaneForkSnapshot { - available: is_forkable(Some(agent.agent_kind.as_str()), agent.session_id.as_deref()), - forked_from_pane_id: agent.spawned_from_pane_id.clone(), + available, + reason: (!available && ForkableAgent::parse(&agent.agent_kind).is_some()) + .then(|| "This agent has not reported its conversation yet".to_owned()), + // Any child a parent declared has a `spawned_from_pane_id`; only one + // that was started as a fork is a fork of it. + forked_from_pane_id: agent + .started_as_fork + .then(|| agent.spawned_from_pane_id.clone()) + .flatten(), } } diff --git a/herdr-core/src/runtime/delivery.rs b/herdr-core/src/runtime/delivery.rs index 840a1e71b1..dba5186ce1 100644 --- a/herdr-core/src/runtime/delivery.rs +++ b/herdr-core/src/runtime/delivery.rs @@ -1836,6 +1836,7 @@ pub(crate) mod tests { project: None, actor, ended: false, + forked: false, }); guard.delivery_ledger = Ok(Arc::new(ledger)); } @@ -2317,6 +2318,7 @@ pub(crate) mod tests { project: None, actor: runtime.delivery_observations[pane].actor.clone(), ended: false, + forked: false, }); } ledger.next_id = 3; diff --git a/herdr-core/src/runtime/factory.rs b/herdr-core/src/runtime/factory.rs index ee39c13a9c..a4aa62e019 100644 --- a/herdr-core/src/runtime/factory.rs +++ b/herdr-core/src/runtime/factory.rs @@ -804,6 +804,7 @@ mod tests { }, }, ended: false, + forked: false, } } diff --git a/herdr-core/src/runtime/tests/agent_sleep.rs b/herdr-core/src/runtime/tests/agent_sleep.rs index ed74814e21..ece5805b57 100644 --- a/herdr-core/src/runtime/tests/agent_sleep.rs +++ b/herdr-core/src/runtime/tests/agent_sleep.rs @@ -1440,6 +1440,7 @@ impl SleepingChild { project: None, actor: runtime.delivery_observations[pane].actor.clone(), ended: false, + forked: false, }); } ledger.next_id = 3; diff --git a/herdr-core/src/runtime/tests/devices.rs b/herdr-core/src/runtime/tests/devices.rs index c0d7a5f8a8..3f19d44364 100644 --- a/herdr-core/src/runtime/tests/devices.rs +++ b/herdr-core/src/runtime/tests/devices.rs @@ -142,6 +142,7 @@ fn removing_devices_retires_only_their_pane_reads_and_rejects_late_publications( project: None, actor: child.clone(), ended: false, + forked: false, }); ledger.next_id += 1; crate::delivery::watch::start(&mut ledger, &parent, &child, 1).unwrap(); diff --git a/herdr-core/src/runtime/tests/remote_spawn.rs b/herdr-core/src/runtime/tests/remote_spawn.rs index 4e2d416f17..2bf1ffb0cd 100644 --- a/herdr-core/src/runtime/tests/remote_spawn.rs +++ b/herdr-core/src/runtime/tests/remote_spawn.rs @@ -229,6 +229,7 @@ fn spawner() -> Spawner { project: None, actor: actor.clone(), ended: false, + forked: false, }, check: false, }, diff --git a/herdr-core/src/session_sync/coordinator_fence_tests.rs b/herdr-core/src/session_sync/coordinator_fence_tests.rs index 805b06792f..725ec6dc19 100644 --- a/herdr-core/src/session_sync/coordinator_fence_tests.rs +++ b/herdr-core/src/session_sync/coordinator_fence_tests.rs @@ -207,6 +207,7 @@ impl Fixture { project: None, actor, ended: false, + forked: false, }); } ledger.next_id = 4; diff --git a/herdr-core/src/session_sync/tests.rs b/herdr-core/src/session_sync/tests.rs index 9116f401c9..8a137c39fe 100644 --- a/herdr-core/src/session_sync/tests.rs +++ b/herdr-core/src/session_sync/tests.rs @@ -2373,6 +2373,7 @@ fn registrations_end_only_on_a_fresh_snapshot_never_during_the_resync() { session: crate::wire::session_digest(&format!("{id}-native")), }, ended: false, + forked: false, }; let ledger = crate::delivery::ledger::Ledger { next_id: 4, diff --git a/herdr-core/src/sidebar.rs b/herdr-core/src/sidebar.rs index 915a82d24d..1d732f5e2f 100644 --- a/herdr-core/src/sidebar.rs +++ b/herdr-core/src/sidebar.rs @@ -639,6 +639,12 @@ fn project_agent(agent: SessionAgentPayload) -> Result [caption(`${id}-path-${index}`, name, '$--muted-foreground'), caption(`${id}-sep-${index}`, '›', '$--muted-foreground')]), caption(`${id}-mark`, mark, tone, {mono:true,weight:'600'}), provider(`${id}-provider`, kind), caption(`${id}-title`, title, '$--foreground'), + ...(forked ? [icon(`${id}-fork`, 'git-fork', {size:12,fill:'$--subtle-foreground'})] : []), ...(pr ? [prChip(`${id}-pr`, pr)] : []), ...(children ? [themedXref(`${id}-tree`, 'ath-tree-button', 'Tree button', {}, {'ath-tb-n': {content: String(children)}})] : []), frame(`${id}-sp`, 'Spacer', {width:'fill_container',height:1}, []), @@ -156,6 +157,7 @@ export function sessionScreens(tokens, {frame, text, icon, themedXref, screenBut labeled('root','Root pane, a descendant raised: band with 외 1건 (B4, B6)',[pane(`${id}-root`,{mark:'!',tone:'$--warning',provider:'claude',title:'hide 에이전트 지원 PR 묶음 머지 조율',pr:{number:812,state:'mergeable'},children:8,band:{verb:'승인',what:'e2e 테스트 돌리던 중',who:['codex','테스트 작성'],age:'12m',more:1},terminal:'› 에이전트 지원 PR 다섯 개의 머지 순서를 맞추는 중'})]), labeled('child','Child pane: path back to the root, its own PR and its children after the title (B20, B21)',[pane(`${id}-child`,{path:[root],title:'P8 읽기 전용 준비',pr:{number:811,state:'failed'},children:2})]), labeled('grand','Grandchild pane: two ancestors, no PR and no children (B20)',[pane(`${id}-grand`,{path:[root,'P8 읽기 전용 준비'],mark:'!',tone:'$--warning',title:'테스트 작성',terminal:'Allow bash: pnpm --dir web e2e ? (y/n)'})]), + labeled('fork','Forked pane: the fork mark after the title, whose tooltip says which pane it was forked from (issue 916)',[pane(`${id}-fork`,{path:[root],provider:'claude',title:'P8 읽기 전용 준비',forked:true})]), labeled('two','Two own PRs: PR 2 ×1 (B22)',[pane(`${id}-two`,{path:[root],mark:'✓',tone:'$--success',provider:'claude',title:'P6 OpenCode 세션 리더',pr:{number:811,state:'failed',more:1}})]), labeled('bands','Band per cause (B3)',bands.map(([key,band])=>pane(`${id}-band-${key}`,{path:[root],title:'P8 읽기 전용 준비',band}))), caption(`${id}-rule`,'승인은 label 줄이 없으면 "권한 요청에서 멈춤". 답변의 대기는 부모가 못 받은 시간. 초안은 초안이 걸린 부모를 연다. 띠는 PTY 크기를 바꾸지 않는다.'), diff --git a/web/e2e/agent-fork.spec.ts b/web/e2e/agent-fork.spec.ts new file mode 100644 index 0000000000..bd60f83535 --- /dev/null +++ b/web/e2e/agent-fork.spec.ts @@ -0,0 +1,81 @@ +// Fork agent from the pane menu on an isolated pinned Herdr and hided (issue +// 916): the item is offered on an agent pane whose conversation Herdr +// reported and starts the same conversation again as a new session in a pane +// of its own, which then wears the fork mark. The disabled item of an agent with no conversation yet is the +// pane menu unit test's and the core's. + +import { expect, test } from "@playwright/test"; +import { claudeProjects, setFixtureSession, startHerdr, writeFixtureTranscript } from "./herdr-fixture"; +import { startHided, type Daemon } from "./hided-fixture"; +import { countSent, screenshot } from "./wire"; + +test.describe.configure({ timeout: 150_000 }); + +const SESSION = "11111111-2222-3333-4444-555555555555"; +const FORKED_SESSION = "66666666-7777-8888-9999-000000000000"; + +type Listed = { result: { agents: { pane_id: string; name?: string | null; agent: string }[] } }; +type ProcessInfo = { result: { process_info: { foreground_processes: { argv?: string[] | null }[] } } }; + +test("Fork agent from the pane menu starts the pane's conversation again in a new pane", async ({ page }) => { + await page.setViewportSize({ width: 1440, height: 900 }); + const herdr = await startHerdr(); + let daemon: Daemon | null = null; + try { + const [, forker] = herdr.panes; + // The official Claude integration's report: the conversation id, under + // Herdr's own source. + writeFixtureTranscript(claudeProjects(herdr), SESSION, { task: "Agent two" }); + setFixtureSession(herdr, forker, SESSION); + const agentPanes = () => (herdr.run(["agent", "list"]) as Listed).result.agents.map((agent) => agent.pane_id); + + daemon = await startHided(herdr, "agent-fork"); + const last = new Map>(); + countSent(page, last); + await page.goto(`${daemon.origin}/#token=${daemon.token}`); + await page.locator("[data-checkout]").first().click(); + await expect(page.locator(`[data-pane-view="${forker}"]`)).toBeVisible({ timeout: 20_000 }); + const before = agentPanes(); + + // Fork agent is offered on an agent pane that reported its conversation and + // sends one event naming the pane. + await page.locator(`[data-pane-menu="${forker}"]`).click(); + const item = page.locator('[data-menu-item="fork_agent"]'); + await expect(item).toBeEnabled({ timeout: 20_000 }); + await screenshot(page, "agent-fork-menu"); + await item.click(); + await expect.poll(() => last.get("fork_pane")?.pane_id).toBe(forker); + + // The new execution is a pane of its own that resumes the conversation as + // a new session. + let forked = ""; + await expect.poll(() => { + forked = agentPanes().find((pane) => !before.includes(pane)) ?? ""; + return forked; + }, { timeout: 60_000 }).not.toBe(""); + // The official Claude integration reports the new execution's own + // conversation id; the fork waits for it to register the lineage. + setFixtureSession(herdr, forked, FORKED_SESSION); + await expect.poll( + () => (herdr.run(["pane", "process-info", "--pane", forked]) as ProcessInfo).result.process_info.foreground_processes.map((process) => process.argv?.join(" ")), + { timeout: 30_000 }, + ).toContain(`claude --resume ${SESSION} --fork-session`); + + // The forked pane says so, and names its source; the source does not. + // A fork is the source's descendant, so its sidebar row sits under the + // source's folded children. + const row = page.locator(`nav[data-sidebar] [data-pane="${forked}"]`); + const fold = page.getByRole("button", { name: "Show the children of Agent two" }); + await expect(row.or(fold)).toBeVisible({ timeout: 30_000 }); + if (await fold.isVisible()) await fold.click(); + await row.click(); + const mark = page.locator(`[data-pane-view="${forked}"] [data-pane-fork]`); + await expect(mark).toHaveAttribute("data-pane-fork", forker, { timeout: 30_000 }); + await expect(mark).toHaveAccessibleName("Forked from Agent two"); + await expect(page.locator(`[data-pane-view="${forker}"] [data-pane-fork]`)).toHaveCount(0); + await screenshot(page, "agent-fork-forked"); + } finally { + daemon?.stop(); + herdr.stop(); + } +}); diff --git a/web/src/PaneHeaderBand.tsx b/web/src/PaneHeaderBand.tsx index f7dcec9ca3..9cb118296c 100644 --- a/web/src/PaneHeaderBand.tsx +++ b/web/src/PaneHeaderBand.tsx @@ -1,4 +1,4 @@ -import { ChevronDownIcon, CircleAlertIcon, GitPullRequestIcon, MoonIcon } from "lucide-react"; +import { ChevronDownIcon, CircleAlertIcon, GitForkIcon, GitPullRequestIcon, MoonIcon } from "lucide-react"; import type { TFunction } from "i18next"; import type { Actions } from "./actions"; import { AgentMark } from "./AgentMark"; @@ -11,7 +11,7 @@ import { Hint } from "./components/ui/tooltip"; import { useInterfaceTranslation } from "./i18n/client"; import type { MessageKey } from "./i18n/catalogs"; import { cn } from "./lib/utils"; -import type { PaneHeader, SnapshotRest, AgentRow } from "./snapshot"; +import type { PaneHeader, PaneRow, SnapshotRest, AgentRow } from "./snapshot"; import { useShellStore } from "./store"; import { useUiStore } from "./ui"; import { relationState } from "./lineage"; @@ -29,6 +29,26 @@ const LABELS: Record = { const TONES = { muted: "bg-secondary text-muted-foreground", warning: "bg-warning/10 text-warning", error: "bg-destructive/10 text-destructive", success: "bg-success/10 text-success", pr: "bg-pr-mergeable/10 text-pr-mergeable" }; const ACTION_TONES = { muted: "bg-secondary text-secondary-foreground", warning: "bg-warning text-status-foreground", error: "bg-destructive text-destructive-foreground", success: "bg-success text-status-foreground", pr: "bg-pr-mergeable text-status-foreground" }; +/** + * Marks the pane Fork agent made (issue 916): a quiet icon after the title whose + * name says which pane it was forked from, or that the source is no longer on + * screen. Only the core's fork fact draws it, never a name's shape. + */ +export function PaneForkMark({ pane }: { pane: PaneRow }) { + const { t } = useInterfaceTranslation(); + const source = pane.fork?.forked_from_pane_id; + if (!source) return null; + const name = pane.lineage_path?.find((step) => step.pane_id === source)?.label; + const label = name ? t("panes.fork.forkedFrom", { name }) : t("panes.fork.forked"); + return ( + + + + + ); +} + export function PaneHeaderBand({ paneId, header, actions }: { paneId: string; header: PaneHeader | undefined; actions: Actions }) { const { t } = useInterfaceTranslation(); const relation = useUiStore((state) => state.relation); diff --git a/web/src/PaneRelations.tsx b/web/src/PaneRelations.tsx index 5f9b51e7ce..d907031f69 100644 --- a/web/src/PaneRelations.tsx +++ b/web/src/PaneRelations.tsx @@ -108,6 +108,7 @@ export function RelationStatus({ actions, visiblePaneIds }: { actions: Actions; type PaneMenuId = | `open:${string}` | "sleep_agent" + | "fork_agent" | "copy_name" | "copy_pane_id" | "close_pane" @@ -133,15 +134,26 @@ export function paneMenuItems(pane: PaneRow, title: string): MenuEntry[] = []; if (pane.sleep_action) { - items.push({ + agentActions.push({ id: "sleep_agent", label: translate("panes.menu.sleep"), unavailable: pane.sleep_action.available ? null : (pane.sleep_action.reason ?? translate("panes.menu.sleepUnavailable")), - separated: items.length > 0, }); } - items.push({ id: "copy_name", label: translate("panes.menu.copyName"), unavailable: null, separated: items.length > 0 && !pane.sleep_action }); + // Fork agent (issue 916): offered on an agent pane the core can fork, and drawn + // disabled with the core's reason on an agent that can fork but has not reported its + // conversation yet; an agent with no fork command, and a shell, get no item. + if (pane.fork?.available || pane.fork?.reason) { + agentActions.push({ + id: "fork_agent", + label: translate("panes.menu.fork"), + unavailable: pane.fork.available ? null : (pane.fork.reason ?? translate("panes.menu.forkUnavailable")), + }); + } + if (agentActions.length > 0) items.push(...agentActions.map((item, index) => (index === 0 ? { ...item, separated: items.length > 0 } : item))); + items.push({ id: "copy_name", label: translate("panes.menu.copyName"), unavailable: null, separated: items.length > 0 && agentActions.length === 0 }); items.push({ id: "copy_pane_id", label: translate("panes.menu.copyPaneId"), unavailable: null }); items.push({ id: "close_pane", label: translate("panes.close", { name: title }), unavailable: null, separated: true }); return items; @@ -199,6 +211,8 @@ export function usePaneMenu(pane: PaneRow, title: string, actions: Actions) { return actions.closePane(pane.id); case "sleep_agent": return actions.sleepAgent(pane.id); + case "fork_agent": + return actions.forkPane(pane.id); case "copy": void copySelection(pane.id, "pane menu"); return; diff --git a/web/src/PaneView.tsx b/web/src/PaneView.tsx index c81ff87a55..40720320c6 100644 --- a/web/src/PaneView.tsx +++ b/web/src/PaneView.tsx @@ -7,7 +7,7 @@ import { AgentMark } from "./AgentMark"; import { StatusMark } from "./components/status-mark"; import { Button } from "./components/ui/button"; import { Hint } from "./components/ui/tooltip"; -import { PaneHeaderBand, PanePrChip, PaneTreeButton } from "./PaneHeaderBand"; +import { PaneForkMark, PaneHeaderBand, PanePrChip, PaneTreeButton } from "./PaneHeaderBand"; import { PaneConnectionChip } from "./PaneConnection"; import { AncestorPath, usePaneMenu, type TerminalMenuContext } from "./PaneRelations"; import { chordLabel, commandLabel } from "./shortcutLabels"; @@ -303,6 +303,7 @@ export const PaneView = memo(function PaneView({ {title} + {agentKind ? : null} {agentKind ? : null} {agentKind ? : null} diff --git a/web/src/actions.ts b/web/src/actions.ts index 277b89760f..bc054bd7b1 100644 --- a/web/src/actions.ts +++ b/web/src/actions.ts @@ -933,6 +933,11 @@ export function createActions(send: DispatchFn) { dispatch({ schema_version: 2, kind: "agent_sleep", payload: { pane_id: paneId } }); }, + /** Fork agent from the pane menu: a new execution of this agent's conversation in its own tab. */ + forkPane(paneId: string) { + dispatch({ schema_version: 2, kind: "fork_pane", payload: { pane_id: paneId } }); + }, + /** Wake agent and Retry resume the conversation; Start new session is `fresh` (B12, B14). */ wakeAgent(paneId: string, fresh = false) { dispatch({ schema_version: 2, kind: "agent_wake", payload: { pane_id: paneId, fresh } }); diff --git a/web/src/gallery/SessionWorkflowScene.tsx b/web/src/gallery/SessionWorkflowScene.tsx index bb866e8aab..1ba7c7accd 100644 --- a/web/src/gallery/SessionWorkflowScene.tsx +++ b/web/src/gallery/SessionWorkflowScene.tsx @@ -102,5 +102,5 @@ export function SessionWorkflowScene({ scene: kind, theme, content, scale }: Sce document.documentElement.classList.toggle("light", theme === "light"); document.documentElement.style.setProperty("--interface-scale", String(scale)); }, [fixture, theme, scale]); - return {kind === "session-panel" ?
:
{BANDS.map(([id]) =>
)}
}
; + return {kind === "session-panel" ?
:
{BANDS.map(([id]) =>
)}
}
; } diff --git a/web/src/i18n/resources/panes.ts b/web/src/i18n/resources/panes.ts index 7f050ab725..c8b76c0268 100644 --- a/web/src/i18n/resources/panes.ts +++ b/web/src/i18n/resources/panes.ts @@ -42,6 +42,10 @@ export const panesEnglish = { "panes.relation.child": "Open child: {{name}}", "panes.menu.sleep": "Sleep agent", "panes.menu.sleepUnavailable": "This agent cannot sleep now", + "panes.menu.fork": "Fork agent", + "panes.menu.forkUnavailable": "This agent cannot be forked now", + "panes.fork.forkedFrom": "Forked from {{name}}", + "panes.fork.forked": "Forked from another pane", "panes.menu.copyName": "Copy pane name", "panes.menu.copyPaneId": "Copy pane ID", "panes.menu.paste": "Paste", @@ -233,6 +237,10 @@ const ko = { "panes.relation.child": "자식 열기: {{name}}", "panes.menu.sleep": "에이전트 휴면 전환", "panes.menu.sleepUnavailable": "지금은 이 에이전트를 휴면으로 전환할 수 없습니다", + "panes.menu.fork": "에이전트 포크", + "panes.menu.forkUnavailable": "지금은 이 에이전트를 포크할 수 없습니다", + "panes.fork.forkedFrom": "{{name}}에서 포크됨", + "panes.fork.forked": "다른 pane에서 포크됨", "panes.menu.copyName": "pane 이름 복사", "panes.menu.copyPaneId": "pane ID 복사", "panes.menu.paste": "붙여넣기", @@ -424,6 +432,10 @@ const zhCN = { "panes.relation.child": "打开子智能体:{{name}}", "panes.menu.sleep": "让智能体休眠", "panes.menu.sleepUnavailable": "此智能体目前无法休眠", + "panes.menu.fork": "分叉智能体", + "panes.menu.forkUnavailable": "此智能体目前无法分叉", + "panes.fork.forkedFrom": "从 {{name}} 分叉", + "panes.fork.forked": "从另一个窗格分叉", "panes.menu.copyName": "复制窗格名称", "panes.menu.copyPaneId": "复制窗格 ID", "panes.menu.paste": "粘贴", @@ -615,6 +627,10 @@ const ja = { "panes.relation.child": "子を開く:{{name}}", "panes.menu.sleep": "エージェントを休眠させる", "panes.menu.sleepUnavailable": "このエージェントは今は休眠できません", + "panes.menu.fork": "エージェントをフォーク", + "panes.menu.forkUnavailable": "このエージェントは今はフォークできません", + "panes.fork.forkedFrom": "{{name}} からフォーク", + "panes.fork.forked": "別のペインからフォーク", "panes.menu.copyName": "ペイン名をコピー", "panes.menu.copyPaneId": "ペインIDをコピー", "panes.menu.paste": "貼り付け", diff --git a/web/src/paneMenu.test.ts b/web/src/paneMenu.test.ts index e6cc215dbf..36925e0d68 100644 --- a/web/src/paneMenu.test.ts +++ b/web/src/paneMenu.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { terminalMenuItems, type TerminalMenuContext } from "./PaneRelations"; +import { paneMenuItems, terminalMenuItems, type TerminalMenuContext } from "./PaneRelations"; import type { PaneRow } from "./snapshot"; const pane = { id: "w1:p1", children: null, lineage_path: [] } as unknown as PaneRow; @@ -25,3 +25,29 @@ describe("a right-click in a terminal", () => { expect(zoom({ paneCount: 1 })).toMatchObject({ label: "Zoom pane", unavailable: "This pane is the only one in its tab" }); }); }); + +describe("the pane menu's Fork agent item", () => { + const forkItem = (fork?: PaneRow["fork"], sleep_action?: PaneRow["sleep_action"]) => + paneMenuItems({ id: "w1:p1", children: null, lineage_path: [], fork, sleep_action } as unknown as PaneRow, "reviewer").find((item) => item.id === "fork_agent"); + + it("is offered on a pane the core can fork", () => { + expect(forkItem({ available: true })).toMatchObject({ label: "Fork agent", unavailable: null }); + }); + + it("is drawn disabled with the core's reason on an agent that cannot fork yet", () => { + expect(forkItem({ available: false, reason: "This agent has not reported its conversation yet" })).toMatchObject({ + unavailable: "This agent has not reported its conversation yet", + }); + }); + + it("is absent on a shell and on an agent with no fork command", () => { + expect(forkItem({ available: false, reason: null })).toBeUndefined(); + expect(forkItem()).toBeUndefined(); + }); + + it("sits with Sleep agent, apart from the copy items", () => { + const items = paneMenuItems({ id: "w1:p1", children: null, lineage_path: [], fork: { available: true }, sleep_action: { available: true } } as unknown as PaneRow, "reviewer"); + expect(items.map((item) => item.id)).toEqual(["sleep_agent", "fork_agent", "copy_name", "copy_pane_id", "close_pane"]); + expect(items.filter((item) => item.separated).map((item) => item.id)).toEqual(["close_pane"]); + }); +}); diff --git a/web/src/snapshot.ts b/web/src/snapshot.ts index 895ea4b1ec..7597cb8ac8 100644 --- a/web/src/snapshot.ts +++ b/web/src/snapshot.ts @@ -197,6 +197,13 @@ export type AgentSleep = { progress?: string | null; }; +/** + * What the pane menu and header know about forking this pane (`PaneForkSnapshot`): + * `available` offers Fork agent, `reason` says why a forkable agent cannot fork yet, + * and `forked_from_pane_id` names the pane this one was forked from. + */ +export type PaneFork = { available: boolean; reason?: string | null; forked_from_pane_id?: string | null }; + /** The pane menu's Sleep agent item (`AgentSleepActionSnapshot`); absent where it does not apply. */ export type AgentSleepAction = { available: boolean; reason?: string | null }; @@ -499,6 +506,7 @@ export type PaneRow = { lineage_path?: LineageStep[]; sleep?: AgentSleep; sleep_action?: AgentSleepAction; + fork?: PaneFork; }; export type TabAgent = Pick & { state: Pick };