A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
Fix six small contract-hygiene issues found by a main audit (#2493)
Sebastian Müller893f9d5d9c8a
diff --git a/packages/agent/.changes/contract-hygiene.md b/packages/agent/.changes/contract-hygiene.mdnew file mode 100644index 0000000000..5e770ab084--- /dev/null+++ b/packages/agent/.changes/contract-hygiene.md@@ -0,0 +1 @@+- `turn_end` and `message_update` events are now typed as assistant messages (matching what is actually emitted), and the README documents the `max` thinking level and current `continue()` semantics.diff --git a/packages/agent/README.md b/packages/agent/README.mdindex e28f449c89..be6ff3cf95 100644--- a/packages/agent/README.md+++ b/packages/agent/README.md@@ -150,7 +150,7 @@ When you use the `Agent` class, assistant `message_end` processing is treated asawait agent.continue();```-The last message in context must be `user` or `toolResult` (not `assistant`).+The last message in context must not be `assistant`. When it is, or when the context is empty, `continue()` runs a queued steering or follow-up message instead, and throws `AgentContinueError` with code `nothing-to-continue` only when no message is queued either. A `custom` tail also prefers a queued message over a plain continuation.### Event Types@@ -177,7 +177,7 @@ const agent = new Agent({initialState: {systemPrompt: string,model: Model<any>,- thinkingLevel: "off" | "minimal" | "low" | "medium" | "high" | "xhigh",+ thinkingLevel: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max",tools: AgentTool<any>[],messages: AgentMessage[],},@@ -273,7 +273,7 @@ await agent.prompt("What's in this image?", [// AgentMessage directlyawait agent.prompt({ role: "user", content: "Hello", timestamp: Date.now() });-// Continue from current context (last message must be user or toolResult)+// Continue from current context (tail must not be assistant unless a message is queued)await agent.continue();```diff --git a/packages/agent/src/agent.ts b/packages/agent/src/agent.tsindex 1dc7616532..f89c742c7b 100644--- a/packages/agent/src/agent.ts+++ b/packages/agent/src/agent.ts@@ -610,7 +610,7 @@ export class Agent {}case "turn_end":- if (event.message.role === "assistant" && event.message.errorMessage) {+ if (event.message.errorMessage) {this._state.errorMessage = event.message.errorMessage;}break;diff --git a/packages/agent/src/types.ts b/packages/agent/src/types.tsindex f29074abe0..72c6f43b0f 100644--- a/packages/agent/src/types.ts+++ b/packages/agent/src/types.ts@@ -393,11 +393,11 @@ export type AgentEvent =| { type: "agent_end"; messages: AgentMessage[] }/** One assistant response and its resulting tool calls. */| { type: "turn_start" }- | { type: "turn_end"; message: AgentMessage; toolResults: ToolResultMessage[] }+ | { type: "turn_end"; message: AssistantMessage; toolResults: ToolResultMessage[] }/** Lifecycle events for user, assistant, and tool-result messages. */| { type: "message_start"; message: AgentMessage }/** Only emitted for assistant messages during streaming. */- | { type: "message_update"; message: AgentMessage; assistantMessageEvent: AssistantMessageEvent }+ | { type: "message_update"; message: AssistantMessage; assistantMessageEvent: AssistantMessageEvent }| { type: "message_end"; message: AgentMessage }/** Tool execution events; parallel calls may end in completion rather than source order. */| { type: "tool_execution_start"; toolCallId: string; toolName: string; args: any }diff --git a/packages/coding-agent/.changes/contract-hygiene-cleanup.md b/packages/coding-agent/.changes/contract-hygiene-cleanup.mdnew file mode 100644index 0000000000..ef5bdad1d0--- /dev/null+++ b/packages/coding-agent/.changes/contract-hygiene-cleanup.md@@ -0,0 +1 @@+- Cleaned up contract hygiene in the agent family surfaces: `agent_observe` rows now carry the shared family `status` (`running`/`idle`/`inactive`) plus a separate typed live `activity`, the public `turn_end` and `message_update` events are typed as assistant-only, Ctrl+C in the standalone config selector is remappable through the keybinding config, and the daemon revision catalog, agents-view emptiness comment, and `pi-agent` README no longer state facts the code contradicts.diff --git a/packages/coding-agent/skills/agent-observe/SKILL.md b/packages/coding-agent/skills/agent-observe/SKILL.mdindex 9bc4b5016e..2c1b1dcb20 100644--- a/packages/coding-agent/skills/agent-observe/SKILL.md+++ b/packages/coding-agent/skills/agent-observe/SKILL.md@@ -31,7 +31,8 @@ if child is not None:- `await agent_observe.list_agents()` returns `current` and `agents`, the fullnuclear family: parent, siblings, and direct children, active or not. Eachagent carries `sessionId`, optional `sessionName`, `relationship`- (`parent`/`sibling`/`child`), `status`, `isSessionActive`, and the counts and+ (`parent`/`sibling`/`child`), `status` (`running`/`idle`/`inactive`), the live+ `activity` of a resident session, `isSessionActive`, and the counts andmessage previews known for it: `latestMessage` for a live session,`firstMessage` for an inactive child. A member with no live session hasno `activeSessionId` and no live detail; address it with `agent_message.send`diff --git a/packages/coding-agent/src/core/agent-observe.ts b/packages/coding-agent/src/core/agent-observe.tsindex f3df767924..4a7047deed 100644--- a/packages/coding-agent/src/core/agent-observe.ts+++ b/packages/coding-agent/src/core/agent-observe.ts@@ -1,5 +1,5 @@import type { AgentMessage } from "@earendil-works/pi-agent-core";-import type { AgentFamilyRelationship } from "./agent-messages.js";+import type { AgentFamilyRelationship, AgentFamilyStatus } from "./agent-messages.js";export const AGENT_OBSERVE_SKILL_NAME = "agent-observe";/** Shared cap for the message previews carried by roster rows. */@@ -7,6 +7,12 @@ export const AGENT_OBSERVE_PREVIEW_MAX_CHARS = 240;export const AGENT_OBSERVE_IMPORT_NAME = "agent_observe";export const ORCHESTRATION_HEARTBEAT_SKILL_NAME = "orchestration-heartbeat";+/**+ * What a resident session is doing right now. Separate axis from the family+ * lifecycle in `status`, which every row carries.+ */+export type AgentObserveActivity = "tool" | "model" | "compacting" | "busy" | "user" | "idle";+export interface AgentObserveAgentSummary {/** Absent for family members that have no live session in this daemon. */activeSessionId?: string;@@ -16,7 +22,9 @@ export interface AgentObserveAgentSummary {relationship?: AgentFamilyRelationship;runtimeKind?: "top-level" | "subagent";cwd?: string;- status: string;+ status: AgentFamilyStatus;+ /** Absent for family members that have no live session in this daemon. */+ activity?: AgentObserveActivity;isCurrent: boolean;isStreaming: boolean;isCompacting: boolean;diff --git a/packages/coding-agent/src/modes/agents-view/agents-view-state.ts b/packages/coding-agent/src/modes/agents-view/agents-view-state.tsindex e37c5abbb6..10e821a06f 100644--- a/packages/coding-agent/src/modes/agents-view/agents-view-state.ts+++ b/packages/coding-agent/src/modes/agents-view/agents-view-state.ts@@ -112,8 +112,8 @@ export function shouldShowAgentsViewSession(summary: SessionSummary, manuallyInareturn summary.lifecycle === "live";}-// TODO(unify: #2055): replace with the shared user-content rule once it lands;-// session summaries only carry message counts today.+// Emptiness is judged from the wire summary, which carries message counts only.+// SessionManager.hasUserContent() needs session entries the view never receives.export function isEmptyAgentsViewSession(summary: SessionSummary): boolean {return summary.messageCount === 0;}diff --git a/packages/coding-agent/src/modes/daemon/daemon-mode.ts b/packages/coding-agent/src/modes/daemon/daemon-mode.tsindex 1f459e6574..5f559585a0 100644--- a/packages/coding-agent/src/modes/daemon/daemon-mode.ts+++ b/packages/coding-agent/src/modes/daemon/daemon-mode.ts@@ -54,6 +54,7 @@ import {} from "../../core/agent-messages.js";import {AGENT_OBSERVE_PREVIEW_MAX_CHARS,+ type AgentObserveActivity,type AgentObserveAgentSnapshot,type AgentObserveAgentSummary,type AgentObserveController,@@ -3599,7 +3600,7 @@ export class AgentDaemon {const session = state.runtime.session;const messages = session.messages;const latest = messages.at(-1);- const status = session.isStreaming+ const activity: AgentObserveActivity = session.isStreaming? session.state.pendingToolCalls.size > 0? "tool": "model"@@ -3616,7 +3617,8 @@ export class AgentDaemon {...(summary.sessionName ? { sessionName: summary.sessionName } : {}),...(summary.runtimeKind ? { runtimeKind: summary.runtimeKind } : {}),cwd: summary.cwd,- status,+ status: summary.rosterStatus ?? classifySessionRosterStatus(summary),+ activity,isCurrent: state.activeSessionId === currentState.activeSessionId,isStreaming: summary.isStreaming,isCompacting: summary.isCompacting,diff --git a/packages/coding-agent/src/modes/daemon/daemon-protocol.ts b/packages/coding-agent/src/modes/daemon/daemon-protocol.tsindex 6b860ffbc3..fa246eed90 100644--- a/packages/coding-agent/src/modes/daemon/daemon-protocol.ts+++ b/packages/coding-agent/src/modes/daemon/daemon-protocol.ts@@ -68,6 +68,7 @@ export const DAEMON_COMMAND_ENVELOPE_MIN_PROTOCOL_VERSION = 7;// Revision 19 adds daemon-held session input pauses.// Revision 20 lets cancellation target a prompt the session owns but has not started.// Revision 21 adds capability-gated, session-scoped ACP MCP server replacement.+// Revision 22 scopes ACP MCP replacement and cleanup to a connection owner.// Revision 23 lets workers query the supervisor agent roster on demand.// Revision 24 adds the capability-gated agent-roster subscription and push.// Revision 25 adds capability-gated direct worker peer transport discovery.diff --git a/packages/coding-agent/src/modes/interactive/components/config-selector.ts b/packages/coding-agent/src/modes/interactive/components/config-selector.tsindex 9fbb7d7f3c..ab1cfa4db5 100644--- a/packages/coding-agent/src/modes/interactive/components/config-selector.ts+++ b/packages/coding-agent/src/modes/interactive/components/config-selector.ts@@ -9,7 +9,6 @@ import {type Focusable,getKeybindings,Input,- matchesKey,Spacer,truncateToWidth,visibleWidth,@@ -397,7 +396,7 @@ class ResourceList implements Component, Focusable {this.onCancel?.();return;}- if (matchesKey(data, "ctrl+c")) {+ if (kb.matches(data, "app.clear")) {this.onExit?.();return;}diff --git a/packages/coding-agent/test/daemon-mode.test.ts b/packages/coding-agent/test/daemon-mode.test.tsindex a59a310204..0a4d18f29c 100644--- a/packages/coding-agent/test/daemon-mode.test.ts+++ b/packages/coding-agent/test/daemon-mode.test.ts@@ -824,15 +824,18 @@ describe("daemon mode helpers", () => {? 2: 1: 0,- isStreaming: false,+ isStreaming: state.activeSessionId === "sibling",isCompacting: false,isBashRunning: false,isRetrying: false,- isSessionActive: false,+ isSessionActive: state.activeSessionId === "sibling",hasAcceptedPromptInFlight: false,unfinishedActionCount: 0,messages: [],- state: { pendingToolCalls: new Set(), streamingMessage: undefined },+ state: {+ pendingToolCalls: new Set(state.activeSessionId === "sibling" ? ["call-1"] : []),+ streamingMessage: undefined,+ },hasRunningRlmChildren: () => false,getSessionActionSnapshot: () => ({ queuedCount: 0, steering: [], followUps: [] }),},@@ -850,10 +853,12 @@ describe("daemon mode helpers", () => {const observed = await observe.listAgents();expect(observed.current.activeSessionId).toBe("child");- expect(observed.agents.map((agent) => [agent.relationship, agent.activeSessionId])).toEqual([- ["parent", "root"],- ["sibling", "sibling"],- ["child", "grandchild"],+ expect(+ observed.agents.map((agent) => [agent.relationship, agent.activeSessionId, agent.status, agent.activity]),+ ).toEqual([+ ["parent", "root", "idle", "idle"],+ ["sibling", "sibling", "running", "tool"],+ ["child", "grandchild", "idle", "idle"],]);await expect(observe.getAgent("cousin")).rejects.toThrow("Agent reach is limited to parent, siblings, and children",