@parcha/agentrun-harness-codex 0.1.0-beta.37 → 0.1.0-beta.39

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.
@@ -1,4 +1,5 @@
1
- import { providerInputOverhead, ProxyRefusal, responsesImagesIn } from "@parcha/agentrun-kernel/host";
1
+ import { PLAN_LIMIT_CODE, PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
2
+ import { lastObjectOf, NATIVE_SEARCH_USD, ProxyRefusal, responsesInputOverhead, responsesLocalInputTokens } from "@parcha/agentrun-kernel/host";
2
3
  export const CODEX_RESPONSES_ROUTES = Object.freeze([
3
4
  { method: "GET", path: "/", local: 404 },
4
5
  { method: "POST", path: "/v1/responses", headers: ["accept"] },
@@ -31,8 +32,8 @@ const isLiveSearch = (tool) => Object.keys(tool).length === Object.keys(LIVE_SEA
31
32
  * not listed: their searches, like any model's not listed here (a gateway's own id, say), are an unknown cost, never $0.
32
33
  */
33
34
  const WEB_SEARCH_USD = [
34
- [/^(?:gpt-6|gpt-5|o3|o4-mini)(?:[-.][a-z0-9.-]+)?$/, 0.01],
35
- [/^gpt-4(?:o|\.1)(?:-\d{4}-\d{2}-\d{2})?$/, 0.01],
35
+ [/^(?:gpt-6|gpt-5|o3|o4-mini)(?:[-.][a-z0-9.-]+)?$/, NATIVE_SEARCH_USD],
36
+ [/^gpt-4(?:o|\.1)(?:-\d{4}-\d{2}-\d{2})?$/, NATIVE_SEARCH_USD],
36
37
  ];
37
38
  /** The price of one web search call on `model`, or undefined when it is not known. */
38
39
  export function webSearchUsd(model) {
@@ -51,10 +52,12 @@ export function withWebSearches(price) {
51
52
  return typeof searches === "number" && each !== undefined ? tokens + searches * each : null;
52
53
  };
53
54
  }
55
+ /** What a ChatGPT plan's Responses API does not take: dropped from a request on it. */
56
+ const PLAN_DROPPED_KEYS = new Set(["max_output_tokens", "temperature", "top_p", "metadata", "user", "safety_identifier", "truncation", "background", "prompt_cache_retention"]);
54
57
  const isPlain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
55
58
  /** A list of tool definitions with no provider-hosted tool but the live web search when `search` is on, less any not the
56
- * session's own: `allowed` by name, `mcp` (`mcp__<server>__<tool>`) in a server's namespace. */
57
- function ownTools(tools, allowed, search = false, mcp = new Set()) {
59
+ * session's own (`allowed`, by name). */
60
+ function ownTools(tools, allowed, search = false) {
58
61
  if (!Array.isArray(tools))
59
62
  throw new ProxyRefusal(400, "tools is not a list");
60
63
  const out = [];
@@ -72,9 +75,9 @@ function ownTools(tools, allowed, search = false, mcp = new Set()) {
72
75
  if (DROPPED_TOOLS.has(type))
73
76
  continue;
74
77
  if (type === "namespace") {
75
- // A namespace holds the tools of a built-in family, or of an MCP server (`mcp__<server>`): only the session's own ones
76
- // stay, and an empty one goes.
77
- const kept = ownTools(tool.tools, name.startsWith("mcp__") ? new Set([...mcp].flatMap((own) => (own.startsWith(`${name}__`) ? [own.slice(name.length + 2)] : []))) : allowed);
78
+ // A namespace holds the tools of a built-in family: only the session's own ones stay, and an empty one goes. One of
79
+ // an MCP server's (`mcp__<server>`) holds none of the session's: Codex binds no MCP server of its own.
80
+ const kept = ownTools(tool.tools, name.startsWith("mcp__") ? new Set() : allowed);
78
81
  if (kept.length)
79
82
  out.push({ ...tool, tools: kept });
80
83
  continue;
@@ -172,8 +175,8 @@ function cutEnd(text) {
172
175
  * The value of `key` in the response an answer ends with: a stream's `response.completed` (or `response.incomplete`),
173
176
  * each `data:` line parsed on its own, or a whole JSON body's. The proxy keeps only the first and last 64 KiB of a long
174
177
  * answer, and the completed event carries the whole response (its tools and encrypted reasoning), so its line can be cut
175
- * at the window's start: then the last `"<key>":{` in the text (the response's, which a JSON string cannot contain
176
- * unescaped) is read as one JSON object. The usage is looked for in all the text kept; `tool_usage` only in the cut end
178
+ * at the window's start: then the last `"<key>": {` in the text, whatever its spacing (the kernel's `lastObjectOf`: the
179
+ * response's, which a JSON string cannot contain unescaped), is read as one JSON object. The usage is looked for in all the text kept; `tool_usage` only in the cut end
177
180
  * of the last event (`cutEnd`), since the events before the terminal one carry a `tool_usage` of their own (a count of
178
181
  * 0 as the response starts). No completed event, or no `key` in it, is undefined.
179
182
  */
@@ -210,21 +213,7 @@ function endValue(text, key) {
210
213
  catch { }
211
214
  }
212
215
  const scope = key === "usage" ? text : cutEnd(text);
213
- if (scope === undefined)
214
- return undefined;
215
- const mark = `"${key}":{`;
216
- const at = scope.lastIndexOf(mark);
217
- if (at < 0)
218
- return undefined;
219
- const json = objectAt(scope, at + mark.length - 1);
220
- if (json === undefined)
221
- return undefined;
222
- try {
223
- return JSON.parse(json);
224
- }
225
- catch {
226
- return undefined;
227
- }
216
+ return scope === undefined ? undefined : lastObjectOf(scope, key);
228
217
  }
229
218
  /**
230
219
  * Whether the provider stopped the answer on its content filter: the stream's terminal event (or a whole body) is an
@@ -347,27 +336,6 @@ export function webSearchesOf(text) {
347
336
  const count = isPlain(search) ? search.num_requests : undefined;
348
337
  return typeof count === "number" && Number.isInteger(count) && count >= 0 ? count : undefined;
349
338
  }
350
- /** The items of `type` in `value`, at any depth (a tool's output holds them). */
351
- function itemsIn(value, type) {
352
- if (Array.isArray(value))
353
- return value.reduce((n, item) => n + itemsIn(item, type), 0);
354
- if (!isPlain(value))
355
- return 0;
356
- return (value.type === type ? 1 : 0) + Object.values(value).reduce((n, item) => n + itemsIn(item, type), 0);
357
- }
358
- /**
359
- * The input tokens the provider bills for `body` that it does not carry (`providerInputOverhead`, with its sources). The
360
- * Responses API documents no prompt of its own that it adds on these routes (no hosted tool passes the policy but a
361
- * session's live web search, below), and the framing it puts around each input item and tool definition is a few tokens
362
- * each, fewer than the bytes of the JSON keys that item already spends in the body. An image is billed by its area, not
363
- * its bytes: each counts at the most it can be billed as, in place of the bytes its data URL takes in the body. A file input (a PDF, billed by its pages) has no stated bound, so a
364
- * body with one cannot be measured: this throws, and the request's input is unknown.
365
- */
366
- export function responsesServerInputOverhead(body) {
367
- if (itemsIn(body.input, "input_file") > 0)
368
- throw new Error("a file input's billed size has no stated bound");
369
- return providerInputOverhead("openai-responses", { tools: Array.isArray(body.tools) && body.tools.length > 0, images: responsesImagesIn(body.input), ...(typeof body.model === "string" ? { model: body.model } : {}) });
370
- }
371
339
  /** The text of a tool output item: a string, or the text of each of its parts. */
372
340
  /** Codex's status header of a tool output: the text it starts with (its first part), never what the script printed after it. */
373
341
  function statusText(item) {
@@ -456,7 +424,7 @@ function watchResponse(announce) {
456
424
  }
457
425
  const item = isPlain(event) && event.type === "response.output_item.done" && isPlain(event.item) ? event.item : undefined;
458
426
  if (item?.type === "custom_tool_call" && item.name === "exec" && typeof item.call_id === "string")
459
- announce.exec(item.call_id);
427
+ announce.exec(item.call_id, typeof item.input === "string" ? item.input : "");
460
428
  };
461
429
  const endLine = () => {
462
430
  const done = line;
@@ -515,9 +483,13 @@ export function responsesOutputAsked(body) {
515
483
  /** The least output a Responses body may be limited to and still answer: 1,024 tokens, plus its reasoning effort's
516
484
  * allowance when it reasons. */
517
485
  export function responsesOutputLeast(body) {
518
- const effort = isPlain(body.reasoning) && typeof body.reasoning.effort === "string" ? body.reasoning.effort : undefined;
486
+ const effort = responsesEffort(body);
519
487
  return ANSWER_TOKENS_LEAST + (effort === undefined ? 0 : REASONING_TOKENS_ALLOWED[effort] ?? 0);
520
488
  }
489
+ /** The reasoning effort a Responses body asks its model at (`reasoning.effort`), when it names one. */
490
+ export function responsesEffort(body) {
491
+ return isPlain(body.reasoning) && typeof body.reasoning.effort === "string" && body.reasoning.effort.length > 0 ? body.reasoning.effort : undefined;
492
+ }
521
493
  /** The reasoning tokens a Responses request may bill that its stream never shows (only a summary of its reasoning
522
494
  * streams): its effort's budget; none at effort `none`; and with no effort the body says (the model then reasons at its
523
495
  * own default, or not at all), its output limit, `fallback` when the body names none: the conservative side. An
@@ -567,11 +539,39 @@ export function addResponsesNote(body, text) {
567
539
  const input = Array.isArray(body.input) ? body.input : [];
568
540
  return { ...body, input: [...input, { type: "message", role: "developer", content: [{ type: "input_text", text }] }] };
569
541
  }
542
+ /** The error codes OpenAI's Responses API gives a ChatGPT plan's request past its limit, with status 429. */
543
+ const PLAN_LIMIT_ERRORS = new Set(["usage_limit_exceeded", "subscription_sharing_usage_limit_exceeded"]);
544
+ /** A ChatGPT plan's 429 past its limit (PLAN_LIMIT_ERRORS, as the error's `code` or `type`): final, in PLAN_LIMIT_WORDS.
545
+ * Any other error goes through as it came (a 429 for the rate, which its client waits out and asks again). */
546
+ export function planLimitOf(status, body) {
547
+ if (status !== 429)
548
+ return undefined;
549
+ let parsed;
550
+ try {
551
+ parsed = JSON.parse(body);
552
+ }
553
+ catch {
554
+ return undefined;
555
+ }
556
+ const error = isPlain(parsed) && isPlain(parsed.error) ? parsed.error : isPlain(parsed) ? parsed : undefined;
557
+ const named = [error?.code, error?.type].some((value) => typeof value === "string" && PLAN_LIMIT_ERRORS.has(value));
558
+ return named ? { message: PLAN_LIMIT_WORDS, code: PLAN_LIMIT_CODE } : undefined;
559
+ }
570
560
  export function codexPolicy(options) {
571
561
  const allowed = new Set(options.tools);
572
- const mcp = new Set(options.mcpTools ?? []);
573
562
  const maxOutputTokens = options.maxOutputTokens ?? 32_000;
574
563
  const search = options.webSearch === "live";
564
+ const plan = options.plan === true;
565
+ const tokensOf = search ? (text, body) => {
566
+ const usage = usageOf(text);
567
+ // A request that offered no search (`body`, the one it was sent with: a host's side request through the session's
568
+ // port, a learned workflow's node that offers only `submit`) ran none: 0, read from the request, never an unknown
569
+ // count that would make its whole known cost unknown (withWebSearches). One that offered it reads its answer.
570
+ const offered = Array.isArray(body?.tools) && body.tools.some((tool) => typeof tool === "object" && tool !== null && isLiveSearch(tool));
571
+ if (usage && body && !offered)
572
+ return { ...usage, webSearches: 0 };
573
+ return usage && { ...usage, webSearches: webSearchesOf(text) ?? null };
574
+ } : usageOf;
575
575
  return {
576
576
  id: "codex",
577
577
  routes: CODEX_RESPONSES_ROUTES,
@@ -580,7 +580,7 @@ export function codexPolicy(options) {
580
580
  const auth = String(headers.authorization ?? "");
581
581
  return auth.startsWith("Bearer ") ? auth.slice(7) : "";
582
582
  },
583
- authHeaders: (credential) => ({ authorization: `Bearer ${credential}` }),
583
+ authHeaders: (credential) => ({ authorization: `Bearer ${credential}`, ...(plan ? { originator: "agentrun" } : {}) }),
584
584
  apply(body, _route, context) {
585
585
  // The live search, offered by the request, goes only while the host says web_search may run now: read before this
586
586
  // request is shaped, never once for the session. A read that fails offers none.
@@ -589,34 +589,36 @@ export function codexPolicy(options) {
589
589
  return shaped(body, context, search);
590
590
  return options.searchAllowed().then((now) => shaped(body, context, now === true), () => shaped(body, context, false));
591
591
  },
592
- usageOf: search ? (text, body) => {
593
- const usage = usageOf(text);
594
- // A request that offered no search (`body`, the one it was sent with: a host's side request through the session's
595
- // port, a learned workflow's node that offers only `submit`) ran none: 0, read from the request, never an unknown
596
- // count that would make its whole known cost unknown (withWebSearches). One that offered it reads its answer.
597
- const offered = Array.isArray(body?.tools) && body.tools.some((tool) => typeof tool === "object" && tool !== null && isLiveSearch(tool));
598
- if (usage && body && !offered)
599
- return { ...usage, webSearches: 0 };
600
- return usage && { ...usage, webSearches: webSearchesOf(text) ?? null };
601
- } : usageOf,
592
+ usageOf: plan ? (text, body) => {
593
+ const usage = tokensOf(text, body);
594
+ return usage && { ...usage, billing: "plan" };
595
+ } : tokensOf,
596
+ ...(plan ? { finalError: planLimitOf } : {}),
602
597
  filtered,
603
598
  cut,
604
599
  watch: options.announce ? () => watchResponse(options.announce) : undefined,
605
600
  unwatched: options.announce ? () => options.announce.failed() : undefined,
606
601
  modelOf: (body) => (typeof body.model === "string" ? body.model : undefined),
607
- // The content a web search feeds the model is billed as input, and neither it nor the searches one response runs has a
608
- // stated bound: a body that offers web search has no input bound (undefined), so its input is unmeasured.
609
602
  outputAsked: responsesOutputAsked,
610
603
  outputLeast: responsesOutputLeast,
604
+ effortOf: responsesEffort,
611
605
  reasoningHidden: (body) => responsesReasoningHidden(body, maxOutputTokens),
612
606
  reasoningBytesOf: responsesReasoningBytes,
613
607
  contentBytesOf: responsesContentBytes,
614
- limitOutput: limitResponsesOutput,
608
+ // A plan request is held at $0, so it is never counted. A body that offers the live search has no input bound
609
+ // (below), and is never counted into one.
610
+ ...(plan ? {} : {
611
+ limitOutput: limitResponsesOutput,
612
+ countInputLocally: (body) => (search && Array.isArray(body.tools) && body.tools.some((tool) => isPlain(tool) && tool.type === "web_search") ? undefined : responsesLocalInputTokens(body)),
613
+ }),
614
+ // The content a web search feeds the model is billed as input, and neither it nor the searches one response runs has a
615
+ // stated bound: a body that offers web search has no input bound (undefined), so its input is unmeasured (and never
616
+ // counted into a number).
615
617
  serverInputOverhead: search ? (body) => {
616
618
  if (Array.isArray(body.tools) && body.tools.some((tool) => isPlain(tool) && tool.type === "web_search"))
617
619
  return undefined;
618
- return responsesServerInputOverhead(body);
619
- } : responsesServerInputOverhead,
620
+ return responsesInputOverhead(body);
621
+ } : responsesInputOverhead,
620
622
  };
621
623
  /** The body the provider gets, the live search offered only when `searchNow`. */
622
624
  function shaped(body, context, searchNow) {
@@ -627,7 +629,7 @@ export function codexPolicy(options) {
627
629
  const own = context?.host !== undefined ? sideToolNames(body.tools) : allowed;
628
630
  const out = {};
629
631
  for (const [key, value] of Object.entries(body)) {
630
- if (DROPPED_KEYS.has(key))
632
+ if (DROPPED_KEYS.has(key) || (plan && PLAN_DROPPED_KEYS.has(key)))
631
633
  continue;
632
634
  if (!BODY_KEYS.has(key) && !(context?.host !== undefined && SIDE_KEYS.has(key)))
633
635
  throw new ProxyRefusal(400, "the body has a field the Codex policy does not allow");
@@ -644,7 +646,7 @@ export function codexPolicy(options) {
644
646
  out.text = textOptions(out.text);
645
647
  // Without the search now, its tool is dropped as a session without one drops it (DROPPED_TOOLS).
646
648
  if (out.tools !== undefined)
647
- out.tools = ownTools(out.tools, own, searchNow, mcp);
649
+ out.tools = ownTools(out.tools, own, searchNow);
648
650
  if (out.tool_choice !== undefined)
649
651
  out.tool_choice = toolChoice(out.tool_choice, own, searchNow);
650
652
  if (Array.isArray(out.input) && out.input.some((item) => isPlain(item) && item.type === "additional_tools")) {
@@ -659,6 +661,11 @@ export function codexPolicy(options) {
659
661
  throw new ProxyRefusal(400, "parallel tool calls are not allowed in code mode: the model writes one exec at a time");
660
662
  out.parallel_tool_calls = false;
661
663
  }
664
+ if (plan) {
665
+ if (Array.isArray(out.input) && out.input.some((item) => isPlain(item) && item.role === "system"))
666
+ throw new ProxyRefusal(400, "A ChatGPT plan takes no system-role message: give those words as instructions or a developer message.");
667
+ return { ...out, model: options.model, store: false };
668
+ }
662
669
  const asked = typeof out.max_output_tokens === "number" && out.max_output_tokens > 0 ? out.max_output_tokens : maxOutputTokens;
663
670
  return { ...out, model: options.model, store: false, max_output_tokens: Math.min(asked, maxOutputTokens) };
664
671
  }
@@ -79,10 +79,10 @@ export interface SessionMachine {
79
79
  * The code-mode `exec` call the model proxy's latest answer carried, read before Codex could act on it (none when that
80
80
  * answer held none): what a nested call of a script is tied to, even before the `exec`'s line is in the rollout. */
81
81
  announcedExec?(): string | undefined;
82
+ /** The script of the `exec` the proxy announced last, by its call id: none for any other id. */
83
+ announcedInput?(callId: string): string | undefined;
82
84
  /** Told each line the rollout's tail reads, as it reads it: the harness's view of code mode follows the log from here. */
83
85
  onRolloutLine?(listener: (line: string) => void): void;
84
- /** Given the drive's hooks for a call the harness never sees (a remote MCP server's tool, mcp.ts). */
85
- onCalls?(hooks: CallHooks): void;
86
86
  /** Told when the model proxy reads that the provider cut the turn's answer at its output limit, before Codex has the
87
87
  * piece that carries the stop (its output tokens, when the answer said them): the harness ends the turn there. */
88
88
  onCut?(listener: (stop: {
@@ -97,14 +97,6 @@ export interface SessionMachine {
97
97
  fsync(): Promise<void>;
98
98
  close(): Promise<void>;
99
99
  }
100
- /** The drive's hooks for a call Codex runs without the harness (code-mode.ts gives them, mcp.ts uses them). */
101
- export interface CallHooks {
102
- /** Resolves true once the call's own line (a script's nested call: its script's) is in the log, false when it never came. */
103
- barrier(callId: string): Promise<boolean>;
104
- /** After a recovery: what answers a call of `tool` with `args` that already completed in the interrupted turn (a rewritten
105
- * script re-issues its calls under new ids), taken once; undefined for any other call. */
106
- recovered(tool: string, args: unknown): string | undefined;
107
- }
108
100
  /** What a harness's drive asks its machine factory for: the drive, the model route its proxy serves, and its deadline. */
109
101
  export interface AcquireMachineRequest {
110
102
  ctx: DriveContext;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { CODEX_TOOL_OUTPUT_TOKENS, codexAdapter } from "./adapter.js";
2
2
  /** The policy a Codex session's model proxy applies, for a host that serves the same route itself (a faux harness's). */
3
- export { codexPolicy, webSearchUsd, withWebSearches } from "./host/policy.js";
3
+ export { codexPolicy, planLimitOf, webSearchUsd, withWebSearches } from "./host/policy.js";
4
4
  /** The check the adapter runs on the host's skills when it is made: @parcha/agentrun-kernel' own, as the Claude adapter's. */
5
5
  export { skillProblems } from "@parcha/agentrun-kernel";
6
6
  export type { HostSkill } from "@parcha/agentrun-kernel";
@@ -10,4 +10,4 @@ export { CODEX_VERSION, codexBinary, codexTarget } from "./binary.js";
10
10
  /** The shapes of a tool's schema Codex 0.164 drops or retypes (schema.ts): a host may refuse them sooner (an MCP grant, at its save). */
11
11
  export { codexSchemaProblems } from "./schema.js";
12
12
  export { verifyCodex, verifyCodexAsync, verifyCodexBinary, verifyCodexBinaryAsync } from "./verify.js";
13
- export { CODEX_BINARY_SHA256, CODEX_INSTALL, CODEX_NPM_INTEGRITY, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
13
+ export { CODEX_BASE_INPUT_TOKENS, CODEX_BINARY_SHA256, CODEX_INSTALL, CODEX_NPM_INTEGRITY, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  export { CODEX_TOOL_OUTPUT_TOKENS, codexAdapter } from "./adapter.js";
2
2
  /** The policy a Codex session's model proxy applies, for a host that serves the same route itself (a faux harness's). */
3
- export { codexPolicy, webSearchUsd, withWebSearches } from "./host/policy.js";
3
+ export { codexPolicy, planLimitOf, webSearchUsd, withWebSearches } from "./host/policy.js";
4
4
  /** The check the adapter runs on the host's skills when it is made: @parcha/agentrun-kernel' own, as the Claude adapter's. */
5
5
  export { skillProblems } from "@parcha/agentrun-kernel";
6
6
  export { CODEX_VERSION, codexBinary, codexTarget } from "./binary.js";
7
7
  /** The shapes of a tool's schema Codex 0.164 drops or retypes (schema.ts): a host may refuse them sooner (an MCP grant, at its save). */
8
8
  export { codexSchemaProblems } from "./schema.js";
9
9
  export { verifyCodex, verifyCodexAsync, verifyCodexBinary, verifyCodexBinaryAsync } from "./verify.js";
10
- export { CODEX_BINARY_SHA256, CODEX_INSTALL, CODEX_NPM_INTEGRITY, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
10
+ export { CODEX_BASE_INPUT_TOKENS, CODEX_BINARY_SHA256, CODEX_INSTALL, CODEX_NPM_INTEGRITY, CodexNotInstalled, CodexPinMismatch } from "./versions.js";
package/dist/scripts.d.ts CHANGED
@@ -18,14 +18,32 @@ export type Tie = {
18
18
  } | {
19
19
  kind: "none";
20
20
  };
21
+ /** What a rollout line says of a script: its `exec` line opened it (`input`, the script), or an output finished it (`output`,
22
+ * that output's text; `failed`, the script failed, as its status header says). */
23
+ export type ScriptEvent = {
24
+ kind: "opened";
25
+ exec: string;
26
+ input: string;
27
+ } | {
28
+ kind: "finished";
29
+ exec: string;
30
+ output: string;
31
+ failed: boolean;
32
+ };
21
33
  export declare class Scripts {
22
34
  private readonly open;
23
35
  /** The `exec` calls whose script finished. */
24
36
  private readonly done;
25
37
  /** The cell each `wait` call in the rollout resumes. */
26
38
  private readonly waitsOn;
27
- /** Reads one rollout line. */
28
- note(line: string): void;
39
+ /** Reads one rollout line: what it says of a script, if anything. A script opened (its `exec` line, with its input, the
40
+ * script) or finished (the output that ended it: its own, or the `wait`'s on its cell). */
41
+ note(line: string): ScriptEvent | undefined;
42
+ private finish;
43
+ /** The unfinished `exec` that yielded on cell `cell`, if any. */
44
+ execOn(cell: string): string | undefined;
45
+ /** The script of an unfinished `exec` whose line the rollout holds; none for any other. */
46
+ inputOf(exec: string): string | undefined;
29
47
  /** The scripts that may call a host tool now: the rollout's unfinished ones, and the `exec` the proxy's latest answer carried
30
48
  * if it is not among them and has not finished (its line may not be in the rollout yet). */
31
49
  live(announced?: string): string[];
@@ -58,6 +76,14 @@ export interface NestedFact {
58
76
  rollout?: RolloutNested;
59
77
  /** The host parked the call for a person's approval (`parkedKey`'s record): it did not run, whatever its record says. */
60
78
  parked?: true;
79
+ /** Asked again on this resume (code-mode.ts recoverItems): it never reached its intent before, as a park at the host's gate
80
+ * leaves a call, and went through the gate now, the person's answer on it: what it answered, and whether it ran (a refusal
81
+ * never does). */
82
+ resumed?: {
83
+ text: string;
84
+ isError: boolean;
85
+ ran: boolean;
86
+ };
61
87
  }
62
88
  export type Settled = {
63
89
  kind: "completed";
@@ -83,6 +109,19 @@ export declare const markParked: (ctx: DriveContext, callId: string) => Promise<
83
109
  * (`boundResult`), since the store keeps a result whole and Codex got its cut; or the stored text itself, as a session
84
110
  * written before that bound holds it in both records. */
85
111
  export declare function settle(fact: NestedFact): Settled;
112
+ /** The most a recovered script's output holds (a cut-off `exec`'s, or the `wait` on its cell): one result at the host's bound, as
113
+ * the script was handed it, and the words that tell each call's outcome around it. It stands in for the script's own output,
114
+ * which the model reads as one tool result. Past it, every result it quotes is cut to the same share, each keeping its start
115
+ * and its last line (a filed answer's says where the whole is) and saying where it was cut (`cut`): never silently, and every
116
+ * call's outcome is still told. Only when the lines alone pass it is the output itself cut, with its note: the calls past
117
+ * the cut are not in it, and the recovery note does not say they are (`Recovered.shown`). */
118
+ export declare const EXEC_RECOVERY_MAX_CHARS: number;
119
+ /** A recovered output, and the calls whose outcome it tells (`shown`): each whose line is whole in it and quotes some of its
120
+ * result or error (all of it, or its start with the line saying where it was cut). */
121
+ export interface Recovered {
122
+ output: string;
123
+ shown: string[];
124
+ }
86
125
  /** A tie record of a nested call: the `exec` it ran under (none when the answer that wrote the script could not be read to its end,
87
126
  * so which script it was cannot be told) and the turn it ran in. */
88
127
  export interface NestedTie {
@@ -96,10 +135,29 @@ export declare function recoveryFacts<T>(execs: readonly string[], ties: readonl
96
135
  own: T[];
97
136
  loose: T[];
98
137
  }>;
138
+ /** Whether a recovered script's output tells what the call came to, its result or its error (a call that waited for a person's
139
+ * approval, then was answered, included): the recovery note then says the outcome is there, not that it is not shown. */
140
+ export declare function outcomeShown(fact: NestedFact): boolean;
99
141
  /** The output a cut-off `exec` is answered with: its nested calls, in order, each with what it came to, and that nothing was run
100
142
  * again. A completed call's effect is done, a never tool's included; a call with no end is interrupted. `loose`: calls of this turn
101
143
  * whose script could not be told (given to the last cut-off exec only), listed apart under their own heading. */
144
+ /** What a dangling `wait` on a yielded exec's cell is told when calls of that script that waited for a person's approval
145
+ * were answered on this resume (code-mode.ts recoverItems): each call's outcome, in order. */
146
+ export declare function waitResumedText(cell: string, resumed: readonly NestedFact[]): string;
147
+ /** waitResumedText, and the calls whose outcome it tells. */
148
+ export declare function waitResumed(cell: string, resumed: readonly NestedFact[]): Recovered;
149
+ /** What the host's row of an `exec` a recovery answered shows: the model is told its script was cut short, but on the record
150
+ * those words belong to an exec that failed (recoveredFailed). One that ended ok shows its calls' outcomes alone. */
151
+ export declare function recoveredRowText(output: string, failed: boolean): string;
152
+ /** Whether a cut-off `exec` answered with its recovered output (execRecovery) failed, by the rule a codemode script stopped
153
+ * and run again follows on every other harness (serve's runner/meta-tools.ts endedWith): it failed when its last call did
154
+ * not run (a person refused it, or a park was never answered), was cut off before it reported, or failed; or when it made
155
+ * no call of its own. A script whose last call ran and answered (one that parked and was allowed, too) was stopped and
156
+ * resumed, not failed. `own`: its calls, in order. */
157
+ export declare function recoveredFailed(own: readonly NestedFact[]): boolean;
102
158
  export declare function execRecoveryOutput(facts: readonly NestedFact[], loose?: readonly NestedFact[]): string;
159
+ /** execRecoveryOutput, and the calls whose outcome it tells: only those the recovery note may say are above. */
160
+ export declare function execRecovery(facts: readonly NestedFact[], loose?: readonly NestedFact[]): Recovered;
103
161
  /** The text of a tool's recorded output (a string, or `{ text }` with images). */
104
162
  export declare function outputTextOf(output: unknown): string;
105
163
  /** A call by its tool and arguments, whatever the order of the arguments' keys: what a `never` tool's call is matched on. */