@parcha/agentrun-serve 0.1.0-beta.42 → 0.1.0-beta.44

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 (181) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/README.md +221 -31
  3. package/dist/cli.js +42 -8
  4. package/dist/composio-preset.d.ts +4 -3
  5. package/dist/composio-preset.js +12 -4
  6. package/dist/composio-triggers.d.ts +20 -2
  7. package/dist/composio-triggers.js +183 -17
  8. package/dist/computer-lost.d.ts +11 -0
  9. package/dist/computer-lost.js +19 -0
  10. package/dist/computer-record.d.ts +10 -2
  11. package/dist/computer-record.js +50 -18
  12. package/dist/computer-setting.d.ts +1 -0
  13. package/dist/computer-setting.js +2 -2
  14. package/dist/console/assets/index-BUktRvS-.css +1 -0
  15. package/dist/console/assets/index-nB9kTfIN.js +711 -0
  16. package/dist/console/index.html +2 -2
  17. package/dist/decisions.js +0 -4
  18. package/dist/errors.d.ts +1 -0
  19. package/dist/errors.js +3 -0
  20. package/dist/harness-table.d.ts +51 -3
  21. package/dist/harness-table.js +101 -13
  22. package/dist/harness.d.ts +18 -1
  23. package/dist/harness.js +21 -9
  24. package/dist/host.d.ts +12 -10
  25. package/dist/host.js +18 -16
  26. package/dist/import-sources.js +25 -5
  27. package/dist/import-worker.d.ts +3 -0
  28. package/dist/import-worker.js +7 -5
  29. package/dist/import.d.ts +22 -1
  30. package/dist/import.js +141 -28
  31. package/dist/learn/audit.d.ts +123 -0
  32. package/dist/learn/audit.js +159 -0
  33. package/dist/learn/check.d.ts +3 -0
  34. package/dist/learn/check.js +1 -1
  35. package/dist/learn/compile.d.ts +50 -74
  36. package/dist/learn/compile.js +90 -124
  37. package/dist/learn/delete.d.ts +17 -0
  38. package/dist/learn/delete.js +44 -0
  39. package/dist/learn/folder.d.ts +9 -0
  40. package/dist/learn/folder.js +13 -2
  41. package/dist/learn/promote.d.ts +92 -200
  42. package/dist/learn/promote.js +65 -187
  43. package/dist/learn/replay-calls.d.ts +5 -0
  44. package/dist/learn/replay-calls.js +12 -1
  45. package/dist/learn/secrets.d.ts +8 -0
  46. package/dist/learn/secrets.js +12 -0
  47. package/dist/learn/skills.d.ts +4 -0
  48. package/dist/learn/skills.js +19 -5
  49. package/dist/learn/workflow-nodes.d.ts +23 -3
  50. package/dist/learn/workflow-nodes.js +30 -12
  51. package/dist/learned-nodes.d.ts +9 -34
  52. package/dist/learned-nodes.js +11 -23
  53. package/dist/learned-workflow.d.ts +6 -8
  54. package/dist/learned-workflow.js +18 -57
  55. package/dist/learning-batch.d.ts +13 -5
  56. package/dist/learning-batch.js +34 -8
  57. package/dist/learning-cost.d.ts +111 -4
  58. package/dist/learning-cost.js +120 -3
  59. package/dist/learning-evals.d.ts +2 -0
  60. package/dist/learning-evals.js +4 -3
  61. package/dist/learning-routes.d.ts +8 -0
  62. package/dist/learning-routes.js +18 -1
  63. package/dist/learning-setting.d.ts +16 -1
  64. package/dist/learning-setting.js +34 -2
  65. package/dist/learning.d.ts +1 -1
  66. package/dist/listen-first.d.ts +30 -0
  67. package/dist/listen-first.js +115 -0
  68. package/dist/llms.txt +2 -1
  69. package/dist/mcp-servers-store.d.ts +12 -12
  70. package/dist/model.d.ts +8 -4
  71. package/dist/model.js +16 -8
  72. package/dist/openapi.js +203 -87
  73. package/dist/owner.d.ts +8 -0
  74. package/dist/owner.js +11 -0
  75. package/dist/paid-calls.d.ts +6 -0
  76. package/dist/paid-calls.js +11 -1
  77. package/dist/place.d.ts +8 -3
  78. package/dist/place.js +13 -9
  79. package/dist/provider.js +15 -1
  80. package/dist/run-launch.d.ts +6 -3
  81. package/dist/run-launch.js +2 -0
  82. package/dist/run-learning-served.d.ts +1 -1
  83. package/dist/run-model-key.d.ts +64 -0
  84. package/dist/run-model-key.js +147 -0
  85. package/dist/runner/adapter-loop.d.ts +10 -0
  86. package/dist/runner/adapter-loop.js +26 -4
  87. package/dist/runner/adapter-run-spec.d.ts +6 -3
  88. package/dist/runner/adapter-run-spec.js +83 -25
  89. package/dist/runner/adapters/index.d.ts +4 -2
  90. package/dist/runner/adapters/index.js +13 -4
  91. package/dist/runner/audit.d.ts +68 -0
  92. package/dist/runner/audit.js +349 -0
  93. package/dist/runner/beside.d.ts +2 -1
  94. package/dist/runner/beside.js +6 -3
  95. package/dist/runner/claim-secrets.d.ts +49 -0
  96. package/dist/runner/claim-secrets.js +110 -1
  97. package/dist/runner/cli-run-spec.d.ts +2 -1
  98. package/dist/runner/cli-run-spec.js +44 -15
  99. package/dist/runner/commands.d.ts +3 -6
  100. package/dist/runner/feedback-round.d.ts +3 -2
  101. package/dist/runner/feedback-round.js +8 -7
  102. package/dist/runner/harness-loops.js +31 -23
  103. package/dist/runner/journal-kinds.d.ts +5 -7
  104. package/dist/runner/journal-kinds.js +0 -7
  105. package/dist/runner/learning-dispatch.d.ts +0 -16
  106. package/dist/runner/learning-dispatch.js +4 -47
  107. package/dist/runner/learning-end.d.ts +55 -13
  108. package/dist/runner/learning-end.js +128 -44
  109. package/dist/runner/learning-factory.d.ts +1 -1
  110. package/dist/runner/learning-factory.js +1 -4
  111. package/dist/runner/learning-loop.d.ts +2 -38
  112. package/dist/runner/learning-loop.js +8 -116
  113. package/dist/runner/loop-contract.d.ts +6 -0
  114. package/dist/runner/loop-contract.js +4 -0
  115. package/dist/runner/loop.js +6 -2
  116. package/dist/runner/main.d.ts +1 -0
  117. package/dist/runner/main.js +25 -8
  118. package/dist/runner/memory-claim.d.ts +9 -6
  119. package/dist/runner/memory-claim.js +12 -9
  120. package/dist/runner/promotion.d.ts +55 -54
  121. package/dist/runner/promotion.js +232 -585
  122. package/dist/runner/reflect-hook.d.ts +14 -0
  123. package/dist/runner/reflect-hook.js +28 -3
  124. package/dist/runner/runner.js +57 -4
  125. package/dist/runner/store-secrets.js +9 -5
  126. package/dist/runner/workflow-first.d.ts +6 -5
  127. package/dist/runner/workflow-first.js +17 -12
  128. package/dist/runner/workflow-spec.js +10 -2
  129. package/dist/runs-over-store.d.ts +5 -4
  130. package/dist/runs-over-store.js +13 -3
  131. package/dist/sdk/workflows.d.ts +1 -1
  132. package/dist/server.d.ts +64 -50
  133. package/dist/server.js +516 -134
  134. package/dist/store/index.d.ts +2 -2
  135. package/dist/store/index.js +1 -1
  136. package/dist/store/seal.d.ts +20 -2
  137. package/dist/store/seal.js +24 -8
  138. package/dist/store/sqlite/run-launch.d.ts +4 -1
  139. package/dist/store/sqlite/run-launch.js +12 -0
  140. package/dist/store/sqlite/store.d.ts +3 -2
  141. package/dist/store/sqlite/store.js +119 -16
  142. package/dist/store/store.d.ts +41 -3
  143. package/dist/store-reads/analytics.js +11 -1
  144. package/dist/store-reads/learning.d.ts +57 -7
  145. package/dist/store-reads/learning.js +194 -28
  146. package/dist/store-reads/loop.d.ts +4 -39
  147. package/dist/store-reads/loop.js +10 -79
  148. package/dist/store-reads/stats.js +13 -3
  149. package/dist/store-view.d.ts +5 -1
  150. package/dist/store-view.js +12 -1
  151. package/dist/telemetry.d.ts +59 -0
  152. package/dist/telemetry.js +153 -0
  153. package/dist/tool-keys-store.d.ts +1 -1
  154. package/dist/tool-keys.d.ts +2 -2
  155. package/dist/tool-plane.d.ts +12 -12
  156. package/dist/tools.d.ts +11 -11
  157. package/dist/tools.js +18 -5
  158. package/dist/trigger-adapter.d.ts +3 -0
  159. package/dist/trigger-adapters.d.ts +4 -0
  160. package/dist/trigger-adapters.js +13 -0
  161. package/dist/trigger-composio.d.ts +58 -1
  162. package/dist/trigger-composio.js +160 -6
  163. package/dist/triggers.d.ts +4 -0
  164. package/dist/triggers.js +22 -3
  165. package/dist/validate.d.ts +11 -7
  166. package/dist/validate.js +8 -7
  167. package/dist/workspace/computer-for-claim.d.ts +15 -5
  168. package/dist/workspace/computer-for-claim.js +228 -32
  169. package/dist/workspace/resolve-computer.d.ts +8 -2
  170. package/dist/workspace/resolve-computer.js +1 -1
  171. package/dist/workspace/run-tools.d.ts +1 -1
  172. package/dist/workspace/run-tools.js +14 -3
  173. package/package.json +10 -9
  174. package/dist/console/assets/index-C3gNPz58.css +0 -1
  175. package/dist/console/assets/index-DYJ_wj27.js +0 -711
  176. package/dist/learn/general.d.ts +0 -69
  177. package/dist/learn/general.js +0 -75
  178. package/dist/learn/refit.d.ts +0 -48
  179. package/dist/learn/refit.js +0 -264
  180. package/dist/runner/step-guard.d.ts +0 -62
  181. package/dist/runner/step-guard.js +0 -93
@@ -0,0 +1,159 @@
1
+ // The audit ledger: audits.jsonl at the top of an agent's git learning folder, one JSON line each, appended by the host
2
+ // alone (runner/audit.ts, and the server for an owner's grade). A `started` line is a shadow audit begun (written before
3
+ // its shadow run is created); a row is one finished audit of a run a promoted learned workflow served first: its shadow
4
+ // run's answer (the same agent on the same input, learning off) against the served one (source `shadow`, the started
5
+ // line's result), or an owner's grade of the served run (source `grade`, agreed = the grade). The open audits are the
6
+ // started lines with no result row: settlement reads their two runs by id, so none is ever lost to a window of runs.
7
+ // Each line keeps the promotion it counts for (`promoted_at`), and the hold rule reads the newest rows of the serving
8
+ // revision's current promotion (holdOf). The engine never reads a row's domain: only whether two answers say the same
9
+ // (learn/promote.ts sameAnswer) and what each run cost.
10
+ import { createHash } from "node:crypto";
11
+ import { COMPUTER_TOOLS } from "@parcha/agentrun-kernel/kernel";
12
+ import { pinAnnotations, toolClassOf, toolWord } from "./replay-calls.js";
13
+ import { AUDITS_FILE, readLearning } from "./folder.js";
14
+ import { promotionStartOf, servingOf } from "./promote.js";
15
+ export { AUDITS_FILE };
16
+ /** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX), and a file well under the
17
+ * folder's file cap (a line is a few hundred bytes); with them, the started lines of theirs, and every open one. */
18
+ export const AUDITS_KEPT = 2_000;
19
+ /** What every shadow run's id starts with: its served run's id follows (shadowRunId). No server-minted id starts so. */
20
+ export const SHADOW_PREFIX = "audit.";
21
+ /** The rows of `lines` (the finished audits), oldest first. */
22
+ export const rowsOf = (lines) => lines.filter((line) => line.source !== "started");
23
+ /** The started lines of `lines` with no result row yet: the audits settlement still owes, oldest first. */
24
+ export function openAudits(lines) {
25
+ const done = new Set(lines.filter((line) => line.source === "shadow").map((line) => line.run));
26
+ return lines.filter((line) => line.source === "started" && !done.has(line.run));
27
+ }
28
+ const sha256 = (text) => createHash("sha256").update(text).digest("hex");
29
+ /** Whether served run `runId` is audited at 1 in `k`: the first 8 hex digits of sha256("audit:" + its id), read as a
30
+ * number, are a multiple of k. A function of the id and k alone, so a claim taken again draws the same. */
31
+ export const auditDrawn = (runId, k) => Number.parseInt(sha256(`audit:${runId}`).slice(0, 8), 16) % Math.max(1, k) === 0;
32
+ /** The k a served run is drawn at: `audit_every`, or `audit_every_later` once its revision served `audit_later_after`. */
33
+ export const auditEveryOf = (loop, served) => (served >= loop.audit_later_after ? loop.audit_every_later : loop.audit_every);
34
+ /** The shadow run's id for served run `runId`: one per served run, ever (a second create is the store's constraint). */
35
+ export const shadowRunId = (runId) => {
36
+ const id = `${SHADOW_PREFIX}${runId}`;
37
+ return id.length <= 128 ? id : `${SHADOW_PREFIX}${sha256(runId).slice(0, 40)}`;
38
+ };
39
+ /** Whether `runId` is a shadow run's. */
40
+ export const isShadowRun = (runId) => runId.startsWith(SHADOW_PREFIX);
41
+ /** The tools an agent's computer brings beside its grants (a browser's one tool, a desktop's or a phone's kernel tools). */
42
+ const broughtBy = (computer) => {
43
+ const kind = computer?.kind;
44
+ return kind === "browser" ? ["browser"] : kind === "desktop" || kind === "phone" ? COMPUTER_TOOLS : [];
45
+ };
46
+ /** The first tool agent revision `revision` can call (its grants, and what its computer brings) that is not read-only by
47
+ * the rule a check's replay skips a write by (learn/replay-calls.ts toolClassOf: an MCP tool by its pinned annotations,
48
+ * readOnlyHint, a built-in by READ_TOOLS); undefined when every one only reads. An agent that can call one is never
49
+ * audited: its shadow, a second run of the agent on the same input, could do that write again. */
50
+ export function auditWriterOf(revision) {
51
+ const body = revision?.body;
52
+ const granted = Array.isArray(body?.tools) ? body.tools.filter((tool) => typeof tool === "string") : [];
53
+ const annotations = pinAnnotations(revision?.mcpPin);
54
+ return [...granted, ...broughtBy(body?.computer)].find((tool) => toolClassOf(tool, annotations) !== "read");
55
+ }
56
+ /** What the promotions read says of an agent never audited (auditWriterOf names `tool`). */
57
+ export const auditsOffWords = (tool) => `audits off: ${toolWord(tool)} can write`;
58
+ /** Whether a served run's launch can be audited: started over the API (no trigger, no origin of its first message) with no
59
+ * uploaded files. A triggered run's context (a GitHub event's checkout, the thread it answers on) is never rebuilt for a
60
+ * shadow, which could answer there too: its served run is not auditable (its record's metrics.not_auditable). */
61
+ export const auditableLaunch = (launch) => !launch.trigger && !launch.inputOrigin && !launch.files?.length;
62
+ const isLine = (value) => {
63
+ if (value === null || typeof value !== "object")
64
+ return false;
65
+ const line = value;
66
+ const cost = (one) => one === null || (typeof one === "number" && Number.isFinite(one));
67
+ const common = typeof line.run === "string" && typeof line.workflow === "string" && typeof line.digest === "string" && (line.promoted_at === null || typeof line.promoted_at === "string")
68
+ && (line.turn === undefined || typeof line.turn === "string") && typeof line.at === "string";
69
+ if (line.source === "started")
70
+ return common && typeof line.shadow_run === "string";
71
+ return common && (line.shadow_run === null || typeof line.shadow_run === "string") && (line.source === "shadow" || line.source === "grade")
72
+ && (line.agreed === null || typeof line.agreed === "boolean") && cost(line.served_cost) && cost(line.shadow_cost);
73
+ };
74
+ /** Why a row has no verdict, as written (AuditRow.skipped, AuditRow.parked): never one of a row with one. */
75
+ const noVerdictOf = (line) => line.agreed !== null ? {} : line.skipped === "no allowance" ? { skipped: "no allowance" } : line.parked === true ? { parked: true } : {};
76
+ /** A line's turn (AuditRow.turn), as written: none when it has none. */
77
+ const turnOf = (line) => (line.turn === undefined ? {} : { turn: line.turn });
78
+ /** The lines of a ledger's text, in the order written; one out of shape is skipped. */
79
+ export function parseLedger(text) {
80
+ const out = [];
81
+ for (const raw of text.split("\n")) {
82
+ if (!raw.trim())
83
+ continue;
84
+ try {
85
+ const value = JSON.parse(raw);
86
+ if (!isLine(value))
87
+ continue;
88
+ const { run, workflow, digest, promoted_at, at } = value;
89
+ out.push(value.source === "started"
90
+ ? { source: "started", run, shadow_run: value.shadow_run, workflow, digest, promoted_at, ...turnOf(value), at }
91
+ : { run, shadow_run: value.shadow_run, workflow, digest, promoted_at, source: value.source, agreed: value.agreed, served_cost: value.served_cost, shadow_cost: value.shadow_cost, ...turnOf(value), ...noVerdictOf(value), at });
92
+ }
93
+ catch {
94
+ // A torn line is no line.
95
+ }
96
+ }
97
+ return out;
98
+ }
99
+ /** The ledger's text for `lines`: from the AUDITS_KEPT-th newest row on, and every open started line before it. */
100
+ export function auditsText(lines) {
101
+ const rows = lines.flatMap((line, i) => (line.source === "started" ? [] : [i]));
102
+ const from = rows.length > AUDITS_KEPT ? rows[rows.length - AUDITS_KEPT] : 0;
103
+ const open = new Set(openAudits(lines));
104
+ return lines.filter((line, i) => i >= from || open.has(line)).map((line) => JSON.stringify(line)).join("\n") + "\n";
105
+ }
106
+ /** The ledger's lines on the folder's main as `folder` reads it (none before the first). */
107
+ export async function ledgerOf(folder) {
108
+ const at = folder.snapshot?.audits;
109
+ return at ? parseLedger(await folder.body(AUDITS_FILE, at.oid)) : [];
110
+ }
111
+ /** The ledger's rows on the folder's main: its finished audits, oldest first. */
112
+ export const readAudits = async (ws) => rowsOf(await readLearning(ws, ledgerOf));
113
+ /** A line's place in the ledger: one per served run and source (a started line's, its shadow's row, a grade's row). */
114
+ export const lineKey = (line) => `${line.source}:${line.run}`;
115
+ /** The change that appends `lines` to the ledger `before` (none when each is there already: lineKey), with the lines it
116
+ * appends. */
117
+ export function auditChange(before, lines) {
118
+ const known = new Set(before.map(lineKey));
119
+ const added = [];
120
+ for (const line of lines) {
121
+ if (known.has(lineKey(line)))
122
+ continue;
123
+ known.add(lineKey(line));
124
+ added.push(line);
125
+ }
126
+ const rows = rowsOf(added).length;
127
+ const said = rows ? `${rows} audit row${rows === 1 ? "" : "s"}` : `${added.length} audit${added.length === 1 ? "" : "s"} started`;
128
+ return added.length ? { added, change: { by: { host: said }, writes: [{ path: AUDITS_FILE, text: auditsText([...before, ...added]) }] } } : { added };
129
+ }
130
+ /** The rows the hold rule counts for `workflow` at `digest` under the promotion begun at `promotedAt` (learn/promote.ts
131
+ * promotionStartOf; none counted for null): those with a verdict, the newest `hold_window` of them. */
132
+ export const windowOf = (rows, workflow, digest, promotedAt, loop) => promotedAt === null ? [] : rows.filter((row) => row.workflow === workflow && row.digest === digest && row.promoted_at === promotedAt && row.agreed !== null).slice(-loop.hold_window);
133
+ /** The hold rule: the counted rows (windowOf) when at least `hold_disagree` of them disagree, else undefined. */
134
+ export function holdOf(rows, workflow, digest, promotedAt, loop) {
135
+ const counted = windowOf(rows, workflow, digest, promotedAt, loop);
136
+ const disagreed = counted.filter((row) => row.agreed === false);
137
+ return disagreed.length >= loop.hold_disagree ? { rows: counted, disagreed } : undefined;
138
+ }
139
+ export function auditLineOf(rows, workflow, digest, promotedAt, loop) {
140
+ const counted = windowOf(rows, workflow, digest, promotedAt, loop);
141
+ return { window: loop.hold_window, disagree: loop.hold_disagree, rows: counted.length, disagreed: counted.filter((row) => row.agreed === false).length };
142
+ }
143
+ export function servingLinesOf(records, rows, loop) {
144
+ return servingOf(records).map(({ workflow, digest }) => {
145
+ const own = records.filter((one) => one.workflow === workflow);
146
+ const newest = own.at(-1);
147
+ const state = newest?.decided === "replaying" ? "checking"
148
+ : digest !== null ? "serving"
149
+ : newest?.decided === "hold" && (newest.check?.stopped || newest.audit?.stopped) ? "stopped"
150
+ : "held";
151
+ const checked = own.findLast((one) => one.check?.n !== undefined)?.check;
152
+ const at = digest ?? newest?.digest;
153
+ return {
154
+ state,
155
+ check: checked ? { n: checked.n, agreed: checked.agreed ?? 0, alone: checked.alone ?? 0, attempt: checked.attempt } : null,
156
+ audit: at === undefined ? null : auditLineOf(rows, workflow, at, promotionStartOf(records, workflow, at)?.at ?? null, loop),
157
+ };
158
+ });
159
+ }
@@ -101,6 +101,9 @@ export type ProposalCheck = {
101
101
  /** `problem` as it may be printed: its path and detail cut of `values` and of every shape learning refuses, a bank's
102
102
  * numbers too (redactLearned: a name refused for one never prints it), whole when over PRINT_MAX. */
103
103
  export declare const printable: (problem: Problem, values: readonly string[]) => Problem;
104
+ /** The model node kinds a tier routes (model.ts MODEL_NODES); a decision node (judge, pick, sift) goes to its decision
105
+ * provider, never a tier. */
106
+ export declare const TIERED_KINDS: ReadonlySet<string>;
104
107
  /** Why a draft's answer is not written on the agent's own model: each model node that writes the state key its
105
108
  * output.path reads (its answering step) and names tier "fast", one line each, in words the compile retry acts on. A
106
109
  * composed workflow node that writes it answers with its own workflow's answering step, held to the same; a map that
@@ -139,7 +139,7 @@ function decodedScanned(path, text, refused, add, deep = true) {
139
139
  }
140
140
  /** The model node kinds a tier routes (model.ts MODEL_NODES); a decision node (judge, pick, sift) goes to its decision
141
141
  * provider, never a tier. */
142
- const TIERED_KINDS = new Set(["agent", "decide", "extract", "report"]);
142
+ export const TIERED_KINDS = new Set(["agent", "decide", "extract", "report"]);
143
143
  const isNode = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.node === "string";
144
144
  /** The state key a step writes (the DSL's writeKeyOf): a report's `report_markdown`, else its `as`, else an agent's,
145
145
  * decide's or extract's label. */
@@ -1,13 +1,10 @@
1
1
  import type { RunRow, Store } from "../store/store.js";
2
2
  import type { AuthorHostAddendum } from "@parcha/agentrun-dsl";
3
- import { type CheckRecord, type PromotionRecord } from "./promote.js";
3
+ import { type AuditHold, type CheckRecord, type PromotionRecord } from "./promote.js";
4
4
  /** How many of the agent's last runs (before the ending one, which is in the session already) the compile turn reads. */
5
5
  export declare const COMPILE_TRACES = 5;
6
6
  /** How many times a refused draft goes back to the model with its errors: at most 1 + COMPILE_RETRIES attempts. */
7
7
  export declare const COMPILE_RETRIES = 3;
8
- /** How many of an agent's runs before the ending one are read for an earlier compile: one there (it may still wait for
9
- * its grade, or it failed) asks none now, so a job is compiled at most once in that many runs. */
10
- export declare const COMPILE_QUIET_RUNS = 4;
11
8
  /** The longest the compile turn may take, every attempt in it, before the run ends with what it has. */
12
9
  export declare const COMPILE_TIMEOUT_MS: number;
13
10
  /** The most of a run's trace the compile turn holds, in characters. */
@@ -15,38 +12,16 @@ export declare const TRACE_MAX = 4000;
15
12
  /** The most of the agent's notes, together, the compile turn reads, in characters. It reads them whole, every rule kept:
16
13
  * notes over it compile nothing, and the record says why (compileTurn), never a workflow from a cut set of rules. */
17
14
  export declare const NOTES_MAX = 96000;
18
- /** A workflow the money rule stopped from running first (runner/workflow-first.ts costLineOf): its name, and its cost a
19
- * run over its last `runs` served runs against the agent's by hand, in dollars. */
20
- export interface ReviseAsk {
21
- readonly workflow: string;
22
- readonly served_usd: number;
23
- readonly by_hand_usd: number;
24
- readonly runs: number;
25
- }
26
- /** A workflow its promotion holds (runner/promotion.ts, learn/promote.ts): the run went by hand, and the hold's record
27
- * says why, from its replay on the agent's graded inputs (`replay`'s numbers) or the graded runs it served (`reason`). */
15
+ /** A workflow its promotion holds (runner/promotion.ts, learn/promote.ts): the run went by hand, and the hold's record says
16
+ * why, from its one check on the agent's own runs (`check`'s numbers and the inputs it disagreed on) or its `reason`. */
28
17
  export interface HeldAsk {
29
18
  readonly workflow: string;
30
19
  readonly digest: string;
31
- readonly source: PromotionRecord["source"];
32
20
  readonly reason: string;
33
- readonly replay?: {
34
- readonly n: number;
35
- readonly agree: number;
36
- readonly agent_acc: number;
37
- readonly wf_acc: number;
38
- readonly delta: number;
39
- readonly handed_back: number;
40
- };
41
- /** A check's hold (source `check`): its numbers and bar, and the inputs it disagreed on, which the recompile reads as
42
- * data. */
43
21
  readonly check?: CheckRecord;
44
- }
45
- /** A run its learned workflow answered alone that a grade said was wrong (runner/feedback-round.ts, a `revise` round):
46
- * the workflow's answer and the grade's words, each cut of the run's secrets. */
47
- export interface GradedAsk {
48
- readonly answer: string;
49
- readonly words: string;
22
+ /** An audit's hold (runner/audit.ts): its window and bar, and the audited runs it disagreed on with the
23
+ * agent's own answer, which the recompile reads as data. */
24
+ readonly audit?: AuditHold;
50
25
  }
51
26
  /** One of the agent's earlier runs as the compile turn reads it: what it was asked, each tool call it made (`tool`, its
52
27
  * input as the timeline previews it, and whether it failed), its answer, and what a person said after (feedback). */
@@ -61,13 +36,11 @@ export interface CompileTrace {
61
36
  readonly feedback: readonly string[];
62
37
  }
63
38
  /** What the compile turn is asked with. `mode` new: the job as a new workflow; revise: `workflow`, whose text is
64
- * `current`, again whole, after it handed this run back (`handedBack`), the money rule stopped it (`revise`), a grade
65
- * said the answer it gave this run alone was wrong (`graded`) or its promotion holds it (`held`).
39
+ * `current`, again whole, once its promotion holds it (`held`).
66
40
  * `reference`: the workflow language as compileReference renders it. `notes`: the agent's active notes, whole.
67
41
  * `traces`: its last runs. `input`: this run's input as it was launched, whose fields a workflow's input takes. `tools`:
68
42
  * those a call node may run, with what each takes and gives (`described`); `judges`: whether the run has a decision
69
- * provider (judge, pick and sift nodes are allowed); `jev`: whether one of them is Jev, not denied (no rule reads it
70
- * now that no step takes a guard).
43
+ * provider (judge, pick and sift nodes are allowed).
71
44
  * `outputSchema`: the agent's, when it has one: a run serving the workflow serves its answer shaped to it, else hands the
72
45
  * run back (answer-json.ts answerAsServed), so the workflow's final output must be that object. */
73
46
  export type CompileAsk = {
@@ -87,7 +60,6 @@ export type CompileAsk = {
87
60
  readonly does: string;
88
61
  }[];
89
62
  readonly judges: boolean;
90
- readonly jev?: boolean;
91
63
  } & ({
92
64
  readonly mode: "new";
93
65
  } | {
@@ -97,10 +69,7 @@ export type CompileAsk = {
97
69
  /** The commit of main `current` was read at: the revision's conflict base (its merge refuses a change to the workflow
98
70
  * on main after this read, never one before it, which the revision was written over). Never told the model. */
99
71
  readonly base?: string;
100
- readonly handedBack?: true;
101
- readonly revise?: ReviseAsk;
102
- readonly graded?: GradedAsk;
103
- readonly held?: HeldAsk;
72
+ readonly held: HeldAsk;
104
73
  });
105
74
  /** One attempt of the compile turn: whether its draft passed the checks, and else why not, in the checks' words. */
106
75
  export type CompileAttempt = {
@@ -118,50 +87,66 @@ export type CompiledRecord = {
118
87
  readonly digest?: string;
119
88
  readonly promoted?: boolean;
120
89
  };
121
- /** Whether the draft a compile kept at `digest` serves (learn/promote.ts records, newest wins): true once promoted, or
122
- * once a threshold refit of it was (its new revision serves in its place); false while held, or once a newer revision
123
- * was skipped for a newer one; undefined while it is queued or replayed, or before its first claim decides it. */
90
+ /** Whether the draft a compile kept at `digest` serves (learn/promote.ts records, newest wins): true once promoted, false
91
+ * while held; undefined while its check runs, or before its first claim decides it. */
124
92
  export declare function promotedOf(records: readonly PromotionRecord[], workflow: string, digest: string): boolean | undefined;
125
93
  /** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
126
94
  * that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
127
- * graded hold counts: with it held there is no champion. One with a revision queued is not: that newer revision replays
128
- * next (a replay ahead of it held meanwhile asks for nothing). Nor one a check stopped (its recompile's check held it
129
- * too): nothing compiles it again. */
95
+ * hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
96
+ * compiles it again. */
130
97
  export declare function heldNamesOf(records: readonly PromotionRecord[]): Set<string>;
131
- /** Whether a store run ended completed (its state `ended`, a plain completion). */
98
+ /** The words a compile's promotion record starts with when every draft of its turn failed its checks (runner/
99
+ * learning-end.ts recordDraftFailed): a hold with nothing checked, the compile's attempt all the same. */
100
+ export declare const DRAFT_FAILED = "its draft failed its checks";
101
+ /** Whether a promotion record is a compile turn's failed draft (DRAFT_FAILED), not a check's decision. */
102
+ export declare const draftFailedOf: (record: PromotionRecord) => boolean;
103
+ /** Which compile a new workflow's is, for an agent with no learned workflow: 2 (the one recompile) right after a first
104
+ * compile whose drafts all failed their checks (the agent's newest record), else 1. */
105
+ export declare function newCompileAttempt(records: readonly PromotionRecord[]): 1 | 2;
106
+ /** Whether the agent's compile stopped on its drafts: its newest record is a recompile's failed draft (nothing compiles
107
+ * a new workflow again until its owner acts). */
108
+ export declare function compileStoppedOf(records: readonly PromotionRecord[]): boolean;
109
+ /** Whether a store run ended completed (its state `ended`, a plain completion), and is no audit's shadow run (an
110
+ * agent's answer kept for an audit, never a run of the agent's own to learn from). */
132
111
  export declare const completedRun: (run: {
112
+ readonly id: string;
133
113
  readonly state: string;
134
114
  readonly outcome: string | null;
135
115
  }) => boolean;
136
116
  /** Whether a store run is a completed run of the agent's own (completedRun), not one its learned workflow answered alone
137
- * nor a check's replay run: what compile_after counts. */
117
+ * nor a check's replay run (nor an audit's shadow, completedRun): what compile_after counts. */
138
118
  export declare const agentRun: (run: {
119
+ readonly id: string;
139
120
  readonly state: string;
140
121
  readonly outcome: string | null;
141
122
  readonly metrics?: unknown;
142
123
  }) => boolean;
143
- /** The agent's last `n` completed runs of its own (agentRun: not one its learned workflow answered alone, not a replay;
144
- * never `exceptRunId`, an archived run or an imported one), newest first, picked before anything else limits them: runs
145
- * its workflow served since, however many, never push them out of the read (it reads more of the agent's ended runs
146
- * until it has `n`, or there are no more). The one read of what compile_after counts and of a check's inputs. */
147
- export declare function lastOwnRuns(store: Pick<Store, "runs">, agentId: string, n: number, exceptRunId?: string): Promise<RunRow[]>;
124
+ /** The agent's newest `n` runs that `keep` keeps (of those the store lists by `listed`: e.g. only ended, not archived),
125
+ * newest first, picked before anything else limits them: runs it does not keep, however many, never push them out of the
126
+ * read (it reads more of the agent's runs until it has `n`, or there are no more). */
127
+ export declare function lastRunsOf(store: Pick<Store, "runs">, agentId: string, n: number, keep: (row: RunRow) => boolean, listed?: {
128
+ readonly state?: "ended";
129
+ readonly archived?: false;
130
+ }): Promise<RunRow[]>;
131
+ /** The agent's last `n` completed runs of its own (agentRun: not one its learned workflow answered alone, not a replay
132
+ * nor a shadow audit; never `exceptRunId`, an archived run or an imported one), newest first (lastRunsOf: runs its
133
+ * workflow served since never push them out of the read). The one read of what compile_after counts and of a check's
134
+ * inputs. */
135
+ export declare const lastOwnRuns: (store: Pick<Store, "runs">, agentId: string, n: number, exceptRunId?: string) => Promise<RunRow[]>;
148
136
  /** Whether a run's look-back compiles its agent's job: the run completed, the agent has no learned workflow (active or
149
- * waiting for its owner's OK), none of its last COMPILE_QUIET_RUNS runs compiled, and it has `compileAfter` completed
137
+ * waiting for its owner's OK), and it has `compileAfter` completed
150
138
  * agent runs (its definition's compile_after, learning-setting.ts), the ending one counted. */
151
139
  export declare const compileDue: (facts: {
152
140
  readonly completed: boolean;
153
141
  readonly runs: number;
154
142
  readonly workflows: number;
155
- readonly compiledLately: boolean;
156
143
  readonly compileAfter: number;
157
144
  }) => boolean;
158
145
  /** This host's addendum to the DSL's author contract: the node kinds it runs, and its rules, each one the checks hold a
159
- * draft to (learn/skills.ts draftProblems; propose.ts; check.ts; guardProblems). No step takes a guard: code checks and
160
- * escalate steps hand back, so `jev` (whether the run can call Jev) changes no rule. */
146
+ * draft to (learn/skills.ts draftProblems; propose.ts; check.ts). */
161
147
  export declare function learnedHost(options: {
162
148
  readonly tools: readonly string[];
163
149
  readonly judges: boolean;
164
- readonly jev?: boolean;
165
150
  readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
166
151
  }): AuthorHostAddendum;
167
152
  /** The workflow language for the compile turn, generated: the DSL's own author contract (rendered from its vocabulary, so
@@ -173,7 +158,6 @@ export declare const compileReference: (dsl: {
173
158
  }, options: {
174
159
  readonly tools: readonly string[];
175
160
  readonly judges: boolean;
176
- readonly jev?: boolean;
177
161
  readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
178
162
  }) => string;
179
163
  /** The worked example's input, as a run gives it. */
@@ -188,7 +172,7 @@ export declare const EXAMPLE_TOOL = "fetch_page";
188
172
  * the run has a tool), an extract step copies compact facts from the page, the verbatim lines the answer will quote among
189
173
  * them. The answer on the agent's own model (no tier: answerTierProblems) from those facts and its own draft alone, never
190
174
  * the page (compactStateProblems), in a re-pick loop of 2 until its quotes are in the page (quoteCheckProblems); then the
191
- * quote check hands back a second miss, and an escalate step a case the policy does not cover. No step takes a guard.
175
+ * quote check hands back a second miss, and an escalate step a case the policy does not cover.
192
176
  * With no tool to fetch with, the facts come from the input and the answer quotes nothing it must check. */
193
177
  export declare function compileExample(fetches?: boolean): Record<string, unknown>;
194
178
  /** Whether `text` is a compile ask: `again` for an attempt the checks sent back, true for the first, else false. */
@@ -203,16 +187,12 @@ export declare function compilePrompt(ask: CompileAsk): string;
203
187
  * fenced as data), and the attempt it was. */
204
188
  export declare function compileAgain(errors: readonly string[], attempt: number): string;
205
189
  /** A compile answer read: the draft's block whole (to check), its name and the notes it says it carries out (only ones
206
- * the turn was given); `unchanged` for a revision the model kept as it is (never a held one's); else why it can't be
207
- * read. */
190
+ * the turn was given); else why it can't be read. */
208
191
  export type CompileRead = {
209
192
  readonly ok: true;
210
193
  readonly name: string;
211
194
  readonly block: string;
212
195
  readonly from_notes: readonly string[];
213
- } | {
214
- readonly ok: false;
215
- readonly unchanged: true;
216
196
  } | {
217
197
  readonly ok: false;
218
198
  readonly error: string;
@@ -237,18 +217,13 @@ type CheckedLike = {
237
217
  /** Why the checks did not keep draft `name` from `checked` (each problem's words, its path's in front when it names
238
218
  * another file); none when its workflow.json is in the proposal. */
239
219
  export declare function draftErrorsOf(checked: CheckedLike | undefined, name: string): string[];
240
- /** The guards a draft carries, one line each: none is asked for (learnedHost's rules: code checks and escalate steps
241
- * hand back; chain14b's step guards made 0 judgments live and its page and facts guards read at chance), so each is
242
- * refused, the SDK bridge's in its words (it has no guardStep callback). None when no step has one. */
243
- export declare function guardProblems(doc: unknown, options?: {
244
- readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
245
- }): string[];
246
220
  /** The record's workflow when no attempt named one. */
247
221
  export declare const UNNAMED = "(unnamed)";
248
- /** The compile turn, start to end: ask, read, check (`check` over the look-back's answer with the draft in it, then the
249
- * guards it must not carry, guardProblems), and on a refusal ask again with the errors, at most 1 + COMPILE_RETRIES
222
+ /** The compile turn, start to end: ask, read, check (`check` over the look-back's answer with the draft in it), and on a refusal ask again with the errors, at most 1 + COMPILE_RETRIES
250
223
  * times and within `deadlineMs`. What it ends with: `kept` with the answer and what the checks made of it when an
251
- * attempt passed; else none, with every attempt. Notes over NOTES_MAX ask nothing: one attempt says why. */
224
+ * attempt passed; else none, with every attempt, and `drafted` when an attempt answered (its drafts failed their
225
+ * checks: the compile's attempt, DRAFT_FAILED; a turn that never answered is none). Notes over NOTES_MAX ask nothing:
226
+ * one attempt says why. */
252
227
  export declare function compileTurn<C extends CheckedLike>(input: {
253
228
  /** One attempt's ask (`attempt` from 1), within `deadlineMs`: its answer, or undefined when the turn timed out or failed. */
254
229
  readonly ask: (prompt: string, attempt: number, deadlineMs: number) => Promise<{
@@ -268,5 +243,6 @@ export declare function compileTurn<C extends CheckedLike>(input: {
268
243
  checked: C;
269
244
  };
270
245
  draftErrors: string[];
246
+ drafted?: true;
271
247
  }>;
272
248
  export {};