@jini-ai/agent-runtime 0.7.3-next.2 → 0.7.4

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 (177) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +38 -0
  3. package/dist/agent-protocol/acp/models.d.ts +0 -10
  4. package/dist/agent-protocol/acp/models.js +0 -10
  5. package/dist/agent-protocol/acp/rpc.d.ts +5 -1
  6. package/dist/agent-protocol/acp/rpc.js +2 -1
  7. package/dist/agent-protocol/acp/session-permission.js +4 -3
  8. package/dist/agent-protocol/acp/session-results.d.ts +4 -4
  9. package/dist/agent-protocol/acp/session-results.js +30 -21
  10. package/dist/agent-protocol/acp/session-run.js +0 -8
  11. package/dist/agent-protocol/acp/session-types.d.ts +0 -1
  12. package/dist/agent-protocol/acp/session-usage.d.ts +12 -0
  13. package/dist/agent-protocol/acp/session-usage.js +29 -0
  14. package/dist/agent-protocol/acp/session.d.ts +1 -1
  15. package/dist/agent-protocol/acp/session.js +10 -4
  16. package/dist/agent-protocol/acp/text-suppression.js +75 -71
  17. package/dist/agent-protocol/pi-rpc/events.d.ts +21 -4
  18. package/dist/agent-protocol/pi-rpc/events.js +9 -9
  19. package/dist/agent-protocol/pi-rpc/internal.d.ts +6 -2
  20. package/dist/agent-protocol/pi-rpc/internal.js +6 -4
  21. package/dist/agent-protocol/pi-rpc/session.js +4 -3
  22. package/dist/anthropic-live-models.js +0 -0
  23. package/dist/claude-code-models.d.ts +3 -1
  24. package/dist/claude-code-models.js +4 -4
  25. package/dist/claude-stream-frames.js +1 -1
  26. package/dist/cli-probe-cache.d.ts +33 -0
  27. package/dist/cli-probe-cache.js +59 -0
  28. package/dist/custom-instructions.d.ts +107 -0
  29. package/dist/custom-instructions.js +80 -0
  30. package/dist/defs/{aider.d.ts → aider/index.d.ts} +2 -1
  31. package/dist/defs/{aider.js → aider/index.js} +6 -3
  32. package/dist/defs/amr/executable-env.d.ts +2 -0
  33. package/dist/defs/amr/executable-env.js +2 -0
  34. package/dist/defs/amr/executable-resolution.d.ts +5 -1
  35. package/dist/defs/amr/executable-resolution.js +1 -1
  36. package/dist/defs/antigravity/index.d.ts +1 -0
  37. package/dist/defs/antigravity/index.js +3 -0
  38. package/dist/defs/antigravity/permissions.d.ts +26 -0
  39. package/dist/defs/antigravity/permissions.js +66 -0
  40. package/dist/defs/{auggie.d.ts → auggie/index.d.ts} +1 -1
  41. package/dist/defs/{auggie.js → auggie/index.js} +3 -3
  42. package/dist/defs/claude/config-dir.d.ts +62 -0
  43. package/dist/defs/claude/config-dir.js +133 -0
  44. package/dist/defs/claude/filesystem.d.ts +33 -0
  45. package/dist/defs/claude/filesystem.js +30 -0
  46. package/dist/defs/{claude.d.ts → claude/index.d.ts} +1 -1
  47. package/dist/defs/{claude.js → claude/index.js} +9 -9
  48. package/dist/defs/claude/mcp-config.d.ts +22 -0
  49. package/dist/defs/claude/mcp-config.js +29 -0
  50. package/dist/defs/claude/mcp-delivery.d.ts +57 -0
  51. package/dist/defs/claude/mcp-delivery.js +75 -0
  52. package/dist/defs/claude/mcp-json.d.ts +34 -0
  53. package/dist/defs/claude/mcp-json.js +38 -0
  54. package/dist/defs/claude/subagent-start.d.ts +12 -0
  55. package/dist/defs/claude/subagent-start.js +35 -0
  56. package/dist/defs/{cline.d.ts → cline/index.d.ts} +1 -1
  57. package/dist/defs/{cline.js → cline/index.js} +3 -3
  58. package/dist/defs/codex/contracts.d.ts +47 -0
  59. package/dist/defs/codex/contracts.js +6 -0
  60. package/dist/defs/codex/event-stream.d.ts +5 -1
  61. package/dist/defs/codex/event-stream.js +29 -24
  62. package/dist/defs/codex/home-config.d.ts +55 -0
  63. package/dist/defs/codex/home-config.js +224 -0
  64. package/dist/defs/codex/home-staging.d.ts +57 -0
  65. package/dist/defs/codex/home-staging.js +184 -0
  66. package/dist/defs/{codex.d.ts → codex/index.d.ts} +2 -2
  67. package/dist/defs/{codex.js → codex/index.js} +3 -3
  68. package/dist/defs/codex/isolation.d.ts +29 -0
  69. package/dist/defs/codex/isolation.js +69 -0
  70. package/dist/defs/codex/launch.d.ts +4 -1
  71. package/dist/defs/codex/launch.js +1 -1
  72. package/dist/defs/codex/mcp-delivery.d.ts +8 -0
  73. package/dist/defs/codex/mcp-delivery.js +5 -0
  74. package/dist/defs/{crush.d.ts → crush/index.d.ts} +1 -1
  75. package/dist/defs/{crush.js → crush/index.js} +3 -3
  76. package/dist/defs/cursor-agent/event-stream.d.ts +5 -1
  77. package/dist/defs/cursor-agent/event-stream.js +14 -7
  78. package/dist/defs/{cursor-agent.d.ts → cursor-agent/index.d.ts} +1 -1
  79. package/dist/defs/{cursor-agent.js → cursor-agent/index.js} +4 -4
  80. package/dist/defs/{deepseek.d.ts → deepseek/index.d.ts} +2 -1
  81. package/dist/defs/{deepseek.js → deepseek/index.js} +6 -3
  82. package/dist/defs/{devin.d.ts → devin/index.d.ts} +1 -1
  83. package/dist/defs/{devin.js → devin/index.js} +3 -3
  84. package/dist/defs/{droid.d.ts → droid/index.d.ts} +1 -1
  85. package/dist/defs/{droid.js → droid/index.js} +3 -3
  86. package/dist/defs/gemini/event-stream.d.ts +5 -1
  87. package/dist/defs/gemini/event-stream.js +15 -12
  88. package/dist/defs/gemini/tool-calls.d.ts +7 -0
  89. package/dist/defs/gemini/tool-calls.js +9 -0
  90. package/dist/defs/{goose.d.ts → goose/index.d.ts} +1 -1
  91. package/dist/defs/{goose.js → goose/index.js} +3 -3
  92. package/dist/defs/{grok-build.d.ts → grok-build/index.d.ts} +1 -1
  93. package/dist/defs/{grok-build.js → grok-build/index.js} +3 -3
  94. package/dist/defs/index.d.ts +28 -28
  95. package/dist/defs/index.js +28 -28
  96. package/dist/defs/{kilo.d.ts → kilo/index.d.ts} +1 -1
  97. package/dist/defs/{kilo.js → kilo/index.js} +3 -3
  98. package/dist/defs/kimi/event-stream.d.ts +4 -1
  99. package/dist/defs/kimi/event-stream.js +6 -5
  100. package/dist/defs/{kimi.d.ts → kimi/index.d.ts} +1 -1
  101. package/dist/defs/{kimi.js → kimi/index.js} +3 -3
  102. package/dist/defs/{kiro.d.ts → kiro/index.d.ts} +1 -1
  103. package/dist/defs/{kiro.js → kiro/index.js} +3 -3
  104. package/dist/defs/mimo/constants.d.ts +2 -0
  105. package/dist/defs/mimo/constants.js +2 -0
  106. package/dist/defs/{mimo.d.ts → mimo/index.d.ts} +1 -1
  107. package/dist/defs/{mimo.js → mimo/index.js} +3 -3
  108. package/dist/defs/opencode/constants.d.ts +2 -0
  109. package/dist/defs/opencode/constants.js +2 -0
  110. package/dist/defs/opencode/event-stream.d.ts +5 -1
  111. package/dist/defs/opencode/event-stream.js +13 -11
  112. package/dist/defs/{opencode.d.ts → opencode/index.d.ts} +2 -2
  113. package/dist/defs/{opencode.js → opencode/index.js} +5 -5
  114. package/dist/defs/opencode/mcp-config.d.ts +108 -0
  115. package/dist/defs/opencode/mcp-config.js +119 -0
  116. package/dist/defs/opencode/model-discovery.d.ts +3 -1
  117. package/dist/defs/opencode/model-discovery.js +1 -1
  118. package/dist/defs/opencode/tool-calls.d.ts +7 -0
  119. package/dist/defs/opencode/tool-calls.js +12 -0
  120. package/dist/defs/{opencode-acp.d.ts → opencode-acp/index.d.ts} +2 -2
  121. package/dist/defs/{opencode-acp.js → opencode-acp/index.js} +4 -4
  122. package/dist/defs/{pi.d.ts → pi/index.d.ts} +1 -1
  123. package/dist/defs/{pi.js → pi/index.js} +3 -3
  124. package/dist/defs/pi/model-discovery.d.ts +4 -1
  125. package/dist/defs/pi/model-discovery.js +1 -1
  126. package/dist/defs/{qoder.d.ts → qoder/index.d.ts} +1 -1
  127. package/dist/defs/{qoder.js → qoder/index.js} +3 -3
  128. package/dist/defs/{qwen.d.ts → qwen/index.d.ts} +1 -1
  129. package/dist/defs/{qwen.js → qwen/index.js} +3 -3
  130. package/dist/defs/{reasonix.d.ts → reasonix/index.d.ts} +1 -1
  131. package/dist/defs/{reasonix.js → reasonix/index.js} +3 -3
  132. package/dist/defs/{trae-cli.d.ts → trae-cli/index.d.ts} +1 -1
  133. package/dist/defs/{trae-cli.js → trae-cli/index.js} +3 -3
  134. package/dist/defs/{vibe.d.ts → vibe/index.d.ts} +1 -1
  135. package/dist/defs/{vibe.js → vibe/index.js} +3 -3
  136. package/dist/executables.js +1 -1
  137. package/dist/inventory/index.d.ts +61 -0
  138. package/dist/inventory/index.js +45 -0
  139. package/dist/json-event-stream-shared.d.ts +10 -2
  140. package/dist/json-event-stream-shared.js +21 -13
  141. package/dist/json-event-stream.js +6 -5
  142. package/dist/launch.js +1 -1
  143. package/dist/model-catalog-live-discovery.d.ts +103 -0
  144. package/dist/model-catalog-live-discovery.js +111 -0
  145. package/dist/model-discovery-adapters.d.ts +6 -1
  146. package/dist/model-discovery-adapters.js +4 -3
  147. package/dist/model-discovery-config.js +1 -1
  148. package/dist/native-permissions.d.ts +19 -0
  149. package/dist/native-permissions.js +22 -0
  150. package/dist/providers/anthropic-messages.js +3 -2
  151. package/dist/providers/connection-guard.js +99 -84
  152. package/dist/providers/connection-test.js +0 -5
  153. package/dist/providers/google-messages.js +1 -1
  154. package/dist/providers/oauth-provider.d.ts +1 -23
  155. package/dist/providers/oauth-provider.js +1 -35
  156. package/dist/providers/openai-chat-request.js +1 -1
  157. package/dist/providers/tool-loop-verdict.d.ts +1 -0
  158. package/dist/providers/tool-loop-verdict.js +4 -1
  159. package/dist/providers/tool-turn-types.d.ts +12 -9
  160. package/dist/providers/tool-turn.d.ts +63 -1
  161. package/dist/providers/tool-turn.js +67 -1
  162. package/dist/qoder-stream.js +66 -66
  163. package/dist/role-marker-guard.js +49 -30
  164. package/dist/runtime-def-binding.js +1 -1
  165. package/dist/runtime-port-bindings.d.ts +82 -0
  166. package/dist/runtime-port-bindings.js +4 -1
  167. package/dist/runtime-strategies.d.ts +100 -0
  168. package/dist/runtime-strategies.js +129 -0
  169. package/package.json +44 -10
  170. package/dist/defs/amp.d.ts +0 -2
  171. package/dist/defs/amp.js +0 -2
  172. package/dist/defs/amr.d.ts +0 -2
  173. package/dist/defs/amr.js +0 -2
  174. package/dist/defs/codebuddy.d.ts +0 -2
  175. package/dist/defs/codebuddy.js +0 -2
  176. package/dist/defs/hermes.d.ts +0 -2
  177. package/dist/defs/hermes.js +0 -2
@@ -0,0 +1,184 @@
1
+ import { promises as fsPromises } from 'node:fs';
2
+ import { homedir, tmpdir, } from 'node:os';
3
+ import { join, resolve, } from 'node:path';
4
+ import { buildCodexHomeConfigToml } from './home-config.js';
5
+ import { assertCodexHomeConfigParses, assertStagedHomeIsolated, CodexMcpIsolationError, codexIsolationRefusalMessage } from './isolation.js';
6
+ import { omitKeys } from '../../core/omit-keys.js';
7
+ export const CODEX_HOME_ENV = 'CODEX_HOME';
8
+ /**
9
+ * Where `'codex-toml'` reads the operator's REAL Codex config from, to seed a run's scratch copy —
10
+ * never where it writes. Resolved against the daemon HOST process's own environment (`hostEnv`,
11
+ * `process.env` at the real call site), not a run's sandboxed spawn env: `CODEX_HOME` is not in
12
+ * `BASELINE_AGENT_ENV_KEYS`, so a spawned child never inherits it anyway, and the whole point here
13
+ * is finding wherever the *operator's actual* Codex install lives, which is a host-machine fact.
14
+ * @param hostEnv - The daemon process's own environment.
15
+ * @returns `hostEnv.CODEX_HOME` when set to a non-blank value (matching Codex's own resolution
16
+ * order), else the CLI's documented default, `~/.codex`.
17
+ * @complexity O(1).
18
+ * @overallScore 100/100
19
+ */
20
+ export function resolveSourceCodexHomeDir({ hostEnv }) {
21
+ const override = hostEnv.CODEX_HOME;
22
+ return override !== undefined && override.trim().length > 0 ? override : join(homedir(), '.codex');
23
+ }
24
+ /**
25
+ * The child env pointed at a staged `CODEX_HOME`. Drops `CODEX_INTERNAL_ORIGINATOR_OVERRIDE`: a
26
+ * first-party originator lets a mentioned skill install and start MCP servers (codex-rs
27
+ * `mcp_skill_dependencies.rs`), and `codex exec` is `codex_exec` without it.
28
+ */
29
+ export function withStagedCodexHome({ env, codexHomeDir }, _options = {}) {
30
+ return { ...omitKeys({ source: env, keys: ['CODEX_INTERNAL_ORIGINATOR_OVERRIDE'] }), CODEX_HOME: codexHomeDir };
31
+ }
32
+ function defaultMkdtempCodexHome({ prefix }) {
33
+ return fsPromises.mkdtemp(join(tmpdir(), prefix));
34
+ }
35
+ function defaultRemoveCodexHomeDir({ path }) {
36
+ return fsPromises.rm(path, { recursive: true, force: true });
37
+ }
38
+ /** Config credentials stay run-scoped, but rollouts must survive both completion and cancellation.
39
+ * Native links keep Codex as the sole writer of sessions and refreshed authentication.
40
+ * Parity also links skills/rules/plugins and other home entries; config.toml alone stays staged
41
+ * so run-scoped bearer tokens never reach the real config. Cleanup removes links, not targets.
42
+ * O(h) I/O for h top-level home entries; locked runs link only sessions and authentication. */
43
+ async function defaultLinkCodexSessionStore({ runHome, sourceHome }, optional = {}) {
44
+ for (const name of ['sessions', 'archived_sessions']) {
45
+ const target = resolve(sourceHome, name);
46
+ await fsPromises.mkdir(target, { recursive: true, mode: 0o700 });
47
+ await fsPromises.symlink(target, join(runHome, name), 'junction');
48
+ }
49
+ await fsPromises.symlink(join(sourceHome, 'auth.json'), join(runHome, 'auth.json'), 'file');
50
+ if (optional.inheritUserConfig !== false) {
51
+ for (const entry of await fsPromises.readdir(sourceHome, { withFileTypes: true })) {
52
+ if (['config.toml', 'auth.json', 'sessions', 'archived_sessions'].includes(entry.name))
53
+ continue;
54
+ await fsPromises.symlink(join(sourceHome, entry.name), join(runHome, entry.name), entry.isDirectory() ? 'junction' : 'file');
55
+ }
56
+ }
57
+ }
58
+ function resolveCodexHomeSeams(options) {
59
+ return {
60
+ mkdtemp: options.mkdtemp ?? defaultMkdtempCodexHome,
61
+ readFile: options.readFile,
62
+ writeFile: options.writeFile,
63
+ removeDir: options.removeDir ?? defaultRemoveCodexHomeDir,
64
+ linkSessionStore: options.linkSessionStore ?? defaultLinkCodexSessionStore,
65
+ };
66
+ }
67
+ /**
68
+ * The staged `config.toml`. With personal MCP off the real home config must parse before its line
69
+ * rewrite is trusted, and the staged home must declare only the bridge and trust no project (so
70
+ * Codex's trust gate keeps project `.codex/config.toml` layers out unless another layer trusts
71
+ * them). Plugin, app and skill-installed servers are turned off on the CLI layer (`defs/codex/index.ts`).
72
+ * Layers outside the home (system, MDM, cloud bundle) are the machine owner's policy, which Off
73
+ * doesn't override (design note 2026-10-27, option N). The spawn-time refusal in
74
+ * {@link stageCodexHome} stays the backstop for every blocked case.
75
+ * @throws {@link CodexMcpIsolationError} when the run can't be isolated.
76
+ */
77
+ function buildStagedCodexConfig({ existingRaw, entry, inheritUserConfig, inheritUserMcp, sourceHome, toolApprovalOwner }) {
78
+ const build = () => buildCodexHomeConfigToml({ existingRaw, entry, inheritUserMcp, inheritUserSettings: inheritUserConfig, toolApprovalOwner });
79
+ if (inheritUserMcp)
80
+ return build();
81
+ const path = join(sourceHome, 'config.toml');
82
+ assertCodexHomeConfigParses({ raw: existingRaw, path });
83
+ const homeConfig = build();
84
+ assertStagedHomeIsolated({ homeConfig, path });
85
+ return homeConfig;
86
+ }
87
+ /**
88
+ * Mechanism 5 of 5 — `'codex-toml'`'s one effect. Stages a fresh, randomly-named `CODEX_HOME`
89
+ * directory (see the host's `RunHomeSeams.mkdtemp` doc for why non-deterministic naming is
90
+ * load-bearing here, not cosmetic) carrying:
91
+ * - `config.toml`: the real Codex home's own config (read best-effort — see
92
+ * {@link buildCodexHomeConfigToml}'s "missing file" handling) with this run's
93
+ * `[mcp_servers.jini]` table appended.
94
+ * - `auth.json`: a link to the real Codex home's stored login, so the spawned CLI is
95
+ * still authenticated. Best-effort is safe here, not merely convenient: a real headless spawn
96
+ * against a `CODEX_HOME` with no `auth.json` at all was confirmed (against installed Codex CLI
97
+ * 0.151.0) to fail fast with a structured `401 Unauthorized` stream event, never an interactive
98
+ * login prompt or a hang — see `defs/codex/index.ts`'s module doc for the full transcript summary.
99
+ *
100
+ * Never changes the real config. Authentication is linked so a CLI token refresh survives cleanup;
101
+ * copying rotating credentials lost refreshes and could log the operator out. Deleting scratch
102
+ * state must not erase linked native state. The run-bound MCP credential stays in scratch config.
103
+ *
104
+ * A failure after the directory is created (a rejecting `writeFile`, most plausibly) does not leak
105
+ * it: the directory may already hold a partial `config.toml` or a copied credential, so the
106
+ * `catch` below best-effort-removes it before rethrowing, exactly the "partial-failure state leak"
107
+ * class of bug this package's own adversarial-test-design guidance calls out.
108
+ * @param runId - Embedded in the temp-dir prefix for traceability, sanitized the same way
109
+ * `@jini-ai/agent-runtime`'s `prepareAgentLogFile`'s `label` is.
110
+ * @param entry - The shared bridge entry.
111
+ * @param sourceCodexHomeDir - Where to read the real install's `config.toml`/`auth.json` from — see {@link resolveSourceCodexHomeDir}.
112
+ * @param seams - Injectable mkdtemp/readFile/writeFile/removeDir/linkSessionStore, real filesystem by default.
113
+ * @throws Whatever staging rejects with — the host (through the `mcpHome` slot's `stage`) turns that into a pre-spawn `AGENT_SPAWN_FAILED` failure, matching `writeMcpJsonForRun`'s own contract.
114
+ * @complexity O(h) filesystem operations for h top-level user-home entries; one staged config write.
115
+ * @overallScore 100/100
116
+ */
117
+ async function prepareCodexHomeForRun(runId, entry, sourceCodexHomeDir, seams, inheritUserConfig = true, inheritUserMcp = true, toolApprovalOwner) {
118
+ // Stricter than `@jini-ai/agent-runtime`'s `prepareAgentLogFile`/`preparePromptFileForAgent`
119
+ // labels (which keep dots): this prefix stages a directory that ends up holding a copied Codex
120
+ // login credential, so it gets `mcpJsonPathForRun`'s tighter discipline instead — dots stripped
121
+ // too, not just path separators, so a run id like `../../etc/evil` cannot leave even a cosmetic
122
+ // `..` substring in the mkdtemp prefix.
123
+ const safeRunId = runId.replace(/[^A-Za-z0-9_-]/g, '-').slice(0, 80) || 'run';
124
+ // The config is read and judged BEFORE the directory exists: an isolation refusal must acquire nothing (no scratch dir, no
125
+ // auth.json link), so there is nothing to release afterwards.
126
+ let existingConfigRaw;
127
+ try {
128
+ existingConfigRaw = inheritUserConfig || inheritUserMcp ? await seams.readFile({ path: join(sourceCodexHomeDir, 'config.toml') }) : undefined;
129
+ }
130
+ catch {
131
+ // No config yet (fresh Codex install) or unreadable — start from just this run's block,
132
+ // matching writeMcpJsonForRun's identical "missing file" handling.
133
+ existingConfigRaw = undefined;
134
+ }
135
+ const content = buildStagedCodexConfig({ existingRaw: existingConfigRaw, entry, inheritUserConfig, inheritUserMcp, sourceHome: sourceCodexHomeDir, toolApprovalOwner });
136
+ const dir = await seams.mkdtemp({ prefix: `jini-codex-home-${safeRunId}-` });
137
+ try {
138
+ await seams.writeFile({ path: join(dir, 'config.toml'), content });
139
+ await seams.linkSessionStore({ runHome: dir, sourceHome: sourceCodexHomeDir }, { inheritUserConfig });
140
+ }
141
+ catch (err) {
142
+ await seams.removeDir({ path: dir }).catch(() => {
143
+ // Best-effort only — the original error below is what the caller must see either way.
144
+ });
145
+ throw err;
146
+ }
147
+ return {
148
+ path: dir,
149
+ cleanup: async () => {
150
+ await seams.removeDir({ path: dir });
151
+ },
152
+ };
153
+ }
154
+ /** True when a Codex run turns off the operator's personal MCP servers or settings, which only a staged home can do. */
155
+ export function codexTurnsOffPersonalConfig({ nativeCapabilities }, _optional = {}) {
156
+ return nativeCapabilities?.userMcp === false || nativeCapabilities?.userSettings === false;
157
+ }
158
+ /** Which personal Codex config a staged home keeps: none when native tools are locked, else what the run's capabilities allow. */
159
+ function codexInheritance(input) {
160
+ const nativeAllowed = input.nativeToolAccess !== false;
161
+ return { settings: nativeAllowed && input.nativeCapabilities?.userSettings !== false, mcp: nativeAllowed && input.nativeCapabilities?.userMcp !== false };
162
+ }
163
+ /**
164
+ * Phase 10b's effect for Codex: stages this run's scratch `CODEX_HOME` directory. An isolation refusal comes back as
165
+ * `refused` with the user-facing message; any other staging failure rejects, for the host to turn into a pre-spawn failure.
166
+ * Either way a partially staged directory is already removed by {@link prepareCodexHomeForRun}.
167
+ * @param input.entry - The stdio bridge entry, or the explicit run listener (same isolation, state links and cleanup).
168
+ * @param input.hostEnv - The daemon's own environment, passed in rather than read from `process.env` so staging stays testable with an injected env.
169
+ * @complexity O(1) plus {@link prepareCodexHomeForRun}'s own cost.
170
+ * @overallScore 100/100
171
+ */
172
+ export async function stageCodexHome(input, _optional = {}) {
173
+ const inherit = codexInheritance(input);
174
+ try {
175
+ const home = await prepareCodexHomeForRun(input.runId, input.entry, resolveSourceCodexHomeDir({ hostEnv: input.hostEnv }), resolveCodexHomeSeams(input.io), inherit.settings, inherit.mcp, input.toolApprovalOwner);
176
+ return { kind: 'staged', home };
177
+ }
178
+ catch (err) {
179
+ if (err instanceof CodexMcpIsolationError)
180
+ return { kind: 'refused', message: codexIsolationRefusalMessage({ reason: err.message }) };
181
+ throw err;
182
+ }
183
+ }
184
+ //# sourceMappingURL=home-staging.js.map
@@ -1,5 +1,5 @@
1
1
  import type { RuntimeModelOption, RuntimeReasoningOption, RuntimeAgentDef, RuntimeBuildOptions, RuntimeContext } from '@jini-ai/core/contracts/agents';
2
- import type { CodexDefOptions } from './codex/options.js';
2
+ import type { CodexDefOptions } from './options.js';
3
3
  /**
4
4
  * Parses `codex debug models` stdout into the Local-CLI picker's model rows.
5
5
  *
@@ -97,4 +97,4 @@ export declare const codexAgentDef: {
97
97
  }): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
98
98
  };
99
99
  export {};
100
- //# sourceMappingURL=codex.d.ts.map
100
+ //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
- import { createAgentModelDiscovery } from '../model-discovery-native.js';
1
+ import { createAgentModelDiscovery } from '../../model-discovery-native.js';
2
2
  /** CODEX_SANDBOX_MODE remains an adapter-scoped operator override; plugin policy is supplied
3
3
  * explicitly by the host, whose native composition resolves CODEX_DISABLE_PLUGINS. */
4
- import { DEFAULT_MODEL_OPTION } from './shared.js';
4
+ import { DEFAULT_MODEL_OPTION } from '../shared.js';
5
5
  /**
6
6
  * The `visibility` values that mean "reachable by id, but do not render in a picker".
7
7
  *
@@ -418,4 +418,4 @@ export const codexAgentDef = {
418
418
  mcpHttp: true,
419
419
  externalMcpInjection: 'codex-toml',
420
420
  };
421
- //# sourceMappingURL=codex.js.map
421
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,29 @@
1
+ /** A run with personal MCP off that Codex cannot keep to the bridge alone: refused, never run with a leak. */
2
+ export declare class CodexMcpIsolationError extends Error {
3
+ }
4
+ /** The user-facing refusal for a {@link CodexMcpIsolationError} reason. */
5
+ export declare function codexIsolationRefusalMessage({ reason }: {
6
+ reason: string;
7
+ }, _optional?: Record<string, never>): string;
8
+ /**
9
+ * The real home config must parse before its line-based rewrite ({@link buildCodexHomeConfigToml})
10
+ * is trusted: a malformed block the rewrite drops would otherwise hide that the line scan misread
11
+ * the file. A missing file (`undefined`) is fine.
12
+ * @throws {@link CodexMcpIsolationError} when it isn't valid TOML.
13
+ */
14
+ export declare function assertCodexHomeConfigParses({ raw, path }: {
15
+ readonly raw: string | undefined;
16
+ readonly path: string;
17
+ }): void;
18
+ /**
19
+ * The staged home config, parsed: it must declare no MCP server but the bridge and trust no
20
+ * project. The home rewrite ({@link buildCodexHomeConfigToml}) is line-based so every other byte
21
+ * survives, so a server or trust entry it cannot see (an escaped header, a dotted root key) or a
22
+ * multi-line value a fake header split is refused here instead of staged. O(n) in the config length.
23
+ * @throws {@link CodexMcpIsolationError} when the staged config would not isolate the run.
24
+ */
25
+ export declare function assertStagedHomeIsolated({ homeConfig, path }: {
26
+ readonly homeConfig: string;
27
+ readonly path: string;
28
+ }): void;
29
+ //# sourceMappingURL=isolation.d.ts.map
@@ -0,0 +1,69 @@
1
+ import { parse } from 'smol-toml';
2
+ import { getRecord } from '../../json-event-stream-shared.js';
3
+ import { JINI_MCP_SERVER_KEY } from './contracts.js';
4
+ /** A run with personal MCP off that Codex cannot keep to the bridge alone: refused, never run with a leak. */
5
+ export class CodexMcpIsolationError extends Error {
6
+ }
7
+ /** The user-facing refusal for a {@link CodexMcpIsolationError} reason. */
8
+ export function codexIsolationRefusalMessage({ reason }, _optional = {}) {
9
+ return `Codex can't run with 'Your MCP servers' off: ${reason} Turn it on in the assistant settings, or choose Claude.`;
10
+ }
11
+ /**
12
+ * Parses one Codex config layer with a real TOML parser, so no spelling (quoted or escaped keys,
13
+ * dotted keys, inline tables, or a `[header]`-shaped line inside a multi-line string or array)
14
+ * hides a server from the check. A file that does not parse is refused: what it declares can't be
15
+ * known, and Codex could not load it either.
16
+ * @complexity O(n) in the file length.
17
+ */
18
+ function parseCodexLayer({ raw, path }, _optional = {}) {
19
+ // Codex isolation is a default security boundary; its parser must ship with the daemon.
20
+ try {
21
+ return parse(raw);
22
+ }
23
+ catch {
24
+ throw new CodexMcpIsolationError(`${path} isn't valid TOML, so its MCP servers can't be checked.`);
25
+ }
26
+ }
27
+ /**
28
+ * Refuses a layer that trusts a project. Codex loads a project's `.codex/config.toml` only when the
29
+ * config merged below it trusts that project (codex-rs `config/src/loader/mod.rs` L:1098-1125), so
30
+ * with no `projects` table anywhere no project layer, worktree root or root-marker range can add a
31
+ * server. Parsed, so a dotted, inline or escaped spelling is caught too.
32
+ */
33
+ function assertTrustsNoProject(config, path) {
34
+ if ('projects' in config)
35
+ throw new CodexMcpIsolationError(`${path} trusts projects in a way that can't be removed safely.`);
36
+ }
37
+ /**
38
+ * The real home config must parse before its line-based rewrite ({@link buildCodexHomeConfigToml})
39
+ * is trusted: a malformed block the rewrite drops would otherwise hide that the line scan misread
40
+ * the file. A missing file (`undefined`) is fine.
41
+ * @throws {@link CodexMcpIsolationError} when it isn't valid TOML.
42
+ */
43
+ export function assertCodexHomeConfigParses({ raw, path }) {
44
+ if (raw !== undefined)
45
+ parseCodexLayer({ raw, path });
46
+ }
47
+ /**
48
+ * The staged home config, parsed: it must declare no MCP server but the bridge and trust no
49
+ * project. The home rewrite ({@link buildCodexHomeConfigToml}) is line-based so every other byte
50
+ * survives, so a server or trust entry it cannot see (an escaped header, a dotted root key) or a
51
+ * multi-line value a fake header split is refused here instead of staged. O(n) in the config length.
52
+ * @throws {@link CodexMcpIsolationError} when the staged config would not isolate the run.
53
+ */
54
+ export function assertStagedHomeIsolated({ homeConfig, path }) {
55
+ const refusal = new CodexMcpIsolationError(`${path} declares MCP servers that can't be removed safely.`);
56
+ let config;
57
+ try {
58
+ config = parseCodexLayer({ raw: homeConfig, path });
59
+ }
60
+ catch {
61
+ throw refusal;
62
+ }
63
+ const servers = getRecord({ value: config.mcp_servers });
64
+ const ids = servers ? Object.keys(servers) : [];
65
+ if (ids.some(id => id !== JINI_MCP_SERVER_KEY))
66
+ throw refusal;
67
+ assertTrustsNoProject(config, path);
68
+ }
69
+ //# sourceMappingURL=isolation.js.map
@@ -1,3 +1,6 @@
1
1
  import type { AgentLaunchResolution } from '@jini-ai/core/contracts/agents';
2
- export declare function resolveCodexLaunch(selectedPath: string, childPathPrepend: string[]): Pick<AgentLaunchResolution, 'launchPath' | 'launchKind' | 'childPathPrepend' | 'diagnostic'>;
2
+ export declare function resolveCodexLaunch({ selectedPath, childPathPrepend }: {
3
+ selectedPath: string;
4
+ childPathPrepend: string[];
5
+ }, _optional?: Record<string, never>): Pick<AgentLaunchResolution, 'launchPath' | 'launchKind' | 'childPathPrepend' | 'diagnostic'>;
3
6
  //# sourceMappingURL=launch.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { accessSync, closeSync, constants, openSync, readdirSync, readSync, realpathSync, statSync } from 'node:fs';
2
2
  import path from 'node:path';
3
- export function resolveCodexLaunch(selectedPath, childPathPrepend) {
3
+ export function resolveCodexLaunch({ selectedPath, childPathPrepend }, _optional = {}) {
4
4
  const native = tryResolveCodexNativeBinary(selectedPath);
5
5
  return {
6
6
  launchPath: native.path ?? selectedPath,
@@ -0,0 +1,8 @@
1
+ /** The bridge delivery for a Codex run: the shared entry, written into a staged home's `config.toml` (see `home-staging.ts`). */
2
+ export declare function buildCodexMcpDelivery<E>({ serverEntry }: {
3
+ readonly serverEntry: E;
4
+ }, _optional?: Record<string, never>): {
5
+ readonly kind: 'codex-toml';
6
+ readonly serverEntry: E;
7
+ };
8
+ //# sourceMappingURL=mcp-delivery.d.ts.map
@@ -0,0 +1,5 @@
1
+ /** The bridge delivery for a Codex run: the shared entry, written into a staged home's `config.toml` (see `home-staging.ts`). */
2
+ export function buildCodexMcpDelivery({ serverEntry }, _optional = {}) {
3
+ return { kind: 'codex-toml', serverEntry };
4
+ }
5
+ //# sourceMappingURL=mcp-delivery.js.map
@@ -30,4 +30,4 @@ export declare const crushAgentDef: {
30
30
  deps?: import("@jini-ai/core/contracts/agents").ModelDiscoveryDeps;
31
31
  }): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
32
32
  };
33
- //# sourceMappingURL=crush.d.ts.map
33
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { createAgentModelDiscovery } from '../model-discovery-native.js';
1
+ import { createAgentModelDiscovery } from '../../model-discovery-native.js';
2
2
  /**
3
3
  * @module defs/crush
4
4
  *
@@ -11,7 +11,7 @@ import { createAgentModelDiscovery } from '../model-discovery-native.js';
11
11
  * No `externalMcpInjection`: Crush reads MCP servers from its `crush.json` config, with no
12
12
  * per-run flag to point it elsewhere.
13
13
  */
14
- import { DEFAULT_MODEL_OPTION } from './shared.js';
14
+ import { DEFAULT_MODEL_OPTION } from '../shared.js';
15
15
  export const crushAgentDef = {
16
16
  // UNVERIFIED live integration locally; source/category and limits are documented in model-discovery-adapters.ts.
17
17
  ...createAgentModelDiscovery('crush', { fallbackModels: () => crushAgentDef.fallbackModels }),
@@ -37,4 +37,4 @@ export const crushAgentDef = {
37
37
  promptViaStdin: true,
38
38
  streamFormat: 'plain',
39
39
  };
40
- //# sourceMappingURL=crush.js.map
40
+ //# sourceMappingURL=index.js.map
@@ -4,5 +4,9 @@ export type CursorStreamState = {
4
4
  turnStart: number;
5
5
  };
6
6
  export declare function createCursorStreamState(): CursorStreamState;
7
- export declare function handleCursorEvent(obj: unknown, onEvent: StreamEventHandler, state: ParserState): boolean;
7
+ export declare function handleCursorEvent({ obj: value, onEvent, state }: {
8
+ obj: unknown;
9
+ onEvent: StreamEventHandler;
10
+ state: ParserState;
11
+ }, _optional?: Record<string, never>): boolean;
8
12
  //# sourceMappingURL=event-stream.d.ts.map
@@ -1,10 +1,13 @@
1
- import { initializingStatus, isRecord, optionalNumber, pickUsage } from '../../json-event-stream-shared.js';
1
+ import { getRecord, initializingStatus, optionalNumber, pickUsage } from '../../json-event-stream-shared.js';
2
2
  export function createCursorStreamState() { return { textSoFar: '', turnStart: 0 }; }
3
3
  function extractCursorText(message) {
4
- const content = isRecord(message) ? message.content : undefined;
4
+ const content = getRecord({ value: message })?.content;
5
5
  const blocks = Array.isArray(content) ? content : [];
6
6
  return blocks
7
- .filter((block) => isRecord(block) && block.type === 'text' && typeof block.text === 'string')
7
+ .filter((block) => {
8
+ const record = getRecord({ value: block });
9
+ return record?.type === 'text' && typeof record.text === 'string';
10
+ })
8
11
  .map((block) => block.text)
9
12
  .join('');
10
13
  }
@@ -82,8 +85,9 @@ const CURSOR_USAGE_FIELDS = [
82
85
  ['cacheReadTokens', 'cached_read_tokens'],
83
86
  ['cacheWriteTokens', 'cached_write_tokens'],
84
87
  ];
85
- export function handleCursorEvent(obj, onEvent, state) {
86
- if (!isRecord(obj))
88
+ export function handleCursorEvent({ obj: value, onEvent, state }, _optional = {}) {
89
+ const obj = getRecord({ value });
90
+ if (!obj)
87
91
  return false;
88
92
  if (obj.type === 'system' && obj.subtype === 'init') {
89
93
  onEvent(initializingStatus({ obj }));
@@ -91,10 +95,13 @@ export function handleCursorEvent(obj, onEvent, state) {
91
95
  }
92
96
  if (obj.type === 'assistant' && obj.message)
93
97
  return handleCursorAssistant(obj, onEvent, state);
94
- if (obj.type === 'result' && isRecord(obj.usage)) {
98
+ if (obj.type === 'result') {
99
+ const usage = getRecord({ value: obj.usage });
100
+ if (!usage)
101
+ return false;
95
102
  onEvent({
96
103
  type: 'usage',
97
- usage: pickUsage({ source: obj.usage, fields: CURSOR_USAGE_FIELDS }),
104
+ usage: pickUsage({ source: usage, fields: CURSOR_USAGE_FIELDS }),
98
105
  durationMs: optionalNumber({ value: obj.duration_ms }),
99
106
  });
100
107
  return true;
@@ -52,4 +52,4 @@ export declare const cursorAgentDef: {
52
52
  }): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
53
53
  };
54
54
  export {};
55
- //# sourceMappingURL=cursor-agent.d.ts.map
55
+ //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
- import { createAgentModelDiscovery } from '../model-discovery-native.js';
2
- import { DEFAULT_MODEL_OPTION } from './shared.js';
3
- import { agentCapabilities } from '../capabilities.js';
1
+ import { createAgentModelDiscovery } from '../../model-discovery-native.js';
2
+ import { DEFAULT_MODEL_OPTION } from '../shared.js';
3
+ import { agentCapabilities } from '../../capabilities.js';
4
4
  /** Agent id, binary name and event-parser key: one string for all three. */
5
5
  const CURSOR_AGENT_ID = 'cursor-agent';
6
6
  /** One `<id>` or `<id> - <label>` listing line; header lines and non-id lines yield null. */
@@ -118,4 +118,4 @@ export const cursorAgentDef = {
118
118
  // (which relies on an explicit per-run path, never auto-discovery — see
119
119
  // `buildClaudeMcpConfigArgs`'s doc for why).
120
120
  };
121
- //# sourceMappingURL=cursor-agent.js.map
121
+ //# sourceMappingURL=index.js.map
@@ -14,6 +14,7 @@ export declare const deepseekAgentDef: {
14
14
  runtimeContext?: import("@jini-ai/core/contracts/agents").RuntimeContext;
15
15
  } | undefined) => string[];
16
16
  maxPromptArgBytes: number;
17
+ argvPromptPosition: "last";
17
18
  streamFormat: string;
18
19
  discoverModels(requiredArgs: {
19
20
  context: import("@jini-ai/core/contracts/agents").ModelDiscoveryContext;
@@ -31,4 +32,4 @@ export declare const deepseekAgentDef: {
31
32
  deps?: import("@jini-ai/core/contracts/agents").ModelDiscoveryDeps;
32
33
  }): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
33
34
  };
34
- //# sourceMappingURL=deepseek.d.ts.map
35
+ //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
- import { createAgentModelDiscovery } from '../model-discovery-native.js';
2
- import { DEFAULT_MODEL_OPTION } from './shared.js';
1
+ import { createAgentModelDiscovery } from '../../model-discovery-native.js';
2
+ import { DEFAULT_MODEL_OPTION } from '../shared.js';
3
3
  export const deepseekAgentDef = {
4
4
  // UNVERIFIED live integration locally; source/category and limits are documented in model-discovery-adapters.ts.
5
5
  ...createAgentModelDiscovery('deepseek', { fallbackModels: () => deepseekAgentDef.fallbackModels }),
@@ -50,6 +50,9 @@ export const deepseekAgentDef = {
50
50
  // argv headroom under the Windows command-line limit for `exec
51
51
  // --auto --model <id>` and any internal quoting.
52
52
  maxPromptArgBytes: 30_000,
53
+ // `buildArgs` pushes the prompt verbatim as the final argv element (pinned by
54
+ // `defs/__tests__/argv-prompt-position.test.ts`), so prompt variants may fit that slot.
55
+ argvPromptPosition: 'last',
53
56
  streamFormat: 'plain',
54
57
  // No `externalMcpInjection`: CodeWhale (this dispatcher's underlying TUI)
55
58
  // does support native MCP via `DEEPSEEK_MCP_CONFIG=<path>` — an explicit
@@ -64,4 +67,4 @@ export const deepseekAgentDef = {
64
67
  // candidate among the 12; needs a 5th strategy, not a stretch of an
65
68
  // existing one.
66
69
  };
67
- //# sourceMappingURL=deepseek.js.map
70
+ //# sourceMappingURL=index.js.map
@@ -37,4 +37,4 @@ export declare const devinAgentDef: {
37
37
  deps?: import("@jini-ai/core/contracts/agents").ModelDiscoveryDeps;
38
38
  }): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
39
39
  };
40
- //# sourceMappingURL=devin.d.ts.map
40
+ //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
- import { createAgentModelDiscovery } from '../model-discovery-native.js';
2
- import { acpModelFetcher, DEFAULT_MODEL_OPTION } from './shared.js';
1
+ import { createAgentModelDiscovery } from '../../model-discovery-native.js';
2
+ import { acpModelFetcher, DEFAULT_MODEL_OPTION } from '../shared.js';
3
3
  export const devinAgentDef = {
4
4
  // UNVERIFIED live integration locally; source/category and limits are documented in model-discovery-adapters.ts.
5
5
  ...createAgentModelDiscovery('devin', { fallbackModels: () => devinAgentDef.fallbackModels }),
@@ -43,4 +43,4 @@ export const devinAgentDef = {
43
43
  // `acp-json-rpc` def — see `types.ts#RuntimeAgentDef.imageDelivery`'s doc.
44
44
  imageDelivery: 'native',
45
45
  };
46
- //# sourceMappingURL=devin.js.map
46
+ //# sourceMappingURL=index.js.map
@@ -30,4 +30,4 @@ export declare const droidAgentDef: {
30
30
  deps?: import("@jini-ai/core/contracts/agents").ModelDiscoveryDeps;
31
31
  }): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
32
32
  };
33
- //# sourceMappingURL=droid.d.ts.map
33
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { createAgentModelDiscovery } from '../model-discovery-native.js';
1
+ import { createAgentModelDiscovery } from '../../model-discovery-native.js';
2
2
  /**
3
3
  * @module defs/droid
4
4
  *
@@ -14,7 +14,7 @@ import { createAgentModelDiscovery } from '../model-discovery-native.js';
14
14
  * variant was reported to fail with stdio MCP servers. The documented text mode is the stable one.
15
15
  * No `externalMcpInjection` for the same reason.
16
16
  */
17
- import { DEFAULT_MODEL_OPTION } from './shared.js';
17
+ import { DEFAULT_MODEL_OPTION } from '../shared.js';
18
18
  export const droidAgentDef = {
19
19
  // UNVERIFIED live integration locally; source/category and limits are documented in model-discovery-adapters.ts.
20
20
  ...createAgentModelDiscovery('droid', { fallbackModels: () => droidAgentDef.fallbackModels }),
@@ -38,4 +38,4 @@ export const droidAgentDef = {
38
38
  promptViaStdin: true,
39
39
  streamFormat: 'plain',
40
40
  };
41
- //# sourceMappingURL=droid.js.map
41
+ //# sourceMappingURL=index.js.map
@@ -6,7 +6,11 @@ export type LegacyGoogleStreamState = {
6
6
  pendingArtifactText: string;
7
7
  };
8
8
  export declare function createLegacyGoogleStreamState(): LegacyGoogleStreamState;
9
- export declare function handleLegacyGoogleStreamEvent(obj: unknown, onEvent: StreamEventHandler, state: ParserState): boolean;
9
+ export declare function handleLegacyGoogleStreamEvent({ obj: value, onEvent, state }: {
10
+ obj: unknown;
11
+ onEvent: StreamEventHandler;
12
+ state: ParserState;
13
+ }, _optional?: Record<string, never>): boolean;
10
14
  export declare function flushPendingArtifactText({ state, onEvent }: {
11
15
  state: ParserState;
12
16
  onEvent: StreamEventHandler;