@parcha/agentrun-harness-codex 0.1.0-beta.79 → 0.1.0-beta.81
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.
- package/CHANGELOG.md +15 -0
- package/dist/code-mode.d.ts +19 -0
- package/dist/code-mode.js +76 -4
- package/dist/config.js +3 -0
- package/dist/harness.js +40 -4
- package/dist/host/machine.js +13 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/scripts.d.ts +45 -2
- package/dist/scripts.js +71 -10
- package/dist/verify.d.ts +13 -3
- package/dist/verify.js +79 -9
- package/dist/versions.d.ts +7 -2
- package/dist/versions.js +11 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.81 (2026-12-01)
|
|
6
|
+
|
|
7
|
+
- A code-mode script that `codex-code-mode-host` did not run to its end ends its turn failed instead of completed, and a host that goes quiet on a script no longer holds the turn open without end. Codex answers an `exec` in its own words, with no script status, when the host is off, did not start, answered outside its protocol, or died with the script in it, and it ended the turn completed; and it waited on a host that took the script and went quiet for as long as the host stayed up. The adapter now counts an `exec` (or the `wait` on its cell) as run only when its output's first text starts with one of Codex's script status headers (`SCRIPT_STATUS`), or with Codex's answer to an `exec` the model wrote wrong (`EXEC_MISTAKES`: no script, or a bad first-line pragma, which Codex answers before it asks the host and the model can put right). Any other answer stops the turn and fails it, naming `codex-code-mode-host` and Codex's words, whether or not a nested call of the script ran first. A host that leaves an `exec` or `wait` unanswered for a minute past the yield the script asked for (Codex's default when it names none), with no nested call of it running, fails the turn the same way. Both lists are checked against the pinned binary. <!-- changes/codex-code-mode-host-down.md -->
|
|
8
|
+
- The loopback model proxy can now check who sends the session's key, not only the key (`ModelProxyOptions.peers`, Linux). Before, any process of the same user could read the key from the harness's environment and use the session's model credential. Now every process that holds the client's socket must be one the host named with `ModelProxy.admitProcess`: the exact process, pinned by its pid and start time, never one of its children and never the host itself. A connection with no holder, or one that is gone, is refused. The check only logs by default: each connection it would refuse is logged once as `would_refuse`, with the session, the reason and the holders' pids, never a key. Setting `AGENTRUN_MODEL_PROXY_PEER_CHECK=enforce` refuses them with a 403. The key is still required either way. The Codex and Claude Agent local machines, OpenCode and Goose turn the check on and name the process they spawn. A socket of another user is refused, unless that user is the one the host says the session runs as (`peers.runUid`), which is admitted on the key alone. A host whose `/proc` can't be read: under `enforce` on Linux the proxy refuses to start (`PROC_UNREADABLE`); otherwise it logs once that the check is off and admits on the key alone. <!-- changes/model-proxy-peer-check.md -->
|
|
9
|
+
- `ModelProxy` has a new method, `admitProcess(pid)`. A host that implements `ModelProxy` itself adds it.
|
|
10
|
+
- `AcpProxy`'s result may carry `admit(pid)`. The ACP harness calls it with the agent's pid once the agent is spawned.
|
|
11
|
+
- `@parcha/agentrun-kernel/host` exports `PEER_CHECK_ENV` and `peerModeOf(env)`.
|
|
12
|
+
|
|
13
|
+
## 0.1.0-beta.80 (2026-12-01)
|
|
14
|
+
|
|
15
|
+
**Breaking:**
|
|
16
|
+
|
|
17
|
+
- The adapter now checks Codex's code-mode host (`codex-code-mode-host`, the binary a code-mode model's `exec` runs in) against a pinned sha256 per target, as it checks Codex's own binary. It looks for the host where Codex does, from the real path of Codex's binary (a link to Codex leads to the folder of the file it links to). In a package's layout (a `codex-package.json` in the folder above `bin/`), that is the package's `codex-resources/` when the host is there, and otherwise the host beside Codex. A host in the other place is checked too. A host that is not the pinned build is refused with `CodexPinMismatch` (pin `code_mode_host_sha256`), and a missing one with `CodexNotInstalled`, before any run starts. A check that passed is kept for the process only while the binary and each host stay the same files, unchanged. `codexPins()` now includes `hostSha256`, and `CODE_MODE_HOST_SHA256` is exported. <!-- changes/codex-code-mode-host-pin.md -->
|
|
18
|
+
A platform the pins list no host for is refused with `CodexPinMismatch` (pin `code_mode_host_sha256`). Pins of a caller's own that leave out `hostSha256` are refused the same way; set `hostSha256: null` to leave the host unchecked, for example for a binary that runs no code-mode model.
|
|
19
|
+
|
|
5
20
|
## 0.1.0-beta.75 (2026-11-30)
|
|
6
21
|
|
|
7
22
|
- On Codex, a call a person denied is no longer made again. When an `exec` waited for a person's approval, the model was told afterwards that its script "was cut short (the session stopped)". It read the denial as a crash to retry past, and asked the person the same question until they cancelled. The output now says the script stopped at a call that waited for approval. When the call was refused, because the person declined it or because the tool was set to deny while the call waited, the output adds that the refusal is an answer: the model should finish without the call or say what it needed it for. <!-- changes/codex-declined-call-not-retried.md -->
|
package/dist/code-mode.d.ts
CHANGED
|
@@ -68,7 +68,20 @@ export interface CodeModeDeps {
|
|
|
68
68
|
/** The bridge's budget (CodexHarnessOptions.resultBudget): a result handed Codex from the log is held to it as the
|
|
69
69
|
* bridge holds one it runs. */
|
|
70
70
|
budget?: ResultBudget;
|
|
71
|
+
/** Told, live, when the code-mode host did not run a script to its end, and the turn fails on it: Codex answered its `exec`
|
|
72
|
+
* (or the `wait` on its cell) with no script status (ScriptEvent.unrun, Codex's words; scripts.ts SCRIPT_STATUS), whether or
|
|
73
|
+
* not a nested call of it ran first (a script that lost its host part way is no completed turn); or the host left the
|
|
74
|
+
* `exec` or `wait` unanswered for `ms` (HOST_SILENCE_MS past its yield), with no nested call of it running. Not for an
|
|
75
|
+
* output this drive wrote itself (a recovered exec's). `text`: what to say of it. */
|
|
76
|
+
hostFailed?(text: string): void;
|
|
77
|
+
/** When the invocation ends (the harness's deadline): a script's wait is not bounded past it. */
|
|
78
|
+
deadline?: number;
|
|
71
79
|
}
|
|
80
|
+
/** How long past its yield (the time Codex waits on an `exec` or a `wait` before it answers "Script running") the code-mode host
|
|
81
|
+
* may leave one unanswered, no nested call of it running, before the turn fails. The first `exec` of a session also starts
|
|
82
|
+
* the host: Codex gives up on its handshake by itself at about 30 s, inside this. Codex itself waits on the host without
|
|
83
|
+
* bound: a host that took the session and then went quiet held the turn open until the invocation was stopped. */
|
|
84
|
+
export declare const HOST_SILENCE_MS = 60000;
|
|
72
85
|
interface Dangling {
|
|
73
86
|
callId: string;
|
|
74
87
|
name: string;
|
|
@@ -146,6 +159,12 @@ export declare function codeMode(deps: CodeModeDeps): {
|
|
|
146
159
|
}, owed: {
|
|
147
160
|
text?: string;
|
|
148
161
|
}[]): Promise<string>;
|
|
162
|
+
/** After a crash, in a turn Codex ended completed: what is said of the first `exec` of its last Codex turn that Codex answered
|
|
163
|
+
* with no script status (as hostFailed says it live), if one is there and no recovery answered it (RECOVERED_END_STREAM: that
|
|
164
|
+
* answer is the adapter's, with no header of its own). Codex can end its turn completed before the harness's interrupt
|
|
165
|
+
* reaches it, and its end line is in the log before the turn's failed end is written: a crash between the two must not
|
|
166
|
+
* leave the recovery to end completed a turn whose script the host never ran. */
|
|
167
|
+
unrunInLastTurn(lines: readonly string[]): Promise<string | undefined>;
|
|
149
168
|
/** A turn ended: the calls answered from the log were for it alone. */
|
|
150
169
|
turnEnded(): void;
|
|
151
170
|
};
|
package/dist/code-mode.js
CHANGED
|
@@ -2,7 +2,7 @@ import { boundKey, boundResult, failureText, openTurn, recoveryNote, recoverySys
|
|
|
2
2
|
// cycle with harness.ts: read repairOutput only inside functions, never at module top level (pinned by "code mode and the harness
|
|
3
3
|
// load in either order and the repair reads repairOutput"). A host loads harness.js first, so at that point none of its const bindings is set.
|
|
4
4
|
import { repairOutput } from "./harness.js";
|
|
5
|
-
import { summarizeRollout } from "./rollout.js";
|
|
5
|
+
import { parseLine, summarizeRollout } from "./rollout.js";
|
|
6
6
|
import { callKey, completedNested, execRecovery, NESTED_CALL, outputTextOf, parkedKey, recoveredFailed, recoveredRowText, recoveryFacts, Scripts, settle, UNWATCHED, waitResumed } from "./scripts.js";
|
|
7
7
|
/** The stream that ties each nested call to the `exec` it ran under: `{ callId, exec, since }` (`since`: the turn it ran in), written before the call runs. */
|
|
8
8
|
export const NESTED_STREAM = "codex.nested";
|
|
@@ -19,6 +19,11 @@ export const SHOWN_STREAM = "codex.nested-shown";
|
|
|
19
19
|
* header for its rollout line to be read by, so the exec's end on the host's record, live or replayed after a later crash, reads this. */
|
|
20
20
|
export const RECOVERED_END_STREAM = "codex.exec-recovered-end";
|
|
21
21
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22
|
+
/** How long past its yield (the time Codex waits on an `exec` or a `wait` before it answers "Script running") the code-mode host
|
|
23
|
+
* may leave one unanswered, no nested call of it running, before the turn fails. The first `exec` of a session also starts
|
|
24
|
+
* the host: Codex gives up on its handshake by itself at about 30 s, inside this. Codex itself waits on the host without
|
|
25
|
+
* bound: a host that took the session and then went quiet held the turn open until the invocation was stopped. */
|
|
26
|
+
export const HOST_SILENCE_MS = 60_000;
|
|
22
27
|
/** Only a custom tool call named `exec` is code mode's: a host tool that happens to be called `exec` is a function call. */
|
|
23
28
|
const isExec = (d) => d.type === "custom_tool_call" && d.name === "exec";
|
|
24
29
|
/** The item that answers a dangling call that is not an `exec`: of the kind the call asks for (the Responses API refuses an output of the
|
|
@@ -121,6 +126,32 @@ export function codeMode(deps) {
|
|
|
121
126
|
const scripts = new Scripts();
|
|
122
127
|
/** The exec each nested call was admitted under. */
|
|
123
128
|
const execOf = new Map();
|
|
129
|
+
/** The execs this drive answered itself (recoverItems): their output is the session's words, with no script status. */
|
|
130
|
+
const answeredHere = new Set();
|
|
131
|
+
/** The `exec` or `wait` waiting on the code-mode host now (its script, and how long Codex waits before it yields), the
|
|
132
|
+
* nested calls of a script running now, and the timer on the host's silence (HOST_SILENCE_MS). */
|
|
133
|
+
let awaited;
|
|
134
|
+
let nestedLive = 0;
|
|
135
|
+
let silence;
|
|
136
|
+
/** Times the host's silence again: from now, while an `exec` or `wait` waits on it and no nested call runs. */
|
|
137
|
+
const watch = () => {
|
|
138
|
+
if (silence)
|
|
139
|
+
clearTimeout(silence);
|
|
140
|
+
silence = undefined;
|
|
141
|
+
if (!awaited || nestedLive > 0 || !deps.hostFailed)
|
|
142
|
+
return;
|
|
143
|
+
const left = deps.deadline === undefined ? Infinity : Math.max(0, deps.deadline - Date.now());
|
|
144
|
+
const ms = Math.min(awaited.yieldMs, left) + HOST_SILENCE_MS;
|
|
145
|
+
silence = setTimeout(() => {
|
|
146
|
+
silence = undefined;
|
|
147
|
+
deps.hostFailed?.(`the host left it unanswered for ${Math.round(ms / 1000)} s`);
|
|
148
|
+
}, ms);
|
|
149
|
+
silence.unref?.();
|
|
150
|
+
};
|
|
151
|
+
machine.signal?.addEventListener?.("abort", () => {
|
|
152
|
+
awaited = undefined;
|
|
153
|
+
watch();
|
|
154
|
+
}, { once: true });
|
|
124
155
|
/** After a recovery: the `never` calls the log holds a completed outcome for, by tool and arguments, until the turn ends. Each answers one re-issue. */
|
|
125
156
|
const recovered = new Map();
|
|
126
157
|
/** Each `exec` whose row this drive opened on the host's record (SessionIO.ownCalls): its end waits for that write. */
|
|
@@ -164,11 +195,18 @@ export function codeMode(deps) {
|
|
|
164
195
|
// recovery ran or found cut off, failed as the recovery recorded (RECOVERED_END_STREAM).
|
|
165
196
|
machine.onRolloutLine?.((line) => {
|
|
166
197
|
const said = scripts.note(line);
|
|
167
|
-
if (!said
|
|
198
|
+
if (!said)
|
|
199
|
+
return;
|
|
200
|
+
// Codex waits on the host from an exec's line or a wait's on its cell, until an output answers it.
|
|
201
|
+
awaited = said.kind === "opened" || said.kind === "waiting" ? { exec: said.exec, yieldMs: said.yieldMs } : awaited?.exec === said.exec ? undefined : awaited;
|
|
202
|
+
watch();
|
|
203
|
+
if (said.kind === "finished" && said.unrun !== undefined && !answeredHere.has(said.exec))
|
|
204
|
+
deps.hostFailed?.(`Codex answered it with no script status: ${said.unrun}`);
|
|
205
|
+
if (!deps.ownCalls)
|
|
168
206
|
return;
|
|
169
207
|
if (said.kind === "opened")
|
|
170
208
|
void openRow(said.exec, said.input).catch((error) => deps.log("codex: an exec's row was not written", { exec: said.exec, error: String(error) }));
|
|
171
|
-
else
|
|
209
|
+
else if (said.kind === "finished")
|
|
172
210
|
endRow(said.exec, said.output, said.failed);
|
|
173
211
|
});
|
|
174
212
|
/** The script a nested call is tied to now, as the log and the proxy's latest answer have it. */
|
|
@@ -280,11 +318,21 @@ export function codeMode(deps) {
|
|
|
280
318
|
// whether or not the answer was built, so a call whose answer throws leaves none in the bridge for the session's life.
|
|
281
319
|
let extras;
|
|
282
320
|
let answer;
|
|
321
|
+
// A script's nested call running is no silence of the host's: its timer starts again once the call is answered.
|
|
322
|
+
const nested = NESTED_CALL.test(callId);
|
|
323
|
+
if (nested) {
|
|
324
|
+
nestedLive += 1;
|
|
325
|
+
watch();
|
|
326
|
+
}
|
|
283
327
|
try {
|
|
284
328
|
answer = await next(req);
|
|
285
329
|
}
|
|
286
330
|
finally {
|
|
287
331
|
extras = deps.bridge.take?.(callId);
|
|
332
|
+
if (nested) {
|
|
333
|
+
nestedLive -= 1;
|
|
334
|
+
watch();
|
|
335
|
+
}
|
|
288
336
|
}
|
|
289
337
|
// A script's nested call gets the tool's value, images and all, to compute on (scriptAnswer); the model's own
|
|
290
338
|
// call gets the words and the images to look at.
|
|
@@ -379,8 +427,10 @@ export function codeMode(deps) {
|
|
|
379
427
|
}
|
|
380
428
|
// This output finishes the cell's exec, and it carries no status header: that exec ends as its last call says.
|
|
381
429
|
const exec = cell === undefined ? undefined : yielders.execOn(cell);
|
|
382
|
-
if (exec !== undefined)
|
|
430
|
+
if (exec !== undefined) {
|
|
383
431
|
journal.append(RECOVERED_END_STREAM, { exec, failed: recoveredFailed(ties.filter((tie) => tie.exec === exec).map(fact)) });
|
|
432
|
+
answeredHere.add(exec);
|
|
433
|
+
}
|
|
384
434
|
items[i] = withOutputKind(waited !== undefined ? { ...item, output: waited } : pictured !== undefined ? { ...item, output: pictured } : item, c);
|
|
385
435
|
return;
|
|
386
436
|
}
|
|
@@ -389,6 +439,7 @@ export function codeMode(deps) {
|
|
|
389
439
|
const recovered = execRecovery(own, loose, budgets[i]);
|
|
390
440
|
items[i] = { type: "custom_tool_call_output", call_id: c.callId, output: recovered.output };
|
|
391
441
|
journal.append(RECOVERED_END_STREAM, { exec: c.callId, failed: recoveredFailed(own) });
|
|
442
|
+
answeredHere.add(c.callId);
|
|
392
443
|
built.add(i);
|
|
393
444
|
shown.push(...recovered.shown);
|
|
394
445
|
});
|
|
@@ -434,9 +485,30 @@ export function codeMode(deps) {
|
|
|
434
485
|
}
|
|
435
486
|
return recoveryUserTurn(owed.map((s) => s.text ?? ""), note.pending.map((s) => s.text ?? ""));
|
|
436
487
|
},
|
|
488
|
+
/** After a crash, in a turn Codex ended completed: what is said of the first `exec` of its last Codex turn that Codex answered
|
|
489
|
+
* with no script status (as hostFailed says it live), if one is there and no recovery answered it (RECOVERED_END_STREAM: that
|
|
490
|
+
* answer is the adapter's, with no header of its own). Codex can end its turn completed before the harness's interrupt
|
|
491
|
+
* reaches it, and its end line is in the log before the turn's failed end is written: a crash between the two must not
|
|
492
|
+
* leave the recovery to end completed a turn whose script the host never ran. */
|
|
493
|
+
async unrunInLastTurn(lines) {
|
|
494
|
+
const answered = new Set((await journal.read(RECOVERED_END_STREAM)).map((r) => r.data.exec));
|
|
495
|
+
const read = new Scripts();
|
|
496
|
+
let unrun;
|
|
497
|
+
for (const line of lines) {
|
|
498
|
+
const l = parseLine(line);
|
|
499
|
+
if (l?.type === "event_msg" && l.payload?.type === "task_started")
|
|
500
|
+
unrun = undefined;
|
|
501
|
+
const said = read.note(line);
|
|
502
|
+
if (unrun === undefined && said?.kind === "finished" && said.unrun !== undefined && !answered.has(said.exec))
|
|
503
|
+
unrun = `Codex answered it with no script status: ${said.unrun}`;
|
|
504
|
+
}
|
|
505
|
+
return unrun;
|
|
506
|
+
},
|
|
437
507
|
/** A turn ended: the calls answered from the log were for it alone. */
|
|
438
508
|
turnEnded() {
|
|
439
509
|
recovered.clear();
|
|
510
|
+
awaited = undefined;
|
|
511
|
+
watch();
|
|
440
512
|
},
|
|
441
513
|
};
|
|
442
514
|
}
|
package/dist/config.js
CHANGED
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
* call chatgpt.com or start a daemon.
|
|
17
17
|
*/
|
|
18
18
|
export const BUILTINS_OFF = {
|
|
19
|
+
// The shell's gate: with it off no shell tool is offered, unified exec's included.
|
|
19
20
|
shell_tool: false,
|
|
21
|
+
// Not a gate in the pinned Codex, which turns unified exec back on whatever config.toml says (codex-rs
|
|
22
|
+
// managed_features.rs, normalize_candidate); kept off here in case a later release honours it.
|
|
20
23
|
unified_exec: false,
|
|
21
24
|
view_image: false,
|
|
22
25
|
image_generation: false,
|
package/dist/harness.js
CHANGED
|
@@ -56,6 +56,14 @@ export const SANDBOX_STREAM = 'codex.sandbox';
|
|
|
56
56
|
export const TAIL_STREAM = 'codex.tail';
|
|
57
57
|
/** Where app-server's git looks for a repository: nowhere (it would otherwise read `/workspace/.git`'s config, which the model writes, outside bwrap). */
|
|
58
58
|
const NO_GIT_DIR = '/nonexistent/dh-no-git';
|
|
59
|
+
/** The end of a turn whose script the code-mode host did not run (CodeModeDeps.hostFailed; after a crash, unrunInLastTurn). */
|
|
60
|
+
/** The outcomes hostFailedEnd made: a session turn keeps one across the Codex turns its carried steers run (`turn`). */
|
|
61
|
+
const hostFailures = new WeakSet();
|
|
62
|
+
const hostFailedEnd = (said) => {
|
|
63
|
+
const outcome = { status: 'failed', error: `codex-code-mode-host did not run the model's script: ${said}`.slice(0, 500) };
|
|
64
|
+
hostFailures.add(outcome);
|
|
65
|
+
return outcome;
|
|
66
|
+
};
|
|
59
67
|
/** A built-in call whose `function_call` line never reached the log: declined, never run. */
|
|
60
68
|
const LAGGING = Object.freeze({ run: false, lagging: true });
|
|
61
69
|
/** The rollout tail failed (the file shrank, was replaced, or is not the session user's): what the drive halts with. */
|
|
@@ -379,7 +387,22 @@ export function codexHarness(options = {}) {
|
|
|
379
387
|
}
|
|
380
388
|
mirror();
|
|
381
389
|
};
|
|
382
|
-
const code = codeMode({ ctx, machine, journal, logged, synced, bridge, log, lines, rpc: () => rpc, guard: (p) => guard(p), threadId: () => threadId, tries: BARRIER_TRIES, declined: LAGGING_RESULT, ...(options.ownCalls ? { ownCalls: options.ownCalls } : {}), ...(options.resultBudget ? { budget: options.resultBudget } : {})
|
|
390
|
+
const code = codeMode({ ctx, machine, journal, logged, synced, bridge, log, lines, rpc: () => rpc, guard: (p) => guard(p), threadId: () => threadId, tries: BARRIER_TRIES, declined: LAGGING_RESULT, ...(options.ownCalls ? { ownCalls: options.ownCalls } : {}), ...(options.resultBudget ? { budget: options.resultBudget } : {}),
|
|
391
|
+
// The code-mode host did not run a script (Codex answered it with no script status, or the host went quiet on it):
|
|
392
|
+
// Codex would end the turn completed, or wait on the host without end. The turn is stopped here, and fails naming
|
|
393
|
+
// the host. A turn the harness already stopped (its answer's cut, a command past the deadline) is not: what Codex
|
|
394
|
+
// writes for the exec it stopped ("aborted by user ...") is the stop's.
|
|
395
|
+
deadline,
|
|
396
|
+
hostFailed: (text) => {
|
|
397
|
+
const t = active;
|
|
398
|
+
log('codex: codex-code-mode-host did not run a script: the turn fails', { said: text.slice(0, 200) });
|
|
399
|
+
if (!t || t.hostFailed !== undefined || t.cut || t.stopped)
|
|
400
|
+
return;
|
|
401
|
+
t.hostFailed = text;
|
|
402
|
+
if (t.id)
|
|
403
|
+
void rpc.request('turn/interrupt', { threadId, turnId: t.id }).catch((err) => log('codex: the turn whose script did not run could not be interrupted', { error: String(err?.message ?? err).slice(0, 200) }));
|
|
404
|
+
},
|
|
405
|
+
});
|
|
383
406
|
/**
|
|
384
407
|
* The hard barrier before a `never` call (§5.6): its `function_call`
|
|
385
408
|
* line in the log, flushed, before its intent. Codex's rollout writer is
|
|
@@ -464,6 +487,7 @@ export function codexHarness(options = {}) {
|
|
|
464
487
|
}
|
|
465
488
|
log('codex: a command ran out of time in this invocation: stopped', { callId: id });
|
|
466
489
|
timedOut.add(id);
|
|
490
|
+
t.stopped = true;
|
|
467
491
|
void rpc.request('turn/interrupt', { threadId, turnId: t.id }).catch((err) => {
|
|
468
492
|
timedOut.delete(id);
|
|
469
493
|
log('codex: the turn could not be interrupted', { callId: id, error: String(err?.message ?? err).slice(0, 200) });
|
|
@@ -764,6 +788,9 @@ export function codexHarness(options = {}) {
|
|
|
764
788
|
if (said)
|
|
765
789
|
journal.message({ type: 'message', role: 'assistant', text: said });
|
|
766
790
|
active = undefined;
|
|
791
|
+
// A script the code-mode host did not run: the turn was stopped for it, and fails naming the host.
|
|
792
|
+
if (t.hostFailed !== undefined)
|
|
793
|
+
return hostFailedEnd(t.hostFailed);
|
|
767
794
|
// Its answer cut at the output limit: the turn was interrupted for it, and ended there, its answer unfinished.
|
|
768
795
|
if (t.cut)
|
|
769
796
|
return { status: 'completed', stopReason: 'length', ...(t.cut.outputTokens !== undefined ? { outputTokens: t.cut.outputTokens } : {}), ...(t.cut.capCut ? { capCut: t.cut.capCut } : {}) };
|
|
@@ -792,9 +819,15 @@ export function codexHarness(options = {}) {
|
|
|
792
819
|
*/
|
|
793
820
|
const turn = async (text, clientId) => {
|
|
794
821
|
let outcome = await codexTurn(text, clientId);
|
|
795
|
-
|
|
822
|
+
// A script the code-mode host did not run fails the whole session turn: a carried steer's Codex turn that completes
|
|
823
|
+
// after it does not end the turn completed.
|
|
824
|
+
let hostFailure = hostFailures.has(outcome) ? outcome : undefined;
|
|
825
|
+
for (let s = carry.shift(); s; s = carry.shift()) {
|
|
796
826
|
outcome = await codexTurn(s.text ?? '', s.id);
|
|
797
|
-
|
|
827
|
+
if (!hostFailure && hostFailures.has(outcome))
|
|
828
|
+
hostFailure = outcome;
|
|
829
|
+
}
|
|
830
|
+
await endTurn(hostFailure ?? outcome);
|
|
798
831
|
};
|
|
799
832
|
// Steers that arrive while a turn runs go into it (`turn/steer`).
|
|
800
833
|
const steer = (t) => {
|
|
@@ -871,7 +904,10 @@ export function codexHarness(options = {}) {
|
|
|
871
904
|
const said = note.turn.entries.some((e) => e.data.type === 'message' && e.data.role === 'assistant' && e.data.text === last);
|
|
872
905
|
if (last && !said)
|
|
873
906
|
journal.message({ type: 'message', role: 'assistant', text: last });
|
|
874
|
-
|
|
907
|
+
// A script of the turn the code-mode host did not run: Codex ended it completed before the interrupt reached it, and the
|
|
908
|
+
// crash took the failed end the live turn was given. It ends failed here as it did there.
|
|
909
|
+
const unrun = await code.unrunInLastTurn(lines);
|
|
910
|
+
await endTurn(unrun === undefined ? { status: 'completed' } : hostFailedEnd(unrun));
|
|
875
911
|
}
|
|
876
912
|
else {
|
|
877
913
|
let text = note.text;
|
package/dist/host/machine.js
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
// - Each child runs in its own process group, which kill() and close() end whole, and dies with this process: started
|
|
13
13
|
// with a watch on its parent (./host's parentWatched, inside the host's confinement), so a host that is SIGKILLed,
|
|
14
14
|
// and runs no close, leaves no Codex behind.
|
|
15
|
-
// - The model proxy (@parcha/agentrun-kernel/host, with the Codex policy) starts with the machine and stops with it.
|
|
15
|
+
// - The model proxy (@parcha/agentrun-kernel/host, with the Codex policy) starts with the machine and stops with it. It
|
|
16
|
+
// checks that the session's key comes from a process this machine spawned, not from one of its children
|
|
17
|
+
// (ModelProxyOptions.peers).
|
|
16
18
|
import { spawn as spawnChild } from "node:child_process";
|
|
17
19
|
import { randomBytes } from "node:crypto";
|
|
18
20
|
import { lstatSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -20,7 +22,7 @@ import { dirname, isAbsolute, join, normalize, sep } from "node:path";
|
|
|
20
22
|
import { createInterface } from "node:readline";
|
|
21
23
|
import { FileTail } from "@parcha/agentrun-kernel/process";
|
|
22
24
|
import { brandMachine } from "./process.js";
|
|
23
|
-
import { parentWatched, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
25
|
+
import { parentWatched, peerModeOf, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
24
26
|
import { codexPolicy, withWebSearches } from "./policy.js";
|
|
25
27
|
import { UNWATCHED } from "../scripts.js";
|
|
26
28
|
import { MODEL_CATALOG_FILE, patchlessCatalog } from "../catalog.js";
|
|
@@ -80,7 +82,7 @@ function inside(base, rel) {
|
|
|
80
82
|
}
|
|
81
83
|
/** Start a child of the session, ended when this process ends. Its git stops at `ceiling` (the session's directory): it never looks for a repository
|
|
82
84
|
* above the session, in a parent the model could write, whose branch and remote would otherwise reach the records. */
|
|
83
|
-
function start(options, from, cwd, ceiling, confine, watch) {
|
|
85
|
+
function start(options, from, cwd, ceiling, confine, watch, admit) {
|
|
84
86
|
// The watch is inside the confinement, so it is set after any switch of user the prefix makes.
|
|
85
87
|
const run = confined(parentWatched({ command: options.command, args: options.args ?? [] }, watch), confine);
|
|
86
88
|
const child = spawnChild(run.command, run.args, {
|
|
@@ -89,6 +91,9 @@ function start(options, from, cwd, ceiling, confine, watch) {
|
|
|
89
91
|
detached: true,
|
|
90
92
|
stdio: ["pipe", "pipe", "pipe"],
|
|
91
93
|
});
|
|
94
|
+
// Named to the model proxy before this turn of the event loop ends, so before the child can have asked it anything.
|
|
95
|
+
if (child.pid !== undefined)
|
|
96
|
+
admit?.(child.pid);
|
|
92
97
|
let stderr = "";
|
|
93
98
|
child.stderr.setEncoding("utf8");
|
|
94
99
|
child.stderr.on("data", (chunk) => {
|
|
@@ -256,6 +261,10 @@ export function localMachine(options) {
|
|
|
256
261
|
for (const listener of cutListeners)
|
|
257
262
|
listener(stop);
|
|
258
263
|
},
|
|
264
|
+
// The key is in app-server's environment, which every process of its user can read: the proxy checks that it comes
|
|
265
|
+
// from a process this machine spawned (app-server), never from that process's children (its code-mode host, a
|
|
266
|
+
// tool). Logged only, unless the host's environment asks to enforce it (PEER_CHECK_ENV).
|
|
267
|
+
peers: { mode: peerModeOf(from), session: ctx.runId },
|
|
259
268
|
}, key);
|
|
260
269
|
const lost = new AbortController();
|
|
261
270
|
const children = new Set();
|
|
@@ -286,7 +295,7 @@ export function localMachine(options) {
|
|
|
286
295
|
spawn: async (spawnOptions) => {
|
|
287
296
|
if (closed)
|
|
288
297
|
throw new Error("agentrun-harness-codex: the session machine is closed");
|
|
289
|
-
const proc = withoutTurnsAfterStop(start(spawnOptions, from, root, ceiling, options.confine, options.parentWatch), ctx.signal);
|
|
298
|
+
const proc = withoutTurnsAfterStop(start(spawnOptions, from, root, ceiling, options.confine, options.parentWatch, (pid) => proxy.admitProcess(pid)), ctx.signal);
|
|
290
299
|
children.add(proc);
|
|
291
300
|
void proc.exited.then(() => children.delete(proc));
|
|
292
301
|
return proc;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export { CODEX_VERSION, codexBinary, codexTarget } from "./binary.js";
|
|
|
10
10
|
/** The shapes of a tool's schema Codex 0.164 drops or retypes (schema.ts): a host may refuse them sooner (an MCP grant, at its save). */
|
|
11
11
|
export { codexSchemaProblems } from "./schema.js";
|
|
12
12
|
export { verifyCodex, verifyCodexAsync, verifyCodexBinary, verifyCodexBinaryAsync } from "./verify.js";
|
|
13
|
-
export { CODEX_BASE_INPUT_TOKENS, CODEX_BINARY_SHA256, CODEX_INSTALL, CODEX_NPM_INTEGRITY, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
|
|
13
|
+
export { CODE_MODE_HOST_SHA256, CODEX_BASE_INPUT_TOKENS, CODEX_BINARY_SHA256, CODEX_INSTALL, CODEX_NPM_INTEGRITY, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
|
package/dist/index.js
CHANGED
|
@@ -7,4 +7,4 @@ export { CODEX_VERSION, codexBinary, codexTarget } from "./binary.js";
|
|
|
7
7
|
/** The shapes of a tool's schema Codex 0.164 drops or retypes (schema.ts): a host may refuse them sooner (an MCP grant, at its save). */
|
|
8
8
|
export { codexSchemaProblems } from "./schema.js";
|
|
9
9
|
export { verifyCodex, verifyCodexAsync, verifyCodexBinary, verifyCodexBinaryAsync } from "./verify.js";
|
|
10
|
-
export { CODEX_BASE_INPUT_TOKENS, CODEX_BINARY_SHA256, CODEX_INSTALL, CODEX_NPM_INTEGRITY, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
|
|
10
|
+
export { CODE_MODE_HOST_SHA256, CODEX_BASE_INPUT_TOKENS, CODEX_BINARY_SHA256, CODEX_INSTALL, CODEX_NPM_INTEGRITY, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
|
package/dist/scripts.d.ts
CHANGED
|
@@ -19,18 +19,61 @@ export type Tie = {
|
|
|
19
19
|
} | {
|
|
20
20
|
kind: "none";
|
|
21
21
|
};
|
|
22
|
-
/** What a rollout line says of a script: its `exec` line opened it (`input`, the script
|
|
23
|
-
*
|
|
22
|
+
/** What a rollout line says of a script: its `exec` line opened it (`input`, the script; `yieldMs`, how long Codex waits on
|
|
23
|
+
* it before it yields); it yielded (`cell`: its exec's output, or a `wait`'s, said "Script running with cell ID N"); a `wait`
|
|
24
|
+
* on its cell began (`yieldMs`, that wait's); or an output finished it (`output`, that output's text; `failed`, the script
|
|
25
|
+
* failed, as its status header says; `unrun`, Codex's own words when no script status came back, SCRIPT_STATUS). */
|
|
24
26
|
export type ScriptEvent = {
|
|
25
27
|
kind: "opened";
|
|
26
28
|
exec: string;
|
|
27
29
|
input: string;
|
|
30
|
+
yieldMs: number;
|
|
31
|
+
} | {
|
|
32
|
+
kind: "yielded";
|
|
33
|
+
exec: string;
|
|
34
|
+
cell: string;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "waiting";
|
|
37
|
+
exec: string;
|
|
38
|
+
cell: string;
|
|
39
|
+
yieldMs: number;
|
|
28
40
|
} | {
|
|
29
41
|
kind: "finished";
|
|
30
42
|
exec: string;
|
|
31
43
|
output: string;
|
|
32
44
|
failed: boolean;
|
|
45
|
+
unrun?: string;
|
|
33
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* The status headers Codex 0.164.0 puts first on an exec's or a wait's output when its code-mode host ran the script and
|
|
49
|
+
* said how it went: it completed, failed (threw, or its cell was gone), was terminated (a `wait` with `terminate`), or still
|
|
50
|
+
* runs (RUNNING). Each is followed by a line of its own ("Wall time ..."). An output that starts with none of them is Codex's
|
|
51
|
+
* own words, not the script's: the host never ran it to an end it could report (it was not there, did not start, answered
|
|
52
|
+
* outside its protocol, or died with the script in it). Codex hands those words to the model and ends the turn completed; the
|
|
53
|
+
* session fails the turn instead (CodeModeDeps.hostFailed), a nested call of that script run first or not. Only the first text
|
|
54
|
+
* of an output is read: what a script prints comes after Codex's header, never before it. test/code-mode-host-down.test.mjs,
|
|
55
|
+
* which CI runs on the pinned binary under AGENTRUN_CODEX_REQUIRE_BINARY=1, finds each header in the pinned binary (Codex
|
|
56
|
+
* builds "Script failed" at run time: a real script that throws holds that one), so a release that rewords one fails there.
|
|
57
|
+
*/
|
|
58
|
+
export declare const SCRIPT_STATUS: readonly string[];
|
|
59
|
+
/**
|
|
60
|
+
* Codex's answers to an `exec` the model wrote wrong (no script, or a bad first-line pragma), each by its fixed part (the words
|
|
61
|
+
* before any detail Codex adds): the model's own mistake, which it reads and can put right in the same turn. No script status
|
|
62
|
+
* comes with them, and none is owed: Codex answers them from the exec's text alone, before it starts or asks the host, so
|
|
63
|
+
* they come back the same with no host beside Codex at all (the sweep and the live rows of test/code-mode-host-down.test.mjs).
|
|
64
|
+
* Each is in the pinned binary (the same test).
|
|
65
|
+
*/
|
|
66
|
+
export declare const EXEC_MISTAKES: readonly string[];
|
|
67
|
+
/** Whether an output's first text is a script status (a header, then its line's end) or Codex's answer to an exec the model
|
|
68
|
+
* wrote wrong: anything else, the host never reported the script. */
|
|
69
|
+
export declare const scriptStatusSaid: (status: string) => boolean;
|
|
70
|
+
/** How long Codex waits on an `exec` before it yields when the script's first-line pragma names no `yield_time_ms` (the pinned
|
|
71
|
+
* Codex's default: a script that never ends yields at about 30 s), and on a `wait` that names none (its tool's description:
|
|
72
|
+
* 10000 ms). */
|
|
73
|
+
export declare const EXEC_YIELD_MS = 30000;
|
|
74
|
+
export declare const WAIT_YIELD_MS = 10000;
|
|
75
|
+
/** The `yield_time_ms` an exec's first-line pragma (`// @exec: {...}`) names, if it names a valid one. */
|
|
76
|
+
export declare function execYieldMs(input: string): number;
|
|
34
77
|
export declare class Scripts {
|
|
35
78
|
private readonly open;
|
|
36
79
|
/** The `exec` calls whose script finished. */
|
package/dist/scripts.js
CHANGED
|
@@ -25,6 +25,57 @@ const RUNNING = /^Script running with cell ID (\S+)/;
|
|
|
25
25
|
/** A script that failed (it threw, or its cell was gone), as its status header says. The rollout's output line has no
|
|
26
26
|
* status field of its own: this header is the only place Codex says how a script ended. */
|
|
27
27
|
const FAILED = /^Script failed\b/;
|
|
28
|
+
/**
|
|
29
|
+
* The status headers Codex 0.164.0 puts first on an exec's or a wait's output when its code-mode host ran the script and
|
|
30
|
+
* said how it went: it completed, failed (threw, or its cell was gone), was terminated (a `wait` with `terminate`), or still
|
|
31
|
+
* runs (RUNNING). Each is followed by a line of its own ("Wall time ..."). An output that starts with none of them is Codex's
|
|
32
|
+
* own words, not the script's: the host never ran it to an end it could report (it was not there, did not start, answered
|
|
33
|
+
* outside its protocol, or died with the script in it). Codex hands those words to the model and ends the turn completed; the
|
|
34
|
+
* session fails the turn instead (CodeModeDeps.hostFailed), a nested call of that script run first or not. Only the first text
|
|
35
|
+
* of an output is read: what a script prints comes after Codex's header, never before it. test/code-mode-host-down.test.mjs,
|
|
36
|
+
* which CI runs on the pinned binary under AGENTRUN_CODEX_REQUIRE_BINARY=1, finds each header in the pinned binary (Codex
|
|
37
|
+
* builds "Script failed" at run time: a real script that throws holds that one), so a release that rewords one fails there.
|
|
38
|
+
*/
|
|
39
|
+
export const SCRIPT_STATUS = Object.freeze(["Script completed", "Script failed", "Script terminated", "Script running with cell ID"]);
|
|
40
|
+
/**
|
|
41
|
+
* Codex's answers to an `exec` the model wrote wrong (no script, or a bad first-line pragma), each by its fixed part (the words
|
|
42
|
+
* before any detail Codex adds): the model's own mistake, which it reads and can put right in the same turn. No script status
|
|
43
|
+
* comes with them, and none is owed: Codex answers them from the exec's text alone, before it starts or asks the host, so
|
|
44
|
+
* they come back the same with no host beside Codex at all (the sweep and the live rows of test/code-mode-host-down.test.mjs).
|
|
45
|
+
* Each is in the pinned binary (the same test).
|
|
46
|
+
*/
|
|
47
|
+
export const EXEC_MISTAKES = Object.freeze([
|
|
48
|
+
"exec expects raw JavaScript source text",
|
|
49
|
+
"exec pragma must be valid JSON with supported fields `yield_time_ms` and `max_output_tokens`: ",
|
|
50
|
+
"exec pragma must be a JSON object with supported fields `yield_time_ms` and `max_output_tokens`",
|
|
51
|
+
"exec pragma must be followed by JavaScript source on subsequent lines",
|
|
52
|
+
"exec pragma only supports `yield_time_ms` and `max_output_tokens`; got `",
|
|
53
|
+
"exec pragma fields `yield_time_ms` and `max_output_tokens` must be non-negative safe integers: ",
|
|
54
|
+
"exec pragma field `yield_time_ms` must be a non-negative safe integer",
|
|
55
|
+
"exec pragma field `max_output_tokens` must be a non-negative safe integer",
|
|
56
|
+
]);
|
|
57
|
+
/** Whether an output's first text is a script status (a header, then its line's end) or Codex's answer to an exec the model
|
|
58
|
+
* wrote wrong: anything else, the host never reported the script. */
|
|
59
|
+
export const scriptStatusSaid = (status) => SCRIPT_STATUS.some((header) => status.startsWith(header) && /^(?:\s|$)/.test(status.slice(header.length))) || EXEC_MISTAKES.some((words) => status.startsWith(words));
|
|
60
|
+
/** How long Codex waits on an `exec` before it yields when the script's first-line pragma names no `yield_time_ms` (the pinned
|
|
61
|
+
* Codex's default: a script that never ends yields at about 30 s), and on a `wait` that names none (its tool's description:
|
|
62
|
+
* 10000 ms). */
|
|
63
|
+
export const EXEC_YIELD_MS = 30_000;
|
|
64
|
+
export const WAIT_YIELD_MS = 10_000;
|
|
65
|
+
/** The `yield_time_ms` an exec's first-line pragma (`// @exec: {...}`) names, if it names a valid one. */
|
|
66
|
+
export function execYieldMs(input) {
|
|
67
|
+
const pragma = /^\s*\/\/\s*@exec:(.*)$/.exec(input.split("\n", 1)[0] ?? "")?.[1];
|
|
68
|
+
try {
|
|
69
|
+
return pragma === undefined ? EXEC_YIELD_MS : yieldOf(JSON.parse(pragma), EXEC_YIELD_MS);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return EXEC_YIELD_MS;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const yieldOf = (args, fallback) => {
|
|
76
|
+
const ms = args?.yield_time_ms;
|
|
77
|
+
return typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0 ? ms : fallback;
|
|
78
|
+
};
|
|
28
79
|
const textOf = (output) => typeof output === "string" ? output : Array.isArray(output) ? output.map((part) => (typeof part?.text === "string" ? part.text : "")).join("\n") : "";
|
|
29
80
|
export class Scripts {
|
|
30
81
|
open = [];
|
|
@@ -47,36 +98,46 @@ export class Scripts {
|
|
|
47
98
|
return undefined;
|
|
48
99
|
const input = typeof p.input === "string" ? p.input : "";
|
|
49
100
|
this.open.push({ exec: id, input });
|
|
50
|
-
return { kind: "opened", exec: id, input };
|
|
101
|
+
return { kind: "opened", exec: id, input, yieldMs: execYieldMs(input) };
|
|
51
102
|
}
|
|
52
103
|
else if (p.type === "custom_tool_call_output") {
|
|
53
104
|
const at = this.open.findIndex((x) => x.exec === id);
|
|
54
105
|
if (at < 0)
|
|
55
106
|
return undefined;
|
|
56
|
-
if (running)
|
|
57
|
-
this.open[at].cell = running[1];
|
|
58
|
-
else
|
|
107
|
+
if (!running)
|
|
59
108
|
return this.finish(at, p.output);
|
|
109
|
+
this.open[at].cell = running[1];
|
|
110
|
+
return { kind: "yielded", exec: id, cell: running[1] };
|
|
60
111
|
}
|
|
61
112
|
else if (p.type === "function_call" && p.name === "wait") {
|
|
62
113
|
try {
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
|
|
114
|
+
const args = JSON.parse(String(p.arguments));
|
|
115
|
+
if (args?.cell_id === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
const cell = String(args.cell_id);
|
|
118
|
+
this.waitsOn.set(id, cell);
|
|
119
|
+
const exec = this.execOn(cell);
|
|
120
|
+
if (exec !== undefined)
|
|
121
|
+
return { kind: "waiting", exec, cell, yieldMs: yieldOf(args, WAIT_YIELD_MS) };
|
|
66
122
|
}
|
|
67
123
|
catch { }
|
|
68
124
|
}
|
|
69
|
-
else if (p.type === "function_call_output" && this.waitsOn.has(id)
|
|
125
|
+
else if (p.type === "function_call_output" && this.waitsOn.has(id)) {
|
|
70
126
|
const at = this.open.findIndex((x) => x.cell === this.waitsOn.get(id));
|
|
71
|
-
if (at
|
|
127
|
+
if (at < 0)
|
|
128
|
+
return undefined;
|
|
129
|
+
if (!running)
|
|
72
130
|
return this.finish(at, p.output);
|
|
131
|
+
this.open[at].cell = running[1];
|
|
132
|
+
return { kind: "yielded", exec: this.open[at].exec, cell: running[1] };
|
|
73
133
|
}
|
|
74
134
|
return undefined;
|
|
75
135
|
}
|
|
76
136
|
finish(at, output) {
|
|
77
137
|
const exec = this.open.splice(at, 1)[0].exec;
|
|
78
138
|
this.done.add(exec);
|
|
79
|
-
|
|
139
|
+
const status = statusOf(output);
|
|
140
|
+
return { kind: "finished", exec, output: textOf(output), failed: FAILED.test(status), ...(scriptStatusSaid(status) ? {} : { unrun: status }) };
|
|
80
141
|
}
|
|
81
142
|
/** The unfinished `exec` that yielded on cell `cell`, if any. */
|
|
82
143
|
execOn(cell) {
|
package/dist/verify.d.ts
CHANGED
|
@@ -6,20 +6,30 @@ export interface CodexPins {
|
|
|
6
6
|
sha256?: string;
|
|
7
7
|
/** The platform package's version (`<version>-<platform>`), when the binary came from one. */
|
|
8
8
|
packageVersion?: string;
|
|
9
|
+
/** The code-mode host's sha256 (CODE_MODE_HOST_SHA256), checked wherever Codex finds it (codeModeHostOf). Undefined
|
|
10
|
+
* (a target the pins do not list) refuses the binary: no host Codex would run is unchecked. `null` leaves the host
|
|
11
|
+
* unchecked, for a caller that names its own pins and runs no code-mode model. */
|
|
12
|
+
hostSha256?: string | null;
|
|
9
13
|
}
|
|
10
14
|
/** The pins for this platform's binary. */
|
|
11
15
|
export declare function codexPins(target?: {
|
|
12
16
|
target: string;
|
|
13
17
|
pkg: string;
|
|
14
18
|
} | undefined): CodexPins;
|
|
19
|
+
/** The code-mode host Codex at `codex` runs, as Codex finds it (codex-rs install-context, code_mode_host_program), from
|
|
20
|
+
* its own executable's real path: in its package's layout (a codex-package.json in the folder above its own), the
|
|
21
|
+
* package's `codex-resources/codex-code-mode-host` when that is a file; else, and with no codex-package.json, the
|
|
22
|
+
* `codex-code-mode-host` beside Codex. */
|
|
23
|
+
export declare function codeModeHostOf(codex: string): string;
|
|
15
24
|
/**
|
|
16
25
|
* The binary at `found.path` checked against `pins`, in order: the platform package's version, the binary's sha256,
|
|
17
|
-
*
|
|
26
|
+
* the sha256 of each code-mode host it could run (codeModeHostOf, from its real path; none pinned for the platform is a
|
|
27
|
+
* refusal), then the version it reports. Returns the path, or the typed error (not thrown) naming the pin, what was expected and
|
|
18
28
|
* what was found. No path, or a binary that cannot be read or run, is `CodexNotInstalled`. The path is made absolute
|
|
19
29
|
* first, from this process's working directory, and that is the one checked and returned: a session starts the binary
|
|
20
30
|
* from its own directory, where a relative `CODEX_BIN` names nothing. The sha256 is read a chunk at a time, never the
|
|
21
|
-
* whole binary in memory, and a check that passed holds for this process while the binary
|
|
22
|
-
* (the kernel's checkedOnce): a host that checks it for each model it resolves, and a run's process that makes its
|
|
31
|
+
* whole binary in memory, and a check that passed holds for this process while the binary and each code-mode host stay
|
|
32
|
+
* the same files, unchanged (the kernel's checkedOnce, keyed by the hosts too): a host that checks it for each model it resolves, and a run's process that makes its
|
|
23
33
|
* adapter, check it once. Its reads hold the event loop: a host checks with verifyCodexBinaryAsync first.
|
|
24
34
|
*/
|
|
25
35
|
export declare function verifyCodexBinary(found: {
|
package/dist/verify.js
CHANGED
|
@@ -1,33 +1,87 @@
|
|
|
1
1
|
// The installed Codex checked against the pins (src/versions.ts) before anything runs, with the typed errors a host maps
|
|
2
2
|
// to a run's failure line. Written for AgentRun.
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { resolve } from "node:path";
|
|
3
|
+
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { env } from "node:process";
|
|
6
6
|
import { checkedOnce, checkedOnceAsync } from "@parcha/agentrun-kernel/host";
|
|
7
7
|
import { codexTarget, findCodex } from "./binary.js";
|
|
8
|
-
import { CODEX_BINARY_SHA256, CODEX_VERSION, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
|
|
8
|
+
import { CODE_MODE_HOST_SHA256, CODEX_BINARY_SHA256, CODEX_VERSION, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
|
|
9
9
|
/** The pins for this platform's binary. */
|
|
10
10
|
export function codexPins(target = codexTarget()) {
|
|
11
|
-
return { version: CODEX_VERSION, sha256: target ? CODEX_BINARY_SHA256[target.target] : undefined, packageVersion: target ? `${CODEX_VERSION}-${target.pkg}` : undefined };
|
|
11
|
+
return { version: CODEX_VERSION, sha256: target ? CODEX_BINARY_SHA256[target.target] : undefined, packageVersion: target ? `${CODEX_VERSION}-${target.pkg}` : undefined, hostSha256: target ? CODE_MODE_HOST_SHA256[target.target] : undefined };
|
|
12
|
+
}
|
|
13
|
+
const HOST = "codex-code-mode-host";
|
|
14
|
+
const isFile = (path) => {
|
|
15
|
+
try {
|
|
16
|
+
return statSync(path).isFile();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/** The folder Codex at `codex` runs from: its real path's, as Codex reads its own executable (current_exe), so a link to
|
|
23
|
+
* Codex leads to the folder of the file it links to. */
|
|
24
|
+
const exeOf = (codex) => {
|
|
25
|
+
try {
|
|
26
|
+
return realpathSync(codex);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return codex;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/** The code-mode host Codex at `codex` runs, as Codex finds it (codex-rs install-context, code_mode_host_program), from
|
|
33
|
+
* its own executable's real path: in its package's layout (a codex-package.json in the folder above its own), the
|
|
34
|
+
* package's `codex-resources/codex-code-mode-host` when that is a file; else, and with no codex-package.json, the
|
|
35
|
+
* `codex-code-mode-host` beside Codex. */
|
|
36
|
+
export function codeModeHostOf(codex) {
|
|
37
|
+
const exe = exeOf(codex);
|
|
38
|
+
const pkg = dirname(dirname(exe));
|
|
39
|
+
const resources = join(pkg, "codex-resources", HOST);
|
|
40
|
+
return isFile(join(pkg, "codex-package.json")) && isFile(resources) ? resources : join(dirname(exe), HOST);
|
|
41
|
+
}
|
|
42
|
+
/** Every code-mode host by Codex at `codex` that is there: the one it runs (codeModeHostOf) first, then the other place
|
|
43
|
+
* it could look, so a host there is held to the pin too and no reading of Codex's rule leaves one unchecked. */
|
|
44
|
+
function codeModeHostsOf(codex) {
|
|
45
|
+
const runs = codeModeHostOf(codex);
|
|
46
|
+
const exe = exeOf(codex);
|
|
47
|
+
const others = [join(dirname(exe), HOST), join(dirname(dirname(exe)), "codex-resources", HOST)].filter((each) => each !== runs && isFile(each));
|
|
48
|
+
return [runs, ...others];
|
|
49
|
+
}
|
|
50
|
+
/** What the check of the binary at `path` against `pins` is kept by, besides the binary itself: the pins, and each
|
|
51
|
+
* code-mode host as the file it is now, so a host changed or swapped after a check that passed is checked again. */
|
|
52
|
+
function checkKey(path, pins) {
|
|
53
|
+
if (!pins.hostSha256)
|
|
54
|
+
return JSON.stringify(pins);
|
|
55
|
+
const hosts = codeModeHostsOf(resolve(path)).map((host) => {
|
|
56
|
+
try {
|
|
57
|
+
const st = statSync(host, { bigint: true });
|
|
58
|
+
return [host, st.dev, st.ino, st.size, st.mtimeNs, st.ctimeNs].join(":");
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return `${host}:none`;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return JSON.stringify({ pins, hosts });
|
|
12
65
|
}
|
|
13
66
|
/**
|
|
14
67
|
* The binary at `found.path` checked against `pins`, in order: the platform package's version, the binary's sha256,
|
|
15
|
-
*
|
|
68
|
+
* the sha256 of each code-mode host it could run (codeModeHostOf, from its real path; none pinned for the platform is a
|
|
69
|
+
* refusal), then the version it reports. Returns the path, or the typed error (not thrown) naming the pin, what was expected and
|
|
16
70
|
* what was found. No path, or a binary that cannot be read or run, is `CodexNotInstalled`. The path is made absolute
|
|
17
71
|
* first, from this process's working directory, and that is the one checked and returned: a session starts the binary
|
|
18
72
|
* from its own directory, where a relative `CODEX_BIN` names nothing. The sha256 is read a chunk at a time, never the
|
|
19
|
-
* whole binary in memory, and a check that passed holds for this process while the binary
|
|
20
|
-
* (the kernel's checkedOnce): a host that checks it for each model it resolves, and a run's process that makes its
|
|
73
|
+
* whole binary in memory, and a check that passed holds for this process while the binary and each code-mode host stay
|
|
74
|
+
* the same files, unchanged (the kernel's checkedOnce, keyed by the hosts too): a host that checks it for each model it resolves, and a run's process that makes its
|
|
21
75
|
* adapter, check it once. Its reads hold the event loop: a host checks with verifyCodexBinaryAsync first.
|
|
22
76
|
*/
|
|
23
77
|
export function verifyCodexBinary(found, pins = codexPins()) {
|
|
24
78
|
const at = located(found, pins);
|
|
25
|
-
return at instanceof Error ? at : checkedOnce(at.path,
|
|
79
|
+
return at instanceof Error ? at : checkedOnce(at.path, checkKey(at.path, pins), () => checkBinary(at.path, pins), passed);
|
|
26
80
|
}
|
|
27
81
|
/** verifyCodexBinary without holding the event loop (the kernel's checkedOnceAsync), its pass kept for it too. */
|
|
28
82
|
export async function verifyCodexBinaryAsync(found, pins = codexPins()) {
|
|
29
83
|
const at = located(found, pins);
|
|
30
|
-
return at instanceof Error ? at : checkedOnceAsync(at.path,
|
|
84
|
+
return at instanceof Error ? at : checkedOnceAsync(at.path, checkKey(at.path, pins), () => checkBinary(at.path, pins), passed);
|
|
31
85
|
}
|
|
32
86
|
const passed = (result) => !(result instanceof Error);
|
|
33
87
|
/** The absolute path of `found`, there and of the pinned package's version; or why not. */
|
|
@@ -56,6 +110,22 @@ function* checkBinary(path, pins) {
|
|
|
56
110
|
if (sha256 !== pins.sha256)
|
|
57
111
|
return new CodexPinMismatch("binary_sha256", pins.sha256, sha256, path);
|
|
58
112
|
}
|
|
113
|
+
// No host pinned for this target: refused, since the host Codex would run is checked against nothing.
|
|
114
|
+
if (pins.hostSha256 === undefined)
|
|
115
|
+
return new CodexPinMismatch("code_mode_host_sha256", "a pinned sha256", "unpinned on this platform", codeModeHostOf(path));
|
|
116
|
+
if (pins.hostSha256 !== null) {
|
|
117
|
+
for (const host of codeModeHostsOf(path)) {
|
|
118
|
+
let sha256;
|
|
119
|
+
try {
|
|
120
|
+
sha256 = yield { kind: "sha256", path: host };
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
return new CodexNotInstalled(`its code-mode host ${host} could not be read: ${String(error?.message ?? error).slice(0, 120)}`);
|
|
124
|
+
}
|
|
125
|
+
if (sha256 !== pins.hostSha256)
|
|
126
|
+
return new CodexPinMismatch("code_mode_host_sha256", pins.hostSha256, sha256, host);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
59
129
|
let reported;
|
|
60
130
|
try {
|
|
61
131
|
reported = (yield { kind: "run", path, args: ["--version"], env: { PATH: env.PATH ?? "/usr/bin:/bin" }, timeoutMs: 10_000 }).trim();
|
package/dist/versions.d.ts
CHANGED
|
@@ -18,8 +18,13 @@ export declare const CODEX_NPM_INTEGRITY: Readonly<Record<string, string>>;
|
|
|
18
18
|
/** The sha256 of the pinned native binary (`vendor/<target>/bin/codex` in the platform package), per target, read from
|
|
19
19
|
* the published packages those integrities name. A binary for a target listed here runs only if it matches. */
|
|
20
20
|
export declare const CODEX_BINARY_SHA256: Readonly<Record<string, string>>;
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/** The sha256 of the pinned code-mode host (`vendor/<target>/bin/codex-code-mode-host` in the platform package), per
|
|
22
|
+
* target, read from the same published packages: the binary Codex runs a code-mode model's `exec` in (config.ts
|
|
23
|
+
* code_mode_host). It runs only if it matches, wherever Codex finds it (verify.ts codeModeHostOf). */
|
|
24
|
+
export declare const CODE_MODE_HOST_SHA256: Readonly<Record<string, string>>;
|
|
25
|
+
/** Which pin a mismatch is about: the binary's sha256, the version it reports, the platform package's version, or the
|
|
26
|
+
* code-mode host's sha256. */
|
|
27
|
+
export type CodexPin = "binary_sha256" | "version" | "package_version" | "code_mode_host_sha256";
|
|
23
28
|
/** The installed Codex is not the build this adapter is pinned to and checked with: nothing runs. */
|
|
24
29
|
export declare class CodexPinMismatch extends Error {
|
|
25
30
|
readonly pin: CodexPin;
|
package/dist/versions.js
CHANGED
|
@@ -33,6 +33,15 @@ export const CODEX_BINARY_SHA256 = Object.freeze({
|
|
|
33
33
|
"x86_64-apple-darwin": "d7e19691e0c1945612475ee8ab32e59ead55472e976b5cea1682d827d34dbba1",
|
|
34
34
|
"aarch64-apple-darwin": "d8990e3ee7acfbc26f91265b12a1a83f0fee40d0e0f8f1f40a37d4ec21f499cf",
|
|
35
35
|
});
|
|
36
|
+
/** The sha256 of the pinned code-mode host (`vendor/<target>/bin/codex-code-mode-host` in the platform package), per
|
|
37
|
+
* target, read from the same published packages: the binary Codex runs a code-mode model's `exec` in (config.ts
|
|
38
|
+
* code_mode_host). It runs only if it matches, wherever Codex finds it (verify.ts codeModeHostOf). */
|
|
39
|
+
export const CODE_MODE_HOST_SHA256 = Object.freeze({
|
|
40
|
+
"x86_64-unknown-linux-musl": "8ee4f472e92ac226a189e98998633b2d07f989f208515750764db660369f2926",
|
|
41
|
+
"aarch64-unknown-linux-musl": "7d28b996b825b13ea058af67655b619a26a125d61d4fb2985694a9c4e77d2e21",
|
|
42
|
+
"x86_64-apple-darwin": "067f9c14f67b02bdb984d4fc4740da14cd397da7ee60b4506eb378921afe3e7d",
|
|
43
|
+
"aarch64-apple-darwin": "416721e33af8822041dc650793512b3e58d43e0be4f3a5c6187eb4dfaad3148a",
|
|
44
|
+
});
|
|
36
45
|
/** The installed Codex is not the build this adapter is pinned to and checked with: nothing runs. */
|
|
37
46
|
export class CodexPinMismatch extends Error {
|
|
38
47
|
pin;
|
|
@@ -41,7 +50,8 @@ export class CodexPinMismatch extends Error {
|
|
|
41
50
|
path;
|
|
42
51
|
code = "CODEX_PIN_MISMATCH";
|
|
43
52
|
constructor(pin, expected, found, path) {
|
|
44
|
-
|
|
53
|
+
const what = pin === "package_version" ? "platform package" : pin === "code_mode_host_sha256" ? "code-mode host" : "binary";
|
|
54
|
+
super(`agentrun-harness-codex: the Codex ${what}${path ? ` at ${path}` : ""} is not the pinned build: its ${pin === "code_mode_host_sha256" ? "sha256" : pin.replace("_", " ")} is ${found}, not ${expected}`);
|
|
45
55
|
this.pin = pin;
|
|
46
56
|
this.expected = expected;
|
|
47
57
|
this.found = found;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-harness-codex",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.81",
|
|
4
4
|
"description": "Codex as an AgentRun harness: a tool-less Codex app-server behind a loopback model proxy, durable in AgentRun's own store, with the host's tools as its only tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"test": "node --test --test-concurrency=8 'test/*.test.mjs'"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@parcha/agentrun-kernel": "0.1.0-beta.
|
|
47
|
+
"@parcha/agentrun-kernel": "0.1.0-beta.81"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@openai/codex": "0.164.0"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@openai/codex": "0.164.0",
|
|
59
|
-
"@parcha/agentrun-dsl": "0.1.0-beta.
|
|
59
|
+
"@parcha/agentrun-dsl": "0.1.0-beta.81"
|
|
60
60
|
},
|
|
61
61
|
"repository": {
|
|
62
62
|
"type": "git",
|