@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
@@ -12,6 +12,42 @@ export declare const LEARNED_NODES = "agentrun.learned_nodes";
12
12
  * however many nodes failed on the way and were recovered, a map's collected item say), or `failed` (it threw, or was
13
13
  * refused before any node ran). */
14
14
  export type LearnedEnded = "complete" | "escalated" | "failed";
15
+ /** The record of a learned_workflow call that ended `failed` with no node kept, where the tool kept none: an agent's call
16
+ * a crash cut mid-call, refused when it was issued again (adapter-loop.ts learnedEntry, learnedCallRan). An earlier
17
+ * attempt may have run nodes and spent, so it is no refusal: its $ is what its call id booked. */
18
+ export declare const failedRecord: (call: string, workflow: string, digest: string, caller: "platform" | "agent") => {
19
+ call: string;
20
+ workflow: string;
21
+ digest: string;
22
+ caller: "platform" | "agent";
23
+ nodes: never[];
24
+ ended: LearnedEnded;
25
+ };
26
+ /** The record of a learned_workflow call refused before the tool saw it (`refused`: it ran nothing), which the loop keeps
27
+ * where the tool never ran: the platform's call its gate refused (runner/adapter-loop.ts serveFirst), and an agent's its
28
+ * gate refused with no attempt of it let go since its last refusal (adapter-loop.ts learnedEntry). Either reads
29
+ * `failed` once anything was booked under its call id (runner/workflow-calls.ts workflowCallsOf). */
30
+ export declare const refusedRecord: (call: string, workflow: string, digest: string, caller: "platform" | "agent") => {
31
+ refused: true;
32
+ call: string;
33
+ workflow: string;
34
+ digest: string;
35
+ caller: "platform" | "agent";
36
+ nodes: never[];
37
+ ended: LearnedEnded;
38
+ };
39
+ /** The mark an agent's learned_workflow call on a CLI gets in the run's journal when its gate lets it go, before it runs:
40
+ * `{ call }`, its call's id (adapter-loop.ts sessionGate). An attempt a crash cuts before its record is kept leaves
41
+ * this, so a later refusal of the call issued again knows an attempt after any earlier refusal may have run. */
42
+ export declare const LEARNED_ALLOWED = "agentrun.learned_allowed";
43
+ /** Whether an attempt of learned_workflow call `call` may have run, from its root's `entries`: the newest of its allow
44
+ * marks (LEARNED_ALLOWED) and its records (LEARNED_NODES) is a mark, or a record not `refused`. Neither: `replayed`, the
45
+ * bridge's word that the call is issued again (a run begun before the marks existed has none), else no attempt was let
46
+ * go, so none ran. */
47
+ export declare function learnedCallRan(entries: readonly {
48
+ readonly kind: string;
49
+ readonly data?: unknown;
50
+ }[], call: string, replayed?: boolean): boolean;
15
51
  /** The most nodes a call keeps: a map over a long list runs its body once per item. */
16
52
  export declare const LEARNED_NODES_MAX = 64;
17
53
  /** One node of a learned workflow's run, as the DSL ended it (its `node.end` event): its label, its kind, how it ended
@@ -7,6 +7,29 @@
7
7
  * `refused: true` on one refused before any node ran (it ran nothing). A run's `workflow_calls` read these
8
8
  * (runner/workflow-calls.ts). */
9
9
  export const LEARNED_NODES = "agentrun.learned_nodes";
10
+ /** The record of a learned_workflow call that ended `failed` with no node kept, where the tool kept none: an agent's call
11
+ * a crash cut mid-call, refused when it was issued again (adapter-loop.ts learnedEntry, learnedCallRan). An earlier
12
+ * attempt may have run nodes and spent, so it is no refusal: its $ is what its call id booked. */
13
+ export const failedRecord = (call, workflow, digest, caller) => ({ call, workflow, digest, caller, nodes: [], ended: "failed" });
14
+ /** The record of a learned_workflow call refused before the tool saw it (`refused`: it ran nothing), which the loop keeps
15
+ * where the tool never ran: the platform's call its gate refused (runner/adapter-loop.ts serveFirst), and an agent's its
16
+ * gate refused with no attempt of it let go since its last refusal (adapter-loop.ts learnedEntry). Either reads
17
+ * `failed` once anything was booked under its call id (runner/workflow-calls.ts workflowCallsOf). */
18
+ export const refusedRecord = (call, workflow, digest, caller) => ({ ...failedRecord(call, workflow, digest, caller), refused: true });
19
+ /** The mark an agent's learned_workflow call on a CLI gets in the run's journal when its gate lets it go, before it runs:
20
+ * `{ call }`, its call's id (adapter-loop.ts sessionGate). An attempt a crash cuts before its record is kept leaves
21
+ * this, so a later refusal of the call issued again knows an attempt after any earlier refusal may have run. */
22
+ export const LEARNED_ALLOWED = "agentrun.learned_allowed";
23
+ /** Whether an attempt of learned_workflow call `call` may have run, from its root's `entries`: the newest of its allow
24
+ * marks (LEARNED_ALLOWED) and its records (LEARNED_NODES) is a mark, or a record not `refused`. Neither: `replayed`, the
25
+ * bridge's word that the call is issued again (a run begun before the marks existed has none), else no attempt was let
26
+ * go, so none ran. */
27
+ export function learnedCallRan(entries, call, replayed = false) {
28
+ const newest = entries.findLast((entry) => (entry.kind === LEARNED_ALLOWED || entry.kind === LEARNED_NODES) && entry.data?.call === call);
29
+ if (newest === undefined)
30
+ return replayed;
31
+ return newest.kind === LEARNED_ALLOWED || newest.data.refused !== true;
32
+ }
10
33
  /** The most nodes a call keeps: a map over a long list runs its body once per item. */
11
34
  export const LEARNED_NODES_MAX = 64;
12
35
  /** The LEARNED_NODES entry that counts for each learned_workflow call in `entries`, by the call's id, as its index in
@@ -7,7 +7,7 @@ export interface LearningResetHost {
7
7
  /** The cancel path, for one run that is not final: true once a cancel stands for it, false when this server cannot
8
8
  * end it (agent-delete.ts AgentDeleteHost.cancel). */
9
9
  cancel(runId: string): Promise<boolean>;
10
- /** `work` in agent `agentId`'s learning queue (learning.ts withAgentRepo). */
10
+ /** `work` in agent `agentId`'s learning queue (learning.ts inLearningQueue). */
11
11
  inQueue<T>(agentId: string, work: () => Promise<T>): Promise<T>;
12
12
  /** How long step 1 waits for the agent's learning runs to be final, and how often it reads them meanwhile. */
13
13
  readonly waitMs: number;
@@ -1,14 +1,13 @@
1
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
2
+ // module's deleteLearning: its learning rows, every save, note, workflow, promotion record, grade and audit row); the agent, its
4
3
  // definition, its runs and everything kept of them (their files, journals, costs, the learning each one kept) stay, so
5
4
  // 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
5
  // revision's compile and check, read from the promotion records the reset deletes: each revision they name is kept
7
6
  // first in the agent's reset ledger (learn/promote.ts keepResetLedger: workflow, digest and K alone), so the share reads
8
7
  // the same after.
9
8
  //
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.
9
+ // What goes with the rows: each run's learning diff (GET /runs/{id}/learning/diff, the text it merged) is read from its
10
+ // save, so it is 404 after; what the run's own record keeps of its learning end stays with the run.
12
11
  //
13
12
  // In order, in the agent's delete turn (server.ts agentWrite: one learning write of an agent at a time, and none once
14
13
  // its DELETE began):
@@ -18,18 +17,17 @@
18
17
  // a workflow it may be served, its compile turn and look-back at its end), and the owner's job is never cancelled
19
18
  // to reset learning. Any such run, or a learning run this server cannot end (an SDK run, an imported one) or one
20
19
  // 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
20
+ // 2. In the agent's learning queue (learning.ts inLearningQueue, where a run's start reads its seed), the agent's runs are read again: one still going (a run started meanwhile) is 409 learning_busy, nothing
23
21
  // deleted. Then deleteLearning, which reads them once more itself.
24
22
  // Idempotent: an agent that never learned, or one reset already, has nothing to delete, and is answered as done.
25
23
  //
26
24
  // Step 2 sets the agent's reset watermark (learn/promote.ts resetAtKey) before it deletes: from then on learning reads
27
25
  // 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
26
+ // audit's draws, the money rule). A run whose start read its seed before step 2
29
27
  // and whose row the store wrote after it keeps what it was started with (its corrections are in its launch), but
30
28
  // 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.
29
+ // (runner/learning-end.ts, reason `reset`), and the store refuses a save on a seed the agent's learning no longer holds
30
+ // (Store.learning save). No workflow is laid for it either: they are read at its seed's save, which is gone.
33
31
  import { ApiError } from "./errors.js";
34
32
  import { LearningInFlight } from "./learn/delete.js";
35
33
  import { isShadowRun } from "./learn/audit.js";
@@ -68,7 +66,7 @@ export async function resetLearning(host, agentId) {
68
66
  if (still.length)
69
67
  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
68
  // 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));
69
+ await keepResetLedger(host.store.settings, agentId, await promotionsOf(host.store.learning, agentId));
72
70
  // The watermark, before anything goes: learning reads no run that started, or read its seed, at or before it (each
73
71
  // seed is read in this queue, so one read before this moment never holds a later time). A seed read after the reset
74
72
  // in the same millisecond counts as before it: its run learns nothing (reason reset) and an SDK start is refused, to
@@ -80,7 +78,7 @@ export async function resetLearning(host, agentId) {
80
78
  const at = Date.now();
81
79
  await keepResetAt(host.store.settings, agentId, at);
82
80
  try {
83
- await host.deleteLearning(host.store, agentId, { keepResetLedger: true, agentDisk: true });
81
+ await host.deleteLearning(host.store, agentId, { keepResetLedger: true });
84
82
  }
85
83
  catch (error) {
86
84
  if (!(error instanceof LearningInFlight))
@@ -1,6 +1,6 @@
1
1
  import type { IncomingMessage, ServerResponse } from "node:http";
2
2
  import { type DraftDecisions } from "./learn/workflow-draft.js";
3
- import { type SnapHistory } from "./learn/folder.js";
3
+ import { type ItemHistory, type LearningRows, type LogChange } from "./learn/rows.js";
4
4
  import type { ServingState } from "./learn/promote.js";
5
5
  import { type ItemStatus, type Learning, type Shown } from "./learning.js";
6
6
  import type { Impact } from "./learning-run.js";
@@ -21,32 +21,21 @@ type Retired = {
21
21
  from?: "active" | "pending";
22
22
  why?: "unreadable";
23
23
  };
24
- type Change = {
25
- by: {
26
- run: string;
27
- } | {
28
- user: true;
29
- via?: string;
30
- };
31
- commit: string;
32
- at: string;
33
- reason: string;
34
- files: string[];
35
- };
24
+ type Change = LogChange;
36
25
  export type Counts = {
37
26
  merged: number;
38
27
  dropped: Record<string, number>;
39
28
  in_progress: number;
40
29
  };
41
30
  export { secretsShown, type Shown } from "./learning.js";
31
+ /** The store's learning, as these routes read and write it. */
32
+ type Rows = {
33
+ readonly learning: LearningRows;
34
+ };
42
35
  export declare const etagOf: (oid: string) => string;
43
- /** Run `runId`'s text taken off agent `agentId`'s learning folder's current files at its purge (learn/commit.ts
44
- * forgetRunText: a workflow it changed last goes back to the version before it that no purged run of `store` wrote),
45
- * in the agent's queue, as every write of the folder is. */
46
- export declare function forgetRunLearning(data: string, agentId: string, runId: string, store: Pick<Store, "runs">): Promise<void>;
47
36
  /** A workflow draft as the view lists it: its folder's name, its workflow.json with its `readme`, its description, its
48
- * status, the run whose merge last changed it, its size in bytes, and the ETag of its README.md (the file that says
49
- * whether it waits, which an approval names); cut of the host's secrets (a name or a file holding one reads [redacted]).
37
+ * status, the run whose text it is, its size in bytes, and the ETag of its README.md (the file that says whether it
38
+ * waits, which an approval names); cut of the host's secrets (a name or a file holding one reads [redacted]).
50
39
  * `status` is one word: its README.md's `pending` or `retired`, else where it stands as the promotions read says it
51
40
  * (`stateOf`, learn/promote.ts servingStateOf): `serving`, `checking`, `held` or `stopped`. */
52
41
  type WorkflowView = {
@@ -59,25 +48,26 @@ type WorkflowView = {
59
48
  bytes: number;
60
49
  etag: string;
61
50
  retired?: Retired;
62
- last_change?: SnapHistory["last"];
51
+ last_change?: ItemHistory["last"];
63
52
  };
64
- /** For tests: how many times a folder's statuses were read (once per commit of its main). */
53
+ /** For tests: how many times an agent's statuses were read (once per save of its learning). */
65
54
  export declare const pendingTestHooks: {
66
55
  reads: number;
67
56
  };
68
- /** Each workflow draft's status on agent `agentId`'s folder's main, by its workflow.json (as its README.md says it):
69
- * `active`, `pending` or `retired`. Built once per main (a list asks for many runs). A folder never made, or with no
70
- * main, holds none; one whose snapshot cannot be read is undefined. */
71
- export declare function statusesOf(data: string, agentId: string): Promise<ReadonlyMap<string, ItemStatus> | undefined>;
72
- /** How many of agent `agentId`'s workflow drafts wait for its owner's OK on its folder's main (statusesOf). A folder
73
- * never made has none waiting; one that cannot be read is undefined (the caller shows no count). */
74
- export declare function pendingCount(data: string, agentId: string): Promise<number | undefined>;
75
- /** GET /agents/{id}/learning: main, its corrections.md, its workflow drafts and the first page of its log, and how the
76
- * agent's runs fared and what learning changed for them (`counts`, `impact`); an agent with no folder (its learning
57
+ /** Each workflow draft's status at agent `agentId`'s newest save, by its workflow.json (as its README.md says it):
58
+ * `active`, `pending` or `retired`. Built once per save (a list asks for many runs): the newest save's id (of any kind,
59
+ * a purge's too) is read first, and the view, its items and their history, only when it moved. An agent with no save
60
+ * holds none; one whose learning cannot be read is undefined. */
61
+ export declare function statusesOf(rows: {
62
+ readonly learning: LearningRows & Pick<Store["learning"], "newestSave">;
63
+ }, agentId: string): Promise<ReadonlyMap<string, ItemStatus> | undefined>;
64
+ /** How many of agent `agentId`'s workflow drafts wait for its owner's OK at its newest save (statusesOf). An agent with
65
+ * no save has none waiting; one that cannot be read is undefined (the caller shows no count). */
66
+ export declare function pendingCount(rows: Parameters<typeof statusesOf>[0], agentId: string): Promise<number | undefined>;
67
+ /** GET /agents/{id}/learning: its newest save, its corrections.md, its workflow drafts and the first page of its log, and
68
+ * how the agent's runs fared and what learning changed for them (`counts`, `impact`); an agent with no save (its learning
77
69
  * never on) has an empty one. `stateOf`: where each workflow neither pending nor retired stands, by its folder name (the
78
- * promotions read's own word: learn/promote.ts servingStateOf over the agent's records). Through the purge gate
79
- * (purged-workflow.ts purgeGate, over `store`'s runs): no workflow a purged run wrote, and no purged run's merge in its
80
- * log. */
70
+ * promotions read's own word: learn/promote.ts servingStateOf over the agent's records). */
81
71
  type AgentView = {
82
72
  agent: string;
83
73
  main: string | null;
@@ -87,13 +77,13 @@ type AgentView = {
87
77
  counts: Counts;
88
78
  impact: Impact;
89
79
  };
90
- export declare function agentLearning(data: string, agentId: string, shown: Shown, counts: Counts, impact: Impact, stateOf: (workflow: string) => ServingState, store: Pick<Store, "runs">): Promise<AgentView>;
91
- /** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first, a purged run's left out
92
- * (purgeGate). */
93
- export declare function learningLog(data: string, agentId: string, query: URLSearchParams, shown: Shown, store: Pick<Store, "runs">): Promise<Page<Change>>;
94
- /** GET /agents/{id}/learning/corrections: corrections.md on main as text (empty when main holds none), its ETag (its blob
95
- * id; an empty file's when there is none) and the cap a PUT keeps to, cut of the host's secrets as every read is. */
96
- export declare function correctionsView(data: string, agentId: string, shown: Shown): Promise<{
80
+ export declare function agentLearning(rows: Rows, agentId: string, shown: Shown, counts: Counts, impact: Impact, stateOf: (workflow: string) => ServingState): Promise<AgentView>;
81
+ /** GET /agents/{id}/learning/log?cursor=&limit=: a page of the agent's log, newest first. */
82
+ export declare function learningLog(rows: Rows, agentId: string, query: URLSearchParams, shown: Shown): Promise<Page<Change>>;
83
+ /** GET /agents/{id}/learning/corrections: corrections.md at the newest save as text (empty when it holds none), its ETag
84
+ * (its blob id; an empty file's when there is none) and the cap a PUT keeps to, cut of the host's secrets as every read
85
+ * is. */
86
+ export declare function correctionsView(rows: Rows, agentId: string, shown: Shown): Promise<{
97
87
  text: string;
98
88
  etag: string;
99
89
  cap_bytes: number;
@@ -102,8 +92,8 @@ export declare function correctionsView(data: string, agentId: string, shown: Sh
102
92
  * read (`ifMatch`: its ETag; none, or `*`, is 428; another version is 412). Refused whole, nothing written, when it holds
103
93
  * what must never be stored (a host secret, text shaped like one, a hidden character) or passes the cap (422 with the
104
94
  * problems, printable). A text read cut of a secret and sent back replaces the secret with the cut: a person's write never
105
- * puts a secret back. In the agent's queue, one commit on main. */
106
- export declare function correctionsWrite(data: string, agentId: string, input: {
95
+ * puts a secret back. One save. */
96
+ export declare function correctionsWrite(rows: Rows, agentId: string, input: {
107
97
  text: string;
108
98
  ifMatch?: string;
109
99
  refuse: readonly string[];
@@ -112,8 +102,8 @@ export declare function correctionsWrite(data: string, agentId: string, input: {
112
102
  etag: string;
113
103
  cap_bytes: number;
114
104
  }>;
115
- /** One revision of a learned workflow: a commit on main that changed its workflow.json, with that commit's text (null
116
- * when the commit holds no such file: it was deleted there), cut of the host's secrets. */
105
+ /** One revision of a learned workflow: a save that changed its workflow.json, with its text there (null when the save
106
+ * deleted it), cut of the host's secrets. */
117
107
  type WorkflowRevision = {
118
108
  commit: string;
119
109
  at: string;
@@ -123,33 +113,26 @@ type WorkflowRevision = {
123
113
  digest: string | null;
124
114
  };
125
115
  /** GET /agents/{id}/learning/workflows/{name}/revisions?limit=: the latest revisions of learned workflow `name` (the
126
- * commits on main's log that changed `workflows/<name>/workflow.json`), oldest first, each with the workflow's text at
127
- * that commit, so a person can step through how it changed. One read-only exec per revision (textsAt), at most `limit`
128
- * of them. `total` counts every such commit the log holds, `truncated` says the log itself is cut (it keeps the latest
129
- * LOG_KEEP changes). A purged run's merge is no revision (purgeGate). A workflow no commit of the log changed is
116
+ * saves that changed `workflows/<name>/workflow.json`), oldest first, each with the workflow's text there, so a person
117
+ * can step through how it changed: at most `limit` of them. `total` counts every such save; `truncated` is false, the
118
+ * rows keep every one. A purged run's save is no revision: its rows went with it. A workflow no save changed is
130
119
  * not_found. */
131
- export declare function workflowRevisions(data: string, agentId: string, name: string, query: URLSearchParams, shown: Shown, store: Pick<Store, "runs">): Promise<{
120
+ export declare function workflowRevisions(rows: Rows, agentId: string, name: string, query: URLSearchParams, shown: Shown): Promise<{
132
121
  name: string;
133
122
  revisions: WorkflowRevision[];
134
123
  total: number;
135
124
  truncated: boolean;
136
125
  }>;
137
126
  /** Learned workflow `name`'s text at `digest` (a champion's, as its promotion records name it), read by that digest and
138
- * never by paging the workflow's history: at `commits` (the records' learning commits, newest first), then at main, the
139
- * first commit whose workflow.json is that digest's text, with the commit it was read at. Undefined when none is (no
140
- * main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (purgeGate), however
141
- * old. One read-only exec per commit tried (textsAt), and one more for the commit that holds the digest, unless
142
- * it is main (snapshotAt). */
143
- export declare function workflowAtDigest(data: string, agentId: string, name: string, digest: string, commits: readonly string[], store: Pick<Store, "runs">): Promise<{
127
+ * never by paging the workflow's history: its newest version whose workflow.json is that digest's, with the save it was
128
+ * written at. Undefined when none is. */
129
+ export declare function workflowAtDigest(rows: Rows, agentId: string, name: string, digest: string): Promise<{
144
130
  text: string;
145
131
  commit: string;
146
132
  } | undefined>;
147
- /** GET /agents/{id}/learning/files/{file}: a draft's file on main as text, its ETag, and its type (workflow.json is
148
- * JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404 any
149
- * missing file is. A file of a workflow still on main whose workflow.json a purged run wrote (its run purged before its
150
- * purge took the folder's text, until its DELETE is sent again) is 410 purged, as every route of that run is
151
- * (purgeGate). */
152
- export declare function readLearnedFile(data: string, agentId: string, raw: string, shown: Shown, store: Pick<Store, "runs">): Promise<{
133
+ /** GET /agents/{id}/learning/files/{file}: a draft's file at the newest save as text, its ETag, and its type
134
+ * (workflow.json is JSON). A purged run's workflow went with its rows, so its files are the 404 any missing file is. */
135
+ export declare function readLearnedFile(rows: Rows, agentId: string, raw: string, shown: Shown): Promise<{
153
136
  text: string;
154
137
  etag: string;
155
138
  type?: string;
@@ -174,22 +157,18 @@ type DraftTools = () => Promise<{
174
157
  decisions?: DraftDecisions;
175
158
  }>;
176
159
  /** POST /agents/{id}/learning/files/{file}/approve, .../retire or .../restore, as a person, on a draft's README.md
177
- * (`file`): If-Match on the version read (none, or `*`, is 428; another is 412), then one commit on main by the learning
178
- * script (learn/folder.ts writeLearning), in the agent's queue, its message `learning: <approved|retired|restored> by a
179
- * person: <file>` with a `Changed-By: user` trailer (and `Approved-Via: console` on an approval). An approval releases a
180
- * held draft (status: pending) to every later run; a retire takes it out of every later run unchecked, so a leaking one
181
- * can always be revoked; a restore brings it back to the status its retire recorded, checked again as a new draft is
182
- * (secrets' shapes, the host's values, hidden characters, its README's format, its workflow.json against the agent's
183
- * tools and gate). A retire of a retired draft commits nothing. An approval or a restore of a workflow whose
184
- * workflow.json a purged run wrote (still on main until its DELETE is sent again) is 410 purged (purgeGate over
185
- * `store`'s runs): no person's change gives it to a run; a retire takes it out as any other. `refuse`: the host's
186
- * secrets. */
187
- export declare function changeWorkflow(data: string, agentId: string, raw: string, input: {
160
+ * (`file`): If-Match on the version read (none, or `*`, is 428; another is 412), then one save of the agent's learning
161
+ * (learn/rows.ts writeLearning), its reason `<approved|retired|restored> by a person: <file>`, and an approval's said to
162
+ * come through the console. An approval releases a held draft (status: pending) to every later run; a retire takes it
163
+ * out of every later run unchecked, so a leaking one can always be revoked; a restore brings it back to the status its
164
+ * retire recorded, checked again as a new draft is (secrets' shapes, the host's values, hidden characters, its README's
165
+ * format, its workflow.json against the agent's tools and gate). A retire of a retired draft saves nothing. `refuse`:
166
+ * the host's secrets. */
167
+ export declare function changeWorkflow(rows: Rows, agentId: string, raw: string, input: {
188
168
  action: "approve" | "retire" | "restore";
189
169
  ifMatch?: string;
190
170
  refuse: readonly string[];
191
171
  draftTools?: DraftTools;
192
- store: Pick<Store, "runs">;
193
172
  }): Promise<{
194
173
  status: 200;
195
174
  file: string;
@@ -207,7 +186,7 @@ export declare function runLearningBody(input: {
207
186
  }, shown: Shown, secrets: readonly string[]): {
208
187
  run: string;
209
188
  state: "dropped" | "merged" | "seeded" | "reflecting";
210
- reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
189
+ reason: "cancelled" | "reset" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "empty" | "checker" | "use" | "purged_since_seed" | null;
211
190
  detail: string | null;
212
191
  at: string;
213
192
  workflows: import("./learning.js").LearnedFile[];
@@ -238,13 +217,13 @@ export declare function runLearningBody(input: {
238
217
  };
239
218
  };
240
219
  /** GET /runs/{id}/learning/diff over the one store: once merged (its learning end, store-reads/learning.ts
241
- * runLearningEnd), its merge commit against its parent, as its merge's script wrote it (`.agentrun/diffs/<run>.json` in
242
- * its agent's learning folder); a run that merged nothing, no file, against the seed its launch's learning start names. A
243
- * run that does not learn (no learning start and no learning end) is not_found. A file's patch is withheld when too large
244
- * (as the script wrote it), or when it holds one of the host's secrets now (`shown`); any other is served as every
245
- * learning text is (`shown.text`: a loopback address reads "a local address"). */
246
- export declare function runDiffOverStore(data: string, store: Store, runId: string, shown: Shown): Promise<{
247
- base: string;
220
+ * runLearningEnd), its merge's save against the one before it (learn/rows.ts runDiff); a run that merged nothing
221
+ * against the seed its launch's learning start names. A run that does not learn (no learning start and no learning
222
+ * end) is not_found, as a merge its agent's learning no longer holds is. A file's patch is withheld when too large, or
223
+ * when it holds one of the host's secrets now (`shown`); any other is served as every learning text is (`shown.text`:
224
+ * a loopback address reads "a local address"). */
225
+ export declare function runDiffOverStore(store: Store, runId: string, shown: Shown): Promise<{
226
+ base: string | null;
248
227
  head: string;
249
228
  files: ({
250
229
  path: string;