@parcha/agentrun-serve 0.1.0-beta.41 → 0.1.0-beta.43

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 (164) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/NOTICE +2 -0
  3. package/README.md +85 -19
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +3 -1
  6. package/dist/calendar/address.d.ts +49 -0
  7. package/dist/calendar/address.js +153 -0
  8. package/dist/calendar/fetch.d.ts +24 -0
  9. package/dist/calendar/fetch.js +146 -0
  10. package/dist/calendar/ics-faux.d.ts +39 -0
  11. package/dist/calendar/ics-faux.js +236 -0
  12. package/dist/calendar/labels.d.ts +3 -0
  13. package/dist/calendar/labels.js +61 -0
  14. package/dist/calendar/names.d.ts +52 -0
  15. package/dist/calendar/names.js +54 -0
  16. package/dist/calendar/parse.d.ts +108 -0
  17. package/dist/calendar/parse.js +625 -0
  18. package/dist/calendar/routes.d.ts +17 -0
  19. package/dist/calendar/routes.js +81 -0
  20. package/dist/calendar/tools.d.ts +23 -0
  21. package/dist/calendar/tools.js +124 -0
  22. package/dist/cli.js +3 -1
  23. package/dist/computer-record.d.ts +55 -0
  24. package/dist/computer-record.js +315 -0
  25. package/dist/computer-setting.d.ts +1 -0
  26. package/dist/computer-setting.js +15 -2
  27. package/dist/computers.js +2 -14
  28. package/dist/console/assets/index-BrcDSBD8.css +1 -0
  29. package/dist/console/assets/index-Bz6IWncl.js +711 -0
  30. package/dist/console/index.html +2 -2
  31. package/dist/decisions.js +0 -4
  32. package/dist/eval-feed.d.ts +2 -2
  33. package/dist/eval-feed.js +9 -5
  34. package/dist/feed/parse.d.ts +3 -2
  35. package/dist/feed/parse.js +9 -18
  36. package/dist/feed/pointer.d.ts +2 -0
  37. package/dist/feed/pointer.js +17 -0
  38. package/dist/file-types.js +1 -0
  39. package/dist/host-command.d.ts +3 -0
  40. package/dist/host-command.js +18 -0
  41. package/dist/host.d.ts +3 -0
  42. package/dist/host.js +3 -0
  43. package/dist/import-sources.js +25 -5
  44. package/dist/learn/audit.d.ts +123 -0
  45. package/dist/learn/audit.js +159 -0
  46. package/dist/learn/check.d.ts +14 -0
  47. package/dist/learn/check.js +194 -14
  48. package/dist/learn/compile.d.ts +75 -78
  49. package/dist/learn/compile.js +175 -176
  50. package/dist/learn/folder.d.ts +9 -0
  51. package/dist/learn/folder.js +13 -2
  52. package/dist/learn/promote.d.ts +138 -196
  53. package/dist/learn/promote.js +68 -184
  54. package/dist/learn/replay-calls.d.ts +5 -0
  55. package/dist/learn/replay-calls.js +12 -1
  56. package/dist/learn/secrets.d.ts +8 -0
  57. package/dist/learn/secrets.js +12 -0
  58. package/dist/learn/skills.js +2 -4
  59. package/dist/learn/workflow-nodes.d.ts +1 -2
  60. package/dist/learn/workflow-nodes.js +2 -3
  61. package/dist/learned-nodes.d.ts +9 -34
  62. package/dist/learned-nodes.js +11 -23
  63. package/dist/learned-workflow.d.ts +6 -8
  64. package/dist/learned-workflow.js +18 -57
  65. package/dist/learning-batch.d.ts +13 -5
  66. package/dist/learning-batch.js +34 -8
  67. package/dist/learning-cost.d.ts +11 -4
  68. package/dist/learning-cost.js +4 -2
  69. package/dist/learning-routes.js +1 -1
  70. package/dist/learning-setting.d.ts +38 -0
  71. package/dist/learning-setting.js +83 -0
  72. package/dist/learning-words.d.ts +3 -0
  73. package/dist/learning-words.js +3 -0
  74. package/dist/learning.d.ts +3 -2
  75. package/dist/learning.js +5 -3
  76. package/dist/mcp-oauth.d.ts +8 -0
  77. package/dist/mcp-oauth.js +7 -0
  78. package/dist/mcp-private-hosts.d.ts +13 -0
  79. package/dist/mcp-private-hosts.js +16 -0
  80. package/dist/openapi.d.ts +1 -0
  81. package/dist/openapi.js +195 -59
  82. package/dist/run-files.d.ts +6 -2
  83. package/dist/run-files.js +29 -7
  84. package/dist/run-launch.d.ts +6 -3
  85. package/dist/run-launch.js +2 -0
  86. package/dist/run-learning-served.d.ts +2 -2
  87. package/dist/run-reads-over-store.d.ts +5 -1
  88. package/dist/run-reads-over-store.js +8 -4
  89. package/dist/run-recordings.d.ts +20 -0
  90. package/dist/run-recordings.js +133 -0
  91. package/dist/runner/adapter-loop.d.ts +5 -1
  92. package/dist/runner/adapter-loop.js +20 -8
  93. package/dist/runner/adapter-run-spec.d.ts +16 -1
  94. package/dist/runner/adapter-run-spec.js +36 -11
  95. package/dist/runner/audit.d.ts +64 -0
  96. package/dist/runner/audit.js +338 -0
  97. package/dist/runner/beside.js +2 -2
  98. package/dist/runner/cli-run-spec.js +25 -12
  99. package/dist/runner/feedback-round.d.ts +9 -25
  100. package/dist/runner/feedback-round.js +19 -40
  101. package/dist/runner/harness-loops.js +1 -15
  102. package/dist/runner/journal-kinds.d.ts +0 -7
  103. package/dist/runner/journal-kinds.js +0 -7
  104. package/dist/runner/learning-dispatch.d.ts +0 -16
  105. package/dist/runner/learning-dispatch.js +4 -47
  106. package/dist/runner/learning-end.d.ts +62 -13
  107. package/dist/runner/learning-end.js +180 -74
  108. package/dist/runner/learning-factory.d.ts +1 -1
  109. package/dist/runner/learning-factory.js +1 -4
  110. package/dist/runner/learning-loop.d.ts +2 -38
  111. package/dist/runner/learning-loop.js +8 -116
  112. package/dist/runner/main.d.ts +11 -0
  113. package/dist/runner/main.js +30 -3
  114. package/dist/runner/mcp-run.d.ts +2 -2
  115. package/dist/runner/promotion.d.ts +78 -50
  116. package/dist/runner/promotion.js +371 -503
  117. package/dist/runner/reflect-hook.d.ts +15 -0
  118. package/dist/runner/reflect-hook.js +28 -14
  119. package/dist/runner/store-secrets.js +3 -1
  120. package/dist/runner/workflow-first.d.ts +6 -11
  121. package/dist/runner/workflow-first.js +24 -25
  122. package/dist/runs-over-store.d.ts +1 -1
  123. package/dist/sdk/runs.js +2 -1
  124. package/dist/secrets.js +2 -2
  125. package/dist/server.d.ts +4 -3
  126. package/dist/server.js +132 -26
  127. package/dist/store/agent-body.d.ts +5 -3
  128. package/dist/store/agent-body.js +14 -10
  129. package/dist/store/sqlite/store.js +1 -0
  130. package/dist/store/store.d.ts +3 -0
  131. package/dist/store-reads/learning.d.ts +18 -7
  132. package/dist/store-reads/learning.js +36 -23
  133. package/dist/store-reads/loop.d.ts +5 -39
  134. package/dist/store-reads/loop.js +21 -80
  135. package/dist/store-view.d.ts +5 -0
  136. package/dist/store-view.js +16 -2
  137. package/dist/template-eval.d.ts +7 -0
  138. package/dist/template-eval.js +54 -6
  139. package/dist/templates.d.ts +3 -1
  140. package/dist/templates.js +14 -1
  141. package/dist/timeline/computer.js +2 -1
  142. package/dist/tool-list.js +1 -0
  143. package/dist/tools.d.ts +7 -0
  144. package/dist/tools.js +11 -0
  145. package/dist/trigger-feed.js +67 -18
  146. package/dist/validate.js +7 -2
  147. package/dist/workspace/computer-for-claim.d.ts +7 -0
  148. package/dist/workspace/computer-for-claim.js +12 -2
  149. package/dist/workspace/paths.d.ts +4 -0
  150. package/dist/workspace/paths.js +9 -0
  151. package/dist/workspace/resolve-computer.d.ts +3 -1
  152. package/dist/workspace/run-tools.d.ts +1 -1
  153. package/dist/workspace/run-tools.js +14 -3
  154. package/launcher/agentrun-serve +31 -24
  155. package/package.json +10 -9
  156. package/templates/README.md +11 -2
  157. package/dist/console/assets/index-C3gNPz58.css +0 -1
  158. package/dist/console/assets/index-COGhx_2Z.js +0 -711
  159. package/dist/learn/general.d.ts +0 -69
  160. package/dist/learn/general.js +0 -75
  161. package/dist/learn/refit.d.ts +0 -48
  162. package/dist/learn/refit.js +0 -264
  163. package/dist/runner/step-guard.d.ts +0 -62
  164. package/dist/runner/step-guard.js +0 -93
@@ -26,6 +26,8 @@ import { learnedFront, learnedName, learnedStatus, retiredFrom, SKILLS_DIR, WORK
26
26
  export const HOST_DIR = ".agentrun";
27
27
  export const SNAPSHOT_FILE = `${HOST_DIR}/snapshot.json`;
28
28
  export const DIFFS_DIR = `${HOST_DIR}/diffs`;
29
+ /** The audit ledger at the folder's top (learn/audit.ts): one JSON row per line. */
30
+ export const AUDITS_FILE = "audits.jsonl";
29
31
  /** The most changes the snapshot's log keeps, newest first; `log_more` says older exist. */
30
32
  export const LOG_KEEP = 200;
31
33
  /** A file main holds over this is no note and no learned file: a note is at most 4 KB (check.ts CAPS.note). */
@@ -225,6 +227,7 @@ export function snapshotOfRead(read) {
225
227
  const orderOf = (path) => order.get(path) ?? Number.MAX_SAFE_INTEGER;
226
228
  const historyOf = (path) => history.get(path) ?? { at };
227
229
  const index = tree.find((entry) => entry.path === INDEX_FILE && regular(entry));
230
+ const audits = tree.find((entry) => entry.path === AUDITS_FILE && regular(entry));
228
231
  const notes = [];
229
232
  const folders = new Map();
230
233
  for (const entry of tree) {
@@ -259,7 +262,7 @@ export function snapshotOfRead(read) {
259
262
  if (item)
260
263
  (kind === "skill" ? skills : workflows).push(item);
261
264
  }
262
- return { v: 1, main, at, index: index ? { oid: index.oid, bytes: index.bytes } : EMPTY_INDEX, notes: notes.sort(noteOrder), skills: skills.sort(byName), workflows: workflows.sort(byName), log, log_more: more };
265
+ return { v: 1, main, at, index: index ? { oid: index.oid, bytes: index.bytes } : EMPTY_INDEX, ...(audits ? { audits: { oid: audits.oid, bytes: audits.bytes } } : {}), notes: notes.sort(noteOrder), skills: skills.sort(byName), workflows: workflows.sort(byName), log, log_more: more };
263
266
  }
264
267
  /** A learned item from its folder's files: listed when its folder is well named, its key file (SKILL.md, a draft's
265
268
  * README.md) is there and reads, and a draft has its workflow.json too, each of those a regular file under FILE_CAP
@@ -288,6 +291,11 @@ function messageOf(by) {
288
291
  const paragraphs = (parts) => parts.map((part) => (part.endsWith("\n") ? part : `${part}\n`)).join("\n");
289
292
  if (!by)
290
293
  return { message: `${INIT_SUBJECT}\n`, subject: INIT_SUBJECT, body: "", runId: "", changedBy: "", approvedVia: "" };
294
+ // The host's own book-keeping (an audit row): no trailer, so no change in the log a person reads.
295
+ if ("host" in by) {
296
+ const subject = `host: ${clean(by.host).trim() || "kept"}`;
297
+ return { message: `${subject}\n`, subject, body: "", runId: "", changedBy: "", approvedVia: "" };
298
+ }
291
299
  if ("run" in by) {
292
300
  const subject = `learning: ${by.run}: merged`;
293
301
  const reason = clean(by.reason).trim() || "merged";
@@ -306,6 +314,8 @@ function oidsOf(snapshot) {
306
314
  if (!snapshot)
307
315
  return out;
308
316
  out.set(INDEX_FILE, snapshot.index.oid);
317
+ if (snapshot.audits)
318
+ out.set(AUDITS_FILE, snapshot.audits.oid);
309
319
  for (const note of snapshot.notes)
310
320
  out.set(note.file, note.oid);
311
321
  for (const item of [...snapshot.skills, ...snapshot.workflows])
@@ -336,6 +346,7 @@ export function nextSnapshot(before, change, seconds) {
336
346
  notes.push(note);
337
347
  }
338
348
  const index = writes.has(INDEX_FILE) ? { oid: writes.get(INDEX_FILE).oid, bytes: writes.get(INDEX_FILE).bytes } : (before?.index ?? EMPTY_INDEX);
349
+ const audits = writes.has(AUDITS_FILE) ? { oid: writes.get(AUDITS_FILE).oid, bytes: writes.get(AUDITS_FILE).bytes } : deletes.has(AUDITS_FILE) ? undefined : before?.audits;
339
350
  const learned = (kind, list) => {
340
351
  const hit = new Set(changed.map(folderOf).filter((folder) => folder?.kind === kind).map((folder) => folder.name));
341
352
  const out = list.filter((item) => !hit.has(item.name)).map((item) => ({ ...item, order: item.order + 1 }));
@@ -367,7 +378,7 @@ export function nextSnapshot(before, change, seconds) {
367
378
  const entry = change && isChange(commit) ? changeEntry(commit, PLACEHOLDER, changed) : undefined;
368
379
  const log = [...(entry ? [entry] : []), ...(before?.log ?? [])];
369
380
  const snapshot = {
370
- v: 1, main: PLACEHOLDER, at: commit.at, index,
381
+ v: 1, main: PLACEHOLDER, at: commit.at, index, ...(audits ? { audits } : {}),
371
382
  notes: notes.sort(noteOrder), skills: learned("skill", before?.skills ?? []), workflows: learned("workflow", before?.workflows ?? []),
372
383
  log: log.slice(0, LOG_KEEP), log_more: Boolean(before?.log_more) || log.length > LOG_KEEP,
373
384
  };
@@ -1,27 +1,18 @@
1
- import type { GuardRow } from "../learned-nodes.js";
2
1
  import type { RunPath } from "../learning-cost.js";
3
2
  import type { FeedbackRound, OpenedRound } from "../runner/feedback-round.js";
4
3
  import type { Settings } from "../store/store.js";
5
4
  import type { Skipped } from "./replay-calls.js";
6
5
  import type { ReplayOutcome } from "../runner/workflow-first.js";
7
- /** How many of the agent's newest graded inputs a replay runs on. */
8
- export declare const REPLAY_INPUTS = 20;
9
- /** The fewest graded inputs a replay runs on: with fewer, a workflow is promoted on its passing dry run, as before. */
10
- export declare const REPLAY_MIN = 5;
11
- /** How far below the agent path's accuracy on the same inputs a workflow may be and still serve: 2 points. */
12
- export declare const PROMOTE_BAR = 0.02;
13
- /** A serving revision's thresholds are refit at most once per this many graded runs it served. */
14
- export declare const REFIT_EVERY = 20;
15
6
  /** How many grades, and how many promotion records, an agent keeps (newest kept). */
16
7
  export declare const GRADES_KEPT = 500;
17
8
  export declare const PROMOTIONS_KEPT = 200;
18
- /** The most characters a grade's words (`label`) may hold, and the most of them and of a wrong answer a revise ask shows. */
9
+ /** The most characters a grade's words (`label`) may hold, and the most of them and of an answer a compile ask shows. */
19
10
  export declare const LABEL_MAX = 4000;
20
11
  export declare const GRADE_SOURCES: readonly ["feedback", "eval"];
21
12
  export type GradeSource = (typeof GRADE_SOURCES)[number];
22
13
  /** One graded run: whether its answer was right (`correct`), the answer's expected fields when the grader knows them
23
- * (`expected`: a replay's answer is right when its JSON holds each of them), who said so, and, read from the run's record
24
- * when it was graded, the path it took and the learned workflow and digest that served it. */
14
+ * (`expected`), who said so, and, read from the run's record when it was graded, the path it took and the learned
15
+ * workflow and digest that served it. */
25
16
  export interface Grade {
26
17
  readonly run: string;
27
18
  readonly correct: boolean;
@@ -31,13 +22,9 @@ export interface Grade {
31
22
  readonly path: RunPath;
32
23
  readonly workflow?: string;
33
24
  readonly digest?: string;
34
- /** Its place among the agent's grades, one more than the grade put before it (a re-grade takes a new one): a cursor a
35
- * serving digest's check counts new grades from (PromotionRecord.checked) that the GRADES_KEPT trim never moves back. */
25
+ /** Its place among the agent's grades, one more than the grade put before it (a re-grade takes a new one), that the
26
+ * GRADES_KEPT trim never moves back: what tells a grade from another given in the same millisecond. */
36
27
  readonly seq?: number;
37
- /** The promotion of `digest` that served the run (its record's `since`, PromotionRecord.since), read from the run's
38
- * record when it was graded: a serving check counts the grade only for that promotion. Absent: one with no since (the
39
- * digest's first), or none served it. Not in the API's view. */
40
- readonly promotion?: number;
41
28
  /** The feedback round the grade opened its run again on, null for none (runner/feedback-round.ts keepGrade). Set only
42
29
  * once the round opened, so a kept grade never names a round that didn't. */
43
30
  readonly feedback?: FeedbackRound | null;
@@ -46,11 +33,11 @@ export interface Grade {
46
33
  * API's view. */
47
34
  readonly feedbackCommand?: number;
48
35
  }
49
- /** What a replay says (learn/refit.ts scoreRows), the shape the promotion record keeps (SPEC: replay {n, agree, agent_acc, wf_acc, delta}):
50
- * `n` inputs; `agree`, how many the workflow answered alone with the graded run's recorded answer; `agent_acc`, the
51
- * agent's accuracy on them (agentRight); `wf_acc`, the workflow's, a hand-back counting as the agent's answer; `delta` = wf_acc -
52
- * agent_acc; `handed_back`, how many it handed back (it answered n - handed_back alone: answersAlone). Accuracies to
53
- * 1e-4. */
36
+ /** What a replay says, the shape a replay's read keeps (SPEC: replay {n, agree, agent_acc, wf_acc, delta}): `n` inputs;
37
+ * `agree`, how many the workflow answered alone with the agent's recorded answer; `agent_acc`, the agent's accuracy on
38
+ * them (1: the agent's own answers are the label); `wf_acc`, the workflow's, a hand-back counting as the agent's answer;
39
+ * `delta` = wf_acc - agent_acc; `handed_back`, how many it handed back (it answered n - handed_back alone:
40
+ * answersAlone). Accuracies to 1e-4. */
54
41
  export interface ReplayScore {
55
42
  readonly n: number;
56
43
  readonly agree: number;
@@ -59,44 +46,27 @@ export interface ReplayScore {
59
46
  readonly delta: number;
60
47
  readonly handed_back: number;
61
48
  }
62
- /** The ReplayScore fields of `x` alone (a scoreRows or refitGuards result, or a record's `replay`): the one pick of them. */
63
- export declare const scoreOf: (x: ReplayScore) => ReplayScore;
64
- /** Whether a replay or refit answered alone on at least one of its inputs: one that hands back every input would never
65
- * serve. The one spelling of it (clears, settle's hold, the compile's held line); the count is n - handed_back. */
49
+ /** Whether a replay answered alone on at least one of its inputs: one that hands back every input would never serve. The
50
+ * one spelling of it (the compile's held line); the count is n - handed_back. */
66
51
  export declare const answersAlone: (score: Pick<ReplayScore, "n" | "handed_back">) => boolean;
67
52
  /** A learned workflow's promotion record at one digest. `decided`: `promote` (it serves first), `hold` (it does not: the
68
- * champion, championOf, takes its runs, else the agent, until a new revision), `replaying` (its replay runs, `runs`,
69
- * are at work; the champion serves meanwhile, else the agent), `queued` (it came while another revision replayed: one
70
- * replays at a time, and a running replay finishes; it replays next once that one is decided, unless a newer revision
71
- * comes first), or `skipped` (a newer revision, `skipped_by`, came while it was queued: only the newest queued one
72
- * replays next, so it never replayed and never serves). `source`: `replay` (decided on its replay), `dry_run` (fewer than REPLAY_MIN graded inputs: promoted on
73
- * its passing dry run), `refit` (a threshold refit wrote this revision, decided on the rows it was fit on), `graded` (a
74
- * serving revision's graded runs fell below the bar: held). `replay`: the numbers it was decided on, with the graded runs
75
- * replayed (`of`), what its replay runs cost (`cost_usd`, null when one's is unknown), its runs' outcomes (`outcomes`,
76
- * ReplayOutcomes: the one count of them, its `skipped_write` the inputs that needed a write the graded run's recording
77
- * does not have, learn/replay-calls.ts, never run, never scored) and the tools that stopped those (`skipped_tools`,
78
- * SkippedTool). `refit`: the guards a refit
79
- * changed. `checked`: the newest grade (its seq) the last refit check read (refits run once per REFIT_EVERY more graded runs
80
- * it served, counted by seq: a count of the grades kept stalls once the GRADES_KEPT trim holds it). `since`: on a replay's
81
- * promote, the agent's newest grade (its seq) when this promotion began: which promotion of the digest it is (a run it
82
- * serves keeps it, Grade.promotion, and its checks count only those runs' grades). `held_on`: the
83
- * served runs graded wrong a revision was held on, owed by its next replay (runner/promotion.ts heldOn). */
53
+ * champion, championOf, takes its runs, else the agent, until a new revision) or `replaying` (its check's replay runs,
54
+ * `runs`, are at work; the champion serves meanwhile, else the agent). `check`: the bar it was checked at and the
55
+ * numbers it was decided on. */
84
56
  export interface PromotionRecord {
85
57
  readonly workflow: string;
86
58
  readonly digest: string;
87
59
  readonly at: string;
88
- readonly decided: "promote" | "hold" | "replaying" | "queued" | "skipped";
89
- readonly source: "replay" | "dry_run" | "refit" | "graded";
60
+ readonly decided: "promote" | "hold" | "replaying";
90
61
  readonly reason: string;
91
- readonly replay?: ReplayScore & {
92
- readonly of: readonly string[];
93
- readonly cost_usd?: number | null;
94
- readonly skipped_tools?: readonly SkippedTool[];
95
- readonly outcomes?: ReplayOutcomes;
96
- };
62
+ /** A compiled draft's one check (runner/promotion.ts): its bar while it replays, its numbers once decided. */
63
+ readonly check?: CheckRecord;
64
+ /** A serving revision's audit hold (runner/audit.ts): the rows that held it. A hold with it is the audit's; one without
65
+ * it, its check's. */
66
+ readonly audit?: AuditHold;
97
67
  readonly runs?: readonly string[];
98
- /** A replaying record's graded runs, one per `runs` entry in order: the input each reserved replay run replays, so a
99
- * launch interrupted after the reservation is finished by a later claim (runner/promotion.ts relaunch). */
68
+ /** A replaying record's runs, one per `runs` entry in order: the agent run whose input each reserved replay run replays,
69
+ * so a launch interrupted after the reservation is finished by a later claim (runner/promotion.ts relaunch). */
100
70
  readonly inputs?: readonly string[];
101
71
  /** The replay's id, minted when it was reserved (a claim's, or a person's POST .../replays) and kept on the record that
102
72
  * decides it: what GET .../replays/{replay_id} reads. */
@@ -107,31 +77,86 @@ export interface PromotionRecord {
107
77
  * credentials run `handed_from` was handed (a claim's claimed run), else none (an owner's replay). One replay runs on
108
78
  * one set of settings. Never in the promotions read (promotionsShown). */
109
79
  readonly launch?: ReplayLaunch;
110
- readonly refit?: {
111
- readonly from: string;
112
- readonly guards: readonly RefitGuard[];
113
- };
114
- readonly checked?: number;
115
- /** A promote record's start (a replay's promote): the agent's newest grade's seq when it was written, which names this
116
- * promotion of the digest: a run it serves keeps it (metrics.workflow_promotion, then Grade.promotion), and its checks
117
- * count only the grades of those runs, never a run served under an earlier promotion and graded after this one, nor
118
- * the ones it was held on. Two promotions of a digest never share it: one is promoted again only after a graded hold,
119
- * which counts runs served (and graded, each at a newer seq) under the one before. Its checks' writes are kept only
120
- * while it is still the digest's promotion (the same since), so a check that read an older promotion writes nothing.
121
- * Absent: the digest's first record (a dry run's or a refit's promote), whose runs keep none. */
122
- readonly since?: number;
123
- /** The runs a revision served that were graded wrong when its graded check held it (newest first, at most REPLAY_INPUTS),
124
- * kept on that hold, on the replay of it its owner starts (those of them still graded and fitting it, each one of its
125
- * inputs), and on a replay's hold: a replay of the revision promotes it only once it answered (or handed back) on every
126
- * one (runner/promotion.ts heldOn). */
127
- readonly held_on?: readonly string[];
128
- /** A skipped revision's newer one: the digest that came while it was queued, and replays in its place. */
129
- readonly skipped_by?: string;
130
80
  /** The learning commit whose workflows/<workflow>/workflow.json is this digest's text: the seed of the claim that
131
- * recorded it, or a refit's own commit. What the digest serves from as the champion (championOf) once a newer revision
132
- * is on the folder's main. */
81
+ * recorded it. What the digest serves from as the champion (championOf) once a newer revision is on the folder's main. */
133
82
  readonly commit?: string;
134
83
  }
84
+ /** One audit row a hold was decided on that disagreed: the served run (`served`) and its input, the run whose answer is
85
+ * the agent's (`run`: the shadow run, else the served run for a grade), the agent's answer (`agent`: the shadow's, null
86
+ * for a grade, which says only that the served answer was wrong) and the served answer (`draft`); `graded`, a row an
87
+ * owner's grade wrote. Each text cut to CHECK_TEXT_MAX: what the one recompile reads as data. */
88
+ export interface AuditDisagreement {
89
+ readonly run: string;
90
+ readonly served: string;
91
+ readonly input: string;
92
+ readonly agent: string | null;
93
+ readonly draft: string | null;
94
+ readonly graded?: true;
95
+ }
96
+ /** An audit hold (runner/audit.ts): the definition's `hold_window` and `hold_disagree` it was decided at, how many rows
97
+ * it read (`rows`, at most the window), the disagreeing ones, and `stopped` when it was a second hold within
98
+ * `stop_window` served runs of the first: no compile is asked, nothing serves again until a new revision lands. */
99
+ export interface AuditHold {
100
+ readonly window: number;
101
+ readonly disagree: number;
102
+ readonly rows: number;
103
+ readonly disagreements: readonly AuditDisagreement[];
104
+ readonly stopped?: true;
105
+ }
106
+ /** The bar a compiled draft's check was started with: the agent definition's loop numbers then (learning-setting.ts), and
107
+ * which check of the compile it is (`attempt`: 1, the first draft's; 2, the one recompile's, after which it stops). */
108
+ export interface CheckBar {
109
+ readonly compile_after: number;
110
+ readonly agree_min: number;
111
+ readonly alone_min: number;
112
+ readonly attempt: 1 | 2;
113
+ }
114
+ /** One input a check's draft did not agree on: the agent's run (`run`) and its input, the agent's recorded answer
115
+ * (`agent`), and the draft's answer, or why it handed the input back (`escalated`), or that a step of it failed
116
+ * (`failed`). Each text cut to CHECK_TEXT_MAX: what a recompile reads as data. */
117
+ export interface CheckDisagreement {
118
+ readonly run: string;
119
+ readonly input: string;
120
+ readonly agent: string | null;
121
+ readonly draft?: string;
122
+ readonly escalated?: string;
123
+ readonly failed?: true;
124
+ }
125
+ /** A check's numbers, once decided: `n` inputs it ran on (a skipped write is none), `agreed` of them answered alone with
126
+ * the agent's recorded answer (sameAnswer), `alone` answered alone (no escalate, no failed step); the inputs (`of`, the
127
+ * agent's runs), what its replay runs cost, their outcomes (one per input: a replay run never created by the deadline
128
+ * failed), how many of its replay runs were never created (`unstarted`, when any), the tools that stopped its skipped
129
+ * inputs, the inputs it did not agree on, and `stopped` when a recompile's check held it too (nothing compiles again). */
130
+ export type CheckRecord = CheckBar & {
131
+ readonly n?: number;
132
+ readonly agreed?: number;
133
+ readonly alone?: number;
134
+ readonly of?: readonly string[];
135
+ readonly cost_usd?: number | null;
136
+ readonly outcomes?: ReplayOutcomes;
137
+ readonly unstarted?: number;
138
+ readonly skipped_tools?: readonly SkippedTool[];
139
+ readonly disagreements?: readonly CheckDisagreement[];
140
+ readonly stopped?: true;
141
+ };
142
+ /** The most characters of an input or an answer a check's disagreement keeps. */
143
+ export declare const CHECK_TEXT_MAX = 1200;
144
+ /** A check's two shares: `agreement`, of the inputs the draft answered alone those that say what the agent said (0 when
145
+ * it answered none alone); `alone`, of the inputs it ran on those it answered alone (0 when none ran). */
146
+ export declare const checkShares: (score: {
147
+ readonly n: number;
148
+ readonly agreed: number;
149
+ readonly alone: number;
150
+ }) => {
151
+ agreement: number;
152
+ alone: number;
153
+ };
154
+ /** Whether a check promotes its draft: agreement at least the bar's agree_min, and alone at least its alone_min. */
155
+ export declare const checkPasses: (score: {
156
+ readonly n: number;
157
+ readonly agreed: number;
158
+ readonly alone: number;
159
+ }, bar: Pick<CheckBar, "agree_min" | "alone_min">) => boolean;
135
160
  /** What a replay's runs are launched with (PromotionRecord.launch). */
136
161
  export interface ReplayLaunch {
137
162
  readonly revision: string;
@@ -147,22 +172,10 @@ export interface SkippedTool {
147
172
  readonly no_read_only_hint: boolean;
148
173
  }
149
174
  /** The tools that stopped `rows`' skipped inputs, most inputs first (then by name). */
150
- export declare function skippedToolsOf(rows: readonly ReplayRow[]): SkippedTool[];
151
- /** One switch a refit changed: a guard's step, its threshold before and after (`threshold` null: the guard switched off,
152
- * gone from the revision), and its new fit when one was fit; or an escalate node a replay recorded (dsl softEscalates),
153
- * switched off (`escalate`: gone from the revision; `was` and `threshold` null, it had none). */
154
- export interface RefitGuard {
155
- readonly node: string;
156
- readonly was: number | null;
157
- readonly threshold: number | null;
158
- readonly fit?: {
159
- readonly w: readonly number[];
160
- readonly b: number;
161
- readonly n: number;
162
- readonly fitted_at: string;
163
- };
164
- readonly escalate?: true;
165
- }
175
+ export declare function skippedToolsOf(rows: readonly {
176
+ readonly outcome: ReplayOutcome;
177
+ readonly skipped?: Skipped;
178
+ }[]): SkippedTool[];
166
179
  export declare const gradesKey: (agentId: string) => string;
167
180
  export declare const promotionsKey: (agentId: string) => string;
168
181
  /** The agent's grades, oldest first. */
@@ -170,32 +183,30 @@ export declare const gradesOf: (settings: Pick<Settings, "get">, agentId: string
170
183
  /** Keeps `grade`, in place of any earlier grade of the same run, the newest GRADES_KEPT kept, at the next `seq`. */
171
184
  export declare const putGrade: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, grade: Grade) => Promise<Grade>;
172
185
  /** Marks the kept grade `grade` (its run, given at its `at`, kept at its `seq`) with the feedback round it opened and
173
- * that round's steer, in place: its `seq` stays, so a serving digest's check never counts it twice. A newer grade of the
174
- * run is left as it is, one given in the same millisecond too (its `seq` is another). The grade, marked. */
186
+ * that round's steer, in place: its `seq` stays. A newer grade of the run is left as it is, one given in the same
187
+ * millisecond too (its `seq` is another). The grade, marked. */
175
188
  export declare const markGradeRound: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, grade: Grade, opened: OpenedRound) => Promise<Grade>;
176
- /** The agent's promotion records, oldest first. A beta.39 store may hold `decided: "superseded"` (a replay a newer draft
177
- * cancelled; beta.40 writes `skipped` for an older draft instead): read as `skipped`, `skipped_by` the draft that
178
- * superseded it, with a reason that says when. Only the read maps (readAs, also what a guarded write compares): the stored
179
- * record is never rewritten. */
180
- export declare const readAs: (one: PromotionRecord) => PromotionRecord;
189
+ /** The agent's promotion records, oldest first: only those in a state this code writes (writtenOf). */
181
190
  export declare const promotionsOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<PromotionRecord[]>;
182
191
  /** The newest record of `workflow` at `digest`, or undefined. */
183
192
  export declare const promotionOf: (records: readonly PromotionRecord[], workflow: string, digest: string) => PromotionRecord | undefined;
184
- /** The champion of `workflow`: the newest record of the digest promoted last (a digest's place is its latest win's,
185
- * winsOf), while that digest's newest record still says promote. A newer revision replaying or held never stops it; a
186
- * wrong served grade asks for a revision and never stops it; it stops when a newer revision's replay promotes that one
187
- * (then the champion), or its own graded runs hold it (source graded: no champion until a revision is promoted). A held
188
- * revision its owner replays (runner/promotion.ts askReplay) and the replay promotes wins again: the champion from then.
189
- * The money rule stops it on its own (runner/workflow-first.ts). Undefined: none. */
193
+ /** The champion of `workflow`: the newest record of the digest promoted last, while that digest's newest record still
194
+ * says promote. A newer revision replaying or held never stops it; it stops when a newer revision's check promotes that
195
+ * one (then the champion), or when its own newest record is a hold (a held revision its owner replays, askReplay, that
196
+ * promotes wins again). The money rule stops it on its own (runner/workflow-first.ts). Undefined: none. */
190
197
  export declare function championOf(records: readonly PromotionRecord[], workflow: string): PromotionRecord | undefined;
191
- /** The revisions of `workflow` other than `digest` whose newest record still says `decided` (replaying, else queued),
192
- * newest first: at most one replaying (one replay at a time, the reservation's guarded write), and at most one queued
193
- * once each newer one skips the one queued before it (runner/promotion.ts). */
194
- export declare function replayingOf(records: readonly PromotionRecord[], workflow: string, digest: string | null, decided?: "replaying" | "queued"): PromotionRecord[];
198
+ /** The newest promotion of `workflow` at `digest`: the promote record that began its newest run of promote records (its
199
+ * first, or the first after a record of that digest that was not promote: an owner's replay that promoted a held
200
+ * revision), or undefined when none was ever promoted. Its `at` names that promotion: an audit row keeps the one serving
201
+ * when its evidence began (learn/audit.ts promoted_at), and the hold rule counts only the rows of the one serving now,
202
+ * so a digest its owner's replay promotes again after a hold starts on no rows. */
203
+ export declare function promotionStartOf(records: readonly PromotionRecord[], workflow: string, digest: string): PromotionRecord | undefined;
204
+ /** The revision of `workflow` other than `digest` whose newest record still says replaying, newest first: at most one (one
205
+ * check at a time, the reservation's guarded write). */
206
+ export declare function replayingOf(records: readonly PromotionRecord[], workflow: string, digest: string | null): PromotionRecord[];
195
207
  /** What each learned workflow with a record serves, by name: `digest`, its champion's (championOf; null: none serves,
196
- * the agent takes its runs), and `replaying`, the revision other than it whose replay is at work (null: none; a queued
197
- * one is not at work yet). What the promotions list says beside the records
198
- * (GET /agents/{id}/learning/promotions). */
208
+ * the agent takes its runs), and `replaying`, the revision other than it whose check is at work (null: none). What the
209
+ * promotions list says beside the records (GET /agents/{id}/learning/promotions). */
199
210
  export declare function servingOf(records: readonly PromotionRecord[]): {
200
211
  workflow: string;
201
212
  digest: string | null;
@@ -204,8 +215,8 @@ export declare function servingOf(records: readonly PromotionRecord[]): {
204
215
  /** The promotions list as it leaves (GET /agents/{id}/learning/promotions): the records and what serves (servingOf), every
205
216
  * text in them cut by `shown` (learning.ts secretsShown, as the other learning reads cut theirs), at any depth and under
206
217
  * any field, so a field added later is cut too: a workflow's name whole (`shown.name`), any other text of its part
207
- * (`shown.text`: a reason, a refit guard's label, a digest, a run id). Numbers and the rest as they are. A replaying
208
- * record's `launch` (a run launch: its notes, model and plane) never leaves: aggregates only. */
218
+ * (`shown.text`: a reason, a digest, a run id). Numbers and the rest as they are. A replaying record's `launch` (a run
219
+ * launch: its notes, model and plane) never leaves: aggregates only. */
209
220
  export declare function promotionsShown(records: readonly PromotionRecord[], shown: {
210
221
  readonly text: (text: string) => string;
211
222
  readonly name: (name: string) => string;
@@ -213,106 +224,37 @@ export declare function promotionsShown(records: readonly PromotionRecord[], sho
213
224
  promotions: PromotionRecord[];
214
225
  serving: ReturnType<typeof servingOf>;
215
226
  };
216
- /** What a guarded promotion write did:`won`, whether this write kept its record (else `still` did not hold when it
227
+ /** What a guarded promotion write did: `won`, whether this write kept its record (else `still` did not hold when it
217
228
  * wrote: another claim's decision came first); `record`, the newest record of its workflow at its digest after (the one
218
- * written when won, else the one there, undefined when none). A claim acts on a decision (starts replay runs, refits,
219
- * cancels) only when it won the write: the loser reads the winner's record, never its turn to act. */
229
+ * written when won, else the one there, undefined when none). A claim acts on a decision (starts replay runs, cancels)
230
+ * only when it won the write: the loser reads the winner's record, never its turn to act. */
220
231
  export type Recorded = {
221
232
  readonly record: PromotionRecord | undefined;
222
233
  readonly won: boolean;
223
234
  };
224
235
  /** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
225
- * and of every record kept (`items`: a check across revisions, one challenger at a time, in the same guarded write): so
226
- * of two claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). `also`:
227
- * records kept after it in the same write, all or none (a queue change and the skips it makes, runner/promotion.ts). */
228
- export declare function recordPromotion(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, record: PromotionRecord, still: (now: PromotionRecord | undefined, items: readonly PromotionRecord[]) => boolean, also?: readonly PromotionRecord[]): Promise<Recorded>;
236
+ * and of every record kept (`items`: a check across revisions, one at a time, in the same guarded write): so of two
237
+ * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). */
238
+ export declare function recordPromotion(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, record: PromotionRecord, still: (now: PromotionRecord | undefined, items: readonly PromotionRecord[]) => boolean): Promise<Recorded>;
229
239
  /** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
230
- * before, whatever was dropped. championOf reads two things, and the trim keeps both: the place of every digest it can
231
- * still see promoted (a promote record kept keeps its win, winsOf, beside it, so an older revision's late graded check
232
- * never reads as a newer promotion), and the digest promoted last, its latest win and its newest record (so a held last
233
- * revision is never trimmed into handing the champion back). The kept records are a run of the newest plus those wins,
234
- * and a win's own run reaches no further back than it: a record that ended an older run of the same digest is newer
235
- * than every record of that run, so a run is never joined to an older one by the trim. The queue's state is kept too,
236
- * whatever its age: a replaying revision's newest record (what its settle, its runs' claims and the one-replay-at-a-time
237
- * check read: dropped, a newer revision would start a second replay while its runs run, and its verdict would never
238
- * land) and a queued one's (what replays next). Neither is a promote record, so championOf reads the same. */
240
+ * before, whatever was dropped: championOf reads the digest promoted last and its newest record, so the trim keeps both
241
+ * (a held last revision is never trimmed into handing the champion back), and a replaying revision's newest record (what
242
+ * its settle, its runs' claims and the one-check-at-a-time rule read: dropped, a newer revision would start a second
243
+ * check while its runs run, and its verdict would never land). The rest is the newest records. */
239
244
  export declare function trimPromotions(items: readonly PromotionRecord[]): PromotionRecord[];
240
- /** One replayed input: the graded run it replays (`of`), its recorded answer, its grade and the path it took (whose
241
- * answer it is: agentRight), and what the workflow
242
- * did on it: answered alone (`answer`), handed back (it escalated: an escalate node or a guard), or failed (a step failed,
243
- * on a credential or tool the replay lacked among them, or its output off its schema; no workflow, a stale digest, a run
244
- * that did not end completed); with its guard rows, read record-only (recordOnly) so each step's p is known. A failed
245
- * row is no evidence either way (learn/refit.ts refitRowsOf leaves it out): the replay ran without what the run it replays had. A
246
- * skipped one (`skipped_write`) is none either: its workflow stopped at a write the graded run's recording does not have,
247
- * which a replay never runs (learn/replay-calls.ts), the one named in `skipped`. */
248
- export interface ReplayRow {
249
- readonly of: string;
250
- readonly recorded: {
251
- readonly answer: string | null;
252
- readonly correct: boolean;
253
- readonly path: RunPath;
254
- readonly expected?: Readonly<Record<string, unknown>>;
255
- };
256
- readonly outcome: ReplayOutcome;
257
- readonly skipped?: Skipped;
258
- readonly answer: string | null;
259
- readonly guards: readonly GuardRow[];
260
- }
261
- /** How many of a replay's own runs ended each way (a run not ended past its deadline is failed): what each run did,
262
- * never the serving thresholds' reading of it (a run that answered below its guard's threshold is answered here, handed
263
- * back in its score). A replay record keeps them as it was decided on. */
245
+ /** How many of a replay's own runs ended each way (a run not ended past its deadline is failed): what each run did. A
246
+ * check record keeps them as it was decided on. */
264
247
  export type ReplayOutcomes = Readonly<Record<ReplayOutcome, number>>;
265
248
  /** Whether two answers say the same: equal as JSON values, else as trimmed text. */
266
249
  export declare const sameAnswer: (a: string | null, b: string | null) => boolean;
267
- /** Whether the workflow's `answer` to a graded input is right by its grade: with the grade's expected fields, when its JSON
268
- * holds each of them (or, one field expected, when the answer is that field's value: a workflow whose output is one
269
- * field answers with its text, or its JSON text when it is no text, learned-workflow.ts learnedOutput). Else, graded
270
- * right, when it says what the graded run said. Graded wrong: on a run a learned workflow answered alone (`workflow`),
271
- * when it says anything else (the bar on a wrong grade is the grade: saying what was graded wrong again is never a tie),
272
- * and wrong when what it said could not be read (nothing says it differs); on a run the agent answered, wrong whatever it
273
- * says (another answer proves nothing: a neutral tie with the agent's, agentRight). */
274
- export declare function answerCorrect(answer: string | null, recorded: ReplayRow["recorded"]): boolean;
275
- /** Whether the agent's answer to a replayed input is right, the agent's side of a replay's score: the graded run's grade
276
- * when the answer graded is the agent's (path `agent`, or `handed_back`: the agent finished it). On a run a learned
277
- * workflow answered alone (`workflow`) the store holds no answer of the agent's on that input, so a right grade is the
278
- * agent's too and a wrong one counts the agent right: the grade's expected answer is the agent's when it gave one, and
279
- * with none the agent is the default. So a revision held on runs it served wrong never ties its own wrong answers; it
280
- * serves again only by answering them right (answerCorrect) or handing them back. */
281
- export declare const agentRight: (recorded: ReplayRow["recorded"]) => boolean;
282
- /** The thresholds a workflow's guards serve at, by step label (the guard rows' `node`): every step of the workflow
283
- * with a `guard` and a `label` (walkGuards). A label names one step: a learned draft that repeats one never runs
284
- * (skills.ts draftProblems, repeatedLabels), so no two steps' rows share a threshold here or in a refit. */
285
- export declare function thresholdsOf(workflowText: string): Map<string, number>;
286
- /** Each node of a workflow document with a guard, by its label as the DSL names its step when it runs, in document order:
287
- * a step of a child workflow (a `workflow` node's `workflow`) as `parent/child`, as the DSL prefixes its events and its
288
- * guard rows (scopeDepsToChild), so a nested guard's serving threshold and its refit read the rows it made. Only the
289
- * workflow's node positions (workflow-nodes.ts): a call's args or a schema shaped like `{label, guard}` is data, never
290
- * a guard, so a replay or a refit never changes it. */
291
- export declare function walkGuards(doc: unknown, visit: (label: string, guard: Record<string, unknown>, node: Record<string, unknown>) => void): void;
292
- /** The threshold a soft escalate's row (GuardRow signal `escalate`) is read at: its p is 0 when it fired, else 1, so it
293
- * hands back at its serving setting exactly when it fired. */
294
- export declare const SOFT_ESCALATE_THRESHOLD = 0.5;
295
- /** The threshold a replay's guards read at: the least the DSL takes (a threshold is in (0, 1), exclusive), so a guard
296
- * hands back only when p is null (a signal it reads is missing) or 0. */
297
- export declare const RECORD_ONLY_THRESHOLD = 1e-9;
298
- /** A workflow's text with every guard's threshold at RECORD_ONLY_THRESHOLD: each guard still reads its signals and
299
- * records its row. What a replay runs, so every step's p is known for the refit and the serving thresholds are applied
300
- * after (learn/refit.ts scoreRows). The text unchanged when it has no guard. */
301
- export declare function recordOnly(workflowText: string): string;
302
- /** Whether a score clears the bar: the workflow's accuracy at most PROMOTE_BAR under the agent path's, and it answered
303
- * alone on at least one input (one that hands back every input scores the agent's own accuracy, and would never serve). */
304
- export declare const clears: (score: Pick<ReplayScore, "delta" | "n" | "handed_back">) => boolean;
305
- /** Whether a score's workflow is at most PROMOTE_BAR under the agent: clears' bar, and what a replay of a held revision
306
- * meets on the runs it was held on alone (runner/promotion.ts settle), where a hand-back on each is fine. */
307
- export declare const withinBar: (score: Pick<ReplayScore, "delta">) => boolean;
308
250
  /** A grade as the API answers it (PUT /runs/{id}/grade; GET /runs/{id}/learning's `graded`, without `expected`). */
309
251
  export declare const gradeView: (grade: Grade) => {
310
252
  source: "feedback" | "eval";
311
253
  graded_at: string;
312
- path: "agent" | "workflow" | "handed_back" | "replay";
254
+ path: "agent" | "workflow" | "handed_back" | "replay" | "audit";
313
255
  workflow: string | null;
314
256
  workflow_digest: string | null;
315
- feedback: "revise" | "look_back" | null;
257
+ feedback: "look_back" | null;
316
258
  expected?: Readonly<Record<string, unknown>> | undefined;
317
259
  run_id: string;
318
260
  correct: boolean;