@automatalabs/acp-agents 1.3.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +66 -21
  2. package/dist/acp-client.d.ts +15 -9
  3. package/dist/acp-client.d.ts.map +1 -1
  4. package/dist/acp-client.js +12 -10
  5. package/dist/agent/acp-agent.d.ts +84 -26
  6. package/dist/agent/acp-agent.d.ts.map +1 -1
  7. package/dist/agent/acp-agent.js +461 -168
  8. package/dist/agent/errors.d.ts +12 -2
  9. package/dist/agent/errors.d.ts.map +1 -1
  10. package/dist/agent/errors.js +38 -9
  11. package/dist/agent/fork.d.ts +7 -5
  12. package/dist/agent/fork.d.ts.map +1 -1
  13. package/dist/agent/fork.js +7 -5
  14. package/dist/agent/messages.d.ts +42 -0
  15. package/dist/agent/messages.d.ts.map +1 -0
  16. package/dist/agent/messages.js +225 -0
  17. package/dist/agent/probe.d.ts +1 -1
  18. package/dist/agent/probe.d.ts.map +1 -1
  19. package/dist/agent/probe.js +5 -1
  20. package/dist/agent/queue.js +2 -2
  21. package/dist/agent/routing.d.ts +19 -1
  22. package/dist/agent/routing.d.ts.map +1 -1
  23. package/dist/agent/routing.js +41 -4
  24. package/dist/agent/stream.d.ts +21 -0
  25. package/dist/agent/stream.d.ts.map +1 -0
  26. package/dist/agent/stream.js +93 -0
  27. package/dist/agent/structured.d.ts +7 -3
  28. package/dist/agent/structured.d.ts.map +1 -1
  29. package/dist/agent/structured.js +24 -14
  30. package/dist/agent/tool-host.d.ts +34 -0
  31. package/dist/agent/tool-host.d.ts.map +1 -0
  32. package/dist/agent/tool-host.js +138 -0
  33. package/dist/agent/tools.d.ts +26 -0
  34. package/dist/agent/tools.d.ts.map +1 -0
  35. package/dist/agent/tools.js +62 -0
  36. package/dist/agent/turn.d.ts +6 -3
  37. package/dist/agent/turn.d.ts.map +1 -1
  38. package/dist/agent/turn.js +15 -67
  39. package/dist/agent/types.d.ts +183 -29
  40. package/dist/agent/types.d.ts.map +1 -1
  41. package/dist/backend.d.ts +13 -5
  42. package/dist/backend.d.ts.map +1 -1
  43. package/dist/backends/claude.d.ts +4 -0
  44. package/dist/backends/claude.d.ts.map +1 -1
  45. package/dist/backends/claude.js +40 -17
  46. package/dist/backends/codex.d.ts +5 -0
  47. package/dist/backends/codex.d.ts.map +1 -1
  48. package/dist/backends/codex.js +15 -9
  49. package/dist/backends/custom.d.ts.map +1 -1
  50. package/dist/backends/custom.js +3 -2
  51. package/dist/backends/opencode.d.ts +4 -0
  52. package/dist/backends/opencode.d.ts.map +1 -1
  53. package/dist/backends/opencode.js +5 -1
  54. package/dist/backends/pi.d.ts +5 -2
  55. package/dist/backends/pi.d.ts.map +1 -1
  56. package/dist/backends/pi.js +15 -3
  57. package/dist/config-catalog.d.ts +4 -0
  58. package/dist/config-catalog.d.ts.map +1 -1
  59. package/dist/config-catalog.js +1 -0
  60. package/dist/index.d.ts +8 -3
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +9 -1
  63. package/dist/interactive.d.ts +4 -5
  64. package/dist/interactive.d.ts.map +1 -1
  65. package/dist/local-mcp-host.d.ts +30 -0
  66. package/dist/local-mcp-host.d.ts.map +1 -0
  67. package/dist/local-mcp-host.js +151 -0
  68. package/dist/protocol-coverage.d.ts +34 -6
  69. package/dist/protocol-coverage.d.ts.map +1 -1
  70. package/dist/protocol-coverage.js +26 -1
  71. package/dist/registry.d.ts +3 -3
  72. package/dist/registry.d.ts.map +1 -1
  73. package/dist/runner.d.ts +5 -0
  74. package/dist/runner.d.ts.map +1 -1
  75. package/dist/runner.js +13 -8
  76. package/dist/structured-output.d.ts +18 -0
  77. package/dist/structured-output.d.ts.map +1 -1
  78. package/dist/structured-output.js +19 -1
  79. package/dist/structured-tool.d.ts +7 -9
  80. package/dist/structured-tool.d.ts.map +1 -1
  81. package/dist/structured-tool.js +14 -102
  82. package/dist/system-prompt.d.ts +13 -0
  83. package/dist/system-prompt.d.ts.map +1 -0
  84. package/dist/system-prompt.js +67 -0
  85. package/dist/traits.d.ts +51 -0
  86. package/dist/traits.d.ts.map +1 -0
  87. package/dist/traits.js +88 -0
  88. package/package.json +4 -4
@@ -1,6 +1,7 @@
1
- import type { PromptResponse, SessionConfigOption, SessionModeState, StopReason, ToolCallContent, ToolCallLocation, ToolCallStatus, ToolKind, Usage } from "@agentclientprotocol/sdk";
2
- import type { AgentHistoryEntry, AgentUsage, McpServerConfig, PromptImage, WorkflowError } from "@automatalabs/shared-types";
3
- import type { TSchema } from "typebox";
1
+ import type { ContentBlock, PromptResponse, SessionConfigOption, SessionModeState, StopReason, ToolCallContent, ToolCallLocation, ToolCallStatus, ToolKind, Usage } from "@agentclientprotocol/sdk";
2
+ import type { AgentHistoryEntry, AgentUsage, McpServerConfig, PromptImage, SystemPromptOptions, WorkflowError } from "@automatalabs/shared-types";
3
+ import type { ContentBlock as McpContentBlock } from "@modelcontextprotocol/sdk/types.js";
4
+ import type { Static, TSchema } from "typebox";
4
5
  import type { AuthStore } from "../auth/auth-store.js";
5
6
  import type { ClientHandlers } from "../client-handlers.js";
6
7
  import type { HarnessConfigReport, HarnessModelsView } from "../config-catalog.js";
@@ -9,62 +10,137 @@ import type { ElicitationResolver, PermissionResolver, ToolPolicy } from "../per
9
10
  import type { ProviderStore } from "../provider-store.js";
10
11
  import type { CustomBackendConfig } from "../registry.js";
11
12
  export type { SessionConfigOption, SessionModeState };
13
+ /** What a function tool's `execute` receives next to its validated input. */
14
+ export interface AcpAgentToolContext {
15
+ /** The ACP session id of the agent that called the tool. */
16
+ readonly sessionId: string;
17
+ /** The agent's resolved backend id. */
18
+ readonly backendId: string;
19
+ /** The agent's `label`, when set. */
20
+ readonly label?: string;
21
+ /** The ACP `tool_call` id the backend surfaced for this call, when the SDK could correlate it:
22
+ * the latest not-yet-settled `tool_call` of the turn in flight whose standard `name` (or
23
+ * `title`) is the tool's name or ends in `__<name>` (pi's `mcp__agent_tools__<name>` alias).
24
+ * Best-effort — undefined when the backend surfaced none before calling. */
25
+ readonly toolCallId?: string;
26
+ /** Aborts when the agent's constructor `signal` fires, when the turn in flight is cancelled
27
+ * (`cancel()`, a per-call `signal`, an early `stream()` exit), when the agent closes or its
28
+ * process dies, and when the backend drops the HTTP request before the result was written. */
29
+ readonly signal: AbortSignal;
30
+ }
31
+ /** What `execute` may return: a string (one text block), MCP content blocks, or a complete
32
+ * `{ content, isError? }` result — `isError: true` is passed through to the agent as-is. The
33
+ * blocks are MCP's `ContentBlock` (`@modelcontextprotocol/sdk/types.js`: `text`, `image`,
34
+ * `audio`, `resource_link`, `resource`) — the `tools/call` result shape the agent receives on the
35
+ * wire — and NOT the ACP `ContentBlock` every other content on the AcpAgent surface uses
36
+ * (`prompt()` input, `AcpAgentMessage.content`, the update events). A `{ type: "text", text }`
37
+ * block is valid in both. */
38
+ export type AcpAgentToolResult = string | McpContentBlock[] | {
39
+ readonly content: McpContentBlock[];
40
+ readonly isError?: boolean;
41
+ };
42
+ /**
43
+ * One client-side function tool (`AcpAgentOptions.tools`). The SDK serves it to the agent as an
44
+ * MCP tool on the per-agent local tool host (`agent_tools`): `name` and `description` are
45
+ * advertised verbatim, `inputSchema` (typebox, like the `schema` option) is advertised as its
46
+ * JSON Schema, and every `tools/call` is validated against it (typebox Convert + Check) before
47
+ * `execute` runs with the converted input. A validation failure or a thrown `execute` is returned
48
+ * to the agent as an `isError: true` result carrying the message, never a transport error. Use
49
+ * `defineTool()` to infer the input type from the schema.
50
+ */
51
+ export interface AcpAgentToolDefinition<TInput extends TSchema = TSchema> {
52
+ /** `^[A-Za-z0-9_-]{1,64}$`, unique across the agent's tools (INVALID_ARGUMENT in the constructor). */
53
+ name: string;
54
+ description: string;
55
+ /** A typebox OBJECT schema (`Type.Object(...)`, JSON `type: "object"`): MCP `tools/call`
56
+ * arguments are an object, so any other top-level type is INVALID_ARGUMENT in the constructor. */
57
+ inputSchema: TInput;
58
+ execute(input: Static<TInput>, ctx: AcpAgentToolContext): Promise<AcpAgentToolResult> | AcpAgentToolResult;
59
+ }
12
60
  export interface AcpAgentOptions {
13
61
  /** ABSOLUTE path that exists and is a directory. Validated synchronously in the constructor and
14
- * the statics BEFORE any process spawns (SCRIPT_VALIDATION_ERROR otherwise). Sent as the
62
+ * the statics BEFORE any process spawns (INVALID_ARGUMENT otherwise). Sent as the
15
63
  * session/new|fork|resume|load `cwd`. */
16
64
  cwd: string;
17
65
  /** Model routing spec with the runner's grammar (`resolveModelRoute`): the first `/`-segment
18
66
  * routes to a registered custom backend (wins) or a built-in; the remainder is the backend's
19
67
  * model id VERBATIM and is sent as `session/set_config_option { configId: "model" }` right after
20
68
  * the session opens. An unrouted spec (no known first segment) goes WHOLE to the default backend
21
- * (`AGENTPRISM_DEFAULT_BACKEND`, else `claude`). Omitted = default backend, no model selection. */
69
+ * (`AGENTPRISM_DEFAULT_BACKEND`, else `claude`). Omitted = default backend, no model selection.
70
+ * This is the model the agent STARTS on: `agent.setModel(spec)` and a per-turn
71
+ * `prompt(…, { model })` switch it mid-session (same backend only); `agent.model` follows. */
22
72
  model?: string;
23
- /** Session mode. Explicit ids are strict (unadvertised → SCRIPT_VALIDATION_ERROR at open).
73
+ /** Session mode. Explicit ids are strict (unadvertised → INVALID_ARGUMENT at open).
24
74
  * Omitted = the backend's `defaultModeId` when advertised (claude `auto`, codex `agent`,
25
75
  * opencode `build`; pi/custom none). */
26
76
  mode?: string;
27
77
  /** Applied verbatim via `session/set_config_option` in ascending option-id order after model
28
- * selection. `"model"` is reserved (SCRIPT_VALIDATION_ERROR in the constructor). Ids not in the
29
- * advertised catalog fail at open with SCRIPT_VALIDATION_ERROR listing the advertised ids. */
78
+ * selection. `"model"` is reserved (INVALID_ARGUMENT in the constructor). Ids not in the
79
+ * advertised catalog fail at open with INVALID_ARGUMENT listing the advertised ids. */
30
80
  configOptions?: Record<string, string | boolean>;
31
81
  /** Session-level structured-output contract (typebox). Claude: `_meta.claudeCode.options.outputFormat`
32
82
  * at session/new|resume|load|fork; Codex: `_meta.outputSchema` on every turn; OpenCode/pi/custom:
33
83
  * the client-hosted `StructuredOutput` HTTP MCP tool injected into `mcpServers` when the agent
34
84
  * advertises `mcpCapabilities.http`, plus the in-prompt contract. Each turn reports
35
- * `structured` / `structuredError`; there is no repair ladder. */
85
+ * `structured` / `structuredError`; a repair ladder runs only when `schemaRetries` asks for one. */
36
86
  schema?: TSchema;
87
+ /** Opt-in structured repair ladder: how many EXTRA turns `prompt()` may spend re-prompting the
88
+ * same session when a schema is active and the turn ended (`end_turn`) with `structured` absent
89
+ * — an integer ≥ 0 (INVALID_ARGUMENT otherwise), default 0 = exactly one turn per `prompt()`.
90
+ * A repair turn sends the runner's repair prompt (`repairPromptText`: the StructuredOutput-tool
91
+ * variant when the tool is active, else the JSON variant, with the previous attempt's
92
+ * `structuredError` appended) with the same turn `_meta`; the native channel (Claude session
93
+ * `outputFormat`, Codex per-turn `outputSchema`, the client-hosted tool) stays authoritative.
94
+ * Every repair turn is a real turn: events fire, `stream()` yields them, `usage` accumulates.
95
+ * The resolved `AcpAgentTurn` is the FINAL attempt's plus `structuredAttempts`. A turn that ended
96
+ * `cancelled` / `refusal` / `max_tokens` / `max_turn_requests` is never repaired. Overridable
97
+ * per turn (`AcpAgentPromptOptions.schemaRetries`); inherited by forks. */
98
+ schemaRetries?: number;
37
99
  /** Client-provided MCP servers (stdio/http/sse/acp). Capability-gated by the connection exactly
38
100
  * like the runner. */
39
101
  mcpServers?: McpServerConfig[];
40
- /** Headless permission auto-policy: allow/deny lists + `defaultOutcome` (default "allow"). */
41
- tools?: ToolPolicy;
42
- /** Session-scoped async permission resolver; wins over `tools` unless the request matches an
43
- * explicit list (same precedence as the runner: resolver > policy). */
102
+ /** Client-side function tools, served to the agent over HTTP MCP from a per-agent local host
103
+ * injected into `mcpServers` as `agent_tools` (`agent_tools_2`, … when a caller's server holds
104
+ * the name) on `session/new|resume|load|fork` and an id-only fork's reattach. Names are
105
+ * validated in the constructor (INVALID_ARGUMENT before any spawn); an agent that does not
106
+ * advertise `mcpCapabilities.http` fails the open with INVALID_ARGUMENT — tools are never
107
+ * silently dropped. Inherited by forks (each runs its own host); the host closes with the
108
+ * agent. An empty array is the same as omitting the option. */
109
+ tools?: AcpAgentToolDefinition[];
110
+ /** Headless permission auto-policy: allow/deny lists + `defaultOutcome` (default "allow").
111
+ * Consulted only when no `onPermissionRequest` resolver is installed. */
112
+ permissions?: ToolPolicy;
113
+ /** Session-scoped async permission resolver. When present it answers EVERY permission request
114
+ * (the runner's default precedence); `permissions` is the headless fallback without one. */
44
115
  onPermissionRequest?: PermissionResolver;
45
116
  /** Elicitation responder; its presence is what advertises `elicitation` at initialize. */
46
117
  onElicitation?: ElicitationResolver;
47
118
  /** Generic session/new `_meta` passthrough. Layered UNDER backend-computed keys (shallow, like
48
119
  * the runner) and, when `raw !== false`, OVER `backend.rawMessagesMeta()`. */
49
120
  meta?: Record<string, unknown>;
50
- /** Codex-only session instructions → bare `_meta.baseInstructions` / `_meta.developerInstructions`. */
51
- instructions?: {
52
- base?: string;
53
- developer?: string;
54
- };
121
+ /** Backend-neutral system prompt instructions: `replace` swaps the backend's built-in system
122
+ * prompt, `append` adds to it. Validated in the constructor (and `fork()` / the statics) against
123
+ * the routed backend's `Backend.systemPrompt` support BEFORE any process spawns — a field the
124
+ * backend cannot carry is INVALID_ARGUMENT, never a silent no-op (Codex and Claude and pi
125
+ * carry both; OpenCode and custom backends carry neither). Sent on `session/new|resume|load|fork`
126
+ * and the reattach of an id-only fork in the backend's dialect: Codex `_meta.baseInstructions`
127
+ * / `_meta.developerInstructions`, Claude `_meta.systemPrompt` (string, or `{ append }`), pi
128
+ * `_meta.systemPrompt` `{ replace?, append? }`. Wins over the same key in `meta`. Inherited by
129
+ * forks (overridable). */
130
+ systemPrompt?: SystemPromptOptions;
55
131
  /** Human label stamped on every event context and every WorkflowError `agentLabel`; never on
56
132
  * the wire. */
57
133
  label?: string;
58
134
  /** Custom backend registry merged over `AGENTPRISM_BACKENDS` exactly like
59
135
  * `createAcpRunner({ backends })`. Read once in the constructor; malformed →
60
- * SCRIPT_VALIDATION_ERROR. Forks inherit it and cannot override it. */
136
+ * INVALID_ARGUMENT. Forks inherit it and cannot override it. */
61
137
  backends?: Record<string, CustomBackendConfig>;
62
138
  /** Agent-lifetime abort: rejects queued work with `signal.reason`, cancels an in-flight turn,
63
139
  * then closes. Not inherited by forks. */
64
140
  signal?: AbortSignal;
65
- /** Default true: the session log is retained across turns so `history`/`text` are cumulative
66
- * and a fork can seed its child. `false` maps to `retainSessionLog: false` (history/text hold
67
- * only the latest turn). */
141
+ /** Default true: the session log is retained across turns so `history`/`text`/`messages` are
142
+ * cumulative and a fork can seed its child. `false` maps to `retainSessionLog: false`
143
+ * (history/text/messages hold only the latest turn). */
68
144
  retainHistory?: boolean;
69
145
  /** Default true: ask the backend to emit its vendor notifications (`_claude/sdkMessage` on
70
146
  * Claude) so they reach `on("raw_message")` and `turn.raw`. `false` skips
@@ -86,17 +162,27 @@ export interface AcpAgentPromptOptions {
86
162
  /** Turn `_meta` passthrough, merged UNDER the backend's turn meta (backend keys win direct
87
163
  * collisions, exactly like the runner's `mergeTurnMeta`). */
88
164
  meta?: Record<string, unknown>;
165
+ /** Switch the model BEFORE this turn, inside the FIFO (first, ahead of `configOptions` and
166
+ * `mode` — open's order); STICKY for the session and reflected in `agent.model`. Same
167
+ * validation as `setModel()`: the fork rule (the spec must route to this agent's backend and
168
+ * poolKey, `"<backendId>/<model id>"`; a backend-only spec is rejected) → INVALID_ARGUMENT
169
+ * before anything is sent; then `session/set_config_option { configId: "model" }` with the
170
+ * routed remainder verbatim, a wire rejection mapping through the normal error path. */
171
+ model?: string;
89
172
  /** Applied via `session/set_config_option` BEFORE this turn, inside the FIFO; STICKY for the
90
173
  * session. Same validation as the constructor option. */
91
174
  configOptions?: Record<string, string | boolean>;
92
175
  /** Applied via `session/set_mode` before this turn, inside the FIFO; sticky; strict. */
93
176
  mode?: string;
94
177
  /** Per-turn schema override. Allowed ONLY when the backend carries the schema on the turn and
95
- * does not embed it in the prompt (today: Codex). Otherwise SCRIPT_VALIDATION_ERROR naming the
178
+ * does not embed it in the prompt (today: Codex). Otherwise INVALID_ARGUMENT naming the
96
179
  * backend and pointing at the constructor `schema` option. */
97
180
  schema?: TSchema;
181
+ /** Per-turn repair budget (integer ≥ 0; INVALID_ARGUMENT otherwise, before anything is sent);
182
+ * wins over the constructor's `schemaRetries` for this `prompt()` only. */
183
+ schemaRetries?: number;
98
184
  /** Per-call abort: queued, or started but not yet on the wire (the lazy open, the per-turn
99
- * `configOptions`/`mode`) → rejects with the reason without sending; in flight →
185
+ * `model`/`configOptions`/`mode`) → rejects with the reason without sending; in flight →
100
186
  * `session/cancel`, then rejects with the reason. The one way to stop a turn `cancel()` cannot
101
187
  * reach: `cancel()` targets only a turn whose `session/prompt` is on the wire. */
102
188
  signal?: AbortSignal;
@@ -111,7 +197,7 @@ export interface AcpAgentCloseOptions {
111
197
  keep?: boolean;
112
198
  }
113
199
  /** Everything a fork may override. The backend is fixed by the parent: a `model` override must
114
- * route to the same backend (poolKey-equal) or SCRIPT_VALIDATION_ERROR. `backends`, `authStore`,
200
+ * route to the same backend (poolKey-equal) or INVALID_ARGUMENT. `backends`, `authStore`,
115
201
  * `providerStore`, `clientHandlers` are inherited and not overridable. `label` defaults to
116
202
  * `<parent label>/fork-<n>` (or `fork-<n>`); `signal` is never inherited. `cwd` defaults to the
117
203
  * parent's; a different cwd is rejected on `cwd: "source-only"` backends (`FORK_SESSION_TRAITS`). */
@@ -161,6 +247,39 @@ export interface AcpAgentToolCall {
161
247
  /** Shallow merge of every `_meta` seen for this id. */
162
248
  readonly meta?: Record<string, unknown>;
163
249
  }
250
+ /**
251
+ * One message of the transcript, folded from the session/update stream (`turn.messages` for a
252
+ * turn, `agent.messages` for the retained log). The assistant-message boundary is EXACTLY the
253
+ * `text` fold's: text chunks concatenate into one message until a `tool_call`, `tool_call_update`,
254
+ * `agent_thought_chunk`, `plan*` or `user_message_chunk` event (or a changed ACP `messageId`)
255
+ * marks a boundary, and the next text chunk opens a new message — so `turn.text` is the
256
+ * text-bearing assistant messages of the turn joined by `"\n\n"`. Tool calls attach to the
257
+ * assistant message in progress (a turn that starts with a tool call has a leading message with
258
+ * no text); thoughts lead and attach to the assistant message that receives the next assistant
259
+ * content (a trailing thought is a message of its own); a run of `user_message_chunk`s is one
260
+ * user message.
261
+ */
262
+ export interface AcpAgentMessage {
263
+ readonly role: "user" | "assistant";
264
+ /** The ordered blocks of this message. Consecutive text chunks fold into one text block (the
265
+ * first chunk's fields, the concatenated text); other blocks are kept as sent. The verbatim
266
+ * chunks stay in `updates`. */
267
+ readonly content: ContentBlock[];
268
+ /** Assistant only: the tool calls this message issued, folded by `toolCallId` (first-seen
269
+ * order; a later `tool_call_update` updates the call where it lives). Empty for user messages. */
270
+ readonly toolCalls: readonly AcpAgentToolCall[];
271
+ /** Assistant only: the `agent_thought_chunk` blocks folded into this message, consecutive text
272
+ * chunks folded like `content`. A thought is held until the next assistant content and attaches
273
+ * to the message that content lands on: a text chunk (or a non-text block) after a thought
274
+ * OPENS a new message — a thought is a boundary — and the thought goes with it; a tool call
275
+ * attaches to the assistant message in progress, which may already hold text, so `text →
276
+ * thought → tool_call` puts the thought on the message with that text (opening a message when
277
+ * none is in progress). A thought followed by a user message or by the end of the turn is an
278
+ * assistant message of its own with no `content`. Empty for user messages. */
279
+ readonly thoughts: ContentBlock[];
280
+ /** The `receivedAt` of the first update folded into this message. */
281
+ readonly receivedAt: number;
282
+ }
164
283
  export interface AcpAgentTurnUsage {
165
284
  /** THIS turn's tokens: `response.usage` mapped to `AgentUsage` (every installed adapter reports
166
285
  * the turn, not the session — `PROMPT_USAGE_SCOPES`); `cost` = the clamped delta of the
@@ -185,15 +304,23 @@ export interface AcpAgentTurn {
185
304
  readonly updates: ReadonlyArray<AcpAgentUpdateRecord>;
186
305
  /** Every `raw_message` of this turn (Claude `_claude/sdkMessage`). */
187
306
  readonly raw: ReadonlyArray<AcpAgentRawRecord>;
188
- /** tool_call ⊕ tool_call_update folded by toolCallId, first-seen order. */
307
+ /** tool_call ⊕ tool_call_update folded by toolCallId, first-seen order (the flattening of
308
+ * `messages[*].toolCalls`). */
189
309
  readonly toolCalls: ReadonlyArray<AcpAgentToolCall>;
310
+ /** This turn's messages, folded from `updates` (`AcpAgentMessage`): the per-message view of
311
+ * the same chunks `text` folds, with each message's tool calls and thoughts attached. */
312
+ readonly messages: ReadonlyArray<AcpAgentMessage>;
190
313
  readonly permissions: ReadonlyArray<AcpPermissionEvent>;
191
314
  readonly elicitations: ReadonlyArray<AcpElicitationEvent>;
192
315
  readonly usage: AcpAgentTurnUsage;
193
316
  /** Validated (typebox Convert + Check) when a schema was active for the turn. */
194
317
  readonly structured?: unknown;
195
- /** Why `structured` is absent although a schema was active. */
318
+ /** Why `structured` is absent although a schema was active (the LAST attempt's failure when
319
+ * the repair ladder ran). */
196
320
  readonly structuredError?: string;
321
+ /** When a schema was active: the turns this `prompt()` spent — 1 plus the repair turns the
322
+ * `schemaRetries` ladder actually ran (1 under the default budget of 0). Absent without a schema. */
323
+ readonly structuredAttempts?: number;
197
324
  /** This turn's accumulator entries (copies). Per CHUNK, not per message: one `assistant`/`text`
198
325
  * entry per streamed `agent_message_chunk` and one `tool`/`toolCall` entry per `tool_call`, so
199
326
  * `history.length` is not a message count — `text` is the folded, per-message view. */
@@ -202,8 +329,8 @@ export interface AcpAgentTurn {
202
329
  /** A `prompt()` rejection for a turn the agent walled with a typed session failure (codex-acp's
203
330
  * negotiated extension): the runner's mapped `WorkflowError` (`mapTypedSessionFailure`, so codes,
204
331
  * `recoverable` and `details` keep their tested contract) carrying the COMPLETE turn — verbatim
205
- * `response` incl. `_meta`, `usage`, `updates`, `raw`, `toolCalls`, `history` — so nothing is
206
- * stripped. Narrow with `isAcpAgentTurnError`. */
332
+ * `response` incl. `_meta`, `usage`, `updates`, `raw`, `toolCalls`, `messages`, `history` — so
333
+ * nothing is stripped. Narrow with `isAcpAgentTurnError`. */
207
334
  export type AcpAgentTurnError = WorkflowError & {
208
335
  readonly turn: AcpAgentTurn;
209
336
  };
@@ -212,6 +339,33 @@ export type AcpAgentTurnError = WorkflowError & {
212
339
  export type AcpAgentEventMap = AcpRunnerEventMap;
213
340
  export type AcpAgentEventName = keyof AcpAgentEventMap;
214
341
  export type AcpAgentEventListener<K extends AcpAgentEventName> = (event: AcpAgentEventMap[K]) => void;
342
+ /** The event names `stream()` yields: every bus event except the `session_update` catch-all (an
343
+ * update is yielded once, under its `sessionUpdate` kind). */
344
+ export type AcpAgentStreamEventName = Exclude<AcpAgentEventName, "session_update">;
345
+ /**
346
+ * One item of `agent.stream()`: a bus event of this turn tagged with its name as `type` (the
347
+ * payload is the same object `on(name)` delivers — an ACP update variant plus the event context,
348
+ * or a permission / elicitation / raw_message / steering / session_open / session_close /
349
+ * backend_error payload), or the terminal `{ type: "turn", turn }` carrying the `AcpAgentTurn`
350
+ * `prompt()` would have resolved. Narrow on `type`.
351
+ */
352
+ export type AcpAgentStreamEvent = {
353
+ [K in AcpAgentStreamEventName]: {
354
+ readonly type: K;
355
+ } & AcpAgentEventMap[K];
356
+ }[AcpAgentStreamEventName] | {
357
+ readonly type: "turn";
358
+ readonly turn: AcpAgentTurn;
359
+ };
360
+ /** What `stream()` returns: an async iterable that is its own iterator, with `return()` and
361
+ * `throw()` always present (leaving early is part of the contract — both cancel the turn and
362
+ * resolve once it settled; `throw(error)` then rethrows `error`). */
363
+ export interface AcpAgentStream extends AsyncIterableIterator<AcpAgentStreamEvent> {
364
+ next(): Promise<IteratorResult<AcpAgentStreamEvent, undefined>>;
365
+ return(): Promise<IteratorResult<AcpAgentStreamEvent, undefined>>;
366
+ throw(error?: unknown): Promise<IteratorResult<AcpAgentStreamEvent, undefined>>;
367
+ [Symbol.asyncIterator](): AcpAgentStream;
368
+ }
215
369
  /** `idle` (constructed, nothing spawned) → `opening` → `ready` ⇄ `busy` (a queued op is executing)
216
370
  * → `closed` (set the instant `close()` is called, the constructor signal aborts, or the process
217
371
  * dies). */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,KAAK,EACN,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,WAAW,EACX,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B;;8CAE0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ;;;;wGAIoG;IACpG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;6CAEyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;mGAE+F;IAC/F,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CA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AAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEtG;+DAC+D;AAC/D,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;AAEnF;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAC3B;KAAG,CAAC,IAAI,uBAAuB,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;KAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC;CAAE,CAAC,uBAAuB,CAAC,GACvG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC;AAE3D;;sEAEsE;AACtE,MAAM,WAAW,cAAe,SAAQ,qBAAqB,CAAC,mBAAmB,CAAC;IAChF,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAC;IAChE,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAC;IAClE,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAC;IAChF,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC;CAC1C;AAOD;;aAEa;AACb,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE7E,0FAA0F;AAC1F,eAAO,MAAM,UAAU,EAAE,UAOvB,CAAC"}
package/dist/backend.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { TSchema } from "typebox";
2
- import type { ProviderUsageLimitContext } from "@automatalabs/shared-types";
2
+ import type { ProviderUsageLimitContext, SystemPromptOptions } from "@automatalabs/shared-types";
3
3
  import type { AuthProfile } from "./auth/auth-profile.js";
4
+ import type { SystemPromptSupport } from "./protocol-coverage.js";
4
5
  /** Compatibility type path; the registry table is the only authored built-in identity source. */
5
6
  export type { BuiltinBackendId } from "./backends/builtins.js";
6
7
  /** A backend id: one of the built-ins, or the registered name of a custom ACP backend
@@ -26,10 +27,11 @@ export interface StructuredSource {
26
27
  /** Per-session inputs a backend may fold into its `session/new` `_meta`, beyond the schema.
27
28
  * Additive/optional; a backend that doesn't understand a field ignores it. */
28
29
  export interface SessionMetaInputs {
29
- /** CODEX-ONLY: replaces Codex's base system prompt (`thread/start.baseInstructions`). */
30
- baseInstructions?: string;
31
- /** CODEX-ONLY: developer-role instructions (`thread/start.developerInstructions`). */
32
- developerInstructions?: string;
30
+ /** Backend-neutral system prompt instructions, already validated against `Backend.systemPrompt`
31
+ * (`assertSystemPromptSupported`): the backend maps `replace`/`append` onto its own
32
+ * `_meta` dialect — Codex `baseInstructions`/`developerInstructions`, Claude and pi
33
+ * `systemPrompt`. A backend that declares no support never sees a defined value. */
34
+ systemPrompt?: SystemPromptOptions;
33
35
  /** Engine run correlation id. Backends may use it to suppress autonomous session work. */
34
36
  runId?: string;
35
37
  /** Human-readable occurrence label associated with `runId`; never sent unless a backend uses it. */
@@ -66,6 +68,12 @@ export interface Backend {
66
68
  * initialized agent strictly advertises HTTP MCP support. Native schema channels leave this
67
69
  * unset; custom ACP backends opt in unless their registry entry disables it. */
68
70
  readonly injectStructuredOutputTool?: boolean;
71
+ /** Which halves of `SystemPromptOptions` this backend can carry on its session `_meta`
72
+ * (`SYSTEM_PROMPT_SUPPORT` for the built-ins). Undefined = neither: a `systemPrompt` for such a
73
+ * backend is rejected before a session opens — SCRIPT_VALIDATION_ERROR from the runner and
74
+ * `InteractiveSession`, INVALID_ARGUMENT from the AcpAgent SDK — so instructions are never
75
+ * silently dropped. */
76
+ readonly systemPrompt?: SystemPromptSupport;
69
77
  /** OPTIONAL `initialize.clientCapabilities._meta` this backend adds: the namespaced vendor
70
78
  * extensions THIS CLIENT implements for that agent, so the agent may turn them on. Backend-scoped
71
79
  * on purpose — advertising a capability to an agent that does not implement it is noise, and
@@ -1 +1 @@
1
- {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,iGAAiG;AACjG,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D;sFACsF;AACtF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACxB;AAED,8FAA8F;AAC9F,MAAM,WAAW,gBAAgB;IAC/B,8FAA8F;IAC9F,eAAe,IAAI,MAAM,CAAC;IAC1B;;;4FAGwF;IACxF,gBAAgB,IAAI,MAAM,CAAC;IAC3B,uGAAuG;IACvG,mBAAmB,IAAI,OAAO,CAAC;CAChC;AAED;+EAC+E;AAC/E,MAAM,WAAW,iBAAiB;IAChC,yFAAyF;IACzF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sFAAsF;IACtF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,0FAA0F;IAC1F,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oGAAoG;IACpG,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,8FAA8F;AAC9F,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,gFAAgF;AAChF,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,yBAAyB,CAAC;CACpC,CAAC;AAEF,MAAM,WAA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MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACxD;;iDAE6C;IAC7C,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC7E,oGAAoG;IACpG,gBAAgB,CAAC,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC;CACtD;AAED,6FAA6F;AAC7F,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAE7D"}
@@ -11,6 +11,10 @@ export declare class ClaudeBackend implements Backend {
11
11
  classifyProviderError(error: unknown, metadata?: ProviderErrorMetadata): ProviderErrorClassification | undefined;
12
12
  spawnConfig(): SpawnConfig;
13
13
  sessionMetaDefaults(inputs?: SessionMetaInputs): Record<string, unknown> | undefined;
14
+ /** claude-agent-acp reads `_meta.systemPrompt` at session creation (new, resume, load, and the
15
+ * reattach an id-only fork needs): a string replaces the prompt, `{ append }` extends the
16
+ * `claude_code` preset. */
17
+ readonly systemPrompt: import("../protocol-coverage.js").SystemPromptSupport;
14
18
  sessionMeta(schema: TSchema | undefined, inputs?: SessionMetaInputs): Record<string, unknown> | undefined;
15
19
  promptMeta(): Record<string, unknown> | undefined;
16
20
  rawMessagesMeta(): Record<string, unknown> | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/backends/claude.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EACV,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EACjB,MAAM,eAAe,CAAC;AASvB,+FAA+F;AAC/F,eAAO,MAAM,iBAAiB,EAAE,WAK/B,CAAC;AAEF,qBAAa,aA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AC,EAAE,EAAG,QAAQ,CAAU;IAChC,QAAQ,CAAC,aAAa,EAAG,MAAM,CAAU;gBAEpB,WAAW,GAAE,WAA+B;IAEjE,qBAAqB,CACnB,KAAK,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE,qBAAqB,GAC/B,2BAA2B,GAAG,SAAS;IAa1C,WAAW,IAAI,WAAW;IAgB1B,mBAAmB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAMpF;;gCAE4B;IAC5B,QAAQ,CAAC,YAAY,wDAAiC;IAEtD,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAwBzG,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAKjD,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAMtD,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO;CAGpD;AAsBD,eAAO,MAAM,uBAAuB,0DA2BlC,CAAC"}
@@ -5,8 +5,9 @@
5
5
  // The parsed object lands on SDKResultSuccess.structured_output, observable ONLY off the raw
6
6
  // `_claude/sdkMessage` extension notification (the runner's ACP client captures it).
7
7
  import { createRequire } from "node:module";
8
+ import { META_KEYS, } from "@automatalabs/shared-types";
8
9
  import { splitArgs } from "../backend.js";
9
- import { BUILTIN_PROTOCOL_COVERAGE } from "../protocol-coverage.js";
10
+ import { BUILTIN_PROTOCOL_COVERAGE, systemPromptSupport } from "../protocol-coverage.js";
10
11
  import { toAnthropicJsonSchema } from "../schema-strict.js";
11
12
  import { defineBuiltinBackend } from "./define.js";
12
13
  const require = createRequire(import.meta.url);
@@ -59,28 +60,33 @@ export class ClaudeBackend {
59
60
  return undefined;
60
61
  return { claudeCode: { options: { title } } };
61
62
  }
63
+ /** claude-agent-acp reads `_meta.systemPrompt` at session creation (new, resume, load, and the
64
+ * reattach an id-only fork needs): a string replaces the prompt, `{ append }` extends the
65
+ * `claude_code` preset. */
66
+ systemPrompt = systemPromptSupport("claude");
62
67
  sessionMeta(schema, inputs) {
63
- // Claude has no analog to Codex's base/developer instruction overrides. For engine runs, set
64
- // the SDK session title up front: claude-agent-acp >=0.71 otherwise launches an unobserved
65
- // background small-model title-generation call after the first turn. Interactive sessions
66
- // have no runId and retain the adapter's generated-title behavior.
67
- if (!schema)
68
- return undefined;
69
- // Anthropic structured outputs accept only a JSON-Schema subset (additionalProperties:false
70
- // required on every object; numeric/string/array constraints rejected). Normalize the wire
71
- // copy so the native constraint always engages — an incompatible schema would fail the SDK
72
- // constraint and silently degrade the run to unconstrained text + the repair ladder.
73
- const title = workflowSessionTitle(inputs);
74
- const meta = {
75
- claudeCode: {
68
+ const meta = {};
69
+ if (schema) {
70
+ // Anthropic structured outputs accept only a JSON-Schema subset (additionalProperties:false
71
+ // required on every object; numeric/string/array constraints rejected). Normalize the wire
72
+ // copy so the native constraint always engages — an incompatible schema would fail the SDK
73
+ // constraint and silently degrade the run to unconstrained text + the repair ladder.
74
+ // For engine runs, set the SDK session title up front: claude-agent-acp >=0.71 otherwise
75
+ // launches an unobserved background small-model title-generation call after the first
76
+ // turn. Interactive sessions have no runId and retain the adapter's generated-title behavior.
77
+ const title = workflowSessionTitle(inputs);
78
+ meta.claudeCode = {
76
79
  options: {
77
80
  ...(title ? { title } : {}),
78
81
  outputFormat: { type: "json_schema", schema: toAnthropicJsonSchema(schema) },
79
82
  },
80
83
  emitRawSDKMessages: true,
81
- },
82
- };
83
- return meta;
84
+ };
85
+ }
86
+ const systemPrompt = claudeSystemPromptMeta(inputs?.systemPrompt);
87
+ if (systemPrompt !== undefined)
88
+ meta[META_KEYS.systemPrompt] = systemPrompt;
89
+ return Object.keys(meta).length > 0 ? meta : undefined;
84
90
  }
85
91
  promptMeta() {
86
92
  // Claude's schema is session-scoped (read at session/new); nothing on the turn.
@@ -95,6 +101,23 @@ export class ClaudeBackend {
95
101
  return source.rawStructuredOutput();
96
102
  }
97
103
  }
104
+ /** Fold the neutral instructions into claude-agent-acp's single `systemPrompt` slot. The adapter
105
+ * takes EITHER a full replacement string OR preset options (`{ append }` on the `claude_code`
106
+ * preset) — there is no "custom base plus append" form — so `replace` + `append` together become
107
+ * one replacement string: the replaced prompt followed by the appended text, joined by a blank
108
+ * line (exactly what the caller asked for; the seam documents the join). */
109
+ function claudeSystemPromptMeta(options) {
110
+ if (!options)
111
+ return undefined;
112
+ const { replace, append } = options;
113
+ if (replace !== undefined && append !== undefined)
114
+ return `${replace}\n\n${append}`;
115
+ if (replace !== undefined)
116
+ return replace;
117
+ if (append !== undefined)
118
+ return { append };
119
+ return undefined;
120
+ }
98
121
  function workflowSessionTitle(inputs) {
99
122
  if (!inputs?.runId)
100
123
  return undefined;
@@ -20,6 +20,11 @@ export declare class CodexBackend implements Backend {
20
20
  * channel's own equivalents are mapped by `mapTypedSessionFailure`. */
21
21
  classifyProviderError(error: unknown, metadata?: ProviderErrorMetadata): ProviderErrorClassification | undefined;
22
22
  spawnConfig(): SpawnConfig;
23
+ /** The fork reads bare `_meta.baseInstructions` (replaces Codex's base system prompt) and
24
+ * `_meta.developerInstructions` (developer-role instructions on top of it) at session/new,
25
+ * resume, load, AND fork — a Codex fork is live (no reattach), so the `session/fork` request's
26
+ * own `_meta` is the only delivery and the adapter threads it into thread/fork. */
27
+ readonly systemPrompt: import("../protocol-coverage.js").SystemPromptSupport;
23
28
  sessionMeta(_schema: TSchema | undefined, inputs?: SessionMetaInputs): Record<string, unknown> | undefined;
24
29
  promptMeta(schema: TSchema | undefined): Record<string, unknown> | undefined;
25
30
  nativeStructured(source: StructuredSource): unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/backends/codex.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO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AqB,EACrB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAUvB,6FAA6F;AAC7F,eAAO,MAAM,gBAAgB,EAAE,WAe9B,CAAC;AAEF,qBAAa,YAAa,YAAW,OAAO;IAI9B,QAAQ,CAAC,WAAW,EAAE,WAAW;IAH7C,QAAQ,CAAC,EAAE,EAAG,OAAO,CAAU;IAC/B,QAAQ,CAAC,aAAa,EAAG,OAAO,CAAU;gBAErB,WAAW,GAAE,WAA8B;IAEhE;;;qGAGiG;IACjG,QAAQ,CAAC,oBAAoB,oCAA2C;IAExE;;;;4EAIwE;IACxE,qBAAqB,CACnB,KAAK,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE,qBAAqB,GAC/B,2BAA2B,GAAG,SAAS;IAW1C,WAAW,IAAI,WAAW;IAe1B;;;wFAGoF;IACpF,QAAQ,CAAC,YAAY,wDAAgC;IAErD,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAa1G,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAK5E,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO;CAMpD;AAED,eAAO,MAAM,sBAAsB,yDAwBjC,CAAC"}
@@ -11,7 +11,7 @@
11
11
  import { createRequire } from "node:module";
12
12
  import { CODEX_META_KEYS, META_KEYS } from "@automatalabs/shared-types";
13
13
  import { splitArgs } from "../backend.js";
14
- import { BUILTIN_PROTOCOL_COVERAGE } from "../protocol-coverage.js";
14
+ import { BUILTIN_PROTOCOL_COVERAGE, systemPromptSupport } from "../protocol-coverage.js";
15
15
  import { toStrictJsonSchema } from "../schema-strict.js";
16
16
  import { parseFinalJson } from "../structured-output.js";
17
17
  import { TYPED_SESSION_FAILURE_CLIENT_CAPABILITY } from "../typed-failures.js";
@@ -75,17 +75,23 @@ export class CodexBackend {
75
75
  const bin = env.AGENTPRISM_CODEX_ACP_BIN ?? require.resolve("@automatalabs/codex-acp");
76
76
  return { command: process.execPath, args: [bin], env };
77
77
  }
78
+ /** The fork reads bare `_meta.baseInstructions` (replaces Codex's base system prompt) and
79
+ * `_meta.developerInstructions` (developer-role instructions on top of it) at session/new,
80
+ * resume, load, AND fork — a Codex fork is live (no reattach), so the `session/fork` request's
81
+ * own `_meta` is the only delivery and the adapter threads it into thread/fork. */
82
+ systemPrompt = systemPromptSupport("codex");
78
83
  sessionMeta(_schema, inputs) {
79
84
  // Codex carries the SCHEMA on the turn (see promptMeta), so nothing schema-related rides
80
- // session/new. But the optional base/developer instruction overrides ARE session-scoped: the
81
- // @automatalabs/codex-acp fork reads these bare `_meta` keys and threads them into
82
- // thread/start.{baseInstructions,developerInstructions}. Emit them only when set so an
83
- // unconfigured run sends no `_meta` at all (preserving the "Codex default" path).
85
+ // session/new. The neutral system-prompt instructions ARE session-scoped: the
86
+ // @automatalabs/codex-acp fork reads the bare `_meta` keys and threads them into
87
+ // thread/{start,resume,fork}.{baseInstructions,developerInstructions}. Emit them only when set so
88
+ // an unconfigured run sends no `_meta` at all (preserving the "Codex default" path).
84
89
  const meta = {};
85
- if (inputs?.baseInstructions !== undefined)
86
- meta[CODEX_META_KEYS.baseInstructions] = inputs.baseInstructions;
87
- if (inputs?.developerInstructions !== undefined)
88
- meta[CODEX_META_KEYS.developerInstructions] = inputs.developerInstructions;
90
+ const systemPrompt = inputs?.systemPrompt;
91
+ if (systemPrompt?.replace !== undefined)
92
+ meta[CODEX_META_KEYS.baseInstructions] = systemPrompt.replace;
93
+ if (systemPrompt?.append !== undefined)
94
+ meta[CODEX_META_KEYS.developerInstructions] = systemPrompt.append;
89
95
  return Object.keys(meta).length > 0 ? meta : undefined;
90
96
  }
91
97
  promptMeta(schema) {
@@ -1 +1 @@
1
- {"version":3,"file":"custom.d.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,CAAC,QAAQ,CAAC,MAAM;IAVnC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;mGAC+F;IAC/F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;oFAEgF;IAChF,QAAQ,CAAC,mBAAmB,QAAQ;IACpC,QAAQ,CAAC,0BAA0B,EAAE,OAAO,CAAC;gBAEhB,MAAM,EAAE,iBAAiB;IAWtD,WAAW,IAAI,WAAW;IAS1B,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAQ1D,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAM9E,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAQ5E,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO;CAKpD"}
@@ -11,8 +11,9 @@
11
11
  // - config-level `_meta`: the registry entry's static `sessionMeta` rides every session/new
12
12
  // (per-call RunOptions.meta merges over it in the ACP client; backend-computed
13
13
  // keys and the runId stamp win over both).
14
- // SessionMetaInputs (Codex base/developer instruction overrides) are IGNORED — they are a
15
- // codex-acp vendor contract; a custom agent's knobs travel through the generic meta channels.
14
+ // The neutral `systemPrompt` instructions are NOT carried (`Backend.systemPrompt` undefined): ACP
15
+ // has no standard system-prompt key, so the validators refuse them for a custom backend up front
16
+ // and a custom agent's own knobs travel through the generic meta channels instead.
16
17
  import { createHash } from "node:crypto";
17
18
  import { META_KEYS } from "@automatalabs/shared-types";
18
19
  import { toJsonSchema } from "../schema-strict.js";
@@ -12,6 +12,10 @@ export declare class OpenCodeBackend implements Backend {
12
12
  readonly injectStructuredOutputTool = true;
13
13
  classifyProviderError(error: unknown, metadata?: ProviderErrorMetadata): ProviderErrorClassification | undefined;
14
14
  spawnConfig(): SpawnConfig;
15
+ /** `opencode acp` reads no session `_meta` (its ACP service consults `_meta` only for
16
+ * terminal-auth at initialize); system prompts live in OpenCode's own config and agent
17
+ * definitions. Declared unsupported so a `systemPrompt` is refused, never dropped. */
18
+ readonly systemPrompt: import("../protocol-coverage.js").SystemPromptSupport;
15
19
  sessionMeta(): Record<string, unknown> | undefined;
16
20
  promptMeta(schema: TSchema | undefined): Record<string, unknown> | undefined;
17
21
  nativeStructured(source: StructuredSource): unknown;