@jini-ai/daemon 0.3.8 → 0.5.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 (173) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/README.md +50 -8
  3. package/dist/agent-executor/contracts.d.ts +736 -0
  4. package/dist/agent-executor/contracts.js +28 -0
  5. package/dist/agent-executor/event-translation.d.ts +87 -0
  6. package/dist/agent-executor/event-translation.js +230 -0
  7. package/dist/agent-executor/events.d.ts +190 -0
  8. package/dist/agent-executor/events.js +848 -0
  9. package/dist/agent-executor/handoff.d.ts +18 -0
  10. package/dist/agent-executor/handoff.js +16 -0
  11. package/dist/agent-executor/index.d.ts +98 -0
  12. package/dist/agent-executor/index.js +98 -0
  13. package/dist/agent-executor/launch.d.ts +375 -0
  14. package/dist/agent-executor/launch.js +1001 -0
  15. package/dist/agent-executor/mcp-bridge.d.ts +338 -0
  16. package/dist/agent-executor/mcp-bridge.js +835 -0
  17. package/dist/agent-executor/values.d.ts +5 -0
  18. package/dist/agent-executor/values.js +13 -0
  19. package/dist/agent-executor.d.ts +375 -176
  20. package/dist/agent-executor.js +388 -335
  21. package/dist/artifacts/index.d.ts +14 -0
  22. package/dist/artifacts/index.js +14 -0
  23. package/dist/artifacts/manifest.d.ts +90 -0
  24. package/dist/artifacts/manifest.js +229 -0
  25. package/dist/artifacts/publication-guard.d.ts +28 -0
  26. package/dist/artifacts/publication-guard.js +77 -0
  27. package/dist/artifacts/runtime-compat.d.ts +37 -0
  28. package/dist/artifacts/runtime-compat.js +33 -0
  29. package/dist/artifacts/store.d.ts +85 -0
  30. package/dist/artifacts/store.js +92 -0
  31. package/dist/artifacts/stub-guard.d.ts +73 -0
  32. package/dist/artifacts/stub-guard.js +198 -0
  33. package/dist/artifacts/text-suppression.d.ts +68 -0
  34. package/dist/artifacts/text-suppression.js +184 -0
  35. package/dist/close-status.d.ts +11 -8
  36. package/dist/close-status.js +31 -19
  37. package/dist/continuation/continuation-transport.d.ts +3 -1
  38. package/dist/continuation/continuation-transport.js +1 -1
  39. package/dist/continuation/journal.d.ts +12 -5
  40. package/dist/continuation/journal.js +4 -4
  41. package/dist/continuation/run-scoped-context-store.d.ts +13 -4
  42. package/dist/continuation/run-scoped-context-store.js +6 -6
  43. package/dist/continuation/run-start-handler.d.ts +1 -1
  44. package/dist/continuation/run-start-handler.js +3 -16
  45. package/dist/delegated-tool-bridge.d.ts +7 -3
  46. package/dist/delegated-tool-bridge.js +32 -31
  47. package/dist/event-log.d.ts +7 -5
  48. package/dist/event-log.js +12 -11
  49. package/dist/frontend-capability-tools.d.ts +1 -1
  50. package/dist/frontend-capability-tools.js +3 -2
  51. package/dist/frontend-session-registry.d.ts +32 -9
  52. package/dist/frontend-session-registry.js +12 -11
  53. package/dist/http/active-context.d.ts +105 -0
  54. package/dist/http/active-context.js +67 -0
  55. package/dist/http/agents.d.ts +68 -0
  56. package/dist/http/agents.js +12 -0
  57. package/dist/http/attachments.d.ts +618 -0
  58. package/dist/http/attachments.js +1034 -0
  59. package/dist/http/cancel-owned-runs.d.ts +49 -0
  60. package/dist/http/cancel-owned-runs.js +35 -0
  61. package/dist/http/component-catalog.d.ts +84 -0
  62. package/dist/http/component-catalog.js +64 -0
  63. package/dist/http/connectors.d.ts +209 -0
  64. package/dist/http/connectors.js +409 -0
  65. package/dist/http/daemon-status.d.ts +76 -0
  66. package/dist/http/daemon-status.js +55 -0
  67. package/dist/http/db-ops.d.ts +123 -0
  68. package/dist/http/db-ops.js +189 -0
  69. package/dist/http/delegated-tools.d.ts +113 -0
  70. package/dist/http/delegated-tools.js +230 -0
  71. package/dist/http/frontend-control.d.ts +136 -0
  72. package/dist/http/frontend-control.js +79 -0
  73. package/dist/http/frontend-sessions.d.ts +110 -0
  74. package/dist/http/frontend-sessions.js +180 -0
  75. package/dist/http/health.d.ts +95 -0
  76. package/dist/http/health.js +40 -0
  77. package/dist/http/host-tools.d.ts +214 -0
  78. package/dist/http/host-tools.js +329 -0
  79. package/dist/http/index.d.ts +52 -0
  80. package/dist/http/index.js +27 -0
  81. package/dist/http/media.d.ts +146 -0
  82. package/dist/http/media.js +346 -0
  83. package/dist/http/memory.d.ts +265 -0
  84. package/dist/http/memory.js +328 -0
  85. package/dist/http/model-proxy.d.ts +49 -0
  86. package/dist/http/model-proxy.js +642 -0
  87. package/dist/http/remote-run-events.d.ts +70 -0
  88. package/dist/http/remote-run-events.js +224 -0
  89. package/dist/http/research.d.ts +48 -0
  90. package/dist/http/research.js +315 -0
  91. package/dist/http/route-manifest.d.ts +35 -0
  92. package/dist/http/route-manifest.js +103 -0
  93. package/dist/http/routines.d.ts +120 -0
  94. package/dist/http/routines.js +298 -0
  95. package/dist/http/run-credentials.d.ts +73 -0
  96. package/dist/http/run-credentials.js +71 -0
  97. package/dist/http/runs.d.ts +91 -0
  98. package/dist/http/runs.js +221 -0
  99. package/dist/http/terminals.d.ts +138 -0
  100. package/dist/http/terminals.js +325 -0
  101. package/dist/http/tool-catalog.d.ts +78 -0
  102. package/dist/http/tool-catalog.js +66 -0
  103. package/dist/http/workspace-root.d.ts +77 -0
  104. package/dist/http/workspace-root.js +63 -0
  105. package/dist/http/xai.d.ts +90 -0
  106. package/dist/http/xai.js +655 -0
  107. package/dist/image-prompt-delivery.d.ts +13 -3
  108. package/dist/image-prompt-delivery.js +5 -5
  109. package/dist/index.d.ts +556 -4
  110. package/dist/index.js +556 -4
  111. package/dist/legacy-data-migration.d.ts +59 -8
  112. package/dist/legacy-data-migration.js +38 -33
  113. package/dist/read-only-tools.d.ts +130 -0
  114. package/dist/read-only-tools.js +115 -0
  115. package/dist/remote-tool-bridge.d.ts +11 -5
  116. package/dist/remote-tool-bridge.js +15 -15
  117. package/dist/routines/index.d.ts +1 -1
  118. package/dist/routines/index.js +1 -1
  119. package/dist/routines/routine-store.d.ts +34 -12
  120. package/dist/routines/routine-store.js +21 -20
  121. package/dist/routines/schedule.d.ts +48 -10
  122. package/dist/routines/schedule.js +21 -21
  123. package/dist/routines/scheduler.d.ts +32 -11
  124. package/dist/routines/scheduler.js +61 -57
  125. package/dist/routines/types.d.ts +10 -3
  126. package/dist/run/core/result.d.ts +6 -2
  127. package/dist/run/core/result.js +3 -3
  128. package/dist/run/core/retry.d.ts +17 -4
  129. package/dist/run/core/retry.js +7 -11
  130. package/dist/run/diagnostics/diagnostics.d.ts +14 -4
  131. package/dist/run/diagnostics/diagnostics.js +7 -7
  132. package/dist/run/index.d.ts +1 -1
  133. package/dist/run/index.js +1 -1
  134. package/dist/run-credentials.d.ts +138 -0
  135. package/dist/run-credentials.js +152 -0
  136. package/dist/run-lifecycle.d.ts +92 -33
  137. package/dist/run-lifecycle.js +81 -74
  138. package/dist/scheduler.d.ts +8 -0
  139. package/dist/scheduler.js +2 -0
  140. package/dist/session-coordination.d.ts +115 -0
  141. package/dist/session-coordination.js +111 -0
  142. package/dist/store/agent-sessions/errors.d.ts +8 -0
  143. package/dist/store/agent-sessions/errors.js +10 -0
  144. package/dist/store/agent-sessions/index.d.ts +12 -0
  145. package/dist/store/agent-sessions/index.js +19 -0
  146. package/dist/store/agent-sessions/pglite.d.ts +12 -0
  147. package/dist/store/agent-sessions/pglite.js +7 -0
  148. package/dist/store/agent-sessions/ports.d.ts +24 -0
  149. package/dist/store/agent-sessions/ports.js +2 -0
  150. package/dist/store/agent-sessions/postgres.d.ts +12 -0
  151. package/dist/store/agent-sessions/postgres.js +7 -0
  152. package/dist/store/agent-sessions/schema.d.ts +3 -0
  153. package/dist/store/agent-sessions/schema.js +23 -0
  154. package/dist/store/agent-sessions/sql.d.ts +35 -0
  155. package/dist/store/agent-sessions/sql.js +59 -0
  156. package/dist/store/agent-sessions/sqlite.d.ts +117 -0
  157. package/dist/store/agent-sessions/sqlite.js +128 -0
  158. package/dist/store/event-log/sqlite.d.ts +75 -0
  159. package/dist/store/event-log/sqlite.js +230 -0
  160. package/dist/surface-exchanges.d.ts +97 -0
  161. package/dist/surface-exchanges.js +153 -0
  162. package/dist/terminal-session.d.ts +43 -11
  163. package/dist/terminal-session.js +22 -20
  164. package/dist/tokens.js +4 -4
  165. package/dist/tool-audit.d.ts +114 -0
  166. package/dist/tool-audit.js +95 -0
  167. package/dist/tool-executor.d.ts +22 -7
  168. package/dist/tool-executor.js +16 -16
  169. package/dist/tool-result-media.d.ts +3 -1
  170. package/dist/tool-result-media.js +1 -1
  171. package/dist/tool-result-surfaces.d.ts +3 -1
  172. package/dist/tool-result-surfaces.js +1 -1
  173. package/package.json +127 -9
@@ -81,10 +81,10 @@
81
81
  * byte-identical to pre-gap-4 behavior — every `'failed'` outcome
82
82
  * resumable:false). OD's ~20-vendor-CLI text-matching failure classifier was
83
83
  * deliberately never ported (see `run/core/failure-taxonomy.ts`'s own doc and
84
- * `source-map.md`). The real zero-config classifier lives in `@jini-ai/daemon`'s
84
+ * `archived provenance ledger`). The real zero-config classifier lives in `@jini-ai/daemon`'s
85
85
  * `run/core/retry.ts` (`resumableFromProcessExit`/`classifyProcessExitFailure`)
86
86
  * and is wired in by `@jini-ai/server`'s `createLocalNodeDaemon` — see that
87
- * package's own source-map.md, and `run/core/retry.ts`'s own doc for the
87
+ * package's own archived provenance ledger, and `run/core/retry.ts`'s own doc for the
88
88
  * classification policy and its 2026-07-22 merge-time reconciliation against
89
89
  * a second, independently-built (and rejected) classifier that once lived in
90
90
  * this module.
@@ -93,7 +93,7 @@ import { spawn as nodeSpawn, type ChildProcess } from 'node:child_process';
93
93
  import type { Principal } from '@jini-ai/core';
94
94
  import type { RunAgentPayload, RunErrorPayload } from '@jini-ai/protocol';
95
95
  import { applyAgentLaunchEnv, ensureAgentCapabilities, getAgentDef, resolveAgentLaunch, attachAcpSession, attachPiRpcSession, prepareAgentLogFile, preparePromptFileForAgent, type AcpMcpServerInput, type AcpPermissionHandler, type AgentLaunchResolution, type PreparedAgentLogFile, type PreparedPromptFile, type PromptAugmenter, type RuntimeAgentDef, type RuntimeBuildOptions, type RuntimeContext, type RuntimeLockHold } from '@jini-ai/agent-runtime';
96
- import { collectProcessTreePids, createCommandInvocation, listProcessSnapshots, stopProcesses, type ProcessSnapshot, type StopProcessesResult } from '@jini-ai/platform';
96
+ import { createCommandInvocation, listProcessSnapshots, type ProcessSnapshot, type StopProcessesResult } from '@jini-ai/platform';
97
97
  import type { RunByteJournal } from './continuation/journal.js';
98
98
  import { type ImagePromptDelivery } from './image-prompt-delivery.js';
99
99
  import type { RunRetrySideEffectState } from './run/core/index.js';
@@ -122,7 +122,11 @@ type ChildDrivenStreamFormat = JsonStreamFormat | 'plain';
122
122
  * @complexity O(1) — fixed membership check.
123
123
  * @overallScore 100/100
124
124
  */
125
- export declare function isSupportedStreamFormat(value: string): value is SupportedStreamFormat;
125
+ export declare function isSupportedStreamFormat(args: {
126
+ readonly value: string;
127
+ }): args is {
128
+ readonly value: SupportedStreamFormat;
129
+ };
126
130
  /**
127
131
  * Whether `run()` can drive a given def, and — when it can — its `streamFormat` already narrowed for
128
132
  * the dispatch logic that follows. The narrowing rides along deliberately: it is what lets `run()`
@@ -157,7 +161,9 @@ export type AgentExecutorCompatibility = {
157
161
  * @complexity O(1) — fixed field checks.
158
162
  * @overallScore 100/100
159
163
  */
160
- export declare function assessAgentExecutorCompatibility(def: RuntimeAgentDef): AgentExecutorCompatibility;
164
+ export declare function assessAgentExecutorCompatibility({ def }: {
165
+ readonly def: RuntimeAgentDef;
166
+ }): AgentExecutorCompatibility;
161
167
  /**
162
168
  * Whether `run()` can actually drive this def — the discovery-time counterpart to the guards inside
163
169
  * `run()`, so a consumer never offers a user an agent that fails the moment it is selected.
@@ -168,7 +174,9 @@ export declare function assessAgentExecutorCompatibility(def: RuntimeAgentDef):
168
174
  * @complexity O(1).
169
175
  * @overallScore 100/100
170
176
  */
171
- export declare function isAgentExecutorSupported(def: RuntimeAgentDef): boolean;
177
+ export declare function isAgentExecutorSupported({ def }: {
178
+ readonly def: RuntimeAgentDef;
179
+ }): boolean;
172
180
  /**
173
181
  * Result of translating one parsed stream event into this engine's
174
182
  * vocabulary. `'agent'` is the common case (forward as a `RunAgentPayload`
@@ -194,7 +202,7 @@ export declare function isAgentExecutorSupported(def: RuntimeAgentDef): boolean;
194
202
  * `tool_use` block in the same assistant message has already been
195
203
  * translated (so a caller can decide whether to keep stdin open before
196
204
  * closing it), but v1 (pre-gap-3) discarded it and closed stdin
197
- * unconditionally on any `turn-end` — see `packages/daemon/source-map.md`'s
205
+ * unconditionally on any `turn-end` — see `packages/daemon/archived provenance ledger`'s
198
206
  * "Design decision 2" note. `wireChildLifecycle` now reads it to decide
199
207
  * whether `stop_reason: 'tool_use'` means "inject a tool result and keep
200
208
  * going" (gap 3, gated — see `ContinuationOptions`) or "close stdin as
@@ -222,14 +230,24 @@ export type AgentRuntimeEventTranslation = {
222
230
  * original "omit the whole `usage` field rather than emit an empty object" behavior.
223
231
  * @complexity O(1).
224
232
  */
225
- export declare function extractUsageTokens(rawUsage: Record<string, unknown> | undefined): {
233
+ export declare function extractUsageTokens({ rawUsage }: {
234
+ readonly rawUsage: Record<string, unknown> | undefined;
235
+ }): {
226
236
  input_tokens?: number;
227
237
  output_tokens?: number;
228
238
  } | undefined;
229
- export declare function translateStatusEvent(rawEvent: Record<string, unknown>): AgentRuntimeEventTranslation;
230
- export declare function translateToolResultEvent(rawEvent: Record<string, unknown>): AgentRuntimeEventTranslation;
231
- export declare function translateErrorEvent(rawEvent: Record<string, unknown>): AgentRuntimeEventTranslation;
232
- export declare function translateTurnEndEvent(rawEvent: Record<string, unknown>): AgentRuntimeEventTranslation;
239
+ export declare function translateStatusEvent({ rawEvent }: {
240
+ readonly rawEvent: Record<string, unknown>;
241
+ }): AgentRuntimeEventTranslation;
242
+ export declare function translateToolResultEvent({ rawEvent }: {
243
+ readonly rawEvent: Record<string, unknown>;
244
+ }): AgentRuntimeEventTranslation;
245
+ export declare function translateErrorEvent({ rawEvent }: {
246
+ readonly rawEvent: Record<string, unknown>;
247
+ }): AgentRuntimeEventTranslation;
248
+ export declare function translateTurnEndEvent({ rawEvent }: {
249
+ readonly rawEvent: Record<string, unknown>;
250
+ }): AgentRuntimeEventTranslation;
233
251
  /**
234
252
  * Narrows one parser-emitted `{type, ...}` record into this engine's
235
253
  * `RunAgentPayload` union (or the `error`/`turn-end`/`ignored` routing
@@ -252,13 +270,18 @@ export declare function translateTurnEndEvent(rawEvent: Record<string, unknown>)
252
270
  * @complexity O(1) — one table lookup, no iteration.
253
271
  * @overallScore 100/100
254
272
  */
255
- export declare function translateAgentRuntimeEvent(rawEvent: unknown): AgentRuntimeEventTranslation;
273
+ export declare function translateAgentRuntimeEvent({ rawEvent }: {
274
+ readonly rawEvent: unknown;
275
+ }): AgentRuntimeEventTranslation;
256
276
  /** Machine-readable failure reasons `run()` can reject with — every one is preceded by a `lifecycle.finish({status:'failed'})` call (see module doc's Invariant section). */
257
- export type AgentExecutorErrorCode = 'AGENT_NOT_FOUND' | 'AGENT_RUNTIME_UNSUPPORTED' | 'AGENT_BINARY_NOT_RESOLVED' | 'AGENT_SPAWN_FAILED' | 'AGENT_PROMPT_TOO_LARGE';
277
+ export type AgentExecutorErrorCode = 'AGENT_PERMISSION_MODE_INVALID' | 'AGENT_NOT_FOUND' | 'AGENT_RUNTIME_UNSUPPORTED' | 'AGENT_BINARY_NOT_RESOLVED' | 'AGENT_SPAWN_FAILED' | 'AGENT_PROMPT_TOO_LARGE';
258
278
  /** Thrown by `AgentExecutor.run()` on every failure path — never a bare `Error`, so callers can branch on `.code` instead of parsing `.message`. */
259
279
  export declare class AgentExecutorError extends Error {
260
280
  readonly code: AgentExecutorErrorCode;
261
- constructor(code: AgentExecutorErrorCode, message: string);
281
+ constructor({ code, message }: {
282
+ readonly code: AgentExecutorErrorCode;
283
+ readonly message: string;
284
+ });
262
285
  }
263
286
  export interface AgentExecutorRunInput {
264
287
  readonly runId: string;
@@ -272,9 +295,10 @@ export interface AgentExecutorRunInput {
272
295
  /**
273
296
  * Forwarded verbatim to `RuntimeBuildOptions.permissionMode` (see `@jini-ai/agent-runtime`'s
274
297
  * `types.ts`). Every def that has an auto-approve flag (`bypassPermissions` / `--yolo` /
275
- * `--dangerously-skip-permissions`) uses it by default when this is omitted — unchanged
276
- * behavior, since there is no TTY on a spawned subprocess to answer an interactive prompt.
277
- * A host that wants a run to NOT auto-approve every action passes `'restricted'` here.
298
+ * `--dangerously-skip-permissions`) historically enabled it when omitted because a spawned
299
+ * subprocess has no TTY for interactive approval. That rationale explains the old behavior;
300
+ * the daemon now fails closed with 'restricted'. A host must explicitly select 'bypass' to
301
+ * delegate auto-approval, and any unknown mode is rejected before launching a process.
278
302
  */
279
303
  readonly permissionMode?: 'bypass' | 'restricted';
280
304
  /**
@@ -351,12 +375,20 @@ export interface AgentExecutor {
351
375
  * underlying run is always already transitioned to `'failed'` via
352
376
  * `lifecycle.finish()` before this rejects (see module doc's Invariant).
353
377
  */
354
- run(input: AgentExecutorRunInput): Promise<void>;
378
+ run(requiredArgs: Pick<AgentExecutorRunInput, "runId" | "agentId" | "prompt" | "cwd">, optionalArgs?: Pick<AgentExecutorRunInput, "model" | "reasoning" | "permissionMode" | "imagePaths" | "extraAllowedDirs" | "uploadRoot" | "credentialEnv" | "env" | "resumeSessionId" | "newSessionId" | "disallowedTools" | "allowedTools" | "settingSources" | "settings">): Promise<void>;
355
379
  }
380
+ /** Process discovery is a getter; process collection and stopping accept explicit host inputs. */
381
+ export type CollectProcessTreePidsPort = (args: {
382
+ readonly processes: ProcessSnapshot[];
383
+ readonly rootPids: Array<number | null | undefined>;
384
+ }) => number[];
385
+ export type StopProcessesPort = (args: {
386
+ readonly pids: Array<number | null | undefined>;
387
+ }) => Promise<StopProcessesResult>;
356
388
  interface TerminateChildTreeDeps {
357
389
  readonly listProcessSnapshots: () => Promise<ProcessSnapshot[]>;
358
- readonly collectProcessTreePids: typeof collectProcessTreePids;
359
- readonly stopProcesses: (pids: Array<number | null | undefined>) => Promise<StopProcessesResult>;
390
+ readonly collectProcessTreePids: CollectProcessTreePidsPort;
391
+ readonly stopProcesses: StopProcessesPort;
360
392
  }
361
393
  /**
362
394
  * Which step reported a contained failure through `onCleanupFailure` (SEC-007).
@@ -434,6 +466,14 @@ export interface McpJsonInjectionOptions {
434
466
  readonly command: string;
435
467
  /** Extra argv for `command`. @default [] */
436
468
  readonly args?: readonly string[];
469
+ /**
470
+ * Extra env for the bridge child, for hosts whose `command` is not a plain Node binary. An Electron
471
+ * host passes `{ ELECTRON_RUN_AS_NODE: '1' }`: its `process.execPath` is the app itself, which boots
472
+ * as a GUI app without that flag and never speaks MCP. `buildAgentEnv`'s allowlist strips the
473
+ * host's own copy from the CLI, so it can only reach the bridge through here. `JINI_*` keys are
474
+ * ignored: the run id, callback URL and token are this driver's to set. @default {}
475
+ */
476
+ readonly env?: Readonly<Record<string, string>>;
437
477
  /** The daemon's own loopback base URL the spawned `jini-mcp` process calls back into via `JINI_DAEMON_URL` (see `packages/mcp/src/bin/serve.ts`'s `DAEMON_URL_ENV_VAR`). */
438
478
  readonly daemonUrl: string;
439
479
  /**
@@ -459,11 +499,18 @@ export interface McpJsonInjectionOptions {
459
499
  * @throws Anything the host's own minting throws. `run()` turns a rejection into a pre-spawn
460
500
  * `AGENT_SPAWN_FAILED` failure rather than spawning a child that cannot authenticate.
461
501
  */
462
- readonly credential?: (runId: string) => string | Promise<string>;
502
+ readonly credential?: ({ runId }: {
503
+ readonly runId: string;
504
+ }) => string | Promise<string>;
463
505
  /** Reads the project's own `cwd/.mcp.json` so this driver merges its servers in rather than dropping them. Rejecting (ENOENT or otherwise) is treated as "no existing file" — see `writeMcpJsonForRun`. This file is only ever *read*. @default the real `fs.promises.readFile` (utf8) */
464
- readonly readFile?: (path: string) => Promise<string>;
506
+ readonly readFile?: ({ path }: {
507
+ readonly path: string;
508
+ }) => Promise<string>;
465
509
  /** Writes the merged content to this run's own config path (see {@link mcpJsonPathForRun}), never to the project's `.mcp.json`. @default the real `fs.promises.writeFile` (utf8) */
466
- readonly writeFile?: (path: string, content: string) => Promise<void>;
510
+ readonly writeFile?: ({ path, content }: {
511
+ readonly path: string;
512
+ readonly content: string;
513
+ }) => Promise<void>;
467
514
  /**
468
515
  * Removes this run's config file once the run is over — it holds a live per-run bearer token, so
469
516
  * leaving it behind is the same class of confidentiality gap as a leaked prompt file (see
@@ -471,7 +518,9 @@ export interface McpJsonInjectionOptions {
471
518
  * pre-spawn/spawn-failure path, and a rejection is reported rather than allowed to strand the run.
472
519
  * @default `fs.promises.rm(path, { force: true })` — already-gone is success, not an error.
473
520
  */
474
- readonly removeFile?: (path: string) => Promise<void>;
521
+ readonly removeFile?: ({ path }: {
522
+ readonly path: string;
523
+ }) => Promise<void>;
475
524
  /**
476
525
  * `'codex-toml'` only. Creates a fresh, randomly-named directory `prepareCodexHomeForRun` stages
477
526
  * as a run's scratch `CODEX_HOME`. **Must be non-deterministic (a real `mkdtemp`, not a
@@ -486,20 +535,39 @@ export interface McpJsonInjectionOptions {
486
535
  * template; the real suffix mkdtemp appends is what makes the path unpredictable.
487
536
  * @default `fs.mkdtemp(path.join(os.tmpdir(), prefix))`
488
537
  */
489
- readonly mkdtemp?: (prefix: string) => Promise<string>;
538
+ readonly mkdtemp?: ({ prefix }: {
539
+ readonly prefix: string;
540
+ }) => Promise<string>;
490
541
  /**
491
542
  * `'codex-toml'` only. Recursively removes the scratch `CODEX_HOME` directory `mkdtemp` above
492
543
  * created — the directory-level analogue of `removeFile`, needed because this mechanism stages a
493
544
  * whole directory (`config.toml` plus a copied `auth.json`), not one file.
494
545
  * @default `fs.rm(path, { recursive: true, force: true })` — already-gone is success, not an error.
495
546
  */
496
- readonly removeDir?: (path: string) => Promise<void>;
547
+ readonly removeDir?: ({ path }: {
548
+ readonly path: string;
549
+ }) => Promise<void>;
497
550
  }
551
+ /** The run-error code a run gets when its CLI reports the injected `jini` bridge as anything but connected. */
552
+ export declare const MCP_BRIDGE_UNAVAILABLE = "MCP_BRIDGE_UNAVAILABLE";
553
+ /**
554
+ * Judges a CLI's startup report of the injected bridge. Returns the bridge's status (`'missing'`
555
+ * when the list omits it) when it is not `'connected'`, and `undefined` when it is connected or
556
+ * when `rawEvent` is not an init status carrying an MCP server list (nothing to judge).
557
+ *
558
+ * `'pending'` counts as a failure on purpose: the CLI decides which MCP tools a session has at
559
+ * startup, so a bridge that is not connected by then never joins this run.
560
+ * @param rawEvent - One parsed stream event, as `@jini-ai/agent-runtime`'s parser emits it.
561
+ * @complexity O(n) in the number of reported servers.
562
+ */
563
+ export declare function unavailableJiniBridgeStatus({ rawEvent }: {
564
+ readonly rawEvent: unknown;
565
+ }): string | undefined;
498
566
  /** One `.mcp.json` `mcpServers` entry — the shape Claude Code's own config schema expects. */
499
567
  interface McpJsonServerEntry {
500
568
  readonly command: string;
501
569
  readonly args: string[];
502
- readonly env: {
570
+ readonly env: Readonly<Record<string, string>> & {
503
571
  readonly JINI_RUN_ID: string;
504
572
  readonly JINI_DAEMON_URL: string;
505
573
  /** Present only when the host supplied a `credential` resolver — see {@link McpJsonInjectionOptions.credential}. */
@@ -513,13 +581,18 @@ interface McpJsonServerEntry {
513
581
  * `writeMcpJsonForRun`'s job, which keeps the effect out of this function.
514
582
  *
515
583
  * @param runId - The run this entry scopes its child to.
516
- * @param options - `command`/`args`/`daemonUrl` from the host's injection options.
584
+ * @param options - `command`/`args`/`daemonUrl`/`env` from the host's injection options.
517
585
  * @param credential - The already-resolved bearer token, or `undefined` to omit `JINI_DAEMON_TOKEN`
518
586
  * entirely. Omitting produces byte-identical output to before this parameter existed.
519
587
  * @complexity O(1).
520
588
  * @overallScore 100/100
521
589
  */
522
- export declare function buildMcpJsonServerEntry(runId: string, options: Pick<McpJsonInjectionOptions, 'command' | 'args' | 'daemonUrl'>, credential?: string): McpJsonServerEntry;
590
+ export declare function buildMcpJsonServerEntry({ runId, options }: {
591
+ readonly runId: string;
592
+ readonly options: Pick<McpJsonInjectionOptions, 'command' | 'args' | 'daemonUrl' | 'env'>;
593
+ }, { credential }?: {
594
+ readonly credential?: string;
595
+ }): McpJsonServerEntry;
523
596
  /**
524
597
  * Merges {@link JINI_MCP_SERVER_KEY} into an existing `.mcp.json`'s `mcpServers` map, preserving
525
598
  * every other key and every other registered server untouched. A missing (`existingRaw ===
@@ -531,7 +604,10 @@ export declare function buildMcpJsonServerEntry(runId: string, options: Pick<Mcp
531
604
  * @complexity O(1) plus `JSON.parse`/`JSON.stringify`'s own cost on a small config file.
532
605
  * @overallScore 100/100
533
606
  */
534
- export declare function mergeMcpJsonContent(existingRaw: string | undefined, serverEntry: McpJsonServerEntry): string;
607
+ export declare function mergeMcpJsonContent({ existingRaw, serverEntry }: {
608
+ readonly existingRaw: string | undefined;
609
+ readonly serverEntry: McpJsonServerEntry;
610
+ }): string;
535
611
  /**
536
612
  * Mechanism 2 of 5 — `'acp-merge'`. Re-shapes the same bridge entry into the `mcpServers` element
537
613
  * an ACP `session/new` call carries, for the 9 ACP-native defs declaring this strategy (amr, devin,
@@ -553,7 +629,9 @@ export declare function mergeMcpJsonContent(existingRaw: string | undefined, ser
553
629
  * @complexity O(1).
554
630
  * @overallScore 100/100
555
631
  */
556
- export declare function buildAcpMcpBridgeServers(entry: McpJsonServerEntry): AcpMcpServerInput[];
632
+ export declare function buildAcpMcpBridgeServers({ entry }: {
633
+ readonly entry: McpJsonServerEntry;
634
+ }): AcpMcpServerInput[];
557
635
  /**
558
636
  * Serialises the bridge entry into the OpenCode-schema config JSON that `OPENCODE_CONFIG_CONTENT`
559
637
  * / `MIMOCODE_CONFIG_CONTENT` carries, merging into whatever the host already put in that variable
@@ -581,7 +659,10 @@ export declare function buildAcpMcpBridgeServers(entry: McpJsonServerEntry): Acp
581
659
  * @complexity O(1) plus `JSON.parse`/`JSON.stringify` over a small config document.
582
660
  * @overallScore 100/100
583
661
  */
584
- export declare function mergeEnvContentMcpConfig(existingRaw: string | undefined, entry: McpJsonServerEntry): string;
662
+ export declare function mergeEnvContentMcpConfig({ existingRaw, entry }: {
663
+ readonly existingRaw: string | undefined;
664
+ readonly entry: McpJsonServerEntry;
665
+ }): string;
585
666
  /**
586
667
  * Merges a staged system-prompt overlay file's path into the `instructions` array of the same
587
668
  * OpenCode-schema config document {@link mergeEnvContentMcpConfig} writes `mcp` into — for a
@@ -619,7 +700,10 @@ export declare function mergeEnvContentMcpConfig(existingRaw: string | undefined
619
700
  * @complexity O(1) plus `JSON.parse`/`JSON.stringify` over a small config document.
620
701
  * @overallScore 100/100
621
702
  */
622
- export declare function mergeEnvContentInstructions(existingRaw: string | undefined, instructionsFilePath: string): string;
703
+ export declare function mergeEnvContentInstructions({ existingRaw, instructionsFilePath }: {
704
+ readonly existingRaw: string | undefined;
705
+ readonly instructionsFilePath: string;
706
+ }): string;
623
707
  /**
624
708
  * Mechanism 5 of 5 — `'codex-toml'`'s serialization step. Builds the `[mcp_servers.jini]` TOML
625
709
  * table (plus, when the entry carries any env vars, a separate `[mcp_servers.jini.env]` table)
@@ -628,13 +712,15 @@ export declare function mergeEnvContentInstructions(existingRaw: string | undefi
628
712
  * Confirmed against a real installed Codex CLI (0.151.0), not assumed from docs: round-tripping
629
713
  * `codex mcp add <name> --env K=V -- <cmd> <args>` against a scratch `CODEX_HOME` and reading back
630
714
  * `config.toml` produced exactly this shape (`command`/`args` as TOML strings/array in the main
631
- * table, env vars in a nested `.env` table) — see `source-map.md` for the transcript.
715
+ * table, env vars in a nested `.env` table) — see `archived provenance ledger` for the transcript.
632
716
  * @param entry - The shared bridge entry from {@link buildMcpJsonServerEntry}.
633
717
  * @returns A TOML fragment with no leading/trailing blank-line padding — {@link buildCodexHomeConfigToml} owns spacing when combining it with existing content.
634
718
  * @complexity O(n) in the number of argv/env entries.
635
719
  * @overallScore 100/100
636
720
  */
637
- export declare function buildCodexMcpServerToml(entry: McpJsonServerEntry): string;
721
+ export declare function buildCodexMcpServerToml({ entry }: {
722
+ readonly entry: McpJsonServerEntry;
723
+ }): string;
638
724
  /**
639
725
  * Builds the full `config.toml` a run's scratch `CODEX_HOME` gets: the real Codex home's own
640
726
  * config, with any pre-existing `[mcp_servers.jini]` table removed (see
@@ -655,7 +741,10 @@ export declare function buildCodexMcpServerToml(entry: McpJsonServerEntry): stri
655
741
  * @returns The full text to write to the scratch `CODEX_HOME`'s `config.toml`.
656
742
  * @complexity O(n) in the existing config's length.
657
743
  */
658
- export declare function buildCodexHomeConfigToml(existingRaw: string | undefined, entry: McpJsonServerEntry): string;
744
+ export declare function buildCodexHomeConfigToml({ existingRaw, entry }: {
745
+ readonly existingRaw: string | undefined;
746
+ readonly entry: McpJsonServerEntry;
747
+ }): string;
659
748
  /**
660
749
  * Where `'codex-toml'` reads the operator's REAL Codex config from, to seed a run's scratch copy —
661
750
  * never where it writes. Resolved against the daemon HOST process's own environment (`hostEnv`,
@@ -668,7 +757,9 @@ export declare function buildCodexHomeConfigToml(existingRaw: string | undefined
668
757
  * @complexity O(1).
669
758
  * @overallScore 100/100
670
759
  */
671
- export declare function resolveSourceCodexHomeDir(hostEnv: NodeJS.ProcessEnv): string;
760
+ export declare function resolveSourceCodexHomeDir({ hostEnv }: {
761
+ readonly hostEnv: NodeJS.ProcessEnv;
762
+ }): string;
672
763
  /**
673
764
  * What one run's MCP bridge turns into, discriminated by the delivery mechanism its def declared.
674
765
  * Exactly one variant is produced per run, and each variant carries only what its own consumer
@@ -767,10 +858,19 @@ export type PreparedClaudeConfigDir = {
767
858
  };
768
859
  /** The Claude-config-dir mechanism's injectable filesystem seams, real by default — the directory-staging analogue of {@link CodexHomeSeams}, kept as its own small options bag (see {@link CreateAgentExecutorOptions.claudeConfigDirIsolation}) rather than folded into {@link McpJsonInjectionOptions}: isolating the operator's personal config is an env-hygiene concern independent of whether this host configured MCP federation at all, and must not be gated on that unrelated flag. */
769
860
  export interface ClaudeConfigDirSeams {
770
- readonly mkdtemp: (prefix: string) => Promise<string>;
771
- readonly readFile: (path: string) => Promise<string>;
772
- readonly writeFile: (path: string, content: string) => Promise<void>;
773
- readonly removeDir: (path: string) => Promise<void>;
861
+ readonly mkdtemp: ({ prefix }: {
862
+ readonly prefix: string;
863
+ }) => Promise<string>;
864
+ readonly readFile: ({ path }: {
865
+ readonly path: string;
866
+ }) => Promise<string>;
867
+ readonly writeFile: ({ path, content }: {
868
+ readonly path: string;
869
+ readonly content: string;
870
+ }) => Promise<void>;
871
+ readonly removeDir: ({ path }: {
872
+ readonly path: string;
873
+ }) => Promise<void>;
774
874
  }
775
875
  /**
776
876
  * `CreateAgentExecutorOptions.claudeConfigDirIsolation` — every field optional and real-filesystem
@@ -783,13 +883,22 @@ export interface ClaudeConfigDirSeams {
783
883
  */
784
884
  export interface ClaudeConfigDirIsolationOptions {
785
885
  /** @default the real `fs.promises.mkdtemp(path.join(os.tmpdir(), prefix))` */
786
- readonly mkdtemp?: (prefix: string) => Promise<string>;
886
+ readonly mkdtemp?: ({ prefix }: {
887
+ readonly prefix: string;
888
+ }) => Promise<string>;
787
889
  /** Reads the operator's real `.credentials.json`, if any — see {@link prepareClaudeConfigDirForRun}'s own doc. @default the real `fs.promises.readFile` (utf8) */
788
- readonly readFile?: (path: string) => Promise<string>;
890
+ readonly readFile?: ({ path }: {
891
+ readonly path: string;
892
+ }) => Promise<string>;
789
893
  /** Writes the copied `.credentials.json` into the scratch directory. @default the real `fs.promises.writeFile` (utf8) */
790
- readonly writeFile?: (path: string, content: string) => Promise<void>;
894
+ readonly writeFile?: ({ path, content }: {
895
+ readonly path: string;
896
+ readonly content: string;
897
+ }) => Promise<void>;
791
898
  /** @default `fs.promises.rm(path, { recursive: true, force: true })` — already-gone is success, not an error. */
792
- readonly removeDir?: (path: string) => Promise<void>;
899
+ readonly removeDir?: ({ path }: {
900
+ readonly path: string;
901
+ }) => Promise<void>;
793
902
  }
794
903
  /**
795
904
  * Where `claude`'s own config resolution reads the operator's REAL config from, to seed a run's
@@ -803,7 +912,9 @@ export interface ClaudeConfigDirIsolationOptions {
803
912
  * default, `~/.claude`.
804
913
  * @complexity O(1).
805
914
  */
806
- export declare function resolveSourceClaudeConfigDir(hostEnv: NodeJS.ProcessEnv): string;
915
+ export declare function resolveSourceClaudeConfigDir({ hostEnv }: {
916
+ readonly hostEnv: NodeJS.ProcessEnv;
917
+ }): string;
807
918
  /**
808
919
  * Gap 4 of the run/chat orchestration Final Recommendation: what
809
920
  * `classifyFailure` (see `CreateAgentExecutorOptions.classifyFailure`) is
@@ -865,7 +976,9 @@ export type ClassifyFailure = (context: FailureClassificationContext) => boolean
865
976
  export declare const DEFAULT_BUFFERED_STDOUT_MAX_BYTES: number;
866
977
  /** The side-effect signals {@link applyAgentTranslationSideEffects} reports through, one callback per signal so a caller only wires the ones it actually tracks. */
867
978
  interface AgentTranslationSideEffectSink {
868
- readonly onSessionId: (sessionId: string) => void;
979
+ readonly onSessionId: (args: {
980
+ readonly sessionId: string;
981
+ }) => void;
869
982
  readonly onToolCall: () => void;
870
983
  readonly onUserVisibleOutput: () => void;
871
984
  }
@@ -881,7 +994,11 @@ interface AgentTranslationSideEffectSink {
881
994
  * @param sink - The driver-specific effects to apply.
882
995
  * @complexity O(1).
883
996
  */
884
- export declare function applyAgentTranslationSideEffects(payload: RunAgentPayload, sessionId: string | undefined, sink: AgentTranslationSideEffectSink): void;
997
+ export declare function applyAgentTranslationSideEffects({ payload, sessionId, sink }: {
998
+ readonly payload: RunAgentPayload;
999
+ readonly sessionId: string | undefined;
1000
+ readonly sink: AgentTranslationSideEffectSink;
1001
+ }): void;
885
1002
  export interface CreateAgentExecutorOptions {
886
1003
  readonly lifecycle: RunLifecycle;
887
1004
  /** @default the real `@jini-ai/agent-runtime` registry lookup */
@@ -926,9 +1043,9 @@ export interface CreateAgentExecutorOptions {
926
1043
  /** @default the real `@jini-ai/platform` process-snapshot enumerator */
927
1044
  readonly listProcessSnapshots?: typeof listProcessSnapshots;
928
1045
  /** @default the real `@jini-ai/platform` descendant-PID collector */
929
- readonly collectProcessTreePids?: typeof collectProcessTreePids;
1046
+ readonly collectProcessTreePids?: CollectProcessTreePidsPort;
930
1047
  /** @default the real `@jini-ai/platform` SIGTERM→SIGKILL escalator */
931
- readonly stopProcesses?: typeof stopProcesses;
1048
+ readonly stopProcesses?: StopProcessesPort;
932
1049
  /** Host-owned sink for a process-tree cleanup failure (SEC-007) — e.g. EPERM stopping descendants. @default logs a redacted diagnostic via `console.error` */
933
1050
  readonly onCleanupFailure?: (context: AgentCleanupFailureContext) => void;
934
1051
  /**
@@ -1036,72 +1153,97 @@ export interface CreateAgentExecutorOptions {
1036
1153
  * @overallScore 100/100
1037
1154
  */
1038
1155
  /** `createAgentExecutor`'s internal `failBeforeSpawn` — a nested closure over `lifecycle`, so every extracted `run()` phase below takes it as an explicit injected collaborator rather than reaching for a module-level one. */
1039
- type FailBeforeSpawn = (runId: string, code: AgentExecutorErrorCode, message: string) => Promise<never>;
1156
+ type FailBeforeSpawn = (args: {
1157
+ readonly runId: string;
1158
+ readonly code: AgentExecutorErrorCode;
1159
+ readonly message: string;
1160
+ }) => Promise<never>;
1040
1161
  interface ResolvedDefAndFormat {
1041
1162
  readonly def: RuntimeAgentDef;
1042
1163
  readonly streamFormat: SupportedStreamFormat;
1043
1164
  }
1044
1165
  /** Phase 1: registry lookup + `assessAgentExecutorCompatibility` guard. */
1045
- export declare function resolveDefAndStreamFormat(input: Pick<AgentExecutorRunInput, 'runId' | 'agentId'>, deps: {
1046
- readonly getAgentDef: typeof getAgentDef;
1047
- readonly failBeforeSpawn: FailBeforeSpawn;
1166
+ export declare function resolveDefAndStreamFormat({ input, deps }: {
1167
+ readonly input: Pick<AgentExecutorRunInput, 'runId' | 'agentId'>;
1168
+ readonly deps: {
1169
+ readonly getAgentDef: typeof getAgentDef;
1170
+ readonly failBeforeSpawn: FailBeforeSpawn;
1171
+ };
1048
1172
  }): Promise<ResolvedDefAndFormat>;
1049
1173
  /** Phase 2: image-prompt-delivery augmentation + argv-budget guard for argv-bound defs. */
1050
- export declare function resolveImageDeliveryAndArgvBudget(input: {
1051
- readonly runId: string;
1052
- readonly def: RuntimeAgentDef;
1053
- readonly prompt: string;
1054
- readonly imagePaths: readonly string[] | undefined;
1055
- readonly extraAllowedDirs: readonly string[] | undefined;
1056
- }, deps: {
1057
- readonly failBeforeSpawn: FailBeforeSpawn;
1174
+ export declare function resolveImageDeliveryAndArgvBudget({ input, deps }: {
1175
+ readonly input: {
1176
+ readonly runId: string;
1177
+ readonly def: RuntimeAgentDef;
1178
+ readonly prompt: string;
1179
+ readonly imagePaths: readonly string[] | undefined;
1180
+ readonly extraAllowedDirs: readonly string[] | undefined;
1181
+ };
1182
+ readonly deps: {
1183
+ readonly failBeforeSpawn: FailBeforeSpawn;
1184
+ };
1058
1185
  }): Promise<ImagePromptDelivery>;
1059
1186
  /**
1060
1187
  * Phase 3a: the subprocess environment this run's launch resolution and spawn should use — the
1061
1188
  * caller-supplied escape hatch verbatim, or the deny-by-default `BASELINE_AGENT_ENV_KEYS` allowlist.
1062
1189
  * Pure.
1063
1190
  */
1064
- export declare function resolveRunEnv(input: Pick<AgentExecutorRunInput, 'env' | 'credentialEnv'>, hostEnv: NodeJS.ProcessEnv): Record<string, string>;
1191
+ export declare function resolveRunEnv({ input, hostEnv }: {
1192
+ readonly input: Pick<AgentExecutorRunInput, 'env' | 'credentialEnv'>;
1193
+ readonly hostEnv: NodeJS.ProcessEnv;
1194
+ }): Record<string, string>;
1065
1195
  /** A resolved launch whose `launchPath` is confirmed non-null — see {@link resolveLaunch}. */
1066
1196
  type ConfirmedAgentLaunchResolution = AgentLaunchResolution & {
1067
1197
  readonly launchPath: string;
1068
1198
  };
1069
1199
  /** Phase 3b: launch-path resolution + binary-not-resolved guard. */
1070
- export declare function resolveLaunch(input: {
1071
- readonly runId: string;
1072
- readonly def: RuntimeAgentDef;
1073
- readonly resolvedEnv: Record<string, string>;
1074
- }, deps: {
1075
- readonly resolveAgentLaunch: typeof resolveAgentLaunch;
1076
- readonly failBeforeSpawn: FailBeforeSpawn;
1200
+ export declare function resolveLaunch({ input, deps }: {
1201
+ readonly input: {
1202
+ readonly runId: string;
1203
+ readonly def: RuntimeAgentDef;
1204
+ readonly resolvedEnv: Record<string, string>;
1205
+ };
1206
+ readonly deps: {
1207
+ readonly resolveAgentLaunch: typeof resolveAgentLaunch;
1208
+ readonly failBeforeSpawn: FailBeforeSpawn;
1209
+ };
1077
1210
  }): Promise<ConfirmedAgentLaunchResolution>;
1078
1211
  /** Phase 4a: stage a `promptViaFile` def's prompt to a temp file (a no-op for every other def). */
1079
- export declare function stagePromptFile(input: {
1080
- readonly runId: string;
1081
- readonly def: RuntimeAgentDef;
1082
- readonly prompt: string;
1083
- }, deps: {
1084
- readonly preparePromptFileForAgent: typeof preparePromptFileForAgent;
1085
- readonly failBeforeSpawn: FailBeforeSpawn;
1212
+ export declare function stagePromptFile({ input, deps }: {
1213
+ readonly input: {
1214
+ readonly runId: string;
1215
+ readonly def: RuntimeAgentDef;
1216
+ readonly prompt: string;
1217
+ };
1218
+ readonly deps: {
1219
+ readonly preparePromptFileForAgent: typeof preparePromptFileForAgent;
1220
+ readonly failBeforeSpawn: FailBeforeSpawn;
1221
+ };
1086
1222
  }): Promise<PreparedPromptFile | null>;
1087
1223
  /** Phase 4b: stage a `needsAgentLogFile` def's diagnostic-log path (a no-op for every other def). */
1088
- export declare function stageLogFile(input: {
1089
- readonly runId: string;
1090
- readonly def: RuntimeAgentDef;
1091
- readonly preparedPromptFile: PreparedPromptFile | null;
1092
- }, deps: {
1093
- readonly prepareAgentLogFile: typeof prepareAgentLogFile;
1094
- readonly failBeforeSpawn: FailBeforeSpawn;
1224
+ export declare function stageLogFile({ input, deps }: {
1225
+ readonly input: {
1226
+ readonly runId: string;
1227
+ readonly def: RuntimeAgentDef;
1228
+ readonly preparedPromptFile: PreparedPromptFile | null;
1229
+ };
1230
+ readonly deps: {
1231
+ readonly prepareAgentLogFile: typeof prepareAgentLogFile;
1232
+ readonly failBeforeSpawn: FailBeforeSpawn;
1233
+ };
1095
1234
  }): Promise<PreparedAgentLogFile | null>;
1096
1235
  /** Phase 5: resolves this run's MCP bridge delivery (credential resolution + {@link buildMcpBridgeDelivery}). */
1097
- export declare function resolveMcpBridgeForRun(input: {
1098
- readonly runId: string;
1099
- readonly cwd: string;
1100
- readonly def: RuntimeAgentDef;
1101
- }, deps: {
1102
- readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1103
- readonly cleanupStagedFiles: () => Promise<void>;
1104
- readonly failBeforeSpawn: FailBeforeSpawn;
1236
+ export declare function resolveMcpBridgeForRun({ input, deps }: {
1237
+ readonly input: {
1238
+ readonly runId: string;
1239
+ readonly cwd: string;
1240
+ readonly def: RuntimeAgentDef;
1241
+ };
1242
+ readonly deps: {
1243
+ readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1244
+ readonly cleanupStagedFiles: () => Promise<void>;
1245
+ readonly failBeforeSpawn: FailBeforeSpawn;
1246
+ };
1105
1247
  }): Promise<McpBridgeDelivery | null>;
1106
1248
  /**
1107
1249
  * Phase 6a/10c: the subprocess environment every env-riding mechanism uses — mechanism 3+4
@@ -1124,10 +1266,18 @@ export declare function resolveMcpBridgeForRun(input: {
1124
1266
  * @complexity O(1) plus `mergeEnvContentMcpConfig`'s and `mergeEnvContentInstructions`'s own `JSON.parse`/`JSON.stringify` cost.
1125
1267
  * @overallScore 100/100
1126
1268
  */
1127
- export declare function computeChildEnv(spawnEnv: NodeJS.ProcessEnv, mcpBridge: McpBridgeDelivery | null, codexHomeDir?: string, systemPromptEnvOverrides?: Readonly<Record<string, string>>, stagedInstructionsFile?: {
1128
- readonly varName: string;
1129
- readonly path: string;
1130
- }, claudeConfigDir?: string): NodeJS.ProcessEnv;
1269
+ export declare function computeChildEnv({ spawnEnv, mcpBridge }: {
1270
+ readonly spawnEnv: NodeJS.ProcessEnv;
1271
+ readonly mcpBridge: McpBridgeDelivery | null;
1272
+ }, { codexHomeDir, systemPromptEnvOverrides, stagedInstructionsFile, claudeConfigDir }?: {
1273
+ readonly codexHomeDir?: string;
1274
+ readonly systemPromptEnvOverrides?: Readonly<Record<string, string>>;
1275
+ readonly stagedInstructionsFile?: {
1276
+ readonly varName: string;
1277
+ readonly path: string;
1278
+ };
1279
+ readonly claudeConfigDir?: string;
1280
+ }): NodeJS.ProcessEnv;
1131
1281
  /**
1132
1282
  * Phase 6b: the `RuntimeContext` `buildArgs` receives — `undefined` unless a file, bridge path, or
1133
1283
  * session id was staged. Pure.
@@ -1139,9 +1289,20 @@ export declare function computeChildEnv(spawnEnv: NodeJS.ProcessEnv, mcpBridge:
1139
1289
  * session id, with no prompt/log file staged and no claude-mcp-json bridge, is exactly the common
1140
1290
  * case for a resumed turn.
1141
1291
  */
1142
- export declare function computeRuntimeContext(preparedPromptFile: PreparedPromptFile | null, preparedLogFile: PreparedAgentLogFile | null, mcpBridge: McpBridgeDelivery | null, resumeSessionId?: string | null, newSessionId?: string): RuntimeContext | undefined;
1143
- /** Phase 9a: the def's `buildArgs` 4th argument — `undefined` when the run selects no model/reasoning/permissionMode/overlay/tool-restriction at all (byte-identical to omitting the argument). Pure. */
1144
- export declare function buildAgentBuildArgsOptions(input: Pick<AgentExecutorRunInput, 'model' | 'reasoning' | 'permissionMode' | 'disallowedTools' | 'allowedTools' | 'settingSources' | 'settings'>, systemPromptOverlay: string | null | undefined): RuntimeBuildOptions | undefined;
1292
+ export declare function computeRuntimeContext({ preparedPromptFile, preparedLogFile, mcpBridge }: {
1293
+ readonly preparedPromptFile: PreparedPromptFile | null;
1294
+ readonly preparedLogFile: PreparedAgentLogFile | null;
1295
+ readonly mcpBridge: McpBridgeDelivery | null;
1296
+ }, { resumeSessionId, newSessionId }?: {
1297
+ readonly resumeSessionId?: string | null;
1298
+ readonly newSessionId?: string;
1299
+ }): RuntimeContext | undefined;
1300
+ /** Phase 9a: the def's `buildArgs` 4th argument. Historically omitted when every override was absent;
1301
+ * that let defs silently enable auto-approval. Always supply the validated restricted default now. Pure. */
1302
+ export declare function buildAgentBuildArgsOptions({ input, systemPromptOverlay }: {
1303
+ readonly input: Pick<AgentExecutorRunInput, 'model' | 'reasoning' | 'permissionMode' | 'disallowedTools' | 'allowedTools' | 'settingSources' | 'settings'>;
1304
+ readonly systemPromptOverlay: string | null | undefined;
1305
+ }): RuntimeBuildOptions | undefined;
1145
1306
  /**
1146
1307
  * {@link resolveSystemPromptOverlayDelivery}'s decision, threaded out of that one resolver to every
1147
1308
  * channel that can actually carry the overlay to the CLI.
@@ -1241,32 +1402,38 @@ export declare function resolveSystemPromptOverlayDelivery(input: {
1241
1402
  * therefore only ever reach the 7 defs whose `buildArgs` reads its first argument at all — the
1242
1403
  * other 17 declare it `_prompt` and discard it, which is exactly how the overlay used to go missing.
1243
1404
  */
1244
- export declare function buildRunArgs(input: {
1245
- readonly runId: string;
1246
- readonly def: RuntimeAgentDef;
1247
- readonly imageDelivery: ImagePromptDelivery;
1248
- readonly imagePaths: readonly string[] | undefined;
1249
- readonly runInput: Pick<AgentExecutorRunInput, 'model' | 'reasoning' | 'permissionMode'>;
1250
- readonly systemPromptOverlay: string | null | undefined;
1251
- readonly overlayDelivery: SystemPromptOverlayDelivery;
1252
- readonly runtimeContext: RuntimeContext | undefined;
1253
- }, deps: {
1254
- readonly releaseStagedResources: () => Promise<void>;
1255
- readonly failBeforeSpawn: FailBeforeSpawn;
1405
+ export declare function buildRunArgs({ input, deps }: {
1406
+ readonly input: {
1407
+ readonly runId: string;
1408
+ readonly def: RuntimeAgentDef;
1409
+ readonly imageDelivery: ImagePromptDelivery;
1410
+ readonly imagePaths: readonly string[] | undefined;
1411
+ readonly runInput: Pick<AgentExecutorRunInput, 'model' | 'reasoning' | 'permissionMode'>;
1412
+ readonly systemPromptOverlay: string | null | undefined;
1413
+ readonly overlayDelivery: SystemPromptOverlayDelivery;
1414
+ readonly runtimeContext: RuntimeContext | undefined;
1415
+ };
1416
+ readonly deps: {
1417
+ readonly releaseStagedResources: () => Promise<void>;
1418
+ readonly failBeforeSpawn: FailBeforeSpawn;
1419
+ };
1256
1420
  }): Promise<{
1257
1421
  readonly args: string[];
1258
1422
  readonly envOverrides: Readonly<Record<string, string>>;
1259
1423
  }>;
1260
1424
  /** Phase 10: mechanism 1 of 5's one effect — stages this run's own `.mcp.json`, returning the path `cleanupStagedFiles` should later remove (`undefined` for every other mechanism / unconfigured host). */
1261
- export declare function writeMcpJsonIfNeeded(input: {
1262
- readonly runId: string;
1263
- readonly cwd: string;
1264
- readonly def: RuntimeAgentDef;
1265
- readonly mcpBridge: McpBridgeDelivery | null;
1266
- }, deps: {
1267
- readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1268
- readonly releaseStagedResources: () => Promise<void>;
1269
- readonly failBeforeSpawn: FailBeforeSpawn;
1425
+ export declare function writeMcpJsonIfNeeded({ input, deps }: {
1426
+ readonly input: {
1427
+ readonly runId: string;
1428
+ readonly cwd: string;
1429
+ readonly def: RuntimeAgentDef;
1430
+ readonly mcpBridge: McpBridgeDelivery | null;
1431
+ };
1432
+ readonly deps: {
1433
+ readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1434
+ readonly releaseStagedResources: () => Promise<void>;
1435
+ readonly failBeforeSpawn: FailBeforeSpawn;
1436
+ };
1270
1437
  }): Promise<string | undefined>;
1271
1438
  /** {@link prepareSystemPromptOverlayFileIfNeeded}'s result. */
1272
1439
  export type PreparedSystemPromptOverlayFile = {
@@ -1293,13 +1460,16 @@ export type PreparedSystemPromptOverlayFile = {
1293
1460
  * @complexity O(1) plus one directory creation and one file write.
1294
1461
  * @overallScore 100/100
1295
1462
  */
1296
- export declare function prepareSystemPromptOverlayFileIfNeeded(input: {
1297
- readonly runId: string;
1298
- readonly def: RuntimeAgentDef;
1299
- readonly overlay: string | null | undefined;
1300
- }, deps: {
1301
- readonly releaseStagedResources: () => Promise<void>;
1302
- readonly failBeforeSpawn: FailBeforeSpawn;
1463
+ export declare function prepareSystemPromptOverlayFileIfNeeded({ input, deps }: {
1464
+ readonly input: {
1465
+ readonly runId: string;
1466
+ readonly def: RuntimeAgentDef;
1467
+ readonly overlay: string | null | undefined;
1468
+ };
1469
+ readonly deps: {
1470
+ readonly releaseStagedResources: () => Promise<void>;
1471
+ readonly failBeforeSpawn: FailBeforeSpawn;
1472
+ };
1303
1473
  }): Promise<PreparedSystemPromptOverlayFile | null>;
1304
1474
  /**
1305
1475
  * Phase 10b: mechanism 5 of 5's one effect — stages this run's scratch `CODEX_HOME` directory,
@@ -1311,15 +1481,18 @@ export declare function prepareSystemPromptOverlayFileIfNeeded(input: {
1311
1481
  * @complexity O(1) plus {@link prepareCodexHomeForRun}'s own cost.
1312
1482
  * @overallScore 100/100
1313
1483
  */
1314
- export declare function prepareCodexHomeIfNeeded(input: {
1315
- readonly runId: string;
1316
- readonly def: RuntimeAgentDef;
1317
- readonly mcpBridge: McpBridgeDelivery | null;
1318
- }, deps: {
1319
- readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1320
- readonly hostEnv: NodeJS.ProcessEnv;
1321
- readonly releaseStagedResources: () => Promise<void>;
1322
- readonly failBeforeSpawn: FailBeforeSpawn;
1484
+ export declare function prepareCodexHomeIfNeeded({ input, deps }: {
1485
+ readonly input: {
1486
+ readonly runId: string;
1487
+ readonly def: RuntimeAgentDef;
1488
+ readonly mcpBridge: McpBridgeDelivery | null;
1489
+ };
1490
+ readonly deps: {
1491
+ readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1492
+ readonly hostEnv: NodeJS.ProcessEnv;
1493
+ readonly releaseStagedResources: () => Promise<void>;
1494
+ readonly failBeforeSpawn: FailBeforeSpawn;
1495
+ };
1323
1496
  }): Promise<PreparedCodexHome | null>;
1324
1497
  /**
1325
1498
  * Finding 1 of SEC-assistant-env-isolation-2026-09-07's one effect — stages this run's scratch
@@ -1344,25 +1517,31 @@ export declare function prepareCodexHomeIfNeeded(input: {
1344
1517
  * @param deps.hostEnv - The daemon's own environment, threaded through to {@link resolveSourceClaudeConfigDir} rather than read from a module-level `process.env`, matching {@link prepareCodexHomeIfNeeded}'s identical testability reasoning.
1345
1518
  * @complexity O(1) plus {@link prepareClaudeConfigDirForRun}'s own cost.
1346
1519
  */
1347
- export declare function prepareClaudeConfigDirIfNeeded(input: {
1348
- readonly runId: string;
1349
- readonly def: RuntimeAgentDef;
1350
- }, deps: {
1351
- readonly enabled: boolean;
1352
- readonly claudeConfigDirIsolation: ClaudeConfigDirIsolationOptions | undefined;
1353
- readonly hostEnv: NodeJS.ProcessEnv;
1354
- readonly releaseStagedResources: () => Promise<void>;
1355
- readonly failBeforeSpawn: FailBeforeSpawn;
1520
+ export declare function prepareClaudeConfigDirIfNeeded({ input, deps }: {
1521
+ readonly input: {
1522
+ readonly runId: string;
1523
+ readonly def: RuntimeAgentDef;
1524
+ };
1525
+ readonly deps: {
1526
+ readonly enabled: boolean;
1527
+ readonly claudeConfigDirIsolation: ClaudeConfigDirIsolationOptions | undefined;
1528
+ readonly hostEnv: NodeJS.ProcessEnv;
1529
+ readonly releaseStagedResources: () => Promise<void>;
1530
+ readonly failBeforeSpawn: FailBeforeSpawn;
1531
+ };
1356
1532
  }): Promise<PreparedClaudeConfigDir | null>;
1357
1533
  /** Phase 11: post-`buildArgs` guard for argv-bound defs whose resolved binary is a Windows shim/.exe — a no-op off-Windows and for non-argv-bound defs. */
1358
- export declare function guardWindowsCommandLineBudget(input: {
1359
- readonly runId: string;
1360
- readonly def: RuntimeAgentDef;
1361
- readonly launchPath: string;
1362
- readonly args: readonly string[];
1363
- }, deps: {
1364
- readonly releaseStagedResources: () => Promise<void>;
1365
- readonly failBeforeSpawn: FailBeforeSpawn;
1534
+ export declare function guardWindowsCommandLineBudget({ input, deps }: {
1535
+ readonly input: {
1536
+ readonly runId: string;
1537
+ readonly def: RuntimeAgentDef;
1538
+ readonly launchPath: string;
1539
+ readonly args: readonly string[];
1540
+ };
1541
+ readonly deps: {
1542
+ readonly releaseStagedResources: () => Promise<void>;
1543
+ readonly failBeforeSpawn: FailBeforeSpawn;
1544
+ };
1366
1545
  }): Promise<void>;
1367
1546
  /** {@link spawnAgentChildProcess}'s result — a discriminated union rather than a thrown/rejected outcome so the call can stay synchronous; see that function's doc for why. */
1368
1547
  export type SpawnAgentChildProcessResult = {
@@ -1391,30 +1570,44 @@ export type SpawnAgentChildProcessResult = {
1391
1570
  * which are safe to make asynchronous since no child (and hence no listener race) exists yet.
1392
1571
  * @complexity O(1) plus `spawn`'s own cost.
1393
1572
  */
1394
- export declare function spawnAgentChildProcess(input: {
1395
- readonly cwd: string;
1396
- readonly childEnv: NodeJS.ProcessEnv;
1397
- readonly invocation: ReturnType<typeof createCommandInvocation>;
1398
- }, deps: {
1399
- readonly spawn: typeof nodeSpawn;
1573
+ export declare function spawnAgentChildProcess({ input, deps }: {
1574
+ readonly input: {
1575
+ readonly cwd: string;
1576
+ readonly childEnv: NodeJS.ProcessEnv;
1577
+ readonly invocation: ReturnType<typeof createCommandInvocation>;
1578
+ };
1579
+ readonly deps: {
1580
+ readonly spawn: typeof nodeSpawn;
1581
+ };
1400
1582
  }): SpawnAgentChildProcessResult;
1401
1583
  /** Named predicate replacing an inline `streamFormat === 'acp-json-rpc' || streamFormat === 'pi-rpc'` check — the two formats that own their own prompt/event protocol and skip `wireChildLifecycle`. */
1402
- export declare function isStdinDrivenFormat(streamFormat: SupportedStreamFormat): streamFormat is ChildDrivenStreamFormat;
1584
+ export declare function isStdinDrivenFormat(args: {
1585
+ readonly streamFormat: SupportedStreamFormat;
1586
+ }): args is {
1587
+ readonly streamFormat: ChildDrivenStreamFormat;
1588
+ };
1403
1589
  /** Phase 13: awaits spawn confirmation, routing a failure through the same `failBeforeSpawn` shape every earlier guard uses. */
1404
- export declare function confirmChildSpawned(input: {
1405
- readonly runId: string;
1406
- readonly def: RuntimeAgentDef;
1407
- readonly child: ChildProcess;
1408
- }, deps: {
1409
- readonly releaseStagedResources: () => Promise<void>;
1410
- readonly failBeforeSpawn: FailBeforeSpawn;
1590
+ export declare function confirmChildSpawned({ input, deps }: {
1591
+ readonly input: {
1592
+ readonly runId: string;
1593
+ readonly def: RuntimeAgentDef;
1594
+ readonly child: ChildProcess;
1595
+ };
1596
+ readonly deps: {
1597
+ readonly releaseStagedResources: () => Promise<void>;
1598
+ readonly failBeforeSpawn: FailBeforeSpawn;
1599
+ };
1411
1600
  }): Promise<void>;
1412
1601
  /** Phase 14: starts a `runtimeLock` def's handoff watcher once a live process exists to consume the locked side effect — a no-op when the def declared no `waitForHandoff`. Deliberately not awaited; see `RuntimeLockHold.waitForHandoff`'s own doc. */
1413
- export declare function armHandoffWatcher(runtimeLockHold: RuntimeLockHold | undefined, handoffInput: {
1414
- readonly logFilePath: string | undefined;
1415
- readonly model: string | undefined;
1416
- readonly processExited: AbortSignal;
1417
- }, release: () => void): void;
1602
+ export declare function armHandoffWatcher({ runtimeLockHold, handoffInput, release }: {
1603
+ readonly runtimeLockHold: RuntimeLockHold | undefined;
1604
+ readonly handoffInput: {
1605
+ readonly logFilePath: string | undefined;
1606
+ readonly model: string | undefined;
1607
+ readonly processExited: AbortSignal;
1608
+ };
1609
+ readonly release: () => void;
1610
+ }): void;
1418
1611
  interface RunAcpDispatchInput {
1419
1612
  readonly runId: string;
1420
1613
  readonly agentId: string;
@@ -1438,7 +1631,10 @@ interface RunAcpDispatchDeps extends TerminateChildTreeDeps {
1438
1631
  readonly failBeforeSpawn: FailBeforeSpawn;
1439
1632
  }
1440
1633
  /** Phase 15 (ACP branch): attaches the ACP session, escalating process-tree teardown and failing the run through `failBeforeSpawn` on an attach-time throw. */
1441
- export declare function runAcpDispatch(input: RunAcpDispatchInput, deps: RunAcpDispatchDeps): Promise<void>;
1634
+ export declare function runAcpDispatch({ input, deps }: {
1635
+ readonly input: RunAcpDispatchInput;
1636
+ readonly deps: RunAcpDispatchDeps;
1637
+ }): Promise<void>;
1442
1638
  interface RunPiRpcDispatchInput {
1443
1639
  readonly runId: string;
1444
1640
  readonly agentId: string;
@@ -1460,7 +1656,10 @@ interface RunPiRpcDispatchDeps extends TerminateChildTreeDeps {
1460
1656
  readonly failBeforeSpawn: FailBeforeSpawn;
1461
1657
  }
1462
1658
  /** Phase 15 (pi-rpc branch): same discipline as {@link runAcpDispatch}, for the one `'pi-rpc'` def. */
1463
- export declare function runPiRpcDispatch(input: RunPiRpcDispatchInput, deps: RunPiRpcDispatchDeps): Promise<void>;
1464
- export declare function createAgentExecutor(options: CreateAgentExecutorOptions): AgentExecutor;
1659
+ export declare function runPiRpcDispatch({ input, deps }: {
1660
+ readonly input: RunPiRpcDispatchInput;
1661
+ readonly deps: RunPiRpcDispatchDeps;
1662
+ }): Promise<void>;
1663
+ export declare function createAgentExecutor(requiredArgs: Pick<CreateAgentExecutorOptions, "lifecycle">, optionalArgs?: Pick<CreateAgentExecutorOptions, "getAgentDef" | "resolveAgentLaunch" | "ensureAgentCapabilities" | "applyAgentLaunchEnv" | "createCommandInvocation" | "spawn" | "attachAcpSession" | "acpPermissionHandler" | "attachPiRpcSession" | "preparePromptFileForAgent" | "prepareAgentLogFile" | "listProcessSnapshots" | "collectProcessTreePids" | "stopProcesses" | "onCleanupFailure" | "journal" | "continuation" | "classifyFailure" | "mcpJsonInjection" | "claudeConfigDirIsolation" | "claudeConfigDirIsolationEnabled" | "bufferedStdoutMaxBytes" | "promptAugmenter">): AgentExecutor;
1465
1664
  export {};
1466
1665
  //# sourceMappingURL=agent-executor.d.ts.map