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

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 (287) hide show
  1. package/CHANGELOG.md +149 -1
  2. package/README.md +295 -37
  3. package/dist/agent-delete.d.ts +5 -6
  4. package/dist/agent-delete.js +30 -67
  5. package/dist/agent-package.d.ts +71 -0
  6. package/dist/agent-package.js +345 -0
  7. package/dist/agent-rows.d.ts +1 -1
  8. package/dist/agents-store.d.ts +26 -20
  9. package/dist/agents-store.js +42 -34
  10. package/dist/api-only.d.ts +25 -6
  11. package/dist/api-only.js +34 -13
  12. package/dist/claude-login.d.ts +1 -0
  13. package/dist/claude-login.js +1 -1
  14. package/dist/cli-learning/cli.d.ts +3 -0
  15. package/dist/cli-learning/cli.js +17 -3
  16. package/dist/cli-learning/connections.js +3 -2
  17. package/dist/cli-learning/schema.js +2 -1
  18. package/dist/cli.js +76 -8
  19. package/dist/composio-preset.d.ts +3 -1
  20. package/dist/composio-preset.js +5 -3
  21. package/dist/composio-triggers.d.ts +4 -0
  22. package/dist/composio-triggers.js +4 -1
  23. package/dist/computer-needs.d.ts +32 -0
  24. package/dist/computer-needs.js +80 -0
  25. package/dist/computer-setting.d.ts +5 -2
  26. package/dist/computer-setting.js +8 -1
  27. package/dist/computers.d.ts +0 -2
  28. package/dist/computers.js +1 -1
  29. package/dist/console/assets/index-B_85An2t.js +745 -0
  30. package/dist/console/assets/index-n1YsbnYh.css +1 -0
  31. package/dist/console/index.html +2 -2
  32. package/dist/console-links.d.ts +1 -0
  33. package/dist/console-links.js +2 -0
  34. package/dist/env-switch.d.ts +14 -0
  35. package/dist/env-switch.js +23 -0
  36. package/dist/errors.d.ts +5 -0
  37. package/dist/errors.js +10 -0
  38. package/dist/eval-previous.js +4 -3
  39. package/dist/fal-price.js +10 -13
  40. package/dist/github-connection.d.ts +50 -1
  41. package/dist/github-connection.js +96 -3
  42. package/dist/github-faux.d.ts +11 -2
  43. package/dist/github-faux.js +138 -7
  44. package/dist/github-pull-request.d.ts +37 -0
  45. package/dist/github-pull-request.js +110 -0
  46. package/dist/handed-secret.d.ts +4 -0
  47. package/dist/handed-secret.js +10 -0
  48. package/dist/harness-archive.d.ts +15 -5
  49. package/dist/harness-archive.js +71 -34
  50. package/dist/harness-check.d.ts +2 -1
  51. package/dist/harness-check.js +36 -95
  52. package/dist/harness-egress.d.ts +23 -0
  53. package/dist/harness-egress.js +69 -0
  54. package/dist/harness-recipe-entry.d.ts +71 -0
  55. package/dist/harness-recipe-entry.js +184 -0
  56. package/dist/harness-recipe.d.ts +73 -6
  57. package/dist/harness-recipe.js +185 -31
  58. package/dist/harness-sign-in.d.ts +29 -0
  59. package/dist/harness-sign-in.js +122 -0
  60. package/dist/harness-table.d.ts +21 -0
  61. package/dist/harness-table.js +58 -3
  62. package/dist/harness-zip.d.ts +6 -0
  63. package/dist/harness-zip.js +203 -0
  64. package/dist/ids.d.ts +11 -0
  65. package/dist/ids.js +36 -0
  66. package/dist/learn/commit.d.ts +14 -1
  67. package/dist/learn/commit.js +156 -1
  68. package/dist/learn/compile.js +22 -8
  69. package/dist/learn/folder.d.ts +5 -0
  70. package/dist/learn/folder.js +10 -1
  71. package/dist/learn/learning.sh +15 -3
  72. package/dist/learn/promote.d.ts +2 -2
  73. package/dist/learn/secrets.js +30 -7
  74. package/dist/learning-routes.d.ts +23 -11
  75. package/dist/learning-routes.js +110 -20
  76. package/dist/learning.d.ts +9 -6
  77. package/dist/learning.js +9 -4
  78. package/dist/live-reach.d.ts +34 -7
  79. package/dist/live-reach.js +76 -11
  80. package/dist/mcp-gateway.js +15 -2
  81. package/dist/mcp-probe.d.ts +3 -0
  82. package/dist/mcp-probe.js +8 -3
  83. package/dist/mcp-resources.d.ts +44 -0
  84. package/dist/mcp-resources.js +100 -0
  85. package/dist/mcp-servers-store.d.ts +16 -12
  86. package/dist/model.d.ts +4 -4
  87. package/dist/model.js +6 -6
  88. package/dist/native/cli.js +9 -2
  89. package/dist/native/connection.d.ts +2 -2
  90. package/dist/native/connection.js +5 -2
  91. package/dist/native/discovery.d.ts +2 -0
  92. package/dist/native/discovery.js +10 -6
  93. package/dist/native/remote-worker-bridge.js +36 -4
  94. package/dist/native/remote.d.ts +18 -1
  95. package/dist/native/remote.js +126 -37
  96. package/dist/native/schema.d.ts +6 -0
  97. package/dist/native/schema.js +31 -6
  98. package/dist/native/source-account.d.ts +13 -0
  99. package/dist/native/source-account.js +114 -0
  100. package/dist/native/source-capture-hooks.d.ts +5 -0
  101. package/dist/native/source-capture-hooks.js +102 -0
  102. package/dist/native/source-mcp-selection.d.ts +13 -0
  103. package/dist/native/source-mcp-selection.js +72 -0
  104. package/dist/native/source-runtime-tools.d.ts +19 -0
  105. package/dist/native/source-runtime-tools.js +103 -0
  106. package/dist/native/source-snapshot-types.d.ts +138 -0
  107. package/dist/native/source-snapshot-types.js +12 -0
  108. package/dist/native/source-snapshot.d.ts +8 -0
  109. package/dist/native/source-snapshot.js +1201 -0
  110. package/dist/observation/learning.js +3 -2
  111. package/dist/openapi.js +275 -40
  112. package/dist/print.js +1 -1
  113. package/dist/purged-workflow.d.ts +12 -0
  114. package/dist/purged-workflow.js +43 -0
  115. package/dist/run-keys.d.ts +46 -0
  116. package/dist/run-keys.js +109 -0
  117. package/dist/run-launch.d.ts +16 -1
  118. package/dist/run-launch.js +30 -1
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-model-key.d.ts +2 -2
  121. package/dist/run-model-key.js +5 -5
  122. package/dist/run-secrets.d.ts +2 -0
  123. package/dist/run-secrets.js +7 -4
  124. package/dist/run-view.d.ts +17 -0
  125. package/dist/run-view.js +25 -1
  126. package/dist/runner/adapter-loop.d.ts +11 -3
  127. package/dist/runner/adapter-loop.js +138 -22
  128. package/dist/runner/adapter-run-spec.js +26 -13
  129. package/dist/runner/audit.d.ts +2 -0
  130. package/dist/runner/audit.js +9 -1
  131. package/dist/runner/beside.js +2 -1
  132. package/dist/runner/claim-secrets.d.ts +29 -3
  133. package/dist/runner/claim-secrets.js +38 -4
  134. package/dist/runner/cli-run-spec.js +24 -13
  135. package/dist/runner/harness-loops.d.ts +6 -0
  136. package/dist/runner/harness-loops.js +11 -1
  137. package/dist/runner/held.d.ts +4 -0
  138. package/dist/runner/journal-kinds.d.ts +2 -0
  139. package/dist/runner/learned-first.d.ts +2 -0
  140. package/dist/runner/learned-first.js +1 -1
  141. package/dist/runner/learning-end.d.ts +7 -2
  142. package/dist/runner/learning-end.js +22 -10
  143. package/dist/runner/learning-seed.d.ts +9 -3
  144. package/dist/runner/learning-seed.js +2 -2
  145. package/dist/runner/main.d.ts +1 -0
  146. package/dist/runner/main.js +20 -13
  147. package/dist/runner/mcp-claim.js +6 -1
  148. package/dist/runner/mcp-run.d.ts +10 -7
  149. package/dist/runner/mcp-run.js +3 -5
  150. package/dist/runner/metrics.d.ts +4 -2
  151. package/dist/runner/metrics.js +15 -3
  152. package/dist/runner/monid-run.js +9 -11
  153. package/dist/runner/pr-checkout.d.ts +21 -4
  154. package/dist/runner/pr-checkout.js +103 -4
  155. package/dist/runner/project-checkpoint.d.ts +35 -0
  156. package/dist/runner/project-checkpoint.js +116 -0
  157. package/dist/runner/project-drain.d.ts +8 -0
  158. package/dist/runner/project-drain.js +25 -0
  159. package/dist/runner/project-host.d.ts +10 -0
  160. package/dist/runner/project-host.js +52 -0
  161. package/dist/runner/promotion.d.ts +14 -6
  162. package/dist/runner/promotion.js +98 -41
  163. package/dist/runner/redact.d.ts +13 -0
  164. package/dist/runner/redact.js +67 -1
  165. package/dist/runner/run-channel.d.ts +9 -0
  166. package/dist/runner/run-channel.js +15 -2
  167. package/dist/runner/run-child-host.d.ts +8 -4
  168. package/dist/runner/run-child-host.js +178 -45
  169. package/dist/runner/run-errors.js +2 -2
  170. package/dist/runner/runner-check.d.ts +3 -0
  171. package/dist/runner/runner-check.js +28 -2
  172. package/dist/runner/runner.js +26 -9
  173. package/dist/runner/store-secrets.js +7 -3
  174. package/dist/runner/workflow-first.d.ts +4 -0
  175. package/dist/runner/workflow-first.js +13 -0
  176. package/dist/runner/workflow-loop.d.ts +2 -1
  177. package/dist/runner/workflow-loop.js +2 -1
  178. package/dist/runner/workflow-spec.js +1 -1
  179. package/dist/runs-over-store.d.ts +34 -6
  180. package/dist/runs-over-store.js +133 -25
  181. package/dist/sdk/runs.d.ts +11 -1
  182. package/dist/sdk/runs.js +117 -26
  183. package/dist/sdk/schema.js +12 -2
  184. package/dist/sdk/workflows.d.ts +1 -1
  185. package/dist/server.d.ts +79 -32
  186. package/dist/server.js +673 -113
  187. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  188. package/dist/source-sync/adoption.d.ts +15 -0
  189. package/dist/source-sync/adoption.js +36 -0
  190. package/dist/source-sync/auxiliary.d.ts +23 -0
  191. package/dist/source-sync/auxiliary.js +64 -0
  192. package/dist/source-sync/capture-git.d.ts +5 -0
  193. package/dist/source-sync/capture-git.js +272 -0
  194. package/dist/source-sync/capture-project.d.ts +53 -0
  195. package/dist/source-sync/capture-project.js +206 -0
  196. package/dist/source-sync/capture-refusal.d.ts +7 -0
  197. package/dist/source-sync/capture-refusal.js +16 -0
  198. package/dist/source-sync/capture.d.ts +11 -0
  199. package/dist/source-sync/capture.js +22 -0
  200. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  201. package/dist/source-sync/checkpoint-gate.js +52 -0
  202. package/dist/source-sync/checkpoints.d.ts +66 -0
  203. package/dist/source-sync/checkpoints.js +168 -0
  204. package/dist/source-sync/claim.d.ts +11 -0
  205. package/dist/source-sync/claim.js +48 -0
  206. package/dist/source-sync/destination.d.ts +47 -0
  207. package/dist/source-sync/destination.js +239 -0
  208. package/dist/source-sync/io.d.ts +15 -0
  209. package/dist/source-sync/io.js +52 -0
  210. package/dist/source-sync/local.d.ts +43 -0
  211. package/dist/source-sync/local.js +229 -0
  212. package/dist/source-sync/prepare.d.ts +59 -0
  213. package/dist/source-sync/prepare.js +93 -0
  214. package/dist/source-sync/projects.d.ts +61 -0
  215. package/dist/source-sync/projects.js +130 -0
  216. package/dist/source-sync/registry.d.ts +95 -0
  217. package/dist/source-sync/registry.js +226 -0
  218. package/dist/source-sync/service.d.ts +33 -0
  219. package/dist/source-sync/service.js +118 -0
  220. package/dist/source-sync/skill-edits.d.ts +12 -0
  221. package/dist/source-sync/skill-edits.js +122 -0
  222. package/dist/source-sync/snapshots.d.ts +48 -0
  223. package/dist/source-sync/snapshots.js +448 -0
  224. package/dist/source-sync/types.d.ts +9 -0
  225. package/dist/source-sync/types.js +14 -0
  226. package/dist/source-sync/workspace.d.ts +66 -0
  227. package/dist/source-sync/workspace.js +273 -0
  228. package/dist/store/agent-body.d.ts +6 -2
  229. package/dist/store/agent-body.js +18 -7
  230. package/dist/store/index.d.ts +2 -2
  231. package/dist/store/index.js +1 -1
  232. package/dist/store/schema.d.ts +2 -1
  233. package/dist/store/schema.js +2 -1
  234. package/dist/store/seal.d.ts +5 -1
  235. package/dist/store/seal.js +12 -3
  236. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  237. package/dist/store/sqlite/project-checkpoints.js +70 -0
  238. package/dist/store/sqlite/run-launch.d.ts +4 -12
  239. package/dist/store/sqlite/run-launch.js +5 -19
  240. package/dist/store/sqlite/store.js +224 -170
  241. package/dist/store/store.d.ts +116 -39
  242. package/dist/store/store.js +14 -1
  243. package/dist/store-reads/learning.d.ts +2 -2
  244. package/dist/store-view.d.ts +3 -1
  245. package/dist/store-view.js +17 -5
  246. package/dist/suggestions.d.ts +282 -0
  247. package/dist/suggestions.js +919 -0
  248. package/dist/telemetry.d.ts +8 -1
  249. package/dist/telemetry.js +12 -4
  250. package/dist/template-import.d.ts +27 -2
  251. package/dist/template-import.js +148 -13
  252. package/dist/templates.d.ts +103 -77
  253. package/dist/templates.js +71 -17
  254. package/dist/timeline/index.d.ts +1 -1
  255. package/dist/timeline/index.js +1 -1
  256. package/dist/timeline/timeline.d.ts +5 -0
  257. package/dist/timeline/timeline.js +8 -0
  258. package/dist/tool-plane.d.ts +12 -12
  259. package/dist/tools.d.ts +8 -8
  260. package/dist/trigger-launch-hook.d.ts +49 -0
  261. package/dist/trigger-launch-hook.js +91 -0
  262. package/dist/trigger-targets.d.ts +14 -1
  263. package/dist/trigger-targets.js +20 -0
  264. package/dist/triggers.d.ts +54 -5
  265. package/dist/triggers.js +143 -8
  266. package/dist/uploads-archil.js +1 -1
  267. package/dist/uploads.js +1 -1
  268. package/dist/validate.d.ts +1 -1
  269. package/dist/validate.js +3 -4
  270. package/dist/workspace/computer-for-claim.d.ts +2 -0
  271. package/dist/workspace/computer-for-claim.js +43 -0
  272. package/dist/workspace/paths.d.ts +6 -0
  273. package/dist/workspace/paths.js +6 -0
  274. package/dist/workspace/resolve-computer.d.ts +1 -0
  275. package/dist/workspace/run-tools.d.ts +2 -0
  276. package/dist/workspace/run-tools.js +8 -0
  277. package/dist/workspace/synced-folder.d.ts +1 -1
  278. package/dist/workspace/synced-folder.js +11 -14
  279. package/launcher/agentrun-serve +1 -1
  280. package/package.json +10 -10
  281. package/skills/agentrun-serve/SKILL.md +2 -1
  282. package/templates/README.md +8 -4
  283. package/templates/agent-scout/agent.md +46 -0
  284. package/templates/agent-scout/skills/scout/SKILL.md +88 -0
  285. package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
  286. package/dist/console/assets/index-B-D0EM3j.js +0 -733
  287. package/dist/console/assets/index-DlQepP2J.css +0 -1
@@ -0,0 +1,116 @@
1
+ import { projectBaseline, projectCandidate } from "../source-sync/checkpoints.js";
2
+ import { commitSourceSnapshot, readSourceSnapshot } from "../source-sync/snapshots.js";
3
+ import { captureManagedProject, sourceSnapshotReader, sourceWorkspace } from "../source-sync/workspace.js";
4
+ import { withSourceIO } from "../source-sync/io.js";
5
+ import { held } from "./held.js";
6
+ import { ProjectCaptureRefusal } from "../source-sync/capture-refusal.js";
7
+ export function runProjectCheckpoint(input) {
8
+ const { store, agentId, claim, launch, tools, computer } = input;
9
+ let stage = "drain";
10
+ let refusalSettled = false;
11
+ const uncertain = () => ({ version: 1, status: "uncertain", sourceId: launch.sourceProject.sourceId,
12
+ runId: claim.runId, epoch: claim.epoch, reason: ["read", "open", "capture", "commit", "cleanup"].includes(stage) ? "project_capture_failed" : "project_not_settled", stage });
13
+ return {
14
+ uncertain,
15
+ /** Host-private evidence, never a field the child can supply in a checkpoint receipt. */
16
+ refusalSettled: () => refusalSettled,
17
+ async capture(signal) {
18
+ refusalSettled = false;
19
+ signal.throwIfAborted();
20
+ if (launch.audit || launch.replay) {
21
+ const settle = async () => {
22
+ stage = "settle";
23
+ await tools.settleProject();
24
+ signal.throwIfAborted();
25
+ stage = "sync";
26
+ if (computer.computer && !computer.syncProject)
27
+ throw new Error("The project's computer has no verified durable synchronization capability.");
28
+ await computer.syncProject?.(signal);
29
+ signal.throwIfAborted();
30
+ return { version: 1, status: "discarded", sourceId: launch.sourceProject.sourceId, runId: claim.runId,
31
+ epoch: claim.epoch, reason: "auxiliary_project_changes_not_applied" };
32
+ };
33
+ return input.ioHeld ? settle() : withSourceIO(store, agentId, "snapshot", settle);
34
+ }
35
+ stage = "baseline";
36
+ const baseline = await projectBaseline(store, claim.runId);
37
+ if (!baseline || baseline.epoch >= claim.epoch)
38
+ return { ...uncertain(), reason: "project_baseline_invalid" };
39
+ // Existing-only immutable reads have no filesystem side effects. Refusals here need no unresolved writer
40
+ // receipt; opening a writable backend, stopping programs and every later cleanup do require ownership.
41
+ stage = "read";
42
+ const reader = await sourceSnapshotReader(store, agentId, { ...input.workspace, signal });
43
+ let original;
44
+ try {
45
+ original = await readSourceSnapshot(reader.workspace, baseline.digest);
46
+ }
47
+ finally {
48
+ await reader.end();
49
+ }
50
+ signal.throwIfAborted();
51
+ // A later claim can finish this run while an old claim's backend request is still pending. The run's live row
52
+ // therefore cannot protect these writes from deletion: keep independent durable ownership through cleanup.
53
+ const captureOwned = async () => {
54
+ stage = "settle";
55
+ const logs = await tools.settleProject();
56
+ signal.throwIfAborted();
57
+ stage = "sync";
58
+ if (computer.computer && !computer.syncProject)
59
+ throw new Error("The project's computer has no verified durable synchronization capability.");
60
+ await computer.syncProject?.(signal);
61
+ signal.throwIfAborted();
62
+ stage = "open";
63
+ // Preserve the exact storage selected by the baseline reader, rather than allocating on a different disk
64
+ // if the agent's current disk metadata changes while capture is in progress.
65
+ const cache = await sourceWorkspace(store, agentId, { ...input.workspace, signal }, reader.launchDisk ? { launch: { ...launch, archilDisk: reader.launchDisk } } : {});
66
+ try {
67
+ stage = "capture";
68
+ const snapshot = await captureManagedProject(store, { agentId, runId: claim.runId, launch, workspace: tools.workspace, baseline: original, signal,
69
+ secretValues: await input.secrets(), exclude: [
70
+ { path: "inputs/message.md", recursive: false }, { path: ".agentrun/tmp", recursive: true }, { path: ".agentrun/output", recursive: true },
71
+ ...(launch.sourceProject?.inputs ?? []).map(path => ({ path, recursive: false })), ...logs.map(path => ({ path, recursive: false })),
72
+ ] }, { ...input.workspace, signal });
73
+ signal.throwIfAborted();
74
+ stage = "commit";
75
+ const digest = await commitSourceSnapshot(cache.workspace, snapshot);
76
+ signal.throwIfAborted();
77
+ return projectCandidate({ sourceId: baseline.sourceId, runId: claim.runId, epoch: claim.epoch, baselineRevision: baseline.revision, baselineDigest: baseline.digest, digest });
78
+ }
79
+ finally {
80
+ try {
81
+ await cache.end();
82
+ }
83
+ catch (error) {
84
+ stage = "cleanup";
85
+ throw error;
86
+ }
87
+ }
88
+ };
89
+ const capture = async () => {
90
+ try {
91
+ return await captureOwned();
92
+ }
93
+ catch (error) {
94
+ // Both captureManagedProject's scratch/backend cleanup and captureOwned's cache cleanup have completed
95
+ // before this catch. Execution failures and observed mutations never carry this internal brand.
96
+ if (!(error instanceof ProjectCaptureRefusal) || stage !== "capture" || signal.aborted)
97
+ throw error;
98
+ refusalSettled = true;
99
+ return uncertain();
100
+ }
101
+ };
102
+ return input.ioHeld ? capture() : withSourceIO(store, agentId, "snapshot", capture);
103
+ },
104
+ };
105
+ }
106
+ /** The isolated child asks only for its host-bound checkpoint; it receives no store/cache/credential capability. */
107
+ export function projectCheckpointForRun(input, dispatched) {
108
+ const host = input.workspace.sealKey === undefined ? held() : undefined;
109
+ if (!host)
110
+ return runProjectCheckpoint(input);
111
+ return {
112
+ capture: (signal) => { dispatched(); return host.projectCheckpoint(signal); },
113
+ uncertain: () => ({ version: 1, status: "uncertain", sourceId: input.launch.sourceProject.sourceId,
114
+ runId: input.claim.runId, epoch: input.claim.epoch, reason: "project_not_settled", stage: "drain" }),
115
+ };
116
+ }
@@ -0,0 +1,8 @@
1
+ /** A moved project's dispatch fence within one claim. The store still fences journal commits; this only ensures
2
+ * project capture cannot race host/tool calls admitted by this loop. It never retries an interrupted effect. */
3
+ export declare class ProjectDrain {
4
+ #private;
5
+ get closed(): boolean;
6
+ run<T>(call: () => Promise<T>): Promise<T>;
7
+ close(signal: AbortSignal): Promise<void>;
8
+ }
@@ -0,0 +1,25 @@
1
+ /** A moved project's dispatch fence within one claim. The store still fences journal commits; this only ensures
2
+ * project capture cannot race host/tool calls admitted by this loop. It never retries an interrupted effect. */
3
+ export class ProjectDrain {
4
+ #closed = false;
5
+ #active = new Set();
6
+ get closed() { return this.#closed; }
7
+ async run(call) {
8
+ if (this.#closed)
9
+ throw new Error("The project's dispatch has closed for checkpoint capture.");
10
+ const pending = Promise.resolve().then(call);
11
+ this.#active.add(pending);
12
+ try {
13
+ return await pending;
14
+ }
15
+ finally {
16
+ this.#active.delete(pending);
17
+ }
18
+ }
19
+ async close(signal) {
20
+ this.#closed = true;
21
+ // Cancellation requests a stop; it is never evidence that an already dispatched write actually stopped.
22
+ await Promise.allSettled([...this.#active]);
23
+ signal.throwIfAborted();
24
+ }
25
+ }
@@ -0,0 +1,10 @@
1
+ export declare class ProjectHostGate {
2
+ #private;
3
+ get uncertain(): boolean;
4
+ close(): void;
5
+ drain(): Promise<void>;
6
+ run<T>(work: () => T | Promise<T>, writes?: boolean): Promise<T>;
7
+ /** Recursively cover returned callable handles too (Workspace.attach, computer clients, and Pieces.write).
8
+ * Data stays data; methods retain their original receiver so backend private fields remain valid. */
9
+ capability<T extends object>(value: T): T;
10
+ }
@@ -0,0 +1,52 @@
1
+ /** A moved project's capabilities exported to a child process. Closing denies new calls through retained handles;
2
+ * draining waits for the actual dispatched promises, even if their cancellation has already been requested. */
3
+ import { ClaimRefused } from "./loop-contract.js";
4
+ export class ProjectHostGate {
5
+ #closed = false;
6
+ #active = new Set();
7
+ #wrapped = new WeakMap();
8
+ #uncertain = false;
9
+ get uncertain() { return this.#uncertain; }
10
+ close() { this.#closed = true; }
11
+ async drain() { await Promise.allSettled([...this.#active]); }
12
+ async run(work, writes = true) {
13
+ if (this.#closed)
14
+ throw new ClaimRefused("The project's dispatch has closed for checkpoint capture.");
15
+ const pending = Promise.resolve().then(work);
16
+ this.#active.add(pending);
17
+ try {
18
+ return await pending;
19
+ }
20
+ catch (error) {
21
+ if (writes)
22
+ this.#uncertain = true;
23
+ throw error;
24
+ }
25
+ finally {
26
+ this.#active.delete(pending);
27
+ }
28
+ }
29
+ /** Recursively cover returned callable handles too (Workspace.attach, computer clients, and Pieces.write).
30
+ * Data stays data; methods retain their original receiver so backend private fields remain valid. */
31
+ capability(value) {
32
+ if (value instanceof AbortSignal || value instanceof Date || ArrayBuffer.isView(value) || value instanceof ArrayBuffer || value instanceof Map || value instanceof Set)
33
+ return value;
34
+ if (Array.isArray(value))
35
+ return value.map(item => item && typeof item === "object" ? this.capability(item) : item);
36
+ const existing = this.#wrapped.get(value);
37
+ if (existing)
38
+ return existing;
39
+ const wrapped = new Proxy(value, { get: (target, key) => {
40
+ const member = Reflect.get(target, key, target);
41
+ if (typeof member === "function")
42
+ return (...args) => this.run(async () => {
43
+ const answer = await Reflect.apply(member, target, args);
44
+ return answer && typeof answer === "object" ? this.capability(answer) : answer;
45
+ }, !["read", "stat", "list", "grep", "readBack", "readBackOf", "wait"].includes(String(key))
46
+ && !(key === "call" && typeof args[0] === "string" && ["hello", "files.read", "files.stat", "files.list", "process.read", "process.list", "process.wait"].includes(args[0])));
47
+ return member && typeof member === "object" ? this.capability(member) : member;
48
+ } });
49
+ this.#wrapped.set(value, wrapped);
50
+ return wrapped;
51
+ }
52
+ }
@@ -1,3 +1,4 @@
1
+ import type { AuxiliaryAdmitter } from "../source-sync/auxiliary.js";
1
2
  import type { Context } from "@earendil-works/chord/context";
2
3
  import type { LearnedWorkflow } from "../learning.js";
3
4
  import { type RunLaunch } from "../run-launch.js";
@@ -16,6 +17,7 @@ export declare const REPLAY_DEADLINE_MS: number;
16
17
  export declare const REPLAY_LAUNCH_GRACE_MS: number;
17
18
  export interface PromotionDeps {
18
19
  readonly store: Store;
20
+ readonly admitAuxiliary?: AuxiliaryAdmitter;
19
21
  /** Why model spend beside the claimed run is skipped (claim-secrets.ts claimSpendOff): a replay check starts runs with
20
22
  * no caller's key. Absent: it runs. */
21
23
  readonly spendOff?: (what: string) => string | undefined;
@@ -30,7 +32,8 @@ export interface PromotionDeps {
30
32
  readonly context: Context;
31
33
  readonly log: (line: string) => void;
32
34
  /** The learned workflow `name` as the learning folder held it active at `commit` (a champion's text), or undefined when
33
- * it held none by that name. Absent: no champion serves. */
35
+ * it held none by that name, or a purged run wrote it (learning.ts seedAt): a purged champion is no champion's text,
36
+ * and the agent takes the run. Absent: no champion serves. */
34
37
  readonly champion?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>;
35
38
  /** The digest of the learned workflow `name` the learning folder's main holds now (the newest revision), or undefined
36
39
  * when it holds none by that name. Absent: every revision is the newest. */
@@ -139,9 +142,14 @@ export declare function decideCheck(deps: DecideDeps, name: string, digest: stri
139
142
  }, still: Parameters<typeof recordPromotion>[3], extra: Partial<PromotionRecord>): Promise<import("../learn/promote.js").Recorded>;
140
143
  /** How many of a connected agent's reserved native turns its check gives back in a row (failed, a learned workflow or
141
144
  * nested call in it, redacted evidence, no shadow report, or a shadow that did not answer; never a cancel, and a turn
142
- * that lands starts the count again) before it holds the draft, never promoted and never stopped for good, for the next
143
- * compile to revise and check afresh: five in a row say the integration cannot give a baseline now, not that it never will. */
145
+ * that lands starts the count again) before it holds the draft, never promoted and never stopped for good, for the
146
+ * agent's next compile after compile_after more of its runs (runner/learning-end.ts compileAskOf) to revise and check
147
+ * afresh: five in a row say the integration cannot give a baseline now, not that it never will. The one list of the
148
+ * causes a give-back has: every other mention points here. */
144
149
  export declare const SDK_CHECK_RELEASES = 5;
150
+ /** Whether a hold's check is a connected agent's held on SDK_CHECK_RELEASES give-backs in a row (releaseSdkCheck): only
151
+ * a connected agent's check counts give-backs. */
152
+ export declare const heldOnGiveBacks: (check: CheckRecord | undefined) => boolean;
145
153
  /** Which attempt a revision compile of `held` is when its draft fails its checks (runner/learning-end.ts
146
154
  * recordDraftFailed): 2, the recompile, for any hold but a connected agent's on give-backs, which spends none: its
147
155
  * check's own attempt, until a revise of it has failed once already (the workflow's newest record that failed draft). */
@@ -193,7 +201,8 @@ export declare function sdkCheckDeadline(deps: DecideDeps, pending: PromotionRec
193
201
  /** Gives back a connected agent's reserved native turn that cannot be its check's baseline (`cause`): the check waits for
194
202
  * the next turn the draft takes, nothing decided or promoted, the turns it checked kept on the record. A `counted` turn
195
203
  * (not a cancel, not a start that was never admitted) counts toward SDK_CHECK_RELEASES in a row, whose last holds the
196
- * draft for the next compile, whose revision is checked afresh. Kept only while the record is still this reservation. */
204
+ * draft for a compile after compile_after more runs, whose revision is checked afresh. Kept only while the record is
205
+ * still this reservation. */
197
206
  export declare function releaseSdkCheck(deps: DecideDeps, record: PromotionRecord, cause: string, counted?: boolean): Promise<import("../learn/promote.js").Recorded | undefined>;
198
207
  /** A run's final answer row, its text whole (its last final answer row that is not its end-of-run turn's), or null: none,
199
208
  * or its record could not be read. `turn`: the row of that id instead (the answer an audit is of, runner/audit.ts), so an
@@ -204,8 +213,6 @@ export declare function answerRowOf(store: PromotionDeps["store"], runId: string
204
213
  } | null>;
205
214
  /** A run's final answer, whole (answerRowOf's text; `turn`: that row's), or null. */
206
215
  export declare const answerOf: (store: PromotionDeps["store"], runId: string, context: Context, turn?: string) => Promise<string | null>;
207
- /** Why a replay a person asked for (askReplay) or read (replayView) was refused: `missing`, no such workflow, revision or
208
- * replay of the agent (404); `conflict`, the revision cannot replay now (409), in words that say why. */
209
216
  export declare class ReplayRefused extends Error {
210
217
  readonly kind: "missing" | "conflict";
211
218
  constructor(kind: "missing" | "conflict", message: string);
@@ -215,6 +222,7 @@ export declare class ReplayRefused extends Error {
215
222
  * on: a replay run's is this one with its agent run's input (startReplay), at the revision's learning commit. */
216
223
  export interface ReplayAsk {
217
224
  readonly store: Store;
225
+ readonly admitAuxiliary?: AuxiliaryAdmitter;
218
226
  readonly agentId: string;
219
227
  readonly context: Context;
220
228
  readonly log: (line: string) => void;
@@ -1,8 +1,53 @@
1
+ // Promotion, at a run's claim (champion/challenger, shadow deployment): the learned workflow that fits the run's input
2
+ // serves first only when its digest is promoted (learn/promote.ts). Promote once: a digest with no record yet, the learning
3
+ // folder's newest revision, is checked once (startCheck): a replay run of it (RunLaunch.replay, at workflow cost) on the
4
+ // input of each of the agent's last compile_after completed runs of its own (its definition's `learning`,
5
+ // learning-setting.ts), the agent taking the runs meanwhile. A later claim that finds every check run ended scores each
6
+ // against the agent's own recorded answer (learn/promote.ts sameAnswer; no grade is read) and promotes the digest when,
7
+ // of the inputs it ran on, it answered at least alone_min alone and at least agree_min of those said what the agent said
8
+ // (checkPasses); else it is held, its record keeping the inputs it disagreed on, which the agent's next run's compile
9
+ // turn reads to write its one recompile (learn/compile.ts); that revision is checked the same way, once, and a hold of
10
+ // it stops (nothing compiles again). A check-promoted digest is never checked again: no grade, no refit, no queue, no
11
+ // second replay. Every reserved input counts: one whose replay run was never created, or never ended, by the check's
12
+ // deadline is a failed input. With nothing to check it on (no input of the agent's it takes, or every input skipped at a
13
+ // write) it is never promoted: it stops, its record naming why (stopUnchecked), and asks no recompile.
14
+ //
15
+ // The champion keeps serving meanwhile: while the folder's revision (the challenger) is checked, or once it is held, the
16
+ // digest promoted last (learn/promote.ts championOf) serves the run, read from the learning commit its record names. Only
17
+ // the money rule (workflow-first.ts) stops it. Who serves is the champion alone, read at every run's claim, a queued run's
18
+ // included (servingNow): a digest's own promote record never serves it once another digest was promoted after it. A run
19
+ // already executing (an earlier claim of it served a workflow first) keeps that revision (keptFor). A serving revision
20
+ // this release's workflow DSL refuses (a key an older release took, say) is held at the claim that finds it, once per
21
+ // digest, its reason the DSL's (holdRefused): the run hands back as before, and the hold asks the one recompile.
22
+ // One check at a time: a check at work finishes (a revision newer than it waits, and decides it first: settleAhead). The
23
+ // check is reserved before any of its replay runs starts: its replaying record, naming the runs it will start, is kept
24
+ // only while no other revision of the workflow replays (the rival check in the same guarded write), so two claims of two
25
+ // revisions at once start one check. A reserved run not created yet is pending, never ended: a claim between the
26
+ // reservation and the creates decides nothing, and a launch interrupted there (a crash, a failed create) is finished by a
27
+ // claim REPLAY_LAUNCH_GRACE_MS on, each run under its reserved id on the input its record names (relaunch), with the
28
+ // launch its record chose when it was reserved (PromotionRecord.launch: model, revision, credentials), never the finishing
29
+ // claim's. Every decision is acted on (replay runs started, runs cancelled) only by the claim whose write kept it
30
+ // (learn/promote.ts Recorded.won). A check decided with runs still at work (its deadline passed) cancels them. A replay
31
+ // run's claim refuses it unless its revision still replays (replayClaimed), so a cancel lost to a crash or a failed write
32
+ // never leaves one running.
33
+ // A replay never repeats a side effect and runs with what a served run of the agent has (learn/replay-calls.ts, SPEC B4):
34
+ // each call node's tool is a read or a write; a read runs live through a cache seeded from the agent's recorded calls, a
35
+ // write is answered only from that recording (same tool, same canonical arguments) and is never sent, and an input whose
36
+ // workflow needs a write the recording does not have is skipped (counted in the record's check.outcomes, never scored); a
37
+ // check whose every input was skipped holds the revision in those words, or, when the tool that stopped them is an MCP
38
+ // tool its server listed with no readOnlyHint, naming it (check.skipped_tools). Its credentials resolve at its claim as
39
+ // any run's of the agent do: saved ones from the server's store, and the per_run MCP credentials the run whose claim
40
+ // reserved it was handed (its record's launch.handed_from), sealed anew for the replay run alone (startReplay), never
41
+ // opened outside the claim.
42
+ // Its owner may start one too (askReplay, POST .../revisions/{digest}/replays): a held revision re-checked, or an edited
43
+ // one, on the inputs it was last checked on or the agent's newest, decided by the same settleCheck, at a claim that lays
44
+ // it or at its read (replayView), so its records are a claim-started check's.
45
+ import { sourceSyncOf } from "../source-sync/types.js";
1
46
  import { LEARNING_LABEL } from "../learning.js";
2
47
  import { loopOf } from "../learning-setting.js";
3
48
  import { LEARNED_WORKFLOW_TOOL } from "../learned-workflow.js";
4
49
  import { launchBody, readLaunchBody } from "../run-launch.js";
5
- import { uuidv7 } from "../runs-over-store.js";
50
+ import { uuidv7 } from "../ids.js";
6
51
  import { FINAL_STATES, RunFinal, RunPurged, StoreConstraint } from "../store/store.js";
7
52
  import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
8
53
  import { isCliRecord, piShaped, runEntries, runTimeline } from "../store-reads/journal.js";
@@ -32,7 +77,7 @@ export function claimPromotion(deps) {
32
77
  return {
33
78
  ...deps,
34
79
  kept: async () => (deps.runId ? servedOf(await runEntries(deps.store, deps.runId, deps.context).catch(() => [])) : undefined),
35
- champion: async (name, commit) => (await workflowsAt({ folder: deps.folder, shown: deps.shown }, commit)).find((one) => one.name === name),
80
+ champion: async (name, commit) => (await workflowsAt({ folder: deps.folder, store: deps.store, shown: deps.shown }, commit)).find((one) => one.name === name),
36
81
  newest: async (name) => {
37
82
  const folder = deps.folder();
38
83
  let main;
@@ -42,7 +87,7 @@ export function claimPromotion(deps) {
42
87
  finally {
43
88
  await folder.end().catch(() => undefined);
44
89
  }
45
- const text = main ? (await workflowsAt({ folder: deps.folder, shown: deps.shown }, main)).find((one) => one.name === name) : undefined;
90
+ const text = main ? (await workflowsAt({ folder: deps.folder, store: deps.store, shown: deps.shown }, main)).find((one) => one.name === name) : undefined;
46
91
  return text ? workflowDigest(text) : undefined;
47
92
  },
48
93
  };
@@ -337,6 +382,10 @@ async function checkInputs(deps, workflow, pick, audited = []) {
337
382
  * it fits), it is decided at once: never promoted, it stops with nothing checked (stopUnchecked). */
338
383
  async function startCheck(deps, workflow, digest) {
339
384
  const { store, agentId, log } = deps;
385
+ if ((deps.launch.sourceProject || sourceSyncOf((await store.agents.revision(deps.revisionId))?.body)) && !deps.admitAuxiliary) {
386
+ log(`workflow-first: ${PROJECT_REPLAY_REFUSED}`);
387
+ return;
388
+ }
340
389
  // Its replay runs are runs the runner starts, on no caller's key: skipped where the claimed run brought its own key or
341
390
  // the server holds none (claimSpendOff).
342
391
  const off = deps.spendOff?.("A learned workflow's replay check");
@@ -386,18 +435,22 @@ export const NOTHING_TO_CHECK = "nothing to check it on";
386
435
  export const NEVER_WORD_FOR_WORD = "its answers never matched the agent's word for word, and no fast model compared their decisions (a learning agent with no agree_on wants one: AGENT_MODEL_FAST, or its model_tiers.fast); name the fields that carry the decision (learning.agree_on)";
387
436
  /** What a held check the grader compared says of the inputs it disagreed on: k of n, with one of the decisions. */
388
437
  export const differentDecisionWords = (k, n, example) => `its answers reached a different decision from the agent's on ${k} of ${n}${example ? ` (for example: ${example})` : ""}`;
438
+ /** The one writer of a hold with nothing checked (n 0): `name` at `digest` held for `reason`, never promoted, its check
439
+ * the bar it was held at (`check`: what else the record keeps of it), `stopped` when nothing compiles again until a hold
440
+ * or its owner acts, and `extra` on the record (a connected agent's check: what its reservation carries). Kept only while
441
+ * `still` holds of the digest's record (the one write), and logged. */
442
+ async function holdUnchecked(deps, name, digest, bar, reason, still, { stopped = false, check = {}, extra = {} } = {}) {
443
+ const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, ...(stopped ? { stopped: true } : {}) }, ...seedOf(deps), ...extra }, still);
444
+ if (decided.won)
445
+ deps.log(`workflow-first: ${name} at ${digest} ${stopped ? "stopped" : "held"}: ${reason}`);
446
+ return decided;
447
+ }
389
448
  /** Stops a draft its check had nothing to run on (`why`: no input of the agent's it takes, or every input skipped at a
390
449
  * write): held, never promoted unchecked, its record `stopped` (nothing compiles again until a hold or its owner acts)
391
450
  * and naming the cause, which the compile's draft errors show (store-reads/loop.ts). It asks no recompile: a revision
392
451
  * would have nothing to be checked on either, and a stop with nothing checked never counts as a compile's first check
393
- * (attemptOf). Kept only while `still` holds of the digest's record (the one write). */
394
- async function stopUnchecked(deps, name, digest, bar, why, still, check = {}, extra = {}) {
395
- const reason = `${NOTHING_TO_CHECK}: ${why}. It is not promoted, and it stops: nothing compiles again until a hold or its owner acts`;
396
- const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, stopped: true }, ...seedOf(deps), ...extra }, still);
397
- if (decided.won)
398
- deps.log(`workflow-first: ${name} at ${digest} stopped: ${reason}`);
399
- return decided;
400
- }
452
+ * (attemptOf). */
453
+ const stopUnchecked = (deps, name, digest, bar, why, still, check = {}, extra = {}) => holdUnchecked(deps, name, digest, bar, `${NOTHING_TO_CHECK}: ${why}. It is not promoted, and it stops: nothing compiles again until a hold or its owner acts`, still, { stopped: true, check, extra });
401
454
  /** Decides `ahead`, the check at work for a revision older than the laid (newest) one, as a claim laying it would
402
455
  * (relaunch, then settleCheck) once its runs ended: its text read at its record's commit, its verdict standing (promote
403
456
  * or hold) though a newer revision waits. Left replaying while a run of it is at work, or when its text cannot be read
@@ -573,12 +626,14 @@ async function reserve(deps, workflow, digest, inputs, reason, still, check) {
573
626
  }
574
627
  /** How many of a connected agent's reserved native turns its check gives back in a row (failed, a learned workflow or
575
628
  * nested call in it, redacted evidence, no shadow report, or a shadow that did not answer; never a cancel, and a turn
576
- * that lands starts the count again) before it holds the draft, never promoted and never stopped for good, for the next
577
- * compile to revise and check afresh: five in a row say the integration cannot give a baseline now, not that it never will. */
629
+ * that lands starts the count again) before it holds the draft, never promoted and never stopped for good, for the
630
+ * agent's next compile after compile_after more of its runs (runner/learning-end.ts compileAskOf) to revise and check
631
+ * afresh: five in a row say the integration cannot give a baseline now, not that it never will. The one list of the
632
+ * causes a give-back has: every other mention points here. */
578
633
  export const SDK_CHECK_RELEASES = 5;
579
634
  /** Whether a hold's check is a connected agent's held on SDK_CHECK_RELEASES give-backs in a row (releaseSdkCheck): only
580
635
  * a connected agent's check counts give-backs. */
581
- const heldOnGiveBacks = (check) => (check?.released ?? 0) >= SDK_CHECK_RELEASES;
636
+ export const heldOnGiveBacks = (check) => (check?.released ?? 0) >= SDK_CHECK_RELEASES;
582
637
  /** Which attempt a revision compile of `held` is when its draft fails its checks (runner/learning-end.ts
583
638
  * recordDraftFailed): 2, the recompile, for any hold but a connected agent's on give-backs, which spends none: its
584
639
  * check's own attempt, until a revise of it has failed once already (the workflow's newest record that failed draft). */
@@ -676,15 +731,20 @@ export async function sdkCheckTurn(deps, record, row, still, read = {}) {
676
731
  const fresh = (before?.fresh_reads ?? 0) + (read.fresh_reads ?? 0);
677
732
  const turns = { ...score, of: [row.of, ...(before?.of ?? [])], outcomes: outcomesAdded(outcomes, before?.outcomes), ...(disagreements.length ? { disagreements } : {}), ...(fresh ? { fresh_reads: fresh } : {}) };
678
733
  const check = { ...bar, turns };
679
- const { runs: _runs, inputs: _inputs, ...rest } = record;
680
- const kept = await recordPromotion(deps.store.settings, deps.agentId, {
681
- ...rest, at: iso((deps.now ?? Date.now)()), check,
682
- reason: `Waiting for the next native turn of the connected agent that it takes: ${sdkTurnsWords(check)}. Nothing was promoted.`,
683
- }, (was, current) => turnStill(was, current) && !overtaken(current, was));
734
+ const kept = await waitAgain(deps, record, check, `Waiting for the next native turn of the connected agent that it takes: ${sdkTurnsWords(check)}. Nothing was promoted.`, still);
684
735
  if (kept.won)
685
736
  deps.log(`workflow-first: ${record.workflow} at ${record.digest}: ${sdkTurnsWords(check)}`);
686
737
  return kept;
687
738
  }
739
+ /** Puts a connected agent's check back as waiting for the next native turn it takes, nothing decided or promoted: its
740
+ * reserved turn taken off (runs, inputs), its `check` and `reason` kept. The turn lands once: kept only while `still`
741
+ * holds and the record still reserves that turn (sameReplay, heldTurn), so a second writer that read the same
742
+ * reservation finds it gone, and never over a newer revision's record (overtaken). The one writer of a check put back
743
+ * as waiting: a turn's row (sdkCheckTurn) and a give-back (releaseSdkCheck). */
744
+ function waitAgain(deps, record, check, reason, still = () => true) {
745
+ const { runs: _runs, inputs: _inputs, ...rest } = record;
746
+ return recordPromotion(deps.store.settings, deps.agentId, { ...rest, at: iso((deps.now ?? Date.now)()), check, reason }, (was, current) => still(was, current) && sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was));
747
+ }
688
748
  /** A connected agent's check whose native turn did not settle it by REPLAY_DEADLINE_MS (the backend never completed the
689
749
  * turn, or the server stopped before the run's end): one failed row of its turns (sdkCheckTurn), as a managed check's
690
750
  * replay run not ended by its deadline is a failed input. The hold the turns end in asks the one recompile, and a
@@ -700,7 +760,8 @@ export async function sdkCheckDeadline(deps, pending) {
700
760
  /** Gives back a connected agent's reserved native turn that cannot be its check's baseline (`cause`): the check waits for
701
761
  * the next turn the draft takes, nothing decided or promoted, the turns it checked kept on the record. A `counted` turn
702
762
  * (not a cancel, not a start that was never admitted) counts toward SDK_CHECK_RELEASES in a row, whose last holds the
703
- * draft for the next compile, whose revision is checked afresh. Kept only while the record is still this reservation. */
763
+ * draft for a compile after compile_after more runs, whose revision is checked afresh. Kept only while the record is
764
+ * still this reservation. */
704
765
  export async function releaseSdkCheck(deps, record, cause, counted = true) {
705
766
  if (!record.check)
706
767
  return;
@@ -713,20 +774,11 @@ export async function releaseSdkCheck(deps, record, cause, counted = true) {
713
774
  // Overtaken is read again inside the write: a newer revision's record can land while the cause is being cut.
714
775
  const still = (was, current) => sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was);
715
776
  const bar = { ...record.check, ...(released ? { released } : {}) };
716
- const at = iso((deps.now ?? Date.now)());
717
- if (released >= SDK_CHECK_RELEASES) {
718
- // A hold, never `stopped`: it asks the next compile for a revision (learn/compile.ts heldNamesOf), checked afresh.
719
- const reason = `the connected agent gave back ${plural(released, "reserved native turn")} in a row with no answer to check it against (the last: ${why}). It is not promoted; the agent's next compile revises it, and the revision is checked afresh`;
720
- const held = await recordPromotion(deps.store.settings, deps.agentId, { workflow: record.workflow, digest: record.digest, at, decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [] }, ...seedOf(deps), ...sdkExtra(record) }, still);
721
- if (held.won)
722
- deps.log(`workflow-first: ${record.workflow} at ${record.digest} held: ${reason}`);
723
- return held;
724
- }
725
- const { runs: _runs, inputs: _inputs, ...rest } = record;
726
- const kept = await recordPromotion(deps.store.settings, deps.agentId, {
727
- ...rest, at, check: bar,
728
- reason: `Waiting for a native turn of the connected agent that it takes: ${why}, so that turn was given back${counted ? ` (${released} of ${SDK_CHECK_RELEASES} in a row before it is held for a recompile)` : ""}. Nothing was promoted.`,
729
- }, still);
777
+ // A hold, never `stopped`: it asks a compile for a revision (learn/compile.ts heldNamesOf) after compile_after more runs
778
+ // (runner/learning-end.ts compileAskOf), checked afresh.
779
+ if (released >= SDK_CHECK_RELEASES)
780
+ return holdUnchecked(deps, record.workflow, record.digest, bar, `the connected agent gave back ${plural(released, "reserved native turn")} in a row with no answer to check it against (the last: ${why}). It is not promoted; the agent's next compile after ${plural(bar.compile_after, "more run")} revises it, and the revision is checked afresh`, still, { check: bar.turns?.disagreements?.length ? { disagreements: bar.turns.disagreements } : {}, extra: sdkExtra(record) });
781
+ const kept = await waitAgain(deps, record, bar, `Waiting for a native turn of the connected agent that it takes: ${why}, so that turn was given back${counted ? ` (${released} of ${SDK_CHECK_RELEASES} in a row before it is held for a recompile)` : ""}. Nothing was promoted.`);
730
782
  if (kept.won)
731
783
  deps.log(`workflow-first: ${record.workflow} at ${record.digest} waits for another native turn: ${why}`);
732
784
  return kept;
@@ -735,13 +787,10 @@ export async function releaseSdkCheck(deps, record, cause, counted = true) {
735
787
  * with nothing decided, never promoted (the turns it checked kept on the record), and `stopped` as any stop with
736
788
  * nothing checked, so it spends no recompile (attemptOf): the newer revision is the one checked next. */
737
789
  async function setAside(deps, pending) {
738
- if (!pending.check)
790
+ const { workflow, digest, at: _at, decided: _decided, reason: _reason, check, ...extra } = pending;
791
+ if (!check)
739
792
  return;
740
- await recordPromotion(deps.store.settings, deps.agentId, {
741
- ...pending, at: iso((deps.now ?? Date.now)()), decided: "hold",
742
- reason: `${NOTHING_TO_CHECK}: a newer revision of it landed before the connected agent's native turns finished checking it. It is not promoted; the newer revision is checked instead`,
743
- check: { ...pending.check, n: 0, agreed: 0, alone: 0, of: [], stopped: true },
744
- }, (was, current) => waitingSdk(was) && was.replay_id === pending.replay_id && !overtaken(current, was));
793
+ await holdUnchecked(deps, workflow, digest, check, `${NOTHING_TO_CHECK}: a newer revision of it landed before the connected agent's native turns finished checking it. It is not promoted; the newer revision is checked instead`, (was, current) => waitingSdk(was) && was.replay_id === pending.replay_id && !overtaken(current, was), { stopped: true, extra });
745
794
  }
746
795
  /** The launch a replay's runs all run with (PromotionRecord.launch), chosen once by the claim or person reserving it:
747
796
  * `deps.launch` as a replay run takes it (a claim's claimed run's; a person's ask makes one now), the revision it runs,
@@ -824,9 +873,14 @@ async function startReplay(deps, workflow, digest, of, from, id, launch) {
824
873
  const base = readLaunchBody(launch.body);
825
874
  if (!base)
826
875
  throw new Error(`the launch of ${workflow.name} at ${digest}'s replay could not be read`);
876
+ const source = sourceSyncOf((await store.agents.revision(launch.revision))?.body);
877
+ if (base.sourceProject || source && !deps.admitAuxiliary)
878
+ throw new ReplayRefused("conflict", PROJECT_REPLAY_REFUSED);
827
879
  const replay = { ...base, input: from.input, title: `Replay of ${workflow.name}: ${from.title}`.slice(0, 200), replay: { of, workflow: workflow.name, digest } };
828
880
  const sealed = await handedTo(deps, launch, id);
829
881
  try {
882
+ if (source)
883
+ return (await deps.admitAuxiliary({ runId: id, agentId, revisionId: launch.revision, launch: replay, ...(sealed ? { sealed } : {}) })).created;
830
884
  await store.runs.create({ id, agentId, revisionId: launch.revision }, { body: launchBody(replay), ...(sealed ? { sealed } : {}) });
831
885
  return true;
832
886
  }
@@ -926,6 +980,7 @@ function skipWordsOf(tools, skipped) {
926
980
  }
927
981
  /** Why a replay a person asked for (askReplay) or read (replayView) was refused: `missing`, no such workflow, revision or
928
982
  * replay of the agent (404); `conflict`, the revision cannot replay now (409), in words that say why. */
983
+ const PROJECT_REPLAY_REFUSED = "An auxiliary replay requires its own project placement for this moved agent; nothing was started. Start a normal run to use the saved project.";
929
984
  export class ReplayRefused extends Error {
930
985
  kind;
931
986
  constructor(kind, message) {
@@ -993,9 +1048,11 @@ export async function askReplay(ask, name, digest, inputs) {
993
1048
  if (!picked.length)
994
1049
  throw new ReplayRefused("conflict", `${name} at ${digest} has no input to replay on: none of ${typeof inputs === "number" ? `the agent's newest ${plural(inputs, "completed run")}` : last ? "the runs it was last checked on" : "the agent's last completed runs"} has an input it fits. Nothing was started.`);
995
1050
  const { launch, revisionId } = await ask.launchOf(picked[0].launch.input);
1051
+ if (launch.sourceProject || sourceSyncOf((await ask.store.agents.revision(revisionId))?.body) && !ask.admitAuxiliary)
1052
+ throw new ReplayRefused("conflict", PROJECT_REPLAY_REFUSED);
996
1053
  if (!launch.learning || launch.learning.noWorkflows)
997
1054
  throw new ReplayRefused("conflict", `A replay runs ${name} as a run of the agent that learns does, and the agent's runs do not take learned workflows here (its learning is off, it takes no workflows, or this server's is off).`);
998
- const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, ...(ask.now ? { now: ask.now } : {}) };
1055
+ const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, ...(ask.admitAuxiliary ? { admitAuxiliary: ask.admitAuxiliary } : {}), ...(ask.now ? { now: ask.now } : {}) };
999
1056
  const bar = { ...loop, attempt: attemptOf(records, name, digest) };
1000
1057
  const said = `checking it on ${plural(picked.length, "input")} of the agent's own runs, as its owner asked`;
1001
1058
  // Kept only while the revision's newest record is still the one read here: each record write stamps a new `at`.
@@ -24,9 +24,22 @@ export declare const processSecretRedactor: () => Redact;
24
24
  export interface HeldRedact extends Redact {
25
25
  /** Cut `values` too from here on, each in every form; one shorter than MIN_SECRET, whitespace aside, is left out. */
26
26
  hold(values: readonly string[]): void;
27
+ /** Hold `values`, and cut them from run `runId`'s journal as it is written too (runner.ts): the run's own tool keys
28
+ * (run-keys.ts), erased at its turn's end, so no read after it could cut them. */
29
+ carry(runId: string, values: readonly string[]): void;
30
+ /** The cut of what run `runId` carried (`carry`), or undefined while it carried none. */
31
+ carried(runId: string): Redact | undefined;
32
+ /** Forget what run `runId` carried, once the runner lets its claim go: a later run's writes are never cut of it. The
33
+ * values stay held (`hold`). */
34
+ dropCarried(runId: string): void;
27
35
  }
28
36
  /** `base`, then every value held since (`hold`). One that holds already is itself: wrapped once, the one instance. */
29
37
  export declare function heldRedactor(base: Redact): HeldRedact;
38
+ /** Every string inside `value` cut by `cut`: what the run's process writes, as the runner's redactor would cut it in a
39
+ * loop of its own (rule three: no secret the runner holds is written). `names`: each object's and map's names too (a
40
+ * model may write a value as a JSON name); two names cut to one are both kept, the later ones numbered. A number that
41
+ * shows a value `cut` holds (a key of digits alone, quoted as a JSON number: key-refusal.ts heldNumber) is "[redacted]". */
42
+ export declare function cutDeep<T>(value: T, cut: Redact, names?: boolean): T;
30
43
  /** The secrets a claim opened from the store (`env`, claimSecrets' environment for the run) held by `redact`, the run's
31
44
  * one redactor, so a host tool's or a provider's error that echoes one is cut in the run's record, its end and its logs. */
32
45
  export declare function holdClaimed(redact: HeldRedact, env: NodeJS.ProcessEnv): void;