diff --git a/docs/subsystems/gateway-sessions.md b/docs/subsystems/gateway-sessions.md index b5545d109..56f330133 100644 --- a/docs/subsystems/gateway-sessions.md +++ b/docs/subsystems/gateway-sessions.md @@ -664,7 +664,35 @@ establishes them, `parent_session` and `root_session`. A child whose root is not known keeps an empty `root_session`; Codex entries without explicit identity metadata, gateway-only entries and conflicting identities set `role` to `unknown` and do not acquire a guessed parent or root. These fields are omitted -for other agents. This is Codex-specific (#1591). +for other agents, except a Claude-format branch (below). This is Codex-specific +(#1591). + +Claude Code copies a conversation into a new session file when it forks one +(`--resume --fork-session`, the Agent SDK's `forkSession`, `/branch`): +every message again, under the same uuids, with the new session id; after a +compaction the copy starts at the compaction's summary +([`cc_copies.go`](../../internal/sessions/cc_copies.go), `ccFamily`). Files +are grouped by their first message and their compactions' summaries. A file +whose last message and first message another file of the group holds is a +copy: not listed, its id in `Copies`, counted in the stats only for what the +keeper doesn't hold (`ccRest`). A file that holds what came before the +other's start (the compaction the fork started after) is never that one's +copy. What is left of the group went on apart and is one conversation: the +head is the file that holds the others' first message as they don't hold +its, else the one a `/branch` names in `forkedFrom`, else the earliest, then +the lowest key. Each other one is a branch: listed with `role` `branch` and +`parent_session` the head's id, its transcript (`TranscriptOf`, Markdown +export) is the head's from its start up to the last message the two share, +then the branch's own lines (`branchTranscript`), and the stats count only +its own lines. A search reads the branch's own file. Neo (#feedback, after +v0.1.1809): a client that ran each task in a fork of a compacted session +showed a row per task, each opening on the summary and that one task, while +the session itself was hidden as a fork's copy. See +`TestClaudeForksAfterCompactAreBranches`, +`TestClaudeSlashBranchAfterCompactIsABranch`, +`TestClaudeBranchNamesItsSession` and +`TestClaudeCopyBeforeACompactionIsCounted`; the fixtures in +`testdata/claude-forks` are Claude Code 2.1.312's own files. A session whose agent keeps its subagents' conversations beside its own lists them in `subagents` on the sessions API (`/api/sessions`, `one`, `manage`; #2261, @@ -721,7 +749,9 @@ kind, set in under the subagent that started it, and a click shows its conversation (`sub=`). A Codex thread whose `parent_session` chain reaches a listed session is drawn, as a session with its own details, Resume and Delete, under its parent in the same fold; a loop of parents, a chain deeper -than eight or a parent not listed leaves it on top. The folder's count and +than eight or a parent not listed leaves it on top. A Claude branch is drawn +under its session the same way, and the fold names them apart ("2 +branches · 1 subagent"). The folder's count and checkbox cover the sessions under others. See `sessions-subagents.test.cjs`. Codex keeps the existing session-title precedence. Only when that leaves the diff --git a/internal/gui/assets/plugins/sessions/client.js b/internal/gui/assets/plugins/sessions/client.js index 7a474edc5..491a6fb03 100644 --- a/internal/gui/assets/plugins/sessions/client.js +++ b/internal/gui/assets/plugins/sessions/client.js @@ -691,7 +691,8 @@ magpie.plugin("sessions", (ctx) => { } // nest finds the sessions shown that are under another one shown: a - // Codex thread whose parent_session is, by a chain with no loop in it + // Codex thread, or a Claude branch, whose parent_session is, by a chain + // with no loop in it function nest(list) { const byId = new Map(list.map((s) => [s.id, s])); kidsOf = new Map(); @@ -938,18 +939,23 @@ magpie.plugin("sessions", (ctx) => { // subagentsBox is the fold under a session with its subagents: those // its agent started inside it, each opened to its conversation, and the - // Codex threads it started, drawn as sessions + // Codex threads it started, drawn as sessions; and the Claude sessions + // forked from it that went on (role "branch"), named apart function subagentsBox(s, kids, depth) { const box = el("div", "sm-subs"); const k = s.agent + "/" + s.id; const subs = subTree(s.subagents || []); - const n = kids.length + subs.length; + const branches = kids.filter((c) => c.role === "branch").length; + const n = kids.length + subs.length - branches; + const words = []; + if (branches) words.push(t(branches === 1 ? "{n} branch" : "{n} branches", { n: branches })); + if (n || !branches) words.push(t(n === 1 ? "{n} subagent" : "{n} subagents", { n })); const draw = () => { const open = subsOpen.has(k) || (!!query.trim() && kids.length > 0); const fold = el("button", "fold sm-subs-fold"); fold.type = "button"; fold.setAttribute("aria-expanded", String(open)); - fold.append(svg(CHEV_R, 10, 1.6), el("span", "", t(n === 1 ? "{n} subagent" : "{n} subagents", { n }))); + fold.append(svg(CHEV_R, 10, 1.6), el("span", "", words.join(" · "))); fold.onclick = (e) => { e.stopPropagation(); if (subsOpen.has(k)) subsOpen.delete(k); else subsOpen.add(k); diff --git a/internal/gui/assets/plugins/sessions/i18n.js b/internal/gui/assets/plugins/sessions/i18n.js index eb2c1a038..6f29e932a 100644 --- a/internal/gui/assets/plugins/sessions/i18n.js +++ b/internal/gui/assets/plugins/sessions/i18n.js @@ -7,6 +7,8 @@ magpie.strings({ "Delete all sessions": "删除全部会话", "{n} subagent": "{n} 个子代理", "{n} subagents": "{n} 个子代理", + "{n} branch": "{n} 个分支", + "{n} branches": "{n} 个分支", "Relocate project": "迁移项目会话", "New absolute project path": "新的项目绝对路径", "Preview relocation": "预览迁移", @@ -84,6 +86,8 @@ magpie.strings({ "Delete all sessions": "刪除全部會話", "{n} subagent": "{n} 個子代理", "{n} subagents": "{n} 個子代理", + "{n} branch": "{n} 個分支", + "{n} branches": "{n} 個分支", "Relocate project": "遷移專案會話", "New absolute project path": "新的專案絕對路徑", "Preview relocation": "預覽遷移", @@ -161,6 +165,8 @@ magpie.strings({ "Delete all sessions": "すべてのセッションを削除", "{n} subagent": "{n} 個のサブエージェント", "{n} subagents": "{n} 個のサブエージェント", + "{n} branch": "{n} 個のブランチ", + "{n} branches": "{n} 個のブランチ", "Relocate project": "プロジェクトを移動", "New absolute project path": "新しいプロジェクトの絶対パス", "Preview relocation": "移動をプレビュー", @@ -238,6 +244,8 @@ magpie.strings({ "Delete all sessions": "Alle Sitzungen löschen", "{n} subagent": "{n} Subagent", "{n} subagents": "{n} Subagenten", + "{n} branch": "{n} Zweig", + "{n} branches": "{n} Zweige", "Relocate project": "Projekt verschieben", "New absolute project path": "Neuer absoluter Projektpfad", "Preview relocation": "Verschieben prüfen", diff --git a/internal/gui/tests/sessions-subagents.test.cjs b/internal/gui/tests/sessions-subagents.test.cjs index 43b329952..a6b5575b6 100644 --- a/internal/gui/tests/sessions-subagents.test.cjs +++ b/internal/gui/tests/sessions-subagents.test.cjs @@ -9,6 +9,8 @@ // parent_session is listed is drawn under that session, a session of its // own still (its details open where it is), and only main sessions are on // top; a loop of parents, or a parent not listed, leaves a thread on top. +// A Claude session forked from another that went on (role "branch") sits +// under it the same way, its fold naming them branches. // No click moves the page, nothing has a left-border accent, no