@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
@@ -14,6 +14,13 @@ import { isObject } from "../validate.js";
14
14
  /** How many grades, and how many promotion records, an agent keeps (newest kept). */
15
15
  export const GRADES_KEPT = 500;
16
16
  export const PROMOTIONS_KEPT = 200;
17
+ /** How many champions of a workflow the promotions trim keeps back from the one the purge gate's answer leaves, that
18
+ * one included (trimPromotions): a purge that lands inside one write's ask-to-write window and refuses fewer than this
19
+ * many champions in a row still leaves one before them that serves. */
20
+ export const CHAMPIONS_KEPT = 5;
21
+ /** How many of the newest records the promotions trim keeps ahead of the champions before (CHAMPIONS_KEPT): those only
22
+ * take the room the newest leave, so they never crowd out a decision a check just landed. */
23
+ const RECENT_KEPT = PROMOTIONS_KEPT / 2;
17
24
  /** The most characters a grade's words (`label`) may hold, and the most of them and of an answer a compile ask shows. */
18
25
  export const LABEL_MAX = 4_000;
19
26
  export const GRADE_SOURCES = ["feedback", "eval"];
@@ -176,12 +183,18 @@ export const promotionOf = (records, workflow, digest) => records.findLast((one)
176
183
  /** The champion of `workflow`: the newest record of the digest promoted last, while that digest's newest record still
177
184
  * says promote. A newer revision replaying or held never stops it; it stops when a newer revision's check promotes that
178
185
  * one (then the champion), or when its own newest record is a hold (a held revision its owner replays, askReplay, that
179
- * promotes wins again). The money rule stops it on its own (runner/workflow-first.ts). Undefined: none. */
180
- export function championOf(records, workflow) {
181
- const last = lastPromotedOf(records, workflow);
182
- const now = last === undefined ? undefined : promotionOf(records, workflow, last);
186
+ * promotes wins again). The money rule stops it on its own (runner/workflow-first.ts). A record `refused` names is
187
+ * skipped, as if absent: one whose commit holds its workflow as a purged run wrote it (purged-workflow.ts refusedOf), so
188
+ * after a purge of the champion's run the newest promotion the purge gate lets through serves again. Undefined: none. */
189
+ export function championOf(records, workflow, refused = NONE_REFUSED) {
190
+ const kept = records.filter((one) => one.workflow === workflow && !refused(one));
191
+ const last = lastPromotedOf(kept, workflow);
192
+ const now = last === undefined ? undefined : promotionOf(kept, workflow, last);
183
193
  return now?.decided === "promote" ? now : undefined;
184
194
  }
195
+ const NONE_REFUSED = () => false;
196
+ /** The gate's answer when it could not be asked at all: refuses none, said unread. */
197
+ const UNREAD = Object.assign(() => false, { unread: true });
185
198
  /** The newest promotion of `workflow` at `digest`: the promote record that began its newest run of promote records (its
186
199
  * first, or the first after a record of that digest that was not promote: an owner's replay that promoted a held
187
200
  * revision), or undefined when none was ever promoted. Its `at` names that promotion: an audit row keeps the one serving
@@ -218,19 +231,19 @@ export function replayingOf(records, workflow, digest) {
218
231
  }
219
232
  /** What each learned workflow with a record serves, by name: `digest`, its champion's (championOf; null: none serves,
220
233
  * the agent takes its runs), and `replaying`, the revision other than it whose check is at work (null: none). What the
221
- * promotions list says beside the records (GET /agents/{id}/learning/promotions). */
222
- export function servingOf(records) {
234
+ * promotions list says beside the records (GET /agents/{id}/learning/promotions), its champion skipping `refused`. */
235
+ export function servingOf(records, refused) {
223
236
  const names = [...new Set(records.map((one) => one.workflow))].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
224
237
  return names.map((workflow) => {
225
- const digest = championOf(records, workflow)?.digest ?? null;
238
+ const digest = championOf(records, workflow, refused)?.digest ?? null;
226
239
  return { workflow, digest, replaying: replayingOf(records, workflow, digest)[0]?.digest ?? null };
227
240
  });
228
241
  }
229
- export function servingStateOf(records, workflow, costStop) {
242
+ export function servingStateOf(records, workflow, costStop, refused) {
230
243
  const newest = records.findLast((one) => one.workflow === workflow);
231
244
  if (newest === undefined || newest.decided === "replaying")
232
245
  return "checking";
233
- const champion = championOf(records, workflow);
246
+ const champion = championOf(records, workflow, refused);
234
247
  if (champion)
235
248
  return costStop(workflow, champion.digest) ? "stopped" : "serving";
236
249
  return newest.decided === "hold" && (newest.check?.stopped || newest.audit?.stopped) ? "stopped" : "held";
@@ -239,9 +252,9 @@ export function servingStateOf(records, workflow, costStop) {
239
252
  * text in them cut by `shown` (learning.ts secretsShown, as the other learning reads cut theirs), at any depth and under
240
253
  * any field, so a field added later is cut too: a workflow's name whole (`shown.name`), any other text of its part
241
254
  * (`shown.text`: a reason, a digest, a run id). Numbers and the rest as they are. A replaying record's `launch` (a run
242
- * launch: its notes, model and plane) never leaves: aggregates only. */
243
- export function promotionsShown(records, shown) {
244
- return { promotions: records.map(({ launch: _, ...one }) => shownDeep(one, shown)), serving: servingOf(records).map((one) => shownDeep(one, shown)) };
255
+ * launch: its notes, model and plane) never leaves: aggregates only. Its champions skip `refused` (championOf). */
256
+ export function promotionsShown(records, shown, refused) {
257
+ return { promotions: records.map(({ launch: _, ...one }) => shownDeep(one, shown)), serving: servingOf(records, refused).map((one) => shownDeep(one, shown)) };
245
258
  }
246
259
  /** `value` cut as the promotions read cuts its records (promotionsShown), at any depth and under any field: a workflow's
247
260
  * name whole (`shown.name`), any other text of its part (`shown.text`). Numbers and the rest as they are. */
@@ -258,46 +271,105 @@ const blankedRuns = (record) => [...(record?.check?.disagreements ?? []), ...(re
258
271
  * and of every record kept (`items`: a check across revisions, one at a time, in the same guarded write): so of two
259
272
  * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). What the one
260
273
  * there now has blanked is blanked in `record` too (forgetRunIn): a record built on a copy read before a run's purge
261
- * (a connected agent's next turn, release or decision carries its turns on) never writes that run's text back. */
262
- export async function recordPromotion(settings, agentId, record, still) {
263
- let out = { record, won: true };
264
- await updateKept(settings, promotionsKey(agentId), (saved) => {
265
- const items = writtenOf(saved);
266
- const now = promotionOf(items, record.workflow, record.digest);
267
- if (!still(now, items)) {
268
- out = { record: now, won: false };
269
- return items;
270
- }
271
- const kept = blankedRuns(now).reduce(forgetRunIn, record);
272
- out = { record: kept, won: true };
273
- return trimPromotions([...items, kept]);
274
- });
275
- return out;
274
+ * (a connected agent's next turn, release or decision carries its turns on) never writes that run's text back. The trim
275
+ * keeps the champion past what the purge gate refuses too (`refused`, purged-workflow.ts refusedIn: asked before the
276
+ * guarded write when it would trim, over the records that write reads and `record` after them, so a promotion it lands
277
+ * for a revision the gate refuses is skipped as its readers skip it; a write that would trim records other than those
278
+ * it asked over, another writer's landing in between, reads and asks again). Fails closed: a gate that could not read
279
+ * a commit (Refused.unread) or could not be asked leaves every record, the write trims nothing. */
280
+ export async function recordPromotion(settings, agentId, record, still, refused) {
281
+ for (let tries = 0; tries < 20; tries++) {
282
+ let out;
283
+ const before = refused ? writtenOf(itemsOf(await settings.get(promotionsKey(agentId)))) : [];
284
+ const skip = refused && before.length >= PROMOTIONS_KEPT ? await refused([...before, record]).catch(() => UNREAD) : undefined;
285
+ const asked = JSON.stringify(before);
286
+ await updateKept(settings, promotionsKey(agentId), (saved) => {
287
+ const items = writtenOf(saved);
288
+ const now = promotionOf(items, record.workflow, record.digest);
289
+ if (!still(now, items)) {
290
+ out = { record: now, won: false };
291
+ return items;
292
+ }
293
+ const kept = blankedRuns(now).reduce(forgetRunIn, record);
294
+ if (refused && items.length >= PROMOTIONS_KEPT && JSON.stringify(items) !== asked) {
295
+ out = undefined;
296
+ return items;
297
+ }
298
+ out = { record: kept, won: true };
299
+ return skip?.unread ? [...items, kept] : trimPromotions([...items, kept], skip);
300
+ });
301
+ if (out)
302
+ return out;
303
+ }
304
+ throw new Error(`${promotionsKey(agentId)} kept changing under this write; try again`);
276
305
  }
277
306
  /** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
278
307
  * before, whatever was dropped: championOf reads the digest promoted last and its newest record, so the trim keeps both
279
- * (a held last revision is never trimmed into handing the champion back), and a replaying revision's newest record (what
280
- * its settle, its runs' claims and the one-check-at-a-time rule read: dropped, a newer revision would start a second
281
- * check while its runs run, and its verdict would never land). The rest is the newest records. */
282
- export function trimPromotions(items) {
308
+ * (a held last revision is never trimmed into handing the champion back), read over every record and again past those
309
+ * `refused` names (the purge gate's: a champion its readers skip, so the earlier one they serve is kept), and a
310
+ * replaying revision's newest record (what its settle, its runs' claims and the one-check-at-a-time rule read: dropped,
311
+ * a newer revision would start a second check while its runs run, and its verdict would never land). Then the newest
312
+ * RECENT_KEPT records (the newest one, the record a write just landed, always: its write said it won, so its decision
313
+ * is there for the next claim). Then, in the room those leave, the champions before the one `refused` leaves, nearest
314
+ * first, CHAMPIONS_KEPT in all from that one (a purge landing after the gate answered refuses every champion its run
315
+ * wrote, two or more in a row: the newest one before them still serves), each one's promote and newest record whole
316
+ * or neither. The rest is the newest records. */
317
+ export function trimPromotions(items, refused = NONE_REFUSED) {
283
318
  if (items.length <= PROMOTIONS_KEPT)
284
319
  return [...items];
285
320
  const keep = new Set();
321
+ // The champions before, by how far back: [0] is each workflow's nearest one, so the room goes to those first. Each is
322
+ // its promote and its newest record together.
323
+ const before = [];
286
324
  for (const workflow of new Set(items.map((one) => one.workflow))) {
287
325
  for (const one of replayingOf(items, workflow, null))
288
326
  keep.add(items.lastIndexOf(one));
289
- const last = lastPromotedOf(items, workflow);
290
- if (last === undefined)
291
- continue;
292
- keep.add(items.findLastIndex((one) => one.workflow === workflow && one.digest === last && one.decided === "promote"));
293
- keep.add(items.findLastIndex((one) => one.workflow === workflow && one.digest === last));
327
+ const passes = [NONE_REFUSED, refused];
328
+ for (let pass = 0; pass < passes.length; pass++) {
329
+ const skip = passes[pass];
330
+ const own = (one) => one.workflow === workflow && !skip(one);
331
+ const last = items.findLast((one) => own(one) && one.decided === "promote")?.digest;
332
+ if (last === undefined)
333
+ continue;
334
+ const found = [items.findLastIndex((one) => own(one) && one.digest === last && one.decided === "promote"), items.findLastIndex((one) => own(one) && one.digest === last)];
335
+ if (pass < 2)
336
+ for (const i of found)
337
+ keep.add(i);
338
+ else
339
+ (before[pass - 2] ??= []).push({ workflow, found });
340
+ // The champions before the one `refused` leaves: a purge that lands between the write's ask of the gate and its
341
+ // write refuses each one its run wrote, and the guard (the records read) never sees it, so its readers serve the
342
+ // newest one before them. Past CHAMPIONS_KEPT, or past the room, it fails closed: none serves, never a purged
343
+ // run's text.
344
+ if (pass >= 1 && pass < CHAMPIONS_KEPT)
345
+ passes.push((one) => skip(one) || (one.workflow === workflow && one.digest === last));
346
+ }
294
347
  }
295
- for (let i = items.length - 1, room = PROMOTIONS_KEPT - keep.size; i >= 0 && room > 0; i--) {
296
- if (keep.has(i))
348
+ const newest = (count) => {
349
+ for (let i = items.length - 1; i >= 0 && count > 0; i--) {
350
+ if (keep.has(i))
351
+ continue;
352
+ keep.add(i);
353
+ count -= 1;
354
+ }
355
+ };
356
+ newest(Math.max(keep.has(items.length - 1) ? 0 : 1, Math.min(RECENT_KEPT, PROMOTIONS_KEPT - keep.size)));
357
+ // A champion before goes in whole or not at all: its promote kept without the hold after it would read as promoted, and
358
+ // a revision held for its answers would serve again. One that does not fit cuts its workflow's chain there, so none
359
+ // further back is kept past it (that one would serve in place of the nearer one). The newest records that fill the
360
+ // rest never split one either: a promote they keep, they kept every record after it first.
361
+ const cut = new Set();
362
+ for (const { workflow, found } of before.flat()) {
363
+ if (cut.has(workflow))
297
364
  continue;
298
- keep.add(i);
299
- room -= 1;
365
+ const missing = new Set(found.filter((i) => !keep.has(i)));
366
+ if (keep.size + missing.size > PROMOTIONS_KEPT)
367
+ cut.add(workflow);
368
+ else
369
+ for (const i of missing)
370
+ keep.add(i);
300
371
  }
372
+ newest(PROMOTIONS_KEPT - keep.size);
301
373
  return items.filter((_, i) => keep.has(i));
302
374
  }
303
375
  /** The text inside an answer that is one unlabelled fence and nothing else, or undefined. */
@@ -2,7 +2,15 @@ import { posix } from "node:path";
2
2
  const SK_KEY = /(?<![A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}/;
3
3
  const SLACK_TOKEN = /xox[abposre]-[A-Za-z0-9-]{10,}|xapp-[A-Za-z0-9-]{10,}/;
4
4
  const GITHUB_TOKEN = /gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{20,}/;
5
- const JWT = /eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/;
5
+ /** A JWT: three base64url parts, the first two JSON objects ("eyJ"). It starts at the first "eyJ" of a run of a part's
6
+ * characters, wherever that run starts ("token-eyJ…" too), and not at a later "eyJ" in the same run: read from every
7
+ * "eyJ", a long dotless run was read to its end from each, quadratic in its length (180 s over 256 KiB of "eyJ"). A
8
+ * later start reaches the same "." the first does with fewer characters, so it finds nothing the first doesn't, and
9
+ * the lookbehind reads back only to the "eyJ" before it. */
10
+ const JWT = /eyJ(?<!eyJ[A-Za-z0-9_-]*?eyJ)[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/;
11
+ /** A private key block's header, its key type (RSA, EC, OPENSSH, ENCRYPTED) at most 64 characters each side: two
12
+ * unbounded runs read a long header of repeated words in quadratic time (24 s over 256 KiB of "PRIVATE KEY "). */
13
+ const PRIVATE_KEY = /-----BEGIN[ A-Z0-9]{0,64}PRIVATE KEY[ A-Z0-9]{0,64}-----/;
6
14
  /** A Standard Webhooks signing secret: `whsec_` and base64, this server's or any other's. */
7
15
  const WEBHOOK_SECRET = /whsec_[A-Za-z0-9+/]{24,}={0,2}/;
8
16
  /** The token after a `Bearer` scheme (RFC 6750's characters), in any case: twenty characters or more with a digit among
@@ -37,7 +45,7 @@ const SORT_CODE = /\bsort\s{1,3}code\s{0,3}(?:#|:|\bis\b)?\s{0,3}\d{2}[- ]?\d{2}
37
45
  const SHAPES = [
38
46
  ["AWS access key id", /(?:AKIA|ASIA)[0-9A-Z]{16}/],
39
47
  ["Google API key", /AIza[0-9A-Za-z_-]{35}/],
40
- ["private key block", /-----BEGIN[ A-Z0-9]*PRIVATE KEY[ A-Z0-9]*-----/],
48
+ ["private key block", PRIVATE_KEY],
41
49
  ["GitHub token", GITHUB_TOKEN],
42
50
  ["sk- key", SK_KEY],
43
51
  ["Slack token", SLACK_TOKEN],
@@ -40,11 +40,10 @@ export type Counts = {
40
40
  };
41
41
  export { secretsShown, type Shown } from "./learning.js";
42
42
  export declare const etagOf: (oid: string) => string;
43
- /** Which of `runIds` are purged, by the store's purge mark (its row's purge time). */
44
- export type PurgedOf = (runIds: readonly string[]) => Promise<ReadonlySet<string>>;
45
43
  /** Run `runId`'s text taken off agent `agentId`'s learning folder's current files at its purge (learn/commit.ts
46
- * forgetRunText), in the agent's queue, as every write of the folder is. */
47
- export declare function forgetRunLearning(data: string, agentId: string, runId: string): Promise<void>;
44
+ * forgetRunText: a workflow it changed last goes back to the version before it that no purged run of `store` wrote),
45
+ * in the agent's queue, as every write of the folder is. */
46
+ export declare function forgetRunLearning(data: string, agentId: string, runId: string, store: Pick<Store, "runs">): Promise<void>;
48
47
  /** A workflow draft as the view lists it: its folder's name, its workflow.json with its `readme`, its description, its
49
48
  * status, the run whose merge last changed it, its size in bytes, and the ETag of its README.md (the file that says
50
49
  * whether it waits, which an approval names); cut of the host's secrets (a name or a file holding one reads [redacted]).
@@ -76,8 +75,9 @@ export declare function pendingCount(data: string, agentId: string): Promise<num
76
75
  /** GET /agents/{id}/learning: main, its corrections.md, its workflow drafts and the first page of its log, and how the
77
76
  * agent's runs fared and what learning changed for them (`counts`, `impact`); an agent with no folder (its learning
78
77
  * never on) has an empty one. `stateOf`: where each workflow neither pending nor retired stands, by its folder name (the
79
- * promotions read's own word: learn/promote.ts servingStateOf over the agent's records). Its log serves no purged run's
80
- * merge (`purgedOf`). */
78
+ * promotions read's own word: learn/promote.ts servingStateOf over the agent's records). Through the purge gate
79
+ * (purged-workflow.ts purgeGate, over `store`'s runs): no workflow a purged run wrote, and no purged run's merge in its
80
+ * log. */
81
81
  type AgentView = {
82
82
  agent: string;
83
83
  main: string | null;
@@ -87,10 +87,10 @@ type AgentView = {
87
87
  counts: Counts;
88
88
  impact: Impact;
89
89
  };
90
- export declare function agentLearning(data: string, agentId: string, shown: Shown, counts: Counts, impact: Impact, stateOf: (workflow: string) => ServingState, purgedOf: PurgedOf): Promise<AgentView>;
90
+ export declare function agentLearning(data: string, agentId: string, shown: Shown, counts: Counts, impact: Impact, stateOf: (workflow: string) => ServingState, store: Pick<Store, "runs">): Promise<AgentView>;
91
91
  /** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first, a purged run's left out
92
- * (`purgedOf`). */
93
- export declare function learningLog(data: string, agentId: string, query: URLSearchParams, shown: Shown, purgedOf: PurgedOf): Promise<Page<Change>>;
92
+ * (purgeGate). */
93
+ export declare function learningLog(data: string, agentId: string, query: URLSearchParams, shown: Shown, store: Pick<Store, "runs">): Promise<Page<Change>>;
94
94
  /** GET /agents/{id}/learning/corrections: corrections.md on main as text (empty when main holds none), its ETag (its blob
95
95
  * id; an empty file's when there is none) and the cap a PUT keeps to, cut of the host's secrets as every read is. */
96
96
  export declare function correctionsView(data: string, agentId: string, shown: Shown): Promise<{
@@ -126,9 +126,9 @@ type WorkflowRevision = {
126
126
  * commits on main's log that changed `workflows/<name>/workflow.json`), oldest first, each with the workflow's text at
127
127
  * that commit, so a person can step through how it changed. One read-only exec per revision (textsAt), at most `limit`
128
128
  * of them. `total` counts every such commit the log holds, `truncated` says the log itself is cut (it keeps the latest
129
- * LOG_KEEP changes). A purged run's merge is no revision (`purgedOf`). A workflow no commit of the log changed is
129
+ * LOG_KEEP changes). A purged run's merge is no revision (purgeGate). A workflow no commit of the log changed is
130
130
  * not_found. */
131
- export declare function workflowRevisions(data: string, agentId: string, name: string, query: URLSearchParams, shown: Shown, purgedOf: PurgedOf): Promise<{
131
+ export declare function workflowRevisions(data: string, agentId: string, name: string, query: URLSearchParams, shown: Shown, store: Pick<Store, "runs">): Promise<{
132
132
  name: string;
133
133
  revisions: WorkflowRevision[];
134
134
  total: number;
@@ -137,17 +137,18 @@ export declare function workflowRevisions(data: string, agentId: string, name: s
137
137
  /** Learned workflow `name`'s text at `digest` (a champion's, as its promotion records name it), read by that digest and
138
138
  * never by paging the workflow's history: at `commits` (the records' learning commits, newest first), then at main, the
139
139
  * first commit whose workflow.json is that digest's text, with the commit it was read at. Undefined when none is (no
140
- * main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (purged-workflow.ts),
141
- * however old. One read-only exec per commit tried (textsAt), and one more for the commit that holds the digest, unless
140
+ * main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (purgeGate), however
141
+ * old. One read-only exec per commit tried (textsAt), and one more for the commit that holds the digest, unless
142
142
  * it is main (snapshotAt). */
143
143
  export declare function workflowAtDigest(data: string, agentId: string, name: string, digest: string, commits: readonly string[], store: Pick<Store, "runs">): Promise<{
144
144
  text: string;
145
145
  commit: string;
146
146
  } | undefined>;
147
147
  /** GET /agents/{id}/learning/files/{file}: a draft's file on main as text, its ETag, and its type (workflow.json is
148
- * JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404
149
- * any missing file is. A workflow.json still on main whose writer is purged (a run purged before purges took its
150
- * workflows off, until its DELETE is sent again) is 410 purged, as every route of that run is (purged-workflow.ts). */
148
+ * JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404 any
149
+ * missing file is. A file of a workflow still on main whose workflow.json a purged run wrote (its run purged before its
150
+ * purge took the folder's text, until its DELETE is sent again) is 410 purged, as every route of that run is
151
+ * (purgeGate). */
151
152
  export declare function readLearnedFile(data: string, agentId: string, raw: string, shown: Shown, store: Pick<Store, "runs">): Promise<{
152
153
  text: string;
153
154
  etag: string;
@@ -179,12 +180,16 @@ type DraftTools = () => Promise<{
179
180
  * held draft (status: pending) to every later run; a retire takes it out of every later run unchecked, so a leaking one
180
181
  * can always be revoked; a restore brings it back to the status its retire recorded, checked again as a new draft is
181
182
  * (secrets' shapes, the host's values, hidden characters, its README's format, its workflow.json against the agent's
182
- * tools and gate). A retire of a retired draft commits nothing. `refuse`: the host's secrets. */
183
+ * tools and gate). A retire of a retired draft commits nothing. An approval or a restore of a workflow whose
184
+ * workflow.json a purged run wrote (still on main until its DELETE is sent again) is 410 purged (purgeGate over
185
+ * `store`'s runs): no person's change gives it to a run; a retire takes it out as any other. `refuse`: the host's
186
+ * secrets. */
183
187
  export declare function changeWorkflow(data: string, agentId: string, raw: string, input: {
184
188
  action: "approve" | "retire" | "restore";
185
189
  ifMatch?: string;
186
190
  refuse: readonly string[];
187
191
  draftTools?: DraftTools;
192
+ store: Pick<Store, "runs">;
188
193
  }): Promise<{
189
194
  status: 200;
190
195
  file: string;
@@ -2,8 +2,8 @@ import { createHash } from "node:crypto";
2
2
  import { CORRECTIONS_CAP, draftProblems, frontKeys, isHeld, LEARNED_KEYS, learnedPlace, learnedStatus, printable, released, restorable, restoredLearned, retiredLearned, UNCLEAR_FRONT, unclearFront, unstorable, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
3
3
  import { readmeProblems } from "./learn/workflow-draft.js";
4
4
  import { forgetRunText, putCorrections, readCorrections } from "./learn/commit.js";
5
- import { blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, readLearning, PATCH_CAP, readRunDiff, readSnapshot, runDiffKey, snapshotAt, textsAt, writeLearning } from "./learn/folder.js";
6
- import { purgedRun, purgedWorkflows } from "./purged-workflow.js";
5
+ import { blobOid, FolderBusy, folderOf, FolderRefused, FolderTooLarge, FolderUnreadable, readLearning, PATCH_CAP, readRunDiff, readSnapshot, runDiffKey, snapshotAt, textsAt, writeLearning } from "./learn/folder.js";
6
+ import { purgedRun, purgeGate, purgedRows } from "./purged-workflow.js";
7
7
  import { ApiError, invalid } from "./errors.js";
8
8
  import { detailShown, filesView, learningFolderOf, reasonShown, withAgentRepo } from "./learning.js";
9
9
  import { isObject } from "./validate.js";
@@ -50,21 +50,14 @@ function routeFailure(error) {
50
50
  return error.link ? new Error(error.message) : new ApiError("unavailable", error.message);
51
51
  return error;
52
52
  }
53
- /** Whether a change of `snapshot`'s log is served: none by a purged run (a run's purge, agent-delete.ts purgeRun), so
54
- * the folder's history reads serve none of its merges. Asked at each read, so a log the folder rebuilds names them and
55
- * still serves none. */
56
- async function servedIn(snapshot, purgedOf) {
57
- const runs = [...new Set(snapshot.log.flatMap(({ by }) => ("run" in by ? [by.run] : [])))];
58
- const purged = runs.length ? await purgedOf(runs) : new Set();
59
- return ({ by }) => !("run" in by && purged.has(by.run));
60
- }
61
53
  /** Run `runId`'s text taken off agent `agentId`'s learning folder's current files at its purge (learn/commit.ts
62
- * forgetRunText), in the agent's queue, as every write of the folder is. */
63
- export async function forgetRunLearning(data, agentId, runId) {
54
+ * forgetRunText: a workflow it changed last goes back to the version before it that no purged run of `store` wrote),
55
+ * in the agent's queue, as every write of the folder is. */
56
+ export async function forgetRunLearning(data, agentId, runId, store) {
64
57
  await withAgentRepo(data, agentId, async () => {
65
58
  const { workspace: ws, end } = learningFolderOf(data, agentId);
66
59
  try {
67
- await forgetRunText(ws, runId);
60
+ await forgetRunText(ws, runId, async (run) => (await purgedRows(store, [run])).has(run));
68
61
  }
69
62
  catch (error) {
70
63
  throw routeFailure(error);
@@ -182,23 +175,24 @@ export async function pendingCount(data, agentId) {
182
175
  const status = await statusesOf(data, agentId);
183
176
  return status === undefined ? undefined : [...status.values()].filter((value) => value.status === "pending").length;
184
177
  }
185
- export async function agentLearning(data, agentId, shown, counts, impact, stateOf, purgedOf) {
178
+ export async function agentLearning(data, agentId, shown, counts, impact, stateOf, store) {
186
179
  return reading(data, agentId, async ({ snapshot, body }) => {
187
- const served = await servedIn(snapshot, purgedOf);
180
+ const gate = await purgeGate(snapshot, store, true);
188
181
  const corrections = (await readCorrections(snapshot, body)).text;
189
182
  // A retired draft whose README.md can't be read is said so (unclearFront), read from its file now, as the snapshot's
190
183
  // status was: a few retired items, one read each.
191
184
  const unread = async (item) => item.status === "retired" && unclearFront(await body(item.file, item.oid));
192
- return { agent: agentId, main: snapshot.main, corrections: shown.text(corrections), workflows: await Promise.all(snapshot.workflows.map(async (item) => workflowView(item, shown, stateOf, await unread(item)))), log: logPage(snapshot, 0, LOG_PAGE, shown, served), counts, impact };
185
+ const items = snapshot.workflows.filter(({ name }) => !gate.workflows.has(name));
186
+ return { agent: agentId, main: snapshot.main, corrections: shown.text(corrections), workflows: await Promise.all(items.map(async (item) => workflowView(item, shown, stateOf, await unread(item)))), log: logPage(snapshot, 0, LOG_PAGE, shown, gate.served), counts, impact };
193
187
  }, () => ({ agent: agentId, main: null, corrections: "", workflows: [], log: EMPTY, counts, impact }));
194
188
  }
195
189
  /** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first, a purged run's left out
196
- * (`purgedOf`). */
197
- export async function learningLog(data, agentId, query, shown, purgedOf) {
190
+ * (purgeGate). */
191
+ export async function learningLog(data, agentId, query, shown, store) {
198
192
  const { limit, at } = pageRequest(query, LOG_PAGE);
199
193
  return reading(data, agentId, async ({ snapshot }) => {
200
194
  const page = pageAt(agentId, snapshot, at);
201
- return logPage(page.snapshot, page.offset, limit, shown, await servedIn(page.snapshot, purgedOf));
195
+ return logPage(page.snapshot, page.offset, limit, shown, (await purgeGate(page.snapshot, store, true)).served);
202
196
  }, () => EMPTY);
203
197
  }
204
198
  /** GET /agents/{id}/learning/corrections: corrections.md on main as text (empty when main holds none), its ETag (its blob
@@ -244,9 +238,9 @@ const REVISIONS_DEFAULT = 20;
244
238
  * commits on main's log that changed `workflows/<name>/workflow.json`), oldest first, each with the workflow's text at
245
239
  * that commit, so a person can step through how it changed. One read-only exec per revision (textsAt), at most `limit`
246
240
  * of them. `total` counts every such commit the log holds, `truncated` says the log itself is cut (it keeps the latest
247
- * LOG_KEEP changes). A purged run's merge is no revision (`purgedOf`). A workflow no commit of the log changed is
241
+ * LOG_KEEP changes). A purged run's merge is no revision (purgeGate). A workflow no commit of the log changed is
248
242
  * not_found. */
249
- export async function workflowRevisions(data, agentId, name, query, shown, purgedOf) {
243
+ export async function workflowRevisions(data, agentId, name, query, shown, store) {
250
244
  if (!WORKFLOW_NAME.test(name))
251
245
  throw new ApiError("bad_request", "A workflow's folder is named with lowercase letters, digits, dashes and underscores.");
252
246
  const given = query.get("limit");
@@ -257,7 +251,7 @@ export async function workflowRevisions(data, agentId, name, query, shown, purge
257
251
  if (shown.name(path) !== path)
258
252
  throw new ApiError("not_found", "the agent's learning folder has no such workflow");
259
253
  const found = await reading(data, agentId, async ({ ws, snapshot }) => {
260
- const served = await servedIn(snapshot, purgedOf);
254
+ const { served } = await purgeGate(snapshot, store, true);
261
255
  const touched = snapshot.log.filter((change) => served(change) && change.files.includes(path));
262
256
  const latest = touched.slice(0, limit).reverse();
263
257
  const revisions = [];
@@ -277,8 +271,8 @@ export async function workflowRevisions(data, agentId, name, query, shown, purge
277
271
  /** Learned workflow `name`'s text at `digest` (a champion's, as its promotion records name it), read by that digest and
278
272
  * never by paging the workflow's history: at `commits` (the records' learning commits, newest first), then at main, the
279
273
  * first commit whose workflow.json is that digest's text, with the commit it was read at. Undefined when none is (no
280
- * main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (purged-workflow.ts),
281
- * however old. One read-only exec per commit tried (textsAt), and one more for the commit that holds the digest, unless
274
+ * main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (purgeGate), however
275
+ * old. One read-only exec per commit tried (textsAt), and one more for the commit that holds the digest, unless
282
276
  * it is main (snapshotAt). */
283
277
  export async function workflowAtDigest(data, agentId, name, digest, commits, store) {
284
278
  if (!WORKFLOW_NAME.test(name))
@@ -290,7 +284,7 @@ export async function workflowAtDigest(data, agentId, name, digest, commits, sto
290
284
  if (raw === undefined || createHash("sha256").update(raw).digest("hex").slice(0, 16) !== digest)
291
285
  continue;
292
286
  const at = commit === snapshot.main ? snapshot : await snapshotAt(ws, commit).catch(() => undefined);
293
- if (!at || (await purgedWorkflows(at, store)).has(name))
287
+ if (!at || (await purgeGate(at, store)).workflows.has(name))
294
288
  continue;
295
289
  return { text: raw, commit };
296
290
  }
@@ -325,9 +319,10 @@ function fileOf(raw, use) {
325
319
  return file;
326
320
  }
327
321
  /** GET /agents/{id}/learning/files/{file}: a draft's file on main as text, its ETag, and its type (workflow.json is
328
- * JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404
329
- * any missing file is. A workflow.json still on main whose writer is purged (a run purged before purges took its
330
- * workflows off, until its DELETE is sent again) is 410 purged, as every route of that run is (purged-workflow.ts). */
322
+ * JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404 any
323
+ * missing file is. A file of a workflow still on main whose workflow.json a purged run wrote (its run purged before its
324
+ * purge took the folder's text, until its DELETE is sent again) is 410 purged, as every route of that run is
325
+ * (purgeGate). */
331
326
  export async function readLearnedFile(data, agentId, raw, shown, store) {
332
327
  const file = fileOf(raw, "read");
333
328
  const place = learnedPlace(file);
@@ -335,7 +330,8 @@ export async function readLearnedFile(data, agentId, raw, shown, store) {
335
330
  const oid = blobIn(snapshot, file);
336
331
  if (oid === undefined)
337
332
  return undefined;
338
- const purged = place.kind === "workflow" ? (await purgedWorkflows(snapshot, store)).get(place.name) : undefined;
333
+ // Either file of the workflow: the gate refuses its folder whole, as the view and a merge's diff do.
334
+ const purged = (await purgeGate(snapshot, store)).workflows.get(place.name);
339
335
  if (purged)
340
336
  throw purgedRun(purged);
341
337
  return { oid, text: await body(file, oid) };
@@ -400,7 +396,10 @@ const refused = (problems) => new ApiError("bad_request", `The workflow does not
400
396
  * held draft (status: pending) to every later run; a retire takes it out of every later run unchecked, so a leaking one
401
397
  * can always be revoked; a restore brings it back to the status its retire recorded, checked again as a new draft is
402
398
  * (secrets' shapes, the host's values, hidden characters, its README's format, its workflow.json against the agent's
403
- * tools and gate). A retire of a retired draft commits nothing. `refuse`: the host's secrets. */
399
+ * tools and gate). A retire of a retired draft commits nothing. An approval or a restore of a workflow whose
400
+ * workflow.json a purged run wrote (still on main until its DELETE is sent again) is 410 purged (purgeGate over
401
+ * `store`'s runs): no person's change gives it to a run; a retire takes it out as any other. `refuse`: the host's
402
+ * secrets. */
404
403
  export async function changeWorkflow(data, agentId, raw, input) {
405
404
  const file = fileOf(raw, input.action);
406
405
  const place = learnedPlace(file);
@@ -421,6 +420,11 @@ export async function changeWorkflow(data, agentId, raw, input) {
421
420
  throw new ApiError("not_found", "the agent's learning folder has no such workflow on main");
422
421
  if (!match.includes(etagOf(current.oid)))
423
422
  throw new ApiError("precondition_failed", "The workflow changed since it was read (a run's merge, or another change): read it again.");
423
+ if (input.action !== "retire") {
424
+ const purged = (await purgeGate(snapshot, input.store)).workflows.get(place.name);
425
+ if (purged)
426
+ throw purgedRun(purged);
427
+ }
424
428
  let text;
425
429
  if (input.action === "restore") {
426
430
  const status = learnedStatus(current.text);
@@ -537,18 +541,15 @@ export async function runDiffOverStore(data, store, runId, shown) {
537
541
  }
538
542
  return { base: start?.seed ?? null, head: null, files: [] };
539
543
  }
540
- /** `diff` with each file of a learned workflow whose text at its parent a purged run wrote (purged-workflow.ts), its
541
- * whole `workflows/<name>/` folder (README.md too), diffed against nothing, so its patch never shows that text: its
542
- * text at the merge as an added file, or, deleted there, no file. One more read-only exec when the merge changed such
543
- * a file (snapshotAt), and one per file served so. */
544
+ /** `diff` with each file of a learned workflow whose text at its parent a purged run wrote (purgeGate), its whole
545
+ * `workflows/<name>/` folder (README.md too), diffed against nothing, so its patch never shows that text: its text at
546
+ * the merge as an added file, or, deleted there, no file. One more read-only exec when the merge changed such a file
547
+ * (snapshotAt), and one per file served so. */
544
548
  async function againstPurged(ws, diff, store) {
545
- const replaced = (path, status) => {
546
- const [dir, name, ...rest] = path.split("/");
547
- return status !== "added" && dir === WORKFLOWS_DIR && rest.length ? name : undefined;
548
- };
549
+ const replaced = (path, status) => (status === "added" ? undefined : folderOf(path));
549
550
  if (!diff.files.some(({ path, status }) => replaced(path, status)))
550
551
  return diff;
551
- const purged = await purgedWorkflows(await snapshotAt(ws, diff.parent), store);
552
+ const purged = (await purgeGate(await snapshotAt(ws, diff.parent), store)).workflows;
552
553
  const files = [];
553
554
  for (const entry of diff.files) {
554
555
  const name = replaced(entry.path, entry.status);
package/dist/learning.js CHANGED
@@ -18,7 +18,7 @@ import { folderAt, learningInit, learningWorkspace, readLearning } from "./learn
18
18
  import { agentFolderOf, serialBy } from "./files.js";
19
19
  import { withoutLoopbackAddresses } from "./key-refusal.js";
20
20
  import { DETAIL_MAX, LIST_DETAIL, said, short, wordsOf } from "./learning-words.js";
21
- import { purgedWorkflows } from "./purged-workflow.js";
21
+ import { purgeGate } from "./purged-workflow.js";
22
22
  export { learnsOf } from "./learning-setting.js";
23
23
  /** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
24
24
  * default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
@@ -215,7 +215,7 @@ export async function seedAt(ws, commit, store) {
215
215
  const at = await folderAt(ws, commit);
216
216
  if (!at)
217
217
  throw new Error(`the learning folder's read at ${commit} is gone`);
218
- const purged = store ? await purgedWorkflows(at.snapshot, store) : new Map();
218
+ const purged = store ? (await purgeGate(at.snapshot, store)).workflows : new Map();
219
219
  const seed = await seedIn(commit, at.snapshot, async (_path, oid) => {
220
220
  const bytes = at.blobs.get(oid);
221
221
  if (!bytes)
@@ -0,0 +1,10 @@
1
+ /** A file's front matter, parsed (core schema, unique keys, no merge keys, no aliases), and the body after it; or why it
2
+ * does not read (`problem`, said after "its front matter"); undefined when the file has none. */
3
+ export declare function frontMatter(text: string): {
4
+ data: unknown;
5
+ body: string;
6
+ } | {
7
+ problem: string;
8
+ } | undefined;
9
+ /** agent.md's manifest, its front matter when that reads as a mapping, else undefined (the package reader says why). */
10
+ export declare function manifestOf(text: string): Record<string, unknown> | undefined;
@@ -0,0 +1,30 @@
1
+ // A package file's YAML front matter, read one way wherever it is read: the package reader (templates.ts), its eval
2
+ // cases (template-eval.ts) and `agentrun deploy`, which imports this module (`@parcha/agentrun-serve/manifest`) to find
3
+ // the files a folder's package holds before it sends them. It loads nothing but the YAML parser.
4
+ import { parseDocument } from "yaml";
5
+ /** The front matter: the text between a `---` line at the file's top and the next `---` line. */
6
+ const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
7
+ /** A file's front matter, parsed (core schema, unique keys, no merge keys, no aliases), and the body after it; or why it
8
+ * does not read (`problem`, said after "its front matter"); undefined when the file has none. */
9
+ export function frontMatter(text) {
10
+ const match = FRONT.exec(text);
11
+ if (!match)
12
+ return undefined;
13
+ const doc = parseDocument(match[1], { schema: "core", merge: false, uniqueKeys: true, strict: true });
14
+ if (doc.errors.length)
15
+ return { problem: `is not YAML: ${doc.errors[0].message.split("\n")[0]}` };
16
+ try {
17
+ return { data: doc.toJS({ maxAliasCount: 0 }), body: text.slice(match[0].length) };
18
+ }
19
+ catch (error) {
20
+ return { problem: `is refused: ${error.message}` };
21
+ }
22
+ }
23
+ /** agent.md's manifest, its front matter when that reads as a mapping, else undefined (the package reader says why). */
24
+ export function manifestOf(text) {
25
+ const front = frontMatter(text);
26
+ if (!front || "problem" in front)
27
+ return undefined;
28
+ const { data } = front;
29
+ return typeof data === "object" && data !== null && !Array.isArray(data) ? data : undefined;
30
+ }
@@ -29,11 +29,13 @@ export declare function pinFirst(revision: {
29
29
  * that server's own ports (`own`, Serve.own). `githubApp`:
30
30
  * the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
31
31
  * repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
32
- * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). */
33
- export declare function registryListing(store: Parameters<typeof mcpServersOverStore>[0], sealKey: Buffer, { loopback, own, network, githubApp, appOrigin }?: {
32
+ * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). `composioOrigin`: a
33
+ * test's fake Composio MCP (McpServersOverStore.composioOrigin). */
34
+ export declare function registryListing(store: Parameters<typeof mcpServersOverStore>[0], sealKey: Buffer, { loopback, own, network, githubApp, appOrigin, composioOrigin }?: {
34
35
  loopback?: boolean;
35
36
  own?: readonly string[];
36
37
  network?: OAuthNetwork;
37
38
  githubApp?: GithubAppAccess;
38
39
  appOrigin?: string;
40
+ composioOrigin?: string;
39
41
  }): (server: string, stop?: AbortSignal) => Promise<PinListing>;