@memnexus-ai/mx-agent-cli 0.1.269 → 0.1.271

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 (45) hide show
  1. package/dist/__tests__/codex-deploy-config.test.d.ts +2 -0
  2. package/dist/__tests__/codex-deploy-config.test.d.ts.map +1 -0
  3. package/dist/__tests__/codex-deploy-config.test.js +1170 -0
  4. package/dist/__tests__/codex-deploy-config.test.js.map +1 -0
  5. package/dist/__tests__/codex-trust-keys.test.d.ts +2 -0
  6. package/dist/__tests__/codex-trust-keys.test.d.ts.map +1 -0
  7. package/dist/__tests__/codex-trust-keys.test.js +731 -0
  8. package/dist/__tests__/codex-trust-keys.test.js.map +1 -0
  9. package/dist/__tests__/codex-write-race.test.d.ts +2 -0
  10. package/dist/__tests__/codex-write-race.test.d.ts.map +1 -0
  11. package/dist/__tests__/codex-write-race.test.js +1832 -0
  12. package/dist/__tests__/codex-write-race.test.js.map +1 -0
  13. package/dist/__tests__/runtime-codex-guard-proof.test.js +75 -0
  14. package/dist/__tests__/runtime-codex-guard-proof.test.js.map +1 -1
  15. package/dist/commands/codex-deploy-config.d.ts +111 -0
  16. package/dist/commands/codex-deploy-config.d.ts.map +1 -0
  17. package/dist/commands/codex-deploy-config.js +400 -0
  18. package/dist/commands/codex-deploy-config.js.map +1 -0
  19. package/dist/commands/codex-prove-guards.d.ts +20 -0
  20. package/dist/commands/codex-prove-guards.d.ts.map +1 -1
  21. package/dist/commands/codex-prove-guards.js +54 -1
  22. package/dist/commands/codex-prove-guards.js.map +1 -1
  23. package/dist/commands/codex-trust-keys.d.ts +12 -0
  24. package/dist/commands/codex-trust-keys.d.ts.map +1 -0
  25. package/dist/commands/codex-trust-keys.js +169 -0
  26. package/dist/commands/codex-trust-keys.js.map +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +65 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
  31. package/dist/lib/runtime/codex-adapter.js +15 -15
  32. package/dist/lib/runtime/codex-adapter.js.map +1 -1
  33. package/dist/lib/runtime/codex-config.d.ts +211 -0
  34. package/dist/lib/runtime/codex-config.d.ts.map +1 -1
  35. package/dist/lib/runtime/codex-config.js +1098 -40
  36. package/dist/lib/runtime/codex-config.js.map +1 -1
  37. package/dist/lib/runtime/codex-hooks-list.d.ts +91 -0
  38. package/dist/lib/runtime/codex-hooks-list.d.ts.map +1 -0
  39. package/dist/lib/runtime/codex-hooks-list.js +418 -0
  40. package/dist/lib/runtime/codex-hooks-list.js.map +1 -0
  41. package/dist/lib/runtime/codex-trust-keys.d.ts +95 -0
  42. package/dist/lib/runtime/codex-trust-keys.d.ts.map +1 -0
  43. package/dist/lib/runtime/codex-trust-keys.js +279 -0
  44. package/dist/lib/runtime/codex-trust-keys.js.map +1 -0
  45. package/package.json +1 -1
@@ -0,0 +1,418 @@
1
+ /**
2
+ * `hooks/list` — the only source of Codex's own per-entry hook hashes (#4876).
3
+ *
4
+ * ─── WHY THIS EXISTS ──────────────────────────────────────────────────────────
5
+ * `trusted_hash` in `~/.codex/config.toml` is Codex's hash over ONE hook definition,
6
+ * computed inside the binary. We cannot derive it: a sha256 of the command string, of
7
+ * the group, or of either serialization does not reproduce it. That is what made
8
+ * KI-CODEX-TRUST-HASH-NOT-VERIFIED unfixable — `codexHookTrustPreconditions` could see
9
+ * that a record existed, was enabled and carried a non-empty hash, but not that the
10
+ * hash still MATCHED. A stale hash means Codex silently does not run that hook, while
11
+ * every check we own reports green.
12
+ *
13
+ * The app-server JSON-RPC method `hooks/list` reports `currentHash` per entry. There is
14
+ * no `codex hooks list` subcommand. Verified live on codex-cli 0.145.0 (2026-08-02):
15
+ * the response carries `result.data[].hooks[]` with `key`, `currentHash`, `trustStatus`,
16
+ * `enabled` and `sourcePath`, and the live `trusted_hash` values in the config are
17
+ * BYTE-EQUAL to `currentHash` — prefix included. So verification is a string equality,
18
+ * not a derivation.
19
+ *
20
+ * ─── THE PREFIX ───────────────────────────────────────────────────────────────
21
+ * `currentHash` ALREADY begins with `sha256:` and is 71 characters (`sha256:` + 64 hex).
22
+ * Anything this module emits for a human to paste is passed through VERBATIM. Writing
23
+ * `sha256:sha256:<hex>` is the easiest mistake in the whole grant procedure and it fails
24
+ * silently in the worst direction: Codex never matches the entry, so the hook does not
25
+ * run, while a presence-only precondition reports trust satisfied. Guards inert, tooling
26
+ * green.
27
+ *
28
+ * ─── FAIL CLOSED ──────────────────────────────────────────────────────────────
29
+ * Every parse failure, missing field and empty result is an ERROR here, never an empty
30
+ * success. An empty `data` array is what `hooks/list` returns for an UNTRUSTED project —
31
+ * reading that as "no hooks, nothing to verify" would turn the most important negative
32
+ * result into a green one.
33
+ *
34
+ * ─── THIS IS AN UNTRUSTED-INPUT BOUNDARY (security review #4876) ───────────────
35
+ * Everything below the `spawnSync` is a parser for bytes produced by another process.
36
+ * Nothing in the response is a fact about our own configuration until it is checked, so
37
+ * the parser holds four rules that the first version did not:
38
+ *
39
+ * 1. NOTHING THROWS OUT. A malformed payload (`data:[null]`, `data:[42]`) reached
40
+ * callers as an uncaught TypeError, which surfaces as a stack trace rather than as
41
+ * `prove-guards`' refusal text. Every shape error returns `{ok:false,error}`.
42
+ * 2. NO SILENT LAST-WINS. A duplicate key whose hash DIFFERS, or a second response to
43
+ * the same request id, would let a later entry shadow the real hash — turning a
44
+ * `stale-hash` verdict into `granted`, which is precisely the failure this module
45
+ * exists to detect. Both are refusals.
46
+ * 3. `sourcePath` IS CHECKED AGAINST THE KEY IT ARRIVES WITH. It is this module's
47
+ * evidence for OpenAI bug #27133 (which file Codex really resolved), so an entry
48
+ * claiming a `sourcePath` that is not the key's own file is not a direct observation
49
+ * of anything and is refused rather than recorded as one.
50
+ * 4. A NON-ZERO EXIT IS NOT A RESULT. Parseable stdout from a failed invocation was
51
+ * accepted, and a missing `codex` binary was reported as "produced no response".
52
+ * The exit status is inspected first and stderr is carried into the message.
53
+ */
54
+ import { spawnSync } from 'child_process';
55
+ /** Seconds stdin is held open after the request, matching the invocation verified live. */
56
+ export const HOOKS_LIST_SETTLE_SECONDS = 8;
57
+ /** Wall-clock ceiling for the whole invocation. Generous: the settle wait alone is 8s. */
58
+ export const HOOKS_LIST_TIMEOUT_MS = 40_000;
59
+ /**
60
+ * The only key shape this module will hand on: `<path>:<snake_case event>:<n>:<n>`, with
61
+ * no quote, backslash or control character anywhere in it.
62
+ *
63
+ * ─── WHY A SHAPE CHECK IS A SECURITY CONTROL HERE (security review MF-2) ──────
64
+ * A key from `hooks/list` is interpolated into a TOML table header — `[hooks.state."<key>"]`
65
+ * — in the block `mx-agent codex trust-keys` tells an operator to paste into
66
+ * `~/.codex/config.toml`. Unescaped, a key carrying `"` and a newline closes the header
67
+ * and opens another. The reviewer executed it and got
68
+ * `[projects."/workspace"] trust_level = "trusted"` into the pasteable block: a
69
+ * project-trust grant the operator never chose, written by their own hand.
70
+ *
71
+ * The renderer escapes now too — both layers, because either alone is one edit away from
72
+ * being the only one. This one is the stronger statement: a key of another shape is not
73
+ * something we mis-render, it is something Codex did not report about our configuration.
74
+ */
75
+ export const CODEX_TRUST_KEY_SHAPE = /^[^"\\\x00-\x1f]+:[a-z_]+:\d+:\d+$/;
76
+ /** Split a trust key into its file path and its event/group/hook suffix. */
77
+ export function splitTrustKey(key) {
78
+ const parts = key.split(':');
79
+ if (parts.length < 4)
80
+ return null;
81
+ const suffix = parts.slice(-3).join(':');
82
+ const hooksPath = parts.slice(0, -3).join(':');
83
+ if (!hooksPath || !suffix)
84
+ return null;
85
+ return { hooksPath, suffix };
86
+ }
87
+ /**
88
+ * Parse the newline-delimited JSON-RPC stream `codex app-server` writes.
89
+ *
90
+ * `requestId` is the id used for the `hooks/list` call. Lines that are not JSON, and
91
+ * responses to other ids, are skipped — the stream also carries the `initialize`
92
+ * response and whatever notifications the server emits.
93
+ */
94
+ export function parseHooksListResponse(stdout, requestId = 2) {
95
+ try {
96
+ return parseHooksListResponseInner(stdout, requestId);
97
+ }
98
+ catch (err) {
99
+ // NOTHING FROM ANOTHER PROCESS THROWS OUT OF HERE (SF-1). `queryCodexHooksList`,
100
+ // `buildTrustKeyReport` and both commands sit downstream with no try/catch of their
101
+ // own, so a shape this parser did not anticipate used to reach the operator as a
102
+ // stack trace instead of as the refusal text those commands exist to print.
103
+ return {
104
+ ok: false,
105
+ error: 'the hooks/list response could not be parsed: ' +
106
+ `${err instanceof Error ? err.message : String(err)}. Treating it as no answer — a ` +
107
+ 'response we cannot read is not evidence that a grant is current.',
108
+ };
109
+ }
110
+ }
111
+ function parseHooksListResponseInner(stdout, requestId) {
112
+ let response = null;
113
+ for (const line of stdout.split('\n')) {
114
+ const trimmed = line.trim();
115
+ if (!trimmed)
116
+ continue;
117
+ let parsed;
118
+ try {
119
+ parsed = JSON.parse(trimmed);
120
+ }
121
+ catch {
122
+ continue;
123
+ }
124
+ if (!parsed || typeof parsed !== 'object')
125
+ continue;
126
+ if (parsed.id === requestId) {
127
+ // TWO ANSWERS TO ONE REQUEST IS NOT AN ANSWER (SF-2). Last-wins let a second
128
+ // response overwrite the first, so whichever process wrote last decides what we
129
+ // believe Codex reported.
130
+ if (response) {
131
+ return {
132
+ ok: false,
133
+ error: `the stream carried more than one response to hooks/list request id ${requestId}. ` +
134
+ 'A JSON-RPC id answers once; taking the last one would let whichever line arrived ' +
135
+ 'last decide the hashes. Refusing to read hashes out of an ambiguous stream.',
136
+ };
137
+ }
138
+ response = parsed;
139
+ }
140
+ }
141
+ if (!response) {
142
+ return {
143
+ ok: false,
144
+ error: 'codex app-server produced no response to hooks/list. Without Codex\'s own per-entry ' +
145
+ 'hashes, a recorded trusted_hash cannot be compared to anything — refusing to report ' +
146
+ 'trust as verified.',
147
+ };
148
+ }
149
+ if ('error' in response) {
150
+ const err = response.error;
151
+ return {
152
+ ok: false,
153
+ error: `hooks/list returned a JSON-RPC error (code ${String(err?.code)}): ${String(err?.message)}`,
154
+ };
155
+ }
156
+ const data = response.result?.data;
157
+ if (!Array.isArray(data)) {
158
+ return { ok: false, error: 'hooks/list response had no result.data array — the shape changed.' };
159
+ }
160
+ if (data.length === 0) {
161
+ return {
162
+ ok: false,
163
+ error: 'hooks/list returned an empty result set. That is what Codex reports for an UNTRUSTED ' +
164
+ 'project directory, so it means "no answer", not "no hooks". Grant project trust ' +
165
+ '([projects."<path>"] trust_level = "trusted") and re-run.',
166
+ };
167
+ }
168
+ const entries = [];
169
+ const seenHashByKey = new Map();
170
+ for (const bucket of data) {
171
+ // `data:[null]` and `data:[42]` both reached `.hooks` on a non-object (SF-1).
172
+ if (!bucket || typeof bucket !== 'object')
173
+ continue;
174
+ const hooks = bucket.hooks;
175
+ if (!Array.isArray(hooks))
176
+ continue;
177
+ for (const raw of hooks) {
178
+ if (!raw || typeof raw !== 'object')
179
+ continue;
180
+ const e = raw;
181
+ const key = typeof e.key === 'string' ? e.key : null;
182
+ const currentHash = typeof e.currentHash === 'string' ? e.currentHash : null;
183
+ if (!key) {
184
+ return { ok: false, error: 'hooks/list returned an entry with no key — the shape changed.' };
185
+ }
186
+ if (!currentHash) {
187
+ // NOT skipped, and not defaulted to empty. An entry whose hash we cannot read is
188
+ // an entry whose grant we cannot verify, and the runbook's fallback for that is a
189
+ // human-driven Codex trust prompt — never a guessed value.
190
+ return {
191
+ ok: false,
192
+ error: `hooks/list reported no currentHash for ${key}. The method is experimental and its ` +
193
+ 'shape is not contractual; do not hand-write a hash you did not read out of Codex. ' +
194
+ 'Use the interactive Codex trust prompt for this entry instead.',
195
+ };
196
+ }
197
+ // ── DUPLICATE KEYS (SF-2) ────────────────────────────────────────────────
198
+ // `observedHashesByKey` builds a Map, so a later duplicate silently replaced an
199
+ // earlier one. If the two hashes differ, the second value decides whether a
200
+ // recorded grant reads as `granted` or as `stale-hash` — the exact verdict this
201
+ // module exists to produce. An identical repeat carries no such choice and is
202
+ // dropped; a conflicting one is a refusal.
203
+ const priorHash = seenHashByKey.get(key);
204
+ if (priorHash !== undefined) {
205
+ if (priorHash === currentHash)
206
+ continue;
207
+ return {
208
+ ok: false,
209
+ error: `hooks/list reported two DIFFERENT hashes for the same key ${key} ` +
210
+ `(${priorHash} then ${currentHash}). One of them would silently win and decide ` +
211
+ 'whether a recorded grant reads as current or stale. Refusing to pick.',
212
+ };
213
+ }
214
+ // ── THE KEY'S SHAPE IS CHECKED BEFORE IT IS USED FOR ANYTHING (MF-2) ─────
215
+ // See `CODEX_TRUST_KEY_SHAPE`. A key of any other shape never reaches `entries`,
216
+ // so it can never reach the renderer, the report or the pasteable block.
217
+ if (!CODEX_TRUST_KEY_SHAPE.test(key)) {
218
+ return {
219
+ ok: false,
220
+ error: `hooks/list reported a key that is not of the form <hooks.json path>:<event>:<group>:` +
221
+ `<index>, or that carries a quote, backslash or control character: ${JSON.stringify(key)}. ` +
222
+ 'These keys are written into TOML table headers in the block an operator is told to ' +
223
+ 'paste into ~/.codex/config.toml, so a key of another shape is refused rather than ' +
224
+ 'rendered — it is not a fact about this configuration and it must not become one.',
225
+ };
226
+ }
227
+ // ── sourcePath MUST DESCRIBE THIS KEY'S OWN FILE, AND MUST BE PRESENT ────
228
+ // (SF-3, tightened by security review MF-3.) The key's prefix IS the hooks file
229
+ // Codex keyed the entry on. `sourcePath` is this module's evidence for #27133 — the
230
+ // claim that Codex resolved the main repo's file. A MISMATCH was refused, but an
231
+ // ABSENT or non-string sourcePath skipped the check entirely and the entry was
232
+ // recorded as a direct observation anyway. That is the fail-open direction:
233
+ // `buildTrustKeyReport` treats any direct observation of a file as proof that the
234
+ // file was seen by Codex, which suppresses the byte-identity precondition on the
235
+ // carry-over and lets an entry with no provenance at all grade `granted`. Verified
236
+ // live on codex-cli 0.145.0: every entry carries sourcePath, so its absence is a
237
+ // shape we have never seen from Codex.
238
+ const sourcePath = typeof e.sourcePath === 'string' ? e.sourcePath : null;
239
+ if (sourcePath === null) {
240
+ return {
241
+ ok: false,
242
+ error: `hooks/list reported an entry keyed on ${key} with NO sourcePath. sourcePath is the ` +
243
+ 'only evidence of which file Codex actually resolved the entry from (OpenAI bug ' +
244
+ '#27133), so without it the entry is not a direct observation of anything. Refusing ' +
245
+ 'to record a hash whose provenance is unstated — an unverified grant is not a ' +
246
+ 'verified one.',
247
+ };
248
+ }
249
+ const split = splitTrustKey(key);
250
+ if (!split || split.hooksPath !== sourcePath) {
251
+ return {
252
+ ok: false,
253
+ error: `hooks/list reported an entry keyed on ${key} but sourced from ${sourcePath}. ` +
254
+ 'The key\'s own prefix is the file the hash is keyed to, so an entry naming a ' +
255
+ 'different source file is not a direct observation of that key and is unusable ' +
256
+ 'as one. Refusing to record a hash whose provenance does not match its key.',
257
+ };
258
+ }
259
+ seenHashByKey.set(key, currentHash);
260
+ entries.push({
261
+ key,
262
+ currentHash,
263
+ trustStatus: typeof e.trustStatus === 'string' ? e.trustStatus : null,
264
+ sourcePath,
265
+ enabled: typeof e.enabled === 'boolean' ? e.enabled : null,
266
+ });
267
+ }
268
+ }
269
+ if (entries.length === 0) {
270
+ return {
271
+ ok: false,
272
+ error: 'hooks/list returned no hook entries at all — nothing is registered for this project.',
273
+ };
274
+ }
275
+ return { ok: true, entries };
276
+ }
277
+ /** Single-quote a value for a bash command line. */
278
+ function shq(value) {
279
+ return `'${value.replace(/'/g, "'\\''")}'`;
280
+ }
281
+ /** Exit status GNU `timeout` uses when it had to kill the command. */
282
+ const TIMEOUT_EXIT_STATUS = 124;
283
+ /** The last few stderr lines, for a message an operator can act on. */
284
+ function tailStderr(stderr, lines = 5) {
285
+ const trimmed = (stderr ?? '').replace(/\s+$/, '');
286
+ if (!trimmed)
287
+ return '(no stderr)';
288
+ return trimmed.split('\n').slice(-lines).join(' | ');
289
+ }
290
+ /**
291
+ * Run the `hooks/list` invocation.
292
+ *
293
+ * This is the invocation documented in the G-7 runbook §3.3 and verified live, kept
294
+ * shape-for-shape: three request lines on stdin, then stdin held open while the server
295
+ * answers. `codex app-server` does not answer and exit on an immediate EOF, which is why
296
+ * the settle wait is here rather than a plain `spawnSync` with `input`.
297
+ */
298
+ export function queryCodexHooksList(opts) {
299
+ const { cwd } = opts;
300
+ const exec = opts.exec ??
301
+ ((dir) => {
302
+ const requests = [
303
+ '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"mx-agent","title":"mx-agent","version":"0"}}}',
304
+ '{"jsonrpc":"2.0","method":"initialized","params":{}}',
305
+ JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'hooks/list', params: { cwd: dir } }),
306
+ ];
307
+ const script = `printf '%s\\n' ${requests.map(shq).join(' ')} | ` +
308
+ `{ cat; sleep ${HOOKS_LIST_SETTLE_SECONDS}; } | codex app-server`;
309
+ const timeoutMs = opts.timeoutMs ?? HOOKS_LIST_TIMEOUT_MS;
310
+ // ── THE PIPELINE IS KILLED AS A GROUP, NOT JUST ITS SHELL (SF-4) ─────────
311
+ // `spawnSync`'s own `timeout` signals ONLY the direct child. This command is a
312
+ // three-stage pipeline, so a timeout used to leave `cat`, an 8-second `sleep` and
313
+ // a live `codex app-server` behind — once per run, on a machine several agent
314
+ // sessions share, and `codex app-server` is not a cheap process to leak. GNU
315
+ // `timeout` puts the command in its own process group and signals the GROUP, then
316
+ // SIGKILLs 5s later if it has not gone. `spawnSync`'s timeout stays as a backstop
317
+ // for the case where `timeout` itself never returns, at a longer deadline so the
318
+ // group-kill is what normally fires.
319
+ const timeoutSeconds = Math.max(1, Math.ceil(timeoutMs / 1000));
320
+ const r = spawnSync('timeout', ['-k', '5', `${timeoutSeconds}s`, 'bash', '-c', script], {
321
+ cwd: dir,
322
+ encoding: 'utf-8',
323
+ timeout: timeoutMs + 15_000,
324
+ stdio: ['ignore', 'pipe', 'pipe'],
325
+ });
326
+ if (r.error)
327
+ return { stdout: r.stdout ?? '', error: r.error.message, stderr: r.stderr ?? '' };
328
+ return { stdout: r.stdout ?? '', status: r.status, stderr: r.stderr ?? '' };
329
+ });
330
+ const result = exec(cwd);
331
+ const { stdout, error } = result;
332
+ if (error) {
333
+ return {
334
+ ok: false,
335
+ error: `could not run \`codex app-server\` to read hook hashes: ${error}`,
336
+ };
337
+ }
338
+ // ── A NON-ZERO EXIT IS NOT A RESULT (SF-5) ─────────────────────────────────
339
+ // The status was never inspected and stderr was captured and dropped, so an
340
+ // invocation that failed but happened to have written parseable stdout was read as an
341
+ // answer, and the commonest failure of all — no `codex` on PATH — surfaced as
342
+ // "produced no response to hooks/list", which sends the operator to look at project
343
+ // trust instead of at their installation.
344
+ // AND AN ABSENT STATUS IS NOT A ZERO ONE (security review SF-E). `status !== undefined`
345
+ // made a result with no status field the success path, which is the one shape a
346
+ // hand-rolled or future exec wrapper is most likely to produce: the invocation's
347
+ // outcome is unknown and its stdout was read as an answer. `null` keeps its own
348
+ // signal-kill branch below.
349
+ if (result.status !== 0) {
350
+ const stderrTail = tailStderr(result.stderr);
351
+ if (result.status === undefined) {
352
+ return {
353
+ ok: false,
354
+ error: 'the `codex app-server` invocation reported no exit status, so whether it succeeded is ' +
355
+ 'unknown. Its stdout is not treated as an answer: a run we cannot show completed ' +
356
+ `cannot establish that a grant is current. stderr: ${stderrTail}`,
357
+ };
358
+ }
359
+ if (result.status === null) {
360
+ return {
361
+ ok: false,
362
+ error: 'the `codex app-server` invocation was killed by a signal before it answered ' +
363
+ `hooks/list. stderr: ${stderrTail}`,
364
+ };
365
+ }
366
+ if (result.status === TIMEOUT_EXIT_STATUS) {
367
+ return {
368
+ ok: false,
369
+ error: `the \`codex app-server\` invocation timed out after ${Math.max(1, Math.ceil((opts.timeoutMs ?? HOOKS_LIST_TIMEOUT_MS) / 1000))}s and was killed. No hashes were read, so no grant can be called current. ` +
370
+ `stderr: ${stderrTail}`,
371
+ };
372
+ }
373
+ if (result.status === 127) {
374
+ return {
375
+ ok: false,
376
+ error: '`codex` was not found on PATH, so its own per-entry hashes cannot be read — this ' +
377
+ 'is a missing installation, not an untrusted project. Install the pinned version ' +
378
+ `(npm i -g @openai/codex) and re-run. stderr: ${stderrTail}`,
379
+ };
380
+ }
381
+ return {
382
+ ok: false,
383
+ error: `the \`codex app-server\` invocation exited ${result.status}. Its stdout is not treated ` +
384
+ `as an answer: a failed run's output cannot establish that a grant is current. ` +
385
+ `stderr: ${stderrTail}`,
386
+ };
387
+ }
388
+ return parseHooksListResponse(stdout);
389
+ }
390
+ /** Every observed entry as `key → currentHash`, verbatim. */
391
+ export function observedHashesByKey(entries) {
392
+ const map = new Map();
393
+ for (const e of entries)
394
+ map.set(e.key, e.currentHash);
395
+ return map;
396
+ }
397
+ /**
398
+ * Re-key hashes observed for `fromPath` onto `toPath`.
399
+ *
400
+ * ONLY VALID WHEN THE TWO FILES ARE BYTE-IDENTICAL, which the caller must verify by
401
+ * sha256 — this function cannot check it and does not pretend to. The need arises from
402
+ * OpenAI bug #27133: Codex resolves hooks from the MAIN repo's `.codex/hooks.json`, so
403
+ * `hooks/list` never reports the worktree's own file, while our trust precondition is
404
+ * keyed on exactly that file. Codex's hash is over the entry's CONTENT, not its path
405
+ * (verified: identical content at two directories produced identical `currentHash`), so
406
+ * identical bytes means identical per-index hashes.
407
+ */
408
+ export function carryOverHashes(observed, fromPath, toPath) {
409
+ const carried = new Map();
410
+ for (const [key, hash] of observed) {
411
+ const split = splitTrustKey(key);
412
+ if (!split || split.hooksPath !== fromPath)
413
+ continue;
414
+ carried.set(`${toPath}:${split.suffix}`, hash);
415
+ }
416
+ return carried;
417
+ }
418
+ //# sourceMappingURL=codex-hooks-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-hooks-list.js","sourceRoot":"","sources":["../../../src/lib/runtime/codex-hooks-list.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,2FAA2F;AAC3F,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,0FAA0F;AAC1F,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,C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AAe,CAC7B,QAAqC,EACrC,QAAgB,EAChB,MAAc;IAEd,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,QAAQ,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,KAAK,QAAQ;YAAE,SAAS;QACrD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,95 @@
1
+ import { type CodexHooksListResult } from './codex-hooks-list.js';
2
+ /** What a single hook entry's trust looks like right now. */
3
+ export type TrustKeyStatus = 'granted' | 'ungranted' | 'stale-hash' | 'unverifiable';
4
+ export interface TrustKeyRow {
5
+ key: string;
6
+ status: TrustKeyStatus;
7
+ /** Codex's current hash for the entry, `sha256:<64 hex>` VERBATIM, or null. */
8
+ observedHash: string | null;
9
+ /** How the hash was obtained. `carried-over` requires byte-identical files. */
10
+ observedFrom: 'hooks/list' | 'carried-over' | null;
11
+ /** `trusted_hash` as recorded in the Codex config, VERBATIM, or null when absent. */
12
+ recordedHash: string | null;
13
+ recordEnabled: boolean;
14
+ /** Codex's own verdict, when it reported one for this key. */
15
+ codexTrustStatus: string | null;
16
+ /** One sentence naming what is wrong, or confirming what was checked. */
17
+ detail: string;
18
+ }
19
+ export interface TrustKeySet {
20
+ /** `worktree` or `main-repo`. */
21
+ label: 'worktree' | 'main-repo';
22
+ /** Absolute path of the hooks file these keys are for. */
23
+ hooksPath: string;
24
+ /** sha256 of that file, or null when it is absent or unreadable. */
25
+ hooksSha256: string | null;
26
+ rows: TrustKeyRow[];
27
+ /** Set when the file could not be read — no keys can be listed for it. */
28
+ error?: string;
29
+ }
30
+ export interface TrustKeyReport {
31
+ ok: boolean;
32
+ sets: TrustKeySet[];
33
+ /** Non-fatal observations the operator has to see (file divergence, project trust). */
34
+ warnings: string[];
35
+ /** Set when the report could not be produced at all. */
36
+ error?: string;
37
+ /** Every observed hash, keyed by trust key — the input `prove-guards` verifies against. */
38
+ observedHashes: Map<string, string>;
39
+ }
40
+ export interface BuildTrustKeyReportOptions {
41
+ worktreePath: string;
42
+ /** Main repo root — the file Codex actually reads under #27133 lives under it. */
43
+ mainRepoPath: string;
44
+ codexHome: string;
45
+ /** Result of `hooks/list`, already run against a trusted directory. */
46
+ hooksList: CodexHooksListResult;
47
+ /**
48
+ * sha256 of each hooks file taken IMMEDIATELY BEFORE the `hooks/list` call, keyed by
49
+ * absolute hooks-file path (see `shaCodexHooksFiles`).
50
+ *
51
+ * WHY (SF-8): the carry-over rests on the two files being byte-identical, and the
52
+ * sha that established that was read AFTER `hooks/list` returned — seconds later, on a
53
+ * machine where `mx-agent codex deploy-config` may be running in another session. A
54
+ * deploy landing inside that window makes a carried hash describe bytes that are no
55
+ * longer on disk, and the row would read `granted`. Supplying this makes the identity
56
+ * claim span the whole call: both files are hashed before and after, and any change
57
+ * refuses the carry-over rather than dating it.
58
+ */
59
+ shaBefore?: ReadonlyMap<string, string | null>;
60
+ }
61
+ /** sha256 of the deployed hooks file in each directory, keyed by absolute path. */
62
+ export declare function shaCodexHooksFiles(dirs: readonly string[]): Map<string, string | null>;
63
+ /**
64
+ * Build the full two-set report. Pure: every input is passed in, nothing is spawned.
65
+ */
66
+ export declare function buildTrustKeyReport(opts: BuildTrustKeyReportOptions): TrustKeyReport;
67
+ /**
68
+ * The pasteable `~/.codex/config.toml` block for every entry that needs a grant.
69
+ *
70
+ * THE HASH IS PASSED THROUGH VERBATIM. `currentHash` already begins with `sha256:`;
71
+ * writing `sha256:` in front of it again produces a value Codex never matches, so the
72
+ * hook does not run while a presence-only check reports trust satisfied. That is the
73
+ * single easiest mistake in the grant procedure, and it fails silently, so this function
74
+ * never constructs the value — it only copies it.
75
+ *
76
+ * AND A VALUE OF THE WRONG SHAPE IS NOT OFFERED FOR PASTING AT ALL (SF-6). Verbatim
77
+ * reproduction is the rule for what we DISPLAY; it is not a reason to put a value that
78
+ * failed `CODEX_HASH_SHAPE` under a heading that reads "paste this into your config".
79
+ * The renderer's shape warning came AFTER the block and did not remove the line from it,
80
+ * so the one string this command exists to prevent an operator from writing was printed
81
+ * for them to copy. Shape failures move to `unresolvable`, which carries the reason and
82
+ * ends at the interactive Codex trust prompt.
83
+ */
84
+ export interface UnresolvableTrustKeyRow extends TrustKeyRow {
85
+ /** Why no hash is offered for this row. */
86
+ reason: string;
87
+ }
88
+ export declare function trustGrantToml(rows: readonly TrustKeyRow[]): {
89
+ block: string;
90
+ /** Rows that need a grant but have no hash that may be offered for pasting. */
91
+ unresolvable: UnresolvableTrustKeyRow[];
92
+ };
93
+ /** `sha256:` + 64 lowercase hex — the shape observed live on codex-cli 0.145.0. */
94
+ export declare const CODEX_HASH_SHAPE: RegExp;
95
+ //# sourceMappingURL=codex-trust-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-trust-keys.d.ts","sourceRoot":"","sources":["../../../src/lib/runtime/codex-trust-keys.ts"],"names":[],"mappings":"AAsCA,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAE/B,6DAA6D;AAC7D,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,cAAc,CAAC;AAErF,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,cAAc,CAAC;IACvB,+EAA+E;IAC/E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,+EAA+E;IAC/E,YAAY,EAAE,YAAY,GAAG,cAAc,GAAG,IAAI,CAAC;IACnD,qFAAqF;IACrF,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,EAAE,OAAO,CAAC;IACvB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