@parcha/agentrun-harness-codex 0.1.0-beta.36 → 0.1.0-beta.38
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 +50 -0
- package/README.md +9 -6
- package/dist/adapter.d.ts +7 -0
- package/dist/adapter.js +42 -21
- package/dist/code-mode.d.ts +37 -10
- package/dist/code-mode.js +99 -48
- package/dist/facts.js +4 -4
- package/dist/harness.js +1 -1
- package/dist/host/machine.d.ts +3 -4
- package/dist/host/machine.js +2 -12
- package/dist/host/policy.d.ts +5 -12
- package/dist/host/policy.js +75 -92
- package/dist/host/process.d.ts +12 -17
- package/dist/host/process.js +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/scripts.d.ts +13 -1
- package/dist/scripts.js +14 -1
- package/package.json +3 -3
- package/dist/mcp.d.ts +0 -15
- package/dist/mcp.js +0 -74
package/dist/code-mode.js
CHANGED
|
@@ -3,11 +3,14 @@ import { boundResult, openTurn, recoveryNote, recoverySystemNote, recoveryUserTu
|
|
|
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
5
|
import { summarizeRollout } from "./rollout.js";
|
|
6
|
-
import { callKey, completedNested, execRecoveryOutput, NESTED_CALL, outputTextOf, parkedKey, recoveryFacts, Scripts, settle, UNWATCHED } from "./scripts.js";
|
|
6
|
+
import { callKey, completedNested, execRecoveryOutput, NESTED_CALL, outputTextOf, parkedKey, recoveryFacts, Scripts, settle, UNWATCHED, waitResumedText } 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";
|
|
9
9
|
/** The stream that records the interrupted turns whose recovery note was injected: `{ since }`, once per interrupted turn. */
|
|
10
10
|
export const RECOVERY_NOTE_STREAM = "codex.recovery-note";
|
|
11
|
+
/** A yielded exec's nested call run on a resume (recoverItems), written before it runs: a later recovery of the same turn tells
|
|
12
|
+
* the model's `wait` its outcome from the session's record, never running it again. */
|
|
13
|
+
export const RESUMED_STREAM = "codex.nested-resumed";
|
|
11
14
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
12
15
|
/** Only a custom tool call named `exec` is code mode's: a host tool that happens to be called `exec` is a function call. */
|
|
13
16
|
const isExec = (d) => d.type === "custom_tool_call" && d.name === "exec";
|
|
@@ -27,13 +30,21 @@ function endedTurnSince(state) {
|
|
|
27
30
|
export const waitStoppedText = (cell) => `The session stopped while waiting on cell ${cell}; that cell's script was cut off, and nothing was run again. Check the actual state before relying on it.`;
|
|
28
31
|
/** What the log holds of one nested call: the session's record, the rollout's completion line, and what the turn's recovery note
|
|
29
32
|
* calls it (`told`, by call id). */
|
|
33
|
+
/** What a script's nested call of a tool with a value was sent (scriptAnswer's text), from the tool's stored answer: the rollout
|
|
34
|
+
* holds that text, not the words the store keeps, so recovery compares the two. None for a tool with no value. */
|
|
35
|
+
function sentOf(output) {
|
|
36
|
+
const kept = output;
|
|
37
|
+
if (kept === null || typeof kept !== "object" || kept.structured === undefined)
|
|
38
|
+
return {};
|
|
39
|
+
return { sent: JSON.stringify(withImageData(kept.structured, kept.images ?? [])) };
|
|
40
|
+
}
|
|
30
41
|
function factOf(state, rolled, tie, told = new Map()) {
|
|
31
42
|
const e = state.effects.get(toolKey(tie.callId));
|
|
32
43
|
const status = told.get(tie.callId);
|
|
33
44
|
return {
|
|
34
45
|
callId: tie.callId,
|
|
35
|
-
tool: e ? e.name.replace(/^tool\./, "") : (rolled.get(tie.callId)?.tool ?? "a tool"),
|
|
36
|
-
...(e ? { store: { status: e.status === "completed" ? "completed" : e.status === "failed" ? "failed" : "started", text: e.status === "failed" ? (e.error?.message ?? "") : outputTextOf(e.output), ...(e.error?.interrupted ? { interrupted: true } : {}) } } : {}),
|
|
46
|
+
tool: e ? e.name.replace(/^tool\./, "") : (rolled.get(tie.callId)?.tool ?? tie.tool ?? "a tool"),
|
|
47
|
+
...(e ? { store: { status: e.status === "completed" ? "completed" : e.status === "failed" ? "failed" : "started", text: e.status === "failed" ? (e.error?.message ?? "") : outputTextOf(e.output), ...(e.status === "completed" ? sentOf(e.output) : {}), ...(e.error?.interrupted ? { interrupted: true } : {}) } } : {}),
|
|
37
48
|
...(rolled.has(tie.callId) ? { rollout: rolled.get(tie.callId) } : {}),
|
|
38
49
|
...(status ? { told: status } : {}),
|
|
39
50
|
...(state.effects.get(parkedKey(tie.callId))?.status === "completed" ? { parked: true } : {}),
|
|
@@ -48,9 +59,25 @@ export function imagesNoted(output) {
|
|
|
48
59
|
return undefined;
|
|
49
60
|
return `${outputTextOf(output)}\n\nIt also returned ${count} image${count === 1 ? "" : "s"} (not shown again after the interruption).`;
|
|
50
61
|
}
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
53
|
-
|
|
62
|
+
/** `value` with `images`' data put back, in order, into its image objects (`{ type: "image", mimeType }` with no data,
|
|
63
|
+
* as a computer tool's value leaves them): the value whole, as serve's own script isolate gives a script. */
|
|
64
|
+
export function withImageData(value, images) {
|
|
65
|
+
let next = 0;
|
|
66
|
+
const fill = (part) => {
|
|
67
|
+
if (Array.isArray(part))
|
|
68
|
+
return part.map(fill);
|
|
69
|
+
if (part === null || typeof part !== "object")
|
|
70
|
+
return part;
|
|
71
|
+
const record = part;
|
|
72
|
+
if (record.type === "image" && record.data === undefined && next < images.length)
|
|
73
|
+
return { ...record, data: images[next++].data };
|
|
74
|
+
return Object.fromEntries(Object.entries(record).map(([key, entry]) => [key, fill(entry)]));
|
|
75
|
+
};
|
|
76
|
+
return fill(value);
|
|
77
|
+
}
|
|
78
|
+
/** A nested call's answer from a tool with no value: its items, then a line saying how many images the tool returned,
|
|
79
|
+
* which are not sent (Codex gives a script an image as its data: URL in the result's text, so a script that prints the
|
|
80
|
+
* result would send the model the base64 as words); an answer of any other shape, or no images, as it is. */
|
|
54
81
|
export function withImagesHeld(answer, images) {
|
|
55
82
|
const items = answer?.contentItems;
|
|
56
83
|
if (!images?.length || !Array.isArray(items))
|
|
@@ -58,6 +85,16 @@ export function withImagesHeld(answer, images) {
|
|
|
58
85
|
const count = images.length;
|
|
59
86
|
return { ...answer, contentItems: [...items, { type: "inputText", text: `${count} image${count === 1 ? "" : "s"} it returned ${count === 1 ? "was" : "were"} not sent: in code mode a tool's image reaches the script only as text.` }] };
|
|
60
87
|
}
|
|
88
|
+
/** A code-mode script's nested call's answer. A tool with a value (a computer tool's) answers the value as JSON text,
|
|
89
|
+
* its images' data back in it, so the script reads it with JSON.parse and holds each image whole, to compute on or
|
|
90
|
+
* pass on; any other tool answers its words and a line on its images, which are not sent (`withImagesHeld`). A failed
|
|
91
|
+
* call's answer, or one of any other shape, as it is. */
|
|
92
|
+
export function scriptAnswer(answer, extras) {
|
|
93
|
+
const shaped = answer;
|
|
94
|
+
if (extras?.structured === undefined || !Array.isArray(shaped?.contentItems) || shaped.success === false)
|
|
95
|
+
return withImagesHeld(answer, extras?.images);
|
|
96
|
+
return { ...shaped, contentItems: [{ type: "inputText", text: JSON.stringify(withImageData(extras.structured, extras.images ?? [])) }] };
|
|
97
|
+
}
|
|
61
98
|
/** A dynamic tool call's answer with `images` after its items, each `{ type: "inputImage", imageUrl }` with a data: URL
|
|
62
99
|
* (Codex 0.164's DynamicToolCallOutputContentItem); an answer of any other shape, or no images, as it is. */
|
|
63
100
|
export function withImages(answer, images) {
|
|
@@ -78,28 +115,6 @@ export function codeMode(deps) {
|
|
|
78
115
|
machine.onRolloutLine?.((line) => scripts.note(line));
|
|
79
116
|
/** The script a nested call is tied to now, as the log and the proxy's latest answer have it. */
|
|
80
117
|
const tieNow = () => scripts.tie(machine.announcedExec?.(), (id) => logged.has(id));
|
|
81
|
-
/** A call Codex runs without the harness (a remote MCP server's tool, mcp.ts): the barrier it passes before its intent (its
|
|
82
|
-
* own line in the log, as the harness's barrier has it; a script's nested call, its script's, tied to it by `admit`), and
|
|
83
|
-
* after a recovery the log's answer for a `never` call the interrupted turn completed, re-issued under a new id. */
|
|
84
|
-
machine.onCalls?.({ recovered: (tool, args) => answeredAgain(tool, args), barrier: async (callId) => {
|
|
85
|
-
if (NESTED_CALL.test(callId)) {
|
|
86
|
-
if (!(await admit(callId)))
|
|
87
|
-
return false;
|
|
88
|
-
const exec = execOf.get(callId);
|
|
89
|
-
journal.append(NESTED_STREAM, { callId, exec: exec === undefined || exec === UNWATCHED ? null : exec, since: openTurn(ctx.state())?.since ?? -1 });
|
|
90
|
-
await journal.flush();
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
for (let i = 0; i < deps.tries; i++) {
|
|
94
|
-
if (i)
|
|
95
|
-
await sleep(50 * 2 ** (i - 1));
|
|
96
|
-
await synced();
|
|
97
|
-
if (logged.has(callId))
|
|
98
|
-
return journal.flush().then(() => true);
|
|
99
|
-
}
|
|
100
|
-
deps.log("codex: declined a call whose function_call line is not in the log", { callId });
|
|
101
|
-
return false;
|
|
102
|
-
} });
|
|
103
118
|
/** A `never` nested call: wait for its script's line, as the harness's barrier waits for a call's own. True: admitted. */
|
|
104
119
|
const admit = async (callId) => {
|
|
105
120
|
for (let i = 0;; i++) {
|
|
@@ -141,7 +156,7 @@ export function codeMode(deps) {
|
|
|
141
156
|
if (settled.kind !== "completed")
|
|
142
157
|
continue;
|
|
143
158
|
const key = callKey(fact.tool, e.input);
|
|
144
|
-
recovered.set(key, [...(recovered.get(key) ?? []), { tool: fact.tool, text: settled.text }]);
|
|
159
|
+
recovered.set(key, [...(recovered.get(key) ?? []), { tool: fact.tool, text: settled.text, ...(fact.store?.sent !== undefined ? { sent: fact.store.sent } : {}) }]);
|
|
145
160
|
}
|
|
146
161
|
};
|
|
147
162
|
/** A `never` call the log holds a completed outcome for, re-issued after a recovery: its answer from the log, taken once. Held
|
|
@@ -151,6 +166,10 @@ export function codeMode(deps) {
|
|
|
151
166
|
if (!again)
|
|
152
167
|
return undefined;
|
|
153
168
|
deps.log("codex: answered a never call from the log: it completed before the interruption", { ...(callId ? { callId } : {}), tool: again.tool });
|
|
169
|
+
// A script's call of a tool with a value gets that value's JSON again, as the first call did (scriptAnswer): the script
|
|
170
|
+
// parses it, so no words go before it.
|
|
171
|
+
if (callId !== undefined && NESTED_CALL.test(callId) && again.sent !== undefined)
|
|
172
|
+
return again.sent;
|
|
154
173
|
return boundResult(`Recorded earlier in this turn, not run again: ${again.text}`).text;
|
|
155
174
|
}
|
|
156
175
|
/** The cell a dangling call waited on, when it is code mode's `wait` (a function call named `wait` with a `cell_id`, and no host tool of
|
|
@@ -171,12 +190,6 @@ export function codeMode(deps) {
|
|
|
171
190
|
/** The app-server's request handler, with a code-mode host tool call handled before the harness's own. */
|
|
172
191
|
request(next) {
|
|
173
192
|
return async (req) => {
|
|
174
|
-
// Codex asking to run a remote MCP server's tool, should it ask (approve mode asks nothing): the session's only MCP
|
|
175
|
-
// servers are its own, at its model proxy, which serves only the granted tools and records each call before it
|
|
176
|
-
// sends it (mcp.ts). Any other elicitation is the harness's to decline.
|
|
177
|
-
const meta = req.params?._meta;
|
|
178
|
-
if (req.method === "mcpServer/elicitation/request" && meta?.codex_approval_kind === "mcp_tool_call")
|
|
179
|
-
return { action: "accept", content: {}, _meta: null };
|
|
180
193
|
if (req.method === "item/tool/call") {
|
|
181
194
|
const p = req.params ?? {};
|
|
182
195
|
const callId = String(p.callId ?? "");
|
|
@@ -194,23 +207,23 @@ export function codeMode(deps) {
|
|
|
194
207
|
if (exec)
|
|
195
208
|
execOf.set(callId, exec);
|
|
196
209
|
// Never the unwatched-answer marker: a call tied to no known exec is journaled with none.
|
|
197
|
-
journal.append(NESTED_STREAM, { callId, exec: exec === undefined || exec === UNWATCHED ? null : exec, since: openTurn(ctx.state())?.since ?? -1 });
|
|
210
|
+
journal.append(NESTED_STREAM, { callId, exec: exec === undefined || exec === UNWATCHED ? null : exec, since: openTurn(ctx.state())?.since ?? -1, tool: String(p.tool), args: p.arguments ?? {} });
|
|
198
211
|
}
|
|
199
212
|
// The harness answers with the result's text; its images follow as `inputImage` items, which Codex 0.164's
|
|
200
213
|
// dynamic tool output takes (DynamicToolCallResponse.contentItems, its app-server schema), each a data: URL.
|
|
201
|
-
// The call runs first (`next`): its images are kept by the bridge as it answers, and taken after,
|
|
202
|
-
// the answer was built, so a call whose answer throws leaves none in the bridge for the session's life.
|
|
203
|
-
let
|
|
214
|
+
// The call runs first (`next`): its images and value are kept by the bridge as it answers, and taken after,
|
|
215
|
+
// whether or not the answer was built, so a call whose answer throws leaves none in the bridge for the session's life.
|
|
216
|
+
let extras;
|
|
204
217
|
let answer;
|
|
205
218
|
try {
|
|
206
219
|
answer = await next(req);
|
|
207
220
|
}
|
|
208
221
|
finally {
|
|
209
|
-
|
|
222
|
+
extras = deps.bridge.take?.(callId);
|
|
210
223
|
}
|
|
211
|
-
// A script's nested call
|
|
212
|
-
//
|
|
213
|
-
return NESTED_CALL.test(callId) ?
|
|
224
|
+
// A script's nested call gets the tool's value, images and all, to compute on (scriptAnswer); the model's own
|
|
225
|
+
// call gets the words and the images to look at.
|
|
226
|
+
return NESTED_CALL.test(callId) ? scriptAnswer(answer, extras) : withImages(answer, extras?.images);
|
|
214
227
|
}
|
|
215
228
|
return next(req);
|
|
216
229
|
};
|
|
@@ -219,16 +232,53 @@ export function codeMode(deps) {
|
|
|
219
232
|
* any other call keeps its generic output, as an item of its own kind, and code mode's `wait` is told that it had started. `since`: the
|
|
220
233
|
* turn the dangling calls ran in: the interrupted one a recovery note resumes, or with none, the turn that ended last. Every output is then
|
|
221
234
|
* held to the host's bound as the tool bridge holds a call's result (`boundResult`): these come from the log, not through the bridge, and
|
|
222
|
-
* both repairs (with a recovery note and without) inject what this leaves.
|
|
223
|
-
|
|
224
|
-
|
|
235
|
+
* both repairs (with a recovery note and without) inject what this leaves. `resume`: the open turn a recovery note resumes, whose
|
|
236
|
+
* parked nested calls run now; the repair of an ended turn (repairUnnoted) only tells, and runs nothing. */
|
|
237
|
+
async recoverItems(items, dangling, lines, since, resume = false) {
|
|
225
238
|
const ties = (await journal.read(NESTED_STREAM)).map((r) => r.data);
|
|
226
239
|
const execs = dangling.filter(isExec).map((d) => d.callId);
|
|
227
240
|
const rolled = completedNested(lines);
|
|
241
|
+
// A nested call of a cut-off exec that never reached its intent and that Codex was never answered (its script went with
|
|
242
|
+
// the session: the host's gate parked it for a person's approval, or a crash came before its intent) runs now, through
|
|
243
|
+
// the bridge under its own id, the gate first, so the person's answer on it holds, as a dangling call of the model's own
|
|
244
|
+
// does (resumeUnstartedCalls): its outcome is the exec's output, and nothing runs it again. A gate that parks again
|
|
245
|
+
// rejects out of here, nothing written. Only on the resume of the open turn: an ended turn's repair runs nothing, so a call a
|
|
246
|
+
// person may never have answered does not run on a later turn. A script whose exec had yielded ("Script running") made
|
|
247
|
+
// its call in this turn while the model waited on its cell: that call runs too, and the dangling `wait` tells its
|
|
248
|
+
// outcome (with none dangling there is nowhere to tell it, and it does not run).
|
|
249
|
+
const resumed = new Map();
|
|
250
|
+
const cut = new Set(execs);
|
|
251
|
+
const carrier = dangling.findIndex((c) => !isExec(c) && waitedCell(c) !== undefined);
|
|
252
|
+
const yieldedTies = [];
|
|
253
|
+
const ranBefore = resume ? new Set((await journal.read(RESUMED_STREAM)).map((r) => r.data.callId)) : new Set();
|
|
254
|
+
for (const tie of resume ? ties : []) {
|
|
255
|
+
const cutOff = tie.exec === null ? tie.since === since && execs.length > 0 : cut.has(tie.exec);
|
|
256
|
+
const yielded = !cutOff && carrier >= 0 && tie.since === since;
|
|
257
|
+
const done = ctx.state().effects.get(toolKey(tie.callId));
|
|
258
|
+
// Run on an earlier recovery of this turn that stopped before the wait was answered: told from its record.
|
|
259
|
+
if (yielded && ranBefore.has(tie.callId) && (done?.status === "completed" || done?.status === "failed") && !rolled.has(tie.callId)) {
|
|
260
|
+
resumed.set(tie.callId, { text: done.status === "failed" ? (done.error?.message ?? "") : outputTextOf(done.output), isError: done.status === "failed", ran: true });
|
|
261
|
+
yieldedTies.push(tie);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if ((!cutOff && !yielded) || tie.tool === undefined || done || rolled.has(tie.callId))
|
|
265
|
+
continue;
|
|
266
|
+
if (!deps.bridge.call || !deps.bridge.get(tie.tool))
|
|
267
|
+
continue;
|
|
268
|
+
if (yielded) {
|
|
269
|
+
journal.append(RESUMED_STREAM, { callId: tie.callId });
|
|
270
|
+
await journal.flush();
|
|
271
|
+
}
|
|
272
|
+
const result = await deps.bridge.call(tie.tool, tie.args ?? {}, tie.callId);
|
|
273
|
+
resumed.set(tie.callId, { text: result.text, isError: result.isError, ran: ctx.state().effects.has(toolKey(tie.callId)) });
|
|
274
|
+
if (yielded)
|
|
275
|
+
yieldedTies.push(tie);
|
|
276
|
+
}
|
|
277
|
+
const state = ctx.state();
|
|
228
278
|
// Each cut-off exec lists its own calls. A call whose script could not be told when it ran (an answer the proxy did not see to its end)
|
|
229
279
|
// is listed once, apart, in the LAST cut-off exec's output, if it ran in this interrupted turn.
|
|
230
280
|
const told = new Map((recoveryNote(state)?.calls ?? []).map((c) => [c.callId, c.status]));
|
|
231
|
-
const listed = recoveryFacts(execs, ties, since, (tie) => factOf(state, rolled, tie, told));
|
|
281
|
+
const listed = recoveryFacts(execs, ties, since, (tie) => ({ ...factOf(state, rolled, tie, told), ...(resumed.has(tie.callId) ? { resumed: resumed.get(tie.callId) } : {}) }));
|
|
232
282
|
dangling.forEach((c, i) => {
|
|
233
283
|
if (!isExec(c)) {
|
|
234
284
|
// Code mode's `wait` on a cell had started: the generic answer, that the call never started, would be false.
|
|
@@ -238,7 +288,8 @@ export function codeMode(deps) {
|
|
|
238
288
|
// as JSON, so the model would read their base64 as text. Its text and a line on them instead; they are not sent.
|
|
239
289
|
const done = state.effects.get(toolKey(c.callId));
|
|
240
290
|
const pictured = cell === undefined && done?.status === "completed" ? imagesNoted(done.output) : undefined;
|
|
241
|
-
|
|
291
|
+
const waited = cell === undefined ? undefined : i === carrier && yieldedTies.length > 0 ? waitResumedText(cell, yieldedTies.map((tie) => ({ ...factOf(state, rolled, tie, told), resumed: resumed.get(tie.callId) }))) : waitStoppedText(cell);
|
|
292
|
+
items[i] = withOutputKind(waited !== undefined ? { ...item, output: waited } : pictured !== undefined ? { ...item, output: pictured } : item, c);
|
|
242
293
|
return;
|
|
243
294
|
}
|
|
244
295
|
const { own, loose } = listed.get(c.callId);
|
package/dist/facts.js
CHANGED
|
@@ -14,16 +14,16 @@ export const facts = Object.freeze({
|
|
|
14
14
|
// One run's memory, measured with the server's (serve's host.ts): Codex's app-server beside the run's process.
|
|
15
15
|
runMib: 192,
|
|
16
16
|
// OpenAI's reasoning efforts stop at xhigh.
|
|
17
|
-
// Its own MCP client binds the session's remote MCP servers.
|
|
18
|
-
mcp: true,
|
|
19
17
|
thinking: Object.freeze(["low", "medium", "high", "xhigh"]),
|
|
20
18
|
// Codex's own live search, booked per call.
|
|
21
19
|
webSearch: "live",
|
|
22
20
|
ownModel: false,
|
|
21
|
+
// Its own code mode runs the model's scripts, each nested call one of the host's tools through its bridge.
|
|
22
|
+
ownCodemode: true,
|
|
23
23
|
normalizeModel: (model) => model,
|
|
24
24
|
install: Object.freeze({ npmLine: CODEX_INSTALL, spec: `@openai/codex@${CODEX_VERSION}`, codes: Object.freeze({ install: "CODEX_NOT_INSTALLED", pins: "CODEX_PIN_MISMATCH" }) }),
|
|
25
|
-
//
|
|
26
|
-
//
|
|
25
|
+
// The shapes Codex drops or retypes in a host tool's schema (a run's MCP tool's among them), measured on the pinned
|
|
26
|
+
// binary (schema.ts).
|
|
27
27
|
schemaProblems: codexSchemaProblems,
|
|
28
28
|
// Codex's own tools, each the host's table tool it is.
|
|
29
29
|
nativeTools: Object.freeze({ web_search: "web_search", shell: "bash" }),
|
package/dist/harness.js
CHANGED
|
@@ -847,7 +847,7 @@ export function codexHarness(options = {}) {
|
|
|
847
847
|
if (resume && summary.dangling.length > 0) {
|
|
848
848
|
// Calls the rollout has no output for get theirs from the log.
|
|
849
849
|
const items = summary.dangling.map((c) => ({ type: 'function_call_output', call_id: c.callId, output: repairOutput(ctx.state(), c) }));
|
|
850
|
-
await code.recoverItems(items, summary.dangling, lines, note.turn.since);
|
|
850
|
+
await code.recoverItems(items, summary.dangling, lines, note.turn.since, true);
|
|
851
851
|
await guard(rpc.request('thread/inject_items', { threadId, items }));
|
|
852
852
|
await guard(synced());
|
|
853
853
|
}
|
package/dist/host/machine.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AcquireMachine, CacheDir, SessionProcess } from "./process.js";
|
|
2
|
-
import type { SessionMcp } from "@parcha/agentrun-kernel";
|
|
3
2
|
import { type ModelProxyHooks, type ModelProxyOptions, type ParentWatch } from "@parcha/agentrun-kernel/host";
|
|
4
3
|
import { type CodexCommand } from "../catalog.js";
|
|
5
4
|
/** The variables a child takes from this process, when they are set. */
|
|
@@ -25,6 +24,9 @@ export interface LocalMachineOptions {
|
|
|
25
24
|
/** Codex's own web search, live: Codex's config says `web_search = "live"` (`configure`), and the proxy admits the tool
|
|
26
25
|
* Codex then sends and adds each search to the price. Default off. */
|
|
27
26
|
webSearch?: "live";
|
|
27
|
+
/** With `webSearch`: whether the host lets the session search now, asked before each request that offers it
|
|
28
|
+
* (CodexPolicyOptions.searchAllowed). */
|
|
29
|
+
searchAllowed?: () => Promise<boolean>;
|
|
28
30
|
/** The model proxy: the runner's hooks, the provider's price, and the session's tools and limits; its route comes
|
|
29
31
|
* from the harness. */
|
|
30
32
|
proxy: {
|
|
@@ -35,9 +37,6 @@ export interface LocalMachineOptions {
|
|
|
35
37
|
log?: ModelProxyOptions["log"];
|
|
36
38
|
fetch?: typeof fetch;
|
|
37
39
|
};
|
|
38
|
-
/** The session's remote MCP servers (mcp.ts): each served at the proxy's `/mcp/<server>`, written in Codex's config,
|
|
39
|
-
* and each call recorded in the drive's session before it is sent. */
|
|
40
|
-
mcp?: SessionMcp;
|
|
41
40
|
/** For tests: the process environment the allowlist reads. Default `process.env`. */
|
|
42
41
|
env?: Readonly<Record<string, string | undefined>>;
|
|
43
42
|
/** Files one of the session's private directories holds at the start of every drive: written when the machine is
|
package/dist/host/machine.js
CHANGED
|
@@ -23,7 +23,6 @@ import { brandMachine } from "./process.js";
|
|
|
23
23
|
import { parentWatched, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
24
24
|
import { codexPolicy, withWebSearches } from "./policy.js";
|
|
25
25
|
import { UNWATCHED } from "../scripts.js";
|
|
26
|
-
import { CODEX_MCP_CLIENT, mcpServersConfig, recorded } from "../mcp.js";
|
|
27
26
|
import { MODEL_CATALOG_FILE, patchlessCatalog } from "../catalog.js";
|
|
28
27
|
/** The variables a child takes from this process, when they are set. */
|
|
29
28
|
export const INHERITED_ENV = Object.freeze(["PATH", "LANG", "TZ"]);
|
|
@@ -208,16 +207,14 @@ export function localMachine(options) {
|
|
|
208
207
|
let open = 0;
|
|
209
208
|
const rolloutListeners = [];
|
|
210
209
|
const cutListeners = [];
|
|
211
|
-
let calls;
|
|
212
210
|
const search = options.webSearch === "live";
|
|
213
211
|
const price = options.proxy.price && search ? withWebSearches(options.proxy.price) : options.proxy.price;
|
|
214
212
|
const proxy = await startModelProxy({
|
|
215
213
|
policy: codexPolicy({
|
|
216
214
|
model: route.models.model,
|
|
217
215
|
tools: options.proxy.tools,
|
|
218
|
-
...(options.mcp ? { mcpTools: options.mcp.servers.flatMap((server) => server.tools.map((tool) => `mcp__${server.name}__${tool.name}`)) } : {}),
|
|
219
216
|
...(options.proxy.maxOutputTokens ? { maxOutputTokens: options.proxy.maxOutputTokens } : {}),
|
|
220
|
-
...(search ? { webSearch: "live" } : {}),
|
|
217
|
+
...(search ? { webSearch: "live", ...(options.searchAllowed ? { searchAllowed: options.searchAllowed } : {}) } : {}),
|
|
221
218
|
announce: {
|
|
222
219
|
// The cost is liveness, not safety: after an overlap a never call is declined until the next single answer, which the model's
|
|
223
220
|
// next wait or exec gives.
|
|
@@ -237,8 +234,6 @@ export function localMachine(options) {
|
|
|
237
234
|
origin: route.target,
|
|
238
235
|
credential: async () => (await route.credential()) ?? "",
|
|
239
236
|
...(price ? { price } : {}),
|
|
240
|
-
// The kernel's proxy mounts the session's MCP door for Codex's own client; each call is recorded first (recorded).
|
|
241
|
-
...(options.mcp ? { mcp: { session: recorded(options.mcp, ctx, () => calls), client: CODEX_MCP_CLIENT } } : {}),
|
|
242
237
|
...(options.proxy.log ? { log: options.proxy.log } : {}),
|
|
243
238
|
...(options.proxy.fetch ? { fetch: options.proxy.fetch } : {}),
|
|
244
239
|
// The provider stopped the turn's answer on its content filter: no retry of it can pass, so the turn ends at once.
|
|
@@ -264,15 +259,10 @@ export function localMachine(options) {
|
|
|
264
259
|
onRolloutLine: (listener) => void rolloutListeners.push(listener),
|
|
265
260
|
onCut: (listener) => void cutListeners.push(listener),
|
|
266
261
|
openTurn: () => proxy.openTurn(),
|
|
267
|
-
|
|
268
|
-
...(search || options.mcp || catalog ? {
|
|
262
|
+
...(search || catalog ? {
|
|
269
263
|
configure: (config) => {
|
|
270
264
|
if (search)
|
|
271
265
|
config.web_search = "live";
|
|
272
|
-
// Codex's bearer for the proxy's /mcp/<server> is the key it sends to the proxy's model route.
|
|
273
|
-
const keyEnv = (config.model_providers?.gateway?.env_key ?? "");
|
|
274
|
-
if (options.mcp)
|
|
275
|
-
config.mcp_servers = mcpServersConfig(options.mcp, proxy.url, keyEnv);
|
|
276
266
|
// Only with the built-ins off: with them on, apply_patch runs through the shell.
|
|
277
267
|
const features = config.features;
|
|
278
268
|
if (catalog && features?.shell_tool !== true && features?.unified_exec !== true)
|
package/dist/host/policy.d.ts
CHANGED
|
@@ -15,14 +15,16 @@ export interface CodexPolicyOptions {
|
|
|
15
15
|
model: string;
|
|
16
16
|
/** The session's own tool names: every other tool definition is dropped. */
|
|
17
17
|
tools: readonly string[];
|
|
18
|
-
/** The granted tools of the session's remote MCP servers, `mcp__<server>__<tool>`: the pinned CLI offers a server's tools
|
|
19
|
-
* in a namespace named `mcp__<server>`, each by the server's own name. */
|
|
20
|
-
mcpTools?: readonly string[];
|
|
21
18
|
/** The most output tokens one request may ask for. Default 32 000. */
|
|
22
19
|
maxOutputTokens?: number;
|
|
23
20
|
/** Codex's own web search, live: the live search tool the pinned CLI sends passes, and a `tool_choice` naming it. Each
|
|
24
21
|
* response's usage then carries the searches it ran (`webSearches`), which `withWebSearches` prices. Default off. */
|
|
25
22
|
webSearch?: "live";
|
|
23
|
+
/** With `webSearch`: whether the host lets the session search now (its web_search setting, SessionIO.permission), asked
|
|
24
|
+
* before each request that offers the live search. The provider runs a search inside the request, where no gate sees
|
|
25
|
+
* it, so a request sent while this is false (or throws) offers no search, as a session without one sends it; a
|
|
26
|
+
* `tool_choice` naming the search is then refused. Absent: the live search is offered whenever `webSearch` is on. */
|
|
27
|
+
searchAllowed?: () => Promise<boolean>;
|
|
26
28
|
/** Told, before Codex has the piece of an answer, what the answer carries: `response()` when an answer starts, and
|
|
27
29
|
* `exec(callId)` for each code-mode `exec` call it holds. The session ties a script's nested calls to the `exec` of the
|
|
28
30
|
* latest answer, which is known here before Codex can run anything of it. */
|
|
@@ -63,15 +65,6 @@ export declare function usageOf(text: string): ProxyUsage | undefined;
|
|
|
63
65
|
/** The web searches a Responses answer ran, as its terminal event reports them (`tool_usage.web_search.num_requests`,
|
|
64
66
|
* what OpenAI bills per call), or undefined when that event's own count cannot be read: an unknown cost, never 0. */
|
|
65
67
|
export declare function webSearchesOf(text: string): number | undefined;
|
|
66
|
-
/**
|
|
67
|
-
* The input tokens the provider bills for `body` that it does not carry (`providerInputOverhead`, with its sources). The
|
|
68
|
-
* Responses API documents no prompt of its own that it adds on these routes (no hosted tool passes the policy but a
|
|
69
|
-
* session's live web search, below), and the framing it puts around each input item and tool definition is a few tokens
|
|
70
|
-
* each, fewer than the bytes of the JSON keys that item already spends in the body. An image is billed by its area, not
|
|
71
|
-
* its bytes: each counts at the most it can be billed as, in place of the bytes its data URL takes in the body. A file input (a PDF, billed by its pages) has no stated bound, so a
|
|
72
|
-
* body with one cannot be measured: this throws, and the request's input is unknown.
|
|
73
|
-
*/
|
|
74
|
-
export declare function responsesServerInputOverhead(body: Record<string, unknown>): number;
|
|
75
68
|
/** The tokens a request keeps for its answer when its output is limited. */
|
|
76
69
|
export declare const ANSWER_TOKENS_LEAST = 1024;
|
|
77
70
|
/** What a reasoning request at each effort is allowed for its reasoning beside its answer, when its output is limited:
|