@parcha/agentrun-serve 0.1.0-beta.42 → 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 (81) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +8 -7
  3. package/dist/console/assets/index-BrcDSBD8.css +1 -0
  4. package/dist/console/assets/{index-DYJ_wj27.js → index-Bz6IWncl.js} +186 -186
  5. package/dist/console/index.html +2 -2
  6. package/dist/decisions.js +0 -4
  7. package/dist/import-sources.js +25 -5
  8. package/dist/learn/audit.d.ts +123 -0
  9. package/dist/learn/audit.js +159 -0
  10. package/dist/learn/compile.d.ts +50 -74
  11. package/dist/learn/compile.js +90 -124
  12. package/dist/learn/folder.d.ts +9 -0
  13. package/dist/learn/folder.js +13 -2
  14. package/dist/learn/promote.d.ts +86 -200
  15. package/dist/learn/promote.js +57 -183
  16. package/dist/learn/replay-calls.d.ts +5 -0
  17. package/dist/learn/replay-calls.js +12 -1
  18. package/dist/learn/secrets.d.ts +8 -0
  19. package/dist/learn/secrets.js +12 -0
  20. package/dist/learn/skills.js +2 -4
  21. package/dist/learn/workflow-nodes.d.ts +1 -2
  22. package/dist/learn/workflow-nodes.js +2 -3
  23. package/dist/learned-nodes.d.ts +9 -34
  24. package/dist/learned-nodes.js +11 -23
  25. package/dist/learned-workflow.d.ts +6 -8
  26. package/dist/learned-workflow.js +18 -57
  27. package/dist/learning-batch.d.ts +13 -5
  28. package/dist/learning-batch.js +34 -8
  29. package/dist/learning-cost.d.ts +11 -4
  30. package/dist/learning-cost.js +4 -2
  31. package/dist/learning-routes.js +1 -1
  32. package/dist/learning-setting.d.ts +16 -1
  33. package/dist/learning-setting.js +34 -2
  34. package/dist/openapi.js +95 -55
  35. package/dist/run-launch.d.ts +6 -3
  36. package/dist/run-launch.js +2 -0
  37. package/dist/run-learning-served.d.ts +1 -1
  38. package/dist/runner/adapter-loop.d.ts +4 -0
  39. package/dist/runner/adapter-loop.js +17 -2
  40. package/dist/runner/adapter-run-spec.js +16 -5
  41. package/dist/runner/audit.d.ts +64 -0
  42. package/dist/runner/audit.js +338 -0
  43. package/dist/runner/beside.js +1 -1
  44. package/dist/runner/cli-run-spec.js +15 -5
  45. package/dist/runner/feedback-round.js +1 -4
  46. package/dist/runner/harness-loops.js +1 -15
  47. package/dist/runner/journal-kinds.d.ts +0 -7
  48. package/dist/runner/journal-kinds.js +0 -7
  49. package/dist/runner/learning-dispatch.d.ts +0 -16
  50. package/dist/runner/learning-dispatch.js +4 -47
  51. package/dist/runner/learning-end.d.ts +52 -13
  52. package/dist/runner/learning-end.js +124 -44
  53. package/dist/runner/learning-factory.d.ts +1 -1
  54. package/dist/runner/learning-factory.js +1 -4
  55. package/dist/runner/learning-loop.d.ts +2 -38
  56. package/dist/runner/learning-loop.js +8 -116
  57. package/dist/runner/main.js +1 -1
  58. package/dist/runner/promotion.d.ts +50 -54
  59. package/dist/runner/promotion.js +191 -583
  60. package/dist/runner/reflect-hook.d.ts +10 -0
  61. package/dist/runner/reflect-hook.js +6 -0
  62. package/dist/runner/workflow-first.d.ts +6 -5
  63. package/dist/runner/workflow-first.js +17 -12
  64. package/dist/server.js +61 -16
  65. package/dist/store/sqlite/store.js +1 -0
  66. package/dist/store/store.d.ts +3 -0
  67. package/dist/store-reads/learning.d.ts +17 -6
  68. package/dist/store-reads/learning.js +36 -23
  69. package/dist/store-reads/loop.d.ts +4 -39
  70. package/dist/store-reads/loop.js +10 -79
  71. package/dist/store-view.js +12 -2
  72. package/dist/workspace/run-tools.d.ts +1 -1
  73. package/dist/workspace/run-tools.js +14 -3
  74. package/package.json +9 -9
  75. package/dist/console/assets/index-C3gNPz58.css +0 -1
  76. package/dist/learn/general.d.ts +0 -69
  77. package/dist/learn/general.js +0 -75
  78. package/dist/learn/refit.d.ts +0 -48
  79. package/dist/learn/refit.js +0 -264
  80. package/dist/runner/step-guard.d.ts +0 -62
  81. package/dist/runner/step-guard.js +0 -93
@@ -1,17 +1,8 @@
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;
@@ -20,8 +11,8 @@ 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,47 +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: "check" | "replay" | "dry_run" | "refit" | "graded";
60
+ readonly decided: "promote" | "hold" | "replaying";
90
61
  readonly reason: string;
91
- /** A compiled draft's one check (source `check`, runner/promotion.ts): its bar while it replays, its numbers once
92
- * decided. */
62
+ /** A compiled draft's one check (runner/promotion.ts): its bar while it replays, its numbers once decided. */
93
63
  readonly check?: CheckRecord;
94
- readonly replay?: ReplayScore & {
95
- readonly of: readonly string[];
96
- readonly cost_usd?: number | null;
97
- readonly skipped_tools?: readonly SkippedTool[];
98
- readonly outcomes?: ReplayOutcomes;
99
- };
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;
100
67
  readonly runs?: readonly string[];
101
- /** A replaying record's graded runs, one per `runs` entry in order: the input each reserved replay run replays, so a
102
- * 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). */
103
70
  readonly inputs?: readonly string[];
104
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
105
72
  * decides it: what GET .../replays/{replay_id} reads. */
@@ -110,31 +77,32 @@ export interface PromotionRecord {
110
77
  * credentials run `handed_from` was handed (a claim's claimed run), else none (an owner's replay). One replay runs on
111
78
  * one set of settings. Never in the promotions read (promotionsShown). */
112
79
  readonly launch?: ReplayLaunch;
113
- readonly refit?: {
114
- readonly from: string;
115
- readonly guards: readonly RefitGuard[];
116
- };
117
- readonly checked?: number;
118
- /** A promote record's start (a replay's promote): the agent's newest grade's seq when it was written, which names this
119
- * promotion of the digest: a run it serves keeps it (metrics.workflow_promotion, then Grade.promotion), and its checks
120
- * count only the grades of those runs, never a run served under an earlier promotion and graded after this one, nor
121
- * the ones it was held on. Two promotions of a digest never share it: one is promoted again only after a graded hold,
122
- * which counts runs served (and graded, each at a newer seq) under the one before. Its checks' writes are kept only
123
- * while it is still the digest's promotion (the same since), so a check that read an older promotion writes nothing.
124
- * Absent: the digest's first record (a dry run's or a refit's promote), whose runs keep none. */
125
- readonly since?: number;
126
- /** The runs a revision served that were graded wrong when its graded check held it (newest first, at most REPLAY_INPUTS),
127
- * kept on that hold, on the replay of it its owner starts (those of them still graded and fitting it, each one of its
128
- * inputs), and on a replay's hold: a replay of the revision promotes it only once it answered (or handed back) on every
129
- * one (runner/promotion.ts heldOn). */
130
- readonly held_on?: readonly string[];
131
- /** A skipped revision's newer one: the digest that came while it was queued, and replays in its place. */
132
- readonly skipped_by?: string;
133
80
  /** The learning commit whose workflows/<workflow>/workflow.json is this digest's text: the seed of the claim that
134
- * recorded it, or a refit's own commit. What the digest serves from as the champion (championOf) once a newer revision
135
- * 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. */
136
82
  readonly commit?: string;
137
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
+ }
138
106
  /** The bar a compiled draft's check was started with: the agent definition's loop numbers then (learning-setting.ts), and
139
107
  * which check of the compile it is (`attempt`: 1, the first draft's; 2, the one recompile's, after which it stops). */
140
108
  export interface CheckBar {
@@ -155,10 +123,10 @@ export interface CheckDisagreement {
155
123
  readonly failed?: true;
156
124
  }
157
125
  /** A check's numbers, once decided: `n` inputs it ran on (a skipped write is none), `agreed` of them answered alone with
158
- * the agent's recorded answer (sameAnswer), `alone` answered alone (no escalate, no failed step, no guard under its
159
- * serving threshold); the inputs (`of`, the agent's runs), what its replay runs cost, their outcomes, the tools that
160
- * stopped its skipped inputs, the inputs it did not agree on, and `stopped` when a recompile's check held it too
161
- * (nothing compiles again). */
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). */
162
130
  export type CheckRecord = CheckBar & {
163
131
  readonly n?: number;
164
132
  readonly agreed?: number;
@@ -166,6 +134,7 @@ export type CheckRecord = CheckBar & {
166
134
  readonly of?: readonly string[];
167
135
  readonly cost_usd?: number | null;
168
136
  readonly outcomes?: ReplayOutcomes;
137
+ readonly unstarted?: number;
169
138
  readonly skipped_tools?: readonly SkippedTool[];
170
139
  readonly disagreements?: readonly CheckDisagreement[];
171
140
  readonly stopped?: true;
@@ -203,22 +172,10 @@ export interface SkippedTool {
203
172
  readonly no_read_only_hint: boolean;
204
173
  }
205
174
  /** The tools that stopped `rows`' skipped inputs, most inputs first (then by name). */
206
- export declare function skippedToolsOf(rows: readonly Pick<ReplayRow, "outcome" | "skipped">[]): SkippedTool[];
207
- /** One switch a refit changed: a guard's step, its threshold before and after (`threshold` null: the guard switched off,
208
- * gone from the revision), and its new fit when one was fit; or an escalate node a replay recorded (dsl softEscalates),
209
- * switched off (`escalate`: gone from the revision; `was` and `threshold` null, it had none). */
210
- export interface RefitGuard {
211
- readonly node: string;
212
- readonly was: number | null;
213
- readonly threshold: number | null;
214
- readonly fit?: {
215
- readonly w: readonly number[];
216
- readonly b: number;
217
- readonly n: number;
218
- readonly fitted_at: string;
219
- };
220
- readonly escalate?: true;
221
- }
175
+ export declare function skippedToolsOf(rows: readonly {
176
+ readonly outcome: ReplayOutcome;
177
+ readonly skipped?: Skipped;
178
+ }[]): SkippedTool[];
222
179
  export declare const gradesKey: (agentId: string) => string;
223
180
  export declare const promotionsKey: (agentId: string) => string;
224
181
  /** The agent's grades, oldest first. */
@@ -226,32 +183,30 @@ export declare const gradesOf: (settings: Pick<Settings, "get">, agentId: string
226
183
  /** Keeps `grade`, in place of any earlier grade of the same run, the newest GRADES_KEPT kept, at the next `seq`. */
227
184
  export declare const putGrade: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, grade: Grade) => Promise<Grade>;
228
185
  /** Marks the kept grade `grade` (its run, given at its `at`, kept at its `seq`) with the feedback round it opened and
229
- * that round's steer, in place: its `seq` stays, so a serving digest's check never counts it twice. A newer grade of the
230
- * 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. */
231
188
  export declare const markGradeRound: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, grade: Grade, opened: OpenedRound) => Promise<Grade>;
232
- /** The agent's promotion records, oldest first. A beta.39 store may hold `decided: "superseded"` (a replay a newer draft
233
- * cancelled; beta.40 writes `skipped` for an older draft instead): read as `skipped`, `skipped_by` the draft that
234
- * superseded it, with a reason that says when. Only the read maps (readAs, also what a guarded write compares): the stored
235
- * record is never rewritten. */
236
- export declare const readAs: (one: PromotionRecord) => PromotionRecord;
189
+ /** The agent's promotion records, oldest first: only those in a state this code writes (writtenOf). */
237
190
  export declare const promotionsOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<PromotionRecord[]>;
238
191
  /** The newest record of `workflow` at `digest`, or undefined. */
239
192
  export declare const promotionOf: (records: readonly PromotionRecord[], workflow: string, digest: string) => PromotionRecord | undefined;
240
- /** The champion of `workflow`: the newest record of the digest promoted last (a digest's place is its latest win's,
241
- * winsOf), while that digest's newest record still says promote. A newer revision replaying or held never stops it; a
242
- * wrong served grade asks for nothing and never stops it alone; it stops when a newer revision's replay promotes that one
243
- * (then the champion), or its own graded runs hold it (source graded: no champion until a revision is promoted). A held
244
- * revision its owner replays (runner/promotion.ts askReplay) and the replay promotes wins again: the champion from then.
245
- * 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. */
246
197
  export declare function championOf(records: readonly PromotionRecord[], workflow: string): PromotionRecord | undefined;
247
- /** The revisions of `workflow` other than `digest` whose newest record still says `decided` (replaying, else queued),
248
- * newest first: at most one replaying (one replay at a time, the reservation's guarded write), and at most one queued
249
- * once each newer one skips the one queued before it (runner/promotion.ts). */
250
- 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[];
251
207
  /** What each learned workflow with a record serves, by name: `digest`, its champion's (championOf; null: none serves,
252
- * the agent takes its runs), and `replaying`, the revision other than it whose replay is at work (null: none; a queued
253
- * one is not at work yet). What the promotions list says beside the records
254
- * (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). */
255
210
  export declare function servingOf(records: readonly PromotionRecord[]): {
256
211
  workflow: string;
257
212
  digest: string | null;
@@ -260,8 +215,8 @@ export declare function servingOf(records: readonly PromotionRecord[]): {
260
215
  /** The promotions list as it leaves (GET /agents/{id}/learning/promotions): the records and what serves (servingOf), every
261
216
  * text in them cut by `shown` (learning.ts secretsShown, as the other learning reads cut theirs), at any depth and under
262
217
  * any field, so a field added later is cut too: a workflow's name whole (`shown.name`), any other text of its part
263
- * (`shown.text`: a reason, a refit guard's label, a digest, a run id). Numbers and the rest as they are. A replaying
264
- * 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. */
265
220
  export declare function promotionsShown(records: readonly PromotionRecord[], shown: {
266
221
  readonly text: (text: string) => string;
267
222
  readonly name: (name: string) => string;
@@ -269,103 +224,34 @@ export declare function promotionsShown(records: readonly PromotionRecord[], sho
269
224
  promotions: PromotionRecord[];
270
225
  serving: ReturnType<typeof servingOf>;
271
226
  };
272
- /** 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
273
228
  * wrote: another claim's decision came first); `record`, the newest record of its workflow at its digest after (the one
274
- * written when won, else the one there, undefined when none). A claim acts on a decision (starts replay runs, refits,
275
- * 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. */
276
231
  export type Recorded = {
277
232
  readonly record: PromotionRecord | undefined;
278
233
  readonly won: boolean;
279
234
  };
280
235
  /** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
281
- * and of every record kept (`items`: a check across revisions, one challenger at a time, in the same guarded write): so
282
- * of two claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). `also`:
283
- * records kept after it in the same write, all or none (a queue change and the skips it makes, runner/promotion.ts). */
284
- 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>;
285
239
  /** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
286
- * before, whatever was dropped. championOf reads two things, and the trim keeps both: the place of every digest it can
287
- * still see promoted (a promote record kept keeps its win, winsOf, beside it, so an older revision's late graded check
288
- * never reads as a newer promotion), and the digest promoted last, its latest win and its newest record (so a held last
289
- * revision is never trimmed into handing the champion back). The kept records are a run of the newest plus those wins,
290
- * 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
291
- * 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,
292
- * whatever its age: a replaying revision's newest record (what its settle, its runs' claims and the one-replay-at-a-time
293
- * check read: dropped, a newer revision would start a second replay while its runs run, and its verdict would never
294
- * 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. */
295
244
  export declare function trimPromotions(items: readonly PromotionRecord[]): PromotionRecord[];
296
- /** One replayed input: the graded run it replays (`of`), its recorded answer, its grade and the path it took (whose
297
- * answer it is: agentRight), and what the workflow
298
- * did on it: answered alone (`answer`), handed back (it escalated: an escalate node or a guard), or failed (a step failed,
299
- * on a credential or tool the replay lacked among them, or its output off its schema; no workflow, a stale digest, a run
300
- * that did not end completed); with its guard rows, read record-only (recordOnly) so each step's p is known. A failed
301
- * row is no evidence either way (learn/refit.ts refitRowsOf leaves it out): the replay ran without what the run it replays had. A
302
- * skipped one (`skipped_write`) is none either: its workflow stopped at a write the graded run's recording does not have,
303
- * which a replay never runs (learn/replay-calls.ts), the one named in `skipped`. */
304
- export interface ReplayRow {
305
- readonly of: string;
306
- readonly recorded: {
307
- readonly answer: string | null;
308
- readonly correct: boolean;
309
- readonly path: RunPath;
310
- readonly expected?: Readonly<Record<string, unknown>>;
311
- };
312
- readonly outcome: ReplayOutcome;
313
- readonly skipped?: Skipped;
314
- readonly answer: string | null;
315
- readonly guards: readonly GuardRow[];
316
- }
317
- /** How many of a replay's own runs ended each way (a run not ended past its deadline is failed): what each run did,
318
- * never the serving thresholds' reading of it (a run that answered below its guard's threshold is answered here, handed
319
- * 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. */
320
247
  export type ReplayOutcomes = Readonly<Record<ReplayOutcome, number>>;
321
248
  /** Whether two answers say the same: equal as JSON values, else as trimmed text. */
322
249
  export declare const sameAnswer: (a: string | null, b: string | null) => boolean;
323
- /** Whether the workflow's `answer` to a graded input is right by its grade: with the grade's expected fields, when its JSON
324
- * holds each of them (or, one field expected, when the answer is that field's value: a workflow whose output is one
325
- * field answers with its text, or its JSON text when it is no text, learned-workflow.ts learnedOutput). Else, graded
326
- * right, when it says what the graded run said. Graded wrong: on a run a learned workflow answered alone (`workflow`),
327
- * when it says anything else (the bar on a wrong grade is the grade: saying what was graded wrong again is never a tie),
328
- * and wrong when what it said could not be read (nothing says it differs); on a run the agent answered, wrong whatever it
329
- * says (another answer proves nothing: a neutral tie with the agent's, agentRight). */
330
- export declare function answerCorrect(answer: string | null, recorded: ReplayRow["recorded"]): boolean;
331
- /** 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
332
- * when the answer graded is the agent's (path `agent`, or `handed_back`: the agent finished it). On a run a learned
333
- * workflow answered alone (`workflow`) the store holds no answer of the agent's on that input, so a right grade is the
334
- * 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
335
- * with none the agent is the default. So a revision held on runs it served wrong never ties its own wrong answers; it
336
- * serves again only by answering them right (answerCorrect) or handing them back. */
337
- export declare const agentRight: (recorded: ReplayRow["recorded"]) => boolean;
338
- /** The thresholds a workflow's guards serve at, by step label (the guard rows' `node`): every step of the workflow
339
- * with a `guard` and a `label` (walkGuards). A label names one step: a learned draft that repeats one never runs
340
- * (skills.ts draftProblems, repeatedLabels), so no two steps' rows share a threshold here or in a refit. */
341
- export declare function thresholdsOf(workflowText: string): Map<string, number>;
342
- /** Each node of a workflow document with a guard, by its label as the DSL names its step when it runs, in document order:
343
- * a step of a child workflow (a `workflow` node's `workflow`) as `parent/child`, as the DSL prefixes its events and its
344
- * guard rows (scopeDepsToChild), so a nested guard's serving threshold and its refit read the rows it made. Only the
345
- * workflow's node positions (workflow-nodes.ts): a call's args or a schema shaped like `{label, guard}` is data, never
346
- * a guard, so a replay or a refit never changes it. */
347
- export declare function walkGuards(doc: unknown, visit: (label: string, guard: Record<string, unknown>, node: Record<string, unknown>) => void): void;
348
- /** The threshold a soft escalate's row (GuardRow signal `escalate`) is read at: its p is 0 when it fired, else 1, so it
349
- * hands back at its serving setting exactly when it fired. */
350
- export declare const SOFT_ESCALATE_THRESHOLD = 0.5;
351
- /** The threshold a replay's guards read at: the least the DSL takes (a threshold is in (0, 1), exclusive), so a guard
352
- * hands back only when p is null (a signal it reads is missing) or 0. */
353
- export declare const RECORD_ONLY_THRESHOLD = 1e-9;
354
- /** A workflow's text with every guard's threshold at RECORD_ONLY_THRESHOLD: each guard still reads its signals and
355
- * records its row. What a replay runs, so every step's p is known for the refit and the serving thresholds are applied
356
- * after (learn/refit.ts scoreRows). The text unchanged when it has no guard. */
357
- export declare function recordOnly(workflowText: string): string;
358
- /** Whether a score clears the bar: the workflow's accuracy at most PROMOTE_BAR under the agent path's, and it answered
359
- * alone on at least one input (one that hands back every input scores the agent's own accuracy, and would never serve). */
360
- export declare const clears: (score: Pick<ReplayScore, "delta" | "n" | "handed_back">) => boolean;
361
- /** Whether a score's workflow is at most PROMOTE_BAR under the agent: clears' bar, and what a replay of a held revision
362
- * meets on the runs it was held on alone (runner/promotion.ts settle), where a hand-back on each is fine. */
363
- export declare const withinBar: (score: Pick<ReplayScore, "delta">) => boolean;
364
250
  /** A grade as the API answers it (PUT /runs/{id}/grade; GET /runs/{id}/learning's `graded`, without `expected`). */
365
251
  export declare const gradeView: (grade: Grade) => {
366
252
  source: "feedback" | "eval";
367
253
  graded_at: string;
368
- path: "agent" | "workflow" | "handed_back" | "replay";
254
+ path: "agent" | "workflow" | "handed_back" | "replay" | "audit";
369
255
  workflow: string | null;
370
256
  workflow_digest: string | null;
371
257
  feedback: "look_back" | null;