@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.55

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 (190) hide show
  1. package/CHANGELOG.md +110 -2
  2. package/README.md +266 -88
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/api-only.d.ts +16 -4
  9. package/dist/api-only.js +21 -7
  10. package/dist/cli.js +5 -3
  11. package/dist/composio-made.d.ts +26 -1
  12. package/dist/composio-made.js +39 -2
  13. package/dist/composio-preset.d.ts +3 -2
  14. package/dist/composio-preset.js +46 -14
  15. package/dist/computer-held-routes.js +2 -3
  16. package/dist/computer-setting.d.ts +4 -2
  17. package/dist/computer-setting.js +0 -2
  18. package/dist/computers-running.d.ts +8 -0
  19. package/dist/computers-running.js +27 -0
  20. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  21. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  22. package/dist/console/assets/index-DYhU4adm.css +1 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/docker-host-addresses.d.ts +23 -3
  25. package/dist/docker-host-addresses.js +90 -18
  26. package/dist/exa-keyless.d.ts +2 -3
  27. package/dist/exa-keyless.js +43 -127
  28. package/dist/firecrawl-keyless.d.ts +41 -0
  29. package/dist/firecrawl-keyless.js +152 -0
  30. package/dist/handed-secret.d.ts +3 -1
  31. package/dist/handed-secret.js +4 -2
  32. package/dist/harness-keys.d.ts +98 -0
  33. package/dist/harness-keys.js +247 -0
  34. package/dist/harness-recipe-entry.d.ts +14 -9
  35. package/dist/harness-recipe-entry.js +25 -14
  36. package/dist/harness-table.d.ts +16 -1
  37. package/dist/harness-table.js +19 -7
  38. package/dist/harness.d.ts +4 -0
  39. package/dist/harness.js +12 -1
  40. package/dist/host-check.d.ts +2 -0
  41. package/dist/host-check.js +6 -0
  42. package/dist/import-summary.d.ts +1 -1
  43. package/dist/import-summary.js +1 -1
  44. package/dist/import.d.ts +5 -5
  45. package/dist/import.js +54 -67
  46. package/dist/keyless-mcp.d.ts +36 -0
  47. package/dist/keyless-mcp.js +127 -0
  48. package/dist/learn/audit.d.ts +3 -3
  49. package/dist/learn/audit.js +3 -3
  50. package/dist/learn/commit.d.ts +8 -7
  51. package/dist/learn/commit.js +60 -20
  52. package/dist/learn/compile.d.ts +4 -3
  53. package/dist/learn/compile.js +7 -5
  54. package/dist/learn/folder.d.ts +16 -3
  55. package/dist/learn/folder.js +46 -13
  56. package/dist/learn/promote.d.ts +37 -13
  57. package/dist/learn/promote.js +112 -40
  58. package/dist/learn/secrets.js +10 -2
  59. package/dist/learning-routes.d.ts +22 -17
  60. package/dist/learning-routes.js +40 -39
  61. package/dist/learning.js +2 -2
  62. package/dist/manifest.d.ts +10 -0
  63. package/dist/manifest.js +30 -0
  64. package/dist/mcp-pin-first.d.ts +4 -2
  65. package/dist/mcp-pin-first.js +5 -2
  66. package/dist/mcp-secret-writes.d.ts +16 -7
  67. package/dist/mcp-secret-writes.js +35 -27
  68. package/dist/mcp-servers-store.d.ts +30 -6
  69. package/dist/mcp-servers-store.js +112 -28
  70. package/dist/mcp-sources.d.ts +10 -2
  71. package/dist/mcp-sources.js +9 -2
  72. package/dist/mcp-store.d.ts +13 -7
  73. package/dist/mcp-store.js +12 -9
  74. package/dist/model-form.d.ts +3 -2
  75. package/dist/model-form.js +11 -7
  76. package/dist/model.d.ts +20 -4
  77. package/dist/model.js +68 -9
  78. package/dist/native/history.d.ts +1 -1
  79. package/dist/native/history.js +2 -2
  80. package/dist/ollama-provider.d.ts +92 -0
  81. package/dist/ollama-provider.js +495 -0
  82. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  83. package/dist/openapi.js +127 -37
  84. package/dist/page.d.ts +11 -3
  85. package/dist/page.js +22 -7
  86. package/dist/place-offers.d.ts +17 -1
  87. package/dist/place-offers.js +46 -5
  88. package/dist/print.js +1 -1
  89. package/dist/purged-workflow.d.ts +35 -7
  90. package/dist/purged-workflow.js +73 -26
  91. package/dist/run-computer.d.ts +2 -0
  92. package/dist/run-computer.js +2 -0
  93. package/dist/run-files.d.ts +4 -0
  94. package/dist/run-files.js +4 -0
  95. package/dist/run-keys.d.ts +2 -4
  96. package/dist/run-keys.js +6 -7
  97. package/dist/run-launch.d.ts +4 -0
  98. package/dist/run-launch.js +4 -0
  99. package/dist/run-reads-over-store.d.ts +3 -2
  100. package/dist/run-reads-over-store.js +66 -2
  101. package/dist/run-secrets.js +5 -2
  102. package/dist/runner/adapter-loop.d.ts +6 -3
  103. package/dist/runner/adapter-loop.js +34 -15
  104. package/dist/runner/adapter-run-spec.d.ts +3 -0
  105. package/dist/runner/adapter-run-spec.js +5 -3
  106. package/dist/runner/audit.js +8 -4
  107. package/dist/runner/beside.d.ts +2 -1
  108. package/dist/runner/beside.js +6 -2
  109. package/dist/runner/claim-secrets.d.ts +5 -8
  110. package/dist/runner/claim-secrets.js +6 -0
  111. package/dist/runner/cli-run-spec.d.ts +1 -1
  112. package/dist/runner/cli-run-spec.js +38 -6
  113. package/dist/runner/harness-loops.d.ts +22 -9
  114. package/dist/runner/harness-loops.js +21 -11
  115. package/dist/runner/held.d.ts +3 -0
  116. package/dist/runner/learning-end.d.ts +1 -1
  117. package/dist/runner/learning-end.js +8 -3
  118. package/dist/runner/loop-contract.d.ts +5 -4
  119. package/dist/runner/main.js +4 -2
  120. package/dist/runner/mcp-claim.d.ts +3 -0
  121. package/dist/runner/mcp-claim.js +26 -2
  122. package/dist/runner/mcp-run.d.ts +3 -0
  123. package/dist/runner/mcp-run.js +2 -1
  124. package/dist/runner/metrics.d.ts +10 -10
  125. package/dist/runner/metrics.js +19 -38
  126. package/dist/runner/model-route.d.ts +3 -0
  127. package/dist/runner/model-route.js +6 -2
  128. package/dist/runner/promotion.d.ts +15 -9
  129. package/dist/runner/promotion.js +25 -15
  130. package/dist/runner/run-child-host.js +17 -7
  131. package/dist/runner/run-child.js +3 -1
  132. package/dist/runner/sdk-loop.js +2 -0
  133. package/dist/runner/workflow-loop.d.ts +2 -2
  134. package/dist/runner/workflow-loop.js +1 -2
  135. package/dist/runner/workflow-spec.d.ts +1 -1
  136. package/dist/runner/workflow-spec.js +6 -6
  137. package/dist/sdk/check.d.ts +4 -1
  138. package/dist/sdk/check.js +2 -1
  139. package/dist/sdk/runs.d.ts +2 -2
  140. package/dist/sdk/runs.js +8 -6
  141. package/dist/secret-cut.js +2 -1
  142. package/dist/secret-writes.d.ts +3 -2
  143. package/dist/secret-writes.js +1 -1
  144. package/dist/server.d.ts +44 -8
  145. package/dist/server.js +283 -108
  146. package/dist/standard-webhooks.d.ts +11 -0
  147. package/dist/standard-webhooks.js +20 -2
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/schema.js +5 -2
  150. package/dist/store/sqlite/store.js +90 -34
  151. package/dist/store/store.d.ts +54 -14
  152. package/dist/store-reads/journal.d.ts +7 -2
  153. package/dist/store-reads/journal.js +9 -6
  154. package/dist/store-reads/learning.d.ts +12 -9
  155. package/dist/store-reads/learning.js +18 -24
  156. package/dist/store-view.d.ts +0 -5
  157. package/dist/store-view.js +9 -8
  158. package/dist/template-eval.d.ts +49 -4
  159. package/dist/template-eval.js +168 -45
  160. package/dist/template-import.js +4 -2
  161. package/dist/templates.d.ts +5 -3
  162. package/dist/templates.js +19 -40
  163. package/dist/timeline/labels.d.ts +2 -2
  164. package/dist/timeline/labels.js +2 -2
  165. package/dist/timeline/timeline.d.ts +2 -2
  166. package/dist/timeline/timeline.js +1 -1
  167. package/dist/tool-plane.d.ts +17 -9
  168. package/dist/tool-plane.js +38 -17
  169. package/dist/tools.js +2 -2
  170. package/dist/trigger-launch-hook.d.ts +16 -8
  171. package/dist/trigger-launch-hook.js +32 -23
  172. package/dist/trigger-targets.d.ts +18 -8
  173. package/dist/trigger-targets.js +42 -19
  174. package/dist/triggers.d.ts +85 -23
  175. package/dist/triggers.js +303 -96
  176. package/dist/web-fake.js +3 -3
  177. package/dist/web-fetch-direct.d.ts +4 -0
  178. package/dist/web-fetch-direct.js +8 -1
  179. package/dist/web-fetch.d.ts +12 -3
  180. package/dist/web-fetch.js +47 -14
  181. package/dist/web-search.d.ts +33 -4
  182. package/dist/web-search.js +100 -41
  183. package/dist/webhooks.js +4 -5
  184. package/launcher/agentrun-serve +5 -1
  185. package/package.json +17 -13
  186. package/templates/README.md +2 -2
  187. package/dist/console/assets/index-B_85An2t.js +0 -745
  188. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  189. package/dist/import-sources.d.ts +0 -116
  190. package/dist/import-sources.js +0 -693
@@ -6,10 +6,11 @@
6
6
  // it was on the run's seed (or its `bases` commit) is a conflict, never written over;
7
7
  // - one line of an owner's feedback appended to corrections.md (appendCorrection), after the refusals;
8
8
  // - corrections.md replaced whole by a person (putCorrections), under the ETag they read;
9
- // - a purged run's learned workflows and feedback lines taken off main by the host (forgetRunText).
9
+ // - a purged run's learned workflows put back as they were before it (off main when it wrote them new) and its feedback
10
+ // lines taken off main, by the host (forgetRunText).
10
11
  import { isWorkspaceError } from "../workspace/index.js";
11
12
  import { CORRECTIONS_CAP, CORRECTIONS_FILE, correctionLine, correctionsProblems } from "./corrections.js";
12
- import { blobOid, DIFFS_DIR, folderFailure, FolderMerged, FolderRefused, FolderTooLarge, FolderUnreadable, forgetBody, learningRepair, readLearning, readRunDiff, readSnapshot, runDiffKey, runMergeOf, writeLearning } from "./folder.js";
13
+ import { blobOid, DIFFS_DIR, folderAt, folderFailure, FolderMerged, FolderRefused, FolderTooLarge, FolderUnreadable, forgetBody, learningRepair, readLearning, readRunDiff, readSnapshot, runDiffKey, runMergeOf, writeLearning } from "./folder.js";
13
14
  import { held, isHeld } from "./workflow-draft.js";
14
15
  /** The blob `path` is on the snapshot's main: corrections.md or a draft's file. */
15
16
  function blobOf(snapshot, path) {
@@ -161,16 +162,17 @@ export async function putCorrections(ws, input) {
161
162
  }
162
163
  /**
163
164
  * Run `runId`'s text taken off the folder's current files, at its purge (agent-delete.ts purgeRun): first its learned
164
- * workflows (forgetRunWorkflows), whether or not it left a diff file; then the lines each of its merges added to
165
- * corrections.md, as its diff file keeps them, dropped from main in one host commit per merge (a line a person edited
166
- * since is theirs and stays); each other merge's diff that shows such a line as context written without it; then the
167
- * run's diff files deleted, last, so a call stopped part way finds what it has left to do. Its merges stay in the
168
- * folder's git history until a learning reset or its agent's purge deletes the folder. Idempotent: each merge's scrub
169
- * lands once, nothing left to drop makes no commit, and a run with no diff file and no workflow here is no work.
165
+ * workflows (forgetRunWorkflows; `purged`: whether another run is purged), whether or not it left a diff file; then the
166
+ * lines each of its merges added to corrections.md, as its diff file keeps them, dropped from main in one host commit
167
+ * per merge (a line a person edited since is theirs and stays); each other merge's diff that shows such a line as
168
+ * context written without it; then the run's diff files deleted, last, so a call stopped part way finds what it has
169
+ * left to do. Its merges stay in the folder's git history until a learning reset or its agent's purge deletes the
170
+ * folder. Idempotent: each merge's scrub lands once, nothing left to drop makes no commit, and a run with no diff file
171
+ * and no workflow here is no work.
170
172
  * `commit`: the host's last commit, when one was made.
171
173
  */
172
- export async function forgetRunText(ws, runId) {
173
- let commit = await forgetRunWorkflows(ws, runId);
174
+ export async function forgetRunText(ws, runId, purged) {
175
+ let commit = await forgetRunWorkflows(ws, runId, async (run) => run === runId || (await purged(run)));
174
176
  const names = await diffNames(ws);
175
177
  const own = new RegExp(`^${runId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\.r\\d+)?\\.json(\\..+)?$`);
176
178
  const mine = names.filter((name) => own.test(name));
@@ -225,19 +227,57 @@ export async function forgetRunText(ws, runId) {
225
227
  await ws.remove(`${DIFFS_DIR}/${name}`, { force: true }).catch((error) => { throw folderFailure(error); });
226
228
  return commit ? { commit } : {};
227
229
  }
228
- /** Every path of the learned workflows on `snapshot`'s main whose workflow.json run `runId` wrote last (SnapLearned.run,
229
- * the rule purged-workflow.ts reads): each one's whole `workflows/<name>/` folder, its files and links. */
230
- const runWorkflowPaths = (snapshot, runId) => (snapshot?.workflows ?? []).filter((item) => item.run === runId).flatMap((item) => [...item.files.map(({ path }) => path), ...(item.links ?? [])]);
231
- /** Run `runId`'s learned workflows taken off main in one host commit, so every read of main finds them gone: the commit,
232
- * or undefined when main holds none (a repeat finds none left, and one another run wrote since names that run). The
233
- * snapshot is rebuilt from main first (one more exec): a merge that moved main and stopped before its snapshot leaves
234
- * one that names none of that merge's workflows, and finding no work commits nothing that would show it stale. */
235
- async function forgetRunWorkflows(ws, runId) {
230
+ /** Each learned workflow on main whose workflow.json run `runId` wrote last (SnapLearned.run, the rule purged-workflow.ts
231
+ * reads) put back in one host commit as it stood at the newest commit where its writer was no purged run (`purged`,
232
+ * `runId` among them), every file of its `workflows/<name>/` folder, its writer that run again (the commit's
233
+ * `Written-By` line: folder.ts writerOf); taken off main whole when the purged runs wrote every version of it. So a
234
+ * purge takes off main only what purged runs put there, and a version another run wrote, a champion included, stays
235
+ * served. The commit, or undefined when main holds none of the run's (a repeat finds its own put back, and one another
236
+ * run wrote since names that run). The snapshot is rebuilt from main first (two execs and a checkout): a merge that
237
+ * moved main and stopped before its snapshot leaves one that names none of that merge's workflows, and finding no work
238
+ * commits nothing that would show it stale. One more read-only exec of main's history when the run wrote one, and one
239
+ * per version put back; either read finding nothing refuses (FolderUnreadable), so no guess takes a folder off. */
240
+ async function forgetRunWorkflows(ws, runId, purged) {
236
241
  if (await readSnapshot(ws))
237
242
  await learningRepair(ws);
238
243
  const done = await writeLearning(ws, async ({ snapshot }) => {
239
- const deletes = runWorkflowPaths(snapshot, runId);
240
- return deletes.length ? { result: true, change: { by: { host: "a purged run's workflows removed" }, writes: [], deletes } } : { result: false };
244
+ const mine = (snapshot?.workflows ?? []).filter((item) => item.run === runId);
245
+ if (!mine.length)
246
+ return { result: false };
247
+ // No history read, no guess: a purge that can't tell what came before the run's version refuses (503, sent again
248
+ // later), and never takes the whole folder off main.
249
+ const unread = () => new FolderUnreadable(false, "the learning folder's history at main can't be read, so a purge puts nothing back and takes nothing off: send the DELETE again");
250
+ const history = await folderAt(ws, snapshot.main);
251
+ if (!history)
252
+ throw unread();
253
+ const writes = [];
254
+ const deletes = [];
255
+ const written = {};
256
+ for (const item of mine) {
257
+ // Newest first: the first writer no purged run is the version to put back, as it stood just before the next
258
+ // writer took the file over.
259
+ const writers = history.writers(item.name);
260
+ let back = [];
261
+ for (let i = 1; i < writers.length; i++) {
262
+ const { run } = writers[i];
263
+ if (run !== null && (await purged(run)))
264
+ continue;
265
+ const before = writers[i - 1].before;
266
+ const at = before ? await folderAt(ws, before) : undefined;
267
+ if (!at)
268
+ throw unread();
269
+ const files = at.snapshot.workflows.find((one) => one.name === item.name)?.files ?? [];
270
+ back = files.map(({ path, oid }) => ({ path, text: at.blobs.get(oid).toString("utf8") }));
271
+ // Named even when `back` is main's bytes already, so the writer still moves (folder.ts writtenIn).
272
+ if (back.length)
273
+ written[item.name] = run;
274
+ break;
275
+ }
276
+ writes.push(...back);
277
+ deletes.push(...[...item.files.map(({ path }) => path), ...(item.links ?? [])].filter((path) => !back.some((file) => file.path === path)));
278
+ }
279
+ const host = writes.length ? "a purged run's workflows put back as they were before it" : "a purged run's workflows removed";
280
+ return { result: true, change: { by: { host, written }, writes, deletes } };
241
281
  });
242
282
  return done.result ? done.main : undefined;
243
283
  }
@@ -1,6 +1,6 @@
1
1
  import type { RunRow, Store } from "../store/store.js";
2
2
  import type { AuthorHostAddendum } from "@parcha/agentrun-dsl";
3
- import { type AuditHold, type CheckRecord, type PromotionRecord } from "./promote.js";
3
+ import { type AuditHold, type CheckRecord, type PromotionRecord, type Refused } from "./promote.js";
4
4
  import type { Problem } from "./check.js";
5
5
  /** The info word that opens a workflow draft's block in a compile answer: ````workflow <name>, fenced with four backticks
6
6
  * so a ``` line inside does not close it. */
@@ -108,8 +108,9 @@ export declare function promotedOf(records: readonly PromotionRecord[], workflow
108
108
  /** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
109
109
  * that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
110
110
  * hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
111
- * compiles it again. */
112
- export declare function heldNamesOf(records: readonly PromotionRecord[]): Set<string>;
111
+ * compiles it again. A record `refused` names (the purge gate's: purged-workflow.ts refusedOf) is skipped as championOf
112
+ * skips it, so no purged run's revision is the champion or the hold a compile revises. */
113
+ export declare function heldNamesOf(records: readonly PromotionRecord[], refused?: Refused): Set<string>;
113
114
  /** The words a compile's promotion record starts with when every draft of its turn failed its checks (runner/
114
115
  * learning-end.ts recordDraftFailed): a hold with nothing checked, the compile's attempt all the same. */
115
116
  export declare const DRAFT_FAILED = "its draft failed its checks";
@@ -75,11 +75,13 @@ export function promotedOf(records, workflow, digest) {
75
75
  /** The learned workflows whose newest revision other than their champion (learn/promote.ts championOf, which serves while
76
76
  * that revision is held) is held: each one's compile turn is asked for a revision (once per hold). A champion's own
77
77
  * hold counts: with it held there is no champion. Not one a check stopped (its recompile's check held it too): nothing
78
- * compiles it again. */
79
- export function heldNamesOf(records) {
80
- return new Set([...new Set(records.map(({ workflow }) => workflow))].filter((name) => {
81
- const champion = championOf(records, name)?.digest;
82
- const newest = records.findLast((one) => one.workflow === name && one.digest !== champion);
78
+ * compiles it again. A record `refused` names (the purge gate's: purged-workflow.ts refusedOf) is skipped as championOf
79
+ * skips it, so no purged run's revision is the champion or the hold a compile revises. */
80
+ export function heldNamesOf(records, refused) {
81
+ const kept = refused ? records.filter((one) => !refused(one)) : records;
82
+ return new Set([...new Set(kept.map(({ workflow }) => workflow))].filter((name) => {
83
+ const champion = championOf(kept, name)?.digest;
84
+ const newest = kept.findLast((one) => one.workflow === name && one.digest !== champion);
83
85
  return newest?.decided === "hold" && !newest.check?.stopped && !newest.audit?.stopped;
84
86
  }));
85
87
  }
@@ -91,6 +91,8 @@ export type RunDiff = {
91
91
  };
92
92
  /** Git's blob id of `bytes`: the sha1 of "blob <length>\0" and the bytes. */
93
93
  export declare const blobOid: (bytes: Uint8Array | string) => string;
94
+ /** The draft a path is in, by name: `workflows/<name>/...`; else undefined. */
95
+ export declare function folderOf(path: string): string | undefined;
94
96
  /** A commit as the snapshot reads it: its time (git's %cI, as commitTime keeps it), subject, body and trailers. */
95
97
  type CommitInfo = {
96
98
  at: string;
@@ -130,7 +132,9 @@ export declare function snapshotOfRead(read: ReturnType<typeof parseRead>): Snap
130
132
  * that must be on main as they are on another commit (a run's seed). The script checks both on main as it commits. */
131
133
  export type FolderChange = {
132
134
  /** A run's merge names the run and its reason, and its `round` past the first (a follow-up's correction): its diff is
133
- * kept under runDiffKey. The host's own book-keeping (an audit row) names what it kept. */
135
+ * kept under runDiffKey. The host's own book-keeping (an audit row) names what it kept; a purge that puts a workflow's
136
+ * earlier version back names, by workflow, the run that wrote it (`written`: writerOf; null, none), which moves the
137
+ * writer even when the version put back is main's bytes already (the commit then changes no file). */
134
138
  by: {
135
139
  person: PersonKind;
136
140
  file: string;
@@ -141,6 +145,7 @@ export type FolderChange = {
141
145
  round?: number;
142
146
  } | {
143
147
  host: string;
148
+ written?: Readonly<Record<string, string | null>>;
144
149
  };
145
150
  writes: readonly {
146
151
  path: string;
@@ -272,11 +277,19 @@ export declare function commitChange(ws: Workspace, base: Snapshot | undefined,
272
277
  /** The snapshot of `commit` as main would have it (the script's read at that commit), or undefined when the folder has
273
278
  * no such commit. One exec, read-only: for a run's seed that is no longer main. */
274
279
  export declare function snapshotAt(ws: Workspace, commit: string): Promise<Snapshot | undefined>;
275
- /** `commit` as main would have it (snapshotAt) with the blobs its tree holds, by oid, as git gave them: one read-only
276
- * exec. Undefined when the folder has no such commit. */
280
+ /** A commit that made someone a workflow's writer (writerOf), that writer, and the commit before it (none for the first). */
281
+ export type WriterChange = {
282
+ commit: string;
283
+ before: string | undefined;
284
+ run: string | null;
285
+ };
286
+ /** `commit` as main would have it (snapshotAt) with the blobs its tree holds, by oid, as git gave them, and each
287
+ * workflow's writers over its first-parent history, newest first (`writers`): one read-only exec. Undefined when the
288
+ * folder has no such commit. */
277
289
  export declare function folderAt(ws: Workspace, commit: string): Promise<{
278
290
  snapshot: Snapshot;
279
291
  blobs: ReadonlyMap<string, Buffer>;
292
+ writers: (name: string) => WriterChange[];
280
293
  } | undefined>;
281
294
  /** The texts `commit` holds at `paths` (each a plain path, checkPath), each read alone with one read-only exec (the
282
295
  * script's show: git cat-file over each `<commit>:<path>`), never the whole tree, its blobs or its log, so the read is
@@ -58,7 +58,7 @@ export const blobOid = (bytes) => {
58
58
  const keyFile = (name) => `${WORKFLOWS_DIR}/${name}/README.md`;
59
59
  const viewFile = (name) => `${WORKFLOWS_DIR}/${name}/workflow.json`;
60
60
  /** The draft a path is in, by name: `workflows/<name>/...`; else undefined. */
61
- function folderOf(path) {
61
+ export function folderOf(path) {
62
62
  const [top, name, ...rest] = path.split("/");
63
63
  return top === WORKFLOWS_DIR && name && rest.length ? name : undefined;
64
64
  }
@@ -100,6 +100,23 @@ function changeEntry(commit, sha, files) {
100
100
  const paragraphs = commit.body.split(/\n\s*\n/).map((part) => part.trim()).filter(Boolean);
101
101
  return { commit: sha, at: new Date(commit.at).toISOString(), by, reason: paragraphs.slice(0, -1).join(" ") || commit.subject.replace(/^learning: /, ""), files };
102
102
  }
103
+ /** Who wrote workflow `name`'s workflow.json once `commit` changed it (SnapLearned.run), so the writer follows the bytes:
104
+ * a run's merge, its run; the host's commit, the run its `Written-By: <name> <run>` line names (a purge that put an
105
+ * earlier version back: commit.ts forgetRunWorkflows; a bare `Written-By: <name>`, none), else none; any other (a
106
+ * person's edit), undefined: the writer before it stays. Asked of a commit that changed the file, or one whose
107
+ * Written-By line names it (writtenIn: a put-back of main's own bytes changes no file). Both snapshot readers and
108
+ * folderAt's writers ask it. */
109
+ function writerOf(commit, name) {
110
+ const runId = commit.runId.split(",")[0].trim();
111
+ if (runId)
112
+ return runId;
113
+ if (!commit.subject.startsWith("host: "))
114
+ return undefined;
115
+ const line = commit.body.split("\n").find((one) => one === `Written-By: ${name}` || one.startsWith(`Written-By: ${name} `));
116
+ return line ? line.slice(`Written-By: ${name}`.length).trim() || null : null;
117
+ }
118
+ /** The workflows a host commit's Written-By lines name (writerOf): its writer moves with them, a file changed or not. */
119
+ const writtenIn = (commit) => commit.subject.startsWith("host: ") ? commit.body.split("\n").flatMap((line) => (line.startsWith("Written-By: ") ? [line.slice("Written-By: ".length).split(" ")[0]] : [])).filter(Boolean) : [];
103
120
  /** Whether a commit's message holds a line git's log of changes greps for: `Run-Id: ` or `Changed-By: user`. */
104
121
  const isChange = (commit) => `${commit.subject}\n${commit.body}`.split("\n").some((line) => line.startsWith("Run-Id: ") || line === "Changed-By: user");
105
122
  const byName = (a, b) => byBytes(a.name, b.name);
@@ -182,7 +199,6 @@ export function snapshotOfRead(read) {
182
199
  const log = [];
183
200
  let more = false;
184
201
  records.forEach(({ commit, sha, files }, i) => {
185
- const runId = commit.runId.split(",")[0].trim();
186
202
  for (const file of files) {
187
203
  if (!order.has(file))
188
204
  order.set(file, i);
@@ -191,8 +207,15 @@ export function snapshotOfRead(read) {
191
207
  history.set(file, foldNewer(undefined, commit));
192
208
  else
193
209
  foldOlder(known, commit);
194
- if (runId && !runs.has(file))
195
- runs.set(file, runId);
210
+ const name = folderOf(file);
211
+ const writer = name !== undefined && file === viewFile(name) && !runs.has(file) ? writerOf(commit, name) : undefined;
212
+ if (writer !== undefined)
213
+ runs.set(file, writer);
214
+ }
215
+ for (const name of writtenIn(commit)) {
216
+ const writer = !runs.has(viewFile(name)) ? writerOf(commit, name) : undefined;
217
+ if (writer !== undefined)
218
+ runs.set(viewFile(name), writer);
196
219
  }
197
220
  if (!isChange(commit))
198
221
  return;
@@ -265,7 +288,8 @@ function messageOf(by) {
265
288
  // The host's own book-keeping (an audit row): no trailer, so no change in the log a person reads.
266
289
  if ("host" in by) {
267
290
  const subject = `host: ${clean(by.host).trim() || "kept"}`;
268
- return { message: `${subject}\n`, subject, body: "", runId: "", changedBy: "", approvedVia: "" };
291
+ const body = Object.entries(by.written ?? {}).map(([name, run]) => `Written-By: ${name}${run ? ` ${run}` : ""}\n`).join("");
292
+ return { message: body ? `${subject}\n\n${body}` : `${subject}\n`, subject, body, runId: "", changedBy: "", approvedVia: "" };
269
293
  }
270
294
  if ("run" in by) {
271
295
  const subject = `learning: ${by.run}: merged`;
@@ -304,14 +328,15 @@ export function nextSnapshot(before, change, seconds) {
304
328
  const deletes = new Set(change?.deletes ?? []);
305
329
  const changed = [...new Set([...[...writes].filter(([path, { oid }]) => known.get(path) !== oid).map(([path]) => path), ...[...deletes].filter((path) => !writes.has(path))])].sort(byBytes);
306
330
  const touched = new Set(changed);
307
- const runId = commit.runId;
308
331
  const written = writes.get(CORRECTIONS_FILE);
309
332
  const corrections = written ? { path: CORRECTIONS_FILE, oid: written.oid, bytes: written.bytes } : deletes.has(CORRECTIONS_FILE) ? undefined : before?.corrections;
310
333
  const ledger = writes.get(AUDITS_FILE);
311
334
  const audits = ledger ? { oid: ledger.oid, bytes: ledger.bytes } : deletes.has(AUDITS_FILE) ? undefined : before?.audits;
312
335
  const list = before?.workflows ?? [];
313
336
  const hit = new Set(changed.map(folderOf).filter((name) => name !== undefined));
314
- const workflows = list.filter((item) => !hit.has(item.name)).map((item) => ({ ...item, order: item.order + 1 }));
337
+ // A Written-By line moves its workflow's writer whether or not the commit changes its files (writtenIn).
338
+ const named = new Set(writtenIn(commit));
339
+ const workflows = list.filter((item) => !hit.has(item.name)).map((item) => ({ ...item, order: item.order + 1, ...(named.has(item.name) ? { run: writerOf(commit, item.name) ?? null } : {}) }));
315
340
  for (const name of hit) {
316
341
  const old = list.find((item) => item.name === name);
317
342
  const prefix = `${WORKFLOWS_DIR}/${name}/`;
@@ -327,10 +352,11 @@ export function nextSnapshot(before, change, seconds) {
327
352
  const keyText = writes.get(key)?.text;
328
353
  // A link the change writes a file over, or deletes, is a link no more.
329
354
  const links = (old?.links ?? []).filter((path) => !writes.has(path) && !deletes.has(path));
355
+ const writer = touched.has(viewFile(name)) || named.has(name) ? writerOf(commit, name) : undefined;
330
356
  const item = learnedItem(name, [...files.values()], links, (path) => writes.get(path)?.text, {
331
357
  order: 0,
332
358
  history: touched.has(key) ? foldNewer(old?.history, commit) : (old?.history ?? { at: commit.at }),
333
- run: runId && touched.has(viewFile(name)) ? runId : (old?.run ?? null),
359
+ run: writer !== undefined ? writer : (old?.run ?? null),
334
360
  }, keyText === undefined && old ? { description: old.description, status: old.status, ...(old.retired_from ? { retired_from: old.retired_from } : {}) } : undefined);
335
361
  if (item)
336
362
  workflows.push(item);
@@ -629,8 +655,10 @@ export class FolderTooLarge extends Error {
629
655
  export async function commitChange(ws, base, change) {
630
656
  const seconds = Math.floor(Date.now() / 1000);
631
657
  const { snapshot, changed } = nextSnapshot(base, change, seconds);
632
- // A change that changes nothing on main is no commit: main stays, and nothing is run.
633
- if (base && change && !changed.length)
658
+ // A change that changes nothing on main is no commit: main stays, and nothing is run. One that moves a workflow's
659
+ // writer is a commit, its files the same (a purge's put-back of main's own bytes: writtenIn).
660
+ const moves = snapshot.workflows.some((item) => base?.workflows.find((one) => one.name === item.name)?.run !== item.run);
661
+ if (base && change && !changed.length && !moves)
634
662
  return { landed: true, main: base.main, snapshot: base };
635
663
  const writes = change?.writes ?? [];
636
664
  for (const { path } of writes)
@@ -680,8 +708,9 @@ export async function commitChange(ws, base, change) {
680
708
  export async function snapshotAt(ws, commit) {
681
709
  return (await folderAt(ws, commit))?.snapshot;
682
710
  }
683
- /** `commit` as main would have it (snapshotAt) with the blobs its tree holds, by oid, as git gave them: one read-only
684
- * exec. Undefined when the folder has no such commit. */
711
+ /** `commit` as main would have it (snapshotAt) with the blobs its tree holds, by oid, as git gave them, and each
712
+ * workflow's writers over its first-parent history, newest first (`writers`): one read-only exec. Undefined when the
713
+ * folder has no such commit. */
685
714
  export async function folderAt(ws, commit) {
686
715
  if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(commit))
687
716
  throw new Error(`${JSON.stringify(commit)} is not a commit`);
@@ -692,7 +721,11 @@ export async function folderAt(ws, commit) {
692
721
  throw failed("read", read);
693
722
  const parsed = parseRead(read.stdout);
694
723
  const snapshot = snapshotOfRead(parsed);
695
- return snapshot ? { snapshot, blobs: parsed.blobs } : undefined;
724
+ const writers = (name) => parsed.records.flatMap(({ commit: info, sha, files }, i) => {
725
+ const run = files.includes(viewFile(name)) || writtenIn(info).includes(name) ? writerOf(info, name) : undefined;
726
+ return run === undefined ? [] : [{ commit: sha, before: parsed.records[i + 1]?.sha, run }];
727
+ });
728
+ return snapshot ? { snapshot, blobs: parsed.blobs, writers } : undefined;
696
729
  }
697
730
  /** The texts `commit` holds at `paths` (each a plain path, checkPath), each read alone with one read-only exec (the
698
731
  * script's show: git cat-file over each `<commit>:<path>`), never the whole tree, its blobs or its log, so the read is
@@ -6,6 +6,10 @@ import type { ReplayOutcome } from "../runner/workflow-first.js";
6
6
  /** How many grades, and how many promotion records, an agent keeps (newest kept). */
7
7
  export declare const GRADES_KEPT = 500;
8
8
  export declare const PROMOTIONS_KEPT = 200;
9
+ /** How many champions of a workflow the promotions trim keeps back from the one the purge gate's answer leaves, that
10
+ * one included (trimPromotions): a purge that lands inside one write's ask-to-write window and refuses fewer than this
11
+ * many champions in a row still leaves one before them that serves. */
12
+ export declare const CHAMPIONS_KEPT = 5;
9
13
  /** The most characters a grade's words (`label`) may hold, and the most of them and of an answer a compile ask shows. */
10
14
  export declare const LABEL_MAX = 4000;
11
15
  export declare const GRADE_SOURCES: readonly ["feedback", "eval"];
@@ -259,8 +263,17 @@ export declare const promotionOf: (records: readonly PromotionRecord[], workflow
259
263
  /** The champion of `workflow`: the newest record of the digest promoted last, while that digest's newest record still
260
264
  * says promote. A newer revision replaying or held never stops it; it stops when a newer revision's check promotes that
261
265
  * one (then the champion), or when its own newest record is a hold (a held revision its owner replays, askReplay, that
262
- * promotes wins again). The money rule stops it on its own (runner/workflow-first.ts). Undefined: none. */
263
- export declare function championOf(records: readonly PromotionRecord[], workflow: string): PromotionRecord | undefined;
266
+ * promotes wins again). The money rule stops it on its own (runner/workflow-first.ts). A record `refused` names is
267
+ * skipped, as if absent: one whose commit holds its workflow as a purged run wrote it (purged-workflow.ts refusedOf), so
268
+ * after a purge of the champion's run the newest promotion the purge gate lets through serves again. Undefined: none. */
269
+ export declare function championOf(records: readonly PromotionRecord[], workflow: string, refused?: Refused): PromotionRecord | undefined;
270
+ /** The promotion records championOf skips (purged-workflow.ts refusedOf: the purge gate refuses each at its commit, so
271
+ * it names a record by its workflow and commit, a copy read later included). Every reader that serves or names the
272
+ * champion passes it, and the trim keeps the champion past it (trimPromotions). `unread`: a commit it asked could not be
273
+ * read, so it may refuse too few, and the trim trims nothing on it (recordPromotion fails closed). */
274
+ export type Refused = ((record: PromotionRecord) => boolean) & {
275
+ readonly unread?: boolean;
276
+ };
264
277
  /** The newest promotion of `workflow` at `digest`: the promote record that began its newest run of promote records (its
265
278
  * first, or the first after a record of that digest that was not promote: an owner's replay that promoted a held
266
279
  * revision), or undefined when none was ever promoted. Its `at` names that promotion: an audit row keeps the one serving
@@ -272,8 +285,8 @@ export declare function promotionStartOf(records: readonly PromotionRecord[], wo
272
285
  export declare function replayingOf(records: readonly PromotionRecord[], workflow: string, digest: string | null): PromotionRecord[];
273
286
  /** What each learned workflow with a record serves, by name: `digest`, its champion's (championOf; null: none serves,
274
287
  * the agent takes its runs), and `replaying`, the revision other than it whose check is at work (null: none). What the
275
- * promotions list says beside the records (GET /agents/{id}/learning/promotions). */
276
- export declare function servingOf(records: readonly PromotionRecord[]): {
288
+ * promotions list says beside the records (GET /agents/{id}/learning/promotions), its champion skipping `refused`. */
289
+ export declare function servingOf(records: readonly PromotionRecord[], refused?: Refused): {
277
290
  workflow: string;
278
291
  digest: string | null;
279
292
  replaying: string | null;
@@ -289,16 +302,16 @@ export type ServingState = "serving" | "checking" | "held" | "stopped";
289
302
  /** Whether the money rule stops `workflow` at `digest` from running first: runner/workflow-first.ts costStopOf over the
290
303
  * agent's runs, the decision a run's claim reads (workflowFirstOf). */
291
304
  export type CostStop = (workflow: string, digest: string) => boolean;
292
- export declare function servingStateOf(records: readonly PromotionRecord[], workflow: string, costStop: CostStop): ServingState;
305
+ export declare function servingStateOf(records: readonly PromotionRecord[], workflow: string, costStop: CostStop, refused?: Refused): ServingState;
293
306
  /** The promotions list as it leaves (GET /agents/{id}/learning/promotions): the records and what serves (servingOf), every
294
307
  * text in them cut by `shown` (learning.ts secretsShown, as the other learning reads cut theirs), at any depth and under
295
308
  * any field, so a field added later is cut too: a workflow's name whole (`shown.name`), any other text of its part
296
309
  * (`shown.text`: a reason, a digest, a run id). Numbers and the rest as they are. A replaying record's `launch` (a run
297
- * launch: its notes, model and plane) never leaves: aggregates only. */
310
+ * launch: its notes, model and plane) never leaves: aggregates only. Its champions skip `refused` (championOf). */
298
311
  export declare function promotionsShown(records: readonly PromotionRecord[], shown: {
299
312
  readonly text: (text: string) => string;
300
313
  readonly name: (name: string) => string;
301
- }): {
314
+ }, refused?: Refused): {
302
315
  promotions: PromotionRecord[];
303
316
  serving: ReturnType<typeof servingOf>;
304
317
  };
@@ -320,14 +333,25 @@ export type Recorded = {
320
333
  * and of every record kept (`items`: a check across revisions, one at a time, in the same guarded write): so of two
321
334
  * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). What the one
322
335
  * there now has blanked is blanked in `record` too (forgetRunIn): a record built on a copy read before a run's purge
323
- * (a connected agent's next turn, release or decision carries its turns on) never writes that run's text back. */
324
- export declare function recordPromotion(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, record: PromotionRecord, still: (now: PromotionRecord | undefined, items: readonly PromotionRecord[]) => boolean): Promise<Recorded>;
336
+ * (a connected agent's next turn, release or decision carries its turns on) never writes that run's text back. The trim
337
+ * keeps the champion past what the purge gate refuses too (`refused`, purged-workflow.ts refusedIn: asked before the
338
+ * guarded write when it would trim, over the records that write reads and `record` after them, so a promotion it lands
339
+ * for a revision the gate refuses is skipped as its readers skip it; a write that would trim records other than those
340
+ * it asked over, another writer's landing in between, reads and asks again). Fails closed: a gate that could not read
341
+ * a commit (Refused.unread) or could not be asked leaves every record, the write trims nothing. */
342
+ export declare function recordPromotion(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, record: PromotionRecord, still: (now: PromotionRecord | undefined, items: readonly PromotionRecord[]) => boolean, refused?: (records: readonly PromotionRecord[]) => Promise<Refused>): Promise<Recorded>;
325
343
  /** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
326
344
  * before, whatever was dropped: championOf reads the digest promoted last and its newest record, so the trim keeps both
327
- * (a held last revision is never trimmed into handing the champion back), and a replaying revision's newest record (what
328
- * its settle, its runs' claims and the one-check-at-a-time rule read: dropped, a newer revision would start a second
329
- * check while its runs run, and its verdict would never land). The rest is the newest records. */
330
- export declare function trimPromotions(items: readonly PromotionRecord[]): PromotionRecord[];
345
+ * (a held last revision is never trimmed into handing the champion back), read over every record and again past those
346
+ * `refused` names (the purge gate's: a champion its readers skip, so the earlier one they serve is kept), and a
347
+ * replaying revision's newest record (what its settle, its runs' claims and the one-check-at-a-time rule read: dropped,
348
+ * a newer revision would start a second check while its runs run, and its verdict would never land). Then the newest
349
+ * RECENT_KEPT records (the newest one, the record a write just landed, always: its write said it won, so its decision
350
+ * is there for the next claim). Then, in the room those leave, the champions before the one `refused` leaves, nearest
351
+ * first, CHAMPIONS_KEPT in all from that one (a purge landing after the gate answered refuses every champion its run
352
+ * wrote, two or more in a row: the newest one before them still serves), each one's promote and newest record whole
353
+ * or neither. The rest is the newest records. */
354
+ export declare function trimPromotions(items: readonly PromotionRecord[], refused?: Refused): PromotionRecord[];
331
355
  /** How many of a replay's own runs ended each way (a run not ended past its deadline is failed): what each run did. A
332
356
  * check record keeps them as it was decided on. */
333
357
  export type ReplayOutcomes = Readonly<Record<ReplayOutcome, number>>;