feat(coding-agent): add get_entries and get_tree RPC commands

Adds two read-only RPC commands exposing existing SessionManager reads:

- get_entries: all session entries in append order, with optional since-entry-id cursor (strictly-after semantics, error on unknown id), plus current leafId.
- get_tree: getTree() roots plus current leafId.

Since sessions are append-only trees with stable entry ids, an entry id is a durable cursor: external orchestrators can use these commands to catch up after a restart without losing pre-compaction history, and can observe branch structure (/tree jumps, abandoned branches) that get_messages hides.
This commit is contained in:
Anton Geraschenko
2026-06-11 15:59:27 -07:00
parent 1d48616328
commit 7ba1b6bfef
6 changed files with 167 additions and 0 deletions
@@ -606,6 +606,24 @@ export async function runRpcMode(runtimeHost: AgentSessionRuntime): Promise<neve
return success(id, "get_fork_messages", { messages });
}
case "get_entries": {
const sessionManager = session.sessionManager;
let entries = sessionManager.getEntries();
if (command.since !== undefined) {
const sinceIndex = entries.findIndex((e) => e.id === command.since);
if (sinceIndex === -1) {
return error(id, "get_entries", `Entry not found: ${command.since}`);
}
entries = entries.slice(sinceIndex + 1);
}
return success(id, "get_entries", { entries, leafId: sessionManager.getLeafId() });
}
case "get_tree": {
const sessionManager = session.sessionManager;
return success(id, "get_tree", { tree: sessionManager.getTree(), leafId: sessionManager.getLeafId() });
}
case "get_last_assistant_text": {
const text = session.getLastAssistantText();
return success(id, "get_last_assistant_text", { text });