@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 CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.38 (2026-11-14)
6
+
7
+ - 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.
8
+
9
+ Who breaks: a run parked on an MCP call at the MCP door before this version does not resume its call: cancel it and start it again. A Codex thread started before this version loses its MCP tools when it resumes (Codex resumes a thread with the dynamic tools it started with): start a new run. Code built on the kernel's MCP door breaks too. Removed: `SessionSpec.mcp`, `SessionMcp`, `McpClient`, `AdapterCapabilities` and `AgentAdapter.capabilities()`, `AdapterFacts.mcp`, `ModelProxyOptions.mcp`, `mcpRoute`, `McpHandler` and `McpRouteOptions` (`@parcha/agentrun-kernel/host`), and `McpCallResult.parked`. Hand a session its MCP tools as host tools in `SessionSpec.tools` instead.
10
+ - A provider-native web search's fee is one constant, `NATIVE_SEARCH_USD` ($0.01, $10 per 1,000), instead of three copies. The price does not change.
11
+ - Kernel: `@parcha/agentrun-kernel/host` exports `NATIVE_SEARCH_USD`. The Claude and Codex proxy policies and the runner's hosted search all read it.
12
+ - `@parcha/agentrun-harness-claude` no longer exports `CLAUDE_WEB_SEARCH_USD`; read `NATIVE_SEARCH_USD` from `@parcha/agentrun-kernel/host`.
13
+ - Every harness (pi, Claude Code, OpenCode and Codex) now offers three host tools over the run's own tools: `tools_search`, `tools_call` and `codemode`. Codex gets the first two and keeps its own code mode. With MCP servers on a Claude Code run, the CLI's own tool search is on.
14
+ - `tools_search {query, limit?}` ranks the run's tools by what they do (BM25 over each tool's description and argument words) and answers each match's name, description and input schema. It lists only tools the run may call: never one set to deny, and never the three tools themselves.
15
+ - `tools_call {name, args}` calls one of the run's tools by name. The call is asked about, recorded and booked as that tool's own call, under `<callId>/call`. An ask parks the run, and once approved the call runs once. A deny refuses it in the gate's words. A call of an unknown name, of `tools_call` itself, of `tools_search` or of `codemode` is refused in words, and nothing runs.
16
+ - `codemode {script}` runs a JavaScript script in a QuickJS sandbox. Its `await tools.<name>(args)` calls are each the run's own call, gated, recorded and booked under `<callId>/s<n>`. The sandbox has the tools and nothing else of the run: no environment, keys, files, network or timers.
17
+ - A call inside a script that needs approval follows Codex's rule. The run parks. Once a person answers, the script runs again: recorded calls answer from their records, the parked call runs once (or is refused), its outcome is the script's answer, and the rest of the script does not run.
18
+ - A call made through `tools_call` or a script answers what a direct call answers: its text and images to the model, and in a script its value (a tool's structured result, else its text). On pi the harness's own tools (an extension's, the browser's) are found and called the same way as the host's.
19
+ - A refused call inside a script ends the script with the refusal's words.
20
+ - After a crash, a call that was cut off is told as possibly done, and it is not run again.
21
+ - A paid call made through `tools_call` or a script books exactly as a direct call does: held before it is sent, under the cap, and settled once. The cap's wrap-up still refuses the model's own next call.
22
+ - The three tools' definitions ride on every model request: about 2,000 bytes, 639 tokens on Sonnet. So the smallest caps the README measures rise. A pi desktop run on Sonnet through a gateway now needs $0.07 for its first request and $0.13 for five steps in `strict` mode, or $0.07 in `expected` mode (it was $0.06, $0.12 and $0.06). Straight to Anthropic, it needs $0.04 for its first request, and five steps still need $0.09 in `strict` mode and $0.06 in `expected` mode.
23
+ - Claude Code: with an MCP server's tools on the run, the CLI runs with `ENABLE_TOOL_SEARCH=true` and its ToolSearch. The run's MCP tools reach the model through `hands` only once ToolSearch finds them, and every other tool of the session loads as before. The session's proxy admits the tool search's beta (`advanced-tool-use-2025-11-20`), ToolSearch and its placeholder. It also admits a `tool_reference` block, inside a tool result only, that names one of the session's own tools. Without MCP tools, all of these stay refused.
24
+ - A server started by `agentrun-serve` (and so by `npx agentrun`) can start a worker thread from a file. The launcher no longer passes Node `--input-type`, which a worker inherits and Node refuses. Before this, a `codemode` script there failed with "--input-type can only be used with string input via --eval, --print, or STDIN", and so did pi's code mode on a desktop or a phone.
25
+ - A capped Codex, OpenCode or pi (on OpenAI's Responses) run's next-step estimate is closer to its real input, so it pauses for a raise later and less often: the input bound counts the text the model reads (a tool's output, a message, a call's arguments) at its own bytes instead of its JSON-escaped ones, some 4 to 6% less on a code-mode body full of fetched pages, which keeps more requests under the 272k-token long-context tier where every rate doubles. On a route straight to OpenAI the input is counted exactly by OpenAI's `POST /v1/responses/input_tokens`, asked with only the credential and account headers and never through a gateway; a count that fails or takes over 3 seconds leaves the byte bound. The cap still never spends past itself: tool definitions and encrypted reasoning keep every byte.
26
+ - A long answer through an OpenAI Responses gateway that writes its JSON with spaces is priced, a request that answered while its runner's claim was lost is booked at its cost when the run resumes, and a run whose spend is unknown never reads as a full cap to its learning.
27
+ - Before, the model proxy read a long answer's usage (its terminal event longer than the 64 KiB it keeps) only when the gateway wrote `"usage":{` with no space. A Python gateway (LiteLLM's `json.dumps`) writes `"usage": {`, so such a request was booked at an unknown cost though the harness counted its tokens: the run's cost read unknown with nothing unmetered. pi on the gateway, Codex and OpenCode read the usage the same way and are all fixed. Kernel: `lastObjectOf(text, key)` reads the last `"<key>": {...}` object of a cut answer, whatever its spacing.
28
+ - Before, a runner that lost a run's claim (its lease lapsed while the box stalled) and took the run again in the same process booked a request that had answered meanwhile as cut, at an unknown cost: the lost claim's write of its cost was refused, so the resumed run read the request unanswered. The run's cost read unknown though the request reported its usage on a priced model. Kernel: `SessionWriter.scope` names a session across claims in one process (serve's `journalSessions` sets the run's id beside the key); a booking whose cost write is refused hands it to the next booking of the same scope, whose `bookCut` waits (at most 10 s) for one still in flight and writes it as it would have been written. A request with no price stays unpriced and counts for the cap at its hold. A process that died hands nothing on: its requests are booked cut, as before. A workflow run's model booking now takes them too: its claim books an earlier claim's requests before the workflow resumes, where before it never did, so a workflow's request that answered under a lost claim stayed counted at its hold.
29
+ - Before, a run cancelled or stopped while its model request was being admitted could still send that request: the proxy forwarded it after its client had left, nothing stopped it, and it was booked only once the provider ended it, after the run had ended, so the run read the request as cut at an unknown cost. The proxy now books such a request at nothing (never left) and never sends it, so a run cancelled before any request reached the model costs $0. A request that reached the model and was cut keeps the cut rule: unpriced, counted for the cap at its hold.
30
+ - Before, a capped run whose shown cost was unknown gave its learning grade a cap of $0 ("Not graded: no room under the cap.") and its look-back a reached cap. The grade's cap and the look-back now read the run's spend as its own cap gates read it: an answer with no price counts at the figure the cap held for it, never $0 and never the whole cap. Only when that figure is unknown too, the grade is not queued and says why: "Not graded: this run's spend is unknown, so its budget can't cover the grade."
31
+
32
+ ## 0.1.0-beta.37 (2026-11-13)
33
+
34
+ - Every harness sees a desktop or a phone through one surface: the tools `computer_observe`, `computer_act`, `computer_screenshot` and `computer_script`, the same answers from a script, an MCP client or a tool call. Breaking: the `desktop_*` and `phone_*` tools are gone, replaced by the `computer_*` tools (a desktop's and a phone's alike, held to the `desktop` or `phone` setting), and the script API's `apps.open(id)` returns nothing; bind the app with `computer.app(id)`.
35
+ - `computer_script` runs JavaScript in an isolate in serve whose only binding is `computer` (no network, no keys, no timers); its types are `spec/computer/computer.d.ts`, generated with the tools' schemas by `scripts/generate-computer-surface.mjs` (`--check` in CI). A model reads them compactly (no comments, one line a declaration); `computer_act`'s schema types its steps with no words, and its description declares them as TypeScript.
36
+ - A script's `computer.shell` and `computer.files` are held to the run's tool settings as the `bash`, `write` and `read` tools are (a deny or a read-only bash policy refuses inside the script; a setting that asks refuses, since a script can't wait for a person), and a refused step throws in the script, so the steps after it never run. Without the ui group a scroll goes as wheel clicks (about 120 pixels each), which every driver takes.
37
+ - pi offers its code mode (`codemode`) beside its tools with a desktop or a phone, `computer` bound in its scripts; the call is held to the computer kind's setting.
38
+ - In Codex's code mode a script's call of a computer tool answers the tool's value as JSON, its images' data in it; any other tool answers its words and a line saying its images were not sent (in code mode an image reaches a script only as text). A call a script repeats after a restart, of a computer tool that completed, gets that same JSON again.
39
+ - agentrun-serve's `computerMcp` serves a run's computer tools to an MCP client, each answer with `structuredContent`.
40
+ - The desktop-computer and phone-computer skills teach the route: observe, act by ref, check, and one script for steps already known.
41
+ - A web search on a GPT-6 model (gpt-6-luna, gpt-6.1-sol, gpt-6.1-terra) is booked at OpenAI's $0.01 a call, as on GPT-5. Before, its search had no known price. A pi run's native web_search on a GPT-6 model under any spend cap was refused before it was sent ("the size of the next model request's input is unknown, so the run's cap cannot be kept"). A Codex run with `webSearch: "live"`, or an uncapped pi run, booked an unknown cost for any response that searched.
42
+ - A web_search setting of deny or ask now applies to a Claude Code or Codex run's own web search at its next search, including a run that started while it was allow. Before, the setting was read only when the run started, so a run that started with native search kept searching after the setting changed.
43
+ - Claude Code: each WebSearch asks the run's gate before it runs, as a host tool's call does. A deny refuses it in the gate's words. An ask parks the run on the person with nothing searched; once they allow it, the model's next search with the same query runs once, with no second card.
44
+ - Codex: its search runs inside the provider's model request, so its proxy reads web_search's setting before each request and offers the provider its search only while the setting is allow. A failed read offers no search.
45
+ - `SessionIO.permission(tool)` (agentrun-kernel) is the host's setting for a harness's own tool at the time of the read. The runner reads it from the store each time. `ProviderPolicy.apply` may return a promise.
46
+ - A runner run whose plane resolves web_search to native now gets the harness's own search (#2458). The runner had built the run's environment without its plane, so Claude Code and Codex runs on a runner never had it on.
47
+ - A web_search that resolves to the model provider's own search works again on the runner for pi (#2458). It used to answer "web_search has no model to search on" every time:
48
+ - A pi run's own web_search on an Anthropic or OpenAI model. That is what `auto` picks for pi, and `native` too. Each search now goes through the run's model proxy with the provider's search tool, and its searches are booked at the provider's price on top of its tokens.
49
+ - A learned workflow's call node whose web_search resolves native, on any harness.
50
+
51
+ Each run's search uses that run's own model route, never one shared by the whole process. Hand-written workflow agents were not affected: their web_search never resolves native. Both harness packages now export their `withWebSearches` price wrapper, and the Codex one its `webSearchUsd`. A claude-agent or codex run's own search is not switched on by this change.
52
+
53
+ A capped run holds a hosted search's fees with its tokens before the request is sent, at the most searches the request allows, so the fees can't pass the cap. The kernel's model proxy takes a policy's `feeMaxUsd(body)` and holds it as the request's `feeUsd`; a fee it can't bound leaves the request unmeasured. The proxy also hands `usageOf` the sent body as a second argument, so a pi request on OpenAI's Responses that offered no search reads 0 searches from its body, even when its answer names a search call.
54
+
5
55
  ## 0.1.0-beta.36 (2026-11-13)
6
56
 
7
57
  - Model defaults move to the current models. The OpenAI default (and OpenRouter's, for pi, codex and opencode) is now gpt-6.1-sol, where OpenRouter's was gpt-6-sol. The Claude Agent adapter's default is now claude-sonnet-5-5 (was claude-sonnet-4-5) and the Codex adapter's is openai/gpt-6-luna (was openai/gpt-5.4-mini). A host that relied on a default names its model; the READMEs' examples name the current ones.
package/README.md CHANGED
@@ -22,7 +22,12 @@ const runNode = createHarnessRunner(
22
22
  is not sent, so the model is never told its files are read-only while the host's tools write them
23
23
  (`test/developer-messages.test.mjs`). A classic model is offered exactly the host's tools (and the runner's
24
24
  `submit`); a code-mode model is offered code mode's `exec` and `wait`, whose runtime has no Node modules, no process and no network, and
25
- reaches the host's tools by their own names, as nested calls of the script it writes. The proxy passes `exec` and
25
+ reaches the host's tools by their own names, as nested calls of the script it writes. A nested call of a computer tool
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
+ 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
+ as text (`test/code-mode-images-taken.test.mjs`). Codex's runtime takes no
29
+ binding of ours, so a script that wants the `computer` object itself calls `computer_script`, which runs in the host's
30
+ isolate with `computer` bound. The proxy passes `exec` and
26
31
  `wait` and drops the sub-agent and user-input tools Codex lists beside them; it keeps parallel tool calls off for a
27
32
  code-mode request, and offers no `exec` while a script that yielded still runs, so one script is live at a time. A
28
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
@@ -44,11 +49,9 @@ const runNode = createHarnessRunner(
44
49
  Each search a response ran (`tool_usage.web_search.num_requests`) is added to its price at OpenAI's $0.01 a call; a
45
50
  model with no known search price books an unknown cost. A request that offers web search has no input bound, so a cap
46
51
  treats its input as unknown.
47
- - **Remote MCP servers, when granted.** A session given `spec.mcp` (a host's MCP gateway) writes each server in Codex's
48
- `mcp_servers` at the proxy's `/mcp/<server>`, with the proxy key as Codex's bearer, only the granted tools enabled,
49
- approve mode and `required = true`; the proxy admits those tools in the `mcp__<server>` namespace Codex sends them in.
50
- Codex sends a call without waiting for the session, so the proxy holds it until its line (a script's nested call: its
51
- script's) is in the log, records its intent and only then sends it, through the host's gateway (`src/mcp.ts`).
52
+ - **Remote MCP tools are host tools.** Codex refuses a dynamic tool named `mcp` or `mcp__*` at `thread/start`, so a
53
+ host tool named `mcp__<server>__<tool>` reaches Codex as `mcp_<server>__<tool>`; the session maps the name back for
54
+ the host's gate and its events. Two tools that would reach Codex by one name are refused when the session is checked.
52
55
  - **A private machine.** A session runs in its own directories. Its working directory is the host's workspace when the
53
56
  host names one (`io.cwd`, where the host's file tools write, an untrusted project to Codex), and otherwise an empty
54
57
  directory of the session's. Codex keeps nothing there, and takes no instructions from an `AGENTS.md` in it
package/dist/adapter.d.ts CHANGED
@@ -4,6 +4,13 @@ import { type HostTool as KernelTool } from "@parcha/agentrun-kernel/kernel";
4
4
  import { NativeJournal } from "@parcha/agentrun-kernel/process";
5
5
  import { type ConfineChild } from "./host/machine.js";
6
6
  import { type ModelProxyOptions } from "@parcha/agentrun-kernel/host";
7
+ /**
8
+ * The name Codex is given a host tool by. App-server reserves `mcp__` names for its own MCP client's tools and refuses a
9
+ * dynamic tool so named at the thread's start (`dynamic tool name is reserved`, 0.164.0, #1586), so a run's MCP tool
10
+ * (`mcp__<server>__<tool>`), a host tool like any other, is offered as `mcp_<server>__<tool>`. Every other name is
11
+ * as given. Inside the session only: the host's gate and the session's events name the call by the host's name.
12
+ */
13
+ export declare const codexToolName: (name: string) => string;
7
14
  /**
8
15
  * Codex's `tool_output_token_limit`: the host's result bound (HOST_RESULT_MAX_CHARS), as Codex counts it. Codex keeps a
9
16
  * tool's output in the model's history within its truncation policy (10,000 tokens for each model its catalog holds, less
package/dist/adapter.js CHANGED
@@ -15,7 +15,6 @@ import { HOST_RESULT_MAX_CHARS, READ_SKILL_FILE, hostedTool, readSkillFileTool,
15
15
  import { abortedOutcome, openDrive, SessionHalt } from "@parcha/agentrun-kernel/kernel";
16
16
  import { pendingSubmissions } from "@parcha/agentrun-kernel/kernel";
17
17
  import { NativeJournal, recoveryNote, settleTurn, transcriptOf } from "@parcha/agentrun-kernel/process";
18
- import { CODEX_MCP_CLIENT } from "./mcp.js";
19
18
  import { codexSchemaProblems, describedDescription } from "./schema.js";
20
19
  import { markParked } from "./scripts.js";
21
20
  import { withCheckedBinary } from "./host/sandbox.js";
@@ -28,6 +27,13 @@ import { codexPolicy, withWebSearches } from "./host/policy.js";
28
27
  import { toolImageProblems } from "./tool-images.js";
29
28
  /** A name app-server accepts for a dynamic tool. */
30
29
  const TOOL_NAME = /^[A-Za-z0-9_-]{1,64}$/;
30
+ /**
31
+ * The name Codex is given a host tool by. App-server reserves `mcp__` names for its own MCP client's tools and refuses a
32
+ * dynamic tool so named at the thread's start (`dynamic tool name is reserved`, 0.164.0, #1586), so a run's MCP tool
33
+ * (`mcp__<server>__<tool>`), a host tool like any other, is offered as `mcp_<server>__<tool>`. Every other name is
34
+ * as given. Inside the session only: the host's gate and the session's events name the call by the host's name.
35
+ */
36
+ export const codexToolName = (name) => (name.startsWith("mcp__") ? `mcp_${name.slice("mcp__".length)}` : name);
31
37
  /**
32
38
  * Codex's `tool_output_token_limit`: the host's result bound (HOST_RESULT_MAX_CHARS), as Codex counts it. Codex keeps a
33
39
  * tool's output in the model's history within its truncation policy (10,000 tokens for each model its catalog holds, less
@@ -42,43 +48,49 @@ export const CODEX_TOOL_OUTPUT_TOKENS = Math.ceil((HOST_RESULT_MAX_CHARS * 3) /
42
48
  * line before it runs such a tool is a second guard (the transcript Codex resumes from), not the one that protects it. */
43
49
  export function kernelTool(tool) {
44
50
  return {
45
- name: tool.name,
51
+ name: codexToolName(tool.name),
46
52
  // Codex strips some keywords from the schema its model is given: they are said in plain words in the description
47
53
  // (the schema itself is the host's, and every call is checked against it).
48
54
  description: describedDescription(tool.description, tool.inputSchema),
49
55
  inputSchema: tool.inputSchema,
50
56
  replay: tool.replay,
57
+ ...(tool.nests ? { nests: true } : {}),
58
+ ...(tool.deferred ? { deferred: true } : {}),
51
59
  async execute(input, io) {
52
60
  // The effect's step is `tool:<Codex call id>#<attempt>`: the host sees Codex's call id.
53
61
  const callId = (io.stepId ?? "").replace(/^tool:/, "").replace(/#\d+$/, "");
54
62
  // The step's attempt: above 0 when a crash cut an earlier attempt and the kernel runs the call again.
55
63
  const attempt = Number(/#(\d+)$/.exec(io.stepId ?? "")?.[1] ?? 0);
56
- const result = await tool.call(input, { callId, signal: io.signal, attempt });
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 } : {}) });
57
67
  // A call the host parked for a person's approval did not run: recorded so before its answer, the waiting text.
58
68
  if (result.parked)
59
69
  await markParked(io.ctx, callId);
60
70
  if (result.isError)
61
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 } : {};
62
74
  if (!result.images?.length)
63
- return result.text;
75
+ return result.structured === undefined ? result.text : { text: result.text, ...structured };
64
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.
65
77
  const wrong = toolImageProblems(tool.name, result.images);
66
78
  if (wrong)
67
79
  throw new Error(wrong);
68
80
  // With its images, recorded with the outcome: the answer to Codex carries them after the text (code-mode.ts withImages).
69
- return { text: result.text, images: result.images.map((image) => ({ mimeType: image.mimeType, data: image.data })) };
81
+ return { text: result.text, images: result.images.map((image) => ({ mimeType: image.mimeType, data: image.data })), ...structured };
70
82
  },
71
83
  };
72
84
  }
73
- /** The adapter's event for a harness live event, if it has one. */
74
- function adapterEvent(event) {
85
+ /** 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
+ function adapterEvent(event, hostName) {
75
87
  const e = event;
76
88
  if (e?.type === "text" && typeof e.delta === "string")
77
89
  return { type: "text", delta: e.delta };
78
90
  if (e?.type === "tool_start" && typeof e.name === "string")
79
- return { type: "tool_start", callId: String(e.callId ?? ""), name: e.name, args: e.args };
91
+ return { type: "tool_start", callId: String(e.callId ?? ""), name: hostName(e.name), args: e.args };
80
92
  if (e?.type === "tool_end" && typeof e.name === "string")
81
- return { type: "tool_end", callId: String(e.callId ?? ""), name: e.name, isError: e.isError === true, ...(e.truncated === true ? { truncated: true } : {}) };
93
+ return { type: "tool_end", callId: String(e.callId ?? ""), name: hostName(e.name), isError: e.isError === true, ...(e.truncated === true ? { truncated: true } : {}) };
82
94
  return undefined;
83
95
  }
84
96
  const turnsIn = (drive) => transcriptOf(drive.state()).filter((r) => r.data?.type === "turn");
@@ -119,20 +131,25 @@ export function codexAdapter(options) {
119
131
  };
120
132
  return {
121
133
  id: "codex",
122
- capabilities: () => ({ mcpClient: CODEX_MCP_CLIENT }),
123
134
  check(spec) {
124
135
  const problems = [];
125
136
  if (spec.context === "fork")
126
137
  problems.push("Codex sessions cannot fork another session's transcript; declare context: \"fresh\"");
127
- const seen = new Set();
138
+ // Each tool by the name Codex is given it (codexToolName): two that would reach Codex by one name are refused.
139
+ const seen = new Map();
128
140
  for (const tool of spec.tools) {
141
+ const given = codexToolName(tool.name);
129
142
  if (!TOOL_NAME.test(tool.name))
130
143
  problems.push(`the tool name ${JSON.stringify(tool.name.slice(0, 80))} is not one Codex accepts (letters, digits, _ and -, at most 64)`);
131
- if (seen.has(tool.name))
144
+ const twin = seen.get(given);
145
+ if (twin === tool.name)
132
146
  problems.push(`the tool ${tool.name} is given twice`);
133
- if (skills.length && tool.name === READ_SKILL_FILE)
147
+ else if (twin !== undefined)
148
+ problems.push(`the tools ${twin} and ${tool.name} both reach Codex as ${given}`);
149
+ if (skills.length && given === READ_SKILL_FILE)
134
150
  problems.push(`the tool name ${READ_SKILL_FILE} is the adapter's own when it has skills`);
135
- seen.add(tool.name);
151
+ if (twin === undefined)
152
+ seen.set(given, tool.name);
136
153
  // What no harness takes (an object root, valid 2020-12, no remote $ref), then what Codex would drop or retype in
137
154
  // the tool's schema: refused here, by name, not found out mid-turn. A place the first already refused is not
138
155
  // refused again by the second.
@@ -160,11 +177,17 @@ export function codexAdapter(options) {
160
177
  throw new Error("agentrun-harness-codex: a session needs a private directory: the host lends one (io.dir), or pass sessionsDir");
161
178
  // With skills the model also reads their files (read_skill_file), from the session's own copy of them.
162
179
  const tools = skills.length ? [...spec.tools, hostedTool(io, readSkillFileTool(join(sessionDir(dir, "codex-home"), SKILLS_DIR), skills.map((skill) => ({ name: skill.name, files: Object.keys(skill.files) }))))] : spec.tools;
180
+ // The host's name for each tool as Codex calls it: the gate and the session's events name a call by it.
181
+ const hostNames = new Map(tools.map((t) => [codexToolName(t.name), t.name]));
182
+ const hostName = (name) => hostNames.get(name) ?? name;
163
183
  const effort = spec.effort ?? spec.thinking;
184
+ // The live search runs inside a model request, where no call reaches the gate: it is offered only while the host's
185
+ // web_search setting allows it, read before each request (a deny or ask set mid-run drops it from the next one).
186
+ const searchAllowed = options.webSearch && io.permission ? async () => (await io.permission("web_search")) === "allow" : undefined;
164
187
  const harnessOptions = {
165
188
  tools: tools.map(kernelTool),
166
189
  // The host's gate, asked about each host-tool call before its intent is written.
167
- ...(io.gate ? { gate: (call) => io.gate(call) } : {}),
190
+ ...(io.gate ? { gate: (call) => io.gate({ ...call, tool: hostName(call.tool) }) } : {}),
168
191
  builtins: false,
169
192
  // Codex's bundled skills (imagegen, skill-installer, ...), which it writes under `$CODEX_HOME/skills/.system` at every
170
193
  // start, are off in every session, skills or not: the model is shown the host's skills and no others.
@@ -192,12 +215,10 @@ export function codexAdapter(options) {
192
215
  // The built-ins are off: Codex's own apply_patch, with no environment to run in, is offered to no model
193
216
  // (catalog.ts). A stand-in runs no Codex, so it has no catalog to read.
194
217
  ...(checked !== undefined ? { catalog: { command: checked, ...(options.log ? { log: options.log } : {}) } } : {}),
195
- ...(options.webSearch ? { webSearch: options.webSearch } : {}),
196
- // A granted MCP server's tools: Codex's own MCP client calls them at the proxy (mcp.ts).
197
- ...(spec.mcp?.servers.length ? { mcp: spec.mcp } : {}),
218
+ ...(options.webSearch ? { webSearch: options.webSearch, ...(searchAllowed ? { searchAllowed } : {}) } : {}),
198
219
  proxy: {
199
220
  hooks: io.models,
200
- tools: tools.map((t) => t.name),
221
+ tools: tools.map((t) => codexToolName(t.name)),
201
222
  ...(options.log ? { log: options.log } : {}),
202
223
  ...(options.price ? { price: options.price } : {}),
203
224
  ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}),
@@ -208,7 +229,7 @@ export function codexAdapter(options) {
208
229
  };
209
230
  const harness = checked === undefined ? codexHarness(harnessOptions) : withCheckedBinary(checked, () => codexHarness(harnessOptions));
210
231
  const live = (event) => {
211
- const mapped = adapterEvent(event);
232
+ const mapped = adapterEvent(event, hostName);
212
233
  if (mapped)
213
234
  io.onEvent(mapped);
214
235
  };
@@ -275,7 +296,7 @@ export function codexAdapter(options) {
275
296
  // Started once the session's drive is open, the last step that can fail: an open that fails leaves no listener.
276
297
  const search = options.webSearch === "live";
277
298
  const hostPort = await startModelProxy({
278
- policy: codexPolicy({ model: modelFor(spec), tools: [], ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}), ...(search ? { webSearch: "live" } : {}) }),
299
+ policy: codexPolicy({ model: modelFor(spec), tools: [], ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}), ...(search ? { webSearch: "live", ...(searchAllowed ? { searchAllowed } : {}) } : {}) }),
279
300
  hooks: io.models,
280
301
  model: modelFor(spec),
281
302
  origin: options.provider.origin,
@@ -5,6 +5,9 @@ import { type RolloutSummary } from "./rollout.js";
5
5
  export declare const NESTED_STREAM = "codex.nested";
6
6
  /** The stream that records the interrupted turns whose recovery note was injected: `{ since }`, once per interrupted turn. */
7
7
  export declare const RECOVERY_NOTE_STREAM = "codex.recovery-note";
8
+ /** A yielded exec's nested call run on a resume (recoverItems), written before it runs: a later recovery of the same turn tells
9
+ * the model's `wait` its outcome from the session's record, never running it again. */
10
+ export declare const RESUMED_STREAM = "codex.nested-resumed";
8
11
  interface Journal {
9
12
  append(stream: string, record: unknown): void;
10
13
  flush(): Promise<void>;
@@ -20,16 +23,24 @@ export interface CodeModeDeps {
20
23
  logged: Set<string>;
21
24
  /** Drain the rollout's tail into the log. */
22
25
  synced(): Promise<void>;
23
- /** The tool bridge; `takeImages` gives a call's images once (host/process.ts), for the answer to Codex. */
26
+ /** The tool bridge; `take` gives a call's images and value once (host/process.ts), for the answer to Codex. */
24
27
  bridge: {
25
28
  get(name: string): {
26
29
  name: string;
27
30
  replay: string;
28
31
  } | undefined;
29
- takeImages?(callId: string): readonly {
30
- mimeType: string;
31
- data: string;
32
- }[] | undefined;
32
+ take?(callId: string): {
33
+ images?: readonly {
34
+ mimeType: string;
35
+ data: string;
36
+ }[];
37
+ structured?: unknown;
38
+ } | undefined;
39
+ /** A call through the bridge (gate, intent, call, result): a resumed nested call that never reached its intent (recoverItems). */
40
+ call?(name: string, args: unknown, callId: string): Promise<{
41
+ text: string;
42
+ isError: boolean;
43
+ }>;
33
44
  };
34
45
  log(message: string, fields?: Record<string, unknown>): void;
35
46
  /** The rollout lines restored from the log. */
@@ -63,10 +74,25 @@ export declare const waitStoppedText: (cell: string) => string;
63
74
  /** A recorded result that held images (kernelTool's `{ text, images }`) as its text and a line saying how many, which are not
64
75
  * shown again after the interruption; undefined for a result with none, whose repaired output stays as it is. */
65
76
  export declare function imagesNoted(output: unknown): string | undefined;
66
- /** A code-mode script's nested call's answer: its items, then a line saying how many images the tool returned, which are
67
- * not sent (Codex gives a script an image as its data: URL in the result's text); an answer of any other shape, or no
68
- * images, as it is. */
77
+ type Image = {
78
+ mimeType: string;
79
+ data: string;
80
+ };
81
+ /** `value` with `images`' data put back, in order, into its image objects (`{ type: "image", mimeType }` with no data,
82
+ * as a computer tool's value leaves them): the value whole, as serve's own script isolate gives a script. */
83
+ export declare function withImageData(value: unknown, images: readonly Image[]): unknown;
84
+ /** A nested call's answer from a tool with no value: its items, then a line saying how many images the tool returned,
85
+ * 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
86
+ * result would send the model the base64 as words); an answer of any other shape, or no images, as it is. */
69
87
  export declare function withImagesHeld(answer: unknown, images: readonly unknown[] | undefined): unknown;
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 declare function scriptAnswer(answer: unknown, extras: {
93
+ images?: readonly Image[];
94
+ structured?: unknown;
95
+ } | undefined): unknown;
70
96
  /** A dynamic tool call's answer with `images` after its items, each `{ type: "inputImage", imageUrl }` with a data: URL
71
97
  * (Codex 0.164's DynamicToolCallOutputContentItem); an answer of any other shape, or no images, as it is. */
72
98
  export declare function withImages(answer: unknown, images: readonly {
@@ -83,8 +109,9 @@ export declare function codeMode(deps: CodeModeDeps): {
83
109
  * 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
84
110
  * 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
85
111
  * 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
86
- * both repairs (with a recovery note and without) inject what this leaves. */
87
- recoverItems(items: Record<string, unknown>[], dangling: readonly Dangling[], lines: readonly string[], since: number): Promise<void>;
112
+ * both repairs (with a recovery note and without) inject what this leaves. `resume`: the open turn a recovery note resumes, whose
113
+ * parked nested calls run now; the repair of an ended turn (repairUnnoted) only tells, and runs nothing. */
114
+ recoverItems(items: Record<string, unknown>[], dangling: readonly Dangling[], lines: readonly string[], since: number, resume?: boolean): Promise<void>;
88
115
  /** 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
89
116
  * them (one interrupted mid-call, or settled instead of resumed) left them dangling, and the provider refuses a history with a call unanswered.
90
117
  * Nothing is armed here: a new turn that calls a `never` call the ended turn completed runs it. */