From cbb7fde1558dbae7d930249e33f6407838db447e Mon Sep 17 00:00:00 2001 From: aleksander Date: Fri, 1 May 2026 10:05:59 +0200 Subject: [PATCH] feat(coding-agent/rpc): expose context usage in state Include the current ContextUsage payload in get_state responses so RPC clients can render context-window status without in-process AgentSession access. --- packages/coding-agent/src/modes/rpc/rpc-mode.ts | 1 + packages/coding-agent/src/modes/rpc/rpc-types.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/coding-agent/src/modes/rpc/rpc-mode.ts b/packages/coding-agent/src/modes/rpc/rpc-mode.ts index 87710b80f..76130e240 100644 --- a/packages/coding-agent/src/modes/rpc/rpc-mode.ts +++ b/packages/coding-agent/src/modes/rpc/rpc-mode.ts @@ -574,6 +574,7 @@ export async function runRpcMode(session: AgentSession): Promise { description: tool.description, parameters: tool.parameters, })), + contextUsage: session.getContextUsage(), }; return success(id, "get_state", state); } diff --git a/packages/coding-agent/src/modes/rpc/rpc-types.ts b/packages/coding-agent/src/modes/rpc/rpc-types.ts index cc0779809..6751b34ab 100644 --- a/packages/coding-agent/src/modes/rpc/rpc-types.ts +++ b/packages/coding-agent/src/modes/rpc/rpc-types.ts @@ -7,6 +7,7 @@ import type { AgentMessage, AgentToolResult, ThinkingLevel } from "@oh-my-pi/pi-agent-core"; import type { Effort, ImageContent, Model } from "@oh-my-pi/pi-ai"; import type { BashResult } from "../../exec/bash-executor"; +import type { ContextUsage } from "../../extensibility/extensions/types"; import type { SessionStats } from "../../session/agent-session"; import type { CompactionResult } from "../../session/compaction"; import type { TodoPhase } from "../../tools/todo-write"; @@ -90,6 +91,8 @@ export interface RpcSessionState { /** For session dump / export (plain-text parity with /dump). */ systemPrompt?: string; dumpTools?: Array<{ name: string; description: string; parameters: unknown }>; + /** Current context window usage. Null tokens/percent when unknown (e.g. right after compaction). */ + contextUsage?: ContextUsage; } export interface RpcHandoffResult {