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

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 (194) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +188 -106
  3. package/dist/agent-delete.d.ts +6 -9
  4. package/dist/agent-delete.js +5 -3
  5. package/dist/agent-package.js +11 -1
  6. package/dist/api-only.d.ts +2 -2
  7. package/dist/api-only.js +3 -3
  8. package/dist/archil-routes.d.ts +4 -1
  9. package/dist/archil-routes.js +15 -12
  10. package/dist/archil-settings.d.ts +18 -8
  11. package/dist/archil-settings.js +35 -17
  12. package/dist/chatgpt-plan.d.ts +4 -2
  13. package/dist/chatgpt-plan.js +13 -3
  14. package/dist/claude-login-token.d.ts +5 -0
  15. package/dist/claude-login-token.js +8 -0
  16. package/dist/claude-login.d.ts +49 -3
  17. package/dist/claude-login.js +140 -10
  18. package/dist/cli-learning/connections.js +1 -1
  19. package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
  20. package/dist/console/assets/index-DZi-muIj.js +629 -0
  21. package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
  22. package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
  23. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  24. package/dist/console/index.html +3 -3
  25. package/dist/console/share.html +3 -3
  26. package/dist/decisions.d.ts +1 -1
  27. package/dist/decisions.js +2 -2
  28. package/dist/factory-activity.d.ts +68 -0
  29. package/dist/factory-activity.js +153 -0
  30. package/dist/factory-runs.d.ts +11 -0
  31. package/dist/factory-runs.js +52 -0
  32. package/dist/filed-tool.d.ts +32 -0
  33. package/dist/filed-tool.js +122 -0
  34. package/dist/harness-keys.d.ts +1 -2
  35. package/dist/harness-keys.js +1 -2
  36. package/dist/harness-table.d.ts +4 -0
  37. package/dist/harness-table.js +4 -0
  38. package/dist/harness.js +6 -2
  39. package/dist/import-worker.js +2 -2
  40. package/dist/import.d.ts +9 -0
  41. package/dist/import.js +11 -1
  42. package/dist/key-refusal.d.ts +5 -0
  43. package/dist/key-refusal.js +25 -15
  44. package/dist/learn/audit.d.ts +20 -22
  45. package/dist/learn/audit.js +72 -55
  46. package/dist/learn/check.js +1 -1
  47. package/dist/learn/commit.d.ts +35 -43
  48. package/dist/learn/commit.js +62 -270
  49. package/dist/learn/compile.d.ts +4 -4
  50. package/dist/learn/compile.js +6 -7
  51. package/dist/learn/corrections.js +1 -1
  52. package/dist/learn/delete.d.ts +5 -12
  53. package/dist/learn/delete.js +17 -30
  54. package/dist/learn/forget-run.d.ts +16 -0
  55. package/dist/learn/forget-run.js +53 -0
  56. package/dist/learn/index.js +1 -1
  57. package/dist/learn/learning-of.d.ts +0 -4
  58. package/dist/learn/learning-of.js +0 -5
  59. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  60. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  61. package/dist/learn/legacy/place.d.ts +16 -0
  62. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  63. package/dist/learn/legacy/scrub.d.ts +28 -0
  64. package/dist/learn/legacy/scrub.js +258 -0
  65. package/dist/learn/promote.d.ts +40 -66
  66. package/dist/learn/promote.js +69 -207
  67. package/dist/learn/reset-ledger.d.ts +18 -0
  68. package/dist/learn/reset-ledger.js +14 -0
  69. package/dist/learn/rows.d.ts +186 -0
  70. package/dist/learn/rows.js +376 -0
  71. package/dist/learn/workflow-draft.d.ts +4 -1
  72. package/dist/learn/workflow-draft.js +12 -2
  73. package/dist/learning-reset.d.ts +1 -1
  74. package/dist/learning-reset.js +9 -11
  75. package/dist/learning-routes.d.ts +60 -81
  76. package/dist/learning-routes.js +187 -360
  77. package/dist/learning-words.d.ts +2 -0
  78. package/dist/learning-words.js +2 -0
  79. package/dist/learning.d.ts +18 -24
  80. package/dist/learning.js +35 -66
  81. package/dist/mcp-gateway.d.ts +6 -0
  82. package/dist/mcp-gateway.js +44 -8
  83. package/dist/mcp-resources.d.ts +1 -1
  84. package/dist/native/discovery.d.ts +6 -0
  85. package/dist/native/discovery.js +14 -1
  86. package/dist/native/remote.d.ts +5 -0
  87. package/dist/native/remote.js +16 -0
  88. package/dist/native/runtime.js +3 -2
  89. package/dist/observation/observer.d.ts +6 -6
  90. package/dist/openapi.js +89 -29
  91. package/dist/place-offers.d.ts +3 -0
  92. package/dist/place-offers.js +3 -0
  93. package/dist/place.d.ts +33 -11
  94. package/dist/place.js +61 -26
  95. package/dist/purged-workflow.d.ts +0 -33
  96. package/dist/purged-workflow.js +3 -71
  97. package/dist/redact/match.d.ts +19 -4
  98. package/dist/redact/match.js +123 -30
  99. package/dist/run-launch.d.ts +3 -3
  100. package/dist/run-learning-served.d.ts +3 -3
  101. package/dist/run-learning-served.js +1 -1
  102. package/dist/run-listing.d.ts +1 -1
  103. package/dist/run-timeline-served.d.ts +1 -1
  104. package/dist/run-timeline-served.js +6 -5
  105. package/dist/runnable.js +25 -8
  106. package/dist/runner/adapter-run-spec.js +11 -20
  107. package/dist/runner/audit.d.ts +2 -4
  108. package/dist/runner/audit.js +28 -51
  109. package/dist/runner/cli-run-spec.js +8 -14
  110. package/dist/runner/compare-end.d.ts +0 -2
  111. package/dist/runner/compare-end.js +6 -2
  112. package/dist/runner/disk-free.d.ts +15 -4
  113. package/dist/runner/disk-free.js +25 -7
  114. package/dist/runner/feedback-round.d.ts +1 -1
  115. package/dist/runner/feedback-round.js +2 -2
  116. package/dist/runner/harness-loops.js +2 -3
  117. package/dist/runner/held.d.ts +0 -10
  118. package/dist/runner/held.js +0 -25
  119. package/dist/runner/journal-kinds.d.ts +4 -1
  120. package/dist/runner/journal-kinds.js +1 -1
  121. package/dist/runner/learned-first.d.ts +0 -2
  122. package/dist/runner/learned-first.js +3 -3
  123. package/dist/runner/learning-end.d.ts +12 -16
  124. package/dist/runner/learning-end.js +41 -75
  125. package/dist/runner/learning-seed.d.ts +13 -16
  126. package/dist/runner/learning-seed.js +13 -23
  127. package/dist/runner/main.js +1 -1
  128. package/dist/runner/mcp-run.d.ts +4 -0
  129. package/dist/runner/mcp-run.js +2 -0
  130. package/dist/runner/native-loop.js +2 -3
  131. package/dist/runner/promotion.d.ts +19 -28
  132. package/dist/runner/promotion.js +50 -69
  133. package/dist/runner/reflect-hook.d.ts +2 -2
  134. package/dist/runner/reflect-hook.js +4 -1
  135. package/dist/runner/run-child-host.d.ts +1 -9
  136. package/dist/runner/run-child-host.js +11 -67
  137. package/dist/runner/runner.d.ts +1 -1
  138. package/dist/runner/sdk-loop.js +2 -4
  139. package/dist/sdk/check.d.ts +1 -4
  140. package/dist/sdk/check.js +2 -3
  141. package/dist/sdk/runs.d.ts +20 -7
  142. package/dist/sdk/runs.js +105 -68
  143. package/dist/secrets.d.ts +4 -0
  144. package/dist/secrets.js +44 -10
  145. package/dist/server-fs.d.ts +1 -1
  146. package/dist/server-fs.js +1 -1
  147. package/dist/server-keys.d.ts +6 -0
  148. package/dist/server-keys.js +12 -0
  149. package/dist/server.d.ts +15 -15
  150. package/dist/server.js +214 -164
  151. package/dist/source-sync/auxiliary.js +2 -2
  152. package/dist/store/index.d.ts +1 -1
  153. package/dist/store/index.js +1 -1
  154. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  155. package/dist/store/schema.d.ts +28 -2
  156. package/dist/store/schema.js +81 -5
  157. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  158. package/dist/store/sqlite/learning-rows.js +559 -0
  159. package/dist/store/sqlite/store.d.ts +7 -1
  160. package/dist/store/sqlite/store.js +84 -18
  161. package/dist/store/store.d.ts +219 -6
  162. package/dist/store/store.js +13 -0
  163. package/dist/store-reads/journal.d.ts +33 -3
  164. package/dist/store-reads/journal.js +99 -4
  165. package/dist/store-reads/learning.d.ts +18 -22
  166. package/dist/store-reads/learning.js +35 -26
  167. package/dist/store-reads/loop.js +1 -1
  168. package/dist/store-view.d.ts +24 -2
  169. package/dist/store-view.js +40 -11
  170. package/dist/templates.d.ts +10 -2
  171. package/dist/templates.js +31 -4
  172. package/dist/tool-plane.d.ts +4 -2
  173. package/dist/tool-plane.js +9 -2
  174. package/dist/web-holds.d.ts +2 -0
  175. package/dist/web-holds.js +5 -2
  176. package/dist/web-run.js +2 -1
  177. package/dist/workspace/archil-exec.js +1 -1
  178. package/dist/workspace/archil.d.ts +1 -1
  179. package/dist/workspace/archil.js +1 -1
  180. package/dist/workspace/computer-deps.js +5 -3
  181. package/dist/workspace/computer-providers.d.ts +11 -1
  182. package/dist/workspace/computer-providers.js +29 -2
  183. package/dist/workspace/index.d.ts +1 -2
  184. package/dist/workspace/index.js +1 -2
  185. package/dist/workspace/paths.d.ts +0 -4
  186. package/dist/workspace/paths.js +0 -6
  187. package/dist/workspace/workspace.d.ts +1 -1
  188. package/dist/workspace/workspace.js +1 -1
  189. package/package.json +13 -13
  190. package/templates/TOOLS.md +46 -0
  191. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  192. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  193. package/dist/workspace/learning-workspace.d.ts +0 -24
  194. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -1,4 +1,4 @@
1
- import type { KeyEnv } from "../key-meta.js";
1
+ import { type KeyEnv } from "../key-meta.js";
2
2
  import type { Settings } from "../store/store.js";
3
3
  /** The file in the server's data root that holds its id (made once, kept across starts). */
4
4
  export declare const DATA_ROOT_FILE = "data-root.id";
@@ -19,7 +19,8 @@ export declare function sharesServerDisk(store: {
19
19
  }, dataDir: string): Promise<boolean | undefined>;
20
20
  /** Whether the server is in Mode 2, by what the server holds, never by this runner's environment: the Archil settings
21
21
  * saved in the store, or set in the server's own environment, whose names (never values) it says at each start
22
- * (runner-check.ts RUN_ENV_KEY). */
22
+ * (runner-check.ts RUN_ENV_KEY). The region is the one name a server in Mode 2 by its environment always has: its S3
23
+ * URL is the region's when it sets none, and a server whose settings there are not whole does not start. */
23
24
  export declare function serverInArchilMode(store: {
24
25
  settings: Pick<Settings, "get">;
25
26
  }): Promise<boolean>;
@@ -35,10 +36,20 @@ export declare function diskFreeRefusal(store: {
35
36
  export declare const DISK_FREE_MODE_1 = "this runner's data directory is not the server's, and the server keeps each run's folder on its own disk (Mode 1: the server holds no Archil settings, saved or in its environment), which this runner can't reach. Save the Archil settings so runs' folders are on Archil (Mode 2), or start the runner on the server's data directory.";
36
37
  /** A disk-free runner's words while the server is in Mode 2 by its own environment and this runner holds no Archil settings. */
37
38
  export declare const DISK_FREE_NO_ARCHIL: string;
39
+ /** Why a runner given a region without an S3 URL can't claim now, or undefined while it can. Such a runner reaches Archil
40
+ * at the region's S3 URL (archil-settings.ts ARCHIL_S3_URLS), and the server's may be another: the server is started with
41
+ * AGENTRUN_ARCHIL_S3_URL (its run-facing names say so, never the value, so one that is the region's own is refused too),
42
+ * or it is in Mode 2 by saved settings whose s3Url is not the runner's. Any runner, on the server's disk or not, on either
43
+ * store: a run's folder on Archil is reached by the runner and the server at one endpoint, or not claimed. */
44
+ export declare function archilS3Refusal(store: {
45
+ settings: Pick<Settings, "get">;
46
+ }, env: KeyEnv): Promise<string | undefined>;
47
+ /** A runner's words while it is given a region without an S3 URL and the server's S3 URL may be another (archilS3Refusal). */
48
+ export declare const ARCHIL_S3_URL_NOT_HELD: string;
38
49
  /** How long a gate's answer is kept between polls (diskFreeGate): a change of mode reaches a runner within this. */
39
50
  export declare const DISK_FREE_GATE_MS = 5000;
40
- /** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: diskFreeRefusal, its answer kept for
41
- * DISK_FREE_GATE_MS between polls and read again when asked fresh. */
51
+ /** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: archilS3Refusal, else diskFreeRefusal, its
52
+ * answer kept for DISK_FREE_GATE_MS between polls and read again when asked fresh. */
42
53
  export declare function diskFreeGate(store: {
43
54
  settings: Pick<Settings, "get">;
44
55
  }, dataDir: string, env: KeyEnv, storeKind: string, now?: () => number): (fresh: boolean) => Promise<string | undefined>;
@@ -12,7 +12,8 @@
12
12
  import { randomBytes } from "node:crypto";
13
13
  import { readFileSync, writeFileSync } from "node:fs";
14
14
  import { join } from "node:path";
15
- import { ARCHIL_SETTINGS_ENV, loadArchilSettings } from "../archil-settings.js";
15
+ import { ARCHIL_SETTINGS_ENV, archilSettingsFromEnv, loadArchilSettings } from "../archil-settings.js";
16
+ import { envValue } from "../key-meta.js";
16
17
  import { serverRunEnv } from "./runner-check.js";
17
18
  /** The file in the server's data root that holds its id (made once, kept across starts). */
18
19
  export const DATA_ROOT_FILE = "data-root.id";
@@ -52,12 +53,13 @@ export async function sharesServerDisk(store, dataDir) {
52
53
  }
53
54
  /** Whether the server is in Mode 2, by what the server holds, never by this runner's environment: the Archil settings
54
55
  * saved in the store, or set in the server's own environment, whose names (never values) it says at each start
55
- * (runner-check.ts RUN_ENV_KEY). */
56
+ * (runner-check.ts RUN_ENV_KEY). The region is the one name a server in Mode 2 by its environment always has: its S3
57
+ * URL is the region's when it sets none, and a server whose settings there are not whole does not start. */
56
58
  export async function serverInArchilMode(store) {
57
59
  if ((await loadArchilSettings(store)) !== undefined)
58
60
  return true;
59
61
  const names = await serverRunEnv(store);
60
- return names !== undefined && [ARCHIL_SETTINGS_ENV.region, ARCHIL_SETTINGS_ENV.s3Url].every((name) => names.includes(name));
62
+ return names !== undefined && names.includes(ARCHIL_SETTINGS_ENV.region);
61
63
  }
62
64
  /** Why a runner on `dataDir` can't serve the runs its store holds now, or undefined while it can. On Postgres, a runner
63
65
  * whose `dataDir` is not the server's disk can't while the server keeps runs' folders on that disk (Mode 1: the server
@@ -78,18 +80,34 @@ export async function diskFreeRefusal(store, dataDir, env, storeKind) {
78
80
  /** A disk-free runner's words while the server is in Mode 1: what the runner can't do, why, and the two ways out. */
79
81
  export const DISK_FREE_MODE_1 = "this runner's data directory is not the server's, and the server keeps each run's folder on its own disk (Mode 1: the server holds no Archil settings, saved or in its environment), which this runner can't reach. Save the Archil settings so runs' folders are on Archil (Mode 2), or start the runner on the server's data directory.";
80
82
  /** A disk-free runner's words while the server is in Mode 2 by its own environment and this runner holds no Archil settings. */
81
- export const DISK_FREE_NO_ARCHIL = `this runner's data directory is not the server's, and the server keeps each run's folder on Archil (Mode 2) by the Archil settings in its environment, which this runner does not hold. Hand this runner the server's ${ARCHIL_SETTINGS_ENV.region} and ${ARCHIL_SETTINGS_ENV.s3Url} (and ${ARCHIL_SETTINGS_ENV.image} when the server has it), or save the Archil settings in the store.`;
83
+ export const DISK_FREE_NO_ARCHIL = `this runner's data directory is not the server's, and the server keeps each run's folder on Archil (Mode 2) by the Archil settings in its environment, which this runner does not hold. Hand this runner the server's ${ARCHIL_SETTINGS_ENV.region} (and ${ARCHIL_SETTINGS_ENV.s3Url} and ${ARCHIL_SETTINGS_ENV.image} when the server has them), or save the Archil settings in the store.`;
84
+ /** Why a runner given a region without an S3 URL can't claim now, or undefined while it can. Such a runner reaches Archil
85
+ * at the region's S3 URL (archil-settings.ts ARCHIL_S3_URLS), and the server's may be another: the server is started with
86
+ * AGENTRUN_ARCHIL_S3_URL (its run-facing names say so, never the value, so one that is the region's own is refused too),
87
+ * or it is in Mode 2 by saved settings whose s3Url is not the runner's. Any runner, on the server's disk or not, on either
88
+ * store: a run's folder on Archil is reached by the runner and the server at one endpoint, or not claimed. */
89
+ export async function archilS3Refusal(store, env) {
90
+ if (envValue(env, ARCHIL_SETTINGS_ENV.region) === undefined || envValue(env, ARCHIL_SETTINGS_ENV.s3Url) !== undefined)
91
+ return undefined;
92
+ const names = await serverRunEnv(store);
93
+ if (names?.includes(ARCHIL_SETTINGS_ENV.region))
94
+ return names.includes(ARCHIL_SETTINGS_ENV.s3Url) ? ARCHIL_S3_URL_NOT_HELD : undefined;
95
+ const saved = await loadArchilSettings(store);
96
+ return saved !== undefined && saved.s3Url !== archilSettingsFromEnv(env)?.s3Url ? ARCHIL_S3_URL_NOT_HELD : undefined;
97
+ }
98
+ /** A runner's words while it is given a region without an S3 URL and the server's S3 URL may be another (archilS3Refusal). */
99
+ export const ARCHIL_S3_URL_NOT_HELD = `this runner is given ${ARCHIL_SETTINGS_ENV.region} without ${ARCHIL_SETTINGS_ENV.s3Url}, so it would reach Archil at its region's S3 URL, and the server's may be another (the server is started with ${ARCHIL_SETTINGS_ENV.s3Url}, or its saved Archil settings hold another s3Url): a run's folder is reached at the server's or not at all. Hand this runner the server's S3 URL as ${ARCHIL_SETTINGS_ENV.s3Url}.`;
82
100
  /** How long a gate's answer is kept between polls (diskFreeGate): a change of mode reaches a runner within this. */
83
101
  export const DISK_FREE_GATE_MS = 5_000;
84
- /** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: diskFreeRefusal, its answer kept for
85
- * DISK_FREE_GATE_MS between polls and read again when asked fresh. */
102
+ /** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: archilS3Refusal, else diskFreeRefusal, its
103
+ * answer kept for DISK_FREE_GATE_MS between polls and read again when asked fresh. */
86
104
  export function diskFreeGate(store, dataDir, env, storeKind, now = Date.now) {
87
105
  let kept;
88
106
  return async (fresh) => {
89
107
  const at = now();
90
108
  if (!fresh && kept && at - kept.at < DISK_FREE_GATE_MS)
91
109
  return kept.words;
92
- const words = await diskFreeRefusal(store, dataDir, env, storeKind);
110
+ const words = (await archilS3Refusal(store, env)) ?? (await diskFreeRefusal(store, dataDir, env, storeKind));
93
111
  kept = { at, words };
94
112
  return words;
95
113
  };
@@ -93,4 +93,4 @@ export declare function openFeedbackRound(store: Pick<Store, "runs" | "agents">,
93
93
  * round it asks for (openFeedbackRound), and only then marks the kept grade with that round and its steer. The grade is
94
94
  * kept first, so the round's end reads it; the round is named last, so a reopen that fails (thrown, or a run that can't
95
95
  * be opened again) leaves a grade naming none, never one claiming a round that didn't open. The grade as kept. */
96
- export declare function keepGrade(store: Pick<Store, "runs" | "agents" | "settings">, agentId: string, grade: Grade, label: string | undefined, canTurn?: (launch: RunLaunch) => boolean): Promise<Grade>;
96
+ export declare function keepGrade(store: Pick<Store, "runs" | "agents" | "learning">, agentId: string, grade: Grade, label: string | undefined, canTurn?: (launch: RunLaunch) => boolean): Promise<Grade>;
@@ -144,7 +144,7 @@ export async function openFeedbackRound(store, grade, label, canTurn = () => tru
144
144
  * kept first, so the round's end reads it; the round is named last, so a reopen that fails (thrown, or a run that can't
145
145
  * be opened again) leaves a grade naming none, never one claiming a round that didn't open. The grade as kept. */
146
146
  export async function keepGrade(store, agentId, grade, label, canTurn) {
147
- const kept = await putGrade(store.settings, agentId, { ...grade, feedback: null });
147
+ const kept = await putGrade(store.learning, agentId, { ...grade, feedback: null });
148
148
  const opened = await openFeedbackRound(store, kept, label, canTurn);
149
- return opened ? markGradeRound(store.settings, agentId, kept, opened) : kept;
149
+ return opened ? markGradeRound(store.learning, agentId, kept, opened) : kept;
150
150
  }
@@ -129,9 +129,8 @@ async function loopOn(deps, harness, launch, runId) {
129
129
  throw new NeverFits(tooBig);
130
130
  const entry = harnessOf(env, harness);
131
131
  // A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
132
- // where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
133
- // path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The spec is the loop's only source of a step; a run that does
134
- // not learn supplies none. The same for the pi and the CLI spec.
132
+ // (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The spec is the loop's only source of a step; a run that
133
+ // does not learn supplies none. The same for the pi and the CLI spec.
135
134
  return createAdapterLoop((claim, adapterRun) => entry?.facts && entry.adapter
136
135
  ? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
137
136
  : adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), { ...deps.modelRetry, ...(deps.tracing ? { tracing: deps.tracing } : {}) });
@@ -133,9 +133,6 @@ export interface Held {
133
133
  emailAccount(): Promise<OpenedAccount | undefined>;
134
134
  /** The server's calendar, opened, for a run whose revision grants calendar_events; else none. */
135
135
  calendar(): Promise<SavedCalendar | undefined>;
136
- /** A call of the run's agent's learning folder (learn/folder.ts), the runner's own Workspace of it, held to what a
137
- * run's learning does there (run-child-host.ts learningCall). */
138
- learning(method: string, args: readonly unknown[]): Promise<unknown>;
139
136
  /** The harness `name`'s install for the claim (harness-install.ts installForClaim), run by the runner. */
140
137
  install(name: string, signal?: AbortSignal): Promise<void>;
141
138
  /** The claim's computer (workspace/computer-for-claim.ts), made and held by the runner. */
@@ -185,13 +182,6 @@ export declare function heldSignInReads(): {
185
182
  peek(agentId: string, resolution: string): Promise<never>;
186
183
  forgotten(agentId: string, resolution: string): Promise<never>;
187
184
  };
188
- /** The agent's learning folder in a run's own process (learn/folder.ts learningWorkspace): each call made by its runner on
189
- * the folder of the claim's agent (Held.learning), whatever place this process names. No background program, mount or
190
- * attach: a learning folder has none. */
191
- export declare function heldLearningFolder(): {
192
- readonly workspace: Workspace;
193
- end(): Promise<void>;
194
- };
195
185
  /** A learning run's end-of-run step in a run's own process (learning-end.ts learningEndOfRun): its runner's
196
186
  * (Held.endOfRun), whatever deps the process would have built it with. */
197
187
  export declare function heldEndOfRun(): EndOfRunTurn;
@@ -22,31 +22,6 @@ export function heldSignInReads() {
22
22
  forgotten: (_agentId, resolution) => at.signInForgotten(resolution),
23
23
  };
24
24
  }
25
- /** The agent's learning folder in a run's own process (learn/folder.ts learningWorkspace): each call made by its runner on
26
- * the folder of the claim's agent (Held.learning), whatever place this process names. No background program, mount or
27
- * attach: a learning folder has none. */
28
- export function heldLearningFolder() {
29
- const at = heldOrThrow("a run's learning folder");
30
- const call = (method) => (...args) => at.learning(method, args);
31
- const none = (what) => async () => {
32
- throw new Error(`a learning folder has no ${what} in a run's own process`);
33
- };
34
- const workspace = {
35
- read: call("read"),
36
- write: call("write"),
37
- append: call("append"),
38
- stat: call("stat"),
39
- list: call("list"),
40
- mkdir: call("mkdir"),
41
- grep: call("grep"),
42
- remove: call("remove"),
43
- exec: call("exec"),
44
- process: { start: none("background program"), list: none("background program"), output: none("background program"), signal: none("background program"), wait: none("background program") },
45
- mountSpec: none("mount"),
46
- attach: none("attach"),
47
- };
48
- return { workspace, end: async () => { } };
49
- }
50
25
  /** A learning run's end-of-run step in a run's own process (learning-end.ts learningEndOfRun): its runner's
51
26
  * (Held.endOfRun), whatever deps the process would have built it with. */
52
27
  export function heldEndOfRun() {
@@ -110,7 +110,7 @@ export declare const KINDS: {
110
110
  readonly learningMerged: "agentrun.learning.merged";
111
111
  /** Why a learning run merged nothing, with the run's end. */
112
112
  readonly learningDropped: "agentrun.learning.dropped";
113
- /** The learning folder could not be reached: the run parks and tries again after a backoff. */
113
+ /** The learning could not be reached: the run parks and tries again after a backoff. */
114
114
  readonly learningUnavailable: "agentrun.learning.unavailable";
115
115
  /** A browser hand-over (pi-browser's browser_request_handoff), on the root. The run's browser host commits the ask, the
116
116
  * whole of it (HandoverAsked); its answer is an entry too (HandoverAnswered): the person's (a browser_hand_back row
@@ -191,6 +191,9 @@ export interface CallStartData {
191
191
  readonly parentCallId?: string;
192
192
  readonly tool: string;
193
193
  readonly input: unknown;
194
+ /** An SDK learned_workflow start whose input is stored withheld: the workflow it names, one the run was given, as the
195
+ * server kept it apart from the input (sdk/runs.ts SdkInbox.workflow_calls). Never the caller's text otherwise. */
196
+ readonly workflow?: string;
194
197
  /** May run again after a crash (it changes nothing outside the run): the tool registry's own flag. */
195
198
  readonly replaySafe: boolean;
196
199
  /** Written as its CLI's tool bridge's gate asked about it (adapter-loop.ts bridgeGate), before any answer: nothing is sent
@@ -110,7 +110,7 @@ export const KINDS = {
110
110
  learningMerged: "agentrun.learning.merged",
111
111
  /** Why a learning run merged nothing, with the run's end. */
112
112
  learningDropped: "agentrun.learning.dropped",
113
- /** The learning folder could not be reached: the run parks and tries again after a backoff. */
113
+ /** The learning could not be reached: the run parks and tries again after a backoff. */
114
114
  learningUnavailable: "agentrun.learning.unavailable",
115
115
  /** A browser hand-over (pi-browser's browser_request_handoff), on the root. The run's browser host commits the ask, the
116
116
  * whole of it (HandoverAsked); its answer is an entry too (HandoverAnswered): the person's (a browser_hand_back row
@@ -1,6 +1,5 @@
1
1
  import type { Context } from "@earendil-works/chord/context";
2
2
  import type { LearnedWorkflow, Shown } from "../learning.js";
3
- import type { LearningFolder } from "../learn/folder.js";
4
3
  import type { Recorded } from "../learn/replay-calls.js";
5
4
  import type { RunLaunch } from "../run-launch.js";
6
5
  import type { Store } from "../store/store.js";
@@ -20,7 +19,6 @@ export interface LearnedFirstDeps {
20
19
  readonly launch: RunLaunch;
21
20
  readonly context: Context;
22
21
  readonly log: (line: string) => void;
23
- readonly folder: () => LearningFolder;
24
22
  readonly shown: () => Promise<Shown>;
25
23
  readonly spendOff?: (what: string) => string | undefined;
26
24
  }
@@ -7,13 +7,13 @@ import { toolStopsOf, workflowFirstOf } from "./workflow-first.js";
7
7
  /** The claim's learned first choice over `laid`, the workflows its seed lay laid (see the file's head). A replay run's
8
8
  * claim that is refused throws ClaimRefused, as replayClaimed does. */
9
9
  export async function learnedFirst(deps, laid) {
10
- const { store, agentId, runId, revisionId, launch, context, log, folder, shown } = deps;
10
+ const { store, agentId, runId, revisionId, launch, context, log, shown } = deps;
11
11
  const own = { ...(deps.sealKey ? { sealKey: deps.sealKey } : {}), ...(deps.spendOff ? { spendOff: deps.spendOff } : {}), ...(deps.admitAuxiliary ? { admitAuxiliary: deps.admitAuxiliary } : {}) };
12
12
  // A replay run lays only the workflow it replays (promotion.ts replayLaid).
13
13
  const laidFlows = replayLaid(launch, laid);
14
14
  if (launch.learning && !launch.replay && !launch.audit)
15
- await settleAudits({ store, agentId, revisionId, context, log, folder, shown, ...own });
16
- const promotion = claimPromotion({ store, agentId, runId, revisionId, launch, context, log, folder, shown, ...own });
15
+ await settleAudits({ store, agentId, revisionId, context, log, shown, ...own });
16
+ const promotion = claimPromotion({ store, agentId, runId, revisionId, launch, context, log, shown, ...own });
17
17
  const learns = learnsWorkflows(deps.kind, laidFlows);
18
18
  // The agent's past runs, read once for both sides of the money rule: the platform's first choice and the agent's tool.
19
19
  let read;
@@ -1,6 +1,6 @@
1
1
  import { type EntryLike, type TimelineEvent } from "../timeline/index.js";
2
+ import type { AgentLearning } from "../learn/rows.js";
2
3
  import { type LearningChange, type LearningCommitResult } from "../learn/commit.js";
3
- import { type LearningFolder } from "../learn/folder.js";
4
4
  import { type CompileAsk, type CompileTrace, type DraftChecked } from "../learn/compile.js";
5
5
  import type { RunPath } from "../learning-cost.js";
6
6
  import { type RunLaunch } from "../run-launch.js";
@@ -8,16 +8,13 @@ import type { SignInReader } from "../run-view.js";
8
8
  import { type Store } from "../store/store.js";
9
9
  import type { EndOfRunTurn } from "./loop-contract.js";
10
10
  import { type DraftCommit } from "./reflect-hook.js";
11
- /** What the step reads: the run's store, the data directory (the server's tool settings a draft's tools are read with),
12
- * the agent's learning folder (where the run's place keeps it), the runner's environment (the host's secrets a draft or
11
+ /** What the step reads: the run's store (its agent's learning among it), the data directory (the server's tool settings
12
+ * a draft's tools are read with), the runner's environment (the host's secrets a draft or
13
13
  * a correction is refused for), and what the run was handed (its claim's keys, its sign-in's pointers through
14
14
  * `signIns`), which it never learns. */
15
15
  export interface LearningEndDeps {
16
16
  readonly store: Store;
17
17
  readonly data: string;
18
- /** Agent `agentId`'s learning folder, where the run's place keeps it: learningWorkspace({ mode: "local", agentId, data })
19
- * in Mode 1, { mode: "archil", agentId, archil } in Mode 2. Opened for each read or write, and ended after it. */
20
- readonly learningFolder: (agentId: string) => LearningFolder;
21
18
  readonly env?: NodeJS.ProcessEnv;
22
19
  /** The agent's sign-ins, opened (sign-ins-store.ts signInReads over the store and the seal key): the pointers the run's
23
20
  * row says it was handed are read back through them and never learned. Absent, a run marked as handed one learns
@@ -66,15 +63,14 @@ export declare function auditRoomOf(store: Pick<Store, "runs">, runId: string, l
66
63
  * kernel's unknownSpend refusal does, never "no room". */
67
64
  export declare function capSpendOf(store: Pick<Store, "runs">, runId: string, entries: readonly EntryLike[]): Promise<number | null>;
68
65
  /**
69
- * A run's merge on the agent's learning folder, written by the runner directly (learn/commit.ts learningCommit, one
70
- * exec): its compiled draft's files and its owner's correction, committed by `change.runId` (its Run-Id trailer). A file
71
- * changed on main since the run's seed (or a revision's `bases` commit) is a conflict, never written over; a correction
72
- * that holds what must never be stored, or would take corrections.md past its cap, is refused (past the cap beside a
73
- * draft, it is left out alone and the draft merges). Any failure is logged by its reason alone. The folder is always
74
- * released.
66
+ * A run's merge on the agent's learning, written by the runner directly (learn/commit.ts learningCommit, one save): its
67
+ * compiled draft's files and its owner's correction, saved by `change.runId`. A file changed since the run's seed (or a
68
+ * revision's `bases` save) is a conflict, never written over; a correction that holds what must never be stored, or
69
+ * would take corrections.md past its cap, is refused (past the cap beside a draft, it is left out alone and the draft
70
+ * merges). Any failure is logged by its reason alone.
75
71
  */
76
72
  export declare function commitDirect(deps: {
77
- readonly folder: () => LearningFolder;
73
+ readonly learning: AgentLearning;
78
74
  readonly log: (line: string) => void;
79
75
  }, change: LearningChange): Promise<LearningCommitResult>;
80
76
  /** What a run's owner said of it, in order, each a line for corrections.md: the grade's words its end closes (a feedback
@@ -133,9 +129,9 @@ export declare const draftFailedDigest: (runId: string) => string;
133
129
  * does (the agent's next due run compiles once more: learn/compile.ts newCompileAttempt); a recompile's (a revision of
134
130
  * a held workflow, or a new one after a first compile's failed drafts) stops (compileStoppedOf, heldNamesOf): nothing
135
131
  * compiles it again. A revision of a connected agent's hold on give-backs is no recompile (runner/promotion.ts
136
- * reviseAttemptOf). One record per run (its digest is the run's), written once: a claim that ends the run again
137
- * writes none. */
138
- export declare function recordDraftFailed(deps: Pick<LearningEndDeps, "store" | "log" | "learningFolder">, input: {
132
+ * reviseAttemptOf). One record per run (its digest is the run's, and the record is the run's: its purge takes it, and
133
+ * one written after that purge writes nothing), written once: a claim that ends the run again writes none. */
134
+ export declare function recordDraftFailed(deps: Pick<LearningEndDeps, "store" | "log">, input: {
139
135
  runId: string;
140
136
  agentId: string;
141
137
  compile: CompileAsk;
@@ -27,7 +27,7 @@ import { correctionRefused, learningCommit } from "../learn/commit.js";
27
27
  import { CAPS, checkDraft, problemWords, unstorable } from "../learn/index.js";
28
28
  import { repickSiteOf } from "../learn/check.js";
29
29
  import { repickLabelOf, repickRewrite } from "../learn/repick.js";
30
- import { folderAt, holdsCommit, readLearning, readSnapshot, runMergeOf, snapshotAt, textsAt } from "../learn/folder.js";
30
+ import { holdsSave, learningOf, readAt, readLearning, readOf, runMergeOf } from "../learn/rows.js";
31
31
  import { completedRun, compileStoppedOf, lastOwnRuns, sinceReset, compileDue, compilePrompt, compileReference, COMPILE_TRACES, DRAFT_FAILED, draftFailedOf, heldNamesOf, newCompileAttempt } from "../learn/compile.js";
32
32
  import { heldOnGiveBacks, reviseAttemptOf, sdkInputText } from "./promotion.js";
33
33
  import { loopOf, repickOf } from "../learning-setting.js";
@@ -44,7 +44,6 @@ import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
44
44
  import { FINAL_STATES } from "../store/store.js";
45
45
  import { shadowRunId } from "../learn/audit.js";
46
46
  import { getMcpServer } from "../mcp-store.js";
47
- import { purgeGate, refusedIn } from "../purged-workflow.js";
48
47
  import { readApprovers } from "../server-approvers.js";
49
48
  import { isCliRecord, runEntries, runTimeline, withoutFeedbackRounds } from "../store-reads/journal.js";
50
49
  import { capNowOf, KINDS } from "./journal-kinds.js";
@@ -105,7 +104,7 @@ export function learningEndOfRun(launch, deps) {
105
104
  },
106
105
  // A round whose merge is on main already (a stop after its commit, before its end was saved) is not checked for room
107
106
  // again: its merge gives back what it did.
108
- correctionRefused: ({ runId, agentId, round: at, text, refuse }) => withFolder(deps, agentId, (folder) => correctionRefused(folder.workspace, text, refuse, { runId, round: at })),
107
+ correctionRefused: ({ runId, agentId, round: at, text, refuse }) => correctionRefused(learningOf(deps.store, agentId), text, refuse, { runId, round: at }),
109
108
  // A run with no workflow binding (an SDK run's `noWorkflows`) compiles nothing.
110
109
  ...(start.noWorkflows ? {} : {
111
110
  compileFacts: (input) => compileAskOf(deps, { ...input, input: launch.input, ...(launch.sdk ? { sdkTask: sdkInputText(launch) } : {}), seedWorkflows: start.workflows?.length ?? 0, corrections: start.section }),
@@ -133,7 +132,7 @@ export function learningEndOfRun(launch, deps) {
133
132
  checkDraft: ({ runId, agentId, draft, refuse, revised }) => checkDraftOf(deps, { runId, agentId, seed, draft, refuse, ...(revised ? { revised } : {}) }),
134
133
  commit: async ({ runId, agentId, round: at, draft, correction, refuse }) => {
135
134
  const reason = draft ? `Compiled the job as workflow ${draft.name}${correction !== undefined ? ", with its owner's correction" : ""}.` : "Its owner's correction.";
136
- const done = await commitDirect({ folder: () => deps.learningFolder(agentId), log: deps.log ?? (() => undefined) }, {
135
+ const done = await commitDirect({ learning: learningOf(deps.store, agentId), log: deps.log ?? (() => undefined) }, {
137
136
  runId, round: at, reason, seed, ...(mustHold ? { mustHold } : {}), files: draft ? draft.files.map((file) => ({ ...file })) : [],
138
137
  ...(draft?.held?.length ? { held: [...draft.held] } : {}), ...(draft?.bases ? { bases: draft.bases } : {}),
139
138
  ...(correction !== undefined ? { correction, refuseValues: refuse } : {}),
@@ -153,15 +152,14 @@ export function learningEndOfRun(launch, deps) {
153
152
  // The one check at the entry of a run's learning end, before any merge, look-back, compile, draft check or record: a
154
153
  // run whose seed was read at or before a reset of its agent's learning (its watermark, learn/promote.ts resetAtOf; a
155
154
  // start that records no time is read as before it) learns nothing, whole. Its corrections and compile would land on
156
- // what the reset left. Read by time alone: a Mode 2 run's end writes the folder on its disk, which never held the
157
- // seed the server read from its own folder, so a commit missing here says nothing of a reset.
155
+ // what the reset left.
158
156
  const reset = await resetAtOf(deps.store.settings, input.agentId);
159
157
  if (reset !== undefined && !(start.seededAt !== undefined && start.seededAt > reset)) {
160
158
  return { also: [{ table: "learning_proposals", row: { turn: null, proposal: { state: "dropped", reason: "reset", detail: said.reset } } }] };
161
159
  }
162
- // The second wall, once the agent's learning was reset: a seed this folder holds now is one its merge must still
163
- // find (commit.ts mustHold), so a reset after this check refuses the merge whole in the script.
164
- const mustHold = reset !== undefined && (await withFolder(deps, input.agentId, (folder) => holdsCommit(folder.workspace, start.seed))) ? start.seed : undefined;
160
+ // The second wall, once the agent's learning was reset: a seed its learning holds now is one its merge must still
161
+ // find (commit.ts mustHold), so a reset after this check refuses the merge whole in the save's own transaction.
162
+ const mustHold = reset !== undefined && (await holdsSave(learningOf(deps.store, input.agentId), start.seed)) ? start.seed : undefined;
165
163
  // Which end of the run this is: the round after the newest it kept (a follow-up opened the run again after it), else
166
164
  // its first. A replayed end reads the same round: its rows are written only with the end that closes it.
167
165
  const prior = await deps.store.learning.proposal(input.runId);
@@ -216,35 +214,18 @@ export async function capSpendOf(store, runId, entries) {
216
214
  const beside = await shadowBesideOf(store, runId);
217
215
  return beside === null ? null : spent + beside;
218
216
  }
219
- /** `read` over agent `agentId`'s learning folder, opened for it and always ended after. */
220
- async function withFolder(deps, agentId, read) {
221
- const folder = deps.learningFolder(agentId);
222
- try {
223
- return await read(folder);
224
- }
225
- finally {
226
- await folder.end().catch(() => undefined);
227
- }
228
- }
229
217
  /**
230
- * A run's merge on the agent's learning folder, written by the runner directly (learn/commit.ts learningCommit, one
231
- * exec): its compiled draft's files and its owner's correction, committed by `change.runId` (its Run-Id trailer). A file
232
- * changed on main since the run's seed (or a revision's `bases` commit) is a conflict, never written over; a correction
233
- * that holds what must never be stored, or would take corrections.md past its cap, is refused (past the cap beside a
234
- * draft, it is left out alone and the draft merges). Any failure is logged by its reason alone. The folder is always
235
- * released.
218
+ * A run's merge on the agent's learning, written by the runner directly (learn/commit.ts learningCommit, one save): its
219
+ * compiled draft's files and its owner's correction, saved by `change.runId`. A file changed since the run's seed (or a
220
+ * revision's `bases` save) is a conflict, never written over; a correction that holds what must never be stored, or
221
+ * would take corrections.md past its cap, is refused (past the cap beside a draft, it is left out alone and the draft
222
+ * merges). Any failure is logged by its reason alone.
236
223
  */
237
224
  export async function commitDirect(deps, change) {
238
- const folder = deps.folder();
239
- try {
240
- const done = await learningCommit(folder.workspace, change);
241
- if (!done.ok)
242
- deps.log(`learning: run ${change.runId}: its merge could not be written (${done.reason})`);
243
- return done;
244
- }
245
- finally {
246
- await folder.end();
247
- }
225
+ const done = await learningCommit(deps.learning, change);
226
+ if (!done.ok)
227
+ deps.log(`learning: run ${change.runId}: its merge could not be written (${done.reason})`);
228
+ return done;
248
229
  }
249
230
  /** A merge's result as the hook reads it. */
250
231
  const committedOf = (done) => done.ok ? { ok: true, commit: done.commit, ...(done.refusedCorrection ? { refusedCorrection: done.refusedCorrection } : {}) } : done.reason === "unavailable" ? { ok: false, reason: "unavailable", problems: [] } : { ok: false, reason: done.reason, problems: done.problems };
@@ -347,17 +328,13 @@ export async function checkDraftOf(deps, input) {
347
328
  const readmePath = `${WORKFLOWS_DIR}/${name}/README.md`;
348
329
  const revised = input.revised && input.revised.workflow === name && input.revised.base !== input.seed ? input.revised : undefined;
349
330
  const base = revised?.base ?? input.seed;
350
- const at = await withFolder(deps, input.agentId, async (folder) => {
351
- const now = await readSnapshot(folder.workspace);
352
- const snapshot = now?.main === base ? now : await snapshotAt(folder.workspace, base);
353
- if (!snapshot)
354
- throw new Error(`the learning folder has no commit ${base}`);
355
- return { snapshot, texts: (await textsAt(folder.workspace, base, [jsonPath, readmePath])) ?? {} };
356
- });
357
- if (at.texts[jsonPath] === json && at.texts[readmePath] === readme)
331
+ const at = await readAt(learningOf(deps.store, input.agentId), base);
332
+ if (!at)
333
+ throw new Error(`the agent's learning has no save ${base}`);
334
+ if (at.text(jsonPath) === json && at.text(readmePath) === readme)
358
335
  return { errors: [] };
359
336
  const refused = (problems) => ({ errors: problems.map((problem) => problemWords([problem])), problems });
360
- const held = new Set(at.snapshot.workflows.flatMap((item) => item.files.map(({ path }) => path)));
337
+ const held = new Set((at.view?.workflows ?? []).flatMap((item) => item.files.map(({ path }) => path)));
361
338
  const changeOf = (path, text) => ({ path, status: held.has(path) ? "modified" : "added", mode: "100644", bytes: Buffer.from(text) });
362
339
  // Its example is the run's own input, read as every text it gave is: one that holds what must never be stored refuses
363
340
  // the draft, said at its README, though it is never written there.
@@ -373,7 +350,7 @@ export async function checkDraftOf(deps, input) {
373
350
  // none of the compact state rule), so an SDK agent's drafts are never rewritten.
374
351
  const repick = workflowAdapters === undefined ? repickOf(await learningOfRun(deps.store, input.runId)) : undefined;
375
352
  // A draft whose text on main has a status is a person's call (retired, or waiting for their OK): never changed.
376
- const kept = at.snapshot.workflows.filter((item) => item.status !== "active").map((item) => item.file);
353
+ const kept = (at.view?.workflows ?? []).filter((item) => item.status !== "active").map((item) => item.file);
377
354
  const check = (text, dryRuns) => checkDraft({
378
355
  changes: [changeOf(jsonPath, text), changeOf(readmePath, readme)], refuseValues: input.refuse, tools, dsl,
379
356
  ...(Object.keys(gated).length ? { gated } : {}), ...(Object.keys(deniedBy).length ? { deniedBy } : {}), ...(decisions ? { decisions } : {}),
@@ -405,7 +382,7 @@ export async function checkDraftOf(deps, input) {
405
382
  else
406
383
  deps.log?.(`learning.repick: workflow ${name} is kept as compiled; its re-pick over the run's pages failed the checks (${[...new Set(again.map((problem) => problem.rule))].join(", ")})`);
407
384
  }
408
- if (text !== json && at.texts[jsonPath] === text && at.texts[readmePath] === readme)
385
+ if (text !== json && at.text(jsonPath) === text && at.text(readmePath) === readme)
409
386
  return { errors: [] };
410
387
  const files = [{ path: jsonPath, text }, { path: readmePath, text: readme }];
411
388
  return {
@@ -477,11 +454,11 @@ export const draftFailedDigest = (runId) => createHash("sha256").update(`draft-f
477
454
  * does (the agent's next due run compiles once more: learn/compile.ts newCompileAttempt); a recompile's (a revision of
478
455
  * a held workflow, or a new one after a first compile's failed drafts) stops (compileStoppedOf, heldNamesOf): nothing
479
456
  * compiles it again. A revision of a connected agent's hold on give-backs is no recompile (runner/promotion.ts
480
- * reviseAttemptOf). One record per run (its digest is the run's), written once: a claim that ends the run again
481
- * writes none. */
457
+ * reviseAttemptOf). One record per run (its digest is the run's, and the record is the run's: its purge takes it, and
458
+ * one written after that purge writes nothing), written once: a claim that ends the run again writes none. */
482
459
  export async function recordDraftFailed(deps, input) {
483
460
  try {
484
- const records = await promotionsOf(deps.store.settings, input.agentId);
461
+ const records = await promotionsOf(deps.store.learning, input.agentId);
485
462
  const attempt = input.compile.mode === "revise" ? reviseAttemptOf(records, input.compile.held) : newCompileAttempt(records);
486
463
  const { compile_after, agree_min, alone_min } = await loopOfRun(deps.store, input.runId);
487
464
  const workflow = input.compile.mode === "revise" ? input.compile.workflow : input.workflow;
@@ -489,7 +466,7 @@ export async function recordDraftFailed(deps, input) {
489
466
  const failed = input.errors.join("; ").slice(0, CHECK_TEXT_MAX) || "no draft passed";
490
467
  const reason = `${DRAFT_FAILED}: ${failed}. ${attempt === 2 ? "It was the recompile, so it stops: nothing compiles again until its owner acts" : "It is not promoted; the next due run compiles it once more"}`;
491
468
  const check = { compile_after, agree_min, alone_min, attempt, n: 0, agreed: 0, alone: 0, agent_agreed: 0, of: [], ...(attempt === 2 ? { stopped: true } : {}) };
492
- const kept = await recordPromotion(deps.store.settings, input.agentId, { workflow, digest, at: new Date().toISOString(), decided: "hold", reason, check }, (was) => was === undefined, refusedIn(() => deps.learningFolder(input.agentId), deps.store, deps.log));
469
+ const kept = await recordPromotion(deps.store.learning, input.agentId, { workflow, digest, at: new Date().toISOString(), decided: "hold", reason, check }, (was) => was === undefined, { anyDigest: true, runId: input.runId });
493
470
  if (kept.won)
494
471
  deps.log?.(`learning: run ${input.runId}: the compile of ${workflow} failed its checks (attempt ${attempt}${attempt === 2 ? ", stopped" : ""})`);
495
472
  }
@@ -543,10 +520,8 @@ export async function compileAskOf(deps, input) {
543
520
  const { agentId } = input;
544
521
  // A revision is asked only of a workflow its promotion holds, once per hold. The workflows whose newest revision other
545
522
  // than their champion (learn/promote.ts championOf: it serves while that one is held) is held: the run's own may be one.
546
- // A record the purge gate refuses is skipped as the champion's readers skip it (purged-workflow.ts refusedOf); a gate
547
- // that can't be asked skips none, and the text read below is gated again.
548
- const records = await promotionsOf(deps.store.settings, agentId).catch(() => []);
549
- const heldNames = heldNamesOf(records, records.length ? await refusedIn(() => deps.learningFolder(agentId), deps.store, deps.log)(records).catch(() => undefined) : undefined);
523
+ const records = await promotionsOf(deps.store.learning, agentId).catch(() => []);
524
+ const heldNames = heldNamesOf(records);
550
525
  // The loop's numbers on the agent's definition (the revision this run runs): the first compile waits for compile_after
551
526
  // completed agent runs, the ending one counted.
552
527
  const { compile_after: compileAfter } = await loopOfRun(deps.store, input.runId);
@@ -576,17 +551,15 @@ export async function compileAskOf(deps, input) {
576
551
  const shown = secretsShown(input.refuse);
577
552
  const holds = (value) => holdsSecret(typeof value === "string" ? value : (JSON.stringify(value) ?? ""), shown);
578
553
  const leftOut = { workflows: new Set(), traces: 0, input: false };
579
- const folder = deps.learningFolder(input.agentId);
580
- // `main`: the commit the snapshot read is main's at, which `current` was read from.
554
+ const learning = learningOf(deps.store, input.agentId);
555
+ // `main`: the save the read is at, which `current` was read from.
581
556
  let read;
582
557
  try {
583
- // A workflow a purged run wrote is neither counted nor told (purgeGate), on main or at a replayed round's parent.
584
- const readFrom = async ({ snapshot, body }) => {
585
- const purged = (await purgeGate(snapshot, deps.store)).workflows;
586
- const workflows = (snapshot?.workflows ?? []).filter(({ name, status }) => (status === "active" || status === "pending") && !purged.has(name));
558
+ const readFrom = async ({ view, text: textAt }) => {
559
+ const workflows = (view?.workflows ?? []).filter(({ status }) => status === "active" || status === "pending");
587
560
  const textOf = async (name) => {
588
561
  const file = workflows.find((one) => one.name === name)?.files.find(({ path }) => path.endsWith("/workflow.json"));
589
- const text = file ? await body(file.path, file.oid) : undefined;
562
+ const text = file ? textAt(file.path) : undefined;
590
563
  if (text === undefined || !(holds(name) || holds(text)))
591
564
  return text;
592
565
  leftOut.workflows.add(shown.name(name));
@@ -610,25 +583,18 @@ export async function compileAskOf(deps, input) {
610
583
  if (record?.decided === "hold" && !record.check?.stopped && !record.audit?.stopped)
611
584
  [held, current] = [record, fitting[0].workflow];
612
585
  }
613
- return { workflows: workflows.length, ...(current !== undefined ? { current } : {}), ...(held ? { held } : {}), ...(snapshot?.main ? { main: snapshot.main } : {}) };
586
+ return { workflows: workflows.length, ...(current !== undefined ? { current } : {}), ...(held ? { held } : {}), ...(view?.main ? { main: view.main } : {}) };
614
587
  };
615
- // A round that merged already (a crash between its commit and its end): main holds its own merge, so the turn is
616
- // decided again on main as that merge read it (its parent), and the replayed answer lands on the merge it made
617
- // (learn/commit.ts learningCommit: a round merges once), never a drop that leaves its commit unrecorded. A stop
618
- // between the merge and its diff file is read back from the run's ref (runMergeOf).
619
- const own = await runMergeOf(folder.workspace, input.runId, input.round);
620
- const before = own ? await folderAt(folder.workspace, own.parent) : undefined;
621
- read = before
622
- ? await readFrom({ snapshot: before.snapshot, body: async (path, oid) => { const blob = before.blobs.get(oid); if (!blob)
623
- throw new Error(`${path} is not in ${own.parent}`); return blob.toString("utf8"); } })
624
- : await readLearning(folder.workspace, readFrom);
588
+ // A round that merged already (a crash between its save and its end): the newest save holds its own merge, so the
589
+ // turn is decided again as that merge read it (the save before it), and the replayed answer lands on the merge it
590
+ // made (learn/commit.ts learningCommit: a round merges once), never a drop that leaves its save unrecorded.
591
+ const own = await runMergeOf(learning, input.runId, input.round);
592
+ const before = own ? (own.parent ? await readAt(learning, own.parent) : readOf(undefined)) : undefined;
593
+ read = before ? await readFrom(before) : await readLearning(learning, readFrom);
625
594
  }
626
595
  catch {
627
596
  return undefined;
628
597
  }
629
- finally {
630
- await folder.end().catch(() => undefined);
631
- }
632
598
  // What it left out, by name and count: said once the facts are gathered, or now when it asks nothing.
633
599
  const sayLeftOut = () => {
634
600
  const parts = [...[...leftOut.workflows].map((name) => `workflow \`${name}\``), ...(leftOut.traces ? [`${leftOut.traces} earlier run${leftOut.traces === 1 ? "" : "s"}`] : []), ...(leftOut.input ? ["the run's input"] : [])];
@@ -1,15 +1,14 @@
1
1
  import { type LearnedWorkflow, type Seed, type Shown } from "../learning.js";
2
- import type { LearningFolder } from "../learn/folder.js";
3
- import type { Store } from "../store/index.js";
4
- /** What a claim reads its seed with: the commit, the agent's learning folder where the run's place keeps it (opened for
5
- * the read and ended after it), the store whose runs say which are purged (a purged run's workflow is no seed's:
6
- * learning.ts seedAt; null in a run's own process, which reads no other run: its lay only tells its runner whether it
7
- * laid any, and the runner reads the seed again with its store, workflowsAt), the server's secrets as cuts (`shown`),
8
- * its log, and `workflows: false` for a run that takes none (an SDK run with no workflow binding). */
2
+ import { type LearningRows } from "../learn/rows.js";
3
+ /** What a claim reads its seed with: the save, the store's learning rows (a run's own process reads them through its
4
+ * runner, run-child-host.ts storeCall), the agent, the server's secrets as cuts (`shown`), its log, and
5
+ * `workflows: false` for a run that takes none (an SDK run with no workflow binding). */
9
6
  export interface LearningSeedLay {
10
7
  readonly seed: string | null;
11
- readonly folder: () => LearningFolder;
12
- readonly store: Pick<Store, "runs"> | null;
8
+ readonly store: {
9
+ readonly learning: LearningRows;
10
+ };
11
+ readonly agentId: string;
13
12
  readonly shown: () => Promise<Shown>;
14
13
  readonly log: (line: string) => void;
15
14
  readonly workflows?: false;
@@ -28,10 +27,8 @@ export declare const laidOf: (laid: LaidSeed | undefined) => {
28
27
  * secrets read (or a choice) that fails after the seed was read answers the seed with no learned workflow. Never
29
28
  * throws: a learning fault never stops a run. */
30
29
  export declare function layLearningSeed(lay: LearningSeedLay): Promise<LaidSeed | undefined>;
31
- /** The learned workflows the folder held active at `commit`, as a claim's read hands them to the learned_workflow tool
32
- * (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
33
- * what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
34
- * commit is gone. */
35
- export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown"> & {
36
- readonly store: Pick<Store, "runs">;
37
- }, commit: string | null): Promise<LearnedWorkflow[]>;
30
+ /** The learned workflows the agent's learning held active at save `save`, read now, as a claim's read hands them to the
31
+ * learned_workflow tool (chooseWorkflows): what a champion serves from while a newer revision of it is the newest
32
+ * (runner/promotion.ts), and what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the
33
+ * store cannot answer or the save is gone. */
34
+ export declare function workflowsAt(read: Pick<LearningSeedLay, "store" | "agentId" | "shown">, save: string | null): Promise<LearnedWorkflow[]>;