From 3c8ab0280e7b6c51338c7d40aff947b1473337fb Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 9 Dec 2025 14:35:09 +0100 Subject: [PATCH] Add get_messages RPC command --- packages/coding-agent/src/modes/rpc/rpc-client.ts | 10 +++++++++- packages/coding-agent/src/modes/rpc/rpc-mode.ts | 8 ++++++++ packages/coding-agent/src/modes/rpc/rpc-types.ts | 10 ++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/coding-agent/src/modes/rpc/rpc-client.ts b/packages/coding-agent/src/modes/rpc/rpc-client.ts index b7c5991a..e269bea1 100644 --- a/packages/coding-agent/src/modes/rpc/rpc-client.ts +++ b/packages/coding-agent/src/modes/rpc/rpc-client.ts @@ -6,7 +6,7 @@ import { type ChildProcess, spawn } from "node:child_process"; import * as readline from "node:readline"; -import type { AgentEvent, Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core"; +import type { AgentEvent, AppMessage, Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core"; import type { CompactionResult, SessionStats } from "../../core/agent-session.js"; import type { BashResult } from "../../core/bash-executor.js"; import type { RpcCommand, RpcResponse, RpcSessionState } from "./rpc-types.js"; @@ -326,6 +326,14 @@ export class RpcClient { return this.getData<{ text: string | null }>(response).text; } + /** + * Get all messages in the session. + */ + async getMessages(): Promise { + const response = await this.send({ type: "get_messages" }); + return this.getData<{ messages: AppMessage[] }>(response).messages; + } + // ========================================================================= // Helpers // ========================================================================= diff --git a/packages/coding-agent/src/modes/rpc/rpc-mode.ts b/packages/coding-agent/src/modes/rpc/rpc-mode.ts index f85e4f43..ac63a836 100644 --- a/packages/coding-agent/src/modes/rpc/rpc-mode.ts +++ b/packages/coding-agent/src/modes/rpc/rpc-mode.ts @@ -227,6 +227,14 @@ export async function runRpcMode(session: AgentSession): Promise { return success(id, "get_last_assistant_text", { text }); } + // ================================================================= + // Messages + // ================================================================= + + case "get_messages": { + return success(id, "get_messages", { messages: session.messages }); + } + default: { const unknownCommand = command as { type: string }; return error(undefined, unknownCommand.type, `Unknown command: ${unknownCommand.type}`); diff --git a/packages/coding-agent/src/modes/rpc/rpc-types.ts b/packages/coding-agent/src/modes/rpc/rpc-types.ts index 9c112b38..4972c9fb 100644 --- a/packages/coding-agent/src/modes/rpc/rpc-types.ts +++ b/packages/coding-agent/src/modes/rpc/rpc-types.ts @@ -5,7 +5,7 @@ * Responses and events are emitted as JSON lines on stdout. */ -import type { Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core"; +import type { AppMessage, Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core"; import type { CompactionResult, SessionStats } from "../../core/agent-session.js"; import type { BashResult } from "../../core/bash-executor.js"; @@ -49,7 +49,10 @@ export type RpcCommand = | { id?: string; type: "switch_session"; sessionPath: string } | { id?: string; type: "branch"; entryIndex: number } | { id?: string; type: "get_branch_messages" } - | { id?: string; type: "get_last_assistant_text" }; + | { id?: string; type: "get_last_assistant_text" } + + // Messages + | { id?: string; type: "get_messages" }; // ============================================================================ // RPC State @@ -146,6 +149,9 @@ export type RpcResponse = data: { text: string | null }; } + // Messages + | { id?: string; type: "response"; command: "get_messages"; success: true; data: { messages: AppMessage[] } } + // Error response (any command can fail) | { id?: string; type: "response"; command: string; success: false; error: string };