@parcha/agentrun-harness-codex 0.0.0-stage → 0.1.0-beta.100

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +349 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +6 -0
  4. package/README.md +80 -2
  5. package/dist/adapter.d.ts +93 -0
  6. package/dist/adapter.js +375 -0
  7. package/dist/app-server.d.ts +53 -0
  8. package/dist/app-server.js +105 -0
  9. package/dist/binary.d.ts +31 -0
  10. package/dist/binary.js +74 -0
  11. package/dist/catalog.d.ts +35 -0
  12. package/dist/catalog.js +104 -0
  13. package/dist/code-mode.d.ts +171 -0
  14. package/dist/code-mode.js +514 -0
  15. package/dist/config.d.ts +84 -0
  16. package/dist/config.js +214 -0
  17. package/dist/facts.d.ts +2 -0
  18. package/dist/facts.js +40 -0
  19. package/dist/harness.d.ts +210 -0
  20. package/dist/harness.js +1112 -0
  21. package/dist/host/kernel.d.ts +20 -0
  22. package/dist/host/kernel.js +3 -0
  23. package/dist/host/machine.d.ts +81 -0
  24. package/dist/host/machine.js +355 -0
  25. package/dist/host/policy.d.ts +113 -0
  26. package/dist/host/policy.js +683 -0
  27. package/dist/host/process.d.ts +151 -0
  28. package/dist/host/process.js +50 -0
  29. package/dist/host/sandbox.d.ts +36 -0
  30. package/dist/host/sandbox.js +35 -0
  31. package/dist/index.d.ts +13 -0
  32. package/dist/index.js +10 -0
  33. package/dist/rollout.d.ts +96 -0
  34. package/dist/rollout.js +170 -0
  35. package/dist/schema.d.ts +14 -0
  36. package/dist/schema.js +178 -0
  37. package/dist/scripts.d.ts +218 -0
  38. package/dist/scripts.js +409 -0
  39. package/dist/tool-images.d.ts +7 -0
  40. package/dist/tool-images.js +18 -0
  41. package/dist/transcript.d.ts +20 -0
  42. package/dist/transcript.js +73 -0
  43. package/dist/verify.d.ts +62 -0
  44. package/dist/verify.js +155 -0
  45. package/dist/versions.d.ts +43 -0
  46. package/dist/versions.js +72 -0
  47. package/package.json +72 -4
  48. package/vendor/durable-harness/UPSTREAM.json +39 -0
package/dist/config.js ADDED
@@ -0,0 +1,214 @@
1
+ // Copyright 2026 Vercel Inc. Licensed under the Apache License, Version 2.0; see LICENSE in this package.
2
+ // From github.com/vercel-labs/durable-harness, packages/harness-codex/src/config.ts at ea8aa4060c (UPSTREAM.json records its blob and sha256).
3
+ // Changed by Parcha, and AgentRun's own since the port from upstream froze on 2026-11-07.
4
+ /**
5
+ * The `config.toml` a session's `CODEX_HOME` gets: the model and its
6
+ * provider (the session's model proxy), and Codex's built-in tools and side
7
+ * features turned off.
8
+ */
9
+ /**
10
+ * Codex features turned off (`codex features list`). With these off, a
11
+ * classic model is offered only the harness's dynamic tools and
12
+ * `request_user_input` (which Codex itself answers "unavailable in Default
13
+ * mode"): no shell, no `apply_patch`, no images, no web, no sub-agents. A
14
+ * code-mode model (luna) is offered code mode's `exec` and `wait`; see
15
+ * `code_mode_host`. The rest are side features that would download plugins,
16
+ * call chatgpt.com or start a daemon.
17
+ */
18
+ export const BUILTINS_OFF = {
19
+ // The shell's gate: with it off no shell tool is offered, unified exec's included.
20
+ shell_tool: false,
21
+ // Not a gate in the pinned Codex, which turns unified exec back on whatever config.toml says (codex-rs
22
+ // managed_features.rs, normalize_candidate); kept off here in case a later release honours it.
23
+ unified_exec: false,
24
+ view_image: false,
25
+ image_generation: false,
26
+ multi_agent: false,
27
+ goals: false,
28
+ sleep_tool: false,
29
+ browser_use: false,
30
+ browser_use_external: false,
31
+ computer_use: false,
32
+ in_app_browser: false,
33
+ // Code mode's JavaScript runtime (no Node, no file system, no network): the only way a code-mode model such as luna
34
+ // calls a tool. Its nested tools are the dynamic tools plus Codex's own MCP resource readers, which run nothing here
35
+ // (read-only, approvals declined, no MCP server); its sub-agent tools are removed by agents.enabled, its apply_patch by
36
+ // the harness's model catalog (catalog.ts).
37
+ code_mode_host: true,
38
+ tool_suggest: false,
39
+ skill_search: false,
40
+ skill_mcp_dependency_install: false,
41
+ tool_call_mcp_elicitation: false,
42
+ realtime_conversation: false,
43
+ workspace_dependencies: false,
44
+ worktrees: false,
45
+ hooks: false,
46
+ plugins: false,
47
+ remote_plugin: false,
48
+ apps: false,
49
+ shell_snapshot: false,
50
+ daemon_auto_start: false,
51
+ // A shell or sub-command path Codex would approve per sub-command (an `approvalId` the drive declines), and the git undo snapshots app-server took itself (outside bwrap): off, though 0.160 has these off or removed already.
52
+ shell_zsh_fork: false,
53
+ unified_exec_zsh_fork: false,
54
+ undo: false,
55
+ };
56
+ /**
57
+ * The features on top of `BUILTINS_OFF` with the built-ins on: the shell
58
+ * (unified exec: `exec_command`, `write_stdin`; `apply_patch` runs through
59
+ * it) and `view_image`. Sub-agents, goals, images, the browser and plugins
60
+ * stay off: their state is not in the rollout, or they reach outside.
61
+ */
62
+ export const BUILTINS_ON = {
63
+ ...BUILTINS_OFF,
64
+ shell_tool: true,
65
+ unified_exec: true,
66
+ view_image: true,
67
+ };
68
+ /**
69
+ * What a command Codex runs inherits: the core variables only (`HOME`,
70
+ * `LOGNAME`, `PATH`, `SHELL`, `USER`, `USERNAME`, `TMPDIR`, `TEMP`, `TMP`),
71
+ * plus `sandbox({ env })` (`set`, `codexConfig`), and never one named like
72
+ * the harness's own (`HARNESS_*`, the provider key's placeholder among them)
73
+ * or a token. Codex 0.160 otherwise passes its whole environment on
74
+ * (docs/workspaces.md §5.6).
75
+ */
76
+ export const SHELL_ENVIRONMENT_POLICY = Object.freeze({ inherit: 'core', exclude: Object.freeze(['HARNESS_*', '*TOKEN*']) });
77
+ /** Whether `name` matches one of the policy's `exclude` patterns (`*` globs, case-insensitive, as Codex matches them). */
78
+ export function excludedName(name) {
79
+ return SHELL_ENVIRONMENT_POLICY.exclude.some((p) => new RegExp(`^${p.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replaceAll('*', '.*')}$`, 'i').test(name));
80
+ }
81
+ export function codexConfig(options) {
82
+ const commandEnv = options.commandEnv ? Object.fromEntries(Object.entries(options.commandEnv).filter(([k]) => !excludedName(k))) : undefined;
83
+ const base = {
84
+ model: options.model,
85
+ model_provider: 'gateway',
86
+ model_context_window: options.contextWindow,
87
+ sandbox_mode: 'read-only',
88
+ web_search: 'disabled',
89
+ check_for_update_on_startup: false,
90
+ shell_environment_policy: {
91
+ inherit: SHELL_ENVIRONMENT_POLICY.inherit,
92
+ exclude: [...SHELL_ENVIRONMENT_POLICY.exclude],
93
+ ...(commandEnv && Object.keys(commandEnv).length ? { set: commandEnv } : {}),
94
+ },
95
+ model_providers: {
96
+ gateway: {
97
+ name: 'AgentRun model proxy',
98
+ base_url: options.baseUrl,
99
+ env_key: options.envKey,
100
+ wire_api: 'responses',
101
+ supports_websockets: false,
102
+ ...(options.streamIdleMs !== undefined ? { stream_idle_timeout_ms: Math.max(1, Math.floor(options.streamIdleMs)) } : {}),
103
+ },
104
+ },
105
+ ...(options.cwd ? { projects: { [options.cwd]: { trust_level: 'untrusted' } } } : {}),
106
+ features: { ...BUILTINS_OFF },
107
+ analytics: { enabled: false },
108
+ // No sub-agents. `multi_agent = false` turns off only V1, and a model Codex's catalog marks V2 (luna, sol) still gets V2's
109
+ // collaboration tools and a developer message saying it can spawn sub-agents: `enabled = false` turns off both.
110
+ agents: { enabled: false, max_depth: 0 },
111
+ };
112
+ return merge(base, options.extra ?? {});
113
+ }
114
+ /**
115
+ * `config` keys the harness sets itself and an app may not (docs/workspaces.md
116
+ * §3.3): the sandbox and approvals (which bwrap and the log's barrier rest
117
+ * on), the commands' environment, the provider and its key (the model port),
118
+ * trust and project config, MCP servers and notifications (they reach outside
119
+ * the log), the features (the built-ins' switch: `builtins`), web search, and
120
+ * the model (`model`). Also what would swap the binary or shell that does the
121
+ * sandboxing, send traffic outside the log (`otel`, `chatgpt_base_url`), grant
122
+ * permission profiles, keep history or snapshots outside the rollout, or read
123
+ * a file the app names (`model_catalog_json`, `RESERVED_CONFIG_SUFFIXES`).
124
+ */
125
+ export const RESERVED_CONFIG_KEYS = Object.freeze([
126
+ 'model',
127
+ 'model_catalog_json',
128
+ 'model_provider',
129
+ 'model_providers',
130
+ 'base_url',
131
+ 'env_key',
132
+ 'sandbox_mode',
133
+ 'sandbox_workspace_write',
134
+ 'approval_policy',
135
+ 'shell_environment_policy',
136
+ 'projects',
137
+ 'profile',
138
+ 'profiles',
139
+ 'mcp_servers',
140
+ 'notify',
141
+ 'features',
142
+ 'web_search',
143
+ 'tools.web_search',
144
+ 'default_permissions',
145
+ 'permissions',
146
+ 'ghost_snapshot',
147
+ 'otel',
148
+ 'chatgpt_base_url',
149
+ 'history',
150
+ 'project_root_markers',
151
+ 'allow_symlinked_codex_home',
152
+ 'agents',
153
+ ]);
154
+ /** Key suffixes reserved at any depth: a binary, a file or a directory Codex would use (`codex_linux_sandbox_exe`, `zsh_path`, `model_instructions_file`, `experimental_compact_prompt_file`, `sqlite_home`, `log_dir`, ...). */
155
+ export const RESERVED_CONFIG_SUFFIXES = Object.freeze(['_exe', '_path', '_file', '_home', '_dir']);
156
+ /** Throw a `TypeError` naming the first key of `config` the harness reserves (a dotted key is a nested table's: `tools.web_search`). */
157
+ export function checkConfig(config) {
158
+ if (config === undefined)
159
+ return;
160
+ if (!isTable(config))
161
+ throw new TypeError('agentrun-harness-codex: config must be an object of config.toml settings');
162
+ const check = (table, prefix) => {
163
+ for (const [k, v] of Object.entries(table)) {
164
+ const path = `${prefix}${k}`;
165
+ // A dotted key in one string (`"tools.web_search"`) is the same setting as the nested one.
166
+ const last = path.slice(path.lastIndexOf('.') + 1);
167
+ if (RESERVED_CONFIG_KEYS.includes(path) || RESERVED_CONFIG_KEYS.some((r) => path.startsWith(`${r}.`)) || RESERVED_CONFIG_SUFFIXES.some((x) => last.endsWith(x))) {
168
+ throw new TypeError(`agentrun-harness-codex: config.${path} is set by the harness (docs/workspaces.md §3.3: ${RESERVED_CONFIG_KEYS.join(', ')} and any key ending ${RESERVED_CONFIG_SUFFIXES.join(', ')} are reserved)`);
169
+ }
170
+ if (isTable(v))
171
+ check(v, `${path}.`);
172
+ }
173
+ };
174
+ check(config, '');
175
+ }
176
+ function merge(a, b) {
177
+ const out = { ...a };
178
+ for (const [k, v] of Object.entries(b)) {
179
+ const prev = out[k];
180
+ out[k] = isTable(prev) && isTable(v) ? merge(prev, v) : v;
181
+ }
182
+ return out;
183
+ }
184
+ const isTable = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
185
+ /** TOML text for a config object: plain values first, then one `[table]` per nested object. */
186
+ export function toToml(config, prefix = []) {
187
+ const plain = [];
188
+ const tables = [];
189
+ for (const [k, v] of Object.entries(config)) {
190
+ if (isTable(v))
191
+ tables.push(toToml(v, [...prefix, k]));
192
+ else
193
+ plain.push(`${key(k)} = ${value(v)}`);
194
+ }
195
+ const head = prefix.length && plain.length ? `[${prefix.map(key).join('.')}]\n` : '';
196
+ return [plain.length ? `${head}${plain.join('\n')}\n` : '', ...tables].filter(Boolean).join('\n');
197
+ }
198
+ const key = (k) => (/^[A-Za-z0-9_-]+$/.test(k) ? k : JSON.stringify(k));
199
+ function value(v) {
200
+ if (typeof v === 'string')
201
+ return JSON.stringify(v);
202
+ if (typeof v === 'number') {
203
+ if (!Number.isFinite(v))
204
+ throw new TypeError(`agentrun-harness-codex: not a TOML number: ${v}`);
205
+ return String(v);
206
+ }
207
+ if (typeof v === 'boolean')
208
+ return String(v);
209
+ if (Array.isArray(v))
210
+ return `[${v.map(value).join(', ')}]`;
211
+ return `{ ${Object.entries(v)
212
+ .map(([k, x]) => `${key(k)} = ${value(x)}`)
213
+ .join(', ')} }`;
214
+ }
@@ -0,0 +1,2 @@
1
+ import type { AdapterFacts } from "@parcha/agentrun-kernel";
2
+ export declare const facts: AdapterFacts;
package/dist/facts.js ADDED
@@ -0,0 +1,40 @@
1
+ import { codexPolicy } from "./host/policy.js";
2
+ import { codexSchemaProblems } from "./schema.js";
3
+ import { CODEX_BASE_INPUT_TOKENS, CODEX_INSTALL, CODEX_VERSION } from "./versions.js";
4
+ export const facts = Object.freeze({
5
+ id: "codex",
6
+ label: "Codex",
7
+ wire: "openai-responses",
8
+ // A message that comes mid-turn waits for the turn's end.
9
+ steer: false,
10
+ // A call that started is never run again (the harness answers it from the log); only the model calls again.
11
+ rerunsStarted: false,
12
+ // An answer its output limit cut ends the turn: the harness ends it there, before Codex asks for the answer again.
13
+ recoversCutAnswers: 0,
14
+ // One run's memory, measured with the server's (serve's host.ts): Codex's app-server beside the run's process.
15
+ runMib: 192,
16
+ // OpenAI's reasoning efforts stop at xhigh.
17
+ thinking: Object.freeze(["low", "medium", "high", "xhigh"]),
18
+ // Codex's own live search, booked per call.
19
+ webSearch: "live",
20
+ ownModel: false,
21
+ // Its proxy forwards with the fetch it is handed: a model the route translates onto its wire runs on it.
22
+ forwardsRoute: true,
23
+ // Its own code mode runs the model's scripts, each nested call one of the host's tools through its bridge.
24
+ ownCodemode: true,
25
+ // Its dynamic tools are given at thread/start alone: thread/resume and thread/settings/update take none (the pinned
26
+ // binary's own app-server schema, ThreadResumeParams and ThreadSettingsUpdateParams).
27
+ toolsFixedAtStart: true,
28
+ normalizeModel: (model) => model,
29
+ install: Object.freeze({ npmLine: CODEX_INSTALL, spec: `@openai/codex@${CODEX_VERSION}`, codes: Object.freeze({ install: "CODEX_NOT_INSTALLED", pins: "CODEX_PIN_MISMATCH" }) }),
30
+ // The shapes Codex drops or retypes in a host tool's schema (a run's MCP tool's among them), measured on the pinned
31
+ // binary (schema.ts).
32
+ schemaProblems: codexSchemaProblems,
33
+ // Codex's own tools, each the host's table tool it is.
34
+ nativeTools: Object.freeze({ web_search: "web_search", shell: "bash" }),
35
+ // A run's MCP tool reaches Codex as `mcp_<server>__<tool>` (adapter.ts codexToolName): the host's is `mcp__<server>__<tool>`.
36
+ hostName: (given) => given.replace(/^mcp_(?!_)/, "mcp__"),
37
+ // Its first request's own input before the agent's prompt, from a Codex run's billing (versions.ts).
38
+ baseInputTokens: CODEX_BASE_INPUT_TOKENS,
39
+ policy: (options) => codexPolicy({ model: options.model, tools: options.tools, ...(options.webSearch === "live" ? { webSearch: "live" } : {}), ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}) }),
40
+ });
@@ -0,0 +1,210 @@
1
+ import type { GateAnswer, GateCall, OwnCalls } from '@parcha/agentrun-kernel';
2
+ import { type Harness, type HostTool, type ReplayPolicy, type SessionState, type Submission } from './host/kernel.js';
3
+ import { type AcquireMachine, type ResultBudget } from './host/process.js';
4
+ import { type TomlValue } from './config.js';
5
+ import { type RolloutCall } from './rollout.js';
6
+ /**
7
+ * Codex on harness-world: a kernel `Harness` that drives `codex app-server
8
+ * (docs/workspaces.md §1 decision 2, §5.6). Every drive acquires the
9
+ * session's VM through the sandbox tier (`attachInDrive` with the session
10
+ * factory's acquire, `machine.acquire`), and refuses a machine the factory
11
+ * didn't brand: `Unavailable('sandbox_required')`.
12
+ *
13
+ * - **Where it runs.** app-server runs as the VM's unprivileged user, its
14
+ * stdio over the relay (`RemoteProcess`, a `LineChannel`), its working
15
+ * directory `/workspace` (the session's Drive, the same on every VM), its
16
+ * `HOME` and `CODEX_HOME` under `/var/lib/dh/s`, wiped before every spawn.
17
+ * `CODEX_HOME` is outside every writable root of Codex's own sandbox, so a
18
+ * command can't rewrite the rollout or `config.toml`.
19
+ * - **Tools.** Tool-less by default: the app's `HostTool`s (`tools`) are
20
+ * app-server dynamic tools, run in the Function, each call the kernel's
21
+ * effect sandwich keyed by Codex's own `call_id` (`tool:<call_id>`), and
22
+ * they are its only tools (shell, `apply_patch` and images off, a
23
+ * `read-only` sandbox). With `builtins: true`, Codex's own shell and
24
+ * `apply_patch` are on, on `/workspace`, under Codex's own sandbox
25
+ * (`sandboxMode`: by default `workspace-write` when bubblewrap's self-test
26
+ * passes in the VM, else `danger-full-access`, the VM being the boundary;
27
+ * the first verdict is recorded in the log, `codex.sandbox`, and every
28
+ * later drive keeps it).
29
+ * Every command and patch asks the drive first (`approvalPolicy:
30
+ * 'untrusted'`): its intent is committed once the rollout line that made
31
+ * the call is in the log, and only then approved, once. Anything else is
32
+ * declined: a second approval for the same call (Codex's "retry without
33
+ * sandbox?"), input to a running command, a sub-command, more
34
+ * permissions, network access. Its outcome is committed when Codex
35
+ * reports the item completed, after the Drive is flushed. Nothing reruns
36
+ * one after a crash: the Drive is durable, not transactional.
37
+ * - **The rollout is mirrored into the log.** Codex keeps its thread as an
38
+ * append-only JSONL file; the relay tails it (`TAIL`, inode and size
39
+ * checked: a replaced or shrunk file stops the drive, and the third time
40
+ * in a turn ends the turn) and every line
41
+ * becomes a record of the session's native journal (`rollout:<threadId>`).
42
+ * Before every `replay: 'never'` call the drive drains the tail (`SYNC`)
43
+ * and checks the call's own line is there (a bounded number of times):
44
+ * without it, the call is declined, never run, and the model is told to
45
+ * try again.
46
+ * - **Every drive restores from the log.** `CODEX_HOME` is wiped and gets a
47
+ * fresh `config.toml` and the mirrored rollout, byte for byte (`FILES`);
48
+ * app-server resumes the thread by id.
49
+ * - **Recovery.** A turn a crash cut off is resumed natively: calls the
50
+ * rollout left without an output get one injected from the log
51
+ * (`thread/inject_items`), then a recovery note built from the log starts
52
+ * a turn. A link to the VM lost mid-drive is re-attached in the same
53
+ * invocation (a bounded number of times, and only while there is work
54
+ * left), once the app's tools still running have settled, and the drive
55
+ * resumes from the log.
56
+ * - **The inbox.** Each submission is placed, then sent with its id as
57
+ * Codex's `clientUserMessageId`: `turn/start`, or `turn/steer` for a
58
+ * steer that arrives while a turn runs.
59
+ *
60
+ * Model traffic goes from the VM's loopback model port through the relay to
61
+ * this drive's `gatewayHandler` (`CODEX_ROUTES`: the fixed path table, the
62
+ * body policy, the model), which adds the credential: the VM
63
+ * never holds it. Codex's provider key is the attach's model key
64
+ * (`SessionMachine.modelKey`, which the relay checks with the caller's pid),
65
+ * hidden from the model's commands
66
+ * (`shell_environment_policy`). app-server runs no git of the Drive's: `GIT_DIR`
67
+ * points nowhere and no git config is read.
68
+ */
69
+ export interface CodexHarnessOptions {
70
+ /**
71
+ * The app's tools, as app-server dynamic tools: each call a kernel effect
72
+ * keyed by Codex's `call_id`, with the tool's replay policy, run where the
73
+ * drive runs (the Function). Its only tools, or (with `builtins: true`)
74
+ * next to the built-ins. Default none.
75
+ */
76
+ tools?: HostTool[];
77
+ /**
78
+ * The host's gate (SessionIO.gate), asked by the tool bridge about each call
79
+ * of `tools` before its intent: a deny is the call's result in the host's
80
+ * words, nothing written and nothing run; a park holds it. Default none.
81
+ */
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;
89
+ /**
90
+ * Codex's own shell and `apply_patch` (and `view_image`), on `/workspace`
91
+ * in the session's VM. Default false (tool-less: `tools` are its only
92
+ * tools). Image generation, web search, sub-agents and plugins stay off
93
+ * either way.
94
+ */
95
+ builtins?: boolean;
96
+ /**
97
+ * Codex's sandbox for its commands, in the VM (the Codex SDK's word; this
98
+ * option was `sandbox`). Needs `builtins: true`. Default: `workspace-write`
99
+ * (writes to `/workspace` and its home, network on) when bubblewrap's
100
+ * self-test passes in the VM at attach, else `danger-full-access` (the VM
101
+ * is the boundary, and holds no credential; the provider key's
102
+ * placeholder is then readable by the model's commands, docs/workspaces.md
103
+ * §5.5).
104
+ */
105
+ sandboxMode?: 'read-only' | 'workspace-write' | 'danger-full-access';
106
+ model?: string;
107
+ /** Developer instructions for the thread (`developerInstructions`). */
108
+ instructions?: string;
109
+ /** Replace Codex's own base instructions (they describe its built-in tools). */
110
+ baseInstructions?: string;
111
+ /** Reasoning effort per turn. Default Codex's. */
112
+ effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
113
+ credential?: () => Promise<string>;
114
+ /** The Gateway's base URL. Default `gatewayUrl()`. */
115
+ gatewayUrl?: string;
116
+ /** The kernel name (its sessions' runs are `workflow//durable-harness@<version>//<name>`). Default `codex`. */
117
+ name?: string;
118
+ /** The model's context window (Gateway ids are unknown to Codex). Default 272,000. */
119
+ contextWindow?: number;
120
+ /** How long Codex waits on a streamed answer that sends nothing (CodexConfigOptions.streamIdleMs). Default Codex's own. */
121
+ streamIdleMs?: number;
122
+ /** What the session's model can take of one tool result (its context window): the tool bridge holds every result to
123
+ * it (boundResult's budget), and so does each result code mode hands Codex from the log. Absent: the host's bound
124
+ * alone (HOST_RESULT_MAX_CHARS). */
125
+ resultBudget?: ResultBudget;
126
+ /** Extra `config.toml` settings, merged over the generated ones. The keys the harness sets itself (`RESERVED_CONFIG_KEYS`) throw. */
127
+ config?: Record<string, TomlValue>;
128
+ /** How often to read the inbox for steers while a turn runs, without hints. Default 500 ms (5 s with hints). */
129
+ inboxPollMs?: number;
130
+ /** Diagnostics (stderr noise, declined approvals, the sandbox's lifecycle). */
131
+ log?: (message: string, fields?: Record<string, unknown>) => void;
132
+ /**
133
+ * The session's VM (internal: durable-harness's `codex()` resolves
134
+ * `workspace: sandbox()` into it). Without it, or with an acquire that
135
+ * gives a machine the sandbox tier's session factory didn't brand, a
136
+ * drive fails its turn with `Unavailable('sandbox_required')`.
137
+ */
138
+ machine?: CodexMachine;
139
+ /**
140
+ */
141
+ test?: {
142
+ command: string;
143
+ args?: string[];
144
+ };
145
+ }
146
+ /** The session's VM, as a `sandbox()` descriptor resolves it (durable-harness's `codex()` builds it). */
147
+ export interface CodexMachine {
148
+ /** The sandbox tier's acquire: its session factory (`sandboxSession`), which brands the machines it gives. */
149
+ acquire: AcquireMachine;
150
+ /** `sandbox({ env })`: non-secret variables for app-server and for the model's commands (`shell_environment_policy.set`). */
151
+ env?: Readonly<Record<string, string>>;
152
+ /** `sandbox({ network })`: the gateway handler refuses what would reach past it through the provider. Default `allow-all`. */
153
+ network?: 'allow-all' | 'deny-all' | {
154
+ readonly allow: readonly string[];
155
+ };
156
+ /** `sandbox({ commandTimeoutMs })`: a built-in command's longest run, within the time left in the invocation. */
157
+ commandTimeoutMs?: number;
158
+ }
159
+ export declare const DEFAULT_MODEL = "openai/gpt-6.1-terra";
160
+ /** A Codex item's replay policy: a command whose every action reads is `safe`; any other command, and every patch, `never`. */
161
+ export declare function codexItemReplay(item: {
162
+ type?: string;
163
+ commandActions?: {
164
+ type?: string;
165
+ }[];
166
+ }): ReplayPolicy;
167
+ /**
168
+ * The env var Codex reads its provider key from (`env_key`; it sends it as
169
+ * `authorization: Bearer`). It holds the attach's model key
170
+ * (`SessionMachine.modelKey`), never a credential: the gateway handler adds
171
+ * that in the Function. Hidden from the
172
+ * model's commands by `shell_environment_policy` (`HARNESS_*`), and exempt
173
+ * from the spawn check's credential-name rule (harness-world-sandbox's
174
+ * `PLACEHOLDER_NAMES`), never from its value rules.
175
+ */
176
+ export declare const KEY_ENV = "HARNESS_CODEX_GATEWAY_KEY";
177
+ /** What the model is told when a call was declined because its line wasn't in the log yet. */
178
+ export declare const LAGGING_NOTE = "[harness] The previous tool call was not run: the session's log had not caught up with it yet. Nothing happened; make the same call again.";
179
+ /** A dynamic tool's result when its call was declined for the same reason. */
180
+ export declare const LAGGING_RESULT = "Not run: the session's log had not caught up with this call yet. Nothing happened; make the same call again.";
181
+ /** The outcome of a command the invocation's deadline stopped. */
182
+ export declare const TIMEOUT_TEXT = "The command ran out of time in this invocation and was stopped: it may have partly taken effect. Check the state it left before running it again.";
183
+ /** The outcome of a command approved too close to the invocation's end: declined, never run. */
184
+ export declare const NO_TIME_TEXT = "Not run: too little time was left in this invocation to run it and record its outcome. Nothing happened; make the same call again.";
185
+ /** The journal stream of the bubblewrap self-test's verdict: `{ sandboxMode, reason? }`, the first one kept. */
186
+ export declare const SANDBOX_STREAM = "codex.sandbox";
187
+ /** The journal stream of rollout tail failures: `{ turn, error }`. */
188
+ export declare const TAIL_STREAM = "codex.tail";
189
+ /** The rollout tail failed (the file shrank, was replaced, or is not the session user's): what the drive halts with. */
190
+ export declare class RolloutTailError extends Error {
191
+ constructor(cause: unknown);
192
+ }
193
+ export declare function codexHarness(options?: CodexHarnessOptions): Harness;
194
+ /** The client id prefix of a recovery note's turn: `recover:<n>`, then `:<id>,<id>` for the submissions it carries. */
195
+ export declare const RECOVER_PREFIX = "recover:";
196
+ /** The client id a recovery note's turn is sent with. */
197
+ export declare function recoveryClientId(n: number, carried: readonly Submission[]): string;
198
+ /**
199
+ * Placed submissions of the open turn that Codex never recorded: no user
200
+ * message in the rollout has their id as its `client_id`, alone or among
201
+ * the ids a recovery note's turn carried. A crash between placing and
202
+ * sending, or a steer it accepted but had not written yet.
203
+ */
204
+ export declare function owedSubmissions(state: SessionState, placed: string[], clientIds: Set<string>): Submission[];
205
+ /**
206
+ * The output injected for a call the rollout left dangling, from what the
207
+ * log knows: the committed result (exactly once), the recorded failure, or
208
+ * that it never started.
209
+ */
210
+ export declare function repairOutput(state: SessionState, call: RolloutCall): string;