Skip to content

armgit / Wake

Public Imported from GitHub
0

All your AI agent sessions in one place — browse, search, resume. Rust + GPUI.

Rust

feat(mcp): read subagent transcripts with wake_get_session and wake-cli show

Corey Chiu571e21ba93b4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index caff97e..5c70942 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
- Fix: ⌘K / Ctrl+K results show the `@host` badge for sessions mirrored from a remote host
- Fix: Insights no longer counts a session twice when it is mirrored from more than one host
- Fix: Settings → Data includes the remote mirrors in the storage size
+- New: `wake_get_session` and `wake-cli show` can read a subagent transcript — the main transcript now lists their ids; pass one as `subagent` / `--subagent`
- Update: search favours recently active sessions a little — an equally good match from last week now outranks one from last year, in ⌘K / Ctrl+K, `wake_search` and `wake-cli search`
- Fix: an agent's own Wake lookups (the `wake_*` tools, `wake-cli` commands) no longer show up as search hits in its session
- Update: search now matches session titles too, in ⌘K / Ctrl+K, `wake_search` and `wake-cli search` — title hits come first and open the session at its start
diff --git a/crates/wake-core/src/cli.rs b/crates/wake-core/src/cli.rs
index 0ce3d8a..be92e79 100644
--- a/crates/wake-core/src/cli.rs
+++ b/crates/wake-core/src/cli.rs
@@ -189,6 +189,13 @@ const F_THINKING: FlagSpec = FlagSpec::new(
"",
"include the assistant's thinking where the agent recorded it",
);
+const F_SUBAGENT: FlagSpec = FlagSpec::new(
+ "--subagent",
+ "subagent",
+ Arity::Value,
+ "ID",
+ "read this subagent transcript instead of the main one (ids are listed at the end of the main transcript)",
+);
const SEARCH_FLAGS: &[FlagSpec] = &[F_PROJECT, F_AGENT, F_SINCE, F_LIMIT];
const SESSIONS_FLAGS: &[FlagSpec] = &[F_PROJECT, F_AGENT, F_SINCE, F_LIMIT, F_STARRED];
@@ -199,6 +206,7 @@ const SHOW_FLAGS: &[FlagSpec] = &[
F_MESSAGE_CHARS,
F_TOOLS,
F_THINKING,
+ F_SUBAGENT,
];
const PROJECTS_FLAGS: &[FlagSpec] = &[F_SINCE, F_LIMIT];
diff --git a/crates/wake-core/src/mcp/tools.rs b/crates/wake-core/src/mcp/tools.rs
index 8ed6d7e..fc9e4dd 100644
--- a/crates/wake-core/src/mcp/tools.rs
+++ b/crates/wake-core/src/mcp/tools.rs
@@ -152,7 +152,7 @@ pub fn definitions() -> Vec<Value> {
json!({
"name": GET_SESSION,
"title": "Read a session transcript",
- "description": "Read one session's transcript, parsed live from the agent's own files, as compact Markdown: user and assistant messages with `[seq N]` markers, tool calls folded to one line each, injected context omitted. Use it after wake_search or wake_list_sessions to see what actually happened — the reasoning, the decisions and the exact steps of an earlier session. Paginated: when the reply ends with a `from_seq` hint, call again with it to continue. Accepts a session key or a `wake://session/<key>#<seq>` reference (the seq becomes the starting point).",
+ "description": "Read one session's transcript, parsed live from the agent's own files, as compact Markdown: user and assistant messages with `[seq N]` markers, tool calls folded to one line each, injected context omitted. Use it after wake_search or wake_list_sessions to see what actually happened — the reasoning, the decisions and the exact steps of an earlier session. Paginated: when the reply ends with a `from_seq` hint, call again with it to continue. Accepts a session key or a `wake://session/<key>#<seq>` reference (the seq becomes the starting point). Subagent transcripts (Claude Code sidechains, Cursor subagents) are listed at the end of the main transcript; pass one's id as `subagent` to read it.",
"inputSchema": {
"type": "object",
"properties": {
@@ -163,6 +163,7 @@ pub fn definitions() -> Vec<Value> {
"max_message_chars": { "type": "integer", "minimum": 100, "maximum": 50000, "default": 4000, "description": "Longer messages are truncated to this many characters." },
"include_tools": { "type": "boolean", "default": false, "description": "Include tool-call inputs and outputs (verbose)." },
"include_thinking": { "type": "boolean", "default": false, "description": "Include the assistant's thinking/reasoning text where the agent recorded it." },
+ "subagent": { "type": "string", "description": "Read this subagent transcript instead of the session's main transcript. The main transcript lists the ids at its end; paging works the same way." },
},
"required": ["key"],
},
@@ -717,6 +718,39 @@ fn find_session(store: &Store, key: &str) -> Result<Result<SessionMeta, String>,
})
}
+/// 主线页脚最多列多少个子代理转录;再多就 "… and N more"(Task 开得多的会话有上百个)
+const MAX_SUBAGENTS_LISTED: usize = 30;
+
+/// `agent-a1b2 — Explore: find the watcher code`;没有边车信息时只有 id
+fn subagent_label(sc: &SidechainInfo) -> String {
+ let desc = [sc.agent_type.as_deref(), sc.description.as_deref()]
+ .into_iter()
+ .flatten()
+ .map(|s| one_line(s, 80))
+ .filter(|s| !s.is_empty())
+ .collect::<Vec<_>>()
+ .join(": ");
+ if desc.is_empty() {
+ sc.id.clone()
+ } else {
+ format!("{} — {desc}", sc.id)
+ }
+}
+
+fn subagent_lines(sidechains: &[SidechainInfo]) -> String {
+ let mut out = String::new();
+ for sc in sidechains.iter().take(MAX_SUBAGENTS_LISTED) {
+ out.push_str(&format!("- {}\n", subagent_label(sc)));
+ }
+ if sidechains.len() > MAX_SUBAGENTS_LISTED {
+ out.push_str(&format!(
+ "- … and {} more\n",
+ sidechains.len() - MAX_SUBAGENTS_LISTED
+ ));
+ }
+ out
+}
+
fn get_session(ctx: &ToolContext, args: &Value) -> ToolResult {
let raw_key = str_arg(args, "key")?
.map(str::trim)
@@ -732,6 +766,9 @@ fn get_session(ctx: &ToolContext, args: &Value) -> ToolResult {
include_tools: bool_arg(args, "include_tools", false)?,
include_thinking: bool_arg(args, "include_thinking", false)?,
};
+ let subagent = str_arg(args, "subagent")?
+ .map(str::trim)
+ .filter(|s| !s.is_empty());
let meta = match find_session(ctx.store, &key)? {
Ok(m) => m,
Err(text) => return Err(ToolError::Failed(text)),
@@ -750,13 +787,54 @@ fn get_session(ctx: &ToolContext, args: &Value) -> ToolResult {
))
})?;
let live = &transcript.meta;
- let total_visible = transcript
- .mainline
+ // 子代理转录按 id 现场解析,不进 TranscriptCache:子代理还在跑时它的文件独立于
+ // 主文件增长,拿主文件的戳当键会一直吐旧内容;文件通常远小于主线,一页一解析
+ let sidechain = match subagent {
+ None => None,
+ Some(id) => {
+ let info = transcript
+ .sidechains
+ .iter()
+ .find(|sc| sc.id == id)
+ .cloned()
+ .ok_or_else(|| {
+ ToolError::Failed(if transcript.sidechains.is_empty() {
+ format!("`{}` has no subagent transcripts.", meta.key)
+ } else {
+ format!(
+ "`{}` has no subagent transcript `{id}`. It has:\n{}",
+ meta.key,
+ subagent_lines(&transcript.sidechains)
+ )
+ })
+ })?;
+ let messages = adapter
+ .load_sidechain(&SessionFileRef::from_meta(&meta), id)
+ .map_err(|e| {
+ ToolError::Failed(format!(
+ "Could not read subagent transcript `{id}` of `{}`: {e:#}",
+ meta.key
+ ))
+ })?;
+ if messages.is_empty() {
+ return Err(ToolError::Failed(format!(
+ "Subagent transcript `{id}` of `{}` is empty or missing on disk.",
+ meta.key
+ )));
+ }
+ Some((info, messages))
+ }
+ };
+ let messages: &[TranscriptMessage] = match &sidechain {
+ Some((_, messages)) => messages,
+ None => &transcript.mainline,
+ };
+ let total_visible = messages
.iter()
.filter(|m| m.kind != MessageKind::Meta)
.count();
- let last_seq = transcript.mainline.last().map(|m| m.seq);
- let page = render_compact(&transcript.mainline, &opts);
+ let last_seq = messages.last().map(|m| m.seq);
+ let page = render_compact(messages, &opts);
let mut out = String::new();
let title = if live.title.is_empty() {
@@ -772,6 +850,9 @@ fn get_session(ctx: &ToolContext, args: &Value) -> ToolResult {
if !meta.host.is_empty() {
facts.push(format!("host: @{}", meta.host));
}
+ if let Some((info, _)) = &sidechain {
+ facts.push(format!("subagent: {}", subagent_label(info)));
+ }
if !live.project_path.is_empty() {
facts.push(format!(
"project: {}{}",
@@ -789,11 +870,26 @@ fn get_session(ctx: &ToolContext, args: &Value) -> ToolResult {
if let Some(src) = meta.source.as_deref().filter(|v| !v.is_empty()) {
facts.push(format!("via {src}"));
}
- facts.push(format!(
- "{} – {}",
- fmt_time(Some(live.created_at)),
- fmt_time(Some(live.updated_at))
- ));
+ // 时间范围:主线用会话的起止,子代理用它自己消息的首末时间(没有就不写)
+ let (start, end) = match &sidechain {
+ Some((_, messages)) => messages.iter().filter_map(|m| m.timestamp).fold(
+ (None, None),
+ |(lo, hi): (Option<i64>, Option<i64>), t| {
+ (
+ Some(lo.map_or(t, |lo| lo.min(t))),
+ Some(hi.map_or(t, |hi| hi.max(t))),
+ )
+ },
+ ),
+ None => (Some(live.created_at), Some(live.updated_at)),
+ };
+ if let (Some(start), Some(end)) = (start, end) {
+ facts.push(format!(
+ "{} – {}",
+ fmt_time(Some(start)),
+ fmt_time(Some(end))
+ ));
+ }
facts.push(format!(
"{total_visible} message{}",
plural(total_visible as i64)
@@ -814,7 +910,11 @@ fn get_session(ctx: &ToolContext, args: &Value) -> ToolResult {
out.push_str("—\n");
let (first, last) = page.seq_range.unwrap_or((from_seq, from_seq));
let mut summary = format!(
- "Showing seq {first}–{last}: {} message{}",
+ "Showing seq {first}–{last}{}: {} message{}",
+ sidechain
+ .as_ref()
+ .map(|(info, _)| format!(" of subagent `{}`", info.id))
+ .unwrap_or_default(),
page.rendered,
plural(page.rendered as i64)
);
@@ -825,20 +925,27 @@ fn get_session(ctx: &ToolContext, args: &Value) -> ToolResult {
plural(page.skipped_meta as i64)
));
}
- if !transcript.sidechains.is_empty() {
- summary.push_str(&format!(
- "; {} subagent transcript{} not included",
+ out.push_str(&summary);
+ out.push_str(".\n");
+ // 主线页脚列出子代理转录:它们不并进主线(各有自己的 seq),按 id 单独读
+ if sidechain.is_none() && !transcript.sidechains.is_empty() {
+ out.push_str(&format!(
+ "{} subagent transcript{} (pass an id as `subagent` to read one):\n{}",
transcript.sidechains.len(),
- plural(transcript.sidechains.len() as i64)
+ plural(transcript.sidechains.len() as i64),
+ subagent_lines(&transcript.sidechains)
));
}
- out.push_str(&summary);
- out.push_str(".\n");
- match page.next_seq {
- Some(next) => out.push_str(&format!(
+ match (page.next_seq, &sidechain) {
+ (Some(next), Some((info, _))) => out.push_str(&format!(
+ "More follows — call {GET_SESSION} again with subagent=\"{}\" and from_seq={next}.\n",
+ info.id
+ )),
+ (Some(next), None) => out.push_str(&format!(
"More follows — call {GET_SESSION} again with from_seq={next}.\n"
)),
- None => out.push_str("End of transcript.\n"),
+ (None, Some(_)) => out.push_str("End of subagent transcript.\n"),
+ (None, None) => out.push_str("End of transcript.\n"),
}
Ok(out)
}
diff --git a/crates/wake-core/tests/cli.rs b/crates/wake-core/tests/cli.rs
index cce3d5e..1a2504d 100644
--- a/crates/wake-core/tests/cli.rs
+++ b/crates/wake-core/tests/cli.rs
@@ -201,6 +201,18 @@ fn cases() -> Vec<(Vec<String>, &'static str, Value)> {
tools::GET_SESSION,
json!({ "key": reference }),
),
+ (
+ argv(&[
+ "show",
+ CLAUDE_KEY,
+ "--subagent",
+ "agent-fixture01",
+ "--messages",
+ "2",
+ ]),
+ tools::GET_SESSION,
+ json!({"key":CLAUDE_KEY,"subagent":"agent-fixture01","max_messages":2}),
+ ),
(
argv(&["projects", "--since", ALWAYS, "--limit", "10"]),
tools::LIST_PROJECTS,
diff --git a/crates/wake-core/tests/fixtures/claude/projects/-Users-tester-Github-wakefx/11111111-aaaa-bbbb-cccc-000000000001/subagents/agent-fixture01.jsonl b/crates/wake-core/tests/fixtures/claude/projects/-Users-tester-Github-wakefx/11111111-aaaa-bbbb-cccc-000000000001/subagents/agent-fixture01.jsonl
new file mode 100644
index 0000000..55f6cb6
--- /dev/null
+++ b/crates/wake-core/tests/fixtures/claude/projects/-Users-tester-Github-wakefx/11111111-aaaa-bbbb-cccc-000000000001/subagents/agent-fixture01.jsonl
@@ -0,0 +1,3 @@
+{"type":"user","uuid":"fx-sub-u0","parentUuid":null,"isSidechain":true,"cwd":"/Users/tester/Github/wakefx","sessionId":"11111111-aaaa-bbbb-cccc-000000000001","timestamp":"2026-08-08T09:02:30.000Z","message":{"role":"user","content":"Find where the QR scanner is wired up. Report file paths only."}}
+{"type":"assistant","uuid":"fx-sub-a1","parentUuid":"fx-sub-u0","isSidechain":true,"cwd":"/Users/tester/Github/wakefx","sessionId":"11111111-aaaa-bbbb-cccc-000000000001","timestamp":"2026-08-08T09:02:41.000Z","message":{"id":"msg_fx_sub_1","role":"assistant","model":"claude-opus-5","content":[{"type":"text","text":"Searching src/ for the scanner hook."}]}}
+{"type":"assistant","uuid":"fx-sub-a2","parentUuid":"fx-sub-a1","isSidechain":true,"cwd":"/Users/tester/Github/wakefx","sessionId":"11111111-aaaa-bbbb-cccc-000000000001","timestamp":"2026-08-08T09:02:55.000Z","message":{"id":"msg_fx_sub_2","role":"assistant","model":"claude-opus-5","content":[{"type":"text","text":"The scanner lives in src/qr/scanner.ts and is mounted from src/App.tsx."}]}}
diff --git a/crates/wake-core/tests/fixtures/claude/projects/-Users-tester-Github-wakefx/11111111-aaaa-bbbb-cccc-000000000001/subagents/agent-fixture01.meta.json b/crates/wake-core/tests/fixtures/claude/projects/-Users-tester-Github-wakefx/11111111-aaaa-bbbb-cccc-000000000001/subagents/agent-fixture01.meta.json
new file mode 100644
index 0000000..e3c2aae
--- /dev/null
+++ b/crates/wake-core/tests/fixtures/claude/projects/-Users-tester-Github-wakefx/11111111-aaaa-bbbb-cccc-000000000001/subagents/agent-fixture01.meta.json
@@ -0,0 +1 @@
+{"agentType":"Explore","description":"find the QR scanner code","toolUseId":"toolu_fixture01"}
diff --git a/crates/wake-core/tests/mcp_stdio.rs b/crates/wake-core/tests/mcp_stdio.rs
index f5a8903..1abf888 100644
--- a/crates/wake-core/tests/mcp_stdio.rs
+++ b/crates/wake-core/tests/mcp_stdio.rs
@@ -310,6 +310,43 @@ fn stdio_contract_end_to_end() {
"tool calls fold to one line by default"
);
+ // 4b. 子代理转录:主线页脚列出 id,按 id 读、同一套分页;未知 id 是给 LLM 看
+ // 的失败结果并附上有哪些
+ assert!(
+ plain_page.contains(
+ "1 subagent transcript (pass an id as `subagent` to read one):\n- agent-fixture01 — Explore: find the QR scanner code\n"
+ ),
+ "{plain_page}"
+ );
+ let (sub, is_err) = c.call(
+ "wake_get_session",
+ json!({ "key": CLAUDE_KEY, "subagent": "agent-fixture01", "max_messages": 1 }),
+ );
+ assert!(!is_err, "{sub}");
+ assert!(
+ sub.contains("subagent: agent-fixture01 — Explore: find the QR scanner code"),
+ "{sub}"
+ );
+ assert_eq!(seqs_in(&sub), vec![0]);
+ assert!(sub.contains("QR scanner is wired up"), "{sub}");
+ let next = next_seq_hint(&sub).expect("the fixture subagent has three messages");
+ assert!(
+ sub.contains(&format!("subagent=\"agent-fixture01\" and from_seq={next}")),
+ "{sub}"
+ );
+ let (rest, _) = c.call(
+ "wake_get_session",
+ json!({ "key": CLAUDE_KEY, "subagent": "agent-fixture01", "from_seq": next }),
+ );
+ assert!(rest.ends_with("End of subagent transcript.\n"), "{rest}");
+ assert!(rest.contains("src/qr/scanner.ts"), "{rest}");
+ let (bad, is_err) = c.call(
+ "wake_get_session",
+ json!({ "key": CLAUDE_KEY, "subagent": "agent-nope" }),
+ );
+ assert!(is_err);
+ assert!(bad.contains("- agent-fixture01"), "{bad}");
+
// 5. 项目匹配:cwd 在项目子目录里、没匹配上、项目清单
let (listed, is_err) = c.call(
"wake_list_sessions",
diff --git a/docs/cli.md b/docs/cli.md
index b0db049..5386552 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -82,6 +82,7 @@ One session's transcript, parsed live from the agent's own files, as compact Mar
| `--message-chars` | N | truncate each message, default 4000, range 100–50000 |
| `--tools` | — | include tool inputs and outputs (verbose) |
| `--thinking` | — | include the assistant's thinking where the agent recorded it |
+| `--subagent` | ID | read this subagent transcript instead of the main one; the main transcript lists the ids at its end |
`show` also accepts a bare native id (the one the agent's own `--resume` wants) and falls back to looking it up. When the same id exists on more than one host it lists the candidates instead of guessing.
@@ -91,6 +92,7 @@ Long transcripts are paginated: when the reply ends with a `from_seq` hint, run
wake-cli show 'claude-code:1b2c3d4e-…'
wake-cli show 'wake://session/claude-code:1b2c3d4e-…#42' --tools
wake-cli show 'codex:0195c2a1-…' --from 120 --messages 40
+wake-cli show 'claude-code:1b2c3d4e-…' --subagent agent-a1b2c3d4
```
### `projects`
diff --git a/docs/mcp.md b/docs/mcp.md
index c6c0d6f..386a51e 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -104,7 +104,7 @@ Everything above happens locally; Wake itself does not change and the other agen
### What it does not do
- No write tools: nothing can delete, star, rename or resume a session. Resuming stays in Wake.
-- Subagent transcripts that live inside a session (Claude Code sidechains, Cursor subagents) are not included in `wake_get_session`; their count is reported so the agent knows they exist. Subagent sessions that Wake tracks as separate sessions (Grok) are folded under their parent in `wake_list_sessions` but can be read by key.
+- Subagent transcripts that live inside a session (Claude Code sidechains, Cursor subagents) are not merged into the main transcript: `wake_get_session` lists their ids at the end and reads one when it is passed as `subagent`. Subagent sessions that Wake tracks as separate sessions (Grok) are folded under their parent in `wake_list_sessions` but can be read by key.
- Antigravity sessions are metadata only — their transcripts are encrypted on disk, so an agent gets the same preview card Wake shows.
- Archived Codex sessions appear in search results but not in `wake_list_sessions` or `wake_list_projects`.
@@ -177,6 +177,7 @@ One transcript as compact Markdown, parsed live from the agent's files.
| `max_message_chars` | integer 100–50000 | 4000 | budget per message, shared by its text, thinking and tool calls; longer content is truncated and marked |
| `include_tools` | boolean | false | include tool inputs and outputs (verbose) |
| `include_thinking` | boolean | false | include the assistant's recorded thinking |
+| `subagent` | string | | read this subagent transcript instead of the main one; the main transcript lists the ids at its end |
The reply starts with a header (title, key, agent, host, project and branch, model, time range, message count), then one block per message:
@@ -190,7 +191,7 @@ inotify queues overflow when …
- 🔧 Grep: need_rescan
```
-Tool calls are folded to one line each (name plus input preview) unless `include_tools` is set; at most 40 tool calls are listed per message, the rest are counted. Injected context (system reminders, IDE context) is skipped and counted. Compaction summaries are kept as quotes. Images are noted, not included. Subagent transcripts are not included; their count is reported.
+Tool calls are folded to one line each (name plus input preview) unless `include_tools` is set; at most 40 tool calls are listed per message, the rest are counted. Injected context (system reminders, IDE context) is skipped and counted. Compaction summaries are kept as quotes. Images are noted, not included. Subagent transcripts (Claude Code sidechains, Cursor subagents) are listed at the end of the main transcript with their ids; pass one as `subagent` to read it, with the same paging options.
The footer says which seqs were shown and either `End of transcript.` or a `from_seq=<n>` hint for the next page. Seq numbers are the same ones Wake's own search results and transcript view use.
diff --git a/skills/wake/SKILL.md b/skills/wake/SKILL.md
index fee0936..7f3a3e1 100644
--- a/skills/wake/SKILL.md
+++ b/skills/wake/SKILL.md
@@ -61,7 +61,9 @@ wake-cli show 'claude-code:1b2c3d4e-…'
```
Add `--tools` for tool inputs and outputs, `--thinking` for recorded reasoning. Both are
-verbose — start without them.
+verbose — start without them. Work done by subagents (Claude Code sidechains, Cursor
+subagents) is not in the main transcript; its ids are listed at the end of the output —
+read one with `--subagent ID`.
**Which projects have history**