@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
@@ -0,0 +1,18 @@
1
+ import { type RuntimeAgentDef, type RuntimeLockHold } from '@jini-ai/agent-runtime';
2
+ /**
3
+ * Phase 7: acquires a `runtimeLock` def's process-global mutex before `buildArgs` runs — see
4
+ * `RuntimeLock`'s own doc for the concrete race. A no-op (`undefined`) for the 23 of 24 defs with no
5
+ * `runtimeLock` declared.
6
+ */
7
+ export declare function acquireRuntimeLockIfConfigured(def: RuntimeAgentDef, model: string | undefined): Promise<RuntimeLockHold | undefined>;
8
+ /** 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. */
9
+ export declare function armHandoffWatcher({ runtimeLockHold, handoffInput, release }: {
10
+ readonly runtimeLockHold: RuntimeLockHold | undefined;
11
+ readonly handoffInput: {
12
+ readonly logFilePath: string | undefined;
13
+ readonly model: string | undefined;
14
+ readonly processExited: AbortSignal;
15
+ };
16
+ readonly release: () => void;
17
+ }): void;
18
+ //# sourceMappingURL=handoff.d.ts.map
@@ -0,0 +1,16 @@
1
+ import {} from '@jini-ai/agent-runtime';
2
+ /**
3
+ * Phase 7: acquires a `runtimeLock` def's process-global mutex before `buildArgs` runs — see
4
+ * `RuntimeLock`'s own doc for the concrete race. A no-op (`undefined`) for the 23 of 24 defs with no
5
+ * `runtimeLock` declared.
6
+ */
7
+ export async function acquireRuntimeLockIfConfigured(def, model) {
8
+ return def.runtimeLock?.acquire({ model });
9
+ }
10
+ /** 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. */
11
+ export function armHandoffWatcher({ runtimeLockHold, handoffInput, release }) {
12
+ if (!runtimeLockHold?.waitForHandoff)
13
+ return;
14
+ void runtimeLockHold.waitForHandoff(handoffInput).then(release, release);
15
+ }
16
+ //# sourceMappingURL=handoff.js.map
@@ -0,0 +1,98 @@
1
+ /**
2
+ * `AgentExecutor` — the driver `RunLifecycle`'s own module doc names as the
3
+ * missing piece: *"It does not spawn or signal a subprocess... A driver...
4
+ * calls `emit()` for agent/stdout/stderr/error events, observes cancellation
5
+ * via `onCancelRequested`, and calls `finish()` once it knows the real
6
+ * outcome."* This folder is that driver — it wires `@jini-ai/agent-runtime`'s
7
+ * registry/launch-resolution/stream-parsers (previously a complete but
8
+ * disconnected library, zero callers anywhere outside its own package) into
9
+ * a real `node:child_process` spawn, feeding both `RunLifecycle.emit()` and
10
+ * this package's own `@jini-ai/protocol` event envelope.
11
+ *
12
+ * ## v1 scope: all 24 registered agent defs
13
+ *
14
+ * `@jini-ai/agent-runtime`'s registry ships 24 built-in defs across four
15
+ * `streamFormat` families. The JSON-stream-parser family — the four
16
+ * `createXStreamHandler`-shaped parsers (`claude-stream-json`,
17
+ * `json-event-stream`, `copilot-stream-json`, `qoder-stream-json`), covering
18
+ * 9 defs (amp, codebuddy, claude, codex, cursor-agent, opencode, mimo,
19
+ * copilot, qoder) — plus all 9 `acp-json-rpc` defs, plus the one `pi-rpc`
20
+ * def (`pi`), are wired here. ACP and pi-rpc each own their own JSON-RPC
21
+ * prompt-delivery protocol, so each takes its own lifecycle branch rather
22
+ * than being treated as a stdout-tail parser; pi-rpc's events arrive through
23
+ * the exact same `{type, ...}` vocabulary `translateAgentRuntimeEvent`
24
+ * already handles for ACP/JSON-stream (confirmed by reading every
25
+ * `mapPiRpcEvent` `send()` call site — no new translation code was needed),
26
+ * so only the driver wiring (spawn → attach → cancel → finish) was new for it.
27
+ *
28
+ * All 5 `streamFormat: 'plain'` defs — grok-build, aider, deepseek, qwen,
29
+ * antigravity — are also driven, per
30
+ * `ADS-memory/reports/proposals/PROP-plain-format-agent-driving-2026-07-21.md`'s
31
+ * recommended "Option B": no structured stream parser at all. By default
32
+ * every raw `child.stdout` chunk is forwarded verbatim as a `text_delta`
33
+ * `'agent'` event, live, as it arrives (see `wireChildLifecycle`'s
34
+ * `streamFormat === 'plain'` branch). Prompt delivery across the 5 is not
35
+ * uniform: qwen and antigravity already fit the pre-existing stdin-only
36
+ * guard; grok-build stages the prompt to a temp file via
37
+ * `preparePromptFileForAgent` (its path threaded into `buildArgs` through a
38
+ * `RuntimeContext`, cleaned up after the child exits on every path,
39
+ * including pre-spawn/spawn-failure ones); aider/deepseek carry the prompt
40
+ * on argv and are guarded pre-spawn by `checkPromptArgvBudget` plus the two
41
+ * Windows CreateProcess command-line-expansion guards
42
+ * (`checkWindowsCmdShimCommandLineBudget`/`checkWindowsDirectExeCommandLineBudget`).
43
+ *
44
+ * ## Antigravity's two extra needs, met declaratively
45
+ *
46
+ * Antigravity was the one def this driver rejected outright, for two reasons
47
+ * the proposal doc (§2c) scoped out to a follow-up: `agy` can print an OAuth
48
+ * sign-in URL to stdout and *still exit 0*, so live streaming leaks it; and
49
+ * its model choice is written into one process-global `settings.json` that
50
+ * `agy` reads on its own startup, so two concurrent runs race on it.
51
+ *
52
+ * Both are now met through **declarative `RuntimeAgentDef` fields this driver
53
+ * reads generically** — `needsAgentLogFile`, `stdoutPolicy`, `runtimeLock` —
54
+ * not a `def.id === 'antigravity'` branch. That mirrors how all 14 of the
55
+ * def's other optional behavior flags (`promptViaFile`, `authProbe`,
56
+ * `capturesSessionIdFromStream`, …) already work, and it is a deliberate
57
+ * divergence from OD's own `server.ts`, which hardcodes `def.id ===
58
+ * 'antigravity'` twice. The three fields are no-ops for the other 23 defs,
59
+ * none of which declares any of them — so nothing else's behavior changed.
60
+ *
61
+ * `run()` still rejects cleanly (never a bare throw) with an
62
+ * `AgentExecutorError` for any def whose `streamFormat` or prompt-delivery
63
+ * shape this driver does not implement — see `isSupportedStreamFormat` and
64
+ * `assessAgentExecutorCompatibility`.
65
+ *
66
+ * ## Invariant
67
+ *
68
+ * `RunLifecycle.start()` already transitions a run to `'running'` before
69
+ * `run()` is ever called. Every *pre-spawn* failure path in `run()` — unknown
70
+ * `agentId`, an unsupported `streamFormat`/prompt-delivery shape, an
71
+ * unresolvable binary, or a spawn error — calls `lifecycle.finish({status:
72
+ * 'failed', resumable: false, code: null, signal: null})` itself before
73
+ * rejecting, so a run can never get stuck `'running'` with no watchdog.
74
+ * `resumable` is unconditionally `false` on these paths — there is no spawned
75
+ * child, hence nothing a classifier could examine (see
76
+ * `FailureClassificationContext`'s own doc).
77
+ *
78
+ * For a run that *did* spawn and then failed, `resumable` is decided by
79
+ * `classifyFailure` (gap 4 — see `ClassifyFailure`'s own doc), an injectable
80
+ * port with no default of its own in this module (`undefined` stays
81
+ * byte-identical to pre-gap-4 behavior — every `'failed'` outcome
82
+ * resumable:false). OD's ~20-vendor-CLI text-matching failure classifier was
83
+ * deliberately never ported (see `run/core/failure-taxonomy.ts`'s own doc and
84
+ * `archived provenance ledger`). The real zero-config classifier lives in `@jini-ai/daemon`'s
85
+ * `run/core/retry.ts` (`resumableFromProcessExit`/`classifyProcessExitFailure`)
86
+ * and is wired in by `@jini-ai/server`'s `createLocalNodeDaemon` — see that
87
+ * package's own archived provenance ledger, and `run/core/retry.ts`'s own doc for the
88
+ * classification policy and its 2026-07-22 merge-time reconciliation against
89
+ * a second, independently-built (and rejected) classifier that once lived in
90
+ * this module.
91
+ */
92
+ export { type SupportedStreamFormat, type AgentExecutorCompatibility, type AgentRuntimeEventTranslation, type AgentExecutorErrorCode, AgentExecutorError, type AgentExecutorRunInput, type AgentExecutor, type CollectProcessTreePidsPort, type StopProcessesPort, type AgentCleanupFailurePhase, type AgentCleanupFailureContext, type ContinuationOptions, type McpJsonInjectionOptions, type McpBridgeDelivery, type PreparedCodexHome, type PreparedClaudeConfigDir, type ClaudeConfigDirSeams, type ClaudeConfigDirIsolationOptions, type FailureClassificationContext, type ClassifyFailure, type CreateAgentExecutorOptions, type SystemPromptOverlayDelivery, type PreparedSystemPromptOverlayFile, type SpawnAgentChildProcessResult, } from './contracts.js';
93
+ export { isSupportedStreamFormat, assessAgentExecutorCompatibility, isAgentExecutorSupported, resolveDefAndStreamFormat, resolveImageDeliveryAndArgvBudget, resolveRunEnv, resolveLaunch, stagePromptFile, stageLogFile, computeChildEnv, computeRuntimeContext, buildAgentBuildArgsOptions, resolveSystemPromptOverlayDelivery, buildRunArgs, prepareSystemPromptOverlayFileIfNeeded, guardWindowsCommandLineBudget, spawnAgentChildProcess, isStdinDrivenFormat, confirmChildSpawned, createAgentExecutor, } from './launch.js';
94
+ export { extractUsageTokens, translateStatusEvent, translateToolResultEvent, translateErrorEvent, translateTurnEndEvent, translateAgentRuntimeEvent, applyAgentTranslationSideEffects, } from './event-translation.js';
95
+ export { MCP_BRIDGE_UNAVAILABLE, unavailableJiniBridgeStatus, buildMcpJsonServerEntry, mergeMcpJsonContent, buildAcpMcpBridgeServers, mergeEnvContentMcpConfig, mergeEnvContentInstructions, buildCodexMcpServerToml, buildCodexHomeConfigToml, resolveSourceCodexHomeDir, buildMcpBridgeDelivery, resolveSourceClaudeConfigDir, resolveMcpBridgeForRun, writeMcpJsonIfNeeded, prepareCodexHomeIfNeeded, prepareClaudeConfigDirIfNeeded, } from './mcp-bridge.js';
96
+ export { DEFAULT_BUFFERED_STDOUT_MAX_BYTES, runAcpDispatch, runPiRpcDispatch, } from './events.js';
97
+ export { armHandoffWatcher, } from './handoff.js';
98
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,98 @@
1
+ /**
2
+ * `AgentExecutor` — the driver `RunLifecycle`'s own module doc names as the
3
+ * missing piece: *"It does not spawn or signal a subprocess... A driver...
4
+ * calls `emit()` for agent/stdout/stderr/error events, observes cancellation
5
+ * via `onCancelRequested`, and calls `finish()` once it knows the real
6
+ * outcome."* This folder is that driver — it wires `@jini-ai/agent-runtime`'s
7
+ * registry/launch-resolution/stream-parsers (previously a complete but
8
+ * disconnected library, zero callers anywhere outside its own package) into
9
+ * a real `node:child_process` spawn, feeding both `RunLifecycle.emit()` and
10
+ * this package's own `@jini-ai/protocol` event envelope.
11
+ *
12
+ * ## v1 scope: all 24 registered agent defs
13
+ *
14
+ * `@jini-ai/agent-runtime`'s registry ships 24 built-in defs across four
15
+ * `streamFormat` families. The JSON-stream-parser family — the four
16
+ * `createXStreamHandler`-shaped parsers (`claude-stream-json`,
17
+ * `json-event-stream`, `copilot-stream-json`, `qoder-stream-json`), covering
18
+ * 9 defs (amp, codebuddy, claude, codex, cursor-agent, opencode, mimo,
19
+ * copilot, qoder) — plus all 9 `acp-json-rpc` defs, plus the one `pi-rpc`
20
+ * def (`pi`), are wired here. ACP and pi-rpc each own their own JSON-RPC
21
+ * prompt-delivery protocol, so each takes its own lifecycle branch rather
22
+ * than being treated as a stdout-tail parser; pi-rpc's events arrive through
23
+ * the exact same `{type, ...}` vocabulary `translateAgentRuntimeEvent`
24
+ * already handles for ACP/JSON-stream (confirmed by reading every
25
+ * `mapPiRpcEvent` `send()` call site — no new translation code was needed),
26
+ * so only the driver wiring (spawn → attach → cancel → finish) was new for it.
27
+ *
28
+ * All 5 `streamFormat: 'plain'` defs — grok-build, aider, deepseek, qwen,
29
+ * antigravity — are also driven, per
30
+ * `ADS-memory/reports/proposals/PROP-plain-format-agent-driving-2026-07-21.md`'s
31
+ * recommended "Option B": no structured stream parser at all. By default
32
+ * every raw `child.stdout` chunk is forwarded verbatim as a `text_delta`
33
+ * `'agent'` event, live, as it arrives (see `wireChildLifecycle`'s
34
+ * `streamFormat === 'plain'` branch). Prompt delivery across the 5 is not
35
+ * uniform: qwen and antigravity already fit the pre-existing stdin-only
36
+ * guard; grok-build stages the prompt to a temp file via
37
+ * `preparePromptFileForAgent` (its path threaded into `buildArgs` through a
38
+ * `RuntimeContext`, cleaned up after the child exits on every path,
39
+ * including pre-spawn/spawn-failure ones); aider/deepseek carry the prompt
40
+ * on argv and are guarded pre-spawn by `checkPromptArgvBudget` plus the two
41
+ * Windows CreateProcess command-line-expansion guards
42
+ * (`checkWindowsCmdShimCommandLineBudget`/`checkWindowsDirectExeCommandLineBudget`).
43
+ *
44
+ * ## Antigravity's two extra needs, met declaratively
45
+ *
46
+ * Antigravity was the one def this driver rejected outright, for two reasons
47
+ * the proposal doc (§2c) scoped out to a follow-up: `agy` can print an OAuth
48
+ * sign-in URL to stdout and *still exit 0*, so live streaming leaks it; and
49
+ * its model choice is written into one process-global `settings.json` that
50
+ * `agy` reads on its own startup, so two concurrent runs race on it.
51
+ *
52
+ * Both are now met through **declarative `RuntimeAgentDef` fields this driver
53
+ * reads generically** — `needsAgentLogFile`, `stdoutPolicy`, `runtimeLock` —
54
+ * not a `def.id === 'antigravity'` branch. That mirrors how all 14 of the
55
+ * def's other optional behavior flags (`promptViaFile`, `authProbe`,
56
+ * `capturesSessionIdFromStream`, …) already work, and it is a deliberate
57
+ * divergence from OD's own `server.ts`, which hardcodes `def.id ===
58
+ * 'antigravity'` twice. The three fields are no-ops for the other 23 defs,
59
+ * none of which declares any of them — so nothing else's behavior changed.
60
+ *
61
+ * `run()` still rejects cleanly (never a bare throw) with an
62
+ * `AgentExecutorError` for any def whose `streamFormat` or prompt-delivery
63
+ * shape this driver does not implement — see `isSupportedStreamFormat` and
64
+ * `assessAgentExecutorCompatibility`.
65
+ *
66
+ * ## Invariant
67
+ *
68
+ * `RunLifecycle.start()` already transitions a run to `'running'` before
69
+ * `run()` is ever called. Every *pre-spawn* failure path in `run()` — unknown
70
+ * `agentId`, an unsupported `streamFormat`/prompt-delivery shape, an
71
+ * unresolvable binary, or a spawn error — calls `lifecycle.finish({status:
72
+ * 'failed', resumable: false, code: null, signal: null})` itself before
73
+ * rejecting, so a run can never get stuck `'running'` with no watchdog.
74
+ * `resumable` is unconditionally `false` on these paths — there is no spawned
75
+ * child, hence nothing a classifier could examine (see
76
+ * `FailureClassificationContext`'s own doc).
77
+ *
78
+ * For a run that *did* spawn and then failed, `resumable` is decided by
79
+ * `classifyFailure` (gap 4 — see `ClassifyFailure`'s own doc), an injectable
80
+ * port with no default of its own in this module (`undefined` stays
81
+ * byte-identical to pre-gap-4 behavior — every `'failed'` outcome
82
+ * resumable:false). OD's ~20-vendor-CLI text-matching failure classifier was
83
+ * deliberately never ported (see `run/core/failure-taxonomy.ts`'s own doc and
84
+ * `archived provenance ledger`). The real zero-config classifier lives in `@jini-ai/daemon`'s
85
+ * `run/core/retry.ts` (`resumableFromProcessExit`/`classifyProcessExitFailure`)
86
+ * and is wired in by `@jini-ai/server`'s `createLocalNodeDaemon` — see that
87
+ * package's own archived provenance ledger, and `run/core/retry.ts`'s own doc for the
88
+ * classification policy and its 2026-07-22 merge-time reconciliation against
89
+ * a second, independently-built (and rejected) classifier that once lived in
90
+ * this module.
91
+ */
92
+ export { AgentExecutorError, } from './contracts.js';
93
+ export { isSupportedStreamFormat, assessAgentExecutorCompatibility, isAgentExecutorSupported, resolveDefAndStreamFormat, resolveImageDeliveryAndArgvBudget, resolveRunEnv, resolveLaunch, stagePromptFile, stageLogFile, computeChildEnv, computeRuntimeContext, buildAgentBuildArgsOptions, resolveSystemPromptOverlayDelivery, buildRunArgs, prepareSystemPromptOverlayFileIfNeeded, guardWindowsCommandLineBudget, spawnAgentChildProcess, isStdinDrivenFormat, confirmChildSpawned, createAgentExecutor, } from './launch.js';
94
+ export { extractUsageTokens, translateStatusEvent, translateToolResultEvent, translateErrorEvent, translateTurnEndEvent, translateAgentRuntimeEvent, applyAgentTranslationSideEffects, } from './event-translation.js';
95
+ export { MCP_BRIDGE_UNAVAILABLE, unavailableJiniBridgeStatus, buildMcpJsonServerEntry, mergeMcpJsonContent, buildAcpMcpBridgeServers, mergeEnvContentMcpConfig, mergeEnvContentInstructions, buildCodexMcpServerToml, buildCodexHomeConfigToml, resolveSourceCodexHomeDir, buildMcpBridgeDelivery, resolveSourceClaudeConfigDir, resolveMcpBridgeForRun, writeMcpJsonIfNeeded, prepareCodexHomeIfNeeded, prepareClaudeConfigDirIfNeeded, } from './mcp-bridge.js';
96
+ export { DEFAULT_BUFFERED_STDOUT_MAX_BYTES, runAcpDispatch, runPiRpcDispatch, } from './events.js';
97
+ export { armHandoffWatcher, } from './handoff.js';
98
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,375 @@
1
+ import { spawn as nodeSpawn, type ChildProcess } from 'node:child_process';
2
+ import { getAgentDef, resolveAgentLaunch, prepareAgentLogFile, preparePromptFileForAgent, type AgentLaunchResolution, type PreparedAgentLogFile, type PreparedPromptFile, type RuntimeAgentDef, type RuntimeBuildOptions, type RuntimeContext } from '@jini-ai/agent-runtime';
3
+ import { createCommandInvocation } from '@jini-ai/platform';
4
+ import { type ImagePromptDelivery } from '../image-prompt-delivery.js';
5
+ import { type SupportedStreamFormat, type ChildDrivenStreamFormat, type AgentExecutorCompatibility, type AgentExecutorRunInput, type AgentExecutor, type McpBridgeDelivery, type CreateAgentExecutorOptions, type FailBeforeSpawn, type SystemPromptOverlayDelivery, type PreparedSystemPromptOverlayFile, type SpawnAgentChildProcessResult } from './contracts.js';
6
+ /**
7
+ * Narrows a `RuntimeAgentDef.streamFormat` string to the supported
8
+ * families.
9
+ * @param value - The def's raw `streamFormat` string.
10
+ * @returns `true` when `value` is one of the JSON-stream-parser, ACP, pi-rpc, or plain formats this driver wires.
11
+ * @complexity O(1) — fixed membership check.
12
+ * @overallScore 100/100
13
+ */
14
+ export declare function isSupportedStreamFormat(args: {
15
+ readonly value: string;
16
+ }): args is {
17
+ readonly value: SupportedStreamFormat;
18
+ };
19
+ /**
20
+ * The single source of truth for whether this executor can drive a def.
21
+ *
22
+ * It exists because that knowledge was previously reachable only by *calling* `run()` and inspecting
23
+ * the failure. Anything that lists agents for a user to pick from — a discovery route, an agent
24
+ * picker, a CLI healthcheck — needs the same answer *before* a run exists, and had no way to ask it.
25
+ * The observable symptom was a consumer advertising an agent that its own executor then rejected the
26
+ * instant it was selected.
27
+ *
28
+ * `run()` consumes this rather than re-checking the conditions itself, so the discovery-time answer
29
+ * and the run-time guards cannot disagree. A predicate that merely duplicated the guards would be
30
+ * the same bug in a second location.
31
+ *
32
+ * @param def - The def to assess. Must be the **full** `RuntimeAgentDef`, not a projected
33
+ * `DetectedAgent`: that type omits `maxPromptArgBytes`, one of the three prompt-delivery signals
34
+ * checked here, so the argv-bound defs (`aider`, `deepseek`) would be misjudged as unsupported.
35
+ * @returns A discriminated result — see {@link AgentExecutorCompatibility}. The `reason` text is
36
+ * operator-facing and is what `run()` reports as its `AGENT_RUNTIME_UNSUPPORTED` message.
37
+ * @complexity O(1) — fixed field checks.
38
+ * @overallScore 100/100
39
+ */
40
+ export declare function assessAgentExecutorCompatibility({ def }: {
41
+ readonly def: RuntimeAgentDef;
42
+ }): AgentExecutorCompatibility;
43
+ /**
44
+ * Whether `run()` can actually drive this def — the discovery-time counterpart to the guards inside
45
+ * `run()`, so a consumer never offers a user an agent that fails the moment it is selected.
46
+ *
47
+ * @param def - The full `RuntimeAgentDef`; see {@link assessAgentExecutorCompatibility} for why a
48
+ * projected `DetectedAgent` is not sufficient.
49
+ * @returns `true` when this executor would attempt the run.
50
+ * @complexity O(1).
51
+ * @overallScore 100/100
52
+ */
53
+ export declare function isAgentExecutorSupported({ def }: {
54
+ readonly def: RuntimeAgentDef;
55
+ }): boolean;
56
+ interface ResolvedDefAndFormat {
57
+ readonly def: RuntimeAgentDef;
58
+ readonly streamFormat: SupportedStreamFormat;
59
+ }
60
+ /** Phase 1: registry lookup + `assessAgentExecutorCompatibility` guard. */
61
+ export declare function resolveDefAndStreamFormat({ input, deps }: {
62
+ readonly input: Pick<AgentExecutorRunInput, 'runId' | 'agentId'>;
63
+ readonly deps: {
64
+ readonly getAgentDef: typeof getAgentDef;
65
+ readonly failBeforeSpawn: FailBeforeSpawn;
66
+ };
67
+ }): Promise<ResolvedDefAndFormat>;
68
+ /** Phase 2: image-prompt-delivery augmentation + argv-budget guard for argv-bound defs. */
69
+ export declare function resolveImageDeliveryAndArgvBudget({ input, deps }: {
70
+ readonly input: {
71
+ readonly runId: string;
72
+ readonly def: RuntimeAgentDef;
73
+ readonly prompt: string;
74
+ readonly imagePaths: readonly string[] | undefined;
75
+ readonly extraAllowedDirs: readonly string[] | undefined;
76
+ };
77
+ readonly deps: {
78
+ readonly failBeforeSpawn: FailBeforeSpawn;
79
+ };
80
+ }): Promise<ImagePromptDelivery>;
81
+ /**
82
+ * Phase 3a: the subprocess environment this run's launch resolution and spawn should use — the
83
+ * caller-supplied escape hatch verbatim, or the deny-by-default `BASELINE_AGENT_ENV_KEYS` allowlist.
84
+ * Pure.
85
+ */
86
+ export declare function resolveRunEnv({ input, hostEnv }: {
87
+ readonly input: Pick<AgentExecutorRunInput, 'env' | 'credentialEnv'>;
88
+ readonly hostEnv: NodeJS.ProcessEnv;
89
+ }): Record<string, string>;
90
+ /** A resolved launch whose `launchPath` is confirmed non-null — see {@link resolveLaunch}. */
91
+ type ConfirmedAgentLaunchResolution = AgentLaunchResolution & {
92
+ readonly launchPath: string;
93
+ };
94
+ /** Phase 3b: launch-path resolution + binary-not-resolved guard. */
95
+ export declare function resolveLaunch({ input, deps }: {
96
+ readonly input: {
97
+ readonly runId: string;
98
+ readonly def: RuntimeAgentDef;
99
+ readonly resolvedEnv: Record<string, string>;
100
+ };
101
+ readonly deps: {
102
+ readonly resolveAgentLaunch: typeof resolveAgentLaunch;
103
+ readonly failBeforeSpawn: FailBeforeSpawn;
104
+ };
105
+ }): Promise<ConfirmedAgentLaunchResolution>;
106
+ /** Phase 4a: stage a `promptViaFile` def's prompt to a temp file (a no-op for every other def). */
107
+ export declare function stagePromptFile({ input, deps }: {
108
+ readonly input: {
109
+ readonly runId: string;
110
+ readonly def: RuntimeAgentDef;
111
+ readonly prompt: string;
112
+ };
113
+ readonly deps: {
114
+ readonly preparePromptFileForAgent: typeof preparePromptFileForAgent;
115
+ readonly failBeforeSpawn: FailBeforeSpawn;
116
+ };
117
+ }): Promise<PreparedPromptFile | null>;
118
+ /** Phase 4b: stage a `needsAgentLogFile` def's diagnostic-log path (a no-op for every other def). */
119
+ export declare function stageLogFile({ input, deps }: {
120
+ readonly input: {
121
+ readonly runId: string;
122
+ readonly def: RuntimeAgentDef;
123
+ readonly preparedPromptFile: PreparedPromptFile | null;
124
+ };
125
+ readonly deps: {
126
+ readonly prepareAgentLogFile: typeof prepareAgentLogFile;
127
+ readonly failBeforeSpawn: FailBeforeSpawn;
128
+ };
129
+ }): Promise<PreparedAgentLogFile | null>;
130
+ /**
131
+ * Phase 6a/10c: the subprocess environment every env-riding mechanism uses — mechanism 3+4
132
+ * (`'opencode-env-content'`/`'mimo-env-content'`, merged into whatever the host already set there,
133
+ * never a CLI argument: the config embeds `JINI_DAEMON_TOKEN`, and process arguments are readable
134
+ * by any other local user through `ps`), mechanism 5 (`'codex-toml'`, `CODEX_HOME` relocation),
135
+ * mechanism 6 (`'env-passthrough'`, the bridge entry's flat env vars set directly with no carrier
136
+ * document — see {@link McpBridgeDelivery}'s own doc), a
137
+ * `systemPromptDelivery: 'env-var'` def's overlay (`reasonix`'s `REASONIX_ACP_SYSTEM_APPEND` today
138
+ * — see `resolveSystemPromptOverlayDelivery`'s own doc), and a `'config-instructions-file'` def's
139
+ * staged overlay file (`opencode` today — see {@link mergeEnvContentInstructions}'s own doc). Pure
140
+ * — `codexHomeDir` and `stagedInstructionsFile` arrive already staged by
141
+ * {@link prepareCodexHomeIfNeeded} and {@link prepareSystemPromptOverlayFileIfNeeded} respectively,
142
+ * the only parts of this mechanism that are NOT pure (real `mkdtemp`/`writeFile` calls).
143
+ * @param spawnEnv - The env every other spawn-time step (launch-path resolution, `applyAgentLaunchEnv`) already computed.
144
+ * @param mcpBridge - This run's resolved bridge delivery, or `null` for an unconfigured host / no-strategy def.
145
+ * @param codexHomeDir - The staged scratch `CODEX_HOME` path for a `'codex-toml'` def, or `undefined` for every other run (including a `'codex-toml'` def when `mcpJsonInjection` was never configured — see `prepareCodexHomeIfNeeded`'s own gate).
146
+ * @param systemPromptEnvOverrides - `resolveSystemPromptOverlayDelivery`'s `envOverrides` — `{}` (default) for every def but an `'env-var'`-strategy one with an overlay present, in which case it carries that one var. Applied after `codexHomeDir`, so it can never be shadowed by it — the two never share a key (`CODEX_HOME` vs. e.g. `REASONIX_ACP_SYSTEM_APPEND`), so the ordering is a documentation choice, not a correctness one.
147
+ * @param stagedInstructionsFile - `varName` (from the def's own `systemPromptDelivery` declaration) and the staged overlay file's `path`, or `undefined` for every def but a `'config-instructions-file'` one with an overlay present. Merged into `varName`'s value AFTER the `mcp` merge above (reading `envContentApplied`, not the original `spawnEnv`, for that same key) so both a `mcp` entry and an `instructions` entry from the two mechanisms survive together in one document — confirmed live this coexistence is safe (see {@link mergeEnvContentInstructions}'s doc).
148
+ * @complexity O(1) plus `mergeEnvContentMcpConfig`'s and `mergeEnvContentInstructions`'s own `JSON.parse`/`JSON.stringify` cost.
149
+ * @overallScore 100/100
150
+ */
151
+ export declare function computeChildEnv({ spawnEnv, mcpBridge }: {
152
+ readonly spawnEnv: NodeJS.ProcessEnv;
153
+ readonly mcpBridge: McpBridgeDelivery | null;
154
+ }, { codexHomeDir, systemPromptEnvOverrides, stagedInstructionsFile, claudeConfigDir }?: {
155
+ readonly codexHomeDir?: string;
156
+ readonly systemPromptEnvOverrides?: Readonly<Record<string, string>>;
157
+ readonly stagedInstructionsFile?: {
158
+ readonly varName: string;
159
+ readonly path: string;
160
+ };
161
+ readonly claudeConfigDir?: string;
162
+ }): NodeJS.ProcessEnv;
163
+ /**
164
+ * Phase 6b: the `RuntimeContext` `buildArgs` receives — `undefined` unless a file, bridge path, or
165
+ * session id was staged. Pure.
166
+ *
167
+ * `resumeSessionId`/`newSessionId` round-trip a prior run's `RunEndPayload.sessionRef` (see
168
+ * `@jini-ai/protocol`'s doc on that field) back into this run's `RuntimeContext`, letting a
169
+ * `resumesSessionViaCli` def (e.g. claude) continue its own CLI session across turns instead of
170
+ * spawning cold every time. Either one alone must still produce a context — a run supplying ONLY a
171
+ * session id, with no prompt/log file staged and no claude-mcp-json bridge, is exactly the common
172
+ * case for a resumed turn.
173
+ */
174
+ export declare function computeRuntimeContext({ preparedPromptFile, preparedLogFile, mcpBridge }: {
175
+ readonly preparedPromptFile: PreparedPromptFile | null;
176
+ readonly preparedLogFile: PreparedAgentLogFile | null;
177
+ readonly mcpBridge: McpBridgeDelivery | null;
178
+ }, { resumeSessionId, newSessionId }?: {
179
+ readonly resumeSessionId?: string | null;
180
+ readonly newSessionId?: string;
181
+ }): RuntimeContext | undefined;
182
+ /** Phase 9a: the def's `buildArgs` 4th argument. Historically omitted when every override was absent;
183
+ * that let defs silently enable auto-approval. Always supply the validated restricted default now. Pure. */
184
+ export declare function buildAgentBuildArgsOptions({ input, systemPromptOverlay }: {
185
+ readonly input: Pick<AgentExecutorRunInput, 'model' | 'reasoning' | 'permissionMode' | 'disallowedTools' | 'allowedTools' | 'settingSources' | 'settings'>;
186
+ readonly systemPromptOverlay: string | null | undefined;
187
+ }): RuntimeBuildOptions | undefined;
188
+ /**
189
+ * **The single dispatch point from a computed system-prompt overlay to its delivery mechanism** —
190
+ * see `RuntimeAgentDef.systemPromptDelivery`'s own doc for the declared shape. Pure and
191
+ * synchronous, mirroring {@link buildMcpBridgeDelivery}'s "keyed off the declared strategy, never
192
+ * off the def's id" contract: a def earns overlay delivery by declaring a strategy, not by being
193
+ * named in this file. That is what makes every def with no declaration work via the fallback
194
+ * without any of their own files being touched.
195
+ *
196
+ * The fallback (no declared strategy — every def but `claude` today) prefixes the overlay directly
197
+ * onto the composed prompt text, clearly delimited from the user's own request. It is gated on
198
+ * session state, not merely on whether an overlay exists: a def that carries its own conversation
199
+ * memory across spawns (`resumesSessionViaCli` / `resumesSessionViaAcpLoad`) persists whatever its
200
+ * session-creating turn sends it — see `RuntimeContext.resumeSessionId`'s own doc: its presence on
201
+ * a run means "continue a prior session", not "start one". Prefixing on every later turn of that
202
+ * same session would therefore bake the overlay into the CLI's own stored history again and again,
203
+ * compounding without bound turn over turn. So the fallback prefixes only when there is no resume
204
+ * target yet (the session's own first turn, or a def with no session memory at all, which never
205
+ * replays anything back at the CLI and so gets it on every turn).
206
+ *
207
+ * `'append-flag'` and `'env-var'` defs are the opposite case: the flag/env var is a fresh,
208
+ * un-stored per-spawn directive — never part of what a resumed session replays — so it is set on
209
+ * every turn unconditionally, exactly `claude`'s pre-existing (now-centralized) behavior before
210
+ * this function existed.
211
+ *
212
+ * @param input.defId - Looks up this def's probed capabilities for an `'append-flag'` strategy's
213
+ * `capabilityKey`. Otherwise unused — the dispatch itself is keyed off `systemPromptDelivery`, per
214
+ * this function's own doc above, never off the id.
215
+ * @param input.systemPromptDelivery - The def's declared strategy, or `undefined` for the fallback.
216
+ * @param input.resumesSessionViaCli - The def's own flag (see `RuntimeAgentDef`'s doc).
217
+ * @param input.resumesSessionViaAcpLoad - The def's own flag (see `RuntimeAgentDef`'s doc).
218
+ * @param input.overlay - The computed `PromptAugmenter.systemOverlay()` result. `null`/`undefined`/
219
+ * empty short-circuits to "no delivery" — byte-identical to no `PromptAugmenter` configured at all.
220
+ * @param input.prompt - The composed prompt `buildArgs` would otherwise receive verbatim.
221
+ * @param input.resumeSessionId - This run's `RuntimeContext.resumeSessionId`; presence means an
222
+ * existing session is being continued, not created.
223
+ * @returns A {@link SystemPromptOverlayDelivery}: the prefix this run's prompt text must carry
224
+ * (`''` unless the fallback applies), that prefix already applied to `input.prompt`, any extra argv
225
+ * to append to whatever `buildArgs` itself returns, and any env var overrides to merge into the
226
+ * spawn env (`{}` for every strategy but `'env-var'`). Every one of `run()`'s four prompt
227
+ * transports consumes this same result — see the interface's own no-double-delivery note.
228
+ * @complexity O(n) in the overlay/prompt lengths — string concatenation only, no I/O.
229
+ * @overallScore 100/100
230
+ */
231
+ export declare function resolveSystemPromptOverlayDelivery(input: {
232
+ readonly defId: string;
233
+ readonly systemPromptDelivery: RuntimeAgentDef['systemPromptDelivery'];
234
+ readonly resumesSessionViaCli: boolean | undefined;
235
+ readonly resumesSessionViaAcpLoad: boolean | undefined;
236
+ readonly overlay: string | null | undefined;
237
+ readonly prompt: string;
238
+ readonly resumeSessionId: string | null | undefined;
239
+ }): SystemPromptOverlayDelivery;
240
+ /**
241
+ * Phase 9b: calls the def's `buildArgs`, releasing staged resources and failing the run on a throw.
242
+ *
243
+ * @param input.overlayDelivery - This run's already-resolved overlay decision, computed once in
244
+ * `run()` rather than here. It is resolved upstream because `buildArgs` is only ONE of the four
245
+ * channels that can carry the prompt: the staged prompt file is written *before* this function
246
+ * runs, and stdin/ACP/pi-rpc send theirs *after* spawn. A decision made inside this function could
247
+ * therefore only ever reach the 7 defs whose `buildArgs` reads its first argument at all — the
248
+ * other 17 declare it `_prompt` and discard it, which is exactly how the overlay used to go missing.
249
+ */
250
+ export declare function buildRunArgs({ input, deps }: {
251
+ readonly input: {
252
+ readonly runId: string;
253
+ readonly def: RuntimeAgentDef;
254
+ readonly imageDelivery: ImagePromptDelivery;
255
+ readonly imagePaths: readonly string[] | undefined;
256
+ readonly runInput: Pick<AgentExecutorRunInput, 'model' | 'reasoning' | 'permissionMode'>;
257
+ readonly systemPromptOverlay: string | null | undefined;
258
+ readonly overlayDelivery: SystemPromptOverlayDelivery;
259
+ readonly runtimeContext: RuntimeContext | undefined;
260
+ };
261
+ readonly deps: {
262
+ readonly releaseStagedResources: () => Promise<void>;
263
+ readonly failBeforeSpawn: FailBeforeSpawn;
264
+ };
265
+ }): Promise<{
266
+ readonly args: string[];
267
+ readonly envOverrides: Readonly<Record<string, string>>;
268
+ }>;
269
+ /**
270
+ * Phase 10b1: `systemPromptDelivery: { strategy: 'config-instructions-file' }`'s one effect —
271
+ * stages the computed overlay to a fresh, run-scoped temp file, so `computeChildEnv` has a real
272
+ * path to merge into that def's `instructions` config array (see
273
+ * {@link mergeEnvContentInstructions}'s own doc for the live verification this mechanism rests on).
274
+ * `null` for every other strategy, an unset `systemPromptDelivery`, or no overlay present at all —
275
+ * byte-identical to before this mechanism existed, matching {@link writeMcpJsonIfNeeded}'s and
276
+ * {@link prepareCodexHomeIfNeeded}'s identical no-op-when-inapplicable gate.
277
+ *
278
+ * `opencode`'s `instructions` field only accepts a file path or a remote URL — confirmed live
279
+ * (2026-09-01): a literal instruction string in the array is silently ignored (no error, just never
280
+ * honored), so an inline-text shortcut is not available and this staging step is load-bearing, not
281
+ * a defensive extra.
282
+ * @param input.def - Only used for its `id`, in the failure message, and its `systemPromptDelivery` declaration.
283
+ * @param input.overlay - The computed `PromptAugmenter.systemOverlay()` result for this run.
284
+ * @complexity O(1) plus one directory creation and one file write.
285
+ * @overallScore 100/100
286
+ */
287
+ export declare function prepareSystemPromptOverlayFileIfNeeded({ input, deps }: {
288
+ readonly input: {
289
+ readonly runId: string;
290
+ readonly def: RuntimeAgentDef;
291
+ readonly overlay: string | null | undefined;
292
+ };
293
+ readonly deps: {
294
+ readonly releaseStagedResources: () => Promise<void>;
295
+ readonly failBeforeSpawn: FailBeforeSpawn;
296
+ };
297
+ }): Promise<PreparedSystemPromptOverlayFile | null>;
298
+ /** 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. */
299
+ export declare function guardWindowsCommandLineBudget({ input, deps }: {
300
+ readonly input: {
301
+ readonly runId: string;
302
+ readonly def: RuntimeAgentDef;
303
+ readonly launchPath: string;
304
+ readonly args: readonly string[];
305
+ };
306
+ readonly deps: {
307
+ readonly releaseStagedResources: () => Promise<void>;
308
+ readonly failBeforeSpawn: FailBeforeSpawn;
309
+ };
310
+ }): Promise<void>;
311
+ /**
312
+ * Phase 12: the real `node:child_process.spawn` call.
313
+ *
314
+ * **Deliberately synchronous, unlike every other phase in this file.** A spawned child can emit
315
+ * `'error'` on the very next microtask tick (Node schedules it eagerly on some failure modes, and a
316
+ * test harness simulating "the child emits 'error' before 'spawn'" does so explicitly via
317
+ * `queueMicrotask`). `run()` must register its `'error'` listeners (`wireChildLifecycle`'s safety net,
318
+ * then `waitForSpawnOrError`'s `child.once('error', reject)`) in the *same synchronous turn* as this
319
+ * spawn call — Node's `EventEmitter` throws synchronously when `'error'` fires with zero listeners
320
+ * attached. Wrapping this call in an `async function` and `await`ing it (as every other phase here
321
+ * does) would insert a microtask tick between spawn and listener registration, occasionally losing
322
+ * that race — confirmed by a real test failure during this refactor (an uncaught `EventEmitter`
323
+ * `'error'` exception) before this function was changed back to a plain, unawaited call returning a
324
+ * result object instead of throwing/rejecting.
325
+ * @returns `{kind:'ok', child}` on success, `{kind:'error', error}` on a synchronous throw from `spawn`
326
+ * — `run()` itself is responsible for cleanup and `failBeforeSpawn` on the error variant, both of
327
+ * which are safe to make asynchronous since no child (and hence no listener race) exists yet.
328
+ * @complexity O(1) plus `spawn`'s own cost.
329
+ */
330
+ export declare function spawnAgentChildProcess({ input, deps }: {
331
+ readonly input: {
332
+ readonly cwd: string;
333
+ readonly childEnv: NodeJS.ProcessEnv;
334
+ readonly invocation: ReturnType<typeof createCommandInvocation>;
335
+ };
336
+ readonly deps: {
337
+ readonly spawn: typeof nodeSpawn;
338
+ };
339
+ }): SpawnAgentChildProcessResult;
340
+ /** 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`. */
341
+ export declare function isStdinDrivenFormat(args: {
342
+ readonly streamFormat: SupportedStreamFormat;
343
+ }): args is {
344
+ readonly streamFormat: ChildDrivenStreamFormat;
345
+ };
346
+ /** Phase 13: awaits spawn confirmation, routing a failure through the same `failBeforeSpawn` shape every earlier guard uses. */
347
+ export declare function confirmChildSpawned({ input, deps }: {
348
+ readonly input: {
349
+ readonly runId: string;
350
+ readonly def: RuntimeAgentDef;
351
+ readonly child: ChildProcess;
352
+ };
353
+ readonly deps: {
354
+ readonly releaseStagedResources: () => Promise<void>;
355
+ readonly failBeforeSpawn: FailBeforeSpawn;
356
+ };
357
+ }): Promise<void>;
358
+ /**
359
+ * Creates the `AgentExecutor` reference implementation: an in-process
360
+ * `RunLifecycle` driver over real (by default) `@jini-ai/agent-runtime`
361
+ * registry lookup, launch resolution, and stream parsing, plus a real
362
+ * `node:child_process.spawn`. Every collaborator is an injectable seam
363
+ * (matching this package's established convention — see
364
+ * `tool-executor.ts`/`run-lifecycle.ts`) so tests can drive a fake child
365
+ * process and a fake registry without touching the filesystem or spawning
366
+ * a real subprocess.
367
+ *
368
+ * @param options.lifecycle - The `RunLifecycle` this executor drives — its `start()` must already have been called for any `runId` passed to `run()`.
369
+ * @returns An `AgentExecutor` whose `run()` never bare-throws (see index.ts module doc's Invariant).
370
+ * @complexity `run()`'s own setup is O(1); steady-state cost is the chosen stream parser's.
371
+ * @overallScore 100/100
372
+ */
373
+ 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;
374
+ export {};
375
+ //# sourceMappingURL=launch.d.ts.map