@jini-ai/daemon 0.3.7 → 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 (159) 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 +382 -177
  20. package/dist/agent-executor.js +408 -344
  21. package/dist/close-status.d.ts +11 -8
  22. package/dist/close-status.js +31 -19
  23. package/dist/continuation/continuation-transport.d.ts +3 -1
  24. package/dist/continuation/continuation-transport.js +1 -1
  25. package/dist/continuation/journal.d.ts +12 -5
  26. package/dist/continuation/journal.js +4 -4
  27. package/dist/continuation/run-scoped-context-store.d.ts +13 -4
  28. package/dist/continuation/run-scoped-context-store.js +6 -6
  29. package/dist/continuation/run-start-handler.d.ts +1 -1
  30. package/dist/continuation/run-start-handler.js +3 -16
  31. package/dist/delegated-tool-bridge.d.ts +7 -3
  32. package/dist/delegated-tool-bridge.js +32 -31
  33. package/dist/event-log.d.ts +7 -5
  34. package/dist/event-log.js +12 -11
  35. package/dist/frontend-capability-tools.d.ts +1 -1
  36. package/dist/frontend-capability-tools.js +3 -2
  37. package/dist/frontend-session-registry.d.ts +32 -9
  38. package/dist/frontend-session-registry.js +12 -11
  39. package/dist/http/active-context.d.ts +105 -0
  40. package/dist/http/active-context.js +67 -0
  41. package/dist/http/agents.d.ts +68 -0
  42. package/dist/http/agents.js +12 -0
  43. package/dist/http/attachments.d.ts +618 -0
  44. package/dist/http/attachments.js +1034 -0
  45. package/dist/http/cancel-owned-runs.d.ts +49 -0
  46. package/dist/http/cancel-owned-runs.js +35 -0
  47. package/dist/http/component-catalog.d.ts +84 -0
  48. package/dist/http/component-catalog.js +64 -0
  49. package/dist/http/connectors.d.ts +209 -0
  50. package/dist/http/connectors.js +409 -0
  51. package/dist/http/daemon-status.d.ts +76 -0
  52. package/dist/http/daemon-status.js +55 -0
  53. package/dist/http/db-ops.d.ts +123 -0
  54. package/dist/http/db-ops.js +189 -0
  55. package/dist/http/delegated-tools.d.ts +113 -0
  56. package/dist/http/delegated-tools.js +230 -0
  57. package/dist/http/frontend-control.d.ts +136 -0
  58. package/dist/http/frontend-control.js +79 -0
  59. package/dist/http/frontend-sessions.d.ts +110 -0
  60. package/dist/http/frontend-sessions.js +180 -0
  61. package/dist/http/health.d.ts +95 -0
  62. package/dist/http/health.js +40 -0
  63. package/dist/http/host-tools.d.ts +214 -0
  64. package/dist/http/host-tools.js +329 -0
  65. package/dist/http/index.d.ts +52 -0
  66. package/dist/http/index.js +27 -0
  67. package/dist/http/media.d.ts +146 -0
  68. package/dist/http/media.js +346 -0
  69. package/dist/http/memory.d.ts +265 -0
  70. package/dist/http/memory.js +328 -0
  71. package/dist/http/model-proxy.d.ts +49 -0
  72. package/dist/http/model-proxy.js +642 -0
  73. package/dist/http/remote-run-events.d.ts +70 -0
  74. package/dist/http/remote-run-events.js +224 -0
  75. package/dist/http/research.d.ts +48 -0
  76. package/dist/http/research.js +315 -0
  77. package/dist/http/route-manifest.d.ts +35 -0
  78. package/dist/http/route-manifest.js +103 -0
  79. package/dist/http/routines.d.ts +120 -0
  80. package/dist/http/routines.js +298 -0
  81. package/dist/http/run-credentials.d.ts +73 -0
  82. package/dist/http/run-credentials.js +71 -0
  83. package/dist/http/runs.d.ts +91 -0
  84. package/dist/http/runs.js +221 -0
  85. package/dist/http/terminals.d.ts +138 -0
  86. package/dist/http/terminals.js +325 -0
  87. package/dist/http/tool-catalog.d.ts +78 -0
  88. package/dist/http/tool-catalog.js +66 -0
  89. package/dist/http/workspace-root.d.ts +77 -0
  90. package/dist/http/workspace-root.js +63 -0
  91. package/dist/http/xai.d.ts +90 -0
  92. package/dist/http/xai.js +655 -0
  93. package/dist/image-prompt-delivery.d.ts +13 -3
  94. package/dist/image-prompt-delivery.js +5 -5
  95. package/dist/index.d.ts +556 -4
  96. package/dist/index.js +556 -4
  97. package/dist/legacy-data-migration.d.ts +59 -8
  98. package/dist/legacy-data-migration.js +38 -33
  99. package/dist/read-only-tools.d.ts +130 -0
  100. package/dist/read-only-tools.js +115 -0
  101. package/dist/remote-tool-bridge.d.ts +11 -5
  102. package/dist/remote-tool-bridge.js +15 -15
  103. package/dist/routines/index.d.ts +1 -1
  104. package/dist/routines/index.js +1 -1
  105. package/dist/routines/routine-store.d.ts +34 -12
  106. package/dist/routines/routine-store.js +21 -20
  107. package/dist/routines/schedule.d.ts +48 -10
  108. package/dist/routines/schedule.js +21 -21
  109. package/dist/routines/scheduler.d.ts +32 -11
  110. package/dist/routines/scheduler.js +61 -57
  111. package/dist/routines/types.d.ts +10 -3
  112. package/dist/run/core/result.d.ts +6 -2
  113. package/dist/run/core/result.js +3 -3
  114. package/dist/run/core/retry.d.ts +17 -4
  115. package/dist/run/core/retry.js +7 -11
  116. package/dist/run/diagnostics/diagnostics.d.ts +14 -4
  117. package/dist/run/diagnostics/diagnostics.js +7 -7
  118. package/dist/run/index.d.ts +1 -1
  119. package/dist/run/index.js +1 -1
  120. package/dist/run-credentials.d.ts +138 -0
  121. package/dist/run-credentials.js +152 -0
  122. package/dist/run-lifecycle.d.ts +92 -33
  123. package/dist/run-lifecycle.js +86 -73
  124. package/dist/scheduler.d.ts +8 -0
  125. package/dist/scheduler.js +2 -0
  126. package/dist/session-coordination.d.ts +115 -0
  127. package/dist/session-coordination.js +111 -0
  128. package/dist/store/agent-sessions/errors.d.ts +8 -0
  129. package/dist/store/agent-sessions/errors.js +10 -0
  130. package/dist/store/agent-sessions/index.d.ts +12 -0
  131. package/dist/store/agent-sessions/index.js +19 -0
  132. package/dist/store/agent-sessions/pglite.d.ts +12 -0
  133. package/dist/store/agent-sessions/pglite.js +7 -0
  134. package/dist/store/agent-sessions/ports.d.ts +24 -0
  135. package/dist/store/agent-sessions/ports.js +2 -0
  136. package/dist/store/agent-sessions/postgres.d.ts +12 -0
  137. package/dist/store/agent-sessions/postgres.js +7 -0
  138. package/dist/store/agent-sessions/schema.d.ts +3 -0
  139. package/dist/store/agent-sessions/schema.js +23 -0
  140. package/dist/store/agent-sessions/sql.d.ts +35 -0
  141. package/dist/store/agent-sessions/sql.js +59 -0
  142. package/dist/store/agent-sessions/sqlite.d.ts +117 -0
  143. package/dist/store/agent-sessions/sqlite.js +128 -0
  144. package/dist/store/event-log/sqlite.d.ts +75 -0
  145. package/dist/store/event-log/sqlite.js +230 -0
  146. package/dist/surface-exchanges.d.ts +97 -0
  147. package/dist/surface-exchanges.js +153 -0
  148. package/dist/terminal-session.d.ts +43 -11
  149. package/dist/terminal-session.js +22 -20
  150. package/dist/tokens.js +4 -4
  151. package/dist/tool-audit.d.ts +114 -0
  152. package/dist/tool-audit.js +95 -0
  153. package/dist/tool-executor.d.ts +22 -7
  154. package/dist/tool-executor.js +16 -16
  155. package/dist/tool-result-media.d.ts +3 -1
  156. package/dist/tool-result-media.js +1 -1
  157. package/dist/tool-result-surfaces.d.ts +3 -1
  158. package/dist/tool-result-surfaces.js +1 -1
  159. 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.
@@ -92,8 +92,8 @@
92
92
  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
- import { applyAgentLaunchEnv, 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';
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 { 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
  /**
@@ -336,6 +360,10 @@ export interface AgentExecutorRunInput {
336
360
  readonly disallowedTools?: readonly string[];
337
361
  /** Same mechanism as {@link disallowedTools}, forwarded to `RuntimeBuildOptions.allowedTools`. */
338
362
  readonly allowedTools?: readonly string[];
363
+ /** Forwarded verbatim to `RuntimeBuildOptions.settingSources` (an empty list = load none of the CLI's settings layers). */
364
+ readonly settingSources?: readonly string[];
365
+ /** Forwarded verbatim to `RuntimeBuildOptions.settings` (extra settings JSON or file path for this run). */
366
+ readonly settings?: string;
339
367
  }
340
368
  export interface AgentExecutor {
341
369
  /**
@@ -347,12 +375,20 @@ export interface AgentExecutor {
347
375
  * underlying run is always already transitioned to `'failed'` via
348
376
  * `lifecycle.finish()` before this rejects (see module doc's Invariant).
349
377
  */
350
- 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>;
351
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>;
352
388
  interface TerminateChildTreeDeps {
353
389
  readonly listProcessSnapshots: () => Promise<ProcessSnapshot[]>;
354
- readonly collectProcessTreePids: typeof collectProcessTreePids;
355
- readonly stopProcesses: (pids: Array<number | null | undefined>) => Promise<StopProcessesResult>;
390
+ readonly collectProcessTreePids: CollectProcessTreePidsPort;
391
+ readonly stopProcesses: StopProcessesPort;
356
392
  }
357
393
  /**
358
394
  * Which step reported a contained failure through `onCleanupFailure` (SEC-007).
@@ -430,6 +466,14 @@ export interface McpJsonInjectionOptions {
430
466
  readonly command: string;
431
467
  /** Extra argv for `command`. @default [] */
432
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>>;
433
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`). */
434
478
  readonly daemonUrl: string;
435
479
  /**
@@ -455,11 +499,18 @@ export interface McpJsonInjectionOptions {
455
499
  * @throws Anything the host's own minting throws. `run()` turns a rejection into a pre-spawn
456
500
  * `AGENT_SPAWN_FAILED` failure rather than spawning a child that cannot authenticate.
457
501
  */
458
- readonly credential?: (runId: string) => string | Promise<string>;
502
+ readonly credential?: ({ runId }: {
503
+ readonly runId: string;
504
+ }) => string | Promise<string>;
459
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) */
460
- readonly readFile?: (path: string) => Promise<string>;
506
+ readonly readFile?: ({ path }: {
507
+ readonly path: string;
508
+ }) => Promise<string>;
461
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) */
462
- readonly writeFile?: (path: string, content: string) => Promise<void>;
510
+ readonly writeFile?: ({ path, content }: {
511
+ readonly path: string;
512
+ readonly content: string;
513
+ }) => Promise<void>;
463
514
  /**
464
515
  * Removes this run's config file once the run is over — it holds a live per-run bearer token, so
465
516
  * leaving it behind is the same class of confidentiality gap as a leaked prompt file (see
@@ -467,7 +518,9 @@ export interface McpJsonInjectionOptions {
467
518
  * pre-spawn/spawn-failure path, and a rejection is reported rather than allowed to strand the run.
468
519
  * @default `fs.promises.rm(path, { force: true })` — already-gone is success, not an error.
469
520
  */
470
- readonly removeFile?: (path: string) => Promise<void>;
521
+ readonly removeFile?: ({ path }: {
522
+ readonly path: string;
523
+ }) => Promise<void>;
471
524
  /**
472
525
  * `'codex-toml'` only. Creates a fresh, randomly-named directory `prepareCodexHomeForRun` stages
473
526
  * as a run's scratch `CODEX_HOME`. **Must be non-deterministic (a real `mkdtemp`, not a
@@ -482,20 +535,39 @@ export interface McpJsonInjectionOptions {
482
535
  * template; the real suffix mkdtemp appends is what makes the path unpredictable.
483
536
  * @default `fs.mkdtemp(path.join(os.tmpdir(), prefix))`
484
537
  */
485
- readonly mkdtemp?: (prefix: string) => Promise<string>;
538
+ readonly mkdtemp?: ({ prefix }: {
539
+ readonly prefix: string;
540
+ }) => Promise<string>;
486
541
  /**
487
542
  * `'codex-toml'` only. Recursively removes the scratch `CODEX_HOME` directory `mkdtemp` above
488
543
  * created — the directory-level analogue of `removeFile`, needed because this mechanism stages a
489
544
  * whole directory (`config.toml` plus a copied `auth.json`), not one file.
490
545
  * @default `fs.rm(path, { recursive: true, force: true })` — already-gone is success, not an error.
491
546
  */
492
- readonly removeDir?: (path: string) => Promise<void>;
547
+ readonly removeDir?: ({ path }: {
548
+ readonly path: string;
549
+ }) => Promise<void>;
493
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;
494
566
  /** One `.mcp.json` `mcpServers` entry — the shape Claude Code's own config schema expects. */
495
567
  interface McpJsonServerEntry {
496
568
  readonly command: string;
497
569
  readonly args: string[];
498
- readonly env: {
570
+ readonly env: Readonly<Record<string, string>> & {
499
571
  readonly JINI_RUN_ID: string;
500
572
  readonly JINI_DAEMON_URL: string;
501
573
  /** Present only when the host supplied a `credential` resolver — see {@link McpJsonInjectionOptions.credential}. */
@@ -509,13 +581,18 @@ interface McpJsonServerEntry {
509
581
  * `writeMcpJsonForRun`'s job, which keeps the effect out of this function.
510
582
  *
511
583
  * @param runId - The run this entry scopes its child to.
512
- * @param options - `command`/`args`/`daemonUrl` from the host's injection options.
584
+ * @param options - `command`/`args`/`daemonUrl`/`env` from the host's injection options.
513
585
  * @param credential - The already-resolved bearer token, or `undefined` to omit `JINI_DAEMON_TOKEN`
514
586
  * entirely. Omitting produces byte-identical output to before this parameter existed.
515
587
  * @complexity O(1).
516
588
  * @overallScore 100/100
517
589
  */
518
- 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;
519
596
  /**
520
597
  * Merges {@link JINI_MCP_SERVER_KEY} into an existing `.mcp.json`'s `mcpServers` map, preserving
521
598
  * every other key and every other registered server untouched. A missing (`existingRaw ===
@@ -527,7 +604,10 @@ export declare function buildMcpJsonServerEntry(runId: string, options: Pick<Mcp
527
604
  * @complexity O(1) plus `JSON.parse`/`JSON.stringify`'s own cost on a small config file.
528
605
  * @overallScore 100/100
529
606
  */
530
- 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;
531
611
  /**
532
612
  * Mechanism 2 of 5 — `'acp-merge'`. Re-shapes the same bridge entry into the `mcpServers` element
533
613
  * an ACP `session/new` call carries, for the 9 ACP-native defs declaring this strategy (amr, devin,
@@ -549,7 +629,9 @@ export declare function mergeMcpJsonContent(existingRaw: string | undefined, ser
549
629
  * @complexity O(1).
550
630
  * @overallScore 100/100
551
631
  */
552
- export declare function buildAcpMcpBridgeServers(entry: McpJsonServerEntry): AcpMcpServerInput[];
632
+ export declare function buildAcpMcpBridgeServers({ entry }: {
633
+ readonly entry: McpJsonServerEntry;
634
+ }): AcpMcpServerInput[];
553
635
  /**
554
636
  * Serialises the bridge entry into the OpenCode-schema config JSON that `OPENCODE_CONFIG_CONTENT`
555
637
  * / `MIMOCODE_CONFIG_CONTENT` carries, merging into whatever the host already put in that variable
@@ -577,7 +659,10 @@ export declare function buildAcpMcpBridgeServers(entry: McpJsonServerEntry): Acp
577
659
  * @complexity O(1) plus `JSON.parse`/`JSON.stringify` over a small config document.
578
660
  * @overallScore 100/100
579
661
  */
580
- 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;
581
666
  /**
582
667
  * Merges a staged system-prompt overlay file's path into the `instructions` array of the same
583
668
  * OpenCode-schema config document {@link mergeEnvContentMcpConfig} writes `mcp` into — for a
@@ -615,7 +700,10 @@ export declare function mergeEnvContentMcpConfig(existingRaw: string | undefined
615
700
  * @complexity O(1) plus `JSON.parse`/`JSON.stringify` over a small config document.
616
701
  * @overallScore 100/100
617
702
  */
618
- 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;
619
707
  /**
620
708
  * Mechanism 5 of 5 — `'codex-toml'`'s serialization step. Builds the `[mcp_servers.jini]` TOML
621
709
  * table (plus, when the entry carries any env vars, a separate `[mcp_servers.jini.env]` table)
@@ -624,13 +712,15 @@ export declare function mergeEnvContentInstructions(existingRaw: string | undefi
624
712
  * Confirmed against a real installed Codex CLI (0.151.0), not assumed from docs: round-tripping
625
713
  * `codex mcp add <name> --env K=V -- <cmd> <args>` against a scratch `CODEX_HOME` and reading back
626
714
  * `config.toml` produced exactly this shape (`command`/`args` as TOML strings/array in the main
627
- * 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.
628
716
  * @param entry - The shared bridge entry from {@link buildMcpJsonServerEntry}.
629
717
  * @returns A TOML fragment with no leading/trailing blank-line padding — {@link buildCodexHomeConfigToml} owns spacing when combining it with existing content.
630
718
  * @complexity O(n) in the number of argv/env entries.
631
719
  * @overallScore 100/100
632
720
  */
633
- export declare function buildCodexMcpServerToml(entry: McpJsonServerEntry): string;
721
+ export declare function buildCodexMcpServerToml({ entry }: {
722
+ readonly entry: McpJsonServerEntry;
723
+ }): string;
634
724
  /**
635
725
  * Builds the full `config.toml` a run's scratch `CODEX_HOME` gets: the real Codex home's own
636
726
  * config, with any pre-existing `[mcp_servers.jini]` table removed (see
@@ -651,7 +741,10 @@ export declare function buildCodexMcpServerToml(entry: McpJsonServerEntry): stri
651
741
  * @returns The full text to write to the scratch `CODEX_HOME`'s `config.toml`.
652
742
  * @complexity O(n) in the existing config's length.
653
743
  */
654
- 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;
655
748
  /**
656
749
  * Where `'codex-toml'` reads the operator's REAL Codex config from, to seed a run's scratch copy —
657
750
  * never where it writes. Resolved against the daemon HOST process's own environment (`hostEnv`,
@@ -664,7 +757,9 @@ export declare function buildCodexHomeConfigToml(existingRaw: string | undefined
664
757
  * @complexity O(1).
665
758
  * @overallScore 100/100
666
759
  */
667
- export declare function resolveSourceCodexHomeDir(hostEnv: NodeJS.ProcessEnv): string;
760
+ export declare function resolveSourceCodexHomeDir({ hostEnv }: {
761
+ readonly hostEnv: NodeJS.ProcessEnv;
762
+ }): string;
668
763
  /**
669
764
  * What one run's MCP bridge turns into, discriminated by the delivery mechanism its def declared.
670
765
  * Exactly one variant is produced per run, and each variant carries only what its own consumer
@@ -763,10 +858,19 @@ export type PreparedClaudeConfigDir = {
763
858
  };
764
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. */
765
860
  export interface ClaudeConfigDirSeams {
766
- readonly mkdtemp: (prefix: string) => Promise<string>;
767
- readonly readFile: (path: string) => Promise<string>;
768
- readonly writeFile: (path: string, content: string) => Promise<void>;
769
- 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>;
770
874
  }
771
875
  /**
772
876
  * `CreateAgentExecutorOptions.claudeConfigDirIsolation` — every field optional and real-filesystem
@@ -779,13 +883,22 @@ export interface ClaudeConfigDirSeams {
779
883
  */
780
884
  export interface ClaudeConfigDirIsolationOptions {
781
885
  /** @default the real `fs.promises.mkdtemp(path.join(os.tmpdir(), prefix))` */
782
- readonly mkdtemp?: (prefix: string) => Promise<string>;
886
+ readonly mkdtemp?: ({ prefix }: {
887
+ readonly prefix: string;
888
+ }) => Promise<string>;
783
889
  /** Reads the operator's real `.credentials.json`, if any — see {@link prepareClaudeConfigDirForRun}'s own doc. @default the real `fs.promises.readFile` (utf8) */
784
- readonly readFile?: (path: string) => Promise<string>;
890
+ readonly readFile?: ({ path }: {
891
+ readonly path: string;
892
+ }) => Promise<string>;
785
893
  /** Writes the copied `.credentials.json` into the scratch directory. @default the real `fs.promises.writeFile` (utf8) */
786
- readonly writeFile?: (path: string, content: string) => Promise<void>;
894
+ readonly writeFile?: ({ path, content }: {
895
+ readonly path: string;
896
+ readonly content: string;
897
+ }) => Promise<void>;
787
898
  /** @default `fs.promises.rm(path, { recursive: true, force: true })` — already-gone is success, not an error. */
788
- readonly removeDir?: (path: string) => Promise<void>;
899
+ readonly removeDir?: ({ path }: {
900
+ readonly path: string;
901
+ }) => Promise<void>;
789
902
  }
790
903
  /**
791
904
  * Where `claude`'s own config resolution reads the operator's REAL config from, to seed a run's
@@ -799,7 +912,9 @@ export interface ClaudeConfigDirIsolationOptions {
799
912
  * default, `~/.claude`.
800
913
  * @complexity O(1).
801
914
  */
802
- export declare function resolveSourceClaudeConfigDir(hostEnv: NodeJS.ProcessEnv): string;
915
+ export declare function resolveSourceClaudeConfigDir({ hostEnv }: {
916
+ readonly hostEnv: NodeJS.ProcessEnv;
917
+ }): string;
803
918
  /**
804
919
  * Gap 4 of the run/chat orchestration Final Recommendation: what
805
920
  * `classifyFailure` (see `CreateAgentExecutorOptions.classifyFailure`) is
@@ -861,7 +976,9 @@ export type ClassifyFailure = (context: FailureClassificationContext) => boolean
861
976
  export declare const DEFAULT_BUFFERED_STDOUT_MAX_BYTES: number;
862
977
  /** The side-effect signals {@link applyAgentTranslationSideEffects} reports through, one callback per signal so a caller only wires the ones it actually tracks. */
863
978
  interface AgentTranslationSideEffectSink {
864
- readonly onSessionId: (sessionId: string) => void;
979
+ readonly onSessionId: (args: {
980
+ readonly sessionId: string;
981
+ }) => void;
865
982
  readonly onToolCall: () => void;
866
983
  readonly onUserVisibleOutput: () => void;
867
984
  }
@@ -877,13 +994,19 @@ interface AgentTranslationSideEffectSink {
877
994
  * @param sink - The driver-specific effects to apply.
878
995
  * @complexity O(1).
879
996
  */
880
- 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;
881
1002
  export interface CreateAgentExecutorOptions {
882
1003
  readonly lifecycle: RunLifecycle;
883
1004
  /** @default the real `@jini-ai/agent-runtime` registry lookup */
884
1005
  readonly getAgentDef?: typeof getAgentDef;
885
1006
  /** @default the real `@jini-ai/agent-runtime` launch resolver */
886
1007
  readonly resolveAgentLaunch?: typeof resolveAgentLaunch;
1008
+ /** @default the real `@jini-ai/agent-runtime` once-per-binary `--help` capability probe */
1009
+ readonly ensureAgentCapabilities?: typeof ensureAgentCapabilities;
887
1010
  /** @default the real `@jini-ai/agent-runtime` PATH-env composer */
888
1011
  readonly applyAgentLaunchEnv?: typeof applyAgentLaunchEnv;
889
1012
  /** @default the real `@jini-ai/platform` cross-platform invocation builder */
@@ -920,9 +1043,9 @@ export interface CreateAgentExecutorOptions {
920
1043
  /** @default the real `@jini-ai/platform` process-snapshot enumerator */
921
1044
  readonly listProcessSnapshots?: typeof listProcessSnapshots;
922
1045
  /** @default the real `@jini-ai/platform` descendant-PID collector */
923
- readonly collectProcessTreePids?: typeof collectProcessTreePids;
1046
+ readonly collectProcessTreePids?: CollectProcessTreePidsPort;
924
1047
  /** @default the real `@jini-ai/platform` SIGTERM→SIGKILL escalator */
925
- readonly stopProcesses?: typeof stopProcesses;
1048
+ readonly stopProcesses?: StopProcessesPort;
926
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` */
927
1050
  readonly onCleanupFailure?: (context: AgentCleanupFailureContext) => void;
928
1051
  /**
@@ -1030,72 +1153,97 @@ export interface CreateAgentExecutorOptions {
1030
1153
  * @overallScore 100/100
1031
1154
  */
1032
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. */
1033
- 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>;
1034
1161
  interface ResolvedDefAndFormat {
1035
1162
  readonly def: RuntimeAgentDef;
1036
1163
  readonly streamFormat: SupportedStreamFormat;
1037
1164
  }
1038
1165
  /** Phase 1: registry lookup + `assessAgentExecutorCompatibility` guard. */
1039
- export declare function resolveDefAndStreamFormat(input: Pick<AgentExecutorRunInput, 'runId' | 'agentId'>, deps: {
1040
- readonly getAgentDef: typeof getAgentDef;
1041
- 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
+ };
1042
1172
  }): Promise<ResolvedDefAndFormat>;
1043
1173
  /** Phase 2: image-prompt-delivery augmentation + argv-budget guard for argv-bound defs. */
1044
- export declare function resolveImageDeliveryAndArgvBudget(input: {
1045
- readonly runId: string;
1046
- readonly def: RuntimeAgentDef;
1047
- readonly prompt: string;
1048
- readonly imagePaths: readonly string[] | undefined;
1049
- readonly extraAllowedDirs: readonly string[] | undefined;
1050
- }, deps: {
1051
- 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
+ };
1052
1185
  }): Promise<ImagePromptDelivery>;
1053
1186
  /**
1054
1187
  * Phase 3a: the subprocess environment this run's launch resolution and spawn should use — the
1055
1188
  * caller-supplied escape hatch verbatim, or the deny-by-default `BASELINE_AGENT_ENV_KEYS` allowlist.
1056
1189
  * Pure.
1057
1190
  */
1058
- 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>;
1059
1195
  /** A resolved launch whose `launchPath` is confirmed non-null — see {@link resolveLaunch}. */
1060
1196
  type ConfirmedAgentLaunchResolution = AgentLaunchResolution & {
1061
1197
  readonly launchPath: string;
1062
1198
  };
1063
1199
  /** Phase 3b: launch-path resolution + binary-not-resolved guard. */
1064
- export declare function resolveLaunch(input: {
1065
- readonly runId: string;
1066
- readonly def: RuntimeAgentDef;
1067
- readonly resolvedEnv: Record<string, string>;
1068
- }, deps: {
1069
- readonly resolveAgentLaunch: typeof resolveAgentLaunch;
1070
- 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
+ };
1071
1210
  }): Promise<ConfirmedAgentLaunchResolution>;
1072
1211
  /** Phase 4a: stage a `promptViaFile` def's prompt to a temp file (a no-op for every other def). */
1073
- export declare function stagePromptFile(input: {
1074
- readonly runId: string;
1075
- readonly def: RuntimeAgentDef;
1076
- readonly prompt: string;
1077
- }, deps: {
1078
- readonly preparePromptFileForAgent: typeof preparePromptFileForAgent;
1079
- 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
+ };
1080
1222
  }): Promise<PreparedPromptFile | null>;
1081
1223
  /** Phase 4b: stage a `needsAgentLogFile` def's diagnostic-log path (a no-op for every other def). */
1082
- export declare function stageLogFile(input: {
1083
- readonly runId: string;
1084
- readonly def: RuntimeAgentDef;
1085
- readonly preparedPromptFile: PreparedPromptFile | null;
1086
- }, deps: {
1087
- readonly prepareAgentLogFile: typeof prepareAgentLogFile;
1088
- 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
+ };
1089
1234
  }): Promise<PreparedAgentLogFile | null>;
1090
1235
  /** Phase 5: resolves this run's MCP bridge delivery (credential resolution + {@link buildMcpBridgeDelivery}). */
1091
- export declare function resolveMcpBridgeForRun(input: {
1092
- readonly runId: string;
1093
- readonly cwd: string;
1094
- readonly def: RuntimeAgentDef;
1095
- }, deps: {
1096
- readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1097
- readonly cleanupStagedFiles: () => Promise<void>;
1098
- 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
+ };
1099
1247
  }): Promise<McpBridgeDelivery | null>;
1100
1248
  /**
1101
1249
  * Phase 6a/10c: the subprocess environment every env-riding mechanism uses — mechanism 3+4
@@ -1118,10 +1266,18 @@ export declare function resolveMcpBridgeForRun(input: {
1118
1266
  * @complexity O(1) plus `mergeEnvContentMcpConfig`'s and `mergeEnvContentInstructions`'s own `JSON.parse`/`JSON.stringify` cost.
1119
1267
  * @overallScore 100/100
1120
1268
  */
1121
- export declare function computeChildEnv(spawnEnv: NodeJS.ProcessEnv, mcpBridge: McpBridgeDelivery | null, codexHomeDir?: string, systemPromptEnvOverrides?: Readonly<Record<string, string>>, stagedInstructionsFile?: {
1122
- readonly varName: string;
1123
- readonly path: string;
1124
- }, 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;
1125
1281
  /**
1126
1282
  * Phase 6b: the `RuntimeContext` `buildArgs` receives — `undefined` unless a file, bridge path, or
1127
1283
  * session id was staged. Pure.
@@ -1133,9 +1289,20 @@ export declare function computeChildEnv(spawnEnv: NodeJS.ProcessEnv, mcpBridge:
1133
1289
  * session id, with no prompt/log file staged and no claude-mcp-json bridge, is exactly the common
1134
1290
  * case for a resumed turn.
1135
1291
  */
1136
- export declare function computeRuntimeContext(preparedPromptFile: PreparedPromptFile | null, preparedLogFile: PreparedAgentLogFile | null, mcpBridge: McpBridgeDelivery | null, resumeSessionId?: string | null, newSessionId?: string): RuntimeContext | undefined;
1137
- /** 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. */
1138
- export declare function buildAgentBuildArgsOptions(input: Pick<AgentExecutorRunInput, 'model' | 'reasoning' | 'permissionMode' | 'disallowedTools' | 'allowedTools'>, 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;
1139
1306
  /**
1140
1307
  * {@link resolveSystemPromptOverlayDelivery}'s decision, threaded out of that one resolver to every
1141
1308
  * channel that can actually carry the overlay to the CLI.
@@ -1235,32 +1402,38 @@ export declare function resolveSystemPromptOverlayDelivery(input: {
1235
1402
  * therefore only ever reach the 7 defs whose `buildArgs` reads its first argument at all — the
1236
1403
  * other 17 declare it `_prompt` and discard it, which is exactly how the overlay used to go missing.
1237
1404
  */
1238
- export declare function buildRunArgs(input: {
1239
- readonly runId: string;
1240
- readonly def: RuntimeAgentDef;
1241
- readonly imageDelivery: ImagePromptDelivery;
1242
- readonly imagePaths: readonly string[] | undefined;
1243
- readonly runInput: Pick<AgentExecutorRunInput, 'model' | 'reasoning' | 'permissionMode'>;
1244
- readonly systemPromptOverlay: string | null | undefined;
1245
- readonly overlayDelivery: SystemPromptOverlayDelivery;
1246
- readonly runtimeContext: RuntimeContext | undefined;
1247
- }, deps: {
1248
- readonly releaseStagedResources: () => Promise<void>;
1249
- 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
+ };
1250
1420
  }): Promise<{
1251
1421
  readonly args: string[];
1252
1422
  readonly envOverrides: Readonly<Record<string, string>>;
1253
1423
  }>;
1254
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). */
1255
- export declare function writeMcpJsonIfNeeded(input: {
1256
- readonly runId: string;
1257
- readonly cwd: string;
1258
- readonly def: RuntimeAgentDef;
1259
- readonly mcpBridge: McpBridgeDelivery | null;
1260
- }, deps: {
1261
- readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1262
- readonly releaseStagedResources: () => Promise<void>;
1263
- 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
+ };
1264
1437
  }): Promise<string | undefined>;
1265
1438
  /** {@link prepareSystemPromptOverlayFileIfNeeded}'s result. */
1266
1439
  export type PreparedSystemPromptOverlayFile = {
@@ -1287,13 +1460,16 @@ export type PreparedSystemPromptOverlayFile = {
1287
1460
  * @complexity O(1) plus one directory creation and one file write.
1288
1461
  * @overallScore 100/100
1289
1462
  */
1290
- export declare function prepareSystemPromptOverlayFileIfNeeded(input: {
1291
- readonly runId: string;
1292
- readonly def: RuntimeAgentDef;
1293
- readonly overlay: string | null | undefined;
1294
- }, deps: {
1295
- readonly releaseStagedResources: () => Promise<void>;
1296
- 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
+ };
1297
1473
  }): Promise<PreparedSystemPromptOverlayFile | null>;
1298
1474
  /**
1299
1475
  * Phase 10b: mechanism 5 of 5's one effect — stages this run's scratch `CODEX_HOME` directory,
@@ -1305,15 +1481,18 @@ export declare function prepareSystemPromptOverlayFileIfNeeded(input: {
1305
1481
  * @complexity O(1) plus {@link prepareCodexHomeForRun}'s own cost.
1306
1482
  * @overallScore 100/100
1307
1483
  */
1308
- export declare function prepareCodexHomeIfNeeded(input: {
1309
- readonly runId: string;
1310
- readonly def: RuntimeAgentDef;
1311
- readonly mcpBridge: McpBridgeDelivery | null;
1312
- }, deps: {
1313
- readonly mcpJsonInjection: McpJsonInjectionOptions | undefined;
1314
- readonly hostEnv: NodeJS.ProcessEnv;
1315
- readonly releaseStagedResources: () => Promise<void>;
1316
- 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
+ };
1317
1496
  }): Promise<PreparedCodexHome | null>;
1318
1497
  /**
1319
1498
  * Finding 1 of SEC-assistant-env-isolation-2026-09-07's one effect — stages this run's scratch
@@ -1338,25 +1517,31 @@ export declare function prepareCodexHomeIfNeeded(input: {
1338
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.
1339
1518
  * @complexity O(1) plus {@link prepareClaudeConfigDirForRun}'s own cost.
1340
1519
  */
1341
- export declare function prepareClaudeConfigDirIfNeeded(input: {
1342
- readonly runId: string;
1343
- readonly def: RuntimeAgentDef;
1344
- }, deps: {
1345
- readonly enabled: boolean;
1346
- readonly claudeConfigDirIsolation: ClaudeConfigDirIsolationOptions | undefined;
1347
- readonly hostEnv: NodeJS.ProcessEnv;
1348
- readonly releaseStagedResources: () => Promise<void>;
1349
- 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
+ };
1350
1532
  }): Promise<PreparedClaudeConfigDir | null>;
1351
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. */
1352
- export declare function guardWindowsCommandLineBudget(input: {
1353
- readonly runId: string;
1354
- readonly def: RuntimeAgentDef;
1355
- readonly launchPath: string;
1356
- readonly args: readonly string[];
1357
- }, deps: {
1358
- readonly releaseStagedResources: () => Promise<void>;
1359
- 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
+ };
1360
1545
  }): Promise<void>;
1361
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. */
1362
1547
  export type SpawnAgentChildProcessResult = {
@@ -1385,30 +1570,44 @@ export type SpawnAgentChildProcessResult = {
1385
1570
  * which are safe to make asynchronous since no child (and hence no listener race) exists yet.
1386
1571
  * @complexity O(1) plus `spawn`'s own cost.
1387
1572
  */
1388
- export declare function spawnAgentChildProcess(input: {
1389
- readonly cwd: string;
1390
- readonly childEnv: NodeJS.ProcessEnv;
1391
- readonly invocation: ReturnType<typeof createCommandInvocation>;
1392
- }, deps: {
1393
- 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
+ };
1394
1582
  }): SpawnAgentChildProcessResult;
1395
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`. */
1396
- 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
+ };
1397
1589
  /** Phase 13: awaits spawn confirmation, routing a failure through the same `failBeforeSpawn` shape every earlier guard uses. */
1398
- export declare function confirmChildSpawned(input: {
1399
- readonly runId: string;
1400
- readonly def: RuntimeAgentDef;
1401
- readonly child: ChildProcess;
1402
- }, deps: {
1403
- readonly releaseStagedResources: () => Promise<void>;
1404
- 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
+ };
1405
1600
  }): Promise<void>;
1406
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. */
1407
- export declare function armHandoffWatcher(runtimeLockHold: RuntimeLockHold | undefined, handoffInput: {
1408
- readonly logFilePath: string | undefined;
1409
- readonly model: string | undefined;
1410
- readonly processExited: AbortSignal;
1411
- }, 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;
1412
1611
  interface RunAcpDispatchInput {
1413
1612
  readonly runId: string;
1414
1613
  readonly agentId: string;
@@ -1432,7 +1631,10 @@ interface RunAcpDispatchDeps extends TerminateChildTreeDeps {
1432
1631
  readonly failBeforeSpawn: FailBeforeSpawn;
1433
1632
  }
1434
1633
  /** Phase 15 (ACP branch): attaches the ACP session, escalating process-tree teardown and failing the run through `failBeforeSpawn` on an attach-time throw. */
1435
- 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>;
1436
1638
  interface RunPiRpcDispatchInput {
1437
1639
  readonly runId: string;
1438
1640
  readonly agentId: string;
@@ -1454,7 +1656,10 @@ interface RunPiRpcDispatchDeps extends TerminateChildTreeDeps {
1454
1656
  readonly failBeforeSpawn: FailBeforeSpawn;
1455
1657
  }
1456
1658
  /** Phase 15 (pi-rpc branch): same discipline as {@link runAcpDispatch}, for the one `'pi-rpc'` def. */
1457
- export declare function runPiRpcDispatch(input: RunPiRpcDispatchInput, deps: RunPiRpcDispatchDeps): Promise<void>;
1458
- 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;
1459
1664
  export {};
1460
1665
  //# sourceMappingURL=agent-executor.d.ts.map