@parcha/agentrun-harness-codex 0.1.0-beta.38 → 0.1.0-beta.40
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 +22 -0
- package/README.md +2 -2
- package/dist/adapter.d.ts +5 -7
- package/dist/adapter.js +22 -43
- package/dist/code-mode.d.ts +15 -2
- package/dist/code-mode.js +110 -16
- package/dist/facts.js +5 -1
- package/dist/harness.d.ts +7 -1
- package/dist/harness.js +1 -1
- package/dist/host/machine.d.ts +3 -0
- package/dist/host/machine.js +11 -1
- package/dist/host/policy.d.ts +16 -3
- package/dist/host/policy.js +58 -17
- package/dist/host/process.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/scripts.d.ts +49 -2
- package/dist/scripts.js +175 -28
- package/dist/versions.d.ts +5 -0
- package/dist/versions.js +5 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.39 (2026-11-16)
|
|
6
|
+
|
|
7
|
+
- A Codex or OpenCode request straight to OpenAI is no longer counted by OpenAI before it is sent: it is held at the kernel's local o200k_base count with its margin, as a request through a gateway already is, so it never waits up to 3 seconds on `POST /v1/responses/input_tokens` first. A capped run on such a route may pause a little sooner than it did on OpenAI's exact count; the cap is still never passed.
|
|
8
|
+
- Breaking, for a host of the kernel: `OPENAI_INPUT_COUNTER` is gone. A `ProviderPolicy` that named it as `countInput` drops it and sets `countInputLocally: responsesLocalInputTokens`. Anthropic's count (`countInput` on the claude-agent policy) is unchanged.
|
|
9
|
+
- A server with no model key can run codex and pi on a person's ChatGPT plan. The owner signs in under `/settings/chatgpt` (OpenAI's Sign in with ChatGPT through pi-ai's own flow, finished by the loopback callback or by pasting the address the sign-in tab ended on), and models named `chatgpt/<id>` go to OpenAI's Responses API on the plan's token, billed to the plan with no price here.
|
|
10
|
+
- `GET /settings/chatgpt`, `POST /settings/chatgpt/sign-in`, `POST /settings/chatgpt/sign-in/finish` and `DELETE /settings/chatgpt` (owner session only). A bad or stale pasted address is a 400 in words. Sign-out revokes the session at OpenAI, then removes it.
|
|
11
|
+
- The sign-in is sealed in one row and read per request by the server and every runner, in their own processes or containers. A token renews once across all of them, 5 minutes before it ends: one holder takes a lease on the row (a compare-and-set on its sealed bytes, `SealedKeys.replaceIf`), and the others adopt the pair it writes back, so a refresh token is never used twice. A renewal sent with no answer read holds the lease to its end, since its refresh token may be spent; a fault OpenAI answers gives it back. A sign-out during a renewal stays. A refused renewal marks the sign-in expired, and runs on it fail at once in words. A 401 from OpenAI, in a pi turn or a workflow's model node, renews the token on the next request when the row still holds it.
|
|
12
|
+
- Capabilities say per harness whether it runs on the plan: pi and codex do, Claude Agent and OpenCode still need a key. Models list `source: "chatgpt"`.
|
|
13
|
+
- On the plan, the Codex policy sends no `max_output_tokens` and none of the keys the plan does not take, refuses a system-role message in words, and names its originator. Its turns are booked with `billing: "plan"` and no cost.
|
|
14
|
+
- Kernel: a model proxy's credential may throw `CredentialUnavailable` to refuse a request in the host's words (`code: "credential_unavailable"`), and `credentialRefused` tells the host the credential a provider answered 401 to.
|
|
15
|
+
- A capped run on a model whose tokenizer is o200k_base, reached over Messages without Anthropic's count (pi on GPT-6.1 Sol through OpenRouter, sent through serve's translation), bounds each request's input by a local count with its stated margin, as a Responses request to a gateway already does. Before, its bytes were the bound: after a few long pages the body passed 272,000 bytes, every rate was priced at Sol's long-context tier, and a $1.50 run stopped at $0.10-0.27 because the cap refused to send a step it could pay for. A Claude model, a body with a document, or one that offers the hosted search keeps the provider count or the byte bound.
|
|
16
|
+
When a run's cap is below what its model needs for one more step and an answer, the wrap-up's words now say so with both amounts, and the effort the model's request asked for when it named one ("This run's cap of $0.25 is below what gpt-6.1-sol at medium effort needs for one more step and an answer, about $0.32."), so a run that stopped its tools at its first call shows the cap was the cause. The rule that decides when a run wraps up has not changed.
|
|
17
|
+
Saving an agent with a cap below that figure (POST /agents, an edit of its definition, or a package install with a per-run budget) now saves with a warning on `definition.max_cost_usd` ("This agent's cap of $0.25 is below what gpt-6.1-sol at medium effort needs for one more step and an answer, about $0.32: a run will wrap up at its first tool call."). It is never refused. The figure is priced on the first request the agent's harness sends: the harness's own input before the agent's prompt (Codex about 12,200 tokens, from billing; Claude Agent, OpenCode and pi measured on their pinned builds, each stated beside its pin), the agent's prompt where the model's tokenizer is o200k_base, and the least output at the agent's effort, its thinking included: a pi agent on a Claude model that thinks with a budget is priced with Claude's 1,024-token thinking minimum, as its first request asks for it.
|
|
18
|
+
- Two fixes to how a Codex code-mode `exec` reads on the timeline, and one line in the desktop and phone skills. An exec that ends ok after its call parked on a person's approval and then ran shows its calls' outcomes alone, without "The exec was cut short after these calls (the session stopped)" or a resumed wait's "that cell's script was cut off". The model is still told those words, and an exec that failed still shows them. An exec the run's end closes, because nothing else ended it (the run stopped while its call waited for approval, or a crash whose next claim never resumed Codex's thread), now reads "Using tool: exec interrupted" with no status (`tool_status` null), never failed: a park or a stop failed nothing. A call a crash cut off still reads failed. The skills' "On Codex" paragraph now says Codex's exec has no top-level `return`, so a script's output goes through `text(...)`.
|
|
19
|
+
- Two fixes to how a Codex code-mode `exec` reads after a park or a crash, and one to pi's wording. A Codex exec's end row now sorts after the rows of the calls its script made: a crash leaves the exec open on the run's record, and Codex's recovered answer to it ends it after the resume. An exec whose call parked on a person's approval and then ran reads ok, with the stopped-and-resumed text, as a codemode script that parked reads on pi and claude-agent, never failed. An exec cut off mid-call still reads failed, after its cut call's row. The same holds for an exec that yielded and was finished by the model's pending `wait` on its cell: it reads ok when its parked call was allowed and ran, and failed when that call was refused or the wait was told the script was cut off. A recovered exec's outcome is saved in the session's log before Codex is answered, so a second crash before its end is recorded still ends it as that outcome says. An exec that no answer of Codex's ends (its run stopped while its call waited for approval, or a crash whose next drive never resumed Codex's thread) is closed with the run, "interrupted", after its calls' rows, never left open or shown failed ahead of them. A computer_op refused before it ran is named on the timeline by its op ("Refused: files.write"), never by "computer_op" or by its arguments, on every harness. On pi, a script's call a crash cut off now reads "interrupted: the process running it stopped before it reported an outcome; it may or may not have taken effect", the words claude-agent, opencode and Codex already give it. On Codex, a computer_op answer stays text, because Codex 0.164.0's code mode hands a script one string and never throws on a tool's reply. The desktop and phone kind skills now say how to read it: an op that ran answers JSON to parse, and a refused op answers the gate's words, which open with `Permission denied:` or `The user denied this`, or give the tool's name then `is read-only for this agent, so this call was refused:` or `can't be called:`.
|
|
20
|
+
- On Codex in code mode, a tool call that finished in the same script as a call waiting for approval now keeps its whole result when the run goes on. Before, the script was cut when the run paused, and on the resume the model got each finished call's result cut to its first 2,000 characters, with a note saying the output of those calls was not shown. So it ran a long read again.
|
|
21
|
+
- A finished call's result, or a failed call's error, comes back as the script got it live: up to the same 120,000-character bound every tool result has, with the usual line saying where it was cut past that.
|
|
22
|
+
- The recovered script output as a whole stays within that bound plus 2,000 characters for the words around the results. Past it, every result in it is cut to the same share, each keeping its start and its last line (a long MCP answer's last line says where the whole answer was filed) and saying where it was cut. Every call's outcome is still told, unless the script made so many calls that their lines alone pass the bound: then the output is cut with the same note, and the recovery note says only the calls still in it are shown above.
|
|
23
|
+
- The recovery note says a finished or failed call's outcome is in the output of the script that made it, instead of "not shown here". A call whose outcome is not in that output (one cut mid-way) keeps the old words.
|
|
24
|
+
- `recoverySystemNote` takes the calls whose outcome is already shown as an optional second argument. Without it the note reads as before, so Claude Code, OpenCode and pi are unchanged.
|
|
25
|
+
- Three fixes to codemode's computer calls. A script call a person allowed carries its computer calls on its own result row only, not on its approval and "ran once you allowed it" rows too, so summing a run's rows counts each computer call once. A script rerun after a crash tells a recorded call whose answer has no value (a file write) by its answer's words, as it was answered live, not as `completed: null`. On Codex, a code-mode `exec` has its own rows, and each host tool call its script makes sits under it (`parent_tool_use_id`, the exec's call id), as a codemode script's calls do on pi, claude-agent and opencode; a host lends this through the new optional `SessionIO.ownCalls`. A Codex script that failed reads failed on its exec's row, never `exec: ok`.
|
|
26
|
+
|
|
5
27
|
## 0.1.0-beta.38 (2026-11-14)
|
|
6
28
|
|
|
7
29
|
- A run's MCP tools are host tools on every harness: each call passes the run's one tool gate before anything is sent, and the runner calls the server with the credential, books the call and records it, as it does any host tool. opencode now runs MCP tools (`features.mcp_client.harnesses` lists it, and an opencode agent granted `mcp:<server>/<tool>` saves and runs). claude-agent offers a granted tool as `mcp__hands__mcp__<server>__<tool>` and codex as `mcp_<server>__<tool>` (Codex refuses a dynamic tool named `mcp__*`); the Timeline, tool settings and approvals still name it `mcp:<server>/<tool>`. A call set to ask on claude-agent, codex or opencode holds the CLI's call while the run waits (no "waits for a person's approval" result row while it is parked); on the person's allow the resumed session gets the call's own result, no `[tool approval]` message. A codex run no longer fails at its start when a granted server can't be reached: the server's error shows at the first call, as on pi. On a code-mode Codex model, a script's tool call held for a person's approval runs once on their allow, under its own call id, and the script's cut-off `exec` reads its result (or, when the `exec` had yielded, the model's `wait` on its cell); before, the resume told the model the call may have run, and the call the model made again asked again, so the allow never reached a call.
|
package/README.md
CHANGED
|
@@ -26,8 +26,8 @@ const runNode = createHarnessRunner(
|
|
|
26
26
|
answers the tool's value as JSON text, its images' data in it, for the script to `JSON.parse`; any other tool answers
|
|
27
27
|
its words and a line saying how many images it returned were not sent, since in code mode an image reaches a script only
|
|
28
28
|
as text (`test/code-mode-images-taken.test.mjs`). Codex's runtime takes no
|
|
29
|
-
binding of ours, so a
|
|
30
|
-
|
|
29
|
+
binding of ours, so a computer run offers `computer_op` (`{op, args}`: apps, shell, files, processes, raw input)
|
|
30
|
+
beside the computer's tools, and a script calls it as a nested call like any other, held to the run's gate. The proxy passes `exec` and
|
|
31
31
|
`wait` and drops the sub-agent and user-input tools Codex lists beside them; it keeps parallel tool calls off for a
|
|
32
32
|
code-mode request, and offers no `exec` while a script that yielded still runs, so one script is live at a time. A
|
|
33
33
|
nested call has an id of Codex's own (`exec-<uuid>`) that no line of the rollout carries and that names no `exec`, so
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type HostSkill } from "@parcha/agentrun-kernel";
|
|
2
|
-
import type { AgentAdapter
|
|
3
|
-
import { type HostTool as KernelTool } from "@parcha/agentrun-kernel/kernel";
|
|
2
|
+
import type { AgentAdapter } from "@parcha/agentrun-kernel";
|
|
4
3
|
import { NativeJournal } from "@parcha/agentrun-kernel/process";
|
|
5
4
|
import { type ConfineChild } from "./host/machine.js";
|
|
6
5
|
import { type ModelProxyOptions } from "@parcha/agentrun-kernel/host";
|
|
@@ -24,6 +23,10 @@ export interface CodexProvider {
|
|
|
24
23
|
origin: string;
|
|
25
24
|
/** The provider key, read per request in this process. It never reaches Codex's process. */
|
|
26
25
|
credential: () => Promise<string> | string;
|
|
26
|
+
/** A person's ChatGPT plan (`credential` its access token), whose rules the proxy keeps (codexPolicy's `plan`). */
|
|
27
|
+
plan?: boolean;
|
|
28
|
+
/** Told the credential a request was sent with when the provider answered 401 to it (ModelProxyOptions.credentialRefused). */
|
|
29
|
+
refused?: (credential: string) => void | Promise<void>;
|
|
27
30
|
}
|
|
28
31
|
/** Codex's own web search, as a session may turn it on: `live` (it searches the web as it runs). */
|
|
29
32
|
export type CodexWebSearch = "live";
|
|
@@ -71,11 +74,6 @@ export interface CodexAdapterOptions {
|
|
|
71
74
|
/** For tests: the fetch the model proxy forwards with. */
|
|
72
75
|
fetch?: typeof fetch;
|
|
73
76
|
}
|
|
74
|
-
/** The kernel's tool for a host tool: the same name, schema and replay policy; a host's error result is the call's failure.
|
|
75
|
-
* The call runs as a kernel effect, whose intent is durable in the session's records before `execute` is entered, so a
|
|
76
|
-
* crash inside a `never` tool is always reported, never repeated. The copied harness's wait for Codex's own `function_call`
|
|
77
|
-
* line before it runs such a tool is a second guard (the transcript Codex resumes from), not the one that protects it. */
|
|
78
|
-
export declare function kernelTool(tool: HostTool): KernelTool;
|
|
79
77
|
/**
|
|
80
78
|
* The mirrored rollout the next drive resumes Codex from, by the harness's own rule (harness.ts, `resume`: the last
|
|
81
79
|
* thread, its first line `session_meta`, its path the one the harness derives); none when it would start a new thread.
|
package/dist/adapter.js
CHANGED
|
@@ -14,7 +14,7 @@ import { join } from "node:path";
|
|
|
14
14
|
import { HOST_RESULT_MAX_CHARS, READ_SKILL_FILE, hostedTool, readSkillFileTool, skillProblems, toolSchemaProblems } from "@parcha/agentrun-kernel";
|
|
15
15
|
import { abortedOutcome, openDrive, SessionHalt } from "@parcha/agentrun-kernel/kernel";
|
|
16
16
|
import { pendingSubmissions } from "@parcha/agentrun-kernel/kernel";
|
|
17
|
-
import { NativeJournal, recoveryNote, settleTurn, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
17
|
+
import { bridgeTool, NativeJournal, recoveryNote, settleTurn, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
18
18
|
import { codexSchemaProblems, describedDescription } from "./schema.js";
|
|
19
19
|
import { markParked } from "./scripts.js";
|
|
20
20
|
import { withCheckedBinary } from "./host/sandbox.js";
|
|
@@ -42,46 +42,6 @@ export const codexToolName = (name) => (name.startsWith("mcp__") ? `mcp_${name.s
|
|
|
42
42
|
* three quarters of a token a character: not a quarter, which holds for ASCII alone.
|
|
43
43
|
*/
|
|
44
44
|
export const CODEX_TOOL_OUTPUT_TOKENS = Math.ceil((HOST_RESULT_MAX_CHARS * 3) / 4);
|
|
45
|
-
/** The kernel's tool for a host tool: the same name, schema and replay policy; a host's error result is the call's failure.
|
|
46
|
-
* The call runs as a kernel effect, whose intent is durable in the session's records before `execute` is entered, so a
|
|
47
|
-
* crash inside a `never` tool is always reported, never repeated. The copied harness's wait for Codex's own `function_call`
|
|
48
|
-
* line before it runs such a tool is a second guard (the transcript Codex resumes from), not the one that protects it. */
|
|
49
|
-
export function kernelTool(tool) {
|
|
50
|
-
return {
|
|
51
|
-
name: codexToolName(tool.name),
|
|
52
|
-
// Codex strips some keywords from the schema its model is given: they are said in plain words in the description
|
|
53
|
-
// (the schema itself is the host's, and every call is checked against it).
|
|
54
|
-
description: describedDescription(tool.description, tool.inputSchema),
|
|
55
|
-
inputSchema: tool.inputSchema,
|
|
56
|
-
replay: tool.replay,
|
|
57
|
-
...(tool.nests ? { nests: true } : {}),
|
|
58
|
-
...(tool.deferred ? { deferred: true } : {}),
|
|
59
|
-
async execute(input, io) {
|
|
60
|
-
// The effect's step is `tool:<Codex call id>#<attempt>`: the host sees Codex's call id.
|
|
61
|
-
const callId = (io.stepId ?? "").replace(/^tool:/, "").replace(/#\d+$/, "");
|
|
62
|
-
// The step's attempt: above 0 when a crash cut an earlier attempt and the kernel runs the call again.
|
|
63
|
-
const attempt = Number(/#(\d+)$/.exec(io.stepId ?? "")?.[1] ?? 0);
|
|
64
|
-
// A tool that nests calls (tools_call) names them by the host's names: the bridge holds them by Codex's.
|
|
65
|
-
const nested = io.nested && { call: (name, args, key) => io.nested.call(codexToolName(name), args, key), memo: io.nested.memo };
|
|
66
|
-
const result = await tool.call(input, { callId, signal: io.signal, attempt, ...(nested ? { nested } : {}) });
|
|
67
|
-
// A call the host parked for a person's approval did not run: recorded so before its answer, the waiting text.
|
|
68
|
-
if (result.parked)
|
|
69
|
-
await markParked(io.ctx, callId);
|
|
70
|
-
if (result.isError)
|
|
71
|
-
throw new Error(result.text);
|
|
72
|
-
// A computer tool's value, recorded with the outcome: a script's nested call is answered it (code-mode.ts scriptAnswer).
|
|
73
|
-
const structured = result.structured !== undefined ? { structured: result.structured } : {};
|
|
74
|
-
if (!result.images?.length)
|
|
75
|
-
return result.structured === undefined ? result.text : { text: result.text, ...structured };
|
|
76
|
-
// An image the model can't be sent is the call's error, by the tool's name and the image, not a request refused later.
|
|
77
|
-
const wrong = toolImageProblems(tool.name, result.images);
|
|
78
|
-
if (wrong)
|
|
79
|
-
throw new Error(wrong);
|
|
80
|
-
// With its images, recorded with the outcome: the answer to Codex carries them after the text (code-mode.ts withImages).
|
|
81
|
-
return { text: result.text, images: result.images.map((image) => ({ mimeType: image.mimeType, data: image.data })), ...structured };
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
45
|
/** The adapter's event for a harness live event, if it has one: a tool's by the host's name for it (`hostName`). */
|
|
86
46
|
function adapterEvent(event, hostName) {
|
|
87
47
|
const e = event;
|
|
@@ -185,9 +145,25 @@ export function codexAdapter(options) {
|
|
|
185
145
|
// web_search setting allows it, read before each request (a deny or ask set mid-run drops it from the next one).
|
|
186
146
|
const searchAllowed = options.webSearch && io.permission ? async () => (await io.permission("web_search")) === "allow" : undefined;
|
|
187
147
|
const harnessOptions = {
|
|
188
|
-
|
|
148
|
+
// The kernel's tool for each host tool (bridgeTool): the same schema and replay policy, a host's error result the
|
|
149
|
+
// call's failure. The call runs as a kernel effect, whose intent is durable before it is entered, so a crash inside
|
|
150
|
+
// a `never` tool is always reported, never repeated (the copied harness's wait for Codex's own `function_call` line
|
|
151
|
+
// before it runs such a tool is a second guard, not the one that protects it).
|
|
152
|
+
tools: tools.map((tool) => bridgeTool(tool, {
|
|
153
|
+
name: codexToolName(tool.name),
|
|
154
|
+
// Codex strips some keywords from the schema its model is given: they are said in plain words in the
|
|
155
|
+
// description (the schema itself is the host's, and every call is checked against it).
|
|
156
|
+
description: describedDescription(tool.description, tool.inputSchema),
|
|
157
|
+
// A tool that nests calls (tools_call) names them by the host's names: the bridge holds them by Codex's.
|
|
158
|
+
nestedName: codexToolName,
|
|
159
|
+
// A call the host parked for a person's approval did not run: recorded so before its answer, the waiting text.
|
|
160
|
+
parked: markParked,
|
|
161
|
+
imageProblems: (images) => toolImageProblems(tool.name, images),
|
|
162
|
+
})),
|
|
189
163
|
// The host's gate, asked about each host-tool call before its intent is written.
|
|
190
164
|
...(io.gate ? { gate: (call) => io.gate({ ...call, tool: hostName(call.tool) }) } : {}),
|
|
165
|
+
// The host's record of a code-mode `exec`: its row, and its script's calls under it.
|
|
166
|
+
...(io.ownCalls ? { ownCalls: io.ownCalls } : {}),
|
|
191
167
|
builtins: false,
|
|
192
168
|
// Codex's bundled skills (imagegen, skill-installer, ...), which it writes under `$CODEX_HOME/skills/.system` at every
|
|
193
169
|
// start, are off in every session, skills or not: the model is shown the host's skills and no others.
|
|
@@ -222,6 +198,8 @@ export function codexAdapter(options) {
|
|
|
222
198
|
...(options.log ? { log: options.log } : {}),
|
|
223
199
|
...(options.price ? { price: options.price } : {}),
|
|
224
200
|
...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}),
|
|
201
|
+
...(options.provider.plan ? { plan: true } : {}),
|
|
202
|
+
...(options.provider.refused ? { credentialRefused: options.provider.refused } : {}),
|
|
225
203
|
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
226
204
|
},
|
|
227
205
|
}),
|
|
@@ -296,11 +274,12 @@ export function codexAdapter(options) {
|
|
|
296
274
|
// Started once the session's drive is open, the last step that can fail: an open that fails leaves no listener.
|
|
297
275
|
const search = options.webSearch === "live";
|
|
298
276
|
const hostPort = await startModelProxy({
|
|
299
|
-
policy: codexPolicy({ model: modelFor(spec), tools: [], ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}), ...(search ? { webSearch: "live", ...(searchAllowed ? { searchAllowed } : {}) } : {}) }),
|
|
277
|
+
policy: codexPolicy({ model: modelFor(spec), tools: [], ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}), ...(options.provider.plan ? { plan: true } : {}), ...(search ? { webSearch: "live", ...(searchAllowed ? { searchAllowed } : {}) } : {}) }),
|
|
300
278
|
hooks: io.models,
|
|
301
279
|
model: modelFor(spec),
|
|
302
280
|
origin: options.provider.origin,
|
|
303
281
|
credential: async () => (await options.provider.credential()) ?? "",
|
|
282
|
+
...(options.provider.refused ? { credentialRefused: options.provider.refused } : {}),
|
|
304
283
|
...(options.price ? { price: search ? withWebSearches(options.price) : options.price } : {}),
|
|
305
284
|
...(options.log ? { log: options.log } : {}),
|
|
306
285
|
...(options.fetch ? { fetch: options.fetch } : {}),
|
package/dist/code-mode.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OwnCalls } from "@parcha/agentrun-kernel";
|
|
1
2
|
import type { DriveContext } from "./host/kernel.js";
|
|
2
3
|
import type { SessionMachine } from "./host/process.js";
|
|
3
4
|
import { type RolloutSummary } from "./rollout.js";
|
|
@@ -8,6 +9,13 @@ export declare const RECOVERY_NOTE_STREAM = "codex.recovery-note";
|
|
|
8
9
|
/** A yielded exec's nested call run on a resume (recoverItems), written before it runs: a later recovery of the same turn tells
|
|
9
10
|
* the model's `wait` its outcome from the session's record, never running it again. */
|
|
10
11
|
export declare const RESUMED_STREAM = "codex.nested-resumed";
|
|
12
|
+
/** The nested calls whose outcome a resume's recovered script output tells (recoverItems): `{ since, callIds }`, written before
|
|
13
|
+
* that output is injected, so the turn's recovery note says the outcome is there, after a crash between the two as well. */
|
|
14
|
+
export declare const SHOWN_STREAM = "codex.nested-shown";
|
|
15
|
+
/** Each `exec` a recovery answered (recoverItems), directly or through the `wait` on its cell, and whether that answer tells a
|
|
16
|
+
* script that failed (recoveredFailed): `{ exec, failed }`, written before the answer is injected. That answer carries no status
|
|
17
|
+
* 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. */
|
|
18
|
+
export declare const RECOVERED_END_STREAM = "codex.exec-recovered-end";
|
|
11
19
|
interface Journal {
|
|
12
20
|
append(stream: string, record: unknown): void;
|
|
13
21
|
flush(): Promise<void>;
|
|
@@ -53,6 +61,9 @@ export interface CodeModeDeps {
|
|
|
53
61
|
/** How often the barrier looks again for a script's line, and what a declined call is told. */
|
|
54
62
|
tries: number;
|
|
55
63
|
declined: string;
|
|
64
|
+
/** The host's record of each `exec` (SessionIO.ownCalls): its row from its rollout lines, and each nested call it makes
|
|
65
|
+
* named under it before the call reaches the gate. */
|
|
66
|
+
ownCalls?: OwnCalls;
|
|
56
67
|
}
|
|
57
68
|
interface Dangling {
|
|
58
69
|
callId: string;
|
|
@@ -71,7 +82,7 @@ export declare function withOutputKind<T extends {
|
|
|
71
82
|
};
|
|
72
83
|
/** What a dangling `wait` of code mode is told: it had started, on the cell named, when the session stopped and took the cell's script with it. */
|
|
73
84
|
export declare const waitStoppedText: (cell: string) => string;
|
|
74
|
-
/** A recorded result that held images (
|
|
85
|
+
/** A recorded result that held images (bridgeTool's `{ text, images }`) as its text and a line saying how many, which are not
|
|
75
86
|
* shown again after the interruption; undefined for a result with none, whose repaired output stays as it is. */
|
|
76
87
|
export declare function imagesNoted(output: unknown): string | undefined;
|
|
77
88
|
type Image = {
|
|
@@ -109,7 +120,9 @@ export declare function codeMode(deps: CodeModeDeps): {
|
|
|
109
120
|
* 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
|
|
110
121
|
* 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
|
|
111
122
|
* 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
|
|
112
|
-
* both repairs (with a recovery note and without) inject what this leaves.
|
|
123
|
+
* both repairs (with a recovery note and without) inject what this leaves. A recovered script's output (a cut-off exec's, a resumed
|
|
124
|
+
* `wait`'s) quotes each finished call's result as the script was handed it and holds its whole to its own bound
|
|
125
|
+
* (scripts.ts EXEC_RECOVERY_MAX_CHARS); on a resume, the calls it tells the outcome of are recorded for the note (SHOWN_STREAM). `resume`: the open turn a recovery note resumes, whose
|
|
113
126
|
* parked nested calls run now; the repair of an ended turn (repairUnnoted) only tells, and runs nothing. */
|
|
114
127
|
recoverItems(items: Record<string, unknown>[], dangling: readonly Dangling[], lines: readonly string[], since: number, resume?: boolean): Promise<void>;
|
|
115
128
|
/** With no recovery note, the calls the rollout has no output for get theirs from the log before any turn is sent: a turn that ended without
|
package/dist/code-mode.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { boundResult, openTurn, recoveryNote, recoverySystemNote, recoveryUserTurn, toolKey, transcriptOf } from "./host/process.js";
|
|
1
|
+
import { boundResult, failureText, openTurn, recoveryNote, recoverySystemNote, recoveryUserTurn, toolKey, transcriptOf } from "./host/process.js";
|
|
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
5
|
import { summarizeRollout } from "./rollout.js";
|
|
6
|
-
import { callKey, completedNested,
|
|
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";
|
|
9
9
|
/** The stream that records the interrupted turns whose recovery note was injected: `{ since }`, once per interrupted turn. */
|
|
@@ -11,6 +11,13 @@ export const RECOVERY_NOTE_STREAM = "codex.recovery-note";
|
|
|
11
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
12
|
* the model's `wait` its outcome from the session's record, never running it again. */
|
|
13
13
|
export const RESUMED_STREAM = "codex.nested-resumed";
|
|
14
|
+
/** The nested calls whose outcome a resume's recovered script output tells (recoverItems): `{ since, callIds }`, written before
|
|
15
|
+
* that output is injected, so the turn's recovery note says the outcome is there, after a crash between the two as well. */
|
|
16
|
+
export const SHOWN_STREAM = "codex.nested-shown";
|
|
17
|
+
/** Each `exec` a recovery answered (recoverItems), directly or through the `wait` on its cell, and whether that answer tells a
|
|
18
|
+
* script that failed (recoveredFailed): `{ exec, failed }`, written before the answer is injected. That answer carries no status
|
|
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
|
+
export const RECOVERED_END_STREAM = "codex.exec-recovered-end";
|
|
14
21
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
15
22
|
/** Only a custom tool call named `exec` is code mode's: a host tool that happens to be called `exec` is a function call. */
|
|
16
23
|
const isExec = (d) => d.type === "custom_tool_call" && d.name === "exec";
|
|
@@ -38,19 +45,21 @@ function sentOf(output) {
|
|
|
38
45
|
return {};
|
|
39
46
|
return { sent: JSON.stringify(withImageData(kept.structured, kept.images ?? [])) };
|
|
40
47
|
}
|
|
48
|
+
/** A failed call's error as the bridge handed it (`failureText`: its message, or words saying it had none). */
|
|
49
|
+
const failedText = (error) => (error ? failureText(error) : "");
|
|
41
50
|
function factOf(state, rolled, tie, told = new Map()) {
|
|
42
51
|
const e = state.effects.get(toolKey(tie.callId));
|
|
43
52
|
const status = told.get(tie.callId);
|
|
44
53
|
return {
|
|
45
54
|
callId: tie.callId,
|
|
46
55
|
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
|
|
56
|
+
...(e ? { store: { status: e.status === "completed" ? "completed" : e.status === "failed" ? "failed" : "started", text: e.status === "failed" ? failedText(e.error) : outputTextOf(e.output), ...(e.status === "completed" ? sentOf(e.output) : {}), ...(e.error?.interrupted ? { interrupted: true } : {}) } } : {}),
|
|
48
57
|
...(rolled.has(tie.callId) ? { rollout: rolled.get(tie.callId) } : {}),
|
|
49
58
|
...(status ? { told: status } : {}),
|
|
50
59
|
...(state.effects.get(parkedKey(tie.callId))?.status === "completed" ? { parked: true } : {}),
|
|
51
60
|
};
|
|
52
61
|
}
|
|
53
|
-
/** A recorded result that held images (
|
|
62
|
+
/** A recorded result that held images (bridgeTool's `{ text, images }`) as its text and a line saying how many, which are not
|
|
54
63
|
* shown again after the interruption; undefined for a result with none, whose repaired output stays as it is. */
|
|
55
64
|
export function imagesNoted(output) {
|
|
56
65
|
const images = output?.images;
|
|
@@ -110,9 +119,54 @@ export function codeMode(deps) {
|
|
|
110
119
|
const execOf = new Map();
|
|
111
120
|
/** 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. */
|
|
112
121
|
const recovered = new Map();
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
/** Each `exec` whose row this drive opened on the host's record (SessionIO.ownCalls): its end waits for that write. */
|
|
123
|
+
const rows = new Map();
|
|
124
|
+
/** The host's record of `exec`'s end, once its row is written: `output`, failed as a recovery recorded it (RECOVERED_END_STREAM)
|
|
125
|
+
* or else as its status header says (`failed`). A crash leaves an exec open on the record (its start is marked as one its
|
|
126
|
+
* harness answers), so its end is always one of these. A recovered exec that ended ok shows its calls' outcomes without
|
|
127
|
+
* the words telling the model its script was cut short (recoveredRowText): on the record, those are a failed exec's. */
|
|
128
|
+
const endRow = (exec, output, failed) => {
|
|
129
|
+
const own = deps.ownCalls;
|
|
130
|
+
if (!own)
|
|
131
|
+
return;
|
|
132
|
+
void (rows.get(exec) ?? Promise.resolve())
|
|
133
|
+
.then(() => journal.read(RECOVERED_END_STREAM))
|
|
134
|
+
.then((kept) => {
|
|
135
|
+
const recovered = kept.findLast((r) => r.data.exec === exec)?.data;
|
|
136
|
+
return recovered ? own.ended(exec, recoveredRowText(output, recovered.failed), recovered.failed) : own.ended(exec, output, failed);
|
|
137
|
+
})
|
|
138
|
+
.catch((error) => deps.log("codex: an exec's end was not written", { exec, error: String(error) }));
|
|
139
|
+
};
|
|
140
|
+
// An `exec` of the log restored that Codex finished before the session stopped: its end, which a crash may have kept off
|
|
141
|
+
// the host's record (a call ended there already says nothing).
|
|
142
|
+
for (const line of deps.lines) {
|
|
143
|
+
const said = scripts.note(line);
|
|
144
|
+
if (said?.kind === "finished")
|
|
145
|
+
endRow(said.exec, said.output, said.failed);
|
|
146
|
+
}
|
|
147
|
+
/** The host's row of the `exec` `exec`, opened once with its script (`{ script }`, as codemode's own input is held), from
|
|
148
|
+
* its rollout line or, before that line is in the rollout, from the proxy's announcement. */
|
|
149
|
+
const openRow = (exec, input) => {
|
|
150
|
+
const own = deps.ownCalls;
|
|
151
|
+
if (!own)
|
|
152
|
+
return Promise.resolve();
|
|
153
|
+
let row = rows.get(exec);
|
|
154
|
+
if (!row)
|
|
155
|
+
rows.set(exec, (row = own.opened(exec, "exec", input === undefined ? {} : { script: input })));
|
|
156
|
+
return row;
|
|
157
|
+
};
|
|
158
|
+
// The lines read live open an `exec`'s row and end it. An `exec` of the log restored is on the host's record already; a
|
|
159
|
+
// cut-off one ends here too, when its recovered output (recoverItems) reaches the rollout: after the rows of the calls the
|
|
160
|
+
// recovery ran or found cut off, failed as the recovery recorded (RECOVERED_END_STREAM).
|
|
161
|
+
machine.onRolloutLine?.((line) => {
|
|
162
|
+
const said = scripts.note(line);
|
|
163
|
+
if (!said || !deps.ownCalls)
|
|
164
|
+
return;
|
|
165
|
+
if (said.kind === "opened")
|
|
166
|
+
void openRow(said.exec, said.input).catch((error) => deps.log("codex: an exec's row was not written", { exec: said.exec, error: String(error) }));
|
|
167
|
+
else
|
|
168
|
+
endRow(said.exec, said.output, said.failed);
|
|
169
|
+
});
|
|
116
170
|
/** The script a nested call is tied to now, as the log and the proxy's latest answer have it. */
|
|
117
171
|
const tieNow = () => scripts.tie(machine.announcedExec?.(), (id) => logged.has(id));
|
|
118
172
|
/** A `never` nested call: wait for its script's line, as the harness's barrier waits for a call's own. True: admitted. */
|
|
@@ -206,6 +260,13 @@ export function codeMode(deps) {
|
|
|
206
260
|
const exec = execOf.get(callId) ?? (tie.kind === "tied" || tie.kind === "held" ? tie.exec : undefined);
|
|
207
261
|
if (exec)
|
|
208
262
|
execOf.set(callId, exec);
|
|
263
|
+
// On the host's record the call sits under its exec's row, written first (from the proxy's announcement when the
|
|
264
|
+
// exec's line is not in the rollout yet), as a codemode script's calls sit under its call on every other harness.
|
|
265
|
+
// A call tied to no known exec names none: no parent is made up.
|
|
266
|
+
if (exec && exec !== UNWATCHED && deps.ownCalls) {
|
|
267
|
+
await openRow(exec, scripts.inputOf(exec) ?? machine.announcedInput?.(exec)).catch((error) => deps.log("codex: an exec's row was not written", { exec, error: String(error) }));
|
|
268
|
+
deps.ownCalls.nestedIn(callId, exec);
|
|
269
|
+
}
|
|
209
270
|
// Never the unwatched-answer marker: a call tied to no known exec is journaled with none.
|
|
210
271
|
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 ?? {} });
|
|
211
272
|
}
|
|
@@ -232,7 +293,9 @@ export function codeMode(deps) {
|
|
|
232
293
|
* 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
|
|
233
294
|
* 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
|
|
234
295
|
* 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
|
|
235
|
-
* both repairs (with a recovery note and without) inject what this leaves.
|
|
296
|
+
* both repairs (with a recovery note and without) inject what this leaves. A recovered script's output (a cut-off exec's, a resumed
|
|
297
|
+
* `wait`'s) quotes each finished call's result as the script was handed it and holds its whole to its own bound
|
|
298
|
+
* (scripts.ts EXEC_RECOVERY_MAX_CHARS); on a resume, the calls it tells the outcome of are recorded for the note (SHOWN_STREAM). `resume`: the open turn a recovery note resumes, whose
|
|
236
299
|
* parked nested calls run now; the repair of an ended turn (repairUnnoted) only tells, and runs nothing. */
|
|
237
300
|
async recoverItems(items, dangling, lines, since, resume = false) {
|
|
238
301
|
const ties = (await journal.read(NESTED_STREAM)).map((r) => r.data);
|
|
@@ -257,7 +320,7 @@ export function codeMode(deps) {
|
|
|
257
320
|
const done = ctx.state().effects.get(toolKey(tie.callId));
|
|
258
321
|
// Run on an earlier recovery of this turn that stopped before the wait was answered: told from its record.
|
|
259
322
|
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
|
|
323
|
+
resumed.set(tie.callId, { text: done.status === "failed" ? failedText(done.error) : outputTextOf(done.output), isError: done.status === "failed", ran: true });
|
|
261
324
|
yieldedTies.push(tie);
|
|
262
325
|
continue;
|
|
263
326
|
}
|
|
@@ -278,26 +341,55 @@ export function codeMode(deps) {
|
|
|
278
341
|
// 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)
|
|
279
342
|
// is listed once, apart, in the LAST cut-off exec's output, if it ran in this interrupted turn.
|
|
280
343
|
const told = new Map((recoveryNote(state)?.calls ?? []).map((c) => [c.callId, c.status]));
|
|
281
|
-
const
|
|
344
|
+
const fact = (tie) => ({ ...factOf(state, rolled, tie, told), ...(resumed.has(tie.callId) ? { resumed: resumed.get(tie.callId) } : {}) });
|
|
345
|
+
const listed = recoveryFacts(execs, ties, since, fact);
|
|
346
|
+
// The exec each dangling `wait`'s cell belongs to, as the rollout has it.
|
|
347
|
+
const yielders = new Scripts();
|
|
348
|
+
for (const line of lines)
|
|
349
|
+
yielders.note(line);
|
|
350
|
+
// The outputs built here hold their quoted results to their own bound (scripts.ts EXEC_RECOVERY_MAX_CHARS): every other is
|
|
351
|
+
// held to the host's below. The calls whose outcome they tell, for the turn's recovery note.
|
|
352
|
+
const built = new Set();
|
|
353
|
+
const shown = [];
|
|
282
354
|
dangling.forEach((c, i) => {
|
|
283
355
|
if (!isExec(c)) {
|
|
284
356
|
// Code mode's `wait` on a cell had started: the generic answer, that the call never started, would be false.
|
|
285
357
|
const cell = waitedCell(c);
|
|
286
358
|
const item = items[i];
|
|
287
|
-
// A completed call whose result held images (
|
|
359
|
+
// A completed call whose result held images (bridgeTool records { text, images }): repairOutput gives the record
|
|
288
360
|
// as JSON, so the model would read their base64 as text. Its text and a line on them instead; they are not sent.
|
|
289
361
|
const done = state.effects.get(toolKey(c.callId));
|
|
290
362
|
const pictured = cell === undefined && done?.status === "completed" ? imagesNoted(done.output) : undefined;
|
|
291
|
-
const
|
|
363
|
+
const answered = cell !== undefined && i === carrier && yieldedTies.length > 0 ? yieldedTies.map((tie) => ({ ...factOf(state, rolled, tie, told), resumed: resumed.get(tie.callId) })) : undefined;
|
|
364
|
+
const recovered = answered && cell !== undefined ? waitResumed(cell, answered) : undefined;
|
|
365
|
+
const waited = cell === undefined ? undefined : recovered ? recovered.output : waitStoppedText(cell);
|
|
366
|
+
if (recovered) {
|
|
367
|
+
built.add(i);
|
|
368
|
+
shown.push(...recovered.shown);
|
|
369
|
+
}
|
|
370
|
+
// This output finishes the cell's exec, and it carries no status header: that exec ends as its last call says.
|
|
371
|
+
const exec = cell === undefined ? undefined : yielders.execOn(cell);
|
|
372
|
+
if (exec !== undefined)
|
|
373
|
+
journal.append(RECOVERED_END_STREAM, { exec, failed: recoveredFailed(ties.filter((tie) => tie.exec === exec).map(fact)) });
|
|
292
374
|
items[i] = withOutputKind(waited !== undefined ? { ...item, output: waited } : pictured !== undefined ? { ...item, output: pictured } : item, c);
|
|
293
375
|
return;
|
|
294
376
|
}
|
|
295
377
|
const { own, loose } = listed.get(c.callId);
|
|
296
|
-
|
|
378
|
+
// Only the calls the output still tells after its bound: a call cut from it is not said to be above.
|
|
379
|
+
const recovered = execRecovery(own, loose);
|
|
380
|
+
items[i] = { type: "custom_tool_call_output", call_id: c.callId, output: recovered.output };
|
|
381
|
+
journal.append(RECOVERED_END_STREAM, { exec: c.callId, failed: recoveredFailed(own) });
|
|
382
|
+
built.add(i);
|
|
383
|
+
shown.push(...recovered.shown);
|
|
297
384
|
});
|
|
298
|
-
|
|
299
|
-
if (typeof item.output === "string")
|
|
385
|
+
items.forEach((item, i) => {
|
|
386
|
+
if (!built.has(i) && typeof item.output === "string")
|
|
300
387
|
item.output = boundResult(item.output).text;
|
|
388
|
+
});
|
|
389
|
+
if (resume && shown.length > 0)
|
|
390
|
+
journal.append(SHOWN_STREAM, { since, callIds: shown });
|
|
391
|
+
// Every record above is in the log before the outputs are injected.
|
|
392
|
+
await journal.flush();
|
|
301
393
|
},
|
|
302
394
|
/** With no recovery note, the calls the rollout has no output for get theirs from the log before any turn is sent: a turn that ended without
|
|
303
395
|
* them (one interrupted mid-call, or settled instead of resumed) left them dangling, and the provider refuses a history with a call unanswered.
|
|
@@ -317,7 +409,9 @@ export function codeMode(deps) {
|
|
|
317
409
|
* would repeat it). With no statuses-only note to give, nothing is injected: the full note carries tool outputs and goes in no slot of the model's. */
|
|
318
410
|
async resumeTurn(note, owed) {
|
|
319
411
|
await arm(note.turn.since);
|
|
320
|
-
|
|
412
|
+
// The calls whose outcome a recovered script output of this turn tells: the note says it is there, not that it is not shown.
|
|
413
|
+
const shown = new Set((await journal.read(SHOWN_STREAM)).filter((r) => r.data.since === note.turn.since).flatMap((r) => r.data.callIds));
|
|
414
|
+
const system = recoverySystemNote(ctx.state(), shown);
|
|
321
415
|
const noted = (await journal.read(RECOVERY_NOTE_STREAM)).some((r) => r.data.since === note.turn.since);
|
|
322
416
|
if (system !== undefined && !noted) {
|
|
323
417
|
await deps.guard(deps.rpc().request("thread/inject_items", { threadId: deps.threadId(), items: [{ type: "message", role: "developer", content: [{ type: "input_text", text: system }] }] }));
|
package/dist/facts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { codexPolicy } from "./host/policy.js";
|
|
2
2
|
import { codexSchemaProblems } from "./schema.js";
|
|
3
|
-
import { CODEX_INSTALL, CODEX_VERSION } from "./versions.js";
|
|
3
|
+
import { CODEX_BASE_INPUT_TOKENS, CODEX_INSTALL, CODEX_VERSION } from "./versions.js";
|
|
4
4
|
export const facts = Object.freeze({
|
|
5
5
|
id: "codex",
|
|
6
6
|
label: "Codex",
|
|
@@ -27,5 +27,9 @@ export const facts = Object.freeze({
|
|
|
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" }),
|
|
30
|
+
// A run's MCP tool reaches Codex as `mcp_<server>__<tool>` (adapter.ts codexToolName): the host's is `mcp__<server>__<tool>`.
|
|
31
|
+
hostName: (given) => given.replace(/^mcp_(?!_)/, "mcp__"),
|
|
32
|
+
// Its first request's own input before the agent's prompt, from a Codex run's billing (versions.ts).
|
|
33
|
+
baseInputTokens: CODEX_BASE_INPUT_TOKENS,
|
|
30
34
|
policy: (options) => codexPolicy({ model: options.model, tools: options.tools, ...(options.webSearch === "live" ? { webSearch: "live" } : {}), ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}) }),
|
|
31
35
|
});
|
package/dist/harness.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GateAnswer, GateCall } from '@parcha/agentrun-kernel';
|
|
1
|
+
import type { GateAnswer, GateCall, OwnCalls } from '@parcha/agentrun-kernel';
|
|
2
2
|
import { type Harness, type HostTool, type ReplayPolicy, type SessionState, type Submission } from './host/kernel.js';
|
|
3
3
|
import { type AcquireMachine } from './host/process.js';
|
|
4
4
|
import { type TomlValue } from './config.js';
|
|
@@ -80,6 +80,12 @@ export interface CodexHarnessOptions {
|
|
|
80
80
|
* words, nothing written and nothing run; a park holds it. Default none.
|
|
81
81
|
*/
|
|
82
82
|
gate?: (call: GateCall) => Promise<GateAnswer>;
|
|
83
|
+
/**
|
|
84
|
+
* The host's record of a code-mode `exec` (SessionIO.ownCalls): its row
|
|
85
|
+
* from its rollout lines, and each host tool call its script makes named
|
|
86
|
+
* under it. Default none.
|
|
87
|
+
*/
|
|
88
|
+
ownCalls?: OwnCalls;
|
|
83
89
|
/**
|
|
84
90
|
* Codex's own shell and `apply_patch` (and `view_image`), on `/workspace`
|
|
85
91
|
* in the session's VM. Default false (tool-less: `tools` are its only
|
package/dist/harness.js
CHANGED
|
@@ -371,7 +371,7 @@ export function codexHarness(options = {}) {
|
|
|
371
371
|
}
|
|
372
372
|
mirror();
|
|
373
373
|
};
|
|
374
|
-
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 });
|
|
374
|
+
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 } : {}) });
|
|
375
375
|
/**
|
|
376
376
|
* The hard barrier before a `never` call (§5.6): its `function_call`
|
|
377
377
|
* line in the log, flushed, before its intent. Codex's rollout writer is
|
package/dist/host/machine.d.ts
CHANGED
|
@@ -34,6 +34,9 @@ export interface LocalMachineOptions {
|
|
|
34
34
|
tools: readonly string[];
|
|
35
35
|
price?: ModelProxyOptions["price"];
|
|
36
36
|
maxOutputTokens?: number;
|
|
37
|
+
/** On a person's ChatGPT plan: its rules (CodexPolicyOptions.plan). */
|
|
38
|
+
plan?: boolean;
|
|
39
|
+
credentialRefused?: ModelProxyOptions["credentialRefused"];
|
|
37
40
|
log?: ModelProxyOptions["log"];
|
|
38
41
|
fetch?: typeof fetch;
|
|
39
42
|
};
|
package/dist/host/machine.js
CHANGED
|
@@ -204,6 +204,8 @@ export function localMachine(options) {
|
|
|
204
204
|
const route = model.options;
|
|
205
205
|
// The code-mode `exec` the model proxy's latest answer carried: set while the answer passes, before Codex has it.
|
|
206
206
|
let announced;
|
|
207
|
+
// The script of the last `exec` announced, by its call id: what the host's record of that exec shows.
|
|
208
|
+
let script;
|
|
207
209
|
let open = 0;
|
|
208
210
|
const rolloutListeners = [];
|
|
209
211
|
const cutListeners = [];
|
|
@@ -214,6 +216,7 @@ export function localMachine(options) {
|
|
|
214
216
|
model: route.models.model,
|
|
215
217
|
tools: options.proxy.tools,
|
|
216
218
|
...(options.proxy.maxOutputTokens ? { maxOutputTokens: options.proxy.maxOutputTokens } : {}),
|
|
219
|
+
...(options.proxy.plan ? { plan: true } : {}),
|
|
217
220
|
...(search ? { webSearch: "live", ...(options.searchAllowed ? { searchAllowed: options.searchAllowed } : {}) } : {}),
|
|
218
221
|
announce: {
|
|
219
222
|
// The cost is liveness, not safety: after an overlap a never call is declined until the next single answer, which the model's
|
|
@@ -224,7 +227,10 @@ export function localMachine(options) {
|
|
|
224
227
|
open += 1;
|
|
225
228
|
announced = open > 1 ? UNWATCHED : undefined;
|
|
226
229
|
},
|
|
227
|
-
exec: (callId) =>
|
|
230
|
+
exec: (callId, input) => {
|
|
231
|
+
script = { callId, input: input ?? "" };
|
|
232
|
+
announced = open > 1 || announced === UNWATCHED ? UNWATCHED : callId;
|
|
233
|
+
},
|
|
228
234
|
failed: () => void (announced = UNWATCHED),
|
|
229
235
|
end: () => void (open = Math.max(0, open - 1)),
|
|
230
236
|
},
|
|
@@ -233,11 +239,14 @@ export function localMachine(options) {
|
|
|
233
239
|
model: route.models.model,
|
|
234
240
|
origin: route.target,
|
|
235
241
|
credential: async () => (await route.credential()) ?? "",
|
|
242
|
+
...(options.proxy.credentialRefused ? { credentialRefused: options.proxy.credentialRefused } : {}),
|
|
236
243
|
...(price ? { price } : {}),
|
|
237
244
|
...(options.proxy.log ? { log: options.proxy.log } : {}),
|
|
238
245
|
...(options.proxy.fetch ? { fetch: options.proxy.fetch } : {}),
|
|
239
246
|
// The provider stopped the turn's answer on its content filter: no retry of it can pass, so the turn ends at once.
|
|
240
247
|
onFiltered: (message) => ctx.halt?.(new Error(message)),
|
|
248
|
+
// The provider's error answer ends the run (a ChatGPT plan's limit reached): no retry or other key can pass it.
|
|
249
|
+
onFinal: (message) => ctx.halt?.(new Error(message)),
|
|
241
250
|
// The provider cut the turn's answer at its output limit: Codex would ask for it again (it retries an incomplete
|
|
242
251
|
// stream), so the harness ends the turn there, its answer cut.
|
|
243
252
|
onCut: (stop) => {
|
|
@@ -256,6 +265,7 @@ export function localMachine(options) {
|
|
|
256
265
|
modelUrl: proxy.url,
|
|
257
266
|
modelKey: key,
|
|
258
267
|
announcedExec: () => announced,
|
|
268
|
+
announcedInput: (callId) => (script?.callId === callId ? script.input : undefined),
|
|
259
269
|
onRolloutLine: (listener) => void rolloutListeners.push(listener),
|
|
260
270
|
onCut: (listener) => void cutListeners.push(listener),
|
|
261
271
|
openTurn: () => proxy.openTurn(),
|