@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52

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 (232) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/README.md +236 -30
  3. package/dist/adapters.js +1 -1
  4. package/dist/agent-delete.d.ts +13 -2
  5. package/dist/agent-delete.js +14 -5
  6. package/dist/agents-store.d.ts +5 -1
  7. package/dist/agents-store.js +17 -7
  8. package/dist/api-only.d.ts +6 -3
  9. package/dist/api-only.js +8 -5
  10. package/dist/archil-routes.d.ts +1 -0
  11. package/dist/archil-routes.js +28 -2
  12. package/dist/capacity.d.ts +50 -0
  13. package/dist/capacity.js +49 -0
  14. package/dist/cli-learning/claude-wire.d.ts +41 -0
  15. package/dist/cli-learning/claude-wire.js +258 -0
  16. package/dist/cli-learning/cli.d.ts +11 -0
  17. package/dist/cli-learning/cli.js +241 -0
  18. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  19. package/dist/cli-learning/codex-worktree.js +119 -0
  20. package/dist/cli-learning/connections.d.ts +62 -0
  21. package/dist/cli-learning/connections.js +87 -0
  22. package/dist/cli-learning/entry.d.ts +1 -0
  23. package/dist/cli-learning/entry.js +4 -0
  24. package/dist/cli-learning/evidence.d.ts +78 -0
  25. package/dist/cli-learning/evidence.js +492 -0
  26. package/dist/cli-learning/hook.d.ts +33 -0
  27. package/dist/cli-learning/hook.js +544 -0
  28. package/dist/cli-learning/install.d.ts +33 -0
  29. package/dist/cli-learning/install.js +335 -0
  30. package/dist/cli-learning/observation-proof.d.ts +14 -0
  31. package/dist/cli-learning/observation-proof.js +10 -0
  32. package/dist/cli-learning/policy.d.ts +48 -0
  33. package/dist/cli-learning/policy.js +363 -0
  34. package/dist/cli-learning/schema.d.ts +16 -0
  35. package/dist/cli-learning/schema.js +27 -0
  36. package/dist/cli-learning/state.d.ts +23 -0
  37. package/dist/cli-learning/state.js +61 -0
  38. package/dist/cli.js +24 -2
  39. package/dist/computer-setting.d.ts +8 -0
  40. package/dist/computer-setting.js +11 -0
  41. package/dist/computers.d.ts +6 -2
  42. package/dist/computers.js +2 -2
  43. package/dist/console/assets/index-B-D0EM3j.js +733 -0
  44. package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
  45. package/dist/console/index.html +2 -2
  46. package/dist/email/email-faux.d.ts +3 -1
  47. package/dist/email/email-faux.js +3 -2
  48. package/dist/email/routes.js +22 -12
  49. package/dist/fal-price.d.ts +76 -0
  50. package/dist/fal-price.js +368 -0
  51. package/dist/harness-install.d.ts +6 -2
  52. package/dist/harness-install.js +40 -8
  53. package/dist/harness.d.ts +1 -1
  54. package/dist/harness.js +2 -2
  55. package/dist/learn/commit.d.ts +5 -0
  56. package/dist/learn/commit.js +4 -1
  57. package/dist/learn/compile.d.ts +13 -5
  58. package/dist/learn/compile.js +24 -7
  59. package/dist/learn/delete.d.ts +12 -6
  60. package/dist/learn/delete.js +17 -11
  61. package/dist/learn/folder.d.ts +11 -0
  62. package/dist/learn/folder.js +20 -3
  63. package/dist/learn/learning-of.d.ts +8 -0
  64. package/dist/learn/learning-of.js +8 -0
  65. package/dist/learn/learning.sh +14 -1
  66. package/dist/learn/promote.d.ts +51 -7
  67. package/dist/learn/promote.js +51 -8
  68. package/dist/learn/secrets.js +14 -3
  69. package/dist/learning-reset.d.ts +18 -0
  70. package/dist/learning-reset.js +115 -0
  71. package/dist/learning-routes.d.ts +1 -1
  72. package/dist/learning-words.d.ts +6 -1
  73. package/dist/learning-words.js +6 -1
  74. package/dist/learning.d.ts +8 -6
  75. package/dist/learning.js +5 -4
  76. package/dist/llms.txt +1 -0
  77. package/dist/mcp-gateway.d.ts +39 -2
  78. package/dist/mcp-gateway.js +41 -10
  79. package/dist/mcp-pin-first.js +3 -2
  80. package/dist/mcp-private-hosts.d.ts +24 -3
  81. package/dist/mcp-private-hosts.js +53 -3
  82. package/dist/mcp-servers-store.d.ts +1 -0
  83. package/dist/mcp-servers-store.js +2 -1
  84. package/dist/media-duration.d.ts +2 -0
  85. package/dist/media-duration.js +136 -0
  86. package/dist/model-gateway.d.ts +2 -0
  87. package/dist/model-gateway.js +3 -1
  88. package/dist/native/runtimes.d.ts +2 -0
  89. package/dist/native/runtimes.js +2 -0
  90. package/dist/observation/learning.d.ts +32 -0
  91. package/dist/observation/learning.js +66 -0
  92. package/dist/observation/observer.d.ts +8 -1
  93. package/dist/observation/observer.js +89 -9
  94. package/dist/observation/schema.js +12 -4
  95. package/dist/observation/usage-identity.d.ts +9 -0
  96. package/dist/observation/usage-identity.js +11 -0
  97. package/dist/openapi.js +133 -24
  98. package/dist/provider.d.ts +8 -0
  99. package/dist/provider.js +14 -2
  100. package/dist/refusal-words.d.ts +0 -3
  101. package/dist/refusal-words.js +0 -3
  102. package/dist/request-metadata.d.ts +20 -0
  103. package/dist/request-metadata.js +24 -0
  104. package/dist/run-launch.d.ts +27 -4
  105. package/dist/run-launch.js +18 -3
  106. package/dist/run-learning-served.d.ts +2 -2
  107. package/dist/run-usage.d.ts +48 -4
  108. package/dist/run-usage.js +156 -39
  109. package/dist/run-view.d.ts +2 -0
  110. package/dist/run-view.js +8 -7
  111. package/dist/runner/adapter-loop.d.ts +3 -1
  112. package/dist/runner/adapter-loop.js +41 -35
  113. package/dist/runner/adapter-run-spec.d.ts +1 -1
  114. package/dist/runner/adapter-run-spec.js +15 -15
  115. package/dist/runner/audit.d.ts +8 -3
  116. package/dist/runner/audit.js +21 -6
  117. package/dist/runner/beside.d.ts +13 -0
  118. package/dist/runner/beside.js +27 -8
  119. package/dist/runner/claim-secrets.d.ts +2 -1
  120. package/dist/runner/claim-secrets.js +5 -3
  121. package/dist/runner/cli-run-spec.d.ts +1 -1
  122. package/dist/runner/cli-run-spec.js +14 -13
  123. package/dist/runner/conformance/harness.js +4 -2
  124. package/dist/runner/disk-free.d.ts +44 -0
  125. package/dist/runner/disk-free.js +96 -0
  126. package/dist/runner/dispatch.js +4 -2
  127. package/dist/runner/feedback-round.d.ts +12 -8
  128. package/dist/runner/feedback-round.js +16 -30
  129. package/dist/runner/harness-loops.js +8 -3
  130. package/dist/runner/journal-kinds.d.ts +4 -1
  131. package/dist/runner/learning-end.d.ts +2 -1
  132. package/dist/runner/learning-end.js +51 -22
  133. package/dist/runner/main.d.ts +17 -6
  134. package/dist/runner/main.js +187 -45
  135. package/dist/runner/mcp-claim.js +1 -1
  136. package/dist/runner/mcp-run.d.ts +9 -0
  137. package/dist/runner/mcp-run.js +16 -1
  138. package/dist/runner/model-route.js +7 -4
  139. package/dist/runner/presence.d.ts +11 -2
  140. package/dist/runner/presence.js +31 -3
  141. package/dist/runner/promotion.d.ts +40 -21
  142. package/dist/runner/promotion.js +130 -59
  143. package/dist/runner/run-child-host.d.ts +12 -15
  144. package/dist/runner/run-child-host.js +52 -112
  145. package/dist/runner/run-errors.js +2 -0
  146. package/dist/runner/runner-check.d.ts +51 -0
  147. package/dist/runner/runner-check.js +206 -0
  148. package/dist/runner/runner-metrics.d.ts +19 -0
  149. package/dist/runner/runner-metrics.js +49 -0
  150. package/dist/runner/runner.d.ts +37 -0
  151. package/dist/runner/runner.js +58 -6
  152. package/dist/runner/sdk-loop.d.ts +2 -2
  153. package/dist/runner/sdk-loop.js +37 -25
  154. package/dist/runner/store-port.d.ts +3 -0
  155. package/dist/runner/workflow-spec.js +3 -3
  156. package/dist/runs-over-store.d.ts +13 -3
  157. package/dist/runs-over-store.js +71 -16
  158. package/dist/sdk/check.d.ts +6 -5
  159. package/dist/sdk/check.js +17 -16
  160. package/dist/sdk/runs.d.ts +22 -2
  161. package/dist/sdk/runs.js +167 -82
  162. package/dist/server.d.ts +3 -0
  163. package/dist/server.js +230 -43
  164. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  165. package/dist/start-switches.js +2 -0
  166. package/dist/stats.d.ts +4 -0
  167. package/dist/stats.js +1 -1
  168. package/dist/store/agent-body.d.ts +16 -0
  169. package/dist/store/agent-body.js +20 -3
  170. package/dist/store/dialect.d.ts +2 -0
  171. package/dist/store/dialect.js +1 -0
  172. package/dist/store/index.d.ts +3 -3
  173. package/dist/store/index.js +2 -2
  174. package/dist/store/journal/storage.d.ts +2 -0
  175. package/dist/store/journal/storage.js +2 -1
  176. package/dist/store/postgres/connection.d.ts +5 -2
  177. package/dist/store/postgres/connection.js +19 -7
  178. package/dist/store/postgres/dialect.js +1 -0
  179. package/dist/store/postgres/migrate.d.ts +30 -0
  180. package/dist/store/postgres/migrate.js +72 -5
  181. package/dist/store/postgres/migration-lint.d.ts +8 -0
  182. package/dist/store/postgres/migration-lint.js +119 -0
  183. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  184. package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
  185. package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
  186. package/dist/store/postgres/store.d.ts +8 -3
  187. package/dist/store/postgres/store.js +31 -11
  188. package/dist/store/schema.d.ts +32 -2
  189. package/dist/store/schema.js +74 -5
  190. package/dist/store/sqlite/run-launch.d.ts +31 -1
  191. package/dist/store/sqlite/run-launch.js +111 -2
  192. package/dist/store/sqlite/run-patch.d.ts +2 -1
  193. package/dist/store/sqlite/run-patch.js +4 -3
  194. package/dist/store/sqlite/store.d.ts +17 -0
  195. package/dist/store/sqlite/store.js +226 -37
  196. package/dist/store/store-schema.d.ts +34 -0
  197. package/dist/store/store-schema.js +125 -0
  198. package/dist/store/store.d.ts +120 -5
  199. package/dist/store/store.js +13 -0
  200. package/dist/store-reads/analytics.d.ts +3 -2
  201. package/dist/store-reads/analytics.js +20 -8
  202. package/dist/store-reads/learning.d.ts +12 -8
  203. package/dist/store-reads/learning.js +33 -24
  204. package/dist/store-reads/loop.d.ts +4 -3
  205. package/dist/store-reads/loop.js +7 -5
  206. package/dist/store-view.d.ts +4 -3
  207. package/dist/store-view.js +11 -7
  208. package/dist/template-eval.js +4 -4
  209. package/dist/templates.d.ts +6 -2
  210. package/dist/templates.js +7 -5
  211. package/dist/timeline/labels.js +1 -1
  212. package/dist/tool-gate.d.ts +4 -2
  213. package/dist/tools.js +1 -1
  214. package/dist/unified-usage.d.ts +24 -0
  215. package/dist/unified-usage.js +400 -0
  216. package/dist/uploads-archil.d.ts +100 -0
  217. package/dist/uploads-archil.js +431 -0
  218. package/dist/uploads.d.ts +52 -1
  219. package/dist/uploads.js +186 -108
  220. package/dist/validate.js +5 -1
  221. package/dist/web-save.d.ts +3 -0
  222. package/dist/web-save.js +17 -2
  223. package/dist/workspace/archil-disk.d.ts +6 -5
  224. package/dist/workspace/archil-disk.js +27 -12
  225. package/dist/workspace/archil-exec.js +1 -1
  226. package/dist/workspace/archil.js +4 -3
  227. package/dist/workspace/revision-skills.js +24 -11
  228. package/dist/workspace/synced-folder.d.ts +3 -3
  229. package/dist/workspace/synced-folder.js +7 -6
  230. package/package.json +10 -10
  231. package/skills/agentrun-serve/SKILL.md +52 -7
  232. package/dist/console/assets/index-D7G6o-1E.js +0 -720
@@ -6,12 +6,18 @@ export declare class LearningInFlight extends Error {
6
6
  readonly runs: readonly string[];
7
7
  constructor(agentId: string, runs: readonly string[]);
8
8
  }
9
- /** Agent `agentId`'s learning deleted: every file of its learning folder (`folder`, learning.ts learningFolderOf: its
10
- * corrections.md and workflows, its git history and snapshot, audits.jsonl), then the learning records the store keeps
11
- * for it (its promotions and grades). Refused (LearningInFlight), with nothing removed, while a run of the agent has not
12
- * ended. Idempotent: what is gone already is skipped, so a second call removes nothing. `files`: the folder's entries it
13
- * removed; `records`: the store's records. `folder` is ended here. */
14
- export declare function deleteLearning(store: Store, agentId: string, folder: LearningFolder): Promise<{
9
+ /** Agent `agentId`'s learning deleted: its learning folder on each other disk it is on (`elsewhere`: a Mode 2 run's end
10
+ * writes it on the Archil disk its claim mounted; server.ts names those disks), then every file of its learning folder
11
+ * here (`folder`, learning.ts learningFolderOf: its corrections.md and workflows, its git history and snapshot,
12
+ * audits.jsonl), then the learning records the store keeps for it (its promotions and grades, and the reset ledger and
13
+ * watermark its earlier resets kept, unless `keepResetLedger`: a reset keeps them, the runs they cover staying).
14
+ * Refused (LearningInFlight), with nothing removed, while a run of the agent has not ended; `elsewhere` failing leaves
15
+ * this folder and the records for the next call. Idempotent: what is gone already is skipped, so a second call removes
16
+ * nothing. `files`: this folder's entries it removed; `records`: the store's records. `folder` is ended here. */
17
+ export declare function deleteLearning(store: Store, agentId: string, folder: LearningFolder, { keepResetLedger, elsewhere }?: {
18
+ keepResetLedger?: boolean;
19
+ elsewhere?: () => Promise<void>;
20
+ }): Promise<{
15
21
  files: number;
16
22
  records: number;
17
23
  }>;
@@ -1,9 +1,11 @@
1
- // An agent's learning, deleted: the learning half of an agent's delete. Its caller (DELETE /v2/agents/{id}) stops the
2
- // agent's runs and learning work first, then calls deleteLearning, then deletes the agent's store rows, in that order:
3
- // a call again after a crash finishes what a first one began, and no learning is left with no agent to own it.
1
+ // An agent's learning, deleted: the learning half of an agent's delete, and the whole of a reset of its learning. Its
2
+ // callers stop the agent's learning work first: DELETE /v2/agents/{id} stops all its runs, calls deleteLearning, then
3
+ // deletes the agent's store rows, in that order, so a call again after a crash finishes what a first one began and no
4
+ // learning is left with no agent to own it; DELETE /v2/agents/{id}/learning (learning-reset.ts) keeps the agent and its
5
+ // runs.
4
6
  import { isWorkspaceError } from "../workspace/workspace.js";
5
7
  import { FINAL_STATES } from "../store/store.js";
6
- import { gradesKey, promotionsKey } from "./promote.js";
8
+ import { gradesKey, promotionsKey, resetAtKey, resetLedgerKey } from "./promote.js";
7
9
  /** A delete refused: work of the agent's learning is still in flight (`runs`: a run of the agent not ended, its
8
10
  * compile turn, a check's replay or an audit's shadow among them). Nothing was removed. */
9
11
  export class LearningInFlight extends Error {
@@ -14,21 +16,25 @@ export class LearningInFlight extends Error {
14
16
  this.runs = runs;
15
17
  }
16
18
  }
17
- /** Agent `agentId`'s learning deleted: every file of its learning folder (`folder`, learning.ts learningFolderOf: its
18
- * corrections.md and workflows, its git history and snapshot, audits.jsonl), then the learning records the store keeps
19
- * for it (its promotions and grades). Refused (LearningInFlight), with nothing removed, while a run of the agent has not
20
- * ended. Idempotent: what is gone already is skipped, so a second call removes nothing. `files`: the folder's entries it
21
- * removed; `records`: the store's records. `folder` is ended here. */
22
- export async function deleteLearning(store, agentId, folder) {
19
+ /** Agent `agentId`'s learning deleted: its learning folder on each other disk it is on (`elsewhere`: a Mode 2 run's end
20
+ * writes it on the Archil disk its claim mounted; server.ts names those disks), then every file of its learning folder
21
+ * here (`folder`, learning.ts learningFolderOf: its corrections.md and workflows, its git history and snapshot,
22
+ * audits.jsonl), then the learning records the store keeps for it (its promotions and grades, and the reset ledger and
23
+ * watermark its earlier resets kept, unless `keepResetLedger`: a reset keeps them, the runs they cover staying).
24
+ * Refused (LearningInFlight), with nothing removed, while a run of the agent has not ended; `elsewhere` failing leaves
25
+ * this folder and the records for the next call. Idempotent: what is gone already is skipped, so a second call removes
26
+ * nothing. `files`: this folder's entries it removed; `records`: the store's records. `folder` is ended here. */
27
+ export async function deleteLearning(store, agentId, folder, { keepResetLedger = false, elsewhere } = {}) {
23
28
  try {
24
29
  const open = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId && !FINAL_STATES.includes(run.state)).map((run) => run.id);
25
30
  if (open.length)
26
31
  throw new LearningInFlight(agentId, open);
32
+ await elsewhere?.();
27
33
  const entries = await folder.workspace.list("").catch((error) => (isWorkspaceError(error, "NOT_FOUND") ? [] : Promise.reject(error)));
28
34
  for (const entry of entries)
29
35
  await folder.workspace.remove(entry.name, { recursive: true, force: true });
30
36
  let records = 0;
31
- for (const key of [promotionsKey(agentId), gradesKey(agentId)]) {
37
+ for (const key of [promotionsKey(agentId), gradesKey(agentId), ...(keepResetLedger ? [] : [resetLedgerKey(agentId), resetAtKey(agentId)])]) {
32
38
  if ((await store.settings.get(key)) === undefined)
33
39
  continue;
34
40
  await store.settings.remove(key);
@@ -152,6 +152,10 @@ export type FolderChange = {
152
152
  commit: string;
153
153
  path: string;
154
154
  }[];
155
+ /** A run's merge: the commit the run was seeded from, which the folder must still hold, whatever the merge writes (a
156
+ * correction alone included), named only when this folder held it as the run's end began (commit.ts mustHold): one a
157
+ * reset of the agent's learning removed refuses the merge. */
158
+ seed?: string;
155
159
  };
156
160
  /** The snapshot once `change` is committed on `before` (none: the folder's first commit) at `seconds`, its main and its
157
161
  * log entry's commit the placeholder the script puts the new main in. Also which paths changed, as git's diff of the
@@ -243,6 +247,7 @@ export type Committed = {
243
247
  refused: {
244
248
  absent: string[];
245
249
  same: string[];
250
+ seed?: string;
246
251
  };
247
252
  } | {
248
253
  unaligned: true;
@@ -273,6 +278,9 @@ export declare function folderAt(ws: Workspace, commit: string): Promise<{
273
278
  * bounded by what is asked, whatever the folder holds. A path the commit holds no file at is not in it. Undefined when
274
279
  * the folder has no such commit. */
275
280
  export declare function textsAt(ws: Workspace, commit: string, paths: readonly string[]): Promise<Record<string, string> | undefined>;
281
+ /** Whether the folder holds `commit`: one read-only exec of the script's show with no path, which reads nothing but
282
+ * that. False once a reset of the agent's learning removed it (or the folder is not a repository). */
283
+ export declare function holdsCommit(ws: Workspace, commit: string): Promise<boolean>;
276
284
  export declare function learningRepair(ws: Workspace): Promise<Snapshot | undefined>;
277
285
  /** The folder's first commit when it has no main yet (an empty tree, the host's), and main's commit: through the
278
286
  * script's init, which makes the repository where there is none. A main with no snapshot (an init that stopped
@@ -282,9 +290,12 @@ export declare function learningInit(ws: Workspace): Promise<string>;
282
290
  export declare class FolderRefused extends Error {
283
291
  readonly absent: string[];
284
292
  readonly same: string[];
293
+ /** A run's merge whose seed (FolderChange.seed) the folder no longer holds: its agent's learning was reset. */
294
+ readonly seed: string | undefined;
285
295
  constructor(refused: {
286
296
  absent: string[];
287
297
  same: string[];
298
+ seed?: string;
288
299
  });
289
300
  }
290
301
  /** A run's merge (its round) that is on main already, made by another call (a reclaimed run racing its first claim, or
@@ -629,7 +629,7 @@ export async function commitChange(ws, base, change) {
629
629
  checkPath(path);
630
630
  for (const path of [...(change?.deletes ?? []), ...(change?.absent ?? []), ...(change?.same ?? []).map(({ path }) => path)])
631
631
  checkPath(path);
632
- for (const { commit } of change?.same ?? [])
632
+ for (const commit of [...(change?.same ?? []).map(({ commit }) => commit), ...(change?.seed !== undefined ? [change.seed] : [])])
633
633
  if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(commit))
634
634
  throw new Error(`${JSON.stringify(commit)} is not a commit`);
635
635
  const ref = `refs/agentrun/import-${randomBytes(8).toString("hex")}`;
@@ -640,6 +640,7 @@ export async function commitChange(ws, base, change) {
640
640
  ...(run ? changed.map((path) => `path ${path}`) : []),
641
641
  ...(change?.absent ?? []).map((path) => `absent ${path}`),
642
642
  ...(change?.same ?? []).map(({ commit, path }) => `same ${commit} ${path}`),
643
+ ...(change?.seed !== undefined ? [`seed ${change.seed}`] : []),
643
644
  ];
644
645
  const stream = importStream(ref, base?.main, writes, change?.deletes ?? [], messageOf(change?.by).message, seconds);
645
646
  const args = base ? ["commit", base.main, ...(run ? [run] : [])] : ["init"];
@@ -654,7 +655,8 @@ export async function commitChange(ws, base, change) {
654
655
  return { stale: true, main: said || undefined };
655
656
  if (result.code === 4) {
656
657
  const lines = said.split("\n");
657
- return { refused: { absent: lines.filter((line) => line.startsWith("absent ")).map((line) => line.slice(7)), same: lines.filter((line) => line.startsWith("same ")).map((line) => line.slice(5)) } };
658
+ const seed = lines.find((line) => line.startsWith("seed "))?.slice(5);
659
+ return { refused: { absent: lines.filter((line) => line.startsWith("absent ")).map((line) => line.slice(7)), same: lines.filter((line) => line.startsWith("same ")).map((line) => line.slice(5)), ...(seed !== undefined ? { seed } : {}) } };
658
660
  }
659
661
  if (result.code === 5 && /^[0-9a-f]{40,64}$/.test(said))
660
662
  return { unaligned: true, main: said };
@@ -716,6 +718,18 @@ export async function textsAt(ws, commit, paths) {
716
718
  }
717
719
  return out;
718
720
  }
721
+ /** Whether the folder holds `commit`: one read-only exec of the script's show with no path, which reads nothing but
722
+ * that. False once a reset of the agent's learning removed it (or the folder is not a repository). */
723
+ export async function holdsCommit(ws, commit) {
724
+ if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(commit))
725
+ throw new Error(`${JSON.stringify(commit)} is not a commit`);
726
+ const result = await runScript(ws, ["show", commit]);
727
+ if (result.code === 1)
728
+ return false;
729
+ if (result.code !== 0)
730
+ throw failed("show", result);
731
+ return true;
732
+ }
719
733
  export async function learningRepair(ws) {
720
734
  for (let tries = 0; tries < WRITE_TRIES; tries++) {
721
735
  const read = await runScript(ws, ["read"]);
@@ -758,11 +772,14 @@ export async function learningInit(ws) {
758
772
  export class FolderRefused extends Error {
759
773
  absent;
760
774
  same;
775
+ /** A run's merge whose seed (FolderChange.seed) the folder no longer holds: its agent's learning was reset. */
776
+ seed;
761
777
  constructor(refused) {
762
- super(`the learning folder's main refused the write: ${[...refused.absent.map((path) => `${path} is there`), ...refused.same.map((path) => `${path} changed`)].join(", ")}`);
778
+ super(`the learning folder's main refused the write: ${[...(refused.seed !== undefined ? [`the run's seed ${refused.seed} is not in the folder`] : []), ...refused.absent.map((path) => `${path} is there`), ...refused.same.map((path) => `${path} changed`)].join(", ")}`);
763
779
  this.name = "FolderRefused";
764
780
  this.absent = refused.absent;
765
781
  this.same = refused.same;
782
+ this.seed = refused.seed;
766
783
  }
767
784
  }
768
785
  /** A run's merge (its round) that is on main already, made by another call (a reclaimed run racing its first claim, or
@@ -0,0 +1,8 @@
1
+ import type { RunLaunch } from "../run-launch.js";
2
+ import type { Store } from "../store/store.js";
3
+ /** The disk a run's launch names as its own: the launch's `archilDisk` of kind "launch", by its id; null for none or its
4
+ * agent's own (the default disk). The store keeps the same on the run's row (RunRow.disk). */
5
+ export declare const learningDiskOf: (launch: Pick<RunLaunch, "archilDisk">) => string | null;
6
+ /** Each named disk a run of agent `agentId` used (Store.runs.every: its built-in learning runs and purged runs included,
7
+ * a purged run's tombstone keeping its disk): where a learning folder of the agent may be, past the server's own. */
8
+ export declare function namedDisksOf(store: Pick<Store, "runs">, agentId: string): Promise<string[]>;
@@ -0,0 +1,8 @@
1
+ /** The disk a run's launch names as its own: the launch's `archilDisk` of kind "launch", by its id; null for none or its
2
+ * agent's own (the default disk). The store keeps the same on the run's row (RunRow.disk). */
3
+ export const learningDiskOf = (launch) => launch.archilDisk?.kind === "launch" ? launch.archilDisk.diskId : null;
4
+ /** Each named disk a run of agent `agentId` used (Store.runs.every: its built-in learning runs and purged runs included,
5
+ * a purged run's tombstone keeping its disk): where a learning folder of the agent may be, past the server's own. */
6
+ export async function namedDisksOf(store, agentId) {
7
+ return [...new Set((await store.runs.every(agentId)).map((run) => run.disk).filter((disk) => disk !== null))];
8
+ }
@@ -32,7 +32,11 @@
32
32
  # snapshot <json> snapshot.json, one line, where a \001M\001 stands for the new main
33
33
  # path <path> (a merge) a path its diff covers
34
34
  # absent <path> <path> must not be on <old>, any mode, any type (else 4: "absent <path>" on stdout)
35
- # same <commit> <path> <path> must be the same on <commit> as on <old> (else 4: "same <path>" on stdout)
35
+ # same <commit> <path> <path> must be the same on <commit> as on <old> (else 4: "same <path>" on stdout); a
36
+ # <commit> the repository does not hold fails it (the folder was reset since it was read)
37
+ # seed <commit> (a run's merge) the commit the run was seeded from, which the repository held as its end began
38
+ # and must hold still (else 4: "seed <commit>" on stdout): a reset since merges nothing, a
39
+ # correction alone included
36
40
  # Exit: 0 done (the new main on stdout), 3 stale (main as it is on stdout), 4 a precondition failed, 5 main moved but
37
41
  # the files could not be brought in line (the new main on stdout; no snapshot written), 6 the run merged already (its
38
42
  # merge on stdout), else git's error on stderr.
@@ -187,10 +191,19 @@ preconditions() {
187
191
  done < "$tmp/absent"
188
192
  sed -n 's/^same //p' "$tmp/head" > "$tmp/same"
189
193
  while read -r c p; do
194
+ # A commit this repository does not hold (the agent's learning reset after the run read it) is no ground to merge on.
195
+ if ! g cat-file -e "$c^{commit}" 2>/dev/null; then
196
+ printf 'same %s\n' "$p" >> "$tmp/failed"
197
+ continue
198
+ fi
190
199
  a=$(g rev-parse -q --verify "$c:$p" 2>/dev/null || true)
191
200
  b=$(g rev-parse -q --verify "$old:$p" 2>/dev/null || true)
192
201
  [ "$a" = "$b" ] || printf 'same %s\n' "$p" >> "$tmp/failed"
193
202
  done < "$tmp/same"
203
+ sed -n 's/^seed //p' "$tmp/head" > "$tmp/seed"
204
+ while read -r c; do
205
+ g cat-file -e "$c^{commit}" 2>/dev/null || printf 'seed %s\n' "$c" >> "$tmp/failed"
206
+ done < "$tmp/seed"
194
207
  if [ -s "$tmp/failed" ]; then
195
208
  cat "$tmp/failed"
196
209
  exit 4
@@ -80,9 +80,10 @@ export interface PromotionRecord {
80
80
  /** The learning commit whose workflows/<workflow>/workflow.json is this digest's text: the seed of the claim that
81
81
  * recorded it. What the digest serves from as the champion (championOf) once a newer revision is on the folder's main. */
82
82
  readonly commit?: string;
83
- /** `sdk`: a connected (SDK) agent's check (runner/promotion.ts reserveSdkCheck), on its reservation and the record that
84
- * decides it. Its one run (`runs`) is the agent's own native turn, not a replay run; a replaying one with no `runs`
85
- * waits for the next native turn the draft takes. Absent: a server replay's. */
83
+ /** `sdk`: a connected (SDK) agent's check (runner/promotion.ts reserveSdkCheck), on each reservation and the record that
84
+ * decides it. Its one run (`runs`) is the agent's native turn reserved now, not a replay run; a replaying one with no
85
+ * `runs` waits for the next native turn the draft takes. It collects its checked turns (`check.turns`) and decides once
86
+ * it holds compile_after of them, as a managed check decides once on its inputs. Absent: a server replay's. */
86
87
  readonly via?: "sdk";
87
88
  }
88
89
  /** One audit row a hold was decided on that disagreed: the served run (`served`) and its input, the run whose answer is
@@ -146,17 +147,34 @@ export type CheckRecord = CheckBar & {
146
147
  readonly skipped_tools?: readonly SkippedTool[];
147
148
  readonly disagreements?: readonly CheckDisagreement[];
148
149
  readonly stopped?: true;
149
- /** A connected agent's check: how many of its reserved native turns gave no answer to check the draft against (a
150
- * cancelled or refused turn, a subagent, redacted evidence, no shadow report) and were given back to wait for the
151
- * next one (runner/promotion.ts SDK_CHECK_RELEASES stops it). Absent: none. */
150
+ /** A connected agent's check: how many of its reserved native turns in a row gave no answer to check the draft against
151
+ * (a refused turn, a subagent, redacted evidence, no shadow report; never a cancel) and were given back to wait for
152
+ * the next one (runner/promotion.ts SDK_CHECK_RELEASES holds it for the next compile). Absent: none. */
152
153
  readonly released?: number;
153
154
  /** A connected agent's check: how many fresh read-only calls its shadow made where the native turn's recording had
154
155
  * no result (the client's opt-in shadowReadFallback). Absent: none, every call was answered from the recording. */
155
156
  readonly fresh_reads?: number;
157
+ /** A connected agent's check still collecting native turns (runner/promotion.ts sdkCheckTurn): the turns checked so
158
+ * far, until it holds compile_after of them and decides once on them all. Absent once decided on them, and on a
159
+ * managed check; a check stopped or set aside before it held them keeps the turns it had. */
160
+ readonly turns?: CheckTurns;
156
161
  /** How it compared with no agree_on: the fast model that read the answers (its name), when it was asked on any input.
157
162
  * With agree_on, the paths compared (CheckBar.agree_on); with neither, the whole answer. */
158
163
  readonly grader?: string;
159
164
  };
165
+ /** A connected agent's checked native turns before its check decides, counted as a decided check counts its inputs:
166
+ * `n` turns, `agreed` and `alone` of them, the agent's runs (`of`, newest first), one outcome per turn (a turn past its
167
+ * deadline failed), each turn it did not agree on, and the shadows' fresh reads. Each is compared on its own turn, its
168
+ * texts cut as a decided check's are. */
169
+ export interface CheckTurns {
170
+ readonly n: number;
171
+ readonly agreed: number;
172
+ readonly alone: number;
173
+ readonly of: readonly string[];
174
+ readonly outcomes: ReplayOutcomes;
175
+ readonly disagreements?: readonly CheckDisagreement[];
176
+ readonly fresh_reads?: number;
177
+ }
160
178
  /** The most characters of an input or an answer a check's disagreement keeps. */
161
179
  export declare const CHECK_TEXT_MAX = 1200;
162
180
  /** A check's two shares: `agreement`, of the inputs the draft answered alone those that say what the agent said (0 when
@@ -196,6 +214,30 @@ export declare function skippedToolsOf(rows: readonly {
196
214
  }[]): SkippedTool[];
197
215
  export declare const gradesKey: (agentId: string) => string;
198
216
  export declare const promotionsKey: (agentId: string) => string;
217
+ /** A learned workflow revision an agent's learning reset deleted (DELETE /agents/{id}/learning, learning-reset.ts): its
218
+ * workflow, its digest and its K (its check's compile_after; null when its records named none), nothing else of its
219
+ * records. What the runs it served carry of its compile and check (store-reads/learning.ts revisionLedgerOf) is read
220
+ * from it after the reset, so a kept run's cost reads as before. The runs keep the same names and digests. */
221
+ export interface ResetRevision {
222
+ readonly workflow: string;
223
+ readonly digest: string;
224
+ readonly k: number | null;
225
+ }
226
+ export declare const resetLedgerKey: (agentId: string) => string;
227
+ /** The revisions the agent's resets deleted, first reset first. */
228
+ export declare const resetLedgerOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<ResetRevision[]>;
229
+ /** Each revision `records` name (one per workflow and digest, its newest record's K) added to the agent's reset ledger,
230
+ * before a reset deletes the records. A revision it holds already keeps its place and takes the records' K: while they
231
+ * stood, the ledger read their K (revisionLedgerOf), so the runs' shares read the same after this reset too. */
232
+ export declare function keepResetLedger(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, records: readonly PromotionRecord[]): Promise<void>;
233
+ /** The agent's reset watermark: when its newest reset began (epoch ms). Learning reads only the runs after it
234
+ * (learn/compile.ts sinceReset): a run that started, or read its learning seed, at or before it learns nothing and is
235
+ * read by no compile, check, audit or money rule. Kept with the reset ledger, and removed with it by the agent's delete (learn/delete.ts). */
236
+ export declare const resetAtKey: (agentId: string) => string;
237
+ /** The agent's reset watermark (resetAtKey), or undefined when its learning was never reset. */
238
+ export declare const resetAtOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<number | undefined>;
239
+ /** Agent `agentId`'s reset watermark set to `at`, in place of an earlier reset's. */
240
+ export declare const keepResetAt: (settings: Pick<Settings, "put">, agentId: string, at: number) => Promise<void>;
199
241
  /** The agent's grades, oldest first. */
200
242
  export declare const gradesOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<Grade[]>;
201
243
  /** Keeps `grade`, in place of any earlier grade of the same run, the newest GRADES_KEPT kept, at the next `seq`. */
@@ -276,7 +318,9 @@ export type Recorded = {
276
318
  };
277
319
  /** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
278
320
  * and of every record kept (`items`: a check across revisions, one at a time, in the same guarded write): so of two
279
- * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). */
321
+ * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). What the one
322
+ * 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. */
280
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>;
281
325
  /** The newest records, at most PROMOTIONS_KEPT, in order, with each workflow's champion (championOf) the same after as
282
326
  * before, whatever was dropped: championOf reads the digest promoted last and its newest record, so the trim keeps both
@@ -7,6 +7,7 @@
7
7
  // its workflows' promotion records), over the settings table; the orchestration is runner/promotion.ts. Grades are what
8
8
  // a person or an eval said of a run (PUT /runs/{id}/grade).
9
9
  import { createHash } from "node:crypto";
10
+ import { isDeepStrictEqual } from "node:util";
10
11
  import { answerJson } from "../answer-json.js";
11
12
  import { pathSegments } from "../learning-setting.js";
12
13
  import { isObject } from "../validate.js";
@@ -61,6 +62,35 @@ async function updateKept(settings, key, update) {
61
62
  }
62
63
  throw new Error(`${key} kept changing under this write; try again`);
63
64
  }
65
+ export const resetLedgerKey = (agentId) => `learning.reset-ledger.${agentId}`;
66
+ /** The revisions the agent's resets deleted, first reset first. */
67
+ export const resetLedgerOf = async (settings, agentId) => itemsOf(await settings.get(resetLedgerKey(agentId)));
68
+ /** Each revision `records` name (one per workflow and digest, its newest record's K) added to the agent's reset ledger,
69
+ * before a reset deletes the records. A revision it holds already keeps its place and takes the records' K: while they
70
+ * stood, the ledger read their K (revisionLedgerOf), so the runs' shares read the same after this reset too. */
71
+ export async function keepResetLedger(settings, agentId, records) {
72
+ const newest = new Map();
73
+ for (const record of records)
74
+ newest.set(`${record.workflow}\0${record.digest}`, { workflow: record.workflow, digest: record.digest, k: record.check?.compile_after ?? null });
75
+ if (!newest.size)
76
+ return;
77
+ await updateKept(settings, resetLedgerKey(agentId), (items) => {
78
+ const held = new Set(items.map((one) => `${one.workflow}\0${one.digest}`));
79
+ return [...items.map((one) => newest.get(`${one.workflow}\0${one.digest}`) ?? one), ...[...newest].filter(([key]) => !held.has(key)).map(([, one]) => one)];
80
+ });
81
+ }
82
+ /** The agent's reset watermark: when its newest reset began (epoch ms). Learning reads only the runs after it
83
+ * (learn/compile.ts sinceReset): a run that started, or read its learning seed, at or before it learns nothing and is
84
+ * read by no compile, check, audit or money rule. Kept with the reset ledger, and removed with it by the agent's delete (learn/delete.ts). */
85
+ export const resetAtKey = (agentId) => `learning.reset-at.${agentId}`;
86
+ /** The agent's reset watermark (resetAtKey), or undefined when its learning was never reset. */
87
+ export const resetAtOf = async (settings, agentId) => {
88
+ const read = await settings.get(resetAtKey(agentId));
89
+ const at = typeof read === "object" && read !== null ? read.at : undefined;
90
+ return typeof at === "number" && Number.isFinite(at) ? at : undefined;
91
+ };
92
+ /** Agent `agentId`'s reset watermark set to `at`, in place of an earlier reset's. */
93
+ export const keepResetAt = (settings, agentId, at) => settings.put(resetAtKey(agentId), { at });
64
94
  /** The agent's grades, oldest first. */
65
95
  export const gradesOf = async (settings, agentId) => itemsOf(await settings.get(gradesKey(agentId)));
66
96
  /** Keeps `grade`, in place of any earlier grade of the same run, the newest GRADES_KEPT kept, at the next `seq`. */
@@ -88,24 +118,31 @@ const blankCheck = (one) => ({
88
118
  });
89
119
  /** An audit's disagreement blanked the same way: its run ids and whether a grade wrote it kept. */
90
120
  const blankAudit = (one) => ({ run: one.run, served: one.served, input: "", agent: null, draft: null, ...(one.graded ? { graded: true } : {}) });
91
- /** `record` with what it copied from run `runId` blanked: each disagreement naming it (a check's agent run; an audit's
92
- * served run or shadow run), and the grader's words its reason quotes from one (differentDecisionWords' example). Its
93
- * decision, numbers and run ids stay. The record itself when it names no such disagreement. */
121
+ /** `record` with what it copied from run `runId` blanked: each disagreement naming it (a check's agent run, a connected
122
+ * agent's collected turn too; an audit's served run or shadow run), and the grader's words its reason quotes from one
123
+ * (differentDecisionWords' example). Its decision, numbers and run ids stay. The record itself when it names no such
124
+ * disagreement. */
94
125
  function forgetRunIn(record, runId) {
95
126
  if (!record || typeof record !== "object")
96
127
  return record;
97
128
  const check = record.check?.disagreements?.some((one) => one.run === runId);
129
+ const turns = record.check?.turns?.disagreements?.some((one) => one.run === runId);
98
130
  const audit = record.audit?.disagreements.some((one) => one.run === runId || one.served === runId);
99
- if (!check && !audit)
131
+ if (!check && !turns && !audit)
100
132
  return record;
101
133
  let reason = record.reason;
102
134
  for (const one of record.check?.disagreements ?? [])
103
135
  if (one.run === runId && one.differs_on !== undefined)
104
136
  reason = reason.replace(` (for example: ${one.differs_on})`, "");
137
+ const blanked = (list) => list.map((one) => (one.run === runId ? blankCheck(one) : one));
105
138
  return {
106
139
  ...record,
107
140
  reason,
108
- ...(check && record.check ? { check: { ...record.check, disagreements: record.check.disagreements.map((one) => (one.run === runId ? blankCheck(one) : one)) } } : {}),
141
+ ...((check || turns) && record.check ? { check: {
142
+ ...record.check,
143
+ ...(check ? { disagreements: blanked(record.check.disagreements) } : {}),
144
+ ...(turns ? { turns: { ...record.check.turns, disagreements: blanked(record.check.turns.disagreements) } } : {}),
145
+ } } : {}),
109
146
  ...(audit && record.audit ? { audit: { ...record.audit, disagreements: record.audit.disagreements.map((one) => (one.run === runId || one.served === runId ? blankAudit(one) : one)) } } : {}),
110
147
  };
111
148
  }
@@ -214,9 +251,14 @@ export function shownDeep(value, shown, key) {
214
251
  : value !== null && typeof value === "object" ? Object.fromEntries(Object.entries(value).map(([field, one]) => [field, shownDeep(one, shown, field)]))
215
252
  : value;
216
253
  }
254
+ /** The runs whose copies `record`'s check has blanked (forgetRunIn): each disagreement, decided or of a turn collected,
255
+ * left as blankCheck leaves it. */
256
+ const blankedRuns = (record) => [...(record?.check?.disagreements ?? []), ...(record?.check?.turns?.disagreements ?? [])].filter((one) => isDeepStrictEqual(one, blankCheck(one))).map((one) => one.run);
217
257
  /** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
218
258
  * and of every record kept (`items`: a check across revisions, one at a time, in the same guarded write): so of two
219
- * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). */
259
+ * claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). What the one
260
+ * 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. */
220
262
  export async function recordPromotion(settings, agentId, record, still) {
221
263
  let out = { record, won: true };
222
264
  await updateKept(settings, promotionsKey(agentId), (saved) => {
@@ -226,8 +268,9 @@ export async function recordPromotion(settings, agentId, record, still) {
226
268
  out = { record: now, won: false };
227
269
  return items;
228
270
  }
229
- out = { record, won: true };
230
- return trimPromotions([...items, record]);
271
+ const kept = blankedRuns(now).reduce(forgetRunIn, record);
272
+ out = { record: kept, won: true };
273
+ return trimPromotions([...items, kept]);
231
274
  });
232
275
  return out;
233
276
  }
@@ -16,6 +16,11 @@ const BEARER_TOKEN = /(?<=\bBearer\s{1,3})(?=[A-Za-z._~+/-]*\d)[A-Za-z0-9._~+/-]
16
16
  * name stays. A signed URL's signature is one: whoever holds the URL holds what it grants. No bracket is a value's
17
17
  * character (a URL writes one percent-encoded), so a value already cut to "[redacted]" is never read as one. */
18
18
  const URL_CREDENTIAL = /(?<=[?&](?:api[_-]?key|access[_-]?token|auth[_-]?token|id[_-]?token|refresh[_-]?token|client[_-]?secret|x-amz-signature|x-amz-security-token|x-goog-signature|token|secret|password|passwd|signature|sig)=)[^\s&#"'`<>\\[\]]{16,}/i;
19
+ const URL_PASSWORD = /:\/\/[^\s/?#@:]+:[^\s/?#@]*@/;
20
+ /** A complete, single-quoted sed search expression whose password is only a capture pattern.
21
+ * The @ inside [^@] is regex syntax, not a password terminator. Require the closing capture,
22
+ * substitution/backreference and quote too; bracketed passwords or bare URLs are never exempt. */
23
+ const SED_URL_CAPTURE = /(?:^|[\s;(])sed[ \t]+-n[ \t]+'s\|https?:\/\/(?:[A-Za-z0-9._~-]+|\[\^:\]\*):\\\(\[\^@\]\*\\\)@[A-Za-z0-9.-]+\|\\1\|p'/g;
19
24
  /** A bank account number beside its word: "account", "acct", "a/c" or "bank account", maybe "number", "no.", "#", ":"
20
25
  * or "is" after it, then six digits or more, single dashes or spaces between them. A count before the word ("4
21
26
  * accounts"), a date (YYYY-MM-DD), a year or a card's last four is none: the word must come first, the digits right
@@ -38,7 +43,7 @@ const SHAPES = [
38
43
  ["Slack token", SLACK_TOKEN],
39
44
  ["JWT", JWT],
40
45
  ["webhook signing secret", WEBHOOK_SECRET],
41
- ["URL with a password", /:\/\/[^\s/?#@:]+:[^\s/?#@]*@/],
46
+ ["URL with a password", URL_PASSWORD],
42
47
  ["bearer token", BEARER_TOKEN],
43
48
  ["URL parameter named like a credential", URL_CREDENTIAL],
44
49
  ];
@@ -50,7 +55,7 @@ export const endsInScheme = (text) => {
50
55
  return head.length < text.length && text.length - head.length <= 3 && /\bBearer$/i.test(head.slice(-7));
51
56
  };
52
57
  /** The kinds of secret-shaped text in `text`. */
53
- export const secretShapes = (text) => SHAPES.filter(([, pattern]) => pattern.test(text)).map(([kind]) => kind);
58
+ export const secretShapes = (text) => SHAPES.filter(([, pattern]) => pattern === URL_PASSWORD ? spans(text, pattern).length > 0 : pattern.test(text)).map(([kind]) => kind);
54
59
  /** A bank's numbers beside their words, which learning never keeps: an account, IBAN, routing or sort-code number. Not
55
60
  * one of SHAPES: a run may show its user an account number (a finance job's answer), and SHAPES cut every run's view;
56
61
  * only what learning keeps refuses them (LS-09: graders held "send refunds to account 4471-0098" for the owner's OK,
@@ -67,9 +72,15 @@ export const learnedSecretShapes = (text) => [...secretShapes(text), ...MONEY_SH
67
72
  function spans(text, pattern) {
68
73
  const re = new RegExp(pattern.source, `${pattern.flags.replace("g", "")}g`);
69
74
  const out = [];
75
+ const expressions = pattern === URL_PASSWORD ? [...text.matchAll(SED_URL_CAPTURE)].map(match => [match.index, match.index + match[0].length]) : [];
76
+ let expression = 0;
70
77
  const next = RESUME.get(pattern) ?? ((m) => m.index + 1);
71
78
  for (let m = re.exec(text); m; m = re.exec(text)) {
72
- out.push([m.index, m.index + m[0].length]);
79
+ while (expression < expressions.length && expressions[expression][1] <= m.index)
80
+ expression++;
81
+ const range = expressions[expression];
82
+ if (!range || m.index < range[0] || m.index + m[0].length > range[1])
83
+ out.push([m.index, m.index + m[0].length]);
73
84
  re.lastIndex = Math.max(m.index + 1, next(m));
74
85
  }
75
86
  return out;
@@ -0,0 +1,18 @@
1
+ import type { DeleteLearning } from "./agent-delete.js";
2
+ import { type Store } from "./store/index.js";
3
+ /** What a reset does outside the learning module, as the server does it. */
4
+ export interface LearningResetHost {
5
+ readonly store: Store;
6
+ readonly deleteLearning: DeleteLearning;
7
+ /** The cancel path, for one run that is not final: true once a cancel stands for it, false when this server cannot
8
+ * end it (agent-delete.ts AgentDeleteHost.cancel). */
9
+ cancel(runId: string): Promise<boolean>;
10
+ /** `work` in agent `agentId`'s learning queue (learning.ts withAgentRepo). */
11
+ inQueue<T>(agentId: string, work: () => Promise<T>): Promise<T>;
12
+ /** How long step 1 waits for the agent's learning runs to be final, and how often it reads them meanwhile. */
13
+ readonly waitMs: number;
14
+ readonly pollMs: number;
15
+ }
16
+ /** Agent `agentId`'s learning reset in the two steps above. Throws ApiError learning_busy, nothing of its learning
17
+ * deleted, while a run of the agent's own is going or its learning runs cannot be stopped in time. */
18
+ export declare function resetLearning(host: LearningResetHost, agentId: string): Promise<void>;