@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.52

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 (135) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +94 -13
  3. package/dist/adapters.js +1 -1
  4. package/dist/agent-delete.d.ts +13 -2
  5. package/dist/agent-delete.js +14 -5
  6. package/dist/agents-store.d.ts +5 -1
  7. package/dist/agents-store.js +10 -4
  8. package/dist/api-only.d.ts +4 -2
  9. package/dist/api-only.js +5 -3
  10. package/dist/archil-routes.d.ts +1 -0
  11. package/dist/archil-routes.js +28 -2
  12. package/dist/computer-setting.d.ts +8 -0
  13. package/dist/computer-setting.js +11 -0
  14. package/dist/computers.d.ts +6 -2
  15. package/dist/computers.js +2 -2
  16. package/dist/console/assets/index-B-D0EM3j.js +733 -0
  17. package/dist/console/assets/index-DlQepP2J.css +1 -0
  18. package/dist/console/index.html +2 -2
  19. package/dist/fal-price.d.ts +76 -0
  20. package/dist/fal-price.js +368 -0
  21. package/dist/learn/commit.d.ts +5 -0
  22. package/dist/learn/commit.js +4 -1
  23. package/dist/learn/compile.d.ts +13 -5
  24. package/dist/learn/compile.js +24 -7
  25. package/dist/learn/delete.d.ts +12 -6
  26. package/dist/learn/delete.js +17 -11
  27. package/dist/learn/folder.d.ts +11 -0
  28. package/dist/learn/folder.js +20 -3
  29. package/dist/learn/learning-of.d.ts +8 -0
  30. package/dist/learn/learning-of.js +8 -0
  31. package/dist/learn/learning.sh +14 -1
  32. package/dist/learn/promote.d.ts +51 -7
  33. package/dist/learn/promote.js +51 -8
  34. package/dist/learning-reset.d.ts +18 -0
  35. package/dist/learning-reset.js +115 -0
  36. package/dist/learning-routes.d.ts +1 -1
  37. package/dist/learning-words.d.ts +5 -0
  38. package/dist/learning-words.js +5 -0
  39. package/dist/learning.d.ts +8 -6
  40. package/dist/learning.js +5 -4
  41. package/dist/llms.txt +1 -0
  42. package/dist/mcp-gateway.d.ts +39 -2
  43. package/dist/mcp-gateway.js +41 -10
  44. package/dist/mcp-pin-first.js +1 -1
  45. package/dist/mcp-servers-store.d.ts +1 -0
  46. package/dist/mcp-servers-store.js +2 -1
  47. package/dist/media-duration.d.ts +2 -0
  48. package/dist/media-duration.js +136 -0
  49. package/dist/openapi.js +45 -12
  50. package/dist/provider.d.ts +8 -0
  51. package/dist/provider.js +14 -2
  52. package/dist/refusal-words.d.ts +0 -3
  53. package/dist/refusal-words.js +0 -3
  54. package/dist/request-metadata.d.ts +20 -0
  55. package/dist/request-metadata.js +24 -0
  56. package/dist/run-launch.d.ts +13 -4
  57. package/dist/run-launch.js +14 -3
  58. package/dist/run-learning-served.d.ts +2 -2
  59. package/dist/run-usage.d.ts +48 -4
  60. package/dist/run-usage.js +156 -39
  61. package/dist/run-view.d.ts +1 -1
  62. package/dist/run-view.js +3 -7
  63. package/dist/runner/adapter-loop.d.ts +3 -1
  64. package/dist/runner/adapter-loop.js +12 -9
  65. package/dist/runner/adapter-run-spec.d.ts +1 -1
  66. package/dist/runner/adapter-run-spec.js +13 -13
  67. package/dist/runner/audit.d.ts +8 -3
  68. package/dist/runner/audit.js +21 -6
  69. package/dist/runner/claim-secrets.d.ts +2 -1
  70. package/dist/runner/claim-secrets.js +5 -3
  71. package/dist/runner/cli-run-spec.d.ts +1 -1
  72. package/dist/runner/cli-run-spec.js +12 -11
  73. package/dist/runner/conformance/harness.js +4 -2
  74. package/dist/runner/dispatch.js +4 -2
  75. package/dist/runner/harness-loops.js +5 -2
  76. package/dist/runner/journal-kinds.d.ts +3 -0
  77. package/dist/runner/learning-end.d.ts +2 -1
  78. package/dist/runner/learning-end.js +47 -22
  79. package/dist/runner/mcp-claim.js +1 -1
  80. package/dist/runner/mcp-run.d.ts +9 -0
  81. package/dist/runner/mcp-run.js +16 -1
  82. package/dist/runner/model-route.js +7 -4
  83. package/dist/runner/promotion.d.ts +40 -21
  84. package/dist/runner/promotion.js +130 -59
  85. package/dist/runner/run-child-host.js +6 -4
  86. package/dist/runner/runner.js +15 -3
  87. package/dist/runner/sdk-loop.d.ts +2 -2
  88. package/dist/runner/sdk-loop.js +3 -3
  89. package/dist/runner/store-port.d.ts +3 -0
  90. package/dist/runner/workflow-spec.js +3 -3
  91. package/dist/runs-over-store.d.ts +5 -2
  92. package/dist/runs-over-store.js +14 -7
  93. package/dist/sdk/check.d.ts +6 -5
  94. package/dist/sdk/check.js +17 -16
  95. package/dist/sdk/runs.js +81 -65
  96. package/dist/server.js +84 -20
  97. package/dist/store/agent-body.d.ts +4 -0
  98. package/dist/store/agent-body.js +4 -1
  99. package/dist/store/index.d.ts +1 -1
  100. package/dist/store/journal/storage.d.ts +2 -0
  101. package/dist/store/journal/storage.js +2 -1
  102. package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
  103. package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
  104. package/dist/store/schema.d.ts +14 -1
  105. package/dist/store/schema.js +42 -4
  106. package/dist/store/sqlite/run-launch.d.ts +22 -0
  107. package/dist/store/sqlite/run-launch.js +72 -7
  108. package/dist/store/sqlite/run-patch.d.ts +2 -1
  109. package/dist/store/sqlite/run-patch.js +4 -3
  110. package/dist/store/sqlite/store.js +141 -29
  111. package/dist/store/store-schema.js +2 -2
  112. package/dist/store/store.d.ts +67 -4
  113. package/dist/store-reads/learning.d.ts +12 -8
  114. package/dist/store-reads/learning.js +33 -24
  115. package/dist/store-reads/loop.d.ts +4 -3
  116. package/dist/store-reads/loop.js +7 -5
  117. package/dist/template-eval.js +4 -4
  118. package/dist/templates.d.ts +3 -0
  119. package/dist/templates.js +7 -5
  120. package/dist/timeline/labels.js +1 -1
  121. package/dist/tools.js +1 -1
  122. package/dist/uploads-archil.js +2 -1
  123. package/dist/uploads.d.ts +0 -3
  124. package/dist/uploads.js +2 -11
  125. package/dist/validate.js +5 -1
  126. package/dist/web-save.d.ts +3 -0
  127. package/dist/web-save.js +17 -2
  128. package/dist/workspace/archil-exec.js +1 -1
  129. package/dist/workspace/archil.js +1 -1
  130. package/dist/workspace/revision-skills.js +24 -11
  131. package/dist/workspace/synced-folder.d.ts +3 -3
  132. package/dist/workspace/synced-folder.js +7 -6
  133. package/package.json +10 -10
  134. package/dist/console/assets/index-Bt1B51b7.js +0 -733
  135. package/dist/console/assets/index-sVftE9Ht.css +0 -1
@@ -629,7 +629,7 @@ export async function commitChange(ws, base, change) {
629
629
  checkPath(path);
630
630
  for (const path of [...(change?.deletes ?? []), ...(change?.absent ?? []), ...(change?.same ?? []).map(({ path }) => path)])
631
631
  checkPath(path);
632
- for (const { commit } of change?.same ?? [])
632
+ for (const commit of [...(change?.same ?? []).map(({ commit }) => commit), ...(change?.seed !== undefined ? [change.seed] : [])])
633
633
  if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(commit))
634
634
  throw new Error(`${JSON.stringify(commit)} is not a commit`);
635
635
  const ref = `refs/agentrun/import-${randomBytes(8).toString("hex")}`;
@@ -640,6 +640,7 @@ export async function commitChange(ws, base, change) {
640
640
  ...(run ? changed.map((path) => `path ${path}`) : []),
641
641
  ...(change?.absent ?? []).map((path) => `absent ${path}`),
642
642
  ...(change?.same ?? []).map(({ commit, path }) => `same ${commit} ${path}`),
643
+ ...(change?.seed !== undefined ? [`seed ${change.seed}`] : []),
643
644
  ];
644
645
  const stream = importStream(ref, base?.main, writes, change?.deletes ?? [], messageOf(change?.by).message, seconds);
645
646
  const args = base ? ["commit", base.main, ...(run ? [run] : [])] : ["init"];
@@ -654,7 +655,8 @@ export async function commitChange(ws, base, change) {
654
655
  return { stale: true, main: said || undefined };
655
656
  if (result.code === 4) {
656
657
  const lines = said.split("\n");
657
- return { refused: { absent: lines.filter((line) => line.startsWith("absent ")).map((line) => line.slice(7)), same: lines.filter((line) => line.startsWith("same ")).map((line) => line.slice(5)) } };
658
+ const seed = lines.find((line) => line.startsWith("seed "))?.slice(5);
659
+ return { refused: { absent: lines.filter((line) => line.startsWith("absent ")).map((line) => line.slice(7)), same: lines.filter((line) => line.startsWith("same ")).map((line) => line.slice(5)), ...(seed !== undefined ? { seed } : {}) } };
658
660
  }
659
661
  if (result.code === 5 && /^[0-9a-f]{40,64}$/.test(said))
660
662
  return { unaligned: true, main: said };
@@ -716,6 +718,18 @@ export async function textsAt(ws, commit, paths) {
716
718
  }
717
719
  return out;
718
720
  }
721
+ /** Whether the folder holds `commit`: one read-only exec of the script's show with no path, which reads nothing but
722
+ * that. False once a reset of the agent's learning removed it (or the folder is not a repository). */
723
+ export async function holdsCommit(ws, commit) {
724
+ if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(commit))
725
+ throw new Error(`${JSON.stringify(commit)} is not a commit`);
726
+ const result = await runScript(ws, ["show", commit]);
727
+ if (result.code === 1)
728
+ return false;
729
+ if (result.code !== 0)
730
+ throw failed("show", result);
731
+ return true;
732
+ }
719
733
  export async function learningRepair(ws) {
720
734
  for (let tries = 0; tries < WRITE_TRIES; tries++) {
721
735
  const read = await runScript(ws, ["read"]);
@@ -758,11 +772,14 @@ export async function learningInit(ws) {
758
772
  export class FolderRefused extends Error {
759
773
  absent;
760
774
  same;
775
+ /** A run's merge whose seed (FolderChange.seed) the folder no longer holds: its agent's learning was reset. */
776
+ seed;
761
777
  constructor(refused) {
762
- super(`the learning folder's main refused the write: ${[...refused.absent.map((path) => `${path} is there`), ...refused.same.map((path) => `${path} changed`)].join(", ")}`);
778
+ super(`the learning folder's main refused the write: ${[...(refused.seed !== undefined ? [`the run's seed ${refused.seed} is not in the folder`] : []), ...refused.absent.map((path) => `${path} is there`), ...refused.same.map((path) => `${path} changed`)].join(", ")}`);
763
779
  this.name = "FolderRefused";
764
780
  this.absent = refused.absent;
765
781
  this.same = refused.same;
782
+ this.seed = refused.seed;
766
783
  }
767
784
  }
768
785
  /** A run's merge (its round) that is on main already, made by another call (a reclaimed run racing its first claim, or
@@ -0,0 +1,8 @@
1
+ import type { RunLaunch } from "../run-launch.js";
2
+ import type { Store } from "../store/store.js";
3
+ /** The disk a run's launch names as its own: the launch's `archilDisk` of kind "launch", by its id; null for none or its
4
+ * agent's own (the default disk). The store keeps the same on the run's row (RunRow.disk). */
5
+ export declare const learningDiskOf: (launch: Pick<RunLaunch, "archilDisk">) => string | null;
6
+ /** Each named disk a run of agent `agentId` used (Store.runs.every: its built-in learning runs and purged runs included,
7
+ * a purged run's tombstone keeping its disk): where a learning folder of the agent may be, past the server's own. */
8
+ export declare function namedDisksOf(store: Pick<Store, "runs">, agentId: string): Promise<string[]>;
@@ -0,0 +1,8 @@
1
+ /** The disk a run's launch names as its own: the launch's `archilDisk` of kind "launch", by its id; null for none or its
2
+ * agent's own (the default disk). The store keeps the same on the run's row (RunRow.disk). */
3
+ export const learningDiskOf = (launch) => launch.archilDisk?.kind === "launch" ? launch.archilDisk.diskId : null;
4
+ /** Each named disk a run of agent `agentId` used (Store.runs.every: its built-in learning runs and purged runs included,
5
+ * a purged run's tombstone keeping its disk): where a learning folder of the agent may be, past the server's own. */
6
+ export async function namedDisksOf(store, agentId) {
7
+ return [...new Set((await store.runs.every(agentId)).map((run) => run.disk).filter((disk) => disk !== null))];
8
+ }
@@ -32,7 +32,11 @@
32
32
  # snapshot <json> snapshot.json, one line, where a \001M\001 stands for the new main
33
33
  # path <path> (a merge) a path its diff covers
34
34
  # absent <path> <path> must not be on <old>, any mode, any type (else 4: "absent <path>" on stdout)
35
- # same <commit> <path> <path> must be the same on <commit> as on <old> (else 4: "same <path>" on stdout)
35
+ # same <commit> <path> <path> must be the same on <commit> as on <old> (else 4: "same <path>" on stdout); a
36
+ # <commit> the repository does not hold fails it (the folder was reset since it was read)
37
+ # seed <commit> (a run's merge) the commit the run was seeded from, which the repository held as its end began
38
+ # and must hold still (else 4: "seed <commit>" on stdout): a reset since merges nothing, a
39
+ # correction alone included
36
40
  # Exit: 0 done (the new main on stdout), 3 stale (main as it is on stdout), 4 a precondition failed, 5 main moved but
37
41
  # the files could not be brought in line (the new main on stdout; no snapshot written), 6 the run merged already (its
38
42
  # merge on stdout), else git's error on stderr.
@@ -187,10 +191,19 @@ preconditions() {
187
191
  done < "$tmp/absent"
188
192
  sed -n 's/^same //p' "$tmp/head" > "$tmp/same"
189
193
  while read -r c p; do
194
+ # A commit this repository does not hold (the agent's learning reset after the run read it) is no ground to merge on.
195
+ if ! g cat-file -e "$c^{commit}" 2>/dev/null; then
196
+ printf 'same %s\n' "$p" >> "$tmp/failed"
197
+ continue
198
+ fi
190
199
  a=$(g rev-parse -q --verify "$c:$p" 2>/dev/null || true)
191
200
  b=$(g rev-parse -q --verify "$old:$p" 2>/dev/null || true)
192
201
  [ "$a" = "$b" ] || printf 'same %s\n' "$p" >> "$tmp/failed"
193
202
  done < "$tmp/same"
203
+ sed -n 's/^seed //p' "$tmp/head" > "$tmp/seed"
204
+ while read -r c; do
205
+ g cat-file -e "$c^{commit}" 2>/dev/null || printf 'seed %s\n' "$c" >> "$tmp/failed"
206
+ done < "$tmp/seed"
194
207
  if [ -s "$tmp/failed" ]; then
195
208
  cat "$tmp/failed"
196
209
  exit 4
@@ -80,9 +80,10 @@ export interface PromotionRecord {
80
80
  /** The learning commit whose workflows/<workflow>/workflow.json is this digest's text: the seed of the claim that
81
81
  * recorded it. What the digest serves from as the champion (championOf) once a newer revision is on the folder's main. */
82
82
  readonly commit?: string;
83
- /** `sdk`: a connected (SDK) agent's check (runner/promotion.ts reserveSdkCheck), on its reservation and the record that
84
- * decides it. Its one run (`runs`) is the agent's own native turn, not a replay run; a replaying one with no `runs`
85
- * waits for the next native turn the draft takes. Absent: a server replay's. */
83
+ /** `sdk`: a connected (SDK) agent's check (runner/promotion.ts reserveSdkCheck), on each reservation and the record that
84
+ * decides it. Its one run (`runs`) is the agent's native turn reserved now, not a replay run; a replaying one with no
85
+ * `runs` waits for the next native turn the draft takes. It collects its checked turns (`check.turns`) and decides once
86
+ * it holds compile_after of them, as a managed check decides once on its inputs. Absent: a server replay's. */
86
87
  readonly via?: "sdk";
87
88
  }
88
89
  /** One audit row a hold was decided on that disagreed: the served run (`served`) and its input, the run whose answer is
@@ -146,17 +147,34 @@ export type CheckRecord = CheckBar & {
146
147
  readonly skipped_tools?: readonly SkippedTool[];
147
148
  readonly disagreements?: readonly CheckDisagreement[];
148
149
  readonly stopped?: true;
149
- /** A connected agent's check: how many of its reserved native turns gave no answer to check the draft against (a
150
- * cancelled or refused turn, a subagent, redacted evidence, no shadow report) and were given back to wait for the
151
- * next one (runner/promotion.ts SDK_CHECK_RELEASES stops it). Absent: none. */
150
+ /** A connected agent's check: how many of its reserved native turns in a row gave no answer to check the draft against
151
+ * (a refused turn, a subagent, redacted evidence, no shadow report; never a cancel) and were given back to wait for
152
+ * the next one (runner/promotion.ts SDK_CHECK_RELEASES holds it for the next compile). Absent: none. */
152
153
  readonly released?: number;
153
154
  /** A connected agent's check: how many fresh read-only calls its shadow made where the native turn's recording had
154
155
  * no result (the client's opt-in shadowReadFallback). Absent: none, every call was answered from the recording. */
155
156
  readonly fresh_reads?: number;
157
+ /** A connected agent's check still collecting native turns (runner/promotion.ts sdkCheckTurn): the turns checked so
158
+ * far, until it holds compile_after of them and decides once on them all. Absent once decided on them, and on a
159
+ * managed check; a check stopped or set aside before it held them keeps the turns it had. */
160
+ readonly turns?: CheckTurns;
156
161
  /** How it compared with no agree_on: the fast model that read the answers (its name), when it was asked on any input.
157
162
  * With agree_on, the paths compared (CheckBar.agree_on); with neither, the whole answer. */
158
163
  readonly grader?: string;
159
164
  };
165
+ /** A connected agent's checked native turns before its check decides, counted as a decided check counts its inputs:
166
+ * `n` turns, `agreed` and `alone` of them, the agent's runs (`of`, newest first), one outcome per turn (a turn past its
167
+ * deadline failed), each turn it did not agree on, and the shadows' fresh reads. Each is compared on its own turn, its
168
+ * texts cut as a decided check's are. */
169
+ export interface CheckTurns {
170
+ readonly n: number;
171
+ readonly agreed: number;
172
+ readonly alone: number;
173
+ readonly of: readonly string[];
174
+ readonly outcomes: ReplayOutcomes;
175
+ readonly disagreements?: readonly CheckDisagreement[];
176
+ readonly fresh_reads?: number;
177
+ }
160
178
  /** The most characters of an input or an answer a check's disagreement keeps. */
161
179
  export declare const CHECK_TEXT_MAX = 1200;
162
180
  /** A check's two shares: `agreement`, of the inputs the draft answered alone those that say what the agent said (0 when
@@ -196,6 +214,30 @@ export declare function skippedToolsOf(rows: readonly {
196
214
  }[]): SkippedTool[];
197
215
  export declare const gradesKey: (agentId: string) => string;
198
216
  export declare const promotionsKey: (agentId: string) => string;
217
+ /** A learned workflow revision an agent's learning reset deleted (DELETE /agents/{id}/learning, learning-reset.ts): its
218
+ * workflow, its digest and its K (its check's compile_after; null when its records named none), nothing else of its
219
+ * records. What the runs it served carry of its compile and check (store-reads/learning.ts revisionLedgerOf) is read
220
+ * from it after the reset, so a kept run's cost reads as before. The runs keep the same names and digests. */
221
+ export interface ResetRevision {
222
+ readonly workflow: string;
223
+ readonly digest: string;
224
+ readonly k: number | null;
225
+ }
226
+ export declare const resetLedgerKey: (agentId: string) => string;
227
+ /** The revisions the agent's resets deleted, first reset first. */
228
+ export declare const resetLedgerOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<ResetRevision[]>;
229
+ /** Each revision `records` name (one per workflow and digest, its newest record's K) added to the agent's reset ledger,
230
+ * before a reset deletes the records. A revision it holds already keeps its place and takes the records' K: while they
231
+ * stood, the ledger read their K (revisionLedgerOf), so the runs' shares read the same after this reset too. */
232
+ export declare function keepResetLedger(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, records: readonly PromotionRecord[]): Promise<void>;
233
+ /** The agent's reset watermark: when its newest reset began (epoch ms). Learning reads only the runs after it
234
+ * (learn/compile.ts sinceReset): a run that started, or read its learning seed, at or before it learns nothing and is
235
+ * read by no compile, check, audit or money rule. Kept with the reset ledger, and removed with it by the agent's delete (learn/delete.ts). */
236
+ export declare const resetAtKey: (agentId: string) => string;
237
+ /** The agent's reset watermark (resetAtKey), or undefined when its learning was never reset. */
238
+ export declare const resetAtOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<number | undefined>;
239
+ /** Agent `agentId`'s reset watermark set to `at`, in place of an earlier reset's. */
240
+ export declare const keepResetAt: (settings: Pick<Settings, "put">, agentId: string, at: number) => Promise<void>;
199
241
  /** The agent's grades, oldest first. */
200
242
  export declare const gradesOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<Grade[]>;
201
243
  /** Keeps `grade`, in place of any earlier grade of the same run, the newest GRADES_KEPT kept, at the next `seq`. */
@@ -276,7 +318,9 @@ export type Recorded = {
276
318
  };
277
319
  /** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
278
320
  * and of every record kept (`items`: a check across revisions, one at a time, in the same guarded write): so of two
279
- * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). */
321
+ * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). What the one
322
+ * there now has blanked is blanked in `record` too (forgetRunIn): a record built on a copy read before a run's purge
323
+ * (a connected agent's next turn, release or decision carries its turns on) never writes that run's text back. */
280
324
  export declare function recordPromotion(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, record: PromotionRecord, still: (now: PromotionRecord | undefined, items: readonly PromotionRecord[]) => boolean): Promise<Recorded>;
281
325
  /** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
282
326
  * before, whatever was dropped: championOf reads the digest promoted last and its newest record, so the trim keeps both
@@ -7,6 +7,7 @@
7
7
  // its workflows' promotion records), over the settings table; the orchestration is runner/promotion.ts. Grades are what
8
8
  // a person or an eval said of a run (PUT /runs/{id}/grade).
9
9
  import { createHash } from "node:crypto";
10
+ import { isDeepStrictEqual } from "node:util";
10
11
  import { answerJson } from "../answer-json.js";
11
12
  import { pathSegments } from "../learning-setting.js";
12
13
  import { isObject } from "../validate.js";
@@ -61,6 +62,35 @@ async function updateKept(settings, key, update) {
61
62
  }
62
63
  throw new Error(`${key} kept changing under this write; try again`);
63
64
  }
65
+ export const resetLedgerKey = (agentId) => `learning.reset-ledger.${agentId}`;
66
+ /** The revisions the agent's resets deleted, first reset first. */
67
+ export const resetLedgerOf = async (settings, agentId) => itemsOf(await settings.get(resetLedgerKey(agentId)));
68
+ /** Each revision `records` name (one per workflow and digest, its newest record's K) added to the agent's reset ledger,
69
+ * before a reset deletes the records. A revision it holds already keeps its place and takes the records' K: while they
70
+ * stood, the ledger read their K (revisionLedgerOf), so the runs' shares read the same after this reset too. */
71
+ export async function keepResetLedger(settings, agentId, records) {
72
+ const newest = new Map();
73
+ for (const record of records)
74
+ newest.set(`${record.workflow}\0${record.digest}`, { workflow: record.workflow, digest: record.digest, k: record.check?.compile_after ?? null });
75
+ if (!newest.size)
76
+ return;
77
+ await updateKept(settings, resetLedgerKey(agentId), (items) => {
78
+ const held = new Set(items.map((one) => `${one.workflow}\0${one.digest}`));
79
+ return [...items.map((one) => newest.get(`${one.workflow}\0${one.digest}`) ?? one), ...[...newest].filter(([key]) => !held.has(key)).map(([, one]) => one)];
80
+ });
81
+ }
82
+ /** The agent's reset watermark: when its newest reset began (epoch ms). Learning reads only the runs after it
83
+ * (learn/compile.ts sinceReset): a run that started, or read its learning seed, at or before it learns nothing and is
84
+ * read by no compile, check, audit or money rule. Kept with the reset ledger, and removed with it by the agent's delete (learn/delete.ts). */
85
+ export const resetAtKey = (agentId) => `learning.reset-at.${agentId}`;
86
+ /** The agent's reset watermark (resetAtKey), or undefined when its learning was never reset. */
87
+ export const resetAtOf = async (settings, agentId) => {
88
+ const read = await settings.get(resetAtKey(agentId));
89
+ const at = typeof read === "object" && read !== null ? read.at : undefined;
90
+ return typeof at === "number" && Number.isFinite(at) ? at : undefined;
91
+ };
92
+ /** Agent `agentId`'s reset watermark set to `at`, in place of an earlier reset's. */
93
+ export const keepResetAt = (settings, agentId, at) => settings.put(resetAtKey(agentId), { at });
64
94
  /** The agent's grades, oldest first. */
65
95
  export const gradesOf = async (settings, agentId) => itemsOf(await settings.get(gradesKey(agentId)));
66
96
  /** Keeps `grade`, in place of any earlier grade of the same run, the newest GRADES_KEPT kept, at the next `seq`. */
@@ -88,24 +118,31 @@ const blankCheck = (one) => ({
88
118
  });
89
119
  /** An audit's disagreement blanked the same way: its run ids and whether a grade wrote it kept. */
90
120
  const blankAudit = (one) => ({ run: one.run, served: one.served, input: "", agent: null, draft: null, ...(one.graded ? { graded: true } : {}) });
91
- /** `record` with what it copied from run `runId` blanked: each disagreement naming it (a check's agent run; an audit's
92
- * served run or shadow run), and the grader's words its reason quotes from one (differentDecisionWords' example). Its
93
- * decision, numbers and run ids stay. The record itself when it names no such disagreement. */
121
+ /** `record` with what it copied from run `runId` blanked: each disagreement naming it (a check's agent run, a connected
122
+ * agent's collected turn too; an audit's served run or shadow run), and the grader's words its reason quotes from one
123
+ * (differentDecisionWords' example). Its decision, numbers and run ids stay. The record itself when it names no such
124
+ * disagreement. */
94
125
  function forgetRunIn(record, runId) {
95
126
  if (!record || typeof record !== "object")
96
127
  return record;
97
128
  const check = record.check?.disagreements?.some((one) => one.run === runId);
129
+ const turns = record.check?.turns?.disagreements?.some((one) => one.run === runId);
98
130
  const audit = record.audit?.disagreements.some((one) => one.run === runId || one.served === runId);
99
- if (!check && !audit)
131
+ if (!check && !turns && !audit)
100
132
  return record;
101
133
  let reason = record.reason;
102
134
  for (const one of record.check?.disagreements ?? [])
103
135
  if (one.run === runId && one.differs_on !== undefined)
104
136
  reason = reason.replace(` (for example: ${one.differs_on})`, "");
137
+ const blanked = (list) => list.map((one) => (one.run === runId ? blankCheck(one) : one));
105
138
  return {
106
139
  ...record,
107
140
  reason,
108
- ...(check && record.check ? { check: { ...record.check, disagreements: record.check.disagreements.map((one) => (one.run === runId ? blankCheck(one) : one)) } } : {}),
141
+ ...((check || turns) && record.check ? { check: {
142
+ ...record.check,
143
+ ...(check ? { disagreements: blanked(record.check.disagreements) } : {}),
144
+ ...(turns ? { turns: { ...record.check.turns, disagreements: blanked(record.check.turns.disagreements) } } : {}),
145
+ } } : {}),
109
146
  ...(audit && record.audit ? { audit: { ...record.audit, disagreements: record.audit.disagreements.map((one) => (one.run === runId || one.served === runId ? blankAudit(one) : one)) } } : {}),
110
147
  };
111
148
  }
@@ -214,9 +251,14 @@ export function shownDeep(value, shown, key) {
214
251
  : value !== null && typeof value === "object" ? Object.fromEntries(Object.entries(value).map(([field, one]) => [field, shownDeep(one, shown, field)]))
215
252
  : value;
216
253
  }
254
+ /** The runs whose copies `record`'s check has blanked (forgetRunIn): each disagreement, decided or of a turn collected,
255
+ * left as blankCheck leaves it. */
256
+ const blankedRuns = (record) => [...(record?.check?.disagreements ?? []), ...(record?.check?.turns?.disagreements ?? [])].filter((one) => isDeepStrictEqual(one, blankCheck(one))).map((one) => one.run);
217
257
  /** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
218
258
  * and of every record kept (`items`: a check across revisions, one at a time, in the same guarded write): so of two
219
- * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). */
259
+ * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). What the one
260
+ * there now has blanked is blanked in `record` too (forgetRunIn): a record built on a copy read before a run's purge
261
+ * (a connected agent's next turn, release or decision carries its turns on) never writes that run's text back. */
220
262
  export async function recordPromotion(settings, agentId, record, still) {
221
263
  let out = { record, won: true };
222
264
  await updateKept(settings, promotionsKey(agentId), (saved) => {
@@ -226,8 +268,9 @@ export async function recordPromotion(settings, agentId, record, still) {
226
268
  out = { record: now, won: false };
227
269
  return items;
228
270
  }
229
- out = { record, won: true };
230
- return trimPromotions([...items, record]);
271
+ const kept = blankedRuns(now).reduce(forgetRunIn, record);
272
+ out = { record: kept, won: true };
273
+ return trimPromotions([...items, kept]);
231
274
  });
232
275
  return out;
233
276
  }
@@ -0,0 +1,18 @@
1
+ import type { DeleteLearning } from "./agent-delete.js";
2
+ import { type Store } from "./store/index.js";
3
+ /** What a reset does outside the learning module, as the server does it. */
4
+ export interface LearningResetHost {
5
+ readonly store: Store;
6
+ readonly deleteLearning: DeleteLearning;
7
+ /** The cancel path, for one run that is not final: true once a cancel stands for it, false when this server cannot
8
+ * end it (agent-delete.ts AgentDeleteHost.cancel). */
9
+ cancel(runId: string): Promise<boolean>;
10
+ /** `work` in agent `agentId`'s learning queue (learning.ts withAgentRepo). */
11
+ inQueue<T>(agentId: string, work: () => Promise<T>): Promise<T>;
12
+ /** How long step 1 waits for the agent's learning runs to be final, and how often it reads them meanwhile. */
13
+ readonly waitMs: number;
14
+ readonly pollMs: number;
15
+ }
16
+ /** Agent `agentId`'s learning reset in the two steps above. Throws ApiError learning_busy, nothing of its learning
17
+ * deleted, while a run of the agent's own is going or its learning runs cannot be stopped in time. */
18
+ export declare function resetLearning(host: LearningResetHost, agentId: string): Promise<void>;
@@ -0,0 +1,115 @@
1
+ // DELETE /v2/agents/{agent_id}/learning: an agent's learning reset, the agent kept. What it learned goes (the learning
2
+ // module's deleteLearning: its learning folder's files, its git history and audit ledger among them, on this server and
3
+ // on every Archil disk its runs used, learn/learning-of.ts namedDisksOf, then its promotions and grades); the agent, its
4
+ // definition, its runs and everything kept of them (their files, journals, costs, the learning each one kept) stay, so
5
+ // the run list, the stats and the usage read the same before and after. A served run's cost carries its share of its
6
+ // revision's compile and check, read from the promotion records the reset deletes: each revision they name is kept
7
+ // first in the agent's reset ledger (learn/promote.ts keepResetLedger: workflow, digest and K alone), so the share reads
8
+ // the same after.
9
+ //
10
+ // What goes with the folder: each run's learning diff (GET /runs/{id}/learning/diff, the text it merged) is the folder's,
11
+ // so it is 404 after; what the run's own record keeps of its learning end stays with the run.
12
+ //
13
+ // In order, in the agent's delete turn (server.ts agentWrite: one learning write of an agent at a time, and none once
14
+ // its DELETE began):
15
+ // 1. The agent's learning work in flight is stopped. A run that exists only for its learning (a check's or an owner's
16
+ // replay, an audit's shadow, a built-in learning run) is cancelled through the cancel path and waited for until it
17
+ // is final. A run of the agent's own still going is not: its learning lives in it (the seed it was started from,
18
+ // a workflow it may be served, its compile turn and look-back at its end), and the owner's job is never cancelled
19
+ // to reset learning. Any such run, or a learning run this server cannot end (an SDK run, an imported one) or one
20
+ // not final by the wait's end, is 409 learning_busy, naming them, and the agent's learning is left as it was.
21
+ // 2. In the agent's learning queue (learning.ts withAgentRepo, where a run's start reads its seed and a person's edit
22
+ // commits), the agent's runs are read again: one still going (a run started meanwhile) is 409 learning_busy, nothing
23
+ // deleted. Then deleteLearning, which reads them once more itself.
24
+ // Idempotent: an agent that never learned, or one reset already, has nothing to delete, and is answered as done.
25
+ //
26
+ // Step 2 sets the agent's reset watermark (learn/promote.ts resetAtKey) before it deletes: from then on learning reads
27
+ // only runs after it (learn/compile.ts sinceReset: compile_after's count, a compile's traces, a check's inputs, an
28
+ // audit's draws, the money rule). A run whose start read the learning folder before step 2
29
+ // and whose row the store wrote after it keeps what it was started with (its corrections are in its launch), but
30
+ // learns nothing: its seed was read before the watermark, so its learning end drops it whole at its entry
31
+ // (runner/learning-end.ts, reason `reset`), and the learning script refuses a merge on a seed the folder no longer holds
32
+ // (learning.sh `seed`). No workflow is laid for it either: they are read at its seed's commit, which is gone.
33
+ import { ApiError } from "./errors.js";
34
+ import { LearningInFlight } from "./learn/delete.js";
35
+ import { isShadowRun } from "./learn/audit.js";
36
+ import { keepResetAt, keepResetLedger, promotionsOf, resetAtKey, resetAtOf } from "./learn/promote.js";
37
+ import { readLaunchBody } from "./run-launch.js";
38
+ import { FINAL_STATES, StoreLaunchMissing } from "./store/index.js";
39
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
40
+ const isFinal = (state) => FINAL_STATES.includes(state);
41
+ /** Whether run `runId` exists only for its agent's learning: an audit's shadow, a replay (a check's or an owner's), or a
42
+ * built-in learning run, by its launch. A run with no launch read here is the agent's own. */
43
+ async function learningOnly(store, runId) {
44
+ if (isShadowRun(runId))
45
+ return true;
46
+ const launch = await store.runs.launch(runId).then((row) => readLaunchBody(row.body), (error) => (error instanceof StoreLaunchMissing ? undefined : Promise.reject(error)));
47
+ return launch !== undefined && (launch.replay !== undefined || launch.audit !== undefined || launch.harness === "learning");
48
+ }
49
+ /** The agent's runs not final, its built-in learning runs included, each with whether it exists only for learning. */
50
+ async function goingOf(store, agentId) {
51
+ const going = (await store.runs.every(agentId)).filter((run) => !isFinal(run.state));
52
+ return Promise.all(going.map(async (run) => ({ id: run.id, learning: await learningOnly(store, run.id) })));
53
+ }
54
+ const busy = (agentId, runs, why, retryMs = 5_000) => new ApiError("learning_busy", `The agent ${agentId}'s learning was not reset: ${why} (${runs.slice(0, 5).join(", ")}${runs.length > 5 ? ` and ${runs.length - 5} more` : ""}). Nothing of its learning was deleted: send the DELETE again once ${runs.length === 1 ? "it has" : "they have"} ended.`, { details: { runs: [...runs] }, retry_after_ms: retryMs });
55
+ const OWN = (n) => (n === 1 ? "a run of its own is still going, and its learning lives in it" : `${n} runs of its own are still going, and their learning lives in them`);
56
+ /** Agent `agentId`'s learning reset in the two steps above. Throws ApiError learning_busy, nothing of its learning
57
+ * deleted, while a run of the agent's own is going or its learning runs cannot be stopped in time. */
58
+ export async function resetLearning(host, agentId) {
59
+ // 1. Its own runs refuse the reset before anything is cancelled; its learning runs are cancelled and waited for.
60
+ const going = await goingOf(host.store, agentId);
61
+ const own = going.filter((run) => !run.learning).map((run) => run.id);
62
+ if (own.length)
63
+ throw busy(agentId, own, OWN(own.length));
64
+ await stopLearningRuns(host, agentId, going.map((run) => run.id));
65
+ // 2. In the agent's learning queue: nothing going (a run started meanwhile refuses it), then its learning deleted.
66
+ await host.inQueue(agentId, async () => {
67
+ const still = await goingOf(host.store, agentId);
68
+ if (still.length)
69
+ throw busy(agentId, still.map((run) => run.id), still.some((run) => !run.learning) ? OWN(still.filter((run) => !run.learning).length) : "its learning work started again");
70
+ // What the agent's kept runs carry of their revisions' compile and check, kept before the records it is read from go.
71
+ await keepResetLedger(host.store.settings, agentId, await promotionsOf(host.store.settings, agentId));
72
+ // The watermark, before anything goes: learning reads no run that started, or read its seed, at or before it (each
73
+ // seed is read in this queue, so one read before this moment never holds a later time). A seed read after the reset
74
+ // in the same millisecond counts as before it: its run learns nothing (reason reset) and an SDK start is refused, to
75
+ // start again, never a run given what the reset deleted. Set first, so no moment has the folder gone and the old runs
76
+ // still read. A delete refused before it removed anything (LearningInFlight) puts the earlier one back, its learning
77
+ // left as it was; one that failed on the way (a disk, a file, a record) may have removed some of it, so the watermark
78
+ // stays and the next call finishes the reset: the old runs never feed a compile into a folder emptied part way.
79
+ const earlier = await resetAtOf(host.store.settings, agentId);
80
+ const at = Date.now();
81
+ await keepResetAt(host.store.settings, agentId, at);
82
+ try {
83
+ await host.deleteLearning(host.store, agentId, { keepResetLedger: true, agentDisk: true });
84
+ }
85
+ catch (error) {
86
+ if (!(error instanceof LearningInFlight))
87
+ throw error;
88
+ await (earlier === undefined ? host.store.settings.remove(resetAtKey(agentId)) : keepResetAt(host.store.settings, agentId, earlier));
89
+ throw busy(agentId, error.runs, "its learning work is in flight");
90
+ }
91
+ });
92
+ }
93
+ /** Step 1's second half: each learning run cancelled once, then read again until each is final. One this server cannot
94
+ * end, or one still going at the wait's end, is learning_busy. */
95
+ async function stopLearningRuns(host, agentId, runs) {
96
+ if (!runs.length)
97
+ return;
98
+ const unended = [];
99
+ for (const runId of runs)
100
+ if (!(await host.cancel(runId)))
101
+ unended.push(runId);
102
+ if (unended.length)
103
+ throw busy(agentId, unended, `its learning work is in ${unended.length === 1 ? "a run" : "runs"} this server cannot end`);
104
+ const deadline = Date.now() + host.waitMs;
105
+ for (;;) {
106
+ const states = new Map((await host.store.runs.every(agentId)).map((run) => [run.id, run.state]));
107
+ // A run no longer there is ended.
108
+ const live = runs.filter((runId) => !isFinal(states.get(runId) ?? "ended"));
109
+ if (!live.length)
110
+ return;
111
+ if (Date.now() >= deadline)
112
+ throw busy(agentId, live, `its learning work was cancelled and ${live.length === 1 ? "one run has" : `${live.length} runs have`} not ended yet`, 2_000);
113
+ await sleep(host.pollMs);
114
+ }
115
+ }
@@ -190,7 +190,7 @@ export declare function runLearningBody(input: {
190
190
  }, shown: Shown, secrets: readonly string[]): {
191
191
  run: string;
192
192
  state: "dropped" | "merged" | "seeded" | "reflecting";
193
- reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
193
+ reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
194
194
  detail: string | null;
195
195
  at: string;
196
196
  workflows: import("./learning.js").LearnedFile[];
@@ -23,7 +23,10 @@ export declare const STOPPED: {
23
23
  readonly unanswered: "the turn that writes its workflow ended before it answered";
24
24
  readonly notChecked: "what it learned could not be checked";
25
25
  readonly refuseUnread: "what the run must never learn (its agent's browser sign-in, the server's secrets) could not be read back, so nothing it learned is kept";
26
+ readonly otherDisk: "the run is on a disk its start named, and a run there learns nothing yet: it started without what the agent learned, and what it does is not learned";
26
27
  };
28
+ /** Why a run whose start has no seed started with nothing learned (run-launch.ts SeedFailed), in words. */
29
+ export declare const seedStopped: (failed: string | undefined) => string;
27
30
  /** A run's learning, in words, by where it stands. */
28
31
  export declare const said: {
29
32
  seeded: (corrections: number, workflows?: number) => string;
@@ -52,6 +55,8 @@ export declare const said: {
52
55
  noBudget: string;
53
56
  unknownCost: string;
54
57
  stopped: (cause: string) => string;
58
+ /** A run whose learning seed predates a reset of its agent's learning (runner/learning-end.ts, reason `reset`). */
59
+ reset: string;
55
60
  };
56
61
  /** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, said again
57
62
  * from its parts (`workflows`, `corrections`, `problems`), each name cut by `cut` first (the host's secrets as they are
@@ -61,7 +61,10 @@ export const STOPPED = {
61
61
  unanswered: "the turn that writes its workflow ended before it answered",
62
62
  notChecked: "what it learned could not be checked",
63
63
  refuseUnread: "what the run must never learn (its agent's browser sign-in, the server's secrets) could not be read back, so nothing it learned is kept",
64
+ otherDisk: "the run is on a disk its start named, and a run there learns nothing yet: it started without what the agent learned, and what it does is not learned",
64
65
  };
66
+ /** Why a run whose start has no seed started with nothing learned (run-launch.ts SeedFailed), in words. */
67
+ export const seedStopped = (failed) => failed === "unreadable" ? STOPPED.unreadable : failed === "not_copied" ? STOPPED.notCopied : failed === "other_disk" ? STOPPED.otherDisk : STOPPED.noSeed;
65
68
  /** A run's learning, in words, by where it stands. */
66
69
  export const said = {
67
70
  seeded: (corrections, workflows = 0) => {
@@ -108,6 +111,8 @@ export const said = {
108
111
  noBudget: "Skipped: no budget left in this run to write what it learned.",
109
112
  unknownCost: "Skipped: this run's spend is unknown, so its budget can't cover writing what it learned.",
110
113
  stopped: (cause) => `Not kept: learning stopped (${cause}).`,
114
+ /** A run whose learning seed predates a reset of its agent's learning (runner/learning-end.ts, reason `reset`). */
115
+ reset: "Dropped: its learning seed predates a reset of the agent's learning.",
111
116
  };
112
117
  /** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, said again
113
118
  * from its parts (`workflows`, `corrections`, `problems`), each name cut by `cut` first (the host's secrets as they are
@@ -14,7 +14,7 @@ export declare function learningOf(env: NodeJS.ProcessEnv, given?: string): Lear
14
14
  * is on main, or `dropped` with a reason from the closed list. A learning fault never refuses a run: it starts with
15
15
  * nothing learned, `seed_failed`. */
16
16
  export declare const LEARNING_STATES: readonly ["seeded", "reflecting", "merged", "dropped"];
17
- export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use"];
17
+ export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use", "reset"];
18
18
  /** A run's own `learning` on its start (POST /agents/{agent_id}/runs): it starts from what its agent learned, as a run that
19
19
  * learns does, and keeps nothing (no compile, no correction, at any end), so runs of one agent read one learned state
20
20
  * however many run at once. Its learning ends `dropped`, reason `use`. */
@@ -111,7 +111,7 @@ export declare const detailShown: (learning: Learning, shown: Shown, max?: numbe
111
111
  export declare const learningView: (learning: Learning, shown: Shown) => {
112
112
  workflows?: LearnedFile[];
113
113
  state: "dropped" | "merged" | "seeded" | "reflecting";
114
- reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
114
+ reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
115
115
  detail: string | null;
116
116
  at: string;
117
117
  };
@@ -126,7 +126,7 @@ export declare function shortOf<T extends {
126
126
  at: string;
127
127
  }>({ state, reason, detail, at: _, ...rest }: T): {
128
128
  state: "dropped" | "merged" | "seeded" | "reflecting";
129
- reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
129
+ reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
130
130
  detail: string | null;
131
131
  } & Omit<T, "at" | "reason" | "state" | "detail">;
132
132
  /** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
@@ -138,11 +138,13 @@ export type Triggered = {
138
138
  text: string;
139
139
  };
140
140
  /** What a run is seeded from: main's commit (null when the folder has none yet), corrections.md's text ("" when none),
141
- * and its active learned workflows, by name. */
141
+ * and its active learned workflows, by name. `at`: when a run's seed was read (seedOf, epoch ms, in the agent's
142
+ * learning queue), which the agent's reset watermark is set in too: a seed read at or before it predates the reset. */
142
143
  export type Seed = {
143
144
  sha: string | null;
144
145
  corrections: string;
145
146
  workflows: LearnedWorkflow[];
147
+ at?: number;
146
148
  };
147
149
  /** A workflow the agent learned, as a run may run it: its name, the line its README says what it does with, and its
148
150
  * workflow.json whole. */
@@ -170,8 +172,8 @@ export declare const withAgentRepo: <T>(data: string, agentId: string, work: ()
170
172
  * under `data`. The one point that names the place; its `end()` is called in a finally after every use. */
171
173
  export declare const learningFolderOf: (data: string, agentId: string) => LearningFolder;
172
174
  /** The seed of a run of agent `agentId` about to be made: main's commit, the folder made first when it is absent (the
173
- * learning script's init), and what main holds for a run (seedIn). In the agent's queue. No git in this process: the
174
- * folder's own script and file API. */
175
+ * learning script's init), what main holds for a run (seedIn), and when it was read (`at`). In the agent's queue, as a
176
+ * reset is (learning-reset.ts). No git in this process: the folder's own script and file API. */
175
177
  export declare function seedOf(data: string, agentId: string): Promise<Seed>;
176
178
  /** What commit `commit` of the folder holds for a run, as seedOf reads main (one read-only exec of the script). No commit
177
179
  * (null) is the empty seed; a commit the folder no longer holds throws. */
package/dist/learning.js CHANGED
@@ -35,7 +35,7 @@ export function learningOf(env, given) {
35
35
  * is on main, or `dropped` with a reason from the closed list. A learning fault never refuses a run: it starts with
36
36
  * nothing learned, `seed_failed`. */
37
37
  export const LEARNING_STATES = ["seeded", "reflecting", "merged", "dropped"];
38
- export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use"];
38
+ export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_failed", "empty", "checker", "use", "reset"];
39
39
  /** A run's own `learning` on its start (POST /agents/{agent_id}/runs): it starts from what its agent learned, as a run that
40
40
  * learns does, and keeps nothing (no compile, no correction, at any end), so runs of one agent read one learned state
41
41
  * however many run at once. Its learning ends `dropped`, reason `use`. */
@@ -189,14 +189,15 @@ async function seedIn(sha, snapshot, text) {
189
189
  return { sha, corrections, workflows };
190
190
  }
191
191
  /** The seed of a run of agent `agentId` about to be made: main's commit, the folder made first when it is absent (the
192
- * learning script's init), and what main holds for a run (seedIn). In the agent's queue. No git in this process: the
193
- * folder's own script and file API. */
192
+ * learning script's init), what main holds for a run (seedIn), and when it was read (`at`). In the agent's queue, as a
193
+ * reset is (learning-reset.ts). No git in this process: the folder's own script and file API. */
194
194
  export function seedOf(data, agentId) {
195
195
  return withAgentRepo(data, agentId, async () => {
196
196
  const { workspace, end } = learningFolderOf(data, agentId);
197
197
  try {
198
198
  await learningInit(workspace);
199
- return await readLearning(workspace, async ({ snapshot, body }) => seedIn(snapshot?.main ?? null, snapshot, body));
199
+ const seed = await readLearning(workspace, async ({ snapshot, body }) => seedIn(snapshot?.main ?? null, snapshot, body));
200
+ return { ...seed, at: Date.now() };
200
201
  }
201
202
  finally {
202
203
  await end();
package/dist/llms.txt CHANGED
@@ -20,6 +20,7 @@ Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/he
20
20
  - `POST /v2/files?path=notes.md` with the file's bytes as the body (`curl --data-binary @notes.md`) uploads a file, answered `201` with the file, ready, its `file_id` under `file`. Name it in a run's `file_ids`, and the run finds it at `inputs/notes.md`. `GET /v2/files` lists the uploads, `DELETE /v2/files/{id}` removes one.
21
21
  - `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends). A run its learned workflow answered alone (`path` `workflow`), or ran first and handed back (`handed_back`), carries `workflow` (`name`, `digest`, and `repick`: `found` when its answer re-picked after a quote miss and found its quotes, `missed` when the re-pick missed too, else null), on the read and on every `GET /v2/runs` row; null on any other run.
22
22
  - An agent that learns: a run its learned workflow served (`path` `workflow`) has the workflow's answer as `result.final_answer`; one handed back (`handed_back`) has the agent's. Its timeline is its `user_message`, the learned_workflow `tool_use` and `tool_result` (its nodes in `learned_nodes`; they write no `decision` rows), then `final_answer` and `usage`; a hand-back puts a `phase` row and the agent's own rows before them. Learning spends on the agent's own model route, key and cap: on `GET /v2/runs/{id}`, `cost.usd` is the run's own spend, the job's; `cost.learning_usd` what learning spent for it (its audit's shadow run and its share of its workflow revision's compile turn and check, spread over the revision's first `compile_after` served runs; a compile that kept no draft is on no run, in the bill's `unattributed_usd`), `cost.all_in_usd` both. A shadow run is in no run list and sends no webhook. `GET /v2/agents/{id}/learning/cost` has the agent's whole bill (`bill`).
23
+ - `DELETE /v2/agents/{id}/learning` resets what the agent learned (its corrections, learned workflows, their history, promotions and grades), on this server and on every Archil disk its runs used, keeping the agent and its runs: `204`, again on a second call; `409 learning_busy` (the runs in `details.runs`) while a run of its own is still going, nothing deleted; `503` while a disk that holds it can't be reached. Learning then reads only the runs after the reset (`compile_after` counts from it); a run that read the agent's learning before it learns nothing (`learning.reason` `reset`).
23
24
  - `GET /v2/runs/{id}/timeline?after=0&limit=100` pages its steps; follow `next_after` until a page is `final` with `has_more` false.
24
25
  - `GET /v2/runs/{id}/files`, then `GET /v2/runs/{id}/files/{path}`: what it wrote.
25
26
  - `POST /v2/runs/{id}/messages` with `{content}` answers a run that asked a question (`input_required`), or follows up; `POST /v2/runs/{id}/cancel` ends one.