@parcha/agentrun-harness-codex 0.0.0-stage → 0.1.0-beta.29
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 +58 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +72 -2
- package/dist/adapter.d.ts +59 -0
- package/dist/adapter.js +276 -0
- package/dist/app-server.d.ts +53 -0
- package/dist/app-server.js +105 -0
- package/dist/binary.d.ts +31 -0
- package/dist/binary.js +74 -0
- package/dist/code-mode.d.ts +90 -0
- package/dist/code-mode.js +204 -0
- package/dist/config.d.ts +81 -0
- package/dist/config.js +208 -0
- package/dist/harness.d.ts +200 -0
- package/dist/harness.js +1100 -0
- package/dist/host/kernel.d.ts +20 -0
- package/dist/host/kernel.js +3 -0
- package/dist/host/machine.d.ts +58 -0
- package/dist/host/machine.js +284 -0
- package/dist/host/policy.d.ts +60 -0
- package/dist/host/policy.js +478 -0
- package/dist/host/process.d.ts +145 -0
- package/dist/host/process.js +28 -0
- package/dist/host/sandbox.d.ts +35 -0
- package/dist/host/sandbox.js +34 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6 -0
- package/dist/rollout.d.ts +102 -0
- package/dist/rollout.js +185 -0
- package/dist/schema.d.ts +14 -0
- package/dist/schema.js +178 -0
- package/dist/scripts.d.ts +94 -0
- package/dist/scripts.js +162 -0
- package/dist/verify.d.ts +37 -0
- package/dist/verify.js +67 -0
- package/dist/versions.d.ts +33 -0
- package/dist/versions.js +57 -0
- package/package.json +68 -4
- package/vendor/durable-harness/UPSTREAM.json +39 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
## 0.1.0-beta.29 (2026-11-04)
|
|
6
|
+
|
|
7
|
+
- **The Codex adapter takes the host's skills, and its sessions no longer see Codex's bundled ones**
|
|
8
|
+
- `codexAdapter({ skills: [{ name, files }] })`: Codex lists each skill to the model by its name and description, and the model reads its `SKILL.md` and its other files with `read_skill_file`, the shared read-only host tool (Codex has no shell here). The skills are written into each session's `CODEX_HOME` at the start of every drive, where Codex lists a user's skills in a turn with its built-ins off; it lists none from a working directory's `.agents/skills` there. A host tool named `read_skill_file` is refused when the adapter has skills.
|
|
9
|
+
- Codex's bundled skills (imagegen, openai-docs, skill-creator, skill-installer) are off in every Codex session, with skills or without (`[skills.bundled] enabled = false`). Before, Codex installed them at every start and listed them to the model, so a session was shown skills its host never gave it.
|
|
10
|
+
- The skills are checked when the adapter is made, and a bad one throws before the binary is looked for. The check, `skillProblems`, and the skill's shape, `HostSkill`, are now in `@parcha/agentrun-kernel` beside `readSkillFileTool`. The Claude adapter's `skillProblems` and `ClaudeAgentSkill` are that check and shape, re-exported, so nothing changes for its users; the Codex adapter exports the same `skillProblems`.
|
|
11
|
+
- The local Codex machine takes a seed of files for one of its private directories (`seed: { dir, files }`, each file's text by its relative path), written at acquire and again after every wipe. A path that is absolute, empty, climbs or starts with a dot, or a directory not the machine's own, is refused when the machine is made.
|
|
12
|
+
- The Codex adapter says what Codex 0.164.0 does to a tool's schema, so no difference is silent. Codex sanitizes the schema its model is given: it strips bounds, patterns, formats, titles, defaults and a few annotations, and it drops or retypes a few shapes (a tuple `items`, `prefixItems`, `patternProperties`, `if`/`then`/`else`, `not`, a non-scalar or untyped non-string `enum`/`const`, `contains`, `dependentRequired`, `propertyNames`, a boolean `items`, constraints inside `allOf`). Checking a session now refuses each of those shapes by tool, JSON pointer and keyword, before anything is paid. For the stripped keywords, the tool's description lists them in plain words under one fixed heading, sorted by pointer, so the model still reads them; the host and the DSL keep checking against the original schema. The measurement is recorded for the public schema corpus and replayed offline.
|
|
13
|
+
- A Codex session can turn on Codex's own web search, live: `codexAdapter({ webSearch: "live" })` sets `web_search = "live"` in Codex's config, and the session's model proxy admits exactly the hosted `web_search` tool the pinned binary then sends (and a `tool_choice` naming it) and refuses any other web search tool; every other hosted tool is dropped or refused as before. Each search a response ran (its `tool_usage.web_search.num_requests`) is added to the response's price at OpenAI's $10 per 1,000 calls, so it counts in the session's cost and the host's budget; a model with no known search price, or a response that does not say how many searches it ran, is booked at an unknown cost. A request that offers web search has no input bound (a search's content is billed as input), so a cap that holds each request's worst case treats its input as unknown. Off by default, and off is unchanged. `CodexWebSearch` is the option's type.
|
|
14
|
+
- The harness packages are published from this release under their final names: `@parcha/agentrun-adapters` is `@parcha/agentrun-kernel`, `@parcha/agentrun-claude-agent` is `@parcha/agentrun-harness-claude`, `@parcha/agentrun-codex` is `@parcha/agentrun-harness-codex`. Their subpaths, directories, harness ids and `AGENTRUN_*` environment variables do not change.
|
|
15
|
+
- Messages these packages raise start with `agentrun-kernel:`, `agentrun-harness-claude:`, `agentrun-harness-codex:`.
|
|
16
|
+
- New package `@parcha/agentrun-harness-codex`, held (not on npm yet): Codex as an AgentRun harness. `codexAdapter(options)` is an `AgentAdapter`, so `createHarnessRunner(codexAdapter(...), { store, tools })` runs a DSL `agent` node on Codex 0.164.0's app-server.
|
|
17
|
+
- Codex's built-in tools are off. A classic model is offered exactly the host's tools and `submit`; a code-mode model is offered code mode's `exec` and `wait`, which reach the host's tools by their own names. A test runs the pinned binary against a scripted model that calls every built-in and checks that nothing runs, writes or spawns.
|
|
18
|
+
- Codex's model traffic goes through a per-session proxy on the loopback interface that holds the provider key, forwards only `POST /v1/responses`, fixes the model, stores nothing at the provider, drops Codex's own web search and every tool that is not the session's (refusing any other provider-hosted tool), and asks the runner before every paid request.
|
|
19
|
+
- The adapter checks the Codex binary it will run against the pins when it is made: the platform package's version, the binary's sha256 and the version it reports. A mismatch or a missing binary is a typed error. A relative `CODEX_BIN` is resolved from the host's working directory, and that absolute path is the one checked and run.
|
|
20
|
+
- Codex runs in the session's own directories with an empty working directory and an allowlisted environment.
|
|
21
|
+
- Sessions are durable in the store the host lends: a session a process died inside resumes from its records, and a `never` tool's cut-off call is reported, never repeated, and a call delivered twice runs its tool once.
|
|
22
|
+
- A spend cap below one request's worst case at its model's output ceiling no longer refuses the run before it starts. Each request is limited to the output tokens what is left of the cap can buy, thinking included, and held at that, so the cap stays exact. A request is refused only when what is left cannot buy its least: 1,024 tokens for its answer, plus its thinking's least when it thinks. A $0.50 cap on Claude Sonnet now runs; before, any cap under about $1.30 could never send a request.
|
|
23
|
+
- A refusal says, in plain words, what the run spent of its cap, what its next request needs and the cap that would run it ("Not sent: ... Raise the cap to at least $0.48 to run it."), on the run's error and its timeline row, after the code `spend_cap_reached (out of budget): `, which pi-ai's retry takes as final. A request the cap refused counts as no model request in the run's usage, on every harness; a run whose only request was refused says "no model request sent". A reply the limit cut short says so on the run's timeline.
|
|
24
|
+
- The model proxy asks the host with a request's own output limit and its least (`outputTokensAsked`, `outputTokensLeast`), and writes the admitted limit (the ticket's `outputTokensMax`) into its body through a policy's new `limitOutput`; it never sends a request unlimited that was admitted with a limit, nor a body longer than the one its input was measured on. The runner's `beforeRequest` may answer `outputTokensMax` beside `holdUsd`, and holds each request in flight at the limit it was admitted with; a limit that is no whole number of tokens above 0 refuses the request, never sends it unlimited.
|
|
25
|
+
- A turn that a halt ended with a reason now ends `failed`, naming it, never `interrupted` with the reason dropped: a harness's spend cap, its transcript mirror, a refused spawn. Only the session's own stop (its interrupt or its close, told apart by identity with the kernel's `SessionHalt`) and its host's stop end a turn `interrupted`. `abortedOutcome` decides it, and both adapters use it. This changes how spend-cap and mirror halts end a turn: a host that read `interrupted` for them now reads `failed` with the reason.
|
|
26
|
+
- A model that runs its tools in code mode, such as gpt-6-sol, now runs on the Codex adapter; it was refused before any request. The adapter no longer reads the binary's model catalog or refuses a code-mode model when a session is checked, and the proxy passes Codex's `exec` and `wait` (and drops the sub-agent and user-input tools listed beside them, and refuses a code-mode request that allows parallel tool calls). A host tool the script calls arrives as a nested call under an id of Codex's own, which no line of the session's log carries, so a `never` tool called that way was declined for good; it now runs once, as soon as the `exec` it runs under is in the log.
|
|
27
|
+
- After a crash, a host tool's call that was cut off is told to Codex by the replay policy the run's log recorded when it started, as the recovery note of the same turn tells it. Before, the output Codex got for a `safe` call said it may have taken effect, while the note said it was safe to repeat: the drive that opens after a crash marks a safe call for a retry, which the output's own rule did not count as interrupted.
|
|
28
|
+
- A Codex session no longer tells the model its files are read-only. Codex sent a `<permissions instructions>` developer message ("`sandbox_mode` is `read-only`: The sandbox only permits reading files") about its own sandbox, which binds only its built-in tools, and those are off. The host's tools write. A model that believed the message refused to write at all and ended its turn with no tool call. The adapter now sets `include_permissions_instructions = false`. Codex's sandbox itself stays read-only.
|
|
29
|
+
- A model Codex's catalog marks multi-agent V2 (luna, sol) is no longer told it can spawn sub-agents. `multi_agent = false` turns off only V1, so Codex still built V2's collaboration tools, which the model proxy dropped, and sent `<multi_agent_role>` and `<multi_agent_mode>` messages describing them. The config now sets `[agents] enabled = false`, which turns off both versions.
|
|
30
|
+
- `CODEX_INSTALL` is exported: the pinned install line (`npm install --save-exact @openai/codex@<version>`) that `CodexNotInstalled` names, so a host can print it without copying its format.
|
|
31
|
+
- Codex dies with the process that started it. The session machine starts Codex with a watch on its parent (the host's `parentWatched`, inside the host's confinement), so a host that is SIGKILLed and runs no close leaves no Codex behind, on a box with or without `setpriv`. A confinement prefix must exec Codex in place, as `setpriv` does: a wrapper that forks and stays as the parent defeats the watch.
|
|
32
|
+
- A call that Codex's rollout holds with no output now gets one from the log whenever a thread resumes, before any turn is sent, and not only under a recovery note. A turn that ended without answering a call (one interrupted mid-call, or settled instead of resumed) left it unanswered, and the next turn's history, with a call left open, was refused by the provider. A cut-off code-mode `exec` is answered first, as a custom tool output built from its nested calls. Every other call gets the generic output, of the kind the call asks for: a custom tool call such as Codex's own `apply_patch` gets a custom tool call output, and a host tool that happens to be named `exec` is answered as the function call it is. A `never` call the ended turn completed is answered as recorded only when a recovery note resumes that turn; a new turn that calls it again runs it. A `wait` of code mode that was waiting on a cell when the session stopped is told so, and that the cell's script was cut off, not that it never started.
|
|
33
|
+
- `codexAdapter` refuses a `webSearch` other than `"live"` with a `TypeError` that names the package as its other errors do, `agentrun-harness-codex: webSearch is "live" or absent`; it began `agentrun-codex:`, the package's name before the rename.
|
|
34
|
+
- Checking a harness's binary against its pins no longer reads the whole binary into memory, and runs once per binary in a process. `verifyCodexBinary` (the codex binary, 294 MiB) and `verifyClaudeAgentCli` (claude-agent's CLI, 231 MiB) each read the file whole to hash it, and agentrun-serve checked each again for every model it resolved: twice per harness in its start's probe, then once per save and once per run check, and a run's own process once more when it made its adapter. One start probe peaked at 395 MiB of memory, 675 MiB with a default model, past a 512 MiB container's limit. The hash now reads 1 MiB at a time, and a check that passed is kept for the process while the binary stays the same file (its path, device, inode, size, and modification and change times, with the pins); touched or replaced, it is checked again, and a failed check is never kept. The kernel's `@parcha/agentrun-kernel/host` exports both parts, `sha256OfFile` and `checkedOnce`.
|
|
35
|
+
- A claude-agent or codex run works in the run's workspace, the directory its file tools write to. Before, the CLI's working directory was an empty one beside it (`runs/<id>/harness/work`): Claude told its model that path, so a file written at its absolute path was refused as "outside the workspace", and the answer quoted the server's data directory. In QA this happened in 3 of 4 Claude runs that wrote a file.
|
|
36
|
+
- `SessionIO.cwd`: a host may name the session's working directory, its workspace. The Claude and Codex adapters run their CLI there, and keep their own state in the session's private directory as before. git stops at the workspace's parent. serve passes the run's `work/`.
|
|
37
|
+
- A file tool's refusal, an error such as ENOENT, and a write's or edit's result on claude-agent and codex name paths in the workspace relative to it (`notes/a.md`, `../escape.md: outside the workspace`), never by the server's data directory. A read's result is the file's own text and is not changed.
|
|
38
|
+
- A host tool's result reaches the model whole on claude-agent and codex. The Claude Agent CLI saved an MCP tool's result past 50,000 characters (a long `web_fetch` page, a `monid` answer, a 50 KB `read`) to a file under its own config directory and told the model to read it, which the run's confinement refuses, so the model could not read the page; Codex kept only the two ends of a result past its truncation policy (10,000 tokens for the models its catalog holds, about 12,000 characters for another). `@parcha/agentrun-kernel` states the bound once, `HOST_RESULT_MAX_CHARS` (120,000 characters, over every host tool's largest result); the Claude Agent adapter lists each host tool with it as `anthropic/maxResultSizeChars` and sets `MAX_MCP_OUTPUT_TOKENS` to it, and the Codex adapter sets `tool_output_token_limit` to it as Codex counts it (four bytes of UTF-8 a token: 90,000).
|
|
39
|
+
`web_fetch` (and `fetch_page`) reads a page a part at a time: `offset` and `max_chars` (20,000 by default, at least 200, at most 50,000; a smaller one or an offset below 0 is refused before anything is fetched, saying so; a workflow's call node reads 50,000 by default) name the part, the Page gives `chars`, its length, and a part that is not the whole page has `truncated` while more follows, `next_offset` where it begins and `original_chars` where the whole length is known; an agent reads a line after the JSON saying which characters these are and the offset that reads on. A page whose HTML pi-browser cut at 1,000,000 characters before reading it gives `html_chars`, its whole length, on every part and no `original_chars`, and the line after its last part says `The page was cut at 1,000,000 characters of HTML before reading; the rest wasn't read.`; `converted: "text"` says its text is plain text, its conversion to markdown having run out of time. The text was cut at 60,000 characters with no way to read the rest. A page's links come with the part at offset 0, at most 200 in 20,000 characters, and a URL longer than 4,096 characters is refused before anything is sent.
|
|
40
|
+
`web_search` leaves out its least relevant results when its answer would pass 100,000 characters, and `omitted` counts them.
|
|
41
|
+
- A host tool's result reaches a harness at most `HOST_RESULT_MAX_CHARS` (120,000) characters long. The kernel's tool bridge, which every host tool's result passes on its way to Claude Agent or Codex, keeps a longer one's start, cut where a character ends, ends it with a line saying where it was cut (`[cut at N of M characters]`), and flags the call's `tool_end` `truncated: true`; the call's record keeps the whole result. On a Codex resume, a call the rollout left unanswered is answered from that record with the same cut. A skill file read with `read_skill_file`, a delegate's answer and a rejection listing every schema error reached the harness whole, however long (a 1 MiB skill file, a 6 MB answer).
|
|
42
|
+
- The model proxy now tells the host, before a paid request is sent, the most input tokens it can be billed for. A spend cap could only count a request's cost once it was billed, so a single request whose input alone was over what was left of the cap was still sent and paid. `beforeRequest` now carries `inputTokensMax`: the UTF-8 bytes of the body exactly as it is sent, plus the input the provider adds that the body does not carry. A byte-level BPE token covers at least one byte, so this never undercounts the body, however dense its text. Each `inFlight` entry carries its own `inputTokensMax` until that request answers, so a cap can hold every open request at its own bound. When the provider's addition cannot be read, `inputTokensMax` is undefined, never 0, and a cap treats that input as unknown.
|
|
43
|
+
- What a provider adds is in one place, `providerInputOverhead(api, shape)` from `@parcha/agentrun-kernel/host`. `api` is pi's API kind, and `shape` is whether the request has tools, its tool_choice and its image count. Each figure is the largest the provider documents for any current model:
|
|
44
|
+
- `anthropic-messages`: the tool-use system prompt the Messages API adds to a body with tools, 675 tokens for tool_choice auto or none and 804 for any or tool, plus 4,784 tokens for each image, its high-resolution tier's maximum.
|
|
45
|
+
- `openai-responses`, and the Azure and Codex Responses kinds: no prompt of their own, and 73,800 tokens for each image. That is 30,000 patches, the most an image may have, times 2.46, the largest model multiplier.
|
|
46
|
+
- `openai-completions`, which OpenAI-compatible gateways speak too: nothing for its per-message formatting, since the body's bytes already bound it; 804 tokens when the request has tools, whatever its tool_choice, the largest Anthropic tool-use prompt, since a gateway may route to an Anthropic model; and 73,800 tokens for each image.
|
|
47
|
+
- Every other API kind, among them pi's `mistral-conversations`, `bedrock-converse-stream`, `google-generative-ai`, `google-vertex` and `pi-messages`, and a faux `faux:<id>`: nothing for text, an assumed 2,048 tokens when the request has tools, and 73,800 tokens for each image. The tool allowance for these kinds is assumed, not documented; it is documented only for `anthropic-messages`, the OpenAI Responses kinds and `openai-completions`. `providerInputOverhead` never returns undefined: only a body that cannot be measured is unmeasured.
|
|
48
|
+
- Images are billed by their area, not their bytes, so a small compressed image of large dimensions is counted at its maximum. A Codex body with a file input (a PDF, billed by its pages) is left unmeasured.
|
|
49
|
+
- A provider policy says what its provider adds with `serverInputOverhead(body)`. The Claude and Codex policies read their body's shape and use the figures above.
|
|
50
|
+
- The faux adapter in `@parcha/agentrun-kernel/testing` measures its prompt's UTF-8 bytes for each request, as a real adapter's proxy measures its body.
|
|
51
|
+
- `inputTokensMaxOf(policy, body, sent)` is exported from `@parcha/agentrun-kernel/host`.
|
|
52
|
+
- The proxy serializes the body once before admission and sends exactly what it measured. A body that cannot be serialized is refused before the runner is asked, so it is never booked.
|
|
53
|
+
- A Claude or Codex turn stopped while the session was still recording the person's message stays stopped. Before, the stop found no turn running, so the session read idle, and the stopped message stayed pending and was sent with the next message. Now a turn that ends on its session's stop leaves the session reading `open_turn` while that message is pending, so serve's stop settles it, and it is never sent.
|
|
54
|
+
- A Claude or Codex turn the person stopped stays stopped when the run's process is replaced. Before, the next process found the stopped turn still open in the session and resumed it: it ran its tools and paid for its model requests again, and its answer came before the person's follow-up. Now serve's open reads the run's stop record and settles that turn, ended `interrupted`, with nothing sent, and the follow-up is a turn of its own. A turn a crash or a drain cut is resumed as before.
|
|
55
|
+
- A stop that lands before the harness took the person's message withdraws that message too, so it is never sent later: not with the follow-up in the same process, and not by a process that replaces it.
|
|
56
|
+
- `AdapterSession` has `settleOpenTurn()`: it records the open turn as ended, interrupted, withdraws the input the turn never placed, and sends nothing. The Claude Agent, Codex and faux adapters implement it. A harness that runs as a child process does both with `settleTurn(drive)` from `@parcha/agentrun-kernel/process`. An adapter written outside this repository without it keeps the old behaviour: its stopped turn is resumed.
|
|
57
|
+
- After `interrupt()`, the Claude Agent and Codex sessions read `open_turn` while the stopped turn is still open in their records. serve's stop settles it there; a runner's pause leaves it for the next process to resume.
|
|
58
|
+
- When the earlier process died before it wrote the stopped turn's end, the next one writes it, `interrupted`, before the follow-up's turn starts.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @parcha/agentrun-harness-codex
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Codex as an AgentRun harness: a DSL `agent` node runs on Codex through `@parcha/agentrun-kernel`, durable in AgentRun's
|
|
4
|
+
own store, with the host's tools as its only tools.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { createHarnessRunner } from "@parcha/agentrun-kernel";
|
|
8
|
+
import { codexAdapter } from "@parcha/agentrun-harness-codex";
|
|
9
|
+
|
|
10
|
+
const runNode = createHarnessRunner(
|
|
11
|
+
codexAdapter({
|
|
12
|
+
model: "gpt-5.4-mini",
|
|
13
|
+
provider: { origin: "https://api.openai.com", credential: () => process.env.OPENAI_API_KEY! },
|
|
14
|
+
sessionsDir: "/var/lib/my-host/codex-sessions",
|
|
15
|
+
}),
|
|
16
|
+
{ store, tools },
|
|
17
|
+
);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- **The host's tools only.** Codex's app-server runs with its built-in tools off: no shell, no file edits, no web, no
|
|
21
|
+
images, no sub-agents. Codex's sandbox stays read-only for those built-ins, and its message describing that sandbox
|
|
22
|
+
is not sent, so the model is never told its files are read-only while the host's tools write them
|
|
23
|
+
(`test/developer-messages.test.mjs`). A classic model is offered exactly the host's tools (and the runner's
|
|
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
|
|
26
|
+
`wait` and drops the sub-agent and user-input tools Codex lists beside them; it keeps parallel tool calls off for a
|
|
27
|
+
code-mode request, and offers no `exec` while a script that yielded still runs, so one script is live at a time. A
|
|
28
|
+
nested call has an id of Codex's own (`exec-<uuid>`) that no line of the rollout carries and that names no `exec`, so
|
|
29
|
+
the session ties it to the one live script: the `exec` the proxy's latest answer carried (read before Codex has that
|
|
30
|
+
part of the answer) or that the rollout shows unfinished. A `never` tool's call waits for that `exec`'s line to be in
|
|
31
|
+
the log, and is declined, never run, while two scripts are live. `test/tool-off.test.mjs` runs the pinned binary
|
|
32
|
+
against a scripted model that calls every built-in, and checks that nothing runs, writes or spawns;
|
|
33
|
+
`test/code-mode-never.test.mjs` runs a `never` tool from code mode, from a script that yielded, and from a second
|
|
34
|
+
script a model wrote while the first ran. After a crash the harness's note about the interrupted turn reaches the model
|
|
35
|
+
once, as a developer message injected on the recovery resume (Codex ignores new developer instructions on resume, and every
|
|
36
|
+
turn opens with `thread/resume`), and the resumed turn's user input is the user's own words or `Continue.`.
|
|
37
|
+
- **The model behind a proxy.** Codex talks to a model proxy on the loopback interface with a key of its session's own;
|
|
38
|
+
it never holds the provider key. The proxy forwards `POST /v1/responses` only, fixes the model, stores nothing at the
|
|
39
|
+
provider, drops any tool that is not the session's, and asks the runner before every paid request, so the turn cap and
|
|
40
|
+
the host's budget hold. Each response's usage comes back to the runner.
|
|
41
|
+
- **Web search, when asked.** The one exception to the above: `webSearch: "live"` sets `web_search = "live"` in Codex's
|
|
42
|
+
config; the proxy then passes exactly the hosted tool Codex sends for it (`{ type: "web_search", external_web_access:
|
|
43
|
+
true }`, recorded in `test/fixtures/responses-request-web-search-live.json`) and refuses any other web search tool.
|
|
44
|
+
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
|
+
model with no known search price books an unknown cost. A request that offers web search has no input bound, so a cap
|
|
46
|
+
treats its input as unknown.
|
|
47
|
+
- **A private machine.** A session runs in its own directories. Its working directory is the host's workspace when the
|
|
48
|
+
host names one (`io.cwd`, where the host's file tools write, an untrusted project to Codex), and otherwise an empty
|
|
49
|
+
directory of the session's. Codex keeps nothing there, and takes no instructions from an `AGENTS.md` in it
|
|
50
|
+
(`test/developer-messages.test.mjs`). Codex's environment is an allowlist (`PATH`, `LANG`, `TZ`, its own homes and the proxy key); nothing else of the host's
|
|
51
|
+
reaches it, and its process group ends with the session.
|
|
52
|
+
- **The host's skills, and no others.** `codexAdapter({ skills: [{ name, files }] })`: Codex lists each skill to the model
|
|
53
|
+
by its name and description, and the model reads its `SKILL.md` and the files it names with `read_skill_file` (it has
|
|
54
|
+
no shell). The skills are written into the session's `CODEX_HOME` at the start of every drive, where Codex lists a
|
|
55
|
+
user's skills even in a turn with its built-ins off (it lists none from a working directory's `.agents/skills` there).
|
|
56
|
+
Codex's bundled skills (imagegen, openai-docs, skill-creator, skill-installer, ...) are off in every session, with
|
|
57
|
+
skills or without. The skills are checked when the adapter is made, by `skillProblems` of `@parcha/agentrun-kernel`,
|
|
58
|
+
the Claude adapter's check: a lowercase name, a `SKILL.md` whose front matter names it and describes it, plain
|
|
59
|
+
relative paths, 1 MiB in all. Codex itself skips a skill with no front matter or no description and lists one under
|
|
60
|
+
its front matter's name, so each of those is refused here instead.
|
|
61
|
+
- **Durable.** A session's records are in the store the host lends (Codex's rollout mirrored line by line, every tool
|
|
62
|
+
call an effect recorded before it runs). A session a process died inside resumes from its records: a `safe` tool runs
|
|
63
|
+
again, a `never` tool's cut-off call is reported to the model as interrupted and never repeated.
|
|
64
|
+
|
|
65
|
+
**Tool schemas.** Codex sanitizes the schema its model is given (measured on the pinned binary, recorded in `test/fixtures/schema-column.json`). The adapter refuses, when a session is checked, the shapes Codex drops or retypes (a tuple `items`, `prefixItems`, `patternProperties`, `if`/`then`/`else`, `not`, a non-scalar or untyped non-string `enum`/`const`, `contains`, `dependentRequired`, `propertyNames`, a boolean `items`, constraints inside `allOf`), naming the tool, the JSON pointer and the keyword. The keywords Codex only strips (bounds, patterns, formats, titles, defaults, examples) are listed in the tool's description, so the model still reads them; the host checks every call against the original schema. A schema object reused in two places is described at its first path.
|
|
66
|
+
|
|
67
|
+
The adapter is pinned to Codex 0.164.0. `@openai/codex` is the host's: an exact optional peer dependency, never shipped
|
|
68
|
+
here (`npm install --save-exact @openai/codex@0.164.0`). `codexAdapter()` checks the binary against the pins when it is
|
|
69
|
+
made and throws `CodexNotInstalled` or `CodexPinMismatch` before any run starts. `CODEX_BIN` names another path to the
|
|
70
|
+
same build.
|
|
71
|
+
|
|
72
|
+
Code this package copies from another project is listed in `vendor/durable-harness/UPSTREAM.json` and credited in
|
|
73
|
+
`NOTICE`.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type HostSkill } from "@parcha/agentrun-kernel";
|
|
2
|
+
import type { AgentAdapter } from "@parcha/agentrun-kernel";
|
|
3
|
+
import { type ConfineChild } from "./host/machine.js";
|
|
4
|
+
import { type ModelProxyOptions } from "@parcha/agentrun-kernel/host";
|
|
5
|
+
/**
|
|
6
|
+
* Codex's `tool_output_token_limit`: the host's result bound (HOST_RESULT_MAX_CHARS), as Codex counts it. Codex keeps a
|
|
7
|
+
* tool's output in the model's history within its truncation policy (10,000 tokens for each model its catalog holds, less
|
|
8
|
+
* for one it does not) and cuts the middle of a longer one; this sets the policy. Codex counts a token as four bytes of
|
|
9
|
+
* UTF-8, and a character (a UTF-16 unit) takes at most three, so a result within the bound in any script takes at most
|
|
10
|
+
* three quarters of a token a character: not a quarter, which holds for ASCII alone.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CODEX_TOOL_OUTPUT_TOKENS: number;
|
|
13
|
+
export interface CodexProvider {
|
|
14
|
+
/** The provider's origin (`https://api.openai.com`): the proxy forwards to its `/v1/responses` only. */
|
|
15
|
+
origin: string;
|
|
16
|
+
/** The provider key, read per request in this process. It never reaches Codex's process. */
|
|
17
|
+
credential: () => Promise<string> | string;
|
|
18
|
+
}
|
|
19
|
+
/** Codex's own web search, as a session may turn it on: `live` (it searches the web as it runs). */
|
|
20
|
+
export type CodexWebSearch = "live";
|
|
21
|
+
export interface CodexAdapterOptions {
|
|
22
|
+
/** The provider's model id, or one per tier (`default` when a node names none). */
|
|
23
|
+
model: string | {
|
|
24
|
+
default: string;
|
|
25
|
+
fast?: string;
|
|
26
|
+
strong?: string;
|
|
27
|
+
};
|
|
28
|
+
provider: CodexProvider;
|
|
29
|
+
/** Start Codex under the host's confinement (its own `confine()`, a `setpriv --no-new-privs` prefix, say). It may only
|
|
30
|
+
* add in front of the pinned binary and its arguments, and never touches its environment. */
|
|
31
|
+
confine?: ConfineChild;
|
|
32
|
+
/** The price of a response; null (or no function) records its cost as unknown. */
|
|
33
|
+
price?: ModelProxyOptions["price"];
|
|
34
|
+
/** Codex's own web search, on the provider (OpenAI's hosted `web_search` tool): `"live"` sets `web_search = "live"` in
|
|
35
|
+
* Codex's config, the model proxy admits exactly the tool Codex then sends, and each search a response ran is added to
|
|
36
|
+
* its price at the model's per-call price (unknown for a model with no known search price). Default off. */
|
|
37
|
+
webSearch?: CodexWebSearch;
|
|
38
|
+
/** The most output tokens one request may ask for. Default 32 000. */
|
|
39
|
+
maxOutputTokens?: number;
|
|
40
|
+
/** The model's context window. Default 272 000. */
|
|
41
|
+
contextWindow?: number;
|
|
42
|
+
/** Where sessions keep their private directories when the host lends none (`io.dir`): one per session key. */
|
|
43
|
+
sessionsDir?: string;
|
|
44
|
+
/** The host's skills, which Codex lists to the model by name and description and the model reads with
|
|
45
|
+
* `read_skill_file`, and no others: never Codex's bundled ones. Checked when the adapter is made (`skillProblems`, the
|
|
46
|
+
* check the Claude adapter runs). Written into each session's private directory. Default none. */
|
|
47
|
+
skills?: readonly HostSkill[];
|
|
48
|
+
/** Diagnostics. */
|
|
49
|
+
log?: (message: string, fields?: Record<string, unknown>) => void;
|
|
50
|
+
/** For tests: a command that speaks app-server's protocol instead of Codex (needs AGENTRUN_CODEX_STANDIN=1 under a test runner). */
|
|
51
|
+
standIn?: {
|
|
52
|
+
command: string;
|
|
53
|
+
args?: string[];
|
|
54
|
+
env?: Record<string, string>;
|
|
55
|
+
};
|
|
56
|
+
/** For tests: the fetch the model proxy forwards with. */
|
|
57
|
+
fetch?: typeof fetch;
|
|
58
|
+
}
|
|
59
|
+
export declare function codexAdapter(options: CodexAdapterOptions): AgentAdapter;
|