@parcha/agentrun-harness-codex 0.1.0-beta.38 → 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.
- package/CHANGELOG.md +22 -0
- package/README.md +2 -2
- package/dist/adapter.d.ts +5 -7
- package/dist/adapter.js +22 -43
- package/dist/code-mode.d.ts +15 -2
- package/dist/code-mode.js +110 -16
- package/dist/facts.js +5 -1
- package/dist/harness.d.ts +7 -1
- package/dist/harness.js +1 -1
- package/dist/host/machine.d.ts +3 -0
- package/dist/host/machine.js +11 -1
- package/dist/host/policy.d.ts +16 -3
- package/dist/host/policy.js +58 -17
- package/dist/host/process.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/scripts.d.ts +49 -2
- package/dist/scripts.js +175 -28
- package/dist/versions.d.ts +5 -0
- package/dist/versions.js +5 -0
- package/package.json +3 -3
package/dist/host/policy.d.ts
CHANGED
|
@@ -26,14 +26,19 @@ export interface CodexPolicyOptions {
|
|
|
26
26
|
* `tool_choice` naming the search is then refused. Absent: the live search is offered whenever `webSearch` is on. */
|
|
27
27
|
searchAllowed?: () => Promise<boolean>;
|
|
28
28
|
/** Told, before Codex has the piece of an answer, what the answer carries: `response()` when an answer starts, and
|
|
29
|
-
* `exec(callId)` for each code-mode `exec` call it holds. The session ties a script's nested
|
|
30
|
-
* latest answer, which is known here before Codex can run anything of it. */
|
|
29
|
+
* `exec(callId, input)` for each code-mode `exec` call it holds, with its script. The session ties a script's nested
|
|
30
|
+
* calls to the `exec` of the latest answer, which is known here before Codex can run anything of it. */
|
|
31
31
|
announce?: {
|
|
32
32
|
response(): void;
|
|
33
|
-
exec(callId: string): void;
|
|
33
|
+
exec(callId: string, input?: string): void;
|
|
34
34
|
failed(): void;
|
|
35
35
|
end(): void;
|
|
36
36
|
};
|
|
37
|
+
/** The route is a person's ChatGPT plan (its access token the credential), whose Responses API keeps rules of its own:
|
|
38
|
+
* no `max_output_tokens` is sent (none is clamped or added: the proxy limits no output and counts no input on it), the
|
|
39
|
+
* keys it does not take are dropped (PLAN_DROPPED_KEYS), a system-role message is refused in words, each request names
|
|
40
|
+
* its originator (`agentrun`), and its usage is booked as the plan's (`billing: "plan"`). */
|
|
41
|
+
plan?: boolean;
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
39
44
|
* Whether the provider stopped the answer on its content filter: the stream's terminal event (or a whole body) is an
|
|
@@ -76,6 +81,8 @@ export declare function responsesOutputAsked(body: Record<string, unknown>): num
|
|
|
76
81
|
/** The least output a Responses body may be limited to and still answer: 1,024 tokens, plus its reasoning effort's
|
|
77
82
|
* allowance when it reasons. */
|
|
78
83
|
export declare function responsesOutputLeast(body: Record<string, unknown>): number;
|
|
84
|
+
/** The reasoning effort a Responses body asks its model at (`reasoning.effort`), when it names one. */
|
|
85
|
+
export declare function responsesEffort(body: Record<string, unknown>): string | undefined;
|
|
79
86
|
/** The reasoning tokens a Responses request may bill that its stream never shows (only a summary of its reasoning
|
|
80
87
|
* streams): its effort's budget; none at effort `none`; and with no effort the body says (the model then reasons at its
|
|
81
88
|
* own default, or not at all), its output limit, `fallback` when the body names none: the conservative side. An
|
|
@@ -94,4 +101,10 @@ export declare function limitResponsesOutput(body: Record<string, unknown>, max:
|
|
|
94
101
|
* at the end of `input`. Caching is by prefix, so the earlier items stay a hit; the client's next request, which sends
|
|
95
102
|
* its own input whole, does not carry it. */
|
|
96
103
|
export declare function addResponsesNote(body: Record<string, unknown>, text: string): Record<string, unknown>;
|
|
104
|
+
/** A ChatGPT plan's 429 past its limit (PLAN_LIMIT_ERRORS, as the error's `code` or `type`): final, in PLAN_LIMIT_WORDS.
|
|
105
|
+
* Any other error goes through as it came (a 429 for the rate, which its client waits out and asks again). */
|
|
106
|
+
export declare function planLimitOf(status: number, body: string): {
|
|
107
|
+
message: string;
|
|
108
|
+
code: string;
|
|
109
|
+
} | undefined;
|
|
97
110
|
export declare function codexPolicy(options: CodexPolicyOptions): ProviderPolicy;
|
package/dist/host/policy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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"] },
|
|
@@ -51,6 +52,8 @@ 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
59
|
* session's own (`allowed`, by name). */
|
|
@@ -421,7 +424,7 @@ function watchResponse(announce) {
|
|
|
421
424
|
}
|
|
422
425
|
const item = isPlain(event) && event.type === "response.output_item.done" && isPlain(event.item) ? event.item : undefined;
|
|
423
426
|
if (item?.type === "custom_tool_call" && item.name === "exec" && typeof item.call_id === "string")
|
|
424
|
-
announce.exec(item.call_id);
|
|
427
|
+
announce.exec(item.call_id, typeof item.input === "string" ? item.input : "");
|
|
425
428
|
};
|
|
426
429
|
const endLine = () => {
|
|
427
430
|
const done = line;
|
|
@@ -480,9 +483,13 @@ export function responsesOutputAsked(body) {
|
|
|
480
483
|
/** The least output a Responses body may be limited to and still answer: 1,024 tokens, plus its reasoning effort's
|
|
481
484
|
* allowance when it reasons. */
|
|
482
485
|
export function responsesOutputLeast(body) {
|
|
483
|
-
const effort =
|
|
486
|
+
const effort = responsesEffort(body);
|
|
484
487
|
return ANSWER_TOKENS_LEAST + (effort === undefined ? 0 : REASONING_TOKENS_ALLOWED[effort] ?? 0);
|
|
485
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
|
+
}
|
|
486
493
|
/** The reasoning tokens a Responses request may bill that its stream never shows (only a summary of its reasoning
|
|
487
494
|
* streams): its effort's budget; none at effort `none`; and with no effort the body says (the model then reasons at its
|
|
488
495
|
* own default, or not at all), its output limit, `fallback` when the body names none: the conservative side. An
|
|
@@ -532,10 +539,39 @@ export function addResponsesNote(body, text) {
|
|
|
532
539
|
const input = Array.isArray(body.input) ? body.input : [];
|
|
533
540
|
return { ...body, input: [...input, { type: "message", role: "developer", content: [{ type: "input_text", text }] }] };
|
|
534
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
|
+
}
|
|
535
560
|
export function codexPolicy(options) {
|
|
536
561
|
const allowed = new Set(options.tools);
|
|
537
562
|
const maxOutputTokens = options.maxOutputTokens ?? 32_000;
|
|
538
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;
|
|
539
575
|
return {
|
|
540
576
|
id: "codex",
|
|
541
577
|
routes: CODEX_RESPONSES_ROUTES,
|
|
@@ -544,7 +580,7 @@ export function codexPolicy(options) {
|
|
|
544
580
|
const auth = String(headers.authorization ?? "");
|
|
545
581
|
return auth.startsWith("Bearer ") ? auth.slice(7) : "";
|
|
546
582
|
},
|
|
547
|
-
authHeaders: (credential) => ({ authorization: `Bearer ${credential}
|
|
583
|
+
authHeaders: (credential) => ({ authorization: `Bearer ${credential}`, ...(plan ? { originator: "agentrun" } : {}) }),
|
|
548
584
|
apply(body, _route, context) {
|
|
549
585
|
// The live search, offered by the request, goes only while the host says web_search may run now: read before this
|
|
550
586
|
// request is shaped, never once for the session. A read that fails offers none.
|
|
@@ -553,16 +589,11 @@ export function codexPolicy(options) {
|
|
|
553
589
|
return shaped(body, context, search);
|
|
554
590
|
return options.searchAllowed().then((now) => shaped(body, context, now === true), () => shaped(body, context, false));
|
|
555
591
|
},
|
|
556
|
-
usageOf:
|
|
557
|
-
const usage =
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
const offered = Array.isArray(body?.tools) && body.tools.some((tool) => typeof tool === "object" && tool !== null && isLiveSearch(tool));
|
|
562
|
-
if (usage && body && !offered)
|
|
563
|
-
return { ...usage, webSearches: 0 };
|
|
564
|
-
return usage && { ...usage, webSearches: webSearchesOf(text) ?? null };
|
|
565
|
-
} : usageOf,
|
|
592
|
+
usageOf: plan ? (text, body) => {
|
|
593
|
+
const usage = tokensOf(text, body);
|
|
594
|
+
return usage && { ...usage, billing: "plan" };
|
|
595
|
+
} : tokensOf,
|
|
596
|
+
...(plan ? { finalError: planLimitOf } : {}),
|
|
566
597
|
filtered,
|
|
567
598
|
cut,
|
|
568
599
|
watch: options.announce ? () => watchResponse(options.announce) : undefined,
|
|
@@ -570,10 +601,16 @@ export function codexPolicy(options) {
|
|
|
570
601
|
modelOf: (body) => (typeof body.model === "string" ? body.model : undefined),
|
|
571
602
|
outputAsked: responsesOutputAsked,
|
|
572
603
|
outputLeast: responsesOutputLeast,
|
|
604
|
+
effortOf: responsesEffort,
|
|
573
605
|
reasoningHidden: (body) => responsesReasoningHidden(body, maxOutputTokens),
|
|
574
606
|
reasoningBytesOf: responsesReasoningBytes,
|
|
575
607
|
contentBytesOf: responsesContentBytes,
|
|
576
|
-
|
|
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
|
+
}),
|
|
577
614
|
// The content a web search feeds the model is billed as input, and neither it nor the searches one response runs has a
|
|
578
615
|
// stated bound: a body that offers web search has no input bound (undefined), so its input is unmeasured (and never
|
|
579
616
|
// counted into a number).
|
|
@@ -582,7 +619,6 @@ export function codexPolicy(options) {
|
|
|
582
619
|
return undefined;
|
|
583
620
|
return responsesInputOverhead(body);
|
|
584
621
|
} : responsesInputOverhead,
|
|
585
|
-
countInput: OPENAI_INPUT_COUNTER,
|
|
586
622
|
};
|
|
587
623
|
/** The body the provider gets, the live search offered only when `searchNow`. */
|
|
588
624
|
function shaped(body, context, searchNow) {
|
|
@@ -593,7 +629,7 @@ export function codexPolicy(options) {
|
|
|
593
629
|
const own = context?.host !== undefined ? sideToolNames(body.tools) : allowed;
|
|
594
630
|
const out = {};
|
|
595
631
|
for (const [key, value] of Object.entries(body)) {
|
|
596
|
-
if (DROPPED_KEYS.has(key))
|
|
632
|
+
if (DROPPED_KEYS.has(key) || (plan && PLAN_DROPPED_KEYS.has(key)))
|
|
597
633
|
continue;
|
|
598
634
|
if (!BODY_KEYS.has(key) && !(context?.host !== undefined && SIDE_KEYS.has(key)))
|
|
599
635
|
throw new ProxyRefusal(400, "the body has a field the Codex policy does not allow");
|
|
@@ -625,6 +661,11 @@ export function codexPolicy(options) {
|
|
|
625
661
|
throw new ProxyRefusal(400, "parallel tool calls are not allowed in code mode: the model writes one exec at a time");
|
|
626
662
|
out.parallel_tool_calls = false;
|
|
627
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
|
+
}
|
|
628
669
|
const asked = typeof out.max_output_tokens === "number" && out.max_output_tokens > 0 ? out.max_output_tokens : maxOutputTokens;
|
|
629
670
|
return { ...out, model: options.model, store: false, max_output_tokens: Math.min(asked, maxOutputTokens) };
|
|
630
671
|
}
|
package/dist/host/process.d.ts
CHANGED
|
@@ -79,6 +79,8 @@ 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
86
|
/** Told when the model proxy reads that the provider cut the turn's answer at its output limit, before Codex has the
|
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
|
-
|
|
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[];
|
|
@@ -91,6 +109,19 @@ export declare const markParked: (ctx: DriveContext, callId: string) => Promise<
|
|
|
91
109
|
* (`boundResult`), since the store keeps a result whole and Codex got its cut; or the stored text itself, as a session
|
|
92
110
|
* written before that bound holds it in both records. */
|
|
93
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
|
+
}
|
|
94
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,
|
|
95
126
|
* so which script it was cannot be told) and the turn it ran in. */
|
|
96
127
|
export interface NestedTie {
|
|
@@ -104,13 +135,29 @@ export declare function recoveryFacts<T>(execs: readonly string[], ties: readonl
|
|
|
104
135
|
own: T[];
|
|
105
136
|
loose: T[];
|
|
106
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;
|
|
107
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
|
|
108
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
|
|
109
143
|
* whose script could not be told (given to the last cut-off exec only), listed apart under their own heading. */
|
|
110
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
|
|
111
145
|
* were answered on this resume (code-mode.ts recoverItems): each call's outcome, in order. */
|
|
112
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;
|
|
113
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;
|
|
114
161
|
/** The text of a tool's recorded output (a string, or `{ text }` with images). */
|
|
115
162
|
export declare function outputTextOf(output: unknown): string;
|
|
116
163
|
/** A call by its tool and arguments, whatever the order of the arguments' keys: what a `never` tool's call is matched on. */
|
package/dist/scripts.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// Which code-mode script a host tool's nested call belongs to. Written for AgentRun.
|
|
2
|
+
//
|
|
3
|
+
// A host tool a code-mode model's script calls arrives on the app-server's stream as a call under an id of Codex's own
|
|
4
|
+
// (`exec-<uuid>`) that carries no parent, no cell and no `exec` id, and the rollout holds no line for it until after it is
|
|
5
|
+
// answered. So the call is tied to the one script that can be running, and that is read from two places that cannot be
|
|
6
|
+
// ahead of Codex:
|
|
7
|
+
// - the rollout: an `exec` call line opens a script, and it stays open until an output says it finished: its own, or, when
|
|
8
|
+
// that says "Script running with cell ID N" (it yielded and went on), the output of the `wait` that finishes cell N;
|
|
9
|
+
// - the model proxy: the `exec` the latest answer carried, which it read before Codex had that part of the answer, so
|
|
10
|
+
// before the `exec`'s line could be in the rollout.
|
|
11
|
+
// The proxy offers no `exec` while a cell runs and no parallel calls, so one script is live at a time. A model that writes an
|
|
12
|
+
// `exec` anyway makes two live, and then a nested call cannot be told from the other's.
|
|
13
|
+
import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
1
14
|
import { boundResult } from "./host/process.js";
|
|
2
15
|
import { parseLine } from "./rollout.js";
|
|
3
16
|
/** The id Codex gives a host tool called from a code-mode script. */
|
|
@@ -9,6 +22,9 @@ export const UNWATCHED = "(unwatched answer)";
|
|
|
9
22
|
const statusOf = (output) => typeof output === "string" ? output : Array.isArray(output) && typeof output[0]?.text === "string" ? output[0].text : "";
|
|
10
23
|
/** A cell that yielded and still runs, as its status header says. */
|
|
11
24
|
const RUNNING = /^Script running with cell ID (\S+)/;
|
|
25
|
+
/** A script that failed (it threw, or its cell was gone), as its status header says. The rollout's output line has no
|
|
26
|
+
* status field of its own: this header is the only place Codex says how a script ended. */
|
|
27
|
+
const FAILED = /^Script failed\b/;
|
|
12
28
|
const textOf = (output) => typeof output === "string" ? output : Array.isArray(output) ? output.map((part) => (typeof part?.text === "string" ? part.text : "")).join("\n") : "";
|
|
13
29
|
export class Scripts {
|
|
14
30
|
open = [];
|
|
@@ -16,27 +32,31 @@ export class Scripts {
|
|
|
16
32
|
done = new Set();
|
|
17
33
|
/** The cell each `wait` call in the rollout resumes. */
|
|
18
34
|
waitsOn = new Map();
|
|
19
|
-
/** Reads one rollout line.
|
|
35
|
+
/** Reads one rollout line: what it says of a script, if anything. A script opened (its `exec` line, with its input, the
|
|
36
|
+
* script) or finished (the output that ended it: its own, or the `wait`'s on its cell). */
|
|
20
37
|
note(line) {
|
|
21
38
|
if (!line.includes("call_id"))
|
|
22
|
-
return;
|
|
39
|
+
return undefined;
|
|
23
40
|
const p = parseLine(line)?.payload;
|
|
24
41
|
if (!p || typeof p.call_id !== "string")
|
|
25
|
-
return;
|
|
42
|
+
return undefined;
|
|
26
43
|
const id = p.call_id;
|
|
27
44
|
const running = RUNNING.exec(statusOf(p.output));
|
|
28
45
|
if (p.type === "custom_tool_call" && p.name === "exec") {
|
|
29
|
-
if (
|
|
30
|
-
|
|
46
|
+
if (this.open.some((x) => x.exec === id))
|
|
47
|
+
return undefined;
|
|
48
|
+
const input = typeof p.input === "string" ? p.input : "";
|
|
49
|
+
this.open.push({ exec: id, input });
|
|
50
|
+
return { kind: "opened", exec: id, input };
|
|
31
51
|
}
|
|
32
52
|
else if (p.type === "custom_tool_call_output") {
|
|
33
53
|
const at = this.open.findIndex((x) => x.exec === id);
|
|
34
54
|
if (at < 0)
|
|
35
|
-
return;
|
|
55
|
+
return undefined;
|
|
36
56
|
if (running)
|
|
37
57
|
this.open[at].cell = running[1];
|
|
38
58
|
else
|
|
39
|
-
this.
|
|
59
|
+
return this.finish(at, p.output);
|
|
40
60
|
}
|
|
41
61
|
else if (p.type === "function_call" && p.name === "wait") {
|
|
42
62
|
try {
|
|
@@ -49,8 +69,22 @@ export class Scripts {
|
|
|
49
69
|
else if (p.type === "function_call_output" && this.waitsOn.has(id) && !running) {
|
|
50
70
|
const at = this.open.findIndex((x) => x.cell === this.waitsOn.get(id));
|
|
51
71
|
if (at >= 0)
|
|
52
|
-
this.
|
|
72
|
+
return this.finish(at, p.output);
|
|
53
73
|
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
finish(at, output) {
|
|
77
|
+
const exec = this.open.splice(at, 1)[0].exec;
|
|
78
|
+
this.done.add(exec);
|
|
79
|
+
return { kind: "finished", exec, output: textOf(output), failed: FAILED.test(statusOf(output)) };
|
|
80
|
+
}
|
|
81
|
+
/** The unfinished `exec` that yielded on cell `cell`, if any. */
|
|
82
|
+
execOn(cell) {
|
|
83
|
+
return this.open.find((x) => x.cell === cell)?.exec;
|
|
84
|
+
}
|
|
85
|
+
/** The script of an unfinished `exec` whose line the rollout holds; none for any other. */
|
|
86
|
+
inputOf(exec) {
|
|
87
|
+
return this.open.find((x) => x.exec === exec)?.input;
|
|
54
88
|
}
|
|
55
89
|
/** The scripts that may call a host tool now: the rollout's unfinished ones, and the `exec` the proxy's latest answer carried
|
|
56
90
|
* if it is not among them and has not finished (its line may not be in the rollout yet). */
|
|
@@ -109,7 +143,71 @@ export function settle(fact) {
|
|
|
109
143
|
return stored.kind === rolled.kind && (rolled.text === stored.text || rolled.text === boundResult(stored.text).text || (store?.sent !== undefined && rolled.text === store.sent)) ? stored : { kind: "interrupted" };
|
|
110
144
|
return stored ?? rolled ?? { kind: "interrupted" };
|
|
111
145
|
}
|
|
112
|
-
|
|
146
|
+
/** 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
|
|
147
|
+
* 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,
|
|
148
|
+
* which the model reads as one tool result. Past it, every result it quotes is cut to the same share, each keeping its start
|
|
149
|
+
* and its last line (a filed answer's says where the whole is) and saying where it was cut (`cut`): never silently, and every
|
|
150
|
+
* call's outcome is still told. Only when the lines alone pass it is the output itself cut, with its note: the calls past
|
|
151
|
+
* the cut are not in it, and the recovery note does not say they are (`Recovered.shown`). */
|
|
152
|
+
export const EXEC_RECOVERY_MAX_CHARS = HOST_RESULT_MAX_CHARS + 2_000;
|
|
153
|
+
/** A last line longer than this is not kept when a result is cut: it is the result's own text, not a pointer to the rest. */
|
|
154
|
+
const LAST_LINE_MAX = 1_000;
|
|
155
|
+
/** `text` within `cap` characters: whole when it fits; else its start, a line saying where it was cut (as `boundResult`'s
|
|
156
|
+
* does), and its last line when that is short (a filed answer's, which says where the whole is), never splitting a
|
|
157
|
+
* character written as a surrogate pair. Whole, too, when the cut would be no shorter (a short result is never swapped
|
|
158
|
+
* for a longer line saying it was cut). `kept`: how much of the start of `text` is there. */
|
|
159
|
+
function cut(text, cap) {
|
|
160
|
+
if (text.length <= cap)
|
|
161
|
+
return { text, kept: text.length };
|
|
162
|
+
const at = text.lastIndexOf("\n");
|
|
163
|
+
const last = at >= 0 && text.length - at <= LAST_LINE_MAX ? text.slice(at) : "";
|
|
164
|
+
const note = (kept) => `\n[cut at ${kept} of ${text.length} characters]`;
|
|
165
|
+
let kept = Math.max(0, cap - note(cap).length - last.length);
|
|
166
|
+
if (kept > 0 && (text.charCodeAt(kept - 1) & 0xfc00) === 0xd800 && (text.charCodeAt(kept) & 0xfc00) === 0xdc00)
|
|
167
|
+
kept -= 1;
|
|
168
|
+
const short = `${text.slice(0, kept)}${note(kept)}${last}`;
|
|
169
|
+
return short.length < text.length ? { text: short, kept } : { text, kept: text.length };
|
|
170
|
+
}
|
|
171
|
+
/** A told call's line, the text it quotes held to `cap`. */
|
|
172
|
+
const lineOf = (told, cap) => (told.text === undefined ? `${told.head}${told.tail}` : `${told.head}${JSON.stringify(cut(told.text, cap).text)}${told.tail}`);
|
|
173
|
+
/** A recovered output built by `build` from its calls' lines (`told`, in the order `build` writes them) at a cap on each
|
|
174
|
+
* quoted text: whole when it fits in EXEC_RECOVERY_MAX_CHARS; else at the largest cap that fits (the same for every quoted
|
|
175
|
+
* text); else, the lines alone passing the bound, the output cut to the bound with its note, and the calls past the cut
|
|
176
|
+
* not in it. */
|
|
177
|
+
function fitted(told, build) {
|
|
178
|
+
const at = (cap, output, limit = output.length) => {
|
|
179
|
+
const shown = [];
|
|
180
|
+
let from = 0;
|
|
181
|
+
for (const t of told) {
|
|
182
|
+
const line = lineOf(t, cap);
|
|
183
|
+
const pos = output.indexOf(line, from);
|
|
184
|
+
if (pos < 0 || pos + line.length > limit)
|
|
185
|
+
break;
|
|
186
|
+
from = pos + line.length;
|
|
187
|
+
if (t.shows && t.callId !== undefined && (t.text === undefined || t.text === "" || cut(t.text, cap).kept > 0))
|
|
188
|
+
shown.push(t.callId);
|
|
189
|
+
}
|
|
190
|
+
return { output, shown };
|
|
191
|
+
};
|
|
192
|
+
const whole = build(Number.POSITIVE_INFINITY);
|
|
193
|
+
if (whole.length <= EXEC_RECOVERY_MAX_CHARS)
|
|
194
|
+
return at(Number.POSITIVE_INFINITY, whole);
|
|
195
|
+
const least = build(0);
|
|
196
|
+
if (least.length > EXEC_RECOVERY_MAX_CHARS) {
|
|
197
|
+
const { text, kept } = cut(least, EXEC_RECOVERY_MAX_CHARS);
|
|
198
|
+
return at(0, text, kept);
|
|
199
|
+
}
|
|
200
|
+
let lo = 0;
|
|
201
|
+
let hi = whole.length;
|
|
202
|
+
while (lo < hi) {
|
|
203
|
+
const mid = Math.ceil((lo + hi) / 2);
|
|
204
|
+
if (build(mid).length <= EXEC_RECOVERY_MAX_CHARS)
|
|
205
|
+
lo = mid;
|
|
206
|
+
else
|
|
207
|
+
hi = mid - 1;
|
|
208
|
+
}
|
|
209
|
+
return at(lo, build(lo));
|
|
210
|
+
}
|
|
113
211
|
/** The nested calls to list for each cut-off `exec` of the interrupted turn `since`: its own, in order; and the calls whose
|
|
114
212
|
* 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. */
|
|
115
213
|
export function recoveryFacts(execs, ties, since, factOf) {
|
|
@@ -120,45 +218,94 @@ export function recoveryFacts(execs, ties, since, factOf) {
|
|
|
120
218
|
out.set(exec, { own: ties.filter((t) => t.exec === exec).map(factOf), loose: exec === last ? loose : [] });
|
|
121
219
|
return out;
|
|
122
220
|
}
|
|
221
|
+
/** What a call of a recovered script came to, as its line tells it. A result or an error it quotes is the one the script was
|
|
222
|
+
* handed live: held to the host's bound as the bridge holds it (`boundResult`); the session's record keeps it whole. */
|
|
123
223
|
const describeCall = (fact, label) => {
|
|
124
224
|
const settled = settle(fact);
|
|
225
|
+
const shows = outcomeShown(fact);
|
|
226
|
+
const told = (head, text, tail) => ({ head, text: boundResult(text).text, tail, callId: fact.callId, shows });
|
|
125
227
|
if (settled.kind === "parked")
|
|
126
|
-
return `${label} was waiting for a person's approval and did not run; it was not run again
|
|
228
|
+
return { head: `${label} was waiting for a person's approval and did not run; it was not run again.`, tail: "" };
|
|
127
229
|
const again = fact.resumed;
|
|
128
230
|
if (again && !again.ran)
|
|
129
|
-
return `${label} waited for a person's approval, then:
|
|
231
|
+
return told(`${label} waited for a person's approval, then: `, again.text, ". It did not run.");
|
|
130
232
|
if (again && again.isError)
|
|
131
|
-
return `${label} waited for a person's approval, then ran and failed:
|
|
233
|
+
return told(`${label} waited for a person's approval, then ran and failed: `, again.text, ". It was not run again.");
|
|
132
234
|
if (again)
|
|
133
|
-
return `${label} waited for a person's approval, then ran:
|
|
235
|
+
return told(`${label} waited for a person's approval, then ran: `, again.text, ". Its effect is done; it was not run again.");
|
|
134
236
|
if (settled.kind === "completed")
|
|
135
|
-
return `${label} completed:
|
|
237
|
+
return told(`${label} completed: `, settled.text, ". Its effect is done; it was not run again.");
|
|
136
238
|
if (settled.kind === "failed")
|
|
137
|
-
return `${label} failed:
|
|
239
|
+
return told(`${label} failed: `, settled.text, ". It was not run again.");
|
|
138
240
|
// Told as the recovery note of the same turn tells it, which reaches the model with this output: a safe tool's call a crash cut off.
|
|
139
241
|
if (fact.told === "retryable")
|
|
140
|
-
return `${label} was started and did not report a result. It is safe to repeat. It was not run again
|
|
141
|
-
return `${label} was started and did not report a result, so it may have taken effect: check before calling it again. It was not run again
|
|
242
|
+
return { head: `${label} was started and did not report a result. It is safe to repeat. It was not run again.`, tail: "" };
|
|
243
|
+
return { head: `${label} was started and did not report a result, so it may have taken effect: check before calling it again. It was not run again.`, tail: "" };
|
|
142
244
|
};
|
|
245
|
+
/** 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
|
|
246
|
+
* approval, then was answered, included): the recovery note then says the outcome is there, not that it is not shown. */
|
|
247
|
+
export function outcomeShown(fact) {
|
|
248
|
+
if (fact.resumed)
|
|
249
|
+
return true;
|
|
250
|
+
const kind = settle(fact).kind;
|
|
251
|
+
return kind === "completed" || kind === "failed";
|
|
252
|
+
}
|
|
143
253
|
/** 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
|
|
144
254
|
* 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
|
|
145
255
|
* whose script could not be told (given to the last cut-off exec only), listed apart under their own heading. */
|
|
146
256
|
/** What a dangling `wait` on a yielded exec's cell is told when calls of that script that waited for a person's approval
|
|
147
257
|
* were answered on this resume (code-mode.ts recoverItems): each call's outcome, in order. */
|
|
148
258
|
export function waitResumedText(cell, resumed) {
|
|
149
|
-
|
|
150
|
-
|
|
259
|
+
return waitResumed(cell, resumed).output;
|
|
260
|
+
}
|
|
261
|
+
/** waitResumedText, and the calls whose outcome it tells. */
|
|
262
|
+
export function waitResumed(cell, resumed) {
|
|
263
|
+
const told = resumed.map((fact, i) => describeCall(fact, `${i + 1}. ${fact.tool}`));
|
|
264
|
+
return fitted(told, (cap) => `${waitCutOpener(cell)}${told.map((t) => lineOf(t, cap)).join("\n")}\nNothing else of the script was run again. Check the actual state before relying on it.`);
|
|
265
|
+
}
|
|
266
|
+
/** The words a resumed `wait`'s output opens with (waitResumed): the model is told its cell's script went with the session. */
|
|
267
|
+
const waitCutOpener = (cell) => `The session stopped while waiting on cell ${cell}; that cell's script was cut off. Its calls that waited for a person's approval were answered since, each once:\n`;
|
|
268
|
+
/** The words a cut-off `exec`'s output opens with when it lists its own calls (execRecovery). */
|
|
269
|
+
const EXEC_CUT_OPENER = "The exec was cut short after these calls (the session stopped), and nothing was run again. Their outcomes, in order:\n";
|
|
270
|
+
/** 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
|
|
271
|
+
* those words belong to an exec that failed (recoveredFailed). One that ended ok shows its calls' outcomes alone. */
|
|
272
|
+
export function recoveredRowText(output, failed) {
|
|
273
|
+
if (failed)
|
|
274
|
+
return output;
|
|
275
|
+
const cell = /^The session stopped while waiting on cell (\S+);/.exec(output)?.[1];
|
|
276
|
+
const opener = cell === undefined ? EXEC_CUT_OPENER : waitCutOpener(cell);
|
|
277
|
+
return output.startsWith(opener) ? output.slice(opener.length) : output;
|
|
278
|
+
}
|
|
279
|
+
/** Whether a cut-off `exec` answered with its recovered output (execRecovery) failed, by the rule a codemode script stopped
|
|
280
|
+
* and run again follows on every other harness (serve's runner/meta-tools.ts endedWith): it failed when its last call did
|
|
281
|
+
* not run (a person refused it, or a park was never answered), was cut off before it reported, or failed; or when it made
|
|
282
|
+
* no call of its own. A script whose last call ran and answered (one that parked and was allowed, too) was stopped and
|
|
283
|
+
* resumed, not failed. `own`: its calls, in order. */
|
|
284
|
+
export function recoveredFailed(own) {
|
|
285
|
+
const last = own.at(-1);
|
|
286
|
+
if (!last)
|
|
287
|
+
return true;
|
|
288
|
+
if (last.resumed)
|
|
289
|
+
return !last.resumed.ran || last.resumed.isError;
|
|
290
|
+
return settle(last).kind !== "completed";
|
|
151
291
|
}
|
|
152
292
|
export function execRecoveryOutput(facts, loose = []) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
return
|
|
293
|
+
return execRecovery(facts, loose).output;
|
|
294
|
+
}
|
|
295
|
+
/** execRecoveryOutput, and the calls whose outcome it tells: only those the recovery note may say are above. */
|
|
296
|
+
export function execRecovery(facts, loose = []) {
|
|
297
|
+
if (facts.length === 0 && loose.length === 0)
|
|
298
|
+
return { output: `The exec was cut short before any tool call of it was recorded; it ran none. Run it again if it is still needed.`, shown: [] };
|
|
299
|
+
const own = facts.map((fact, i) => describeCall(fact, `${i + 1}. ${fact.tool}`));
|
|
300
|
+
const others = loose.map((fact, i) => describeCall(fact, `${i + 1}. ${fact.tool}`));
|
|
301
|
+
return fitted([...own, ...others], (cap) => {
|
|
302
|
+
const apart = others.length
|
|
303
|
+
? `\n${others.length} ${others.length === 1 ? "call" : "calls"} ran whose script could not be told (an answer of the model's could not be read to its end):\n${others.map((t) => lineOf(t, cap)).join("\n")}`
|
|
304
|
+
: "";
|
|
305
|
+
if (own.length === 0)
|
|
306
|
+
return `The exec was cut short, and no call of its own was recorded; the calls below ran, though which script made them could not be told, so do not run it again to find out.${apart}`;
|
|
307
|
+
return `${EXEC_CUT_OPENER}${own.map((t) => lineOf(t, cap)).join("\n")}${apart}`;
|
|
308
|
+
});
|
|
162
309
|
}
|
|
163
310
|
/** The text of a tool's recorded output (a string, or `{ text }` with images). */
|
|
164
311
|
export function outputTextOf(output) {
|
package/dist/versions.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ import { CODEX_VERSION } from "./binary.js";
|
|
|
4
4
|
export { CODEX_VERSION };
|
|
5
5
|
/** The install line for the pinned release (npm installs this platform's binary package with it). */
|
|
6
6
|
export declare const CODEX_INSTALL = "npm install --save-exact @openai/codex@0.164.0";
|
|
7
|
+
/** The input tokens the pinned Codex (0.164.0) sends in its first model request before the agent's own prompt: its own
|
|
8
|
+
* instructions and tool definitions. Measured from billing, not counted: a Codex run on gpt-6.1-sol wrote 12,198 tokens
|
|
9
|
+
* to the provider's cache on its first request, so about 12,200. The facts' `baseInputTokens`: a save under a cap
|
|
10
|
+
* prices a least step on it. Re-measure on a Codex bump. */
|
|
11
|
+
export declare const CODEX_BASE_INPUT_TOKENS = 12200;
|
|
7
12
|
/**
|
|
8
13
|
* npm's integrity of the pinned launcher and of each platform package (an npm alias of
|
|
9
14
|
* `@openai/codex@<version>-<platform>`), as the registry publishes them. npm checks a download against the lockfile's
|