@parcha/agentrun-harness-codex 0.0.0-stage → 0.1.0-beta.101
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 +349 -0
- package/LICENSE +202 -0
- package/NOTICE +6 -0
- package/README.md +80 -2
- package/dist/adapter.d.ts +93 -0
- package/dist/adapter.js +375 -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/catalog.d.ts +35 -0
- package/dist/catalog.js +104 -0
- package/dist/code-mode.d.ts +171 -0
- package/dist/code-mode.js +514 -0
- package/dist/config.d.ts +84 -0
- package/dist/config.js +214 -0
- package/dist/facts.d.ts +2 -0
- package/dist/facts.js +40 -0
- package/dist/harness.d.ts +210 -0
- package/dist/harness.js +1112 -0
- package/dist/host/kernel.d.ts +20 -0
- package/dist/host/kernel.js +3 -0
- package/dist/host/machine.d.ts +81 -0
- package/dist/host/machine.js +355 -0
- package/dist/host/policy.d.ts +113 -0
- package/dist/host/policy.js +683 -0
- package/dist/host/process.d.ts +151 -0
- package/dist/host/process.js +50 -0
- package/dist/host/sandbox.d.ts +36 -0
- package/dist/host/sandbox.js +35 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +10 -0
- package/dist/rollout.d.ts +96 -0
- package/dist/rollout.js +170 -0
- package/dist/schema.d.ts +14 -0
- package/dist/schema.js +178 -0
- package/dist/scripts.d.ts +218 -0
- package/dist/scripts.js +409 -0
- package/dist/tool-images.d.ts +7 -0
- package/dist/tool-images.js +18 -0
- package/dist/transcript.d.ts +20 -0
- package/dist/transcript.js +73 -0
- package/dist/verify.d.ts +62 -0
- package/dist/verify.js +155 -0
- package/dist/versions.d.ts +43 -0
- package/dist/versions.js +72 -0
- package/package.json +72 -4
- package/vendor/durable-harness/UPSTREAM.json +39 -0
package/dist/schema.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// What the Codex adapter does about the schema of a tool, written for AgentRun. Codex 0.164.0 sanitizes the JSON Schema
|
|
2
|
+
// of every tool it offers its model (measured on the pinned binary, test/fixtures/schema-column.json): it drops a set of
|
|
3
|
+
// keywords and it drops or retypes a few shapes. So that no difference is silent:
|
|
4
|
+
// - a shape Codex drops or retypes is REFUSED when the session is checked, by tool, JSON pointer and keyword;
|
|
5
|
+
// - a keyword Codex only strips (a bound, a pattern, a format, a title, a default) is DESCRIBED, in plain words, in the
|
|
6
|
+
// tool's description, which Codex forwards whole. The host and the DSL still validate against the original schema;
|
|
7
|
+
// only the model's copy is described.
|
|
8
|
+
/** The keywords Codex strips and the adapter describes, with the words for each. */
|
|
9
|
+
const DESCRIBED = Object.freeze({
|
|
10
|
+
minLength: (v) => `at least ${show(v)} characters`,
|
|
11
|
+
maxLength: (v) => `at most ${show(v)} characters`,
|
|
12
|
+
maxItems: (v) => `at most ${show(v)} items`,
|
|
13
|
+
minProperties: (v) => `at least ${show(v)} properties`,
|
|
14
|
+
maxProperties: (v) => `at most ${show(v)} properties`,
|
|
15
|
+
minimum: (v) => `at least ${show(v)}`,
|
|
16
|
+
maximum: (v) => `at most ${show(v)}`,
|
|
17
|
+
exclusiveMinimum: (v) => `greater than ${show(v)}`,
|
|
18
|
+
exclusiveMaximum: (v) => `less than ${show(v)}`,
|
|
19
|
+
multipleOf: (v) => `a multiple of ${show(v)}`,
|
|
20
|
+
pattern: (v) => `matches ${show(v)}`,
|
|
21
|
+
format: (v) => `format ${show(v)}`,
|
|
22
|
+
uniqueItems: (v) => (v === true ? "items are unique" : undefined),
|
|
23
|
+
title: (v) => `titled ${JSON.stringify(v)}`,
|
|
24
|
+
default: (v) => `default ${show(v)}`,
|
|
25
|
+
examples: (v) => `examples ${show(v)}`,
|
|
26
|
+
nullable: (v) => (v === true ? "may be null" : undefined),
|
|
27
|
+
deprecated: (v) => (v === true ? "deprecated" : undefined),
|
|
28
|
+
readOnly: (v) => (v === true ? "read only" : undefined),
|
|
29
|
+
writeOnly: (v) => (v === true ? "write only" : undefined),
|
|
30
|
+
});
|
|
31
|
+
/** Keywords Codex strips that mean nothing to a model: a comment for people, the dialect marker `$schema` (Codex drops it
|
|
32
|
+
* whatever it names, and the shared check has already refused one that names no dialect the harnesses take), and the
|
|
33
|
+
* DSL's own `criteria`, which the DSL removes from the model's copy itself. Dropped without a word. */
|
|
34
|
+
const NOISE = Object.freeze(["$comment", "$schema", "criteria"]);
|
|
35
|
+
/** The order the words of one position are written in. */
|
|
36
|
+
const ORDER = ["pattern", "format", "exclusiveMinimum", "exclusiveMaximum", "minimum", "maximum", "multipleOf", "minLength", "maxLength", "maxItems", "minProperties", "maxProperties", "uniqueItems", "nullable", "readOnly", "writeOnly", "deprecated", "default", "examples", "title"];
|
|
37
|
+
export const CODEX_DESCRIBED_KEYWORDS = Object.freeze(Object.keys(DESCRIBED));
|
|
38
|
+
/** The heading the described constraints go under, in the tool's description. */
|
|
39
|
+
export const DESCRIBED_HEADING = "Constraints on the arguments (checked on every call; not part of the schema you were given):";
|
|
40
|
+
const show = (v) => (typeof v === "string" ? v : JSON.stringify(v));
|
|
41
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
42
|
+
const SCALAR = (v) => v === null || ["string", "number", "boolean"].includes(typeof v);
|
|
43
|
+
/** The keywords whose value is a map of schemas, a schema, or a list of schemas: where a schema position is. */
|
|
44
|
+
const SCHEMA_MAPS = ["properties", "$defs", "definitions", "dependentSchemas"];
|
|
45
|
+
const SCHEMA_LISTS = ["anyOf", "oneOf", "allOf"];
|
|
46
|
+
const SCHEMA_ONES = ["items", "additionalProperties", "contains", "propertyNames", "unevaluatedItems", "unevaluatedProperties"];
|
|
47
|
+
const esc = (key) => key.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
48
|
+
/** The schema positions directly below `node`, in the order they are visited. */
|
|
49
|
+
function childrenOf({ pointer, path, node, inAllOf }) {
|
|
50
|
+
const out = [];
|
|
51
|
+
const add = (sub, at, readable, allOf = inAllOf) => {
|
|
52
|
+
if (isObject(sub))
|
|
53
|
+
out.push({ pointer: at, path: readable, node: sub, inAllOf: allOf });
|
|
54
|
+
};
|
|
55
|
+
for (const key of SCHEMA_MAPS) {
|
|
56
|
+
const map = node[key];
|
|
57
|
+
if (isObject(map))
|
|
58
|
+
for (const [name, sub] of Object.entries(map))
|
|
59
|
+
add(sub, `${pointer}/${key}/${esc(name)}`, key === "properties" ? `${path ? `${path}.` : ""}${name}` : `${path ? `${path}.` : ""}${key}.${name}`);
|
|
60
|
+
}
|
|
61
|
+
for (const key of SCHEMA_LISTS) {
|
|
62
|
+
const list = node[key];
|
|
63
|
+
if (Array.isArray(list))
|
|
64
|
+
list.forEach((sub, i) => add(sub, `${pointer}/${key}/${i}`, `${path}${path ? " " : ""}(${key} ${i + 1})`, inAllOf || key === "allOf"));
|
|
65
|
+
}
|
|
66
|
+
for (const key of SCHEMA_ONES) {
|
|
67
|
+
const sub = node[key];
|
|
68
|
+
if (isObject(sub))
|
|
69
|
+
add(sub, `${pointer}/${key}`, key === "items" ? `${path}[]` : `${path}${path ? "." : ""}(${key})`);
|
|
70
|
+
else if (Array.isArray(sub))
|
|
71
|
+
sub.forEach((s, i) => add(s, `${pointer}/${key}/${i}`, `${path}[${i}]`));
|
|
72
|
+
}
|
|
73
|
+
for (const key of ["not", "if", "then", "else"])
|
|
74
|
+
add(node[key], `${pointer}/${key}`, `${path}${path ? "." : ""}(${key})`);
|
|
75
|
+
if (Array.isArray(node.prefixItems))
|
|
76
|
+
node.prefixItems.forEach((s, i) => add(s, `${pointer}/prefixItems/${i}`, `${path}[${i}]`));
|
|
77
|
+
if (isObject(node.patternProperties))
|
|
78
|
+
for (const [name, sub] of Object.entries(node.patternProperties))
|
|
79
|
+
add(sub, `${pointer}/patternProperties/${esc(name)}`, `${path}.(${name})`);
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
/** Every schema position of `schema`, depth first, with `$defs` and union branches. A loop with its own stack, so no
|
|
83
|
+
* depth of schema overflows the call stack. */
|
|
84
|
+
function positions(schema) {
|
|
85
|
+
const out = [];
|
|
86
|
+
if (!isObject(schema))
|
|
87
|
+
return out;
|
|
88
|
+
const stack = [{ pointer: "", path: "", node: schema, inAllOf: false }];
|
|
89
|
+
// A node already visited is skipped, so a cycle (an object that contains itself, which only code can build) ends
|
|
90
|
+
// here whichever caller reaches it. A node shared by two places (not a cycle) is walked at the first.
|
|
91
|
+
const seen = new WeakSet();
|
|
92
|
+
for (let here = stack.pop(); here; here = stack.pop()) {
|
|
93
|
+
if (seen.has(here.node))
|
|
94
|
+
continue;
|
|
95
|
+
seen.add(here.node);
|
|
96
|
+
out.push(here);
|
|
97
|
+
const below = childrenOf(here);
|
|
98
|
+
for (let i = below.length - 1; i >= 0; i -= 1)
|
|
99
|
+
stack.push(below[i]);
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
/** The shapes of `schema` Codex would drop or retype, as one refusal each: `<tool>: <pointer>: <keyword> is not supported by
|
|
104
|
+
* Codex 0.164.0 (it drops or retypes it)`. Empty when Codex carries the schema (less what is described). */
|
|
105
|
+
export function codexSchemaProblems(tool, schema) {
|
|
106
|
+
const problems = [];
|
|
107
|
+
const refuse = (pointer, keyword) => problems.push(`${tool}: ${pointer || "/"}: ${keyword} is not supported by Codex 0.164.0 (it drops or retypes it)`);
|
|
108
|
+
for (const { pointer, node } of positions(schema)) {
|
|
109
|
+
if (Array.isArray(node.items))
|
|
110
|
+
refuse(`${pointer}/items`, "items (an array)");
|
|
111
|
+
if (node.prefixItems !== undefined)
|
|
112
|
+
refuse(`${pointer}/prefixItems`, "prefixItems");
|
|
113
|
+
if (node.patternProperties !== undefined)
|
|
114
|
+
refuse(`${pointer}/patternProperties`, "patternProperties");
|
|
115
|
+
const conditional = ["if", "then", "else"].find((key) => node[key] !== undefined);
|
|
116
|
+
if (conditional)
|
|
117
|
+
refuse(`${pointer}/${conditional}`, "if/then/else");
|
|
118
|
+
if (node.not !== undefined)
|
|
119
|
+
refuse(`${pointer}/not`, "not");
|
|
120
|
+
if ((Array.isArray(node.enum) && node.enum.some((v) => !SCALAR(v))) || (node.const !== undefined && !SCALAR(node.const)))
|
|
121
|
+
refuse(`${pointer}/${node.const !== undefined && !SCALAR(node.const) ? "const" : "enum"}`, "enum with a non-scalar value");
|
|
122
|
+
// With no `type`, Codex types an enum or a const `string`: a number, a boolean or a null in it would be mistyped.
|
|
123
|
+
const values = Array.isArray(node.enum) ? node.enum : node.const !== undefined ? [node.const] : [];
|
|
124
|
+
if (node.type === undefined && values.every(SCALAR) && values.some((v) => typeof v !== "string"))
|
|
125
|
+
refuse(`${pointer}/${Array.isArray(node.enum) ? "enum" : "const"}`, "enum with non-string values and no type (Codex types it string)");
|
|
126
|
+
for (const key of ["contains", "dependentRequired", "propertyNames"])
|
|
127
|
+
if (node[key] !== undefined)
|
|
128
|
+
refuse(`${pointer}/${key}`, key);
|
|
129
|
+
if (node.items === true || node.items === false)
|
|
130
|
+
refuse(`${pointer}/items`, "items (a boolean)");
|
|
131
|
+
if (Array.isArray(node.allOf) && node.allOf.some((member) => isObject(member) && positions(member).some((p) => CODEX_DESCRIBED_KEYWORDS.some((k) => k !== "title" && k !== "default" && p.node[k] !== undefined))))
|
|
132
|
+
refuse(`${pointer}/allOf`, "allOf with constraints in its members");
|
|
133
|
+
}
|
|
134
|
+
return problems;
|
|
135
|
+
}
|
|
136
|
+
/** One line per position that has a stripped keyword, sorted by JSON pointer: `<path>: <type>, <words>`. */
|
|
137
|
+
export function describeDropped(schema) {
|
|
138
|
+
const lines = [];
|
|
139
|
+
for (const { pointer, path, node } of positions(schema)) {
|
|
140
|
+
const words = ORDER.flatMap((key) => (node[key] === undefined ? [] : [DESCRIBED[key](node[key])].filter((w) => w !== undefined)));
|
|
141
|
+
if (!words.length)
|
|
142
|
+
continue;
|
|
143
|
+
const type = typeof node.type === "string" ? [node.type] : [];
|
|
144
|
+
lines.push([pointer, `${path || "(the whole value)"}: ${[...type, ...words].join(", ")}`]);
|
|
145
|
+
}
|
|
146
|
+
return lines.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)).map(([, line]) => line);
|
|
147
|
+
}
|
|
148
|
+
/** The description Codex forwards for a tool: its own, then the described constraints under one heading. */
|
|
149
|
+
export function describedDescription(description, schema) {
|
|
150
|
+
const lines = describeDropped(schema);
|
|
151
|
+
return lines.length ? `${description}\n\n${DESCRIBED_HEADING}\n${lines.map((l) => `- ${l}`).join("\n")}` : description;
|
|
152
|
+
}
|
|
153
|
+
/** `schema` as Codex forwards it, once its strippable keywords are gone: the original less the described keywords, a position
|
|
154
|
+
* left empty typed `{ "type": "string" }` and an object position with no `properties` given `properties: {}`, as measured.
|
|
155
|
+
* For tests, and the recorded column. */
|
|
156
|
+
export function stripDescribed(schema) {
|
|
157
|
+
const copy = structuredClone(schema);
|
|
158
|
+
for (const { node } of positions(copy)) {
|
|
159
|
+
let stripped = false;
|
|
160
|
+
for (const key of [...CODEX_DESCRIBED_KEYWORDS, ...NOISE])
|
|
161
|
+
if (key in node) {
|
|
162
|
+
delete node[key];
|
|
163
|
+
stripped = true;
|
|
164
|
+
}
|
|
165
|
+
// A const is an enum of one; an enum or const with no type is typed string (strings only: the others are refused).
|
|
166
|
+
if (node.const !== undefined) {
|
|
167
|
+
node.enum = [node.const];
|
|
168
|
+
delete node.const;
|
|
169
|
+
}
|
|
170
|
+
if (Array.isArray(node.enum) && node.type === undefined)
|
|
171
|
+
node.type = "string";
|
|
172
|
+
if (stripped && Object.keys(node).length === 0)
|
|
173
|
+
node.type = "string";
|
|
174
|
+
if (node.type === "object" && node.properties === undefined)
|
|
175
|
+
node.properties = {};
|
|
176
|
+
}
|
|
177
|
+
return copy;
|
|
178
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import type { DriveContext } from "@parcha/agentrun-kernel/kernel";
|
|
2
|
+
import { type ResultBudget } from "./host/process.js";
|
|
3
|
+
/** The id Codex gives a host tool called from a code-mode script. */
|
|
4
|
+
export declare const NESTED_CALL: RegExp;
|
|
5
|
+
/** What the session is told when the proxy could not watch an answer to its end: the answer may carry an `exec` it did not see, so
|
|
6
|
+
* no script can be told from it. It counts as a script of its own, one that is never in the log. */
|
|
7
|
+
export declare const UNWATCHED = "(unwatched answer)";
|
|
8
|
+
/** What to do with a nested call: run it under `exec`; hold it until `exec`'s line is in the rollout; refuse it, as two scripts
|
|
9
|
+
* are live; or hold it, as no script is known yet. */
|
|
10
|
+
export type Tie = {
|
|
11
|
+
kind: "tied";
|
|
12
|
+
exec: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "held";
|
|
15
|
+
exec: string;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "ambiguous";
|
|
18
|
+
live: string[];
|
|
19
|
+
} | {
|
|
20
|
+
kind: "none";
|
|
21
|
+
};
|
|
22
|
+
/** What a rollout line says of a script: its `exec` line opened it (`input`, the script; `yieldMs`, how long Codex waits on
|
|
23
|
+
* it before it yields); it yielded (`cell`: its exec's output, or a `wait`'s, said "Script running with cell ID N"); a `wait`
|
|
24
|
+
* on its cell began (`yieldMs`, that wait's); or an output finished it (`output`, that output's text; `failed`, the script
|
|
25
|
+
* failed, as its status header says; `unrun`, Codex's own words when no script status came back, SCRIPT_STATUS). */
|
|
26
|
+
export type ScriptEvent = {
|
|
27
|
+
kind: "opened";
|
|
28
|
+
exec: string;
|
|
29
|
+
input: string;
|
|
30
|
+
yieldMs: number;
|
|
31
|
+
} | {
|
|
32
|
+
kind: "yielded";
|
|
33
|
+
exec: string;
|
|
34
|
+
cell: string;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "waiting";
|
|
37
|
+
exec: string;
|
|
38
|
+
cell: string;
|
|
39
|
+
yieldMs: number;
|
|
40
|
+
} | {
|
|
41
|
+
kind: "finished";
|
|
42
|
+
exec: string;
|
|
43
|
+
output: string;
|
|
44
|
+
failed: boolean;
|
|
45
|
+
unrun?: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The status headers Codex 0.164.0 puts first on an exec's or a wait's output when its code-mode host ran the script and
|
|
49
|
+
* said how it went: it completed, failed (threw, or its cell was gone), was terminated (a `wait` with `terminate`), or still
|
|
50
|
+
* runs (RUNNING). Each is followed by a line of its own ("Wall time ..."). An output that starts with none of them is Codex's
|
|
51
|
+
* own words, not the script's: the host never ran it to an end it could report (it was not there, did not start, answered
|
|
52
|
+
* outside its protocol, or died with the script in it). Codex hands those words to the model and ends the turn completed; the
|
|
53
|
+
* session fails the turn instead (CodeModeDeps.hostFailed), a nested call of that script run first or not. Only the first text
|
|
54
|
+
* of an output is read: what a script prints comes after Codex's header, never before it. test/code-mode-host-down.test.mjs,
|
|
55
|
+
* which CI runs on the pinned binary under AGENTRUN_CODEX_REQUIRE_BINARY=1, finds each header in the pinned binary (Codex
|
|
56
|
+
* builds "Script failed" at run time: a real script that throws holds that one), so a release that rewords one fails there.
|
|
57
|
+
*/
|
|
58
|
+
export declare const SCRIPT_STATUS: readonly string[];
|
|
59
|
+
/**
|
|
60
|
+
* Codex's answers to an `exec` the model wrote wrong (no script, or a bad first-line pragma), each by its fixed part (the words
|
|
61
|
+
* before any detail Codex adds): the model's own mistake, which it reads and can put right in the same turn. No script status
|
|
62
|
+
* comes with them, and none is owed: Codex answers them from the exec's text alone, before it starts or asks the host, so
|
|
63
|
+
* they come back the same with no host beside Codex at all (the sweep and the live rows of test/code-mode-host-down.test.mjs).
|
|
64
|
+
* Each is in the pinned binary (the same test).
|
|
65
|
+
*/
|
|
66
|
+
export declare const EXEC_MISTAKES: readonly string[];
|
|
67
|
+
/** Whether an output's first text is a script status (a header, then its line's end) or Codex's answer to an exec the model
|
|
68
|
+
* wrote wrong: anything else, the host never reported the script. */
|
|
69
|
+
export declare const scriptStatusSaid: (status: string) => boolean;
|
|
70
|
+
/** How long Codex waits on an `exec` before it yields when the script's first-line pragma names no `yield_time_ms` (the pinned
|
|
71
|
+
* Codex's default: a script that never ends yields at about 30 s), and on a `wait` that names none (its tool's description:
|
|
72
|
+
* 10000 ms). */
|
|
73
|
+
export declare const EXEC_YIELD_MS = 30000;
|
|
74
|
+
export declare const WAIT_YIELD_MS = 10000;
|
|
75
|
+
/** The `yield_time_ms` an exec's first-line pragma (`// @exec: {...}`) names, if it names a valid one. */
|
|
76
|
+
export declare function execYieldMs(input: string): number;
|
|
77
|
+
export declare class Scripts {
|
|
78
|
+
private readonly open;
|
|
79
|
+
/** The `exec` calls whose script finished. */
|
|
80
|
+
private readonly done;
|
|
81
|
+
/** The cell each `wait` call in the rollout resumes. */
|
|
82
|
+
private readonly waitsOn;
|
|
83
|
+
/** Reads one rollout line: what it says of a script, if anything. A script opened (its `exec` line, with its input, the
|
|
84
|
+
* script) or finished (the output that ended it: its own, or the `wait`'s on its cell). */
|
|
85
|
+
note(line: string): ScriptEvent | undefined;
|
|
86
|
+
private finish;
|
|
87
|
+
/** The unfinished `exec` that yielded on cell `cell`, if any. */
|
|
88
|
+
execOn(cell: string): string | undefined;
|
|
89
|
+
/** The script of an unfinished `exec` whose line the rollout holds; none for any other. */
|
|
90
|
+
inputOf(exec: string): string | undefined;
|
|
91
|
+
/** The scripts that may call a host tool now: the rollout's unfinished ones, and the `exec` the proxy's latest answer carried
|
|
92
|
+
* if it is not among them and has not finished (its line may not be in the rollout yet). */
|
|
93
|
+
live(announced?: string): string[];
|
|
94
|
+
/** What to do with a nested call now, given the exec the proxy announced and whether a call id is in the rollout. */
|
|
95
|
+
tie(announced: string | undefined, logged: (callId: string) => boolean): Tie;
|
|
96
|
+
}
|
|
97
|
+
/** What the rollout's `item_completed` line says of a nested call: Codex writes it after the call was answered, so a crash
|
|
98
|
+
* before it leaves none. */
|
|
99
|
+
export interface RolloutNested {
|
|
100
|
+
tool: string;
|
|
101
|
+
ok: boolean;
|
|
102
|
+
text: string;
|
|
103
|
+
}
|
|
104
|
+
/** The nested calls the rollout's lines hold a completion for, by their `exec-<uuid>` id. */
|
|
105
|
+
export declare function completedNested(lines: readonly string[]): Map<string, RolloutNested>;
|
|
106
|
+
/** One nested call of a cut-off `exec`, as the two sources have it. */
|
|
107
|
+
export interface NestedFact {
|
|
108
|
+
callId: string;
|
|
109
|
+
tool: string;
|
|
110
|
+
/** The session's own record (the effect of `tool:<id>`): none when the call never started. */
|
|
111
|
+
store?: {
|
|
112
|
+
status: "completed" | "failed" | "started";
|
|
113
|
+
text?: string;
|
|
114
|
+
interrupted?: boolean; /** What a script's nested call was sent for a tool with a value (scriptAnswer: the value as JSON, its images' data in it), which the rollout holds instead of `text`. */
|
|
115
|
+
sent?: string; /** How the bridge cut the result it handed Codex (its record, `boundKey`): the characters kept and the whole length. */
|
|
116
|
+
bound?: {
|
|
117
|
+
kept: number;
|
|
118
|
+
whole: number;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
/** What the harness's recovery note of the same turn calls it (the kernel's one rule, process/recovery.ts): `retryable` is a
|
|
122
|
+
* safe tool's call that a crash cut off, which the note tells the model is safe to repeat. */
|
|
123
|
+
told?: "completed" | "failed" | "interrupted" | "retryable" | "running";
|
|
124
|
+
rollout?: RolloutNested;
|
|
125
|
+
/** The host parked the call for a person's approval (`parkedKey`'s record): it did not run, whatever its record says. */
|
|
126
|
+
parked?: true;
|
|
127
|
+
/** Asked again on this resume (code-mode.ts recoverItems): it never reached its intent before, as a park at the host's gate
|
|
128
|
+
* leaves a call, and went through the gate now, the person's answer on it: what it answered, and whether it ran (a refusal
|
|
129
|
+
* never does). */
|
|
130
|
+
resumed?: {
|
|
131
|
+
text: string;
|
|
132
|
+
isError: boolean;
|
|
133
|
+
ran: boolean;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export type Settled = {
|
|
137
|
+
kind: "completed";
|
|
138
|
+
text: string;
|
|
139
|
+
} | {
|
|
140
|
+
kind: "failed";
|
|
141
|
+
text: string;
|
|
142
|
+
} | {
|
|
143
|
+
kind: "interrupted";
|
|
144
|
+
} | {
|
|
145
|
+
kind: "parked";
|
|
146
|
+
};
|
|
147
|
+
/** The session's record that the host parked the call `callId` for a person's approval, so it did not run: what the call
|
|
148
|
+
* was answered (the host's waiting text) reads as its outcome, and is none. */
|
|
149
|
+
export declare const parkedKey: (callId: string) => string;
|
|
150
|
+
/** Records that the host parked `callId` (a host tool's or a remote MCP server's), before its answer is recorded: a parked
|
|
151
|
+
* call is never told as completed, after a crash either. */
|
|
152
|
+
export declare const markParked: (ctx: DriveContext, callId: string) => Promise<unknown>;
|
|
153
|
+
/** What a nested call came to. A call the host parked is `parked`, whatever else holds: it never ran. Else the store's record first, the rollout's completion second: both complete and agreeing, or
|
|
154
|
+
* one of them, is that outcome; both complete and disagreeing, or a call that started and has no end in either, is
|
|
155
|
+
* interrupted (its effect is unknown), and a failure the store marks interrupted is interrupted. They agree when the
|
|
156
|
+
* rollout holds what the bridge handed Codex for the stored text: the stored text itself; or, where the bridge recorded
|
|
157
|
+
* its cut (`store.bound`), a text that starts with the stored text's kept characters, the stored text as long as the
|
|
158
|
+
* record says, compared on those lengths and never on the cut's note, whose words are free to change; or the stored
|
|
159
|
+
* text cut at the host's bound, as a session written before the record (a release before it) holds it. Any other cut
|
|
160
|
+
* with no record is no proof the two are one call's. */
|
|
161
|
+
export declare function settle(fact: NestedFact): Settled;
|
|
162
|
+
/** 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
|
|
163
|
+
* 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,
|
|
164
|
+
* which the model reads as one tool result. Past it, every result it quotes is cut to the same share, each keeping its start
|
|
165
|
+
* and its last line (a filed answer's says where the whole is) and saying where it was cut (`cut`): never silently, and every
|
|
166
|
+
* call's outcome is still told. Only when the lines alone pass it is the output itself cut, with its note: the calls past
|
|
167
|
+
* the cut are not in it, and the recovery note does not say they are (`Recovered.shown`). */
|
|
168
|
+
export declare const EXEC_RECOVERY_MAX_CHARS: number;
|
|
169
|
+
/** The most a recovered output holds for a model of `budget` (the session's window): EXEC_RECOVERY_MAX_CHARS with none, or
|
|
170
|
+
* one too large to bind (as it always was); else the per-model bound itself (the kernel's resultMaxChars), words and all,
|
|
171
|
+
* since the output is one tool result the model reads. */
|
|
172
|
+
export declare function recoveryMaxChars(budget?: ResultBudget): number;
|
|
173
|
+
/** A recovered output, and the calls whose outcome it tells (`shown`): each whose line is whole in it and quotes some of its
|
|
174
|
+
* result or error (all of it, or its start with the line saying where it was cut). */
|
|
175
|
+
export interface Recovered {
|
|
176
|
+
output: string;
|
|
177
|
+
shown: string[];
|
|
178
|
+
}
|
|
179
|
+
/** 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,
|
|
180
|
+
* so which script it was cannot be told) and the turn it ran in. */
|
|
181
|
+
export interface NestedTie {
|
|
182
|
+
callId: string;
|
|
183
|
+
exec: string | null;
|
|
184
|
+
since?: number;
|
|
185
|
+
}
|
|
186
|
+
/** The nested calls to list for each cut-off `exec` of the interrupted turn `since`: its own, in order; and the calls whose
|
|
187
|
+
* script could not be told, which ran in that turn, under the LAST cut-off exec only, apart from its own, so each is listed once. */
|
|
188
|
+
export declare function recoveryFacts<T>(execs: readonly string[], ties: readonly NestedTie[], since: number, factOf: (tie: NestedTie) => T): Map<string, {
|
|
189
|
+
own: T[];
|
|
190
|
+
loose: T[];
|
|
191
|
+
}>;
|
|
192
|
+
/** 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
|
|
193
|
+
* approval, then was answered, included): the recovery note then says the outcome is there, not that it is not shown. */
|
|
194
|
+
export declare function outcomeShown(fact: NestedFact): boolean;
|
|
195
|
+
/** 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
|
|
196
|
+
* 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
|
|
197
|
+
* whose script could not be told (given to the last cut-off exec only), listed apart under their own heading. */
|
|
198
|
+
/** What a dangling `wait` on a yielded exec's cell is told when calls of that script that waited for a person's approval
|
|
199
|
+
* were answered on this resume (code-mode.ts recoverItems): each call's outcome, in order. */
|
|
200
|
+
export declare function waitResumedText(cell: string, resumed: readonly NestedFact[], budget?: ResultBudget): string;
|
|
201
|
+
/** waitResumedText, and the calls whose outcome it tells. */
|
|
202
|
+
export declare function waitResumed(cell: string, resumed: readonly NestedFact[], budget?: ResultBudget): Recovered;
|
|
203
|
+
/** 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
|
|
204
|
+
* those words belong to an exec that failed (recoveredFailed). One that ended ok shows its calls' outcomes alone. */
|
|
205
|
+
export declare function recoveredRowText(output: string, failed: boolean): string;
|
|
206
|
+
/** Whether a cut-off `exec` answered with its recovered output (execRecovery) failed, by the rule a codemode script stopped
|
|
207
|
+
* and run again follows on every other harness (serve's runner/meta-tools.ts endedWith): it failed when its last call did
|
|
208
|
+
* not run (a person refused it, or a park was never answered), was cut off before it reported, or failed; or when it made
|
|
209
|
+
* no call of its own. A script whose last call ran and answered (one that parked and was allowed, too) was stopped and
|
|
210
|
+
* resumed, not failed. `own`: its calls, in order. */
|
|
211
|
+
export declare function recoveredFailed(own: readonly NestedFact[]): boolean;
|
|
212
|
+
export declare function execRecoveryOutput(facts: readonly NestedFact[], loose?: readonly NestedFact[], budget?: ResultBudget): string;
|
|
213
|
+
/** execRecoveryOutput, and the calls whose outcome it tells: only those the recovery note may say are above. */
|
|
214
|
+
export declare function execRecovery(facts: readonly NestedFact[], loose?: readonly NestedFact[], budget?: ResultBudget): Recovered;
|
|
215
|
+
/** The text of a tool's recorded output (a string, or `{ text }` with images). */
|
|
216
|
+
export declare function outputTextOf(output: unknown): string;
|
|
217
|
+
/** A call by its tool and arguments, whatever the order of the arguments' keys: what a `never` tool's call is matched on. */
|
|
218
|
+
export declare const callKey: (tool: string, args: unknown) => string;
|