Merge pull request #6078 from geraschenko/rpc-get-entries-tree

feat(coding-agent): add get_entries and get_tree RPC commands
This commit is contained in:
Mario Zechner
2026-06-28 17:46:26 +02:00
committed by GitHub
6 changed files with 167 additions and 0 deletions
@@ -10,6 +10,7 @@ import type { ImageContent } from "@earendil-works/pi-ai";
import type { SessionStats } from "../../core/agent-session.ts";
import type { BashResult } from "../../core/bash-executor.ts";
import type { CompactionResult } from "../../core/compaction/index.ts";
import type { SessionEntry, SessionTreeNode } from "../../core/session-manager.ts";
import { attachJsonlLineReader, serializeJsonLine } from "./jsonl.ts";
import type { RpcCommand, RpcResponse, RpcSessionState, RpcSlashCommand } from "./rpc-types.ts";
@@ -388,6 +389,22 @@ export class RpcClient {
return this.getData<{ messages: Array<{ entryId: string; text: string }> }>(response).messages;
}
/**
* Get session entries in append order, optionally only those after the `since` entry id.
*/
async getEntries(since?: string): Promise<{ entries: SessionEntry[]; leafId: string | null }> {
const response = await this.send({ type: "get_entries", since });
return this.getData<{ entries: SessionEntry[]; leafId: string | null }>(response);
}
/**
* Get the session entry tree.
*/
async getTree(): Promise<{ tree: SessionTreeNode[]; leafId: string | null }> {
const response = await this.send({ type: "get_tree" });
return this.getData<{ tree: SessionTreeNode[]; leafId: string | null }>(response);
}
/**
* Get text of last assistant message.
*/
@@ -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 });
@@ -10,6 +10,7 @@ import type { ImageContent, Model } from "@earendil-works/pi-ai";
import type { SessionStats } from "../../core/agent-session.ts";
import type { BashResult } from "../../core/bash-executor.ts";
import type { CompactionResult } from "../../core/compaction/index.ts";
import type { SessionEntry, SessionTreeNode } from "../../core/session-manager.ts";
import type { SourceInfo } from "../../core/source-info.ts";
// ============================================================================
@@ -59,6 +60,8 @@ export type RpcCommand =
| { id?: string; type: "fork"; entryId: string }
| { id?: string; type: "clone" }
| { id?: string; type: "get_fork_messages" }
| { id?: string; type: "get_entries"; since?: string }
| { id?: string; type: "get_tree" }
| { id?: string; type: "get_last_assistant_text" }
| { id?: string; type: "set_session_name"; name: string }
@@ -181,6 +184,20 @@ export type RpcResponse =
success: true;
data: { messages: Array<{ entryId: string; text: string }> };
}
| {
id?: string;
type: "response";
command: "get_entries";
success: true;
data: { entries: SessionEntry[]; leafId: string | null };
}
| {
id?: string;
type: "response";
command: "get_tree";
success: true;
data: { tree: SessionTreeNode[]; leafId: string | null };
}
| {
id?: string;
type: "response";