@memnexus-ai/mx-agent-cli 0.1.246 → 0.1.248

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 (68) hide show
  1. package/dist/__tests__/codex-agent-gate.test.d.ts +2 -0
  2. package/dist/__tests__/codex-agent-gate.test.d.ts.map +1 -0
  3. package/dist/__tests__/codex-agent-gate.test.js +182 -0
  4. package/dist/__tests__/codex-agent-gate.test.js.map +1 -0
  5. package/dist/__tests__/runtime-claude-adapter.test.d.ts +2 -0
  6. package/dist/__tests__/runtime-claude-adapter.test.d.ts.map +1 -0
  7. package/dist/__tests__/runtime-claude-adapter.test.js +70 -0
  8. package/dist/__tests__/runtime-claude-adapter.test.js.map +1 -0
  9. package/dist/__tests__/runtime-codex-adapter.test.d.ts +2 -0
  10. package/dist/__tests__/runtime-codex-adapter.test.d.ts.map +1 -0
  11. package/dist/__tests__/runtime-codex-adapter.test.js +513 -0
  12. package/dist/__tests__/runtime-codex-adapter.test.js.map +1 -0
  13. package/dist/__tests__/runtime-codex-config.test.d.ts +2 -0
  14. package/dist/__tests__/runtime-codex-config.test.d.ts.map +1 -0
  15. package/dist/__tests__/runtime-codex-config.test.js +523 -0
  16. package/dist/__tests__/runtime-codex-config.test.js.map +1 -0
  17. package/dist/__tests__/runtime-codex-version-pin.test.d.ts +2 -0
  18. package/dist/__tests__/runtime-codex-version-pin.test.d.ts.map +1 -0
  19. package/dist/__tests__/runtime-codex-version-pin.test.js +86 -0
  20. package/dist/__tests__/runtime-codex-version-pin.test.js.map +1 -0
  21. package/dist/__tests__/runtime-resolve.test.d.ts +2 -0
  22. package/dist/__tests__/runtime-resolve.test.d.ts.map +1 -0
  23. package/dist/__tests__/runtime-resolve.test.js +172 -0
  24. package/dist/__tests__/runtime-resolve.test.js.map +1 -0
  25. package/dist/__tests__/start-rebase-never-ran.test.d.ts +25 -0
  26. package/dist/__tests__/start-rebase-never-ran.test.d.ts.map +1 -0
  27. package/dist/__tests__/start-rebase-never-ran.test.js +227 -0
  28. package/dist/__tests__/start-rebase-never-ran.test.js.map +1 -0
  29. package/dist/__tests__/start-runtime-wiring.test.d.ts +31 -0
  30. package/dist/__tests__/start-runtime-wiring.test.d.ts.map +1 -0
  31. package/dist/__tests__/start-runtime-wiring.test.js +498 -0
  32. package/dist/__tests__/start-runtime-wiring.test.js.map +1 -0
  33. package/dist/commands/codex-agent-gate.d.ts +23 -0
  34. package/dist/commands/codex-agent-gate.d.ts.map +1 -0
  35. package/dist/commands/codex-agent-gate.js +139 -0
  36. package/dist/commands/codex-agent-gate.js.map +1 -0
  37. package/dist/commands/start.d.ts +21 -0
  38. package/dist/commands/start.d.ts.map +1 -1
  39. package/dist/commands/start.js +190 -25
  40. package/dist/commands/start.js.map +1 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +23 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/lib/claude.d.ts +72 -10
  45. package/dist/lib/claude.d.ts.map +1 -1
  46. package/dist/lib/claude.js +71 -32
  47. package/dist/lib/claude.js.map +1 -1
  48. package/dist/lib/runtime/claude-adapter.d.ts +16 -0
  49. package/dist/lib/runtime/claude-adapter.d.ts.map +1 -0
  50. package/dist/lib/runtime/claude-adapter.js +43 -0
  51. package/dist/lib/runtime/claude-adapter.js.map +1 -0
  52. package/dist/lib/runtime/codex-adapter.d.ts +90 -0
  53. package/dist/lib/runtime/codex-adapter.d.ts.map +1 -0
  54. package/dist/lib/runtime/codex-adapter.js +367 -0
  55. package/dist/lib/runtime/codex-adapter.js.map +1 -0
  56. package/dist/lib/runtime/codex-config.d.ts +254 -0
  57. package/dist/lib/runtime/codex-config.d.ts.map +1 -0
  58. package/dist/lib/runtime/codex-config.js +620 -0
  59. package/dist/lib/runtime/codex-config.js.map +1 -0
  60. package/dist/lib/runtime/resolve.d.ts +46 -0
  61. package/dist/lib/runtime/resolve.d.ts.map +1 -0
  62. package/dist/lib/runtime/resolve.js +113 -0
  63. package/dist/lib/runtime/resolve.js.map +1 -0
  64. package/dist/lib/runtime/types.d.ts +81 -0
  65. package/dist/lib/runtime/types.d.ts.map +1 -0
  66. package/dist/lib/runtime/types.js +39 -0
  67. package/dist/lib/runtime/types.js.map +1 -0
  68. package/package.json +1 -1
@@ -0,0 +1,367 @@
1
+ /**
2
+ * CodexAdapter — launches a team session on OpenAI Codex (#4227 Phase 1,
3
+ * tasks 1.4, 1.8, 1.9).
4
+ *
5
+ * Mirrors `launchClaudeSession`'s process contract exactly: spawn, own the
6
+ * terminal, patch childPid into the already-claimed leader lock, propagate the
7
+ * child's exit code, remove the lock on the way out.
8
+ *
9
+ * THREE THINGS ARE DELIBERATELY CLOSED HERE:
10
+ *
11
+ * 1. THE OPT-IN IS GATED (PRD Phase 1 hard scope rule). Phase 1 cannot close and
12
+ * no non-platform team may opt in to `--runtime codex` until gate G-7 passes —
13
+ * both containment guards proven FIRING SELECTIVELY in a live Codex session
14
+ * (blocked destructive op AND a permitted op succeeding). Until that proof
15
+ * exists, `launch()` refuses. `MX_AGENT_CODEX_PHASE1_DEV=1` is the
16
+ * platform-supervised development escape hatch, and it says so in the refusal.
17
+ *
18
+ * 2. SECURITY-REVIEWER IS INELIGIBLE, HARD-CODED (FR-14b). Not a list entry a
19
+ * config can extend: its job requires Bash, and no proven Codex configuration
20
+ * supplies Bash + host-scoped read + write-deny simultaneously.
21
+ *
22
+ * 3. BAR-RAISER AND RED-TEAM ARE NOT PERSONA-INJECTED IN-SESSION (FR-14a). Their
23
+ * Codex path, if it lands, is a separately-invoked read-only wrapper process,
24
+ * not an in-session subagent.
25
+ */
26
+ import { spawn, spawnSync } from 'child_process';
27
+ import chalk from 'chalk';
28
+ import { sanitizeForMessage } from '../behavioral-injection.js';
29
+ import { removeLock, updateChildPid } from '../leader-lock.js';
30
+ import { CODEX_DEFAULT_MODEL, VERIFIED_CODEX_VERSION, codexHookTrustPreconditions, deployCodexConfig, } from './codex-config.js';
31
+ /** Signal name → number, for mapping a signal-kill to a 128+signum exit code. */
32
+ const SIGNAL_NUMBERS = {
33
+ SIGINT: 2,
34
+ SIGQUIT: 3,
35
+ SIGKILL: 9,
36
+ SIGTERM: 15,
37
+ SIGHUP: 1,
38
+ };
39
+ /**
40
+ * Environment variable that permits a Codex launch while gate G-7 is unpassed.
41
+ * Platform-supervised, trusted-input development only — no guard hook is enforced
42
+ * on Codex in this state (PRD R-5 correction).
43
+ */
44
+ export const CODEX_PHASE1_DEV_ENV = 'MX_AGENT_CODEX_PHASE1_DEV';
45
+ // ── FR-14b / FR-14a / FR-15: agent eligibility ────────────────────────────────
46
+ /** Hard-coded ineligible. Cannot be added to any allowlist by configuration (FR-14b). */
47
+ export const CODEX_HARD_INELIGIBLE_AGENTS = ['security-reviewer'];
48
+ /**
49
+ * Review-gate agents whose Codex path is a separately-invoked wrapper, never an
50
+ * in-session persona injection (FR-14a). Refused here by design, not by omission.
51
+ */
52
+ export const CODEX_WRAPPER_ONLY_AGENTS = ['bar-raiser', 'red-team'];
53
+ /**
54
+ * Every agent whose safety-critical property is enforced by a HOOK rather than by
55
+ * tool typing, with the hook that enforces it. Transcribed from the PRD's
56
+ * per-agent safety mechanism table. For each of these, persona injection makes the
57
+ * agent functional, not safe — eligibility exists only once the named mechanism is
58
+ * ported AND verified firing (FR-15).
59
+ */
60
+ export const CODEX_HOOK_GATED_AGENTS = {
61
+ 'git-expert': 'git-mutation-guard',
62
+ 'memory-creator': 'named-memory-write-guard',
63
+ 'dogfood-auditor': 'named-memory-write-guard',
64
+ 'prd-writer': 'worktree-guard',
65
+ };
66
+ /**
67
+ * Decide whether an agent may run under Codex.
68
+ *
69
+ * `provenGuards` is the set of guard mechanisms proven FIRING SELECTIVELY in a live
70
+ * Codex session — the G-7 artifact. It defaults to empty, so with G-7 unpassed the
71
+ * allowlist is empty for every Bash-holding agent, which is exactly what FR-15's
72
+ * test requires. Passing a guard name here is an assertion that the paired
73
+ * negative+positive proof exists for it; config inspection is not proof (FR-9).
74
+ */
75
+ export function checkCodexAgentEligibility(agent, opts = {}) {
76
+ const provenGuards = opts.provenGuards ?? [];
77
+ if (CODEX_HARD_INELIGIBLE_AGENTS.includes(agent)) {
78
+ return {
79
+ eligible: false,
80
+ reason: `${agent} is not available under codex: it requires Bash, and no proven Codex ` +
81
+ `configuration provides Bash, host-scoped read and write-deny at the same time. ` +
82
+ `Run security review in a Claude session.`,
83
+ };
84
+ }
85
+ if (CODEX_WRAPPER_ONLY_AGENTS.includes(agent)) {
86
+ return {
87
+ eligible: false,
88
+ reason: `${agent} is not persona-injected under codex: its Codex path is a separately-invoked ` +
89
+ `read-only wrapper process (FR-14a fast-follow), not an in-session subagent. ` +
90
+ `Run it in a Claude session.`,
91
+ };
92
+ }
93
+ const requiredGuard = CODEX_HOOK_GATED_AGENTS[agent];
94
+ if (requiredGuard) {
95
+ if (!provenGuards.includes(requiredGuard)) {
96
+ return {
97
+ eligible: false,
98
+ reason: `${agent} unavailable under codex: ${requiredGuard} not verified firing`,
99
+ };
100
+ }
101
+ return { eligible: true };
102
+ }
103
+ // Unknown agent → refuse. An agent whose enforcing mechanism nobody has
104
+ // classified cannot be asserted safe, and fail-open here would make the
105
+ // allowlist decorative.
106
+ return {
107
+ eligible: false,
108
+ reason: `${agent} unavailable under codex: no entry in the per-agent safety mechanism table, ` +
109
+ `so its enforcing mechanism is unknown`,
110
+ };
111
+ }
112
+ export class CodexAdapter {
113
+ id = 'codex';
114
+ model;
115
+ projectRoot;
116
+ projectSlug;
117
+ provenGuards;
118
+ constructor(opts) {
119
+ this.model = opts.model ?? CODEX_DEFAULT_MODEL;
120
+ this.projectRoot = opts.projectRoot;
121
+ if (opts.projectSlug)
122
+ this.projectSlug = opts.projectSlug;
123
+ this.provenGuards = opts.provenGuards ?? [];
124
+ }
125
+ /** True once every Phase 1 containment guard has a paired live proof (gate G-7). */
126
+ get guardsProven() {
127
+ return (this.provenGuards.includes('git-mutation-guard') &&
128
+ this.provenGuards.includes('named-memory-write-guard'));
129
+ }
130
+ /**
131
+ * FR-8: refuse when the `codex` binary is missing, with an install hint and a
132
+ * non-zero exit — never a silent Claude fallback, which would hide which runtime
133
+ * actually ran. Also warns (never blocks) on a version the adapter's probes were
134
+ * not run against.
135
+ */
136
+ preflight() {
137
+ const probe = spawnSync('codex', ['--version'], { stdio: 'pipe', encoding: 'utf-8' });
138
+ if (probe.error || probe.status !== 0) {
139
+ throw new Error('codex CLI not found — install via devcontainer or run: npm i -g @openai/codex');
140
+ }
141
+ const version = (probe.stdout || '').trim();
142
+ // EXACT token comparison, mirroring .devcontainer/post-start.sh
143
+ // (`codex --version | tr -d '\r' | awk '{print $NF}'` then `!=`). A substring
144
+ // test accepted every version that merely CONTAINS the pin — `0.145.0-rc1`,
145
+ // `0.145.01`, `10.145.0` — which is the one class of version most likely to
146
+ // differ in the sandbox behaviour the pin exists to fix (security review NEW-7).
147
+ const versionToken = version.replace(/\r/g, '').trim().split(/\s+/).pop() ?? '';
148
+ if (version && versionToken !== VERIFIED_CODEX_VERSION) {
149
+ // REFUSE, do not warn (security review MF3c). Every containment property this
150
+ // adapter relies on — the hooks.json schema, the hook payload shape, the hook
151
+ // trust requirement, the sandbox write boundary, the stdin behaviour — was
152
+ // established by probing ONE version. The 0.142.4 → 0.145.0 sandbox
153
+ // reimplementation is the precedent: it silently removed the containment
154
+ // codex-review.sh depended on, and a warning printed above a scrolling session
155
+ // banner is not a control. Once the guards have a paired live proof on a pinned
156
+ // version (gate G-7) this softens to a warning, because then there is at least
157
+ // a verified baseline to compare against.
158
+ const message = `refusing to launch --runtime codex: codex reports "${version}", but this adapter's ` +
159
+ `hook schema, hook-trust, sandbox and stdin behaviour were probed on ` +
160
+ `${VERIFIED_CODEX_VERSION}. Every guardrail rests on that one version's behaviour. ` +
161
+ `Install the pinned version (npm i -g @openai/codex@${VERIFIED_CODEX_VERSION}) or re-run ` +
162
+ `the probes and update VERIFIED_CODEX_VERSION.`;
163
+ if (!this.guardsProven)
164
+ throw new Error(message);
165
+ console.log(chalk.yellow(` ⚠ ${message}`));
166
+ }
167
+ }
168
+ deployConfig(ctx) {
169
+ const result = deployCodexConfig({
170
+ projectRoot: this.projectRoot,
171
+ worktreePath: ctx.worktreePath,
172
+ worktreeName: ctx.worktreeName,
173
+ branch: ctx.branch,
174
+ slot: ctx.slot,
175
+ teamSlug: ctx.teamName,
176
+ model: this.model,
177
+ provenGuards: this.provenGuards,
178
+ // #4707: the roleguide must be read from the same ref the Claude path uses.
179
+ baseBranch: ctx.baseBranch,
180
+ ...(this.projectSlug ? { projectSlug: this.projectSlug } : {}),
181
+ ...(ctx.gitRemote ? { gitRemote: ctx.gitRemote } : {}),
182
+ });
183
+ for (const file of result.written) {
184
+ console.log(chalk.dim(` Deployed ${file} (codex)`));
185
+ }
186
+ for (const warning of result.warnings) {
187
+ console.log(chalk.yellow(` ⚠ ${warning}`));
188
+ }
189
+ for (const precondition of result.trust) {
190
+ if (!precondition.satisfied) {
191
+ console.log(chalk.yellow(` ⚠ codex hook precondition unmet (${precondition.id}): ${precondition.detail}`));
192
+ }
193
+ }
194
+ // REFUSE over budget, do not warn (security review NEW-4, same reasoning as the
195
+ // version-mismatch refusal above). Codex truncates the instruction file silently
196
+ // at project_doc_max_bytes, so an over-budget session runs on instructions whose
197
+ // tail nobody can see — and the operator's only signal would be one warning line
198
+ // above a scrolling banner.
199
+ if (result.chain.overBudget) {
200
+ throw new Error(`refusing to launch --runtime codex: ${result.chain.readFile} is ${result.chain.bytes} bytes, ` +
201
+ `over the ${result.chain.cap}-byte project_doc_max_bytes. Codex truncates it SILENTLY, so the ` +
202
+ `session would run on instructions with an unknown tail missing. Shrink the instruction file ` +
203
+ `(AGENTS.md and the worktree-local override are folded into one file under codex), or run ` +
204
+ `this team on Claude with \`mx-agent start <team> --runtime claude\`.`);
205
+ }
206
+ }
207
+ /**
208
+ * FR-6: spawn `codex exec -m <model> -C <worktree> <prompt>`.
209
+ *
210
+ * stdin is `'ignore'`, NOT `'inherit'`. `codex exec` waits for stdin EOF when it
211
+ * is not attached to a TTY — a 7m16s hang was reproduced on v0.144.5, and on
212
+ * 0.145.0 the process still prints "Reading additional input from stdin..." even
213
+ * when a prompt argument is present. Inheriting a non-TTY stdin reintroduces the
214
+ * hang, so this must never become `'inherit'`.
215
+ */
216
+ /**
217
+ * The Phase 1 gate, callable before any side effect (security review S7).
218
+ *
219
+ * `runStart` calls this after preflight and BEFORE it persists `.mx-runtime`, so a
220
+ * refused launch leaves no persisted runtime behind — otherwise the next flagless
221
+ * start would resolve `codex` from a file written by a start that never ran, and
222
+ * the operator would have to know to delete it. `launch` calls it again: the
223
+ * refusal must hold even if a future caller forgets this one.
224
+ */
225
+ assertLaunchAllowed(ctx) {
226
+ // PROJECT TRUST FIRST, above the guardsProven early return (security review NEW-2).
227
+ // This refusal must hold post-G-7 too: proving the guards fire says nothing about
228
+ // whether Codex reads the file that registers them. On an untrusted project every
229
+ // project-local artifact this adapter writes is discarded, so the gate cannot sit
230
+ // behind a G-7 shortcut.
231
+ const projectTrust = codexHookTrustPreconditions({ worktreePath: ctx.worktreePath })
232
+ .find((p) => p.id === 'project-trust');
233
+ if (projectTrust && !projectTrust.satisfied) {
234
+ throw new Error('refusing to launch --runtime codex: this project directory is not trusted in the Codex ' +
235
+ 'config, so Codex IGNORES .codex/config.toml entirely. The declared sandbox_mode, the ' +
236
+ 'declared approval_policy and the MemNexus MCP server are NOT in effect, and ' +
237
+ '.codex/hooks.json is inert — the session would run with the operator\'s inherited ' +
238
+ 'settings and no containment guard. ' +
239
+ // The worktree path reaches this message from the filesystem, so it gets the
240
+ // same treatment claude.ts gives the same value (security review NEW-14):
241
+ // control characters in a path must not steer the terminal that prints them.
242
+ // The remedy is pasteable on purpose: the operator granting trust is a human
243
+ // doing it once per worktree (PO ruling on gate G-7, 2026-07-31), so the
244
+ // message must carry the exact block and the exact file, not a description of
245
+ // them. The ruling also rejected both shortcuts an operator would look for
246
+ // next — mx-agent writing the trust record itself, and a per-launch bypass
247
+ // flag — so the message says they do not exist rather than leaving a search.
248
+ 'Fix — a human adds these two lines to ~/.codex/config.toml, once per worktree:\n\n' +
249
+ `[projects."${sanitizeForMessage(ctx.worktreePath)}"]\n` +
250
+ 'trust_level = "trusted"\n\n' +
251
+ 'That is deliberate policy (PO ruling on gate G-7, 2026-07-31): a human grants ' +
252
+ 'trust, mx-agent will not write the trust record for you, and there is no ' +
253
+ 'bypass flag. ' +
254
+ 'Fallback: run this team on Claude with `mx-agent start <team> --runtime claude`.');
255
+ }
256
+ if (this.guardsProven)
257
+ return;
258
+ // Exact string match (security review S1). `!process.env[X]` treated
259
+ // MX_AGENT_CODEX_PHASE1_DEV=0 and =false as "enabled", so an operator who
260
+ // deliberately turned the hatch OFF the obvious way turned it ON.
261
+ if (process.env[CODEX_PHASE1_DEV_ENV] === '1')
262
+ return;
263
+ throw new Error('refusing to launch --runtime codex: Phase 1 gate G-7 is unpassed. ' +
264
+ 'git-mutation-guard and named-memory-write-guard are not yet proven firing selectively ' +
265
+ 'in a live Codex session, so NO guard hook is enforced on Codex. ' +
266
+ `Platform-supervised development runs only: set ${CODEX_PHASE1_DEV_ENV}=1. ` +
267
+ 'To revert this worktree to Claude: `mx-agent start <team> --runtime claude`, ' +
268
+ 'or delete .mx-runtime.');
269
+ }
270
+ async launch(ctx) {
271
+ this.assertLaunchAllowed(ctx);
272
+ const env = {
273
+ ...process.env,
274
+ CLAUDE_WORKTREE_PATH: ctx.worktreePath,
275
+ CLAUDE_WORKTREE_NAME: ctx.worktreeName,
276
+ CLAUDE_WORKTREE_SLOT: String(ctx.slot),
277
+ CLAUDE_WORKTREE_BRANCH: ctx.branch || '',
278
+ CLAUDE_TEAM_NAME: ctx.teamName,
279
+ // Codex-side pointer to the same worktree. The guard scripts read
280
+ // CLAUDE_PROJECT_DIR; set it explicitly because Codex does not.
281
+ CLAUDE_PROJECT_DIR: ctx.worktreePath,
282
+ };
283
+ // The development hatch is NOT transitive (security review S2). Inherited through
284
+ // the spread, it would reach the session, its subagents, and any nested
285
+ // `mx-agent start` they run — so one supervised launch would silently authorize
286
+ // every unsupervised launch underneath it. The operator re-sets it per launch.
287
+ delete env[CODEX_PHASE1_DEV_ENV];
288
+ console.log();
289
+ console.log(chalk.bold(' Starting Codex...'));
290
+ console.log(chalk.dim(' Press Ctrl+C to exit'));
291
+ console.log();
292
+ // Keep the parent alive while the child owns the terminal — same rationale as
293
+ // launchClaudeSession: reproduce spawnSync's signal behaviour.
294
+ const noop = () => { };
295
+ process.on('SIGINT', noop);
296
+ process.on('SIGTERM', noop);
297
+ try {
298
+ const child = spawn('codex', ['exec', '-m', this.model, '-C', ctx.worktreePath, ctx.initialPrompt], {
299
+ cwd: ctx.worktreePath,
300
+ env,
301
+ // stdin ignored on purpose — see the method header (FR-6 stdin hang).
302
+ stdio: ['ignore', 'inherit', 'inherit'],
303
+ });
304
+ if (typeof child.pid === 'number') {
305
+ try {
306
+ updateChildPid(ctx.worktreePath, child.pid);
307
+ }
308
+ catch {
309
+ // Non-fatal — the wrapper pid alone still gates duplicate starts.
310
+ }
311
+ }
312
+ const { code, signal, error } = await new Promise((resolve) => {
313
+ child.once('error', (err) => resolve({ code: null, signal: null, error: err }));
314
+ child.once('exit', (exitCode, exitSignal) => resolve({ code: exitCode, signal: exitSignal }));
315
+ });
316
+ if (error) {
317
+ console.error(chalk.red(`Failed to launch codex: ${error.message}`));
318
+ removeLock(ctx.worktreePath); // process.exit skips finally — clean up explicitly.
319
+ process.exit(1);
320
+ }
321
+ if (signal) {
322
+ const signum = SIGNAL_NUMBERS[signal] ?? 0;
323
+ removeLock(ctx.worktreePath);
324
+ process.exit(signum ? 128 + signum : 1);
325
+ }
326
+ const exitCode = code ?? 0;
327
+ if (exitCode !== 0) {
328
+ removeLock(ctx.worktreePath);
329
+ process.exit(exitCode);
330
+ }
331
+ }
332
+ finally {
333
+ process.removeListener('SIGINT', noop);
334
+ process.removeListener('SIGTERM', noop);
335
+ removeLock(ctx.worktreePath);
336
+ }
337
+ }
338
+ /**
339
+ * Lines the start banner must print for a Codex launch. Each states a declared
340
+ * degradation rather than leaving it implicit (FR-14b, FR-16, PRD Phase 1).
341
+ */
342
+ bannerNotices(ctx) {
343
+ const notices = [
344
+ 'Security review runs on Claude — security-reviewer is refused under codex (FR-14b).',
345
+ 'Bar-raiser and red-team run on Claude — not persona-injected in-session (FR-14a).',
346
+ 'Behavioral markers are session-start-only under codex, not per-turn (FR-16).',
347
+ ];
348
+ // The declared boundary is only a boundary if Codex reads the file declaring it
349
+ // (security review NEW-2). On an untrusted project it reads none of it.
350
+ if (ctx) {
351
+ const projectTrust = codexHookTrustPreconditions({ worktreePath: ctx.worktreePath })
352
+ .find((p) => p.id === 'project-trust');
353
+ if (projectTrust && !projectTrust.satisfied) {
354
+ notices.push(`This project (${sanitizeForMessage(ctx.worktreePath)}) is NOT trusted in the Codex ` +
355
+ 'config, so .codex/config.toml is ignored ' +
356
+ 'entirely: the declared sandbox_mode and approval_policy are NOT in effect, the MemNexus ' +
357
+ 'MCP server is not configured, and .codex/hooks.json is inert.');
358
+ }
359
+ }
360
+ if (!this.guardsProven) {
361
+ notices.push('NO guard hook is proven enforced under codex: git-mutation-guard and ' +
362
+ 'named-memory-write-guard await gate G-7. Trusted-input, platform-supervised work only.');
363
+ }
364
+ return notices;
365
+ }
366
+ }
367
+ //# sourceMappingURL=codex-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-adapter.js","sourceRoot":"","sources":["../../../src/lib/runtime/codex-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,iB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wF,CACzF,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,254 @@
1
+ import { type ClaudeLocalOptions, type ClaudeLocalDiagnostic } from '../claude.js';
2
+ /**
3
+ * Model the CodexAdapter selects (PRD Open Question 2, Option A — one known-good
4
+ * model for Phase 1; a per-worktree/profile setting is Phase 3 work).
5
+ */
6
+ export declare const CODEX_DEFAULT_MODEL = "gpt-5.5";
7
+ /**
8
+ * Codex CLI version whose behaviour was actually probed for this adapter: hooks
9
+ * file schema, hook payload shape, hook trust requirement, stdin behaviour.
10
+ *
11
+ * This is NOT "the version we happened to have installed". Same discipline as
12
+ * `REVIEWED_CODEX_VERSION` in dev-tools/scripts/codex-review.sh: bumping it
13
+ * without re-running the probes is precisely how the 0.142.4 → 0.145.0 sandbox
14
+ * reimplementation silently removed containment the wrapper relied on.
15
+ */
16
+ export declare const VERIFIED_CODEX_VERSION = "0.145.0";
17
+ /** Codex's default `project_doc_max_bytes`. FR-5's budget. */
18
+ export declare const PROJECT_DOC_MAX_BYTES: number;
19
+ /** Codex's local instruction-override file — the `CLAUDE.local.md` equivalent. */
20
+ export declare const AGENTS_OVERRIDE_FILENAME = "AGENTS.override.md";
21
+ export declare const CODEX_DIR = ".codex";
22
+ export declare const CODEX_CONFIG_FILENAME: string;
23
+ export declare const CODEX_HOOKS_FILENAME: string;
24
+ /**
25
+ * The two containment guards Phase 1 must port AND prove (task 1.10, gate G-7).
26
+ *
27
+ * Scope is deliberately these two and no more. They are the guards whose absence
28
+ * removes an agent's ONLY containment (git-expert → git-mutation-guard;
29
+ * memory-creator/dogfood-auditor → named-memory-write-guard), which is why rev 3
30
+ * moved them out of Phase 2. The remaining category-(a) hooks (worktree-guard,
31
+ * mx-guard-hook, ci-validate-hook, workflow-dispatch-guard,
32
+ * deploy-verification-reminder) are Phase 2 task 2.1 and extend this generator.
33
+ */
34
+ export declare const PHASE1_PORTED_GUARDS: readonly ["git-mutation-guard.sh", "named-memory-write-guard.sh"];
35
+ export interface McpServerSpec {
36
+ name: string;
37
+ command: string;
38
+ args: string[];
39
+ }
40
+ /**
41
+ * Read the MemNexus MCP server definition from the project's `.mcp.json` so the
42
+ * two runtimes are configured from ONE source (design principle 2). Falls back to
43
+ * the known-good invocation when `.mcp.json` is absent or unparseable — a Codex
44
+ * session with no memory server is worse than one configured from the default.
45
+ */
46
+ export declare function resolveMemnexusMcpServer(projectRoot: string): McpServerSpec;
47
+ /**
48
+ * TOML basic-string literal (security review S5).
49
+ *
50
+ * A basic string may not contain a raw newline, carriage return, tab or any other
51
+ * control character — TOML rejects the document, and Codex's config load then fails
52
+ * in a way that takes the MCP server and every setting below it with it. Escaping the
53
+ * quote and backslash alone was not enough: a newline smuggled in through
54
+ * `.mcp.json`'s `command` or `args` would emit a broken file. All C0 controls plus
55
+ * DEL are escaped using TOML's own escape sequences.
56
+ */
57
+ export declare function tomlString(value: string): string;
58
+ /**
59
+ * Sandbox mode the adapter declares (security review MF3a).
60
+ *
61
+ * `workspace-write` confines model-driven writes to the worktree — the boundary
62
+ * R-5's clearance re-established and the one R-2's mitigation leans on while the
63
+ * file-write hook gap (#16732) is open. Declaring it explicitly matters because the
64
+ * previous generator declared NO sandbox mode at all: the session inherited whatever
65
+ * the operator's `~/.codex/config.toml` happened to say, which on this machine is a
66
+ * `trust_level = "trusted"` project entry. "No danger flag is passed" is not the same
67
+ * property as "a boundary is declared", and only the second one is checkable.
68
+ */
69
+ export declare const CODEX_SANDBOX_MODE = "workspace-write";
70
+ /**
71
+ * Approval policy the adapter declares (security review MF3a).
72
+ *
73
+ * `never` means Codex does not stop to ask a human. That is not a relaxation here —
74
+ * it is the only coherent setting for `codex exec`, which is non-interactive: an
75
+ * approval prompt in a session with no human at the terminal is an indefinite hang,
76
+ * not a control. The boundary is therefore the sandbox above plus the ported guard
77
+ * hooks, and the launch banner says so. `untrusted` or `on-request` would convert
78
+ * every escalation into the 7m16s-style stall FR-6 exists to prevent.
79
+ */
80
+ export declare const CODEX_APPROVAL_POLICY = "never";
81
+ /**
82
+ * Generate `.codex/config.toml` (FR-7, MF3a).
83
+ *
84
+ * `project_doc_fallback_filenames = ["CLAUDE.md"]` is the transitional bridge for
85
+ * a worktree that has not yet regenerated its AGENTS.md — belt-and-braces during
86
+ * the Phase 0 migration, per the PRD's instruction-file model.
87
+ *
88
+ * DELIBERATELY NOT SET: `sandbox_workspace_write.network_access`. Denying network
89
+ * would cut the `mx` CLI off from core-api, so a Codex session could not write the
90
+ * memories the dogfooding standard requires, and MemNexus reaches the model over MCP
91
+ * in a separate process regardless. Narrowing egress is a Phase 2 question that needs
92
+ * its own design, not a flag flipped in passing.
93
+ */
94
+ export declare function buildCodexConfigToml(opts: {
95
+ projectRoot: string;
96
+ model?: string;
97
+ }): string;
98
+ export interface CodexHookEntry {
99
+ /** Hook script filename under `.claude/hooks/`. */
100
+ script: string;
101
+ /** Codex event name (PascalCase, as the hooks.json schema requires). */
102
+ event: 'PreToolUse' | 'PostToolUse';
103
+ /** Tool matcher. `Bash` is the shell tool — the one tool Codex hooks fire for. */
104
+ matcher: 'Bash';
105
+ }
106
+ /** The Phase 1 hook set: the two containment guards, PreToolUse, Bash-matched. */
107
+ export declare function phase1HookEntries(): CodexHookEntry[];
108
+ /** Command the SubagentStart gate hook runs. See src/commands/codex-agent-gate.ts. */
109
+ export declare const CODEX_AGENT_GATE_COMMAND = "mx-agent internal-codex-agent-gate";
110
+ /**
111
+ * Wrapper command for one ported guard.
112
+ *
113
+ * NO PATH INTERPOLATION (security review S4). The previous version embedded the
114
+ * worktree path inside a single-quoted shell string twice, so a worktree directory
115
+ * containing an apostrophe — `/workspaces/harry's-repo` — closed the quote and the
116
+ * remainder of the path was executed as shell words. Worktree names are derived from
117
+ * team slugs today, but the path comes from the filesystem, not from a validated
118
+ * allowlist, and "no team will ever have an apostrophe in its checkout path" is not a
119
+ * property this code can assert.
120
+ *
121
+ * The command now reads `CLAUDE_PROJECT_DIR` from the environment, which
122
+ * `CodexAdapter.launch` sets to the worktree path. The only interpolated value is the
123
+ * script filename, constrained by SAFE_SCRIPT_NAME.
124
+ *
125
+ * Fail-OPEN when the script is absent (`|| exit 0`) mirrors the wrapper
126
+ * `.claude/settings.json` uses for the same script: the Codex port reproduces the
127
+ * Claude semantics rather than inventing a different failure model on a security
128
+ * path. `deployCodexConfig` warns by name for each guard script that is missing, so
129
+ * the silent case is at least announced (security review S9).
130
+ */
131
+ export declare function codexHookCommand(script: string): string;
132
+ /**
133
+ * Generate `.codex/hooks.json` (FR-9, task 1.10).
134
+ *
135
+ * Shape verified on codex-cli 0.145.0 — see finding 1 in the file header.
136
+ */
137
+ export declare function buildCodexHooksJson(opts: {
138
+ worktreePath?: string;
139
+ entries?: CodexHookEntry[];
140
+ /** Guards with a paired live proof (gate G-7). Empty → the gate refuses everything. */
141
+ provenGuards?: readonly string[];
142
+ }): string;
143
+ export interface HookTrustPrecondition {
144
+ id: 'hook-trust' | 'project-trust';
145
+ satisfied: boolean;
146
+ detail: string;
147
+ }
148
+ export declare function codexHookTrustPreconditions(opts: {
149
+ worktreePath: string;
150
+ codexHome?: string;
151
+ }): HookTrustPrecondition[];
152
+ /**
153
+ * Generate `AGENTS.override.md` content (FR-7, FR-16).
154
+ *
155
+ * Carries the CLAUDE.local.md generator output — one source, so a behavioral-marker
156
+ * change cannot land on Claude and miss Codex — plus a notice naming the declared
157
+ * degradation: on Claude the marker block is re-injected every turn by a hook; Codex
158
+ * reads this file once, at session start.
159
+ *
160
+ * AND IT CARRIES THE CANONICAL AGENTS.md CONTENT TOO, because on Codex this file
161
+ * REPLACES AGENTS.md rather than adding to it (probed on codex-cli 0.145.0 — see
162
+ * finding 5 in the file header). The PRD called `AGENTS.override.md` the
163
+ * `CLAUDE.local.md` equivalent, but those two files are ADDITIVE on Claude and this
164
+ * one is a REPLACEMENT, so emitting only the local-override content would have left a
165
+ * Codex session reading its isolation context and behavioral markers while never
166
+ * seeing the canonical instructions.
167
+ */
168
+ export declare const CODEX_MARKER_DEGRADATION_NOTICE: string;
169
+ export declare const CODEX_CANONICAL_FOLD_NOTICE: string;
170
+ export declare function buildAgentsOverride(opts: ClaudeLocalOptions): {
171
+ content: string;
172
+ warning?: string;
173
+ /**
174
+ * Every line the generator produced, in order (#4707): the stale-local-tree
175
+ * fallback warning, the git-provenance line, the missing-block warning. The
176
+ * Codex path surfaces the warn-level ones so a fallback is no more silent here
177
+ * than it is on the Claude path.
178
+ */
179
+ diagnostics: ClaudeLocalDiagnostic[];
180
+ hasBehavioralBlock: boolean;
181
+ /** False when no canonical AGENTS.md was found to fold in — a real degradation. */
182
+ hasCanonicalContent: boolean;
183
+ };
184
+ export interface InstructionChainMeasurement {
185
+ /** Bytes Codex will actually read — the size of the single winning file. */
186
+ bytes: number;
187
+ cap: number;
188
+ overBudget: boolean;
189
+ /** The file Codex reads, or null when the worktree has no instruction file at all. */
190
+ readFile: string | null;
191
+ /** Every candidate found, with its own size, whether or not Codex reads it (S10). */
192
+ files: Array<{
193
+ path: string;
194
+ bytes: number;
195
+ read: boolean;
196
+ }>;
197
+ }
198
+ /**
199
+ * Measure the instruction bytes a Codex session reads (FR-5, security review S10).
200
+ *
201
+ * EXACTLY ONE FILE IS READ, in this precedence order, probed on codex-cli 0.145.0
202
+ * (finding 5 in the file header): `AGENTS.override.md`, else `AGENTS.md`, else
203
+ * `CLAUDE.md` via `project_doc_fallback_filenames`. The override REPLACES the
204
+ * canonical file rather than being appended to it, so the previous version of this
205
+ * function — which SUMMED AGENTS.md and the override — reported a total for a chain
206
+ * that does not exist. It over-counted by the size of a file Codex ignores, and it
207
+ * hid the fact that the ignored file was the canonical one.
208
+ *
209
+ * `project_doc_max_bytes` truncates that single file silently (a 433-byte file was
210
+ * cut at a 200-byte cap), so per-file and total are the same number today. Both are
211
+ * reported: `bytes` is what counts against the cap, `files` carries every candidate's
212
+ * own size so a warning can name which file is the problem.
213
+ */
214
+ export declare function measureInstructionChain(worktreePath: string,
215
+ /**
216
+ * Cap to measure against. Defaults to — and callers pass — PROJECT_DOC_MAX_BYTES,
217
+ * the same constant `buildCodexConfigToml` writes into `project_doc_max_bytes`, so
218
+ * the declared cap and the measured cap cannot drift apart (security review NEW-1).
219
+ */
220
+ cap?: number): InstructionChainMeasurement;
221
+ export interface DeployCodexConfigResult {
222
+ written: string[];
223
+ /** Advisory messages the caller surfaces at launch (never blocking). */
224
+ warnings: string[];
225
+ chain: InstructionChainMeasurement;
226
+ trust: HookTrustPrecondition[];
227
+ }
228
+ /**
229
+ * Deploy every Codex config artifact into the worktree. Idempotent — each file is
230
+ * regenerated in full, so a stale artifact cannot survive a restart.
231
+ */
232
+ export declare function deployCodexConfig(opts: {
233
+ projectRoot: string;
234
+ worktreePath: string;
235
+ worktreeName: string;
236
+ branch: string | null;
237
+ slot: number;
238
+ projectSlug?: string;
239
+ teamSlug?: string;
240
+ model?: string;
241
+ /**
242
+ * Base branch whose remote-tracking ref carries the canonical roleguides
243
+ * (#4707). Forwarded to the CLAUDE.local.md generator so a Codex session reads
244
+ * the roleguide from the same ref a Claude session does. Defaults to `main`.
245
+ */
246
+ baseBranch?: string;
247
+ /** Remote holding the canonical tree. Defaults to `origin`. */
248
+ gitRemote?: string;
249
+ /** Guards with a paired live proof (gate G-7); passed to the SubagentStart gate. */
250
+ provenGuards?: readonly string[];
251
+ }): DeployCodexConfigResult;
252
+ /** Does the worktree carry a generated Codex config tree? Used by tests and doctor-style checks. */
253
+ export declare function hasCodexConfig(worktreePath: string): boolean;
254
+ //# sourceMappingURL=codex-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-config.d.ts","sourceRoot":"","sources":["../../../src/lib/runtime/codex-config.ts"],"names":[],"mappings":"AAuEA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAE7C;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,YA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