@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/CHANGELOG.md +26 -9
  2. package/README.md +104 -22
  3. package/dist/agent-delete.d.ts +3 -2
  4. package/dist/agent-delete.js +29 -4
  5. package/dist/api-only.d.ts +7 -10
  6. package/dist/api-only.js +9 -11
  7. package/dist/compute-cost.d.ts +101 -0
  8. package/dist/compute-cost.js +250 -0
  9. package/dist/console/assets/{index-CR2ZGei1.css → index-D0mr9wfZ.css} +1 -1
  10. package/dist/console/assets/index-D7G6o-1E.js +720 -0
  11. package/dist/console/index.html +2 -2
  12. package/dist/eval-previous.d.ts +52 -0
  13. package/dist/eval-previous.js +164 -0
  14. package/dist/file-types.d.ts +2 -0
  15. package/dist/file-types.js +3 -1
  16. package/dist/harness.js +2 -1
  17. package/dist/learn/check.d.ts +8 -5
  18. package/dist/learn/check.js +25 -24
  19. package/dist/learn/repick.d.ts +22 -13
  20. package/dist/learn/repick.js +57 -56
  21. package/dist/learn/workflow-draft.d.ts +4 -0
  22. package/dist/learn/workflow-draft.js +10 -7
  23. package/dist/learned-workflow.js +8 -8
  24. package/dist/learning-setting.js +2 -2
  25. package/dist/openapi.js +25 -17
  26. package/dist/paid-calls.d.ts +13 -6
  27. package/dist/paid-calls.js +14 -8
  28. package/dist/run-launch.d.ts +2 -2
  29. package/dist/run-launch.js +2 -1
  30. package/dist/run-timeline-served.js +5 -3
  31. package/dist/run-usage.d.ts +23 -8
  32. package/dist/run-usage.js +100 -18
  33. package/dist/runner/adapter-loop.d.ts +4 -0
  34. package/dist/runner/adapter-loop.js +15 -1
  35. package/dist/runner/adapter-run-spec.d.ts +8 -3
  36. package/dist/runner/adapter-run-spec.js +13 -6
  37. package/dist/runner/big-writes.d.ts +33 -0
  38. package/dist/runner/big-writes.js +105 -0
  39. package/dist/runner/cli-run-spec.js +14 -6
  40. package/dist/runner/held.d.ts +4 -1
  41. package/dist/runner/learning-end.js +9 -4
  42. package/dist/runner/metrics.d.ts +4 -0
  43. package/dist/runner/metrics.js +9 -0
  44. package/dist/runner/run-child-host.d.ts +15 -2
  45. package/dist/runner/run-child-host.js +24 -8
  46. package/dist/runner/run-child.js +3 -0
  47. package/dist/runner/save-slots.d.ts +9 -0
  48. package/dist/runner/save-slots.js +91 -0
  49. package/dist/sdk/runs.d.ts +3 -4
  50. package/dist/sdk/runs.js +10 -7
  51. package/dist/sdk/runtimes.d.ts +19 -0
  52. package/dist/sdk/runtimes.js +23 -0
  53. package/dist/sdk/schema.d.ts +14 -8
  54. package/dist/sdk/schema.js +18 -6
  55. package/dist/server.d.ts +4 -0
  56. package/dist/server.js +3 -3
  57. package/dist/store/agent-body.d.ts +2 -3
  58. package/dist/store/agent-body.js +3 -2
  59. package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
  60. package/dist/store/schema.d.ts +8 -3
  61. package/dist/store/schema.js +12 -2
  62. package/dist/store/sqlite/connection.d.ts +3 -3
  63. package/dist/store/sqlite/connection.js +3 -3
  64. package/dist/store/sqlite/store.d.ts +2 -4
  65. package/dist/store/sqlite/store.js +95 -85
  66. package/dist/store/store.d.ts +8 -1
  67. package/dist/store-reads/cap.d.ts +9 -5
  68. package/dist/store-reads/cap.js +28 -2
  69. package/dist/store-reads/decisions.d.ts +21 -0
  70. package/dist/store-reads/decisions.js +22 -0
  71. package/dist/store-reads/journal.d.ts +8 -2
  72. package/dist/store-reads/journal.js +27 -8
  73. package/dist/store-view.d.ts +5 -1
  74. package/dist/store-view.js +37 -18
  75. package/dist/template-eval.d.ts +15 -1
  76. package/dist/template-eval.js +92 -13
  77. package/dist/templates.d.ts +1 -1
  78. package/dist/templates.js +4 -3
  79. package/dist/timeline/labels.js +17 -0
  80. package/dist/tool-list.js +1 -0
  81. package/dist/tools.d.ts +6 -2
  82. package/dist/tools.js +13 -1
  83. package/dist/trigger-targets.d.ts +21 -5
  84. package/dist/trigger-targets.js +13 -10
  85. package/dist/web-fake.d.ts +25 -0
  86. package/dist/web-fake.js +38 -1
  87. package/dist/web-save.d.ts +75 -0
  88. package/dist/web-save.js +235 -0
  89. package/dist/workspace/archil-claim.d.ts +5 -2
  90. package/dist/workspace/archil-claim.js +5 -2
  91. package/dist/workspace/archil-disk.d.ts +10 -1
  92. package/dist/workspace/archil-disk.js +19 -1
  93. package/dist/workspace/archil.d.ts +3 -0
  94. package/dist/workspace/archil.js +101 -16
  95. package/dist/workspace/computer-for-claim.d.ts +14 -0
  96. package/dist/workspace/computer-for-claim.js +46 -7
  97. package/dist/workspace/computer-intervals.d.ts +9 -3
  98. package/dist/workspace/computer-intervals.js +17 -8
  99. package/dist/workspace/pieced.d.ts +14 -0
  100. package/dist/workspace/pieced.js +23 -0
  101. package/dist/workspace/run-disk.js +32 -12
  102. package/dist/workspace/run-workspace.d.ts +1 -1
  103. package/dist/workspace/run-workspace.js +11 -6
  104. package/package.json +10 -10
  105. package/templates/README.md +36 -7
  106. package/dist/console/assets/index-Bzn4eUYF.js +0 -715
@@ -6,8 +6,8 @@
6
6
  <meta name="color-scheme" content="light dark" />
7
7
  <title>AgentRun</title>
8
8
  <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23ff8000'/%3E%3Cpath d='M12 9l11 7-11 7z' fill='%23000'/%3E%3C/svg%3E" />
9
- <script type="module" crossorigin src="./assets/index-Bzn4eUYF.js"></script>
10
- <link rel="stylesheet" crossorigin href="./assets/index-CR2ZGei1.css">
9
+ <script type="module" crossorigin src="./assets/index-D7G6o-1E.js"></script>
10
+ <link rel="stylesheet" crossorigin href="./assets/index-D0mr9wfZ.css">
11
11
  </head>
12
12
  <body>
13
13
  <div id="root"></div>
@@ -0,0 +1,52 @@
1
+ import type { Store } from "./store/index.js";
2
+ import { type CompletedOutput, type PreviousHandover } from "./trigger-targets.js";
3
+ import { type Json } from "./validate.js";
4
+ /** One earlier completed run of the trigger: its result.output, and the output schema it was checked against when that
5
+ * is not the package's (`outputSchema`, the fixture's output_schema). */
6
+ export type PreviousResult = {
7
+ output: Json;
8
+ outputSchema?: Json;
9
+ };
10
+ /** A previous case's fixture: the trigger's earlier completed results, oldest first (the last is the one its next run is
11
+ * handed), and the package's schedule trigger that starts the run (filled in by the caller when the fixture names none). */
12
+ export type PreviousFixture = {
13
+ description?: string;
14
+ results: PreviousResult[];
15
+ trigger: string;
16
+ };
17
+ /** `value` read as a previous fixture, each problem through `bad` in words naming `at`; undefined when one does not read.
18
+ * Each output is checked against its own output_schema, else `packageSchema` (the package's output schema), as the
19
+ * server checks a run's answer: a result whose run would have no result.output is refused here, before any run. */
20
+ export declare function previousFixtureOf(value: unknown, at: string, packageSchema: unknown, bad: (message: string) => void): (Omit<PreviousFixture, "trigger"> & {
21
+ trigger?: string;
22
+ }) | undefined;
23
+ /** A result seeded: its run's id, and the fields the output schema of its run's revision names in x-carried (the ones the
24
+ * server reads back for it, TriggerTargetDeps.completedOutput), absent when it names none. */
25
+ export type Seeded = {
26
+ runId: string;
27
+ carried?: readonly string[];
28
+ };
29
+ /** `fixture`'s results seeded in `store` as completed runs of `agentId`, oldest first, each a firing of `triggerId` that
30
+ * started it, ended a day apart before `before` (the clock the case's run fires on): each run's input is `content` (the
31
+ * trigger's), its answer its output as one fenced json block. A result with its own output schema is a run of a revision
32
+ * of its own, the agent's current body with that schema, made and then left behind, so the agent's current revision is
33
+ * the one the case's run starts on. */
34
+ export declare function seedPrevious(store: Store, fixture: PreviousFixture, { agentId, triggerId, content, before }: {
35
+ agentId: string;
36
+ triggerId: string;
37
+ content: string;
38
+ before: number;
39
+ }): Promise<Seeded[]>;
40
+ /** The kinds a `handed` grader expects, PreviousHandover's. */
41
+ export declare const HANDED_KINDS: readonly ["whole", "carried", "too_large", "none"];
42
+ /** What the run whose input content is `content` was handed of its trigger's last result, the last one seeded (`last`),
43
+ * `done` as the server reads it back (its result.output and end as GET /runs/{id} serves them): the handover the trigger
44
+ * makes of it (previousHandover), when the run's input ends with that handover's words; else none. */
45
+ export declare function handedPrevious(content: string, last: Seeded, done: Omit<CompletedOutput, "carried">): PreviousHandover;
46
+ /** A `handed` grader's verdict: the run was handed its previous result as `expect` says (and, for carried fields, each
47
+ * array in `dropped` gave up exactly that many first entries, 0 for none). A field the grader counts that is no carried
48
+ * array the run was handed (a misspelled name, a scalar) fails it by name: never read as 0 dropped. */
49
+ export declare function handedVerdict(handed: PreviousHandover | undefined, expect: PreviousHandover["kind"], dropped?: Readonly<Record<string, number>>): {
50
+ pass: boolean;
51
+ reason: string;
52
+ };
@@ -0,0 +1,164 @@
1
+ // A template eval case's previous runs (template-eval.ts `previous:`): its fixture, checked when the case is read, and its
2
+ // results seeded in the eval's own server's store as completed runs of the run's agent, each a firing of the package's
3
+ // schedule trigger, before that trigger fires the case's run. So the run is handed what previousResultOf hands a
4
+ // scheduled run (trigger-targets.ts) from the server's own reads: the last result's result.output whole up to
5
+ // PREVIOUS_RESULT_MAX_BYTES, else the fields its run's output schema names in x-carried, trimmed to fit, else nothing,
6
+ // said so. Each result is written as the store writes an ended run it did not run (Store.importRun, its transcript as
7
+ // import.ts transcriptOf lays one out): its answer the output as one fenced json block, on the agent's current revision,
8
+ // or on a revision of its own whose output schema is the result's `output_schema` (the trim reads the producing run's
9
+ // schema), the agent's current one left as it was. What the run was handed is the server's own handover of the last result
10
+ // (trigger-targets.ts previousHandover), when its input carries that handover's words (handedPrevious), for its graders
11
+ // and its report.
12
+ import { carriedFields, carriedProblem, schemaCheck } from "./answer-json.js";
13
+ import { transcriptOf } from "./import.js";
14
+ import { launchBody } from "./run-launch.js";
15
+ import { uuidv7 } from "./runs-over-store.js";
16
+ import { previousHandover } from "./trigger-targets.js";
17
+ import { isObject } from "./validate.js";
18
+ const FIXTURE_FIELDS = ["description", "results", "trigger"];
19
+ const RESULT_FIELDS = ["output", "output_schema"];
20
+ /** `value` read as a previous fixture, each problem through `bad` in words naming `at`; undefined when one does not read.
21
+ * Each output is checked against its own output_schema, else `packageSchema` (the package's output schema), as the
22
+ * server checks a run's answer: a result whose run would have no result.output is refused here, before any run. */
23
+ export function previousFixtureOf(value, at, packageSchema, bad) {
24
+ if (!isObject(value))
25
+ return bad(`${at}: a previous fixture is {description?, results: [{output, output_schema?}, ...], trigger?}`), undefined;
26
+ let ok = true;
27
+ const no = (message) => ((ok = false), bad(`${at}: ${message}`));
28
+ for (const key of Object.keys(value).filter((key) => !FIXTURE_FIELDS.includes(key)))
29
+ no(`no field ${key}: its fields are ${FIXTURE_FIELDS.join(", ")}`);
30
+ if (value.description !== undefined && typeof value.description !== "string")
31
+ no("description is text");
32
+ if (value.trigger !== undefined && (typeof value.trigger !== "string" || !value.trigger))
33
+ no("trigger is the name of the package's schedule trigger that starts the run");
34
+ const results = [];
35
+ if (!Array.isArray(value.results) || !value.results.length)
36
+ no("results is the trigger's earlier completed runs, oldest first, at least one: each {output, output_schema?}");
37
+ else {
38
+ for (const [i, result] of value.results.entries()) {
39
+ const where = `results[${i}]`;
40
+ if (!isObject(result)) {
41
+ no(`${where} is {output, output_schema?}`);
42
+ continue;
43
+ }
44
+ for (const key of Object.keys(result).filter((key) => !RESULT_FIELDS.includes(key)))
45
+ no(`${where} has no field ${key}: its fields are ${RESULT_FIELDS.join(", ")}`);
46
+ if (!isObject(result.output))
47
+ no(`${where}.output is the run's result.output, a JSON object`);
48
+ const own = result.output_schema;
49
+ if (own !== undefined) {
50
+ const compiled = schemaCheck(own);
51
+ if ("why" in compiled) {
52
+ no(`${where}.output_schema ${compiled.why}`);
53
+ continue;
54
+ }
55
+ const carried = carriedProblem(own);
56
+ if (carried) {
57
+ no(`${where}.output_schema's x-carried ${carried}`);
58
+ continue;
59
+ }
60
+ }
61
+ const schema = own ?? packageSchema;
62
+ if (schema === undefined) {
63
+ no(`${where} has no output schema it was checked against: give it output_schema, or the package an output (a run's result.output is its answer as an output schema checks it)`);
64
+ continue;
65
+ }
66
+ const compiled = schemaCheck(schema);
67
+ if (!isObject(result.output) || "why" in compiled)
68
+ continue;
69
+ const problems = compiled.check(result.output);
70
+ if (problems.length)
71
+ no(`${where}.output does not meet ${own === undefined ? "the package's output schema" : "its output_schema"}: ${problems.slice(0, 3).join("; ")}`);
72
+ else
73
+ results.push({ output: result.output, ...(own !== undefined ? { outputSchema: own } : {}) });
74
+ }
75
+ }
76
+ if (!ok)
77
+ return undefined;
78
+ return { ...(typeof value.description === "string" ? { description: value.description } : {}), results, ...(typeof value.trigger === "string" ? { trigger: value.trigger } : {}) };
79
+ }
80
+ /** How far apart the seeded results ended, the last that far before the case's run. */
81
+ const SEEDED_APART_MS = 24 * 60 * 60_000;
82
+ /** `fixture`'s results seeded in `store` as completed runs of `agentId`, oldest first, each a firing of `triggerId` that
83
+ * started it, ended a day apart before `before` (the clock the case's run fires on): each run's input is `content` (the
84
+ * trigger's), its answer its output as one fenced json block. A result with its own output schema is a run of a revision
85
+ * of its own, the agent's current body with that schema, made and then left behind, so the agent's current revision is
86
+ * the one the case's run starts on. */
87
+ export async function seedPrevious(store, fixture, { agentId, triggerId, content, before }) {
88
+ const current = (await store.agents.get(agentId))?.currentRevision;
89
+ const revision = current ? await store.agents.revision(current) : undefined;
90
+ if (!current || !revision)
91
+ throw new Error(`the agent ${agentId} has no current revision to seed its previous runs on`);
92
+ const seeded = [];
93
+ for (const [i, result] of fixture.results.entries()) {
94
+ const endedAt = before - (fixture.results.length - i) * SEEDED_APART_MS;
95
+ const startedAt = endedAt - 60_000;
96
+ let revisionId = current;
97
+ if (result.outputSchema !== undefined) {
98
+ revisionId = uuidv7();
99
+ await store.agents.addRevision({
100
+ id: revisionId, agentId, kind: revision.kind, body: { ...revision.body, outputSchema: result.outputSchema },
101
+ ...(revision.skills !== null ? { skills: revision.skills } : {}), ...(revision.mcpPin !== null ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== null ? { monidPin: revision.monidPin } : {}),
102
+ note: "A template eval's previous run, on its own output schema.", ifCurrent: current,
103
+ });
104
+ await store.agents.setCurrent(agentId, current);
105
+ }
106
+ // Run ids sort by their start: each seeded one is older than the next, and than the case's run.
107
+ const runId = uuidv7(startedAt);
108
+ const key = `template-eval-previous-${i + 1}`;
109
+ const answer = `\`\`\`json\n${JSON.stringify(result.output, null, 2)}\n\`\`\``;
110
+ const session = { turns: [{ role: "user", text: content, at: startedAt }, { role: "assistant", text: answer, calls: [], at: endedAt }] };
111
+ await store.importRun({
112
+ id: runId, agentId, revisionId, importedFrom: { source: "pi", session: key + "-" + runId },
113
+ launch: { body: launchBody({ input: { content }, title: `Previous run ${i + 1} of the case`, place: { mode: "runner" }, trigger: { id: triggerId, firing_key: key } }) },
114
+ state: "ended", costUsd: 0, startedAt, endedAt, transcript: transcriptOf(session, (value) => value).batches,
115
+ });
116
+ // The firing that started it, as the trigger's history keeps one: recorded settled (no engine drives it), then started
117
+ // with its run, which moves the trigger's last run to it.
118
+ await store.triggers.record(triggerId, [{ key, by: "schedule", nominalAt: Math.floor(startedAt / 1000) * 1000, status: "skipped" }]);
119
+ await store.triggers.settle(triggerId, key, { status: "started", runId }, { reset: true });
120
+ const carried = carriedFields(result.outputSchema ?? revision.body.outputSchema);
121
+ seeded.push({ runId, ...(carried ? { carried } : {}) });
122
+ }
123
+ return seeded;
124
+ }
125
+ /** The kinds a `handed` grader expects, PreviousHandover's. */
126
+ export const HANDED_KINDS = ["whole", "carried", "too_large", "none"];
127
+ /** What the run whose input content is `content` was handed of its trigger's last result, the last one seeded (`last`),
128
+ * `done` as the server reads it back (its result.output and end as GET /runs/{id} serves them): the handover the trigger
129
+ * makes of it (previousHandover), when the run's input ends with that handover's words; else none. */
130
+ export function handedPrevious(content, last, done) {
131
+ const handover = previousHandover(last.runId, { ...done, ...(last.carried ? { carried: last.carried } : {}) });
132
+ return handover.text && content.endsWith(handover.text) ? handover : { kind: "none", text: "" };
133
+ }
134
+ /** A `handed` grader's verdict: the run was handed its previous result as `expect` says (and, for carried fields, each
135
+ * array in `dropped` gave up exactly that many first entries, 0 for none). A field the grader counts that is no carried
136
+ * array the run was handed (a misspelled name, a scalar) fails it by name: never read as 0 dropped. */
137
+ export function handedVerdict(handed, expect, dropped) {
138
+ if (!handed)
139
+ return { pass: false, reason: "the run has no previous result seeded to read" };
140
+ const said = handedWords(handed);
141
+ if (handed.kind !== expect)
142
+ return { pass: false, reason: `${said}; the grader expects ${KIND_WORDS[expect]}` };
143
+ const lists = Object.keys(handed.dropped ?? {});
144
+ const unknown = Object.keys(dropped ?? {}).filter((field) => !lists.includes(field));
145
+ if (unknown.length)
146
+ return { pass: false, reason: `${said}; the grader counts ${unknown.join(", ")}, which ${unknown.length === 1 ? "is" : "are"} no carried array it was handed (${lists.length ? lists.join(", ") : "none"})` };
147
+ const wrong = Object.entries(dropped ?? {}).filter(([field, n]) => handed.dropped[field] !== n);
148
+ if (wrong.length)
149
+ return { pass: false, reason: `${said}; the grader expects ${wrong.map(([field, n]) => `${field}: the first ${n} dropped`).join(", ")}` };
150
+ return { pass: true, reason: said };
151
+ }
152
+ const KIND_WORDS = {
153
+ whole: "its trigger's last result whole",
154
+ carried: "its trigger's last result as its carried fields",
155
+ too_large: "nothing of its trigger's last result, too large to hand",
156
+ none: "no previous result",
157
+ };
158
+ /** What a run was handed, in words. */
159
+ function handedWords(handed) {
160
+ if (handed.kind !== "carried")
161
+ return `the run was handed ${KIND_WORDS[handed.kind]}`;
162
+ const dropped = Object.entries(handed.dropped ?? {}).filter(([, n]) => n > 0);
163
+ return `the run was handed ${KIND_WORDS.carried} (${(handed.fields ?? []).join(", ")})${dropped.length ? `, ${dropped.map(([field, n]) => `${field}: the first ${n} ${n === 1 ? "entry" : "entries"} dropped`).join("; ")}` : ", nothing dropped"}`;
164
+ }
@@ -2,3 +2,5 @@
2
2
  export declare const INLINE_TYPES: ReadonlySet<string>;
3
3
  /** The type of a file at `path`, by its extension; undefined for one the table does not know. */
4
4
  export declare const typeOf: (path: string) => string | undefined;
5
+ /** The usual extension of a file of `type` (the first the table lists for it, so jpg for image/jpeg); undefined for one it does not serve. */
6
+ export declare const extensionOf: (type: string) => string | undefined;
@@ -4,9 +4,11 @@ import { extname } from "node:path";
4
4
  const TYPES = new Map(Object.entries({
5
5
  txt: "text/plain; charset=utf-8", md: "text/markdown; charset=utf-8", csv: "text/csv; charset=utf-8", json: "application/json", jsonl: "application/x-ndjson",
6
6
  html: "text/html; charset=utf-8", htm: "text/html; charset=utf-8", png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", pdf: "application/pdf",
7
- mp4: "video/mp4",
7
+ mp4: "video/mp4", webm: "video/webm", mp3: "audio/mpeg", wav: "audio/wav", m4a: "audio/mp4", ogg: "audio/ogg",
8
8
  }));
9
9
  /** The types a file is served as in the page (every known type but PDF); any other is a download. */
10
10
  export const INLINE_TYPES = new Set([...TYPES.values()].filter((type) => type !== "application/pdf"));
11
11
  /** The type of a file at `path`, by its extension; undefined for one the table does not know. */
12
12
  export const typeOf = (path) => TYPES.get(extname(path).slice(1).toLowerCase());
13
+ /** The usual extension of a file of `type` (the first the table lists for it, so jpg for image/jpeg); undefined for one it does not serve. */
14
+ export const extensionOf = (type) => [...TYPES].find(([, served]) => served === type)?.[0];
package/dist/harness.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { SDK_RUNTIMES } from "./sdk/runtimes.js";
1
2
  /** The built-in harnesses' ids, in the table's order (harness-table.ts BUILTIN; harness-one-table.test.mjs holds them
2
3
  * equal): the ids a definition may name on any server, and the type of a built-in one. What a server runs is its table's
3
4
  * (harnessIds), which an owner's harness module may add to. */
@@ -11,7 +12,7 @@ export const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
11
12
  * runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
12
13
  * (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
13
14
  export const RESERVED_HARNESS_IDS = Object.freeze([
14
- "learning", "sdk", "workflow", "claude-agent-sdk", "codex-sdk", "eve",
15
+ "learning", "sdk", "workflow", ...SDK_RUNTIMES,
15
16
  ...Object.getOwnPropertyNames(Object.prototype).filter((name) => new RegExp(HARNESS_ID_PATTERN).test(name)),
16
17
  ]);
17
18
  /** The harnesses that run on a person's ChatGPT plan (chatgpt-plan.ts): those whose requests go to OpenAI's Responses
@@ -1,3 +1,4 @@
1
+ import { type RepickSite } from "./repick.js";
1
2
  import { type DraftDecisions, type DraftDryRun, type DraftReader } from "./workflow-draft.js";
2
3
  /** Byte caps (UTF-8). Over a cap is refused, never cut. */
3
4
  export declare const CAPS: Readonly<{
@@ -79,9 +80,9 @@ export declare function answerTierProblems(doc: unknown): string[];
79
80
  * child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
80
81
  * output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
81
82
  * $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
82
- * One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), a top-level re-pick
83
- * loop of the draft whose body is the host's pass marker is read as its pass 1 (learn/repick.ts repickMarked): the
84
- * clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
83
+ * One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), the answer's re-pick
84
+ * loop (repickSiteOf), when its body is the host's pass marker, is read as its pass 1 (learn/repick.ts repickMarked):
85
+ * the clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
85
86
  * hold, and only that exact clone at that place. */
86
87
  export declare function compactStateProblems(doc: unknown, { repick }?: {
87
88
  readonly repick?: boolean;
@@ -95,8 +96,10 @@ export declare function compactStateProblems(doc: unknown, { repick }?: {
95
96
  * H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
96
97
  * quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
97
98
  export declare function quoteCheckProblems(doc: unknown): string[];
98
- /** The labels a run's loop events give `workflow`'s quote re-pick (quoteRule `repicks`): what marks a loop's exit a
99
- * re-pick (learned-nodes.ts LoopRow `repick`). Any other loop that ran twice is an ordinary loop. */
99
+ /** Where `workflow`'s answer is re-picked (quoteRule `repick`): what learning.repick rewrites (learn/repick.ts). */
100
+ export declare const repickSiteOf: (workflow: unknown) => RepickSite | undefined;
101
+ /** The labels a run's loop events give `workflow`'s quote re-pick (repickSiteOf): what marks a loop's exit a re-pick
102
+ * (learned-nodes.ts LoopRow `repick`). Any other loop that ran twice is an ordinary loop. */
100
103
  export declare function repickLabels(workflow: unknown): Set<string>;
101
104
  /** What must never be stored, in every change's name and text, whatever the checks would refuse it for first: the
102
105
  * name and text scans (nameScanned, textOf) of each change, its text read whole (a file over its cap, one not a regular
@@ -4,9 +4,9 @@
4
4
  // host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
5
5
  import { placeholdersOf, placeholderValue } from "@parcha/agentrun-dsl";
6
6
  import { hiddenCharacter } from "./invisible.js";
7
- import { REPICK_PASSES, repickCheckOf, repickMarked } from "./repick.js";
7
+ import { REPICK_PASSES, repickCheckOf, repickLabelOf, repickMarked } from "./repick.js";
8
8
  import { learnedSecretShapes, redactLearned, valueMatcher } from "./secrets.js";
9
- import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedPlace, readmeProblems, WORKFLOW_NAME, WORKFLOWS_DIR } from "./workflow-draft.js";
9
+ import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, isNode, isObject, learnedPlace, readmeProblems, WORKFLOW_NAME, WORKFLOWS_DIR } from "./workflow-draft.js";
10
10
  /** Byte caps (UTF-8). Over a cap is refused, never cut. */
11
11
  export const CAPS = Object.freeze({
12
12
  /** One draft's workflow.json. */
@@ -88,7 +88,6 @@ function decodedScanned(path, text, refused, add, deep = true) {
88
88
  /** The model node kinds a tier routes (model.ts MODEL_NODES); a decision node (judge, pick, sift) goes to its decision
89
89
  * provider, never a tier. */
90
90
  export const TIERED_KINDS = new Set(["agent", "decide", "extract", "report"]);
91
- const isNode = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.node === "string";
92
91
  /** The state key a step writes (the DSL's writeKeyOf): a report's `report_markdown`, else its `as`, else an agent's,
93
92
  * decide's or extract's label. */
94
93
  const writeKeyOf = (node) => (node.node === "report" ? "report_markdown" : typeof node.as === "string" && node.as ? node.as : ["agent", "decide", "extract"].includes(node.node) ? node.label : undefined);
@@ -183,14 +182,14 @@ function pagesRead(value, state, out = new Set(), depth = 0) {
183
182
  * child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
184
183
  * output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
185
184
  * $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
186
- * One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), a top-level re-pick
187
- * loop of the draft whose body is the host's pass marker is read as its pass 1 (learn/repick.ts repickMarked): the
188
- * clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
185
+ * One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), the answer's re-pick
186
+ * loop (repickSiteOf), when its body is the host's pass marker, is read as its pass 1 (learn/repick.ts repickMarked):
187
+ * the clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
189
188
  * hold, and only that exact clone at that place. */
190
189
  export function compactStateProblems(doc, { repick = false } = {}) {
191
190
  const problems = new Set();
192
- // The draft's own top-level marked loops alone (repickMarked): a marker in a composed child is read as written.
193
- const marked = new Map(repick ? repickMarked(doc).map(({ loop, step }) => [loop, step]) : []);
191
+ // The answer's re-pick loop alone (repickMarked): a marker anywhere else is read as written.
192
+ const marked = repick ? repickMarked(repickSiteOf(doc)) : undefined;
194
193
  const walk = (node, pages, depth) => {
195
194
  const after = new Set(pages);
196
195
  if (!isNode(node) || depth > 32)
@@ -239,7 +238,7 @@ export function compactStateProblems(doc, { repick = false } = {}) {
239
238
  // until the marks stop changing. The set read grows on each further pass, so it stops within one pass a key the
240
239
  // workflow names, and never past maxIters; each pass's way out holds the ones before it.
241
240
  const passes = typeof node.maxIters === "number" && node.maxIters >= 1 ? Math.floor(node.maxIters) : Number.POSITIVE_INFINITY;
242
- const body = marked.get(node) ?? node.body;
241
+ const body = node === marked?.loop ? marked.step : node.body;
243
242
  let read = after;
244
243
  let out = walk(body, read, depth + 1);
245
244
  for (let pass = 2; pass <= passes; pass++) {
@@ -299,7 +298,6 @@ export function compactStateProblems(doc, { repick = false } = {}) {
299
298
  }
300
299
  /** The property names that make an answer carry quotes. */
301
300
  const QUOTE_KEYS = new Set(["quote", "quotes"]);
302
- const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
303
301
  const QUOTE_SITES_MAX = 8;
304
302
  function quoteSite(keys) {
305
303
  const lists = keys.filter((key) => key === "[]").length;
@@ -507,10 +505,13 @@ const repickOn = (step, check) => {
507
505
  const of = repickCheckOf(step);
508
506
  return !!of && of.path === check.path && (of.field ?? "") === check.field && JSON.stringify(of.pages) === JSON.stringify(check.pages);
509
507
  };
510
- /** The labels a run's loop events give `workflow`'s quote re-pick (quoteRule `repicks`): what marks a loop's exit a
511
- * re-pick (learned-nodes.ts LoopRow `repick`). Any other loop that ran twice is an ordinary loop. */
508
+ /** Where `workflow`'s answer is re-picked (quoteRule `repick`): what learning.repick rewrites (learn/repick.ts). */
509
+ export const repickSiteOf = (workflow) => (isObject(workflow) ? quoteRule(workflow, {}).repick : undefined);
510
+ /** The labels a run's loop events give `workflow`'s quote re-pick (repickSiteOf): what marks a loop's exit a re-pick
511
+ * (learned-nodes.ts LoopRow `repick`). Any other loop that ran twice is an ordinary loop. */
512
512
  export function repickLabels(workflow) {
513
- return new Set(isObject(workflow) ? quoteRule(workflow, {}).repicks : []);
513
+ const site = repickSiteOf(workflow);
514
+ return new Set(site ? [repickLabelOf(site)] : []);
514
515
  }
515
516
  /** Whether a step's `state` map names state key `key` as the whole marked placeholder `"{answer?}"` (a whole string):
516
517
  * null on a re-pick loop's first pass, before any draft exists, and the failed draft on its second. No path below the
@@ -558,23 +559,23 @@ const quoteEscalatesIn = (node, depth = 0) => {
558
559
  * (its path and field; a place no one pair reads is refused, as quote_missing reads none of it). Its pages are state keys holding a page as
559
560
  * fetched (holdsPage). A composed workflow node writing the whole answer (its `as` the answer's path) whose child
560
561
  * passes this rule in its own state has checked the places in the answer its child's schema declares too; the parent
561
- * still checks any other place its own schema declares. `checked`: the places a passing workflow checked. `repicks`:
562
- * the answer's re-pick as a run's loop events label it, whether the rule applies or not: the step writing the answer
563
- * when it is a loop of REPICK_PASSES until `not` of a quote_missing, else that step's composed child's, which the DSL
564
- * labels `<step>/<its label>` (scopeDepsToChild). */
562
+ * still checks any other place its own schema declares. `checked`: the places a passing workflow checked. `repick`:
563
+ * where the answer is re-picked, whether the rule applies or not: the step writing the answer when it is a loop of
564
+ * REPICK_PASSES until `not` of a quote_missing, else that step's composed child's, which the DSL labels
565
+ * `<step>/<its label>` (scopeDepsToChild). */
565
566
  function quoteRule(workflow, schemasAround, depth = 0) {
566
567
  const output = isObject(workflow.output) ? workflow.output : {};
567
568
  const answerPath = typeof output.path === "string" ? output.path : "";
568
569
  const schemas = isObject(workflow.schemas) ? workflow.schemas : schemasAround;
569
570
  const schemaId = typeof output.schemaId === "string" ? output.schemaId : "";
570
571
  if (!answerPath || depth > 8)
571
- return { applies: false, problems: [], checked: [], repicks: [] };
572
+ return { applies: false, problems: [], checked: [], repick: undefined };
572
573
  const steps = isNode(workflow.root) && workflow.root.node === "chain" && Array.isArray(workflow.root.steps) ? workflow.root.steps : [workflow.root];
573
574
  const answered = steps.findLastIndex((step) => writesKey(step, answerPath.split(".")[0]));
574
575
  const writer = steps[answered];
575
576
  const child = isNode(writer) && writer.node === "workflow" && isObject(writer.workflow) ? quoteRule(writer.workflow, schemas, depth + 1) : undefined;
576
- const repicks = !isNode(writer) ? [] : repickCheckOf(writer) ? [String(writer.label)] : (child?.repicks ?? []).map((label) => `${String(writer.label)}/${label}`);
577
- const none = { applies: false, problems: [], checked: [], repicks };
577
+ const repick = !isNode(writer) ? undefined : repickCheckOf(writer) ? { at: answered, step: writer } : child?.repick && { at: answered, step: writer, inner: child.repick };
578
+ const none = { applies: false, problems: [], checked: [], repick };
578
579
  if (!Object.hasOwn(schemas, schemaId))
579
580
  return none;
580
581
  // Its refs read as the DSL reads them (resolveSchemaForWorkflow): the schema's own inline definitions first, then the catalog.
@@ -584,12 +585,12 @@ function quoteRule(workflow, schemasAround, depth = 0) {
584
585
  if ((!declared.length && !over) || !fetches(workflow.root))
585
586
  return none;
586
587
  if (over)
587
- return { applies: true, checked: [], repicks, problems: [`the answer's schema (${schemaId.slice(0, 64)}) holds quotes in more than ${QUOTE_SITES_MAX} places or nests past ${QUOTE_SITE_DEPTH} keys, past what the quote check reads, and the workflow fetches pages: give the answer fewer places holding quotes, each a quote, a list of quotes or a list of records holding one`] };
588
+ return { applies: true, checked: [], repick, problems: [`the answer's schema (${schemaId.slice(0, 64)}) holds quotes in more than ${QUOTE_SITES_MAX} places or nests past ${QUOTE_SITE_DEPTH} keys, past what the quote check reads, and the workflow fetches pages: give the answer fewer places holding quotes, each a quote, a list of quotes or a list of records holding one`] };
588
589
  const where = (site) => `${schemaId}.${site.keys.join(".").replace(/\.(\[\]|\*)/g, "$1")}`.slice(0, 120);
589
590
  const pages = pageKeysOf(workflow.root);
590
591
  const covered = child?.applies && !child.problems.length && isNode(writer) && writer.as === answerPath ? child.checked : [];
591
592
  const sites = declared.filter((site) => !covered.includes(siteKey(site)));
592
- const passed = { applies: true, problems: [], checked: declared.map(siteKey), repicks };
593
+ const passed = { applies: true, problems: [], checked: declared.map(siteKey), repick };
593
594
  if (!sites.length)
594
595
  return passed;
595
596
  // A place no one path and field reads (quotes under two lists, in a map, in records with no quote key): quote_missing
@@ -644,8 +645,8 @@ function quoteRule(workflow, schemasAround, depth = 0) {
644
645
  }
645
646
  // A composed workflow writing the answer that applies the rule and fails it: its own check is the one to fix.
646
647
  if (problems.length && child?.problems.length)
647
- return { applies: true, checked: [], repicks, problems: child.problems.map((problem) => `the composed workflow step ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer: ${problem}`) };
648
- return problems.length ? { applies: true, problems, checked: [], repicks } : passed;
648
+ return { applies: true, checked: [], repick, problems: child.problems.map((problem) => `the composed workflow step ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer: ${problem}`) };
649
+ return problems.length ? { applies: true, problems, checked: [], repick } : passed;
649
650
  }
650
651
  /** What a draft may write of a workflow (`place`), by itself: a good folder name, never a deletion, a regular file
651
652
  * within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a draft the DSL validates
@@ -1,5 +1,14 @@
1
1
  /** The passes of a checked answer's re-pick loop: the draft, then one re-pick. */
2
2
  export declare const REPICK_PASSES = 2;
3
+ /** Where a workflow's answer is re-picked, as check.ts quoteRule finds it: `step`, its top-level step `at` writing the
4
+ * answer, is the re-pick loop, or a composed workflow node whose child's answer is re-picked at `inner`. */
5
+ export type RepickSite = {
6
+ readonly at: number;
7
+ readonly step: Record<string, unknown>;
8
+ readonly inner?: RepickSite;
9
+ };
10
+ /** The label a run's loop events give the re-pick loop at `site`. */
11
+ export declare const repickLabelOf: (site: RepickSite) => string;
3
12
  /** The quote_missing a re-pick loop waits on: `step`'s, when it is a loop of REPICK_PASSES until `not` of a quote_missing. */
4
13
  export declare const repickCheckOf: (step: unknown) => Record<string, unknown> | undefined;
5
14
  /** The state key the pass marker writes. */
@@ -9,23 +18,23 @@ export declare const repickNote: (keys: readonly string[]) => string;
9
18
  /** The pass-1 step of `loop`, a re-pick loop whose body is the very marker the rewrite derives from that step at the cap
10
19
  * its clone carries (one the setting allows); else undefined. A compiler's variation of it is none. */
11
20
  export declare function repickPassOne(loop: unknown): Record<string, unknown> | undefined;
12
- /** `doc` with its answer's re-pick loop's body the pass marker, its clone capped at `maxChars`; a loop already marked is
13
- * marked again from its pass 1. Undefined when there is none to mark: no top-level re-pick loop whose pass 1 is one model
14
- * step writing the answer (isPassOne), or the marker's key or a label it adds is one the doc or its input already has.
15
- * Given a draft the checks passed (check.ts checkDraft), whose answer step that loop is (quoteRule). `doc` is unchanged. */
16
- export declare function repickRewrite(doc: unknown, maxChars: number): Record<string, unknown> | undefined;
17
- /** The marked re-pick loops of `doc`: those of its own top-level steps whose body is the marker (repickPassOne), each with
18
- * its pass-1 step, its clone's label and cap. The one place a marker counts: the rewrite puts it nowhere else, so the
19
- * compact state rule (check.ts) reads only these as their pass 1, and the runner (repickPageCaps) cuts only their
20
- * clones. A marker in a composed child, which a revised draft could carry, is a page read like any other. */
21
- export declare function repickMarked(doc: unknown): {
21
+ /** `doc` with its answer's re-pick loop, at `site` (check.ts repickSiteOf of `doc`), its body the pass marker, its clone
22
+ * capped at `maxChars`; a loop already marked is marked again from its pass 1. Undefined when the rewrite does not reach
23
+ * it: its pass 1 is not one model step writing its workflow's answer (isPassOne), or the marker's key or a label it adds
24
+ * is one that workflow or its input already has. Given a draft the checks passed (check.ts checkDraft). `doc` is
25
+ * unchanged. */
26
+ export declare function repickRewrite(doc: unknown, site: RepickSite | undefined, maxChars: number): Record<string, unknown> | undefined;
27
+ /** The marked re-pick loop at `site` (check.ts repickSiteOf), when its body is the marker (repickPassOne): its pass-1
28
+ * step, and its clone's label as a run gives it and its cap. The one place a marker counts, the one the rewrite puts it:
29
+ * the compact state rule (check.ts) reads only this loop as its pass 1, and the runner (learned-workflow.ts runNode)
30
+ * cuts only this clone. A marker anywhere else, which a revised draft could carry, is a page read like any other, as
31
+ * is one in a child its node hands the marker's key (handsMark), which would start on the pass that key names. */
32
+ export declare function repickMarked(site: RepickSite | undefined): {
22
33
  readonly loop: Record<string, unknown>;
23
34
  readonly step: Record<string, unknown>;
24
35
  readonly label: string;
25
36
  readonly cap: number;
26
- }[];
27
- /** Each marked re-pick's pass-2 label in `doc`, with its cap (repickMarked): what learned-workflow.ts runNode cuts. */
28
- export declare const repickPageCaps: (doc: unknown) => Map<string, number>;
37
+ } | undefined;
29
38
  /** A model request's state, `user` (the DSL's JSON of it), within `max` characters: as it is when it fits; else each of
30
39
  * its longest strings cut to one length, the most that fits, each ending " [cut at N of M characters]". Undefined when
31
40
  * even every string cut to nothing does not fit (its keys, or many short strings, alone past `max`): the request is