@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.61

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 (250) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +230 -120
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/agent-delete.d.ts +6 -9
  5. package/dist/agent-delete.js +5 -3
  6. package/dist/agent-package.js +11 -1
  7. package/dist/api-only.d.ts +21 -3
  8. package/dist/api-only.js +41 -6
  9. package/dist/archil-routes.d.ts +4 -1
  10. package/dist/archil-routes.js +15 -12
  11. package/dist/archil-settings.d.ts +18 -8
  12. package/dist/archil-settings.js +35 -17
  13. package/dist/browser-person.d.ts +1 -1
  14. package/dist/browser-person.js +1 -1
  15. package/dist/calendar/tools.js +1 -1
  16. package/dist/chatgpt-plan.d.ts +4 -2
  17. package/dist/chatgpt-plan.js +13 -3
  18. package/dist/claude-login-token.d.ts +5 -0
  19. package/dist/claude-login-token.js +8 -0
  20. package/dist/claude-login.d.ts +49 -3
  21. package/dist/claude-login.js +140 -10
  22. package/dist/cli-learning/connections.js +1 -1
  23. package/dist/cli.js +42 -10
  24. package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
  25. package/dist/console/assets/index-BnZV3lvW.js +639 -0
  26. package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
  27. package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.js} +31 -31
  28. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  29. package/dist/console/index.html +3 -3
  30. package/dist/console/share.html +3 -3
  31. package/dist/decisions.d.ts +1 -1
  32. package/dist/decisions.js +2 -2
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +2 -0
  35. package/dist/factory-activity.d.ts +68 -0
  36. package/dist/factory-activity.js +153 -0
  37. package/dist/factory-runs.d.ts +11 -0
  38. package/dist/factory-runs.js +52 -0
  39. package/dist/filed-tool.d.ts +32 -0
  40. package/dist/filed-tool.js +122 -0
  41. package/dist/harness-check.js +2 -1
  42. package/dist/harness-keys.d.ts +1 -2
  43. package/dist/harness-keys.js +1 -2
  44. package/dist/harness-recipe.d.ts +13 -2
  45. package/dist/harness-recipe.js +30 -7
  46. package/dist/harness-sign-in.js +2 -1
  47. package/dist/harness-table.d.ts +9 -3
  48. package/dist/harness-table.js +11 -5
  49. package/dist/harness.js +6 -2
  50. package/dist/import-worker.js +2 -2
  51. package/dist/import.d.ts +9 -0
  52. package/dist/import.js +11 -1
  53. package/dist/key-refusal.d.ts +5 -0
  54. package/dist/key-refusal.js +30 -18
  55. package/dist/learn/audit.d.ts +20 -22
  56. package/dist/learn/audit.js +72 -55
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +35 -43
  59. package/dist/learn/commit.js +62 -270
  60. package/dist/learn/compile.d.ts +4 -4
  61. package/dist/learn/compile.js +6 -7
  62. package/dist/learn/corrections.js +1 -1
  63. package/dist/learn/delete.d.ts +5 -12
  64. package/dist/learn/delete.js +17 -30
  65. package/dist/learn/forget-run.d.ts +16 -0
  66. package/dist/learn/forget-run.js +53 -0
  67. package/dist/learn/index.js +1 -1
  68. package/dist/learn/learning-of.d.ts +0 -4
  69. package/dist/learn/learning-of.js +0 -5
  70. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  71. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  72. package/dist/learn/legacy/place.d.ts +16 -0
  73. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  74. package/dist/learn/legacy/scrub.d.ts +28 -0
  75. package/dist/learn/legacy/scrub.js +258 -0
  76. package/dist/learn/promote.d.ts +40 -66
  77. package/dist/learn/promote.js +69 -207
  78. package/dist/learn/reset-ledger.d.ts +18 -0
  79. package/dist/learn/reset-ledger.js +14 -0
  80. package/dist/learn/rows.d.ts +186 -0
  81. package/dist/learn/rows.js +376 -0
  82. package/dist/learn/secrets.d.ts +2 -1
  83. package/dist/learn/secrets.js +2 -2
  84. package/dist/learn/workflow-draft.d.ts +4 -1
  85. package/dist/learn/workflow-draft.js +12 -2
  86. package/dist/learned-nodes.d.ts +36 -0
  87. package/dist/learned-nodes.js +23 -0
  88. package/dist/learning-reset.d.ts +1 -1
  89. package/dist/learning-reset.js +9 -11
  90. package/dist/learning-routes.d.ts +60 -81
  91. package/dist/learning-routes.js +187 -360
  92. package/dist/learning-words.d.ts +2 -0
  93. package/dist/learning-words.js +2 -0
  94. package/dist/learning.d.ts +18 -24
  95. package/dist/learning.js +35 -66
  96. package/dist/local-model.d.ts +144 -0
  97. package/dist/local-model.js +214 -0
  98. package/dist/mcp-gateway.d.ts +6 -0
  99. package/dist/mcp-gateway.js +44 -8
  100. package/dist/mcp-probe.d.ts +7 -0
  101. package/dist/mcp-probe.js +7 -0
  102. package/dist/mcp-resources.d.ts +1 -1
  103. package/dist/native/discovery.d.ts +6 -0
  104. package/dist/native/discovery.js +14 -1
  105. package/dist/native/remote.d.ts +5 -0
  106. package/dist/native/remote.js +16 -0
  107. package/dist/native/runtime.js +3 -2
  108. package/dist/observation/observer.d.ts +6 -6
  109. package/dist/ollama-provider.d.ts +35 -0
  110. package/dist/ollama-provider.js +108 -2
  111. package/dist/openapi.js +147 -35
  112. package/dist/place-offers.d.ts +3 -0
  113. package/dist/place-offers.js +3 -0
  114. package/dist/place.d.ts +35 -12
  115. package/dist/place.js +67 -29
  116. package/dist/print.js +1 -1
  117. package/dist/purged-workflow.d.ts +0 -33
  118. package/dist/purged-workflow.js +3 -71
  119. package/dist/redact/match.d.ts +36 -8
  120. package/dist/redact/match.js +179 -44
  121. package/dist/run-export.js +4 -2
  122. package/dist/run-launch.d.ts +3 -3
  123. package/dist/run-learning-served.d.ts +3 -3
  124. package/dist/run-learning-served.js +1 -1
  125. package/dist/run-listing.d.ts +1 -1
  126. package/dist/run-timeline-served.d.ts +1 -1
  127. package/dist/run-timeline-served.js +6 -5
  128. package/dist/run-usage.js +3 -2
  129. package/dist/runnable.js +25 -8
  130. package/dist/runner/adapter-loop.d.ts +8 -1
  131. package/dist/runner/adapter-loop.js +100 -20
  132. package/dist/runner/adapter-run-spec.d.ts +3 -5
  133. package/dist/runner/adapter-run-spec.js +35 -61
  134. package/dist/runner/adapters/pi.d.ts +3 -2
  135. package/dist/runner/adapters/pi.js +3 -1
  136. package/dist/runner/audit.d.ts +3 -5
  137. package/dist/runner/audit.js +28 -51
  138. package/dist/runner/cli-run-spec.js +19 -22
  139. package/dist/runner/compare-end.d.ts +1 -3
  140. package/dist/runner/compare-end.js +6 -2
  141. package/dist/runner/disk-free.d.ts +15 -4
  142. package/dist/runner/disk-free.js +25 -7
  143. package/dist/runner/dispatch.js +2 -2
  144. package/dist/runner/feedback-round.d.ts +1 -1
  145. package/dist/runner/feedback-round.js +2 -2
  146. package/dist/runner/harness-loops.d.ts +9 -0
  147. package/dist/runner/harness-loops.js +49 -7
  148. package/dist/runner/held.d.ts +4 -11
  149. package/dist/runner/held.js +0 -25
  150. package/dist/runner/journal-kinds.d.ts +4 -1
  151. package/dist/runner/journal-kinds.js +1 -1
  152. package/dist/runner/learned-first.d.ts +0 -2
  153. package/dist/runner/learned-first.js +3 -3
  154. package/dist/runner/learning-end.d.ts +12 -16
  155. package/dist/runner/learning-end.js +41 -75
  156. package/dist/runner/learning-seed.d.ts +13 -16
  157. package/dist/runner/learning-seed.js +13 -23
  158. package/dist/runner/live-ticker.js +3 -4
  159. package/dist/runner/main.js +1 -1
  160. package/dist/runner/mcp-claim.js +3 -2
  161. package/dist/runner/mcp-run.d.ts +23 -4
  162. package/dist/runner/mcp-run.js +31 -2
  163. package/dist/runner/metrics.d.ts +4 -0
  164. package/dist/runner/metrics.js +9 -3
  165. package/dist/runner/monid-run.js +3 -1
  166. package/dist/runner/native-loop.js +3 -4
  167. package/dist/runner/promotion.d.ts +19 -28
  168. package/dist/runner/promotion.js +50 -69
  169. package/dist/runner/redact.d.ts +3 -0
  170. package/dist/runner/redact.js +7 -0
  171. package/dist/runner/reflect-hook.d.ts +2 -2
  172. package/dist/runner/reflect-hook.js +4 -1
  173. package/dist/runner/run-child-host.d.ts +1 -9
  174. package/dist/runner/run-child-host.js +12 -68
  175. package/dist/runner/runner.d.ts +1 -1
  176. package/dist/runner/sdk-loop.js +7 -7
  177. package/dist/runner/workflow-calls.d.ts +4 -1
  178. package/dist/runner/workflow-calls.js +35 -18
  179. package/dist/runner/workflow-loop.d.ts +1 -1
  180. package/dist/runner/workflow-loop.js +3 -1
  181. package/dist/runner/workflow-spec.d.ts +4 -0
  182. package/dist/runner/workflow-spec.js +18 -13
  183. package/dist/runs-over-store.d.ts +2 -2
  184. package/dist/runs-over-store.js +1 -1
  185. package/dist/sdk/check.d.ts +1 -4
  186. package/dist/sdk/check.js +2 -3
  187. package/dist/sdk/runs.d.ts +20 -7
  188. package/dist/sdk/runs.js +105 -68
  189. package/dist/secret-cut.js +7 -4
  190. package/dist/secret-rules.js +97 -83
  191. package/dist/secrets.d.ts +4 -0
  192. package/dist/secrets.js +44 -10
  193. package/dist/server-fs.d.ts +1 -1
  194. package/dist/server-fs.js +1 -1
  195. package/dist/server-keys.d.ts +6 -0
  196. package/dist/server-keys.js +12 -0
  197. package/dist/server.d.ts +22 -15
  198. package/dist/server.js +311 -198
  199. package/dist/slack.js +2 -1
  200. package/dist/source-sync/auxiliary.js +2 -2
  201. package/dist/store/index.d.ts +1 -1
  202. package/dist/store/index.js +1 -1
  203. package/dist/store/postgres/migrate.js +3 -1
  204. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  205. package/dist/store/schema.d.ts +28 -2
  206. package/dist/store/schema.js +81 -5
  207. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  208. package/dist/store/sqlite/learning-rows.js +559 -0
  209. package/dist/store/sqlite/store.d.ts +7 -1
  210. package/dist/store/sqlite/store.js +84 -18
  211. package/dist/store/store.d.ts +219 -6
  212. package/dist/store/store.js +13 -0
  213. package/dist/store-reads/journal.d.ts +33 -3
  214. package/dist/store-reads/journal.js +99 -4
  215. package/dist/store-reads/learning.d.ts +23 -26
  216. package/dist/store-reads/learning.js +42 -30
  217. package/dist/store-reads/loop.js +1 -1
  218. package/dist/store-view.d.ts +24 -2
  219. package/dist/store-view.js +40 -11
  220. package/dist/templates.d.ts +10 -2
  221. package/dist/templates.js +31 -4
  222. package/dist/tool-plane.d.ts +27 -3
  223. package/dist/tool-plane.js +79 -4
  224. package/dist/tools.d.ts +12 -2
  225. package/dist/tools.js +42 -7
  226. package/dist/trigger-launch-hook.d.ts +2 -2
  227. package/dist/trigger-launch-hook.js +1 -1
  228. package/dist/triggers.d.ts +7 -4
  229. package/dist/triggers.js +4 -4
  230. package/dist/web-holds.d.ts +2 -0
  231. package/dist/web-holds.js +5 -2
  232. package/dist/web-run.js +2 -1
  233. package/dist/workspace/archil-exec.js +1 -1
  234. package/dist/workspace/archil.d.ts +1 -1
  235. package/dist/workspace/archil.js +1 -1
  236. package/dist/workspace/computer-deps.js +5 -3
  237. package/dist/workspace/computer-providers.d.ts +11 -1
  238. package/dist/workspace/computer-providers.js +29 -2
  239. package/dist/workspace/index.d.ts +1 -2
  240. package/dist/workspace/index.js +1 -2
  241. package/dist/workspace/paths.d.ts +0 -4
  242. package/dist/workspace/paths.js +0 -6
  243. package/dist/workspace/workspace.d.ts +1 -1
  244. package/dist/workspace/workspace.js +1 -1
  245. package/package.json +13 -13
  246. package/templates/TOOLS.md +46 -0
  247. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  248. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  249. package/dist/workspace/learning-workspace.d.ts +0 -24
  250. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -1,62 +1,34 @@
1
- // learningCommit: the writes on an agent's learning folder. Every call is ONE exec of the learning script on the folder's
2
- // main (learn/folder.ts commitChange, one hold), computed from the folder's snapshot and the bodies it names. A main
3
- // that moved under it (the script's exit 3) is computed again on the main that won. A folder with no main yet is made
4
- // in the same call (the script's init first). Four writes:
5
- // - a run's compiled workflow draft (learningCommit), already checked, its files whole; a file that is not on main as
6
- // it was on the run's seed (or its `bases` commit) is a conflict, never written over;
7
- // - one line of an owner's feedback appended to corrections.md (appendCorrection), after the refusals;
8
- // - corrections.md replaced whole by a person (putCorrections), under the ETag they read;
9
- // - a purged run's learned workflows put back as they were before it (off main when it wrote them new) and its feedback
10
- // lines taken off main, by the host (forgetRunText).
11
- import { isWorkspaceError } from "../workspace/index.js";
12
1
  import { CORRECTIONS_CAP, CORRECTIONS_FILE, correctionLine, correctionsProblems } from "./corrections.js";
13
- import { blobOid, DIFFS_DIR, folderAt, folderFailure, FolderMerged, FolderRefused, FolderTooLarge, FolderUnreadable, forgetBody, learningRepair, readLearning, readRunDiff, readSnapshot, runDiffKey, runMergeOf, writeLearning } from "./folder.js";
2
+ import { blobOid, LearningBusy, LearningMerged, LearningRefused, readLearning, readView, runDiffKey, runMergeOf, writeLearning } from "./rows.js";
14
3
  import { held, isHeld } from "./workflow-draft.js";
15
- /** The blob `path` is on the snapshot's main: corrections.md or a draft's file. */
16
- function blobOf(snapshot, path) {
17
- if (!snapshot)
18
- return undefined;
19
- if (path === CORRECTIONS_FILE)
20
- return snapshot.corrections?.oid;
21
- for (const item of snapshot.workflows) {
22
- const file = item.files.find((one) => one.path === path);
23
- if (file)
24
- return file.oid;
25
- }
26
- return undefined;
27
- }
28
- /** A write's failure as a result: the script's precondition (a file changed since the seed: a conflict), a write past
29
- * what one exec carries, or the folder unavailable (retry later). */
4
+ /** A write's failure as a result: a precondition (a file changed since the seed, or the seed gone: a conflict), or the
5
+ * store unavailable (retry later). */
30
6
  function failure(error) {
31
- if (error instanceof FolderRefused && error.seed !== undefined)
7
+ if (error instanceof LearningRefused && error.purged !== undefined)
8
+ return { ok: false, reason: "purged", problems: [{ rule: "kept", detail: "a run's learning was purged after this run started, so what it learned can't be told apart from what the purge took" }] };
9
+ if (error instanceof LearningRefused && error.seed !== undefined)
32
10
  return { ok: false, reason: "conflict", problems: [{ rule: "kept", detail: "the agent's learning was reset after the run started, so what it learned has nothing to land on" }] };
33
- if (error instanceof FolderRefused)
34
- return { ok: false, reason: "conflict", problems: [...error.same, ...error.absent].map((path) => ({ rule: "kept", path, detail: `${path} changed on main after the run started` })) };
35
- if (error instanceof FolderTooLarge)
36
- return { ok: false, reason: "refused", problems: [{ rule: "too_large", detail: error.message }] };
11
+ if (error instanceof LearningRefused)
12
+ return { ok: false, reason: "conflict", problems: error.same.map((path) => ({ rule: "kept", path, detail: `${path} changed on main after the run started` })) };
37
13
  return { ok: false, reason: "unavailable", error: error?.message ?? String(error) };
38
14
  }
39
- /** What a write landed, from writeLearning's answer: its new main and the paths it changed. */
40
- const landed = (done) => "pending" in done.result
41
- ? { ok: true, main: done.main, commit: done.main, files: done.snapshot?.log[0]?.commit === done.main ? done.snapshot.log[0].files : [], ...(done.result.refusedCorrection ? { refusedCorrection: done.result.refusedCorrection } : {}) }
42
- : done.result;
43
15
  /**
44
- * A run's merge on the folder's main, one exec of the learning script: its files (a held README with `status: pending`)
45
- * and its owner's correction appended to corrections.md. `ok` with the new main and the paths the commit changed;
46
- * `conflict` when a file is not on main as it was on the run's seed; `refused` when the correction holds what must never
47
- * be stored, or, with no draft beside it, would take corrections.md past its cap (nothing written); `unavailable` when
48
- * the workspace or the exec failed. The draft and the correction are judged apart: a correction past the cap beside a
49
- * draft (the file filled by another write after the run's check, correctionRefused) is left out alone, and the draft
50
- * merges, `ok` with the cap's refusal as `refusedCorrection`. A merge whose run already merged here (this round) is `ok`
51
- * with the commit that holds it, and writes nothing: checked before the write, again on each main it is computed on, and
52
- * by the script in the commit's own ref transaction, so two calls racing for one round (a reclaimed run) merge it once.
16
+ * A run's merge on the agent's learning, one save: its files (a held README with `status: pending`) and its owner's
17
+ * correction appended to corrections.md. `ok` with the new version and the paths it changed; `conflict` when a file is
18
+ * not at the newest version as it was at the run's seed; `purged` when the merge gives files and a run's purge came after
19
+ * its seed (or a revised workflow's base), nothing written; `refused` when the correction holds what must never be stored,
20
+ * or, with no draft beside it, would take corrections.md past its cap (nothing written); `unavailable` when the store
21
+ * failed. The draft and the correction are judged apart: a correction past the cap beside a draft (the file filled by
22
+ * another write after the run's check, correctionRefused) is left out alone, and the draft merges, `ok` with the cap's
23
+ * refusal as `refusedCorrection`. A merge whose run already merged (this round) is `ok` with the save that holds it, and
24
+ * writes nothing: its merge key is taken once, in the save's own transaction, so two calls racing for one round (a
25
+ * reclaimed run) merge it once.
53
26
  */
54
- export async function learningCommit(ws, change, opts = {}) {
55
- const key = runDiffKey(change.runId, change.round);
27
+ export async function learningCommit(learning, change, opts = {}) {
56
28
  try {
57
- const known = await runMergeOf(ws, change.runId, change.round);
29
+ const known = await runMergeOf(learning, change.runId, change.round);
58
30
  if (known)
59
- return await already(ws, change, known.merge, known);
31
+ return await already(learning, change, known.merge, known);
60
32
  const line = change.correction === undefined ? undefined : correctionLine(change.correction);
61
33
  // The line alone first: what it holds is refused whatever the file around it holds.
62
34
  const own = line === undefined ? [] : correctionProblems(line, change.refuseValues);
@@ -65,19 +37,18 @@ export async function learningCommit(ws, change, opts = {}) {
65
37
  const marked = new Set(change.held ?? []);
66
38
  const drafts = change.files.map(({ path, text }) => ({ path, text: marked.has(path) && !isHeld(text) ? held(text) : text }));
67
39
  const same = change.files.flatMap(({ path }) => {
68
- const commit = change.bases?.[path] ?? change.seed;
69
- return commit ? [{ commit, path }] : [];
40
+ const at = change.bases?.[path] ?? change.seed;
41
+ return at ? [{ at, path }] : [];
70
42
  });
71
- const done = await writeLearning(ws, async ({ snapshot, body }) => {
72
- // Read again on each main the write is computed on: a call that merged this round since the check above (a
73
- // reclaimed run's two claims racing) wrote its diff before the snapshot this call read.
74
- const merged = await readRunDiff(ws, key);
75
- if (merged)
76
- return { result: { merged } };
43
+ // Every save the merge's files were read at: a purge after any of them refuses it whole (its correction too). A
44
+ // correction alone copies nothing from them (its line is the owner's new words, appended to the newest
45
+ // corrections.md), so a purge since never refuses it; its `mustHold` still refuses it after a reset.
46
+ const readAt = drafts.length ? [...new Set([change.seed, change.mustHold, ...Object.values(change.bases ?? {})].filter((id) => id !== undefined))] : [];
47
+ const done = await writeLearning(learning, async (read) => {
77
48
  const writes = [...drafts];
78
49
  let refusedCorrection;
79
50
  if (line !== undefined) {
80
- const text = appended(await correctionsOf(snapshot, body), line);
51
+ const text = appended(correctionsOf(read), line);
81
52
  const full = capProblem(text);
82
53
  if (full && !drafts.length)
83
54
  return { result: { ok: false, reason: "refused", problems: [full] } };
@@ -86,30 +57,32 @@ export async function learningCommit(ws, change, opts = {}) {
86
57
  else
87
58
  writes.push({ path: CORRECTIONS_FILE, text });
88
59
  }
89
- // `mustHold`: the script refuses the whole merge when the folder no longer holds it (a reset removed it).
90
- return { result: { pending: true, ...(refusedCorrection ? { refusedCorrection } : {}) }, change: { by: run(change.runId, change.reason, change.round), writes, ...(same.length ? { same } : {}), ...(change.mustHold ? { seed: change.mustHold } : {}) } };
60
+ // `mustHold`: the whole merge is refused when the agent's learning no longer holds it (a reset removed it).
61
+ return { result: { pending: true, ...(refusedCorrection ? { refusedCorrection } : {}) }, change: { by: run(change.runId, change.reason, change.round), writes, ...(same.length ? { same } : {}), ...(change.mustHold ? { seed: change.mustHold } : {}), ...(readAt.length ? { readAt } : {}) } };
91
62
  }, opts.retries ?? 3);
92
- const { result } = done;
93
- return "merged" in result ? await already(ws, change, result.merged.merge, result.merged) : landed({ ...done, result });
63
+ const { result, saved } = done;
64
+ return "pending" in result ? { ok: true, main: saved.id, commit: saved.id, files: [...saved.files], ...(result.refusedCorrection ? { refusedCorrection: result.refusedCorrection } : {}) } : result;
94
65
  }
95
66
  catch (error) {
96
- // The round merged under this call past both reads (its diff not written yet): the script's ref transaction let
97
- // one merge of it land, and this call reads that one.
98
- if (error instanceof FolderMerged)
99
- return already(ws, change, error.merge, await readRunDiff(ws, key).catch(() => undefined)).catch(failure);
67
+ // The round merged under this call past the read above (a reclaimed run's two claims racing): its merge key let one
68
+ // merge of it land, and this call reads that one.
69
+ if (error instanceof LearningMerged)
70
+ return already(learning, change, error.save.id, await runMergeOf(learning, change.runId, change.round).catch(() => undefined)).catch(failure);
71
+ if (error instanceof LearningBusy)
72
+ return { ok: false, reason: "unavailable", error: error.message };
100
73
  return failure(error);
101
74
  }
102
75
  }
103
- /** A round that merged already, `merge` its commit: `ok` with it and the paths its diff names (none when its diff is
104
- * not written yet), nothing written again. Its merge left the correction out only at the cap. */
105
- async function already(ws, change, merge, known) {
76
+ /** A round that merged already, `merge` its save: `ok` with it and the paths its diff names, nothing written again. Its
77
+ * merge left the correction out only at the cap. */
78
+ async function already(learning, change, merge, known) {
106
79
  const left = known !== undefined && change.correction !== undefined && !known.files.some((file) => file.path === CORRECTIONS_FILE);
107
80
  const refusedCorrection = left ? [{ rule: "too_large", path: CORRECTIONS_FILE, detail: `${CORRECTIONS_FILE} was at its cap of ${CORRECTIONS_CAP} bytes when the run's merge was written` }] : [];
108
- return { ok: true, main: (await readSnapshot(ws))?.main ?? merge, commit: merge, files: known ? known.files.map((file) => file.path) : [], already: true, ...(refusedCorrection.length ? { refusedCorrection } : {}) };
81
+ return { ok: true, main: (await readView(learning))?.main ?? merge, commit: merge, files: known ? known.files.map((file) => file.path) : [], already: true, ...(refusedCorrection.length ? { refusedCorrection } : {}) };
109
82
  }
110
83
  const run = (runId, reason, round) => ({ run: runId, reason, ...(round !== undefined && round > 1 ? { round } : {}) });
111
- /** corrections.md's text as main holds it now ("" when it holds none). */
112
- const correctionsOf = async (snapshot, body) => snapshot?.corrections ? body(CORRECTIONS_FILE, snapshot.corrections.oid) : "";
84
+ /** corrections.md's text at the version read ("" when it holds none). */
85
+ const correctionsOf = (read) => read.text(CORRECTIONS_FILE) ?? "";
113
86
  /** corrections.md's text `before` with `line` appended on a line of its own. */
114
87
  const appended = (before, line) => `${before}${before && !before.endsWith("\n") ? "\n" : ""}${line}`;
115
88
  /** What a correction's line holds that must never be stored, whatever the file around it holds. */
@@ -123,224 +96,43 @@ const capProblem = (text) => {
123
96
  * empty when it would be taken. Read before the run's merge, so a refused correction never holds its draft back. A
124
97
  * round (`merge`) whose merge is on main already (a stop after its commit, before the run's end was saved) is never
125
98
  * checked for room again, its own line counted twice: empty, and its merge (learningCommit) gives back what it did. */
126
- export async function correctionRefused(ws, text, refuseValues, merge) {
99
+ export async function correctionRefused(learning, text, refuseValues, merge) {
127
100
  const line = correctionLine(text);
128
101
  const own = correctionProblems(line, refuseValues);
129
102
  if (own.length)
130
103
  return own;
131
- if (merge && (await runMergeOf(ws, merge.runId, merge.round)))
104
+ if (merge && (await learning.rows.saveOf(learning.agentId, { mergeKey: runDiffKey(merge.runId, merge.round) })))
132
105
  return [];
133
- const before = await readLearning(ws, ({ snapshot, body }) => correctionsOf(snapshot, body));
106
+ const before = await readLearning(learning, correctionsOf);
134
107
  const full = capProblem(appended(before, line));
135
108
  return full ? [full] : [];
136
109
  }
137
110
  /** One line of an owner's feedback appended to corrections.md on main, by run `runId`'s merge (learningCommit's
138
111
  * `correction`, with no draft beside it). */
139
- export const appendCorrection = (ws, input) => learningCommit(ws, { runId: input.runId, ...(input.round !== undefined ? { round: input.round } : {}), reason: "the owner's correction", files: [], correction: input.text, ...(input.refuseValues ? { refuseValues: input.refuseValues } : {}) });
140
- /** corrections.md as a person reads it: its text and its ETag's blob (an empty file's when main holds none). */
141
- export async function readCorrections(snapshot, body) {
142
- const text = await correctionsOf(snapshot, body);
143
- return { text, oid: snapshot?.corrections?.oid ?? blobOid("") };
112
+ export const appendCorrection = (learning, input) => learningCommit(learning, { runId: input.runId, ...(input.round !== undefined ? { round: input.round } : {}), reason: "the owner's correction", files: [], correction: input.text, ...(input.refuseValues ? { refuseValues: input.refuseValues } : {}) });
113
+ /** corrections.md as a person reads it: its text and its ETag's blob (an empty file's when it holds none). */
114
+ export function readCorrections(read) {
115
+ return { text: correctionsOf(read), oid: read.view?.corrections?.oid ?? blobOid("") };
144
116
  }
145
117
  /**
146
118
  * corrections.md replaced whole by a person: `ifMatch`, the blob they read (an ETag, quoted or not; an empty file's when
147
- * main held none), must be main's now, else a conflict. Refused, nothing written, as appendCorrection refuses. `ok` with
119
+ * the agent held none), must be the newest's now, else a conflict. Refused, nothing written, as appendCorrection refuses. `ok` with
148
120
  * the new text and its blob.
149
121
  */
150
- export async function putCorrections(ws, input) {
151
- const problems = correctionsProblems(input.text, input.refuseValues);
122
+ export async function putCorrections(learning, input) {
123
+ // Kept as its notes hold it: every line ends in a newline (learn/rows.ts), so the text answered is the text read back.
124
+ const text = input.text === "" || input.text.endsWith("\n") ? input.text : `${input.text}\n`;
125
+ // Judged as sent first, so a refusal counts the bytes the person sent; then with the newline it is kept with.
126
+ const sent = correctionsProblems(input.text, input.refuseValues);
127
+ const problems = sent.length || text === input.text ? sent : correctionsProblems(text, input.refuseValues);
152
128
  if (problems.length)
153
129
  return { ok: false, reason: "refused", problems };
154
130
  const seen = input.ifMatch.trim().replace(/^W\//, "").replace(/^"|"$/g, "");
155
- const { result } = await writeLearning(ws, async ({ snapshot }) => {
156
- const now = snapshot?.corrections?.oid ?? blobOid("");
131
+ const { result } = await writeLearning(learning, async ({ view }) => {
132
+ const now = view?.corrections?.oid ?? blobOid("");
157
133
  if (now !== seen)
158
134
  return { result: { ok: false, reason: "conflict", problems: [{ rule: "kept", path: CORRECTIONS_FILE, detail: `${CORRECTIONS_FILE} changed since it was read` }] } };
159
- return { result: { ok: true, text: input.text, oid: blobOid(input.text) }, change: { by: { person: "edited", file: CORRECTIONS_FILE }, writes: [{ path: CORRECTIONS_FILE, text: input.text }] } };
135
+ return { result: { ok: true, text, oid: blobOid(text) }, change: { by: { person: "edited", file: CORRECTIONS_FILE }, writes: [{ path: CORRECTIONS_FILE, text }] } };
160
136
  });
161
137
  return result;
162
138
  }
163
- /**
164
- * Run `runId`'s text taken off the folder's current files, at its purge (agent-delete.ts purgeRun): first its learned
165
- * workflows (forgetRunWorkflows; `purged`: whether another run is purged), whether or not it left a diff file; then the
166
- * lines each of its merges added to corrections.md, as its diff file keeps them, dropped from main in one host commit
167
- * per merge (a line a person edited since is theirs and stays); each other merge's diff that shows such a line as
168
- * context written without it; then the run's diff files deleted, last, so a call stopped part way finds what it has
169
- * left to do. Its merges stay in the folder's git history until a learning reset or its agent's purge deletes the
170
- * folder. Idempotent: each merge's scrub lands once, nothing left to drop makes no commit, and a run with no diff file
171
- * and no workflow here is no work.
172
- * `commit`: the host's last commit, when one was made.
173
- */
174
- export async function forgetRunText(ws, runId, purged) {
175
- let commit = await forgetRunWorkflows(ws, runId, async (run) => run === runId || (await purged(run)));
176
- const names = await diffNames(ws);
177
- const own = new RegExp(`^${runId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\.r\\d+)?\\.json(\\..+)?$`);
178
- const mine = names.filter((name) => own.test(name));
179
- if (!mine.length)
180
- return commit ? { commit } : {};
181
- const lines = [];
182
- for (const name of mine.filter(isDiffFile)) {
183
- const added = ((await diffOrNone(ws, name))?.files ?? []).flatMap((file) => (file.path === CORRECTIONS_FILE && "patch" in file ? addedLines(file.patch) : []));
184
- if (!added.length)
185
- continue;
186
- lines.push(...added);
187
- // Lands once, by the merge's diff key (the folder's ref for its scrub): a call that stopped after it finds it landed
188
- // and takes no line again, so another run's same line stays; a merge of the run made since (a purge that stopped
189
- // before the run's tombstone left it open to a grade) is a key of its own, scrubbed in its turn.
190
- const done = await writeLearning(ws, async ({ snapshot, body }) => {
191
- if (!snapshot?.corrections)
192
- return { result: undefined };
193
- const before = await body(CORRECTIONS_FILE, snapshot.corrections.oid);
194
- const after = withoutLines(before, added);
195
- if (after === before)
196
- return { result: undefined };
197
- const write = after ? { writes: [{ path: CORRECTIONS_FILE, text: after }] } : { writes: [], deletes: [CORRECTIONS_FILE] };
198
- return { result: snapshot.corrections.oid, change: { by: { host: "a purged run's corrections removed" }, purged: name.slice(0, -".json".length), ...write } };
199
- }).catch((error) => (error instanceof FolderMerged ? { result: undefined, main: undefined } : Promise.reject(error)));
200
- if (done.result !== undefined) {
201
- forgetBody(done.result);
202
- commit = done.main;
203
- }
204
- }
205
- if (lines.length) {
206
- const gone = new Set(lines);
207
- for (const name of names.filter((one) => isDiffFile(one) && !own.test(one))) {
208
- const diff = await diffOrNone(ws, name);
209
- if (!diff)
210
- continue;
211
- let changed = false;
212
- const files = diff.files.map((file) => {
213
- if (file.path !== CORRECTIONS_FILE || !("patch" in file))
214
- return file;
215
- const patch = withoutContext(file.patch, gone);
216
- if (patch === file.patch)
217
- return file;
218
- changed = true;
219
- return { ...file, patch };
220
- });
221
- if (!changed)
222
- continue;
223
- await ws.write(`${DIFFS_DIR}/${name}`, `${JSON.stringify({ ...diff, files })}\n`).catch((error) => { throw folderFailure(error); });
224
- }
225
- }
226
- for (const name of mine)
227
- await ws.remove(`${DIFFS_DIR}/${name}`, { force: true }).catch((error) => { throw folderFailure(error); });
228
- return commit ? { commit } : {};
229
- }
230
- /** Each learned workflow on main whose workflow.json run `runId` wrote last (SnapLearned.run, the rule purged-workflow.ts
231
- * reads) put back in one host commit as it stood at the newest commit where its writer was no purged run (`purged`,
232
- * `runId` among them), every file of its `workflows/<name>/` folder, its writer that run again (the commit's
233
- * `Written-By` line: folder.ts writerOf); taken off main whole when the purged runs wrote every version of it. So a
234
- * purge takes off main only what purged runs put there, and a version another run wrote, a champion included, stays
235
- * served. The commit, or undefined when main holds none of the run's (a repeat finds its own put back, and one another
236
- * run wrote since names that run). The snapshot is rebuilt from main first (two execs and a checkout): a merge that
237
- * moved main and stopped before its snapshot leaves one that names none of that merge's workflows, and finding no work
238
- * commits nothing that would show it stale. One more read-only exec of main's history when the run wrote one, and one
239
- * per version put back; either read finding nothing refuses (FolderUnreadable), so no guess takes a folder off. */
240
- async function forgetRunWorkflows(ws, runId, purged) {
241
- if (await readSnapshot(ws))
242
- await learningRepair(ws);
243
- const done = await writeLearning(ws, async ({ snapshot }) => {
244
- const mine = (snapshot?.workflows ?? []).filter((item) => item.run === runId);
245
- if (!mine.length)
246
- return { result: false };
247
- // No history read, no guess: a purge that can't tell what came before the run's version refuses (503, sent again
248
- // later), and never takes the whole folder off main.
249
- const unread = () => new FolderUnreadable(false, "the learning folder's history at main can't be read, so a purge puts nothing back and takes nothing off: send the DELETE again");
250
- const history = await folderAt(ws, snapshot.main);
251
- if (!history)
252
- throw unread();
253
- const writes = [];
254
- const deletes = [];
255
- const written = {};
256
- for (const item of mine) {
257
- // Newest first: the first writer no purged run is the version to put back, as it stood just before the next
258
- // writer took the file over.
259
- const writers = history.writers(item.name);
260
- let back = [];
261
- for (let i = 1; i < writers.length; i++) {
262
- const { run } = writers[i];
263
- if (run !== null && (await purged(run)))
264
- continue;
265
- const before = writers[i - 1].before;
266
- const at = before ? await folderAt(ws, before) : undefined;
267
- if (!at)
268
- throw unread();
269
- const files = at.snapshot.workflows.find((one) => one.name === item.name)?.files ?? [];
270
- back = files.map(({ path, oid }) => ({ path, text: at.blobs.get(oid).toString("utf8") }));
271
- // Named even when `back` is main's bytes already, so the writer still moves (folder.ts writtenIn).
272
- if (back.length)
273
- written[item.name] = run;
274
- break;
275
- }
276
- writes.push(...back);
277
- deletes.push(...[...item.files.map(({ path }) => path), ...(item.links ?? [])].filter((path) => !back.some((file) => file.path === path)));
278
- }
279
- const host = writes.length ? "a purged run's workflows put back as they were before it" : "a purged run's workflows removed";
280
- return { result: true, change: { by: { host, written }, writes, deletes } };
281
- });
282
- return done.result ? done.main : undefined;
283
- }
284
- /** The names in the folder's diffs directory; none when it is not there. */
285
- const diffNames = (ws) => ws.list(DIFFS_DIR).then((entries) => entries.filter((entry) => entry.kind === "file").map((entry) => entry.name), (error) => (isWorkspaceError(error, "NOT_FOUND") ? [] : Promise.reject(folderFailure(error))));
286
- /** A merge's diff file, `<key>.json`; not one a stopped write left half written (`.json.<suffix>`). */
287
- const isDiffFile = (name) => /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}\.json$/.test(name);
288
- /** Diff file `name` as readRunDiff reads it, or undefined when it does not read as one: a folder that can't be read
289
- * throws. */
290
- const diffOrNone = (ws, name) => readRunDiff(ws, name.slice(0, -".json".length)).catch((error) => (error instanceof FolderUnreadable ? Promise.reject(error) : undefined));
291
- /** The lines a patch (git's hunks) adds and does not take away: what a merge appended. */
292
- function addedLines(patch) {
293
- const lines = patch.split("\n");
294
- const taken = new Map();
295
- for (const line of lines)
296
- if (line.startsWith("-"))
297
- taken.set(line.slice(1), (taken.get(line.slice(1)) ?? 0) + 1);
298
- return lines.filter((line) => line.startsWith("+")).map((line) => line.slice(1)).filter((line) => {
299
- const left = taken.get(line) ?? 0;
300
- if (left)
301
- taken.set(line, left - 1);
302
- return !left && line.trim() !== "";
303
- });
304
- }
305
- /** `text` with the last line equal to each of `lines` left out. */
306
- function withoutLines(text, lines) {
307
- const kept = text.split("\n");
308
- for (const line of lines) {
309
- const at = kept.lastIndexOf(line);
310
- if (at >= 0)
311
- kept.splice(at, 1);
312
- }
313
- return kept.join("\n");
314
- }
315
- /** `patch` (git's hunks) with each context line that is one of `gone` left out, a hunk that lost one given the header
316
- * of what it keeps: the start moved past the lines it lost at its top (git names the line before when it keeps none
317
- * on a side), each count less what it lost. */
318
- function withoutContext(patch, gone) {
319
- const lines = patch.split("\n");
320
- const out = [];
321
- const dropped = (line) => line.startsWith(" ") && gone.has(line.slice(1));
322
- for (let i = 0; i < lines.length;) {
323
- const head = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/.exec(lines[i]);
324
- if (!head) {
325
- out.push(lines[i++]);
326
- continue;
327
- }
328
- let end = i + 1;
329
- while (end < lines.length && !lines[end].startsWith("@@"))
330
- end++;
331
- const body = lines.slice(i + 1, end);
332
- const kept = body.filter((line) => !dropped(line));
333
- const lost = body.length - kept.length;
334
- if (!lost)
335
- out.push(lines[i], ...body);
336
- else {
337
- const top = body.findIndex((line) => !dropped(line));
338
- const lead = top < 0 ? lost : top;
339
- const [olds, news] = [Number(head[2] ?? 1) - lost, Number(head[4] ?? 1) - lost];
340
- const at = (start, count) => Number(start) + lead - (count ? 0 : 1);
341
- out.push(`@@ -${at(head[1], olds)},${olds} +${at(head[3], news)},${news} @@${head[5]}`, ...kept);
342
- }
343
- i = end;
344
- }
345
- return out.join("\n");
346
- }
@@ -1,6 +1,6 @@
1
1
  import type { RunRow, Store } from "../store/store.js";
2
2
  import type { AuthorHostAddendum } from "@parcha/agentrun-dsl";
3
- import { type AuditHold, type CheckRecord, type PromotionRecord, type Refused } from "./promote.js";
3
+ import { type AuditHold, type CheckRecord, type PromotionRecord } from "./promote.js";
4
4
  import type { Problem } from "./check.js";
5
5
  /** The info word that opens a workflow draft's block in a compile answer: ````workflow <name>, fenced with four backticks
6
6
  * so a ``` line inside does not close it. */
@@ -111,9 +111,9 @@ export declare function promotedOf(records: readonly PromotionRecord[], workflow
111
111
  /** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
112
112
  * that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
113
113
  * hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
114
- * compiles it again. A record `refused` names (the purge gate's: purged-workflow.ts refusedOf) is skipped as championOf
115
- * skips it, so no purged run's revision is the champion or the hold a compile revises. */
116
- export declare function heldNamesOf(records: readonly PromotionRecord[], refused?: Refused): Set<string>;
114
+ * compiles it again. A purged run's records are gone with it (Store.learning purgeRun): no purged run's revision is the
115
+ * champion or the hold a compile revises. */
116
+ export declare function heldNamesOf(records: readonly PromotionRecord[]): Set<string>;
117
117
  /** The words a compile's promotion record starts with when every draft of its turn failed its checks (runner/
118
118
  * learning-end.ts recordDraftFailed): a hold with nothing checked, the compile's attempt all the same. */
119
119
  export declare const DRAFT_FAILED = "its draft failed its checks";
@@ -76,13 +76,12 @@ export function promotedOf(records, workflow, digest) {
76
76
  /** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
77
77
  * that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
78
78
  * hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
79
- * compiles it again. A record `refused` names (the purge gate's: purged-workflow.ts refusedOf) is skipped as championOf
80
- * skips it, so no purged run's revision is the champion or the hold a compile revises. */
81
- export function heldNamesOf(records, refused) {
82
- const kept = refused ? records.filter((one) => !refused(one)) : records;
83
- return new Set([...new Set(kept.map(({ workflow }) => workflow))].filter((name) => {
84
- const champion = championOf(kept, name)?.digest;
85
- const newest = kept.findLast((one) => one.workflow === name && one.digest !== champion);
79
+ * compiles it again. A purged run's records are gone with it (Store.learning purgeRun): no purged run's revision is the
80
+ * champion or the hold a compile revises. */
81
+ export function heldNamesOf(records) {
82
+ return new Set([...new Set(records.map(({ workflow }) => workflow))].filter((name) => {
83
+ const champion = championOf(records, name)?.digest;
84
+ const newest = records.findLast((one) => one.workflow === name && one.digest !== champion);
86
85
  return newest?.decided === "hold" && !newest.check?.stopped && !newest.audit?.stopped;
87
86
  }));
88
87
  }
@@ -1,4 +1,4 @@
1
- // An agent's standing corrections: one file, corrections.md, at its learning folder's top, in its owner's words. An
1
+ // An agent's standing corrections: one file, corrections.md, at its learning's top, in its owner's words. An
2
2
  // owner's feedback (a grade with words, a message after the answer) adds one line; a person may replace it whole over
3
3
  // v2. Every run of the agent is served it whole under # Learned. Nothing that must never be stored (a host secret, text
4
4
  // shaped like one, a character a reader does not see) is written, and the file never grows past CORRECTIONS_CAP.
@@ -1,23 +1,16 @@
1
1
  import { type Store } from "../store/store.js";
2
- import type { LearningFolder } from "./folder.js";
3
2
  /** A delete refused: work of the agent's learning is still in flight (`runs`: a run of the agent not ended, its
4
3
  * compile turn, a check's replay or an audit's shadow among them). Nothing was removed. */
5
4
  export declare class LearningInFlight extends Error {
6
5
  readonly runs: readonly string[];
7
6
  constructor(agentId: string, runs: readonly string[]);
8
7
  }
9
- /** Agent `agentId`'s learning deleted: its learning folder on each other disk it is on (`elsewhere`: a Mode 2 run's end
10
- * writes it on the Archil disk its claim mounted; server.ts names those disks), then every file of its learning folder
11
- * here (`folder`, learning.ts learningFolderOf: its corrections.md and workflows, its git history and snapshot,
12
- * audits.jsonl), then the learning records the store keeps for it (its promotions and grades, and the reset ledger and
13
- * watermark its earlier resets kept, unless `keepResetLedger`: a reset keeps them, the runs they cover staying).
14
- * Refused (LearningInFlight), with nothing removed, while a run of the agent has not ended; `elsewhere` failing leaves
15
- * this folder and the records for the next call. Idempotent: what is gone already is skipped, so a second call removes
16
- * nothing. `files`: this folder's entries it removed; `records`: the store's records. `folder` is ended here. */
17
- export declare function deleteLearning(store: Store, agentId: string, folder: LearningFolder, { keepResetLedger, elsewhere }?: {
8
+ /** Agent `agentId`'s learning deleted: every learning row the store keeps for it (Store.learning: its items, saves,
9
+ * promotions, grades and audits), and the reset ledger and watermark its earlier resets kept, unless `keepResetLedger`
10
+ * (a reset keeps them, the runs they cover staying). Refused (LearningInFlight), with nothing removed, while a run of
11
+ * the agent has not ended. Idempotent: a second call removes nothing. `records`: the settings rows it removed. */
12
+ export declare function deleteLearning(store: Store, agentId: string, { keepResetLedger }?: {
18
13
  keepResetLedger?: boolean;
19
- elsewhere?: () => Promise<void>;
20
14
  }): Promise<{
21
- files: number;
22
15
  records: number;
23
16
  }>;
@@ -3,9 +3,8 @@
3
3
  // deletes the agent's store rows, in that order, so a call again after a crash finishes what a first one began and no
4
4
  // learning is left with no agent to own it; DELETE /v2/agents/{id}/learning (learning-reset.ts) keeps the agent and its
5
5
  // runs.
6
- import { isWorkspaceError } from "../workspace/workspace.js";
7
6
  import { FINAL_STATES } from "../store/store.js";
8
- import { gradesKey, promotionsKey, resetAtKey, resetLedgerKey } from "./promote.js";
7
+ import { resetAtKey, resetLedgerKey } from "./promote.js";
9
8
  /** A delete refused: work of the agent's learning is still in flight (`runs`: a run of the agent not ended, its
10
9
  * compile turn, a check's replay or an audit's shadow among them). Nothing was removed. */
11
10
  export class LearningInFlight extends Error {
@@ -16,33 +15,21 @@ export class LearningInFlight extends Error {
16
15
  this.runs = runs;
17
16
  }
18
17
  }
19
- /** Agent `agentId`'s learning deleted: its learning folder on each other disk it is on (`elsewhere`: a Mode 2 run's end
20
- * writes it on the Archil disk its claim mounted; server.ts names those disks), then every file of its learning folder
21
- * here (`folder`, learning.ts learningFolderOf: its corrections.md and workflows, its git history and snapshot,
22
- * audits.jsonl), then the learning records the store keeps for it (its promotions and grades, and the reset ledger and
23
- * watermark its earlier resets kept, unless `keepResetLedger`: a reset keeps them, the runs they cover staying).
24
- * Refused (LearningInFlight), with nothing removed, while a run of the agent has not ended; `elsewhere` failing leaves
25
- * this folder and the records for the next call. Idempotent: what is gone already is skipped, so a second call removes
26
- * nothing. `files`: this folder's entries it removed; `records`: the store's records. `folder` is ended here. */
27
- export async function deleteLearning(store, agentId, folder, { keepResetLedger = false, elsewhere } = {}) {
28
- try {
29
- const open = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId && !FINAL_STATES.includes(run.state)).map((run) => run.id);
30
- if (open.length)
31
- throw new LearningInFlight(agentId, open);
32
- await elsewhere?.();
33
- const entries = await folder.workspace.list("").catch((error) => (isWorkspaceError(error, "NOT_FOUND") ? [] : Promise.reject(error)));
34
- for (const entry of entries)
35
- await folder.workspace.remove(entry.name, { recursive: true, force: true });
36
- let records = 0;
37
- for (const key of [promotionsKey(agentId), gradesKey(agentId), ...(keepResetLedger ? [] : [resetLedgerKey(agentId), resetAtKey(agentId)])]) {
38
- if ((await store.settings.get(key)) === undefined)
39
- continue;
40
- await store.settings.remove(key);
41
- records += 1;
42
- }
43
- return { files: entries.length, records };
44
- }
45
- finally {
46
- await folder.end();
18
+ /** Agent `agentId`'s learning deleted: every learning row the store keeps for it (Store.learning: its items, saves,
19
+ * promotions, grades and audits), and the reset ledger and watermark its earlier resets kept, unless `keepResetLedger`
20
+ * (a reset keeps them, the runs they cover staying). Refused (LearningInFlight), with nothing removed, while a run of
21
+ * the agent has not ended. Idempotent: a second call removes nothing. `records`: the settings rows it removed. */
22
+ export async function deleteLearning(store, agentId, { keepResetLedger = false } = {}) {
23
+ const open = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId && !FINAL_STATES.includes(run.state)).map((run) => run.id);
24
+ if (open.length)
25
+ throw new LearningInFlight(agentId, open);
26
+ await (keepResetLedger ? store.learning.reset(agentId) : store.learning.erase(agentId));
27
+ let records = 0;
28
+ for (const key of keepResetLedger ? [] : [resetLedgerKey(agentId), resetAtKey(agentId)]) {
29
+ if ((await store.settings.get(key)) === undefined)
30
+ continue;
31
+ await store.settings.remove(key);
32
+ records += 1;
47
33
  }
34
+ return { records };
48
35
  }
@@ -0,0 +1,16 @@
1
+ import type { AuditDisagreement, CheckDisagreement, PromotionRecord } from "./promote.js";
2
+ /** A check's disagreement with what it copied from its run blanked: its run id and which way the draft went (an answer,
3
+ * a hand-back, a failed step) and the fields it had wrong (the definition's names, no run text) and where each known
4
+ * answer came from kept, its input, the agent's answer, the draft's, the known answers' values and the grader's words
5
+ * gone. */
6
+ export declare const blankCheck: (one: CheckDisagreement) => CheckDisagreement;
7
+ /** An audit's disagreement blanked the same way: its run ids and whether a grade wrote it kept, its known answer empty. */
8
+ export declare const blankAudit: (one: AuditDisagreement) => AuditDisagreement;
9
+ /** `record` with what it copied from run `runId` blanked: each disagreement naming it (a check's agent run, a connected
10
+ * agent's collected turn too; an audit's served run or shadow run), and the grader's words its reason quotes from one
11
+ * (differentDecisionWords' example). Its decision, numbers and run ids stay. The record itself when it names no such
12
+ * disagreement. */
13
+ export declare function forgetRunIn(record: PromotionRecord, runId: string): PromotionRecord;
14
+ /** The runs whose copies `record` holds (forgetRunIn blanks them): each disagreement's run, a connected agent's collected
15
+ * turn's, an audit's served run and shadow run. */
16
+ export declare function runsNamedIn(record: PromotionRecord): string[];