@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.53

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 (322) hide show
  1. package/CHANGELOG.md +160 -1
  2. package/README.md +306 -36
  3. package/dist/adapters.js +1 -1
  4. package/dist/agent-delete.d.ts +14 -4
  5. package/dist/agent-delete.js +30 -58
  6. package/dist/agent-package.d.ts +71 -0
  7. package/dist/agent-package.js +345 -0
  8. package/dist/agents-store.d.ts +28 -18
  9. package/dist/agents-store.js +48 -34
  10. package/dist/api-only.d.ts +30 -8
  11. package/dist/api-only.js +40 -16
  12. package/dist/archil-routes.d.ts +1 -0
  13. package/dist/archil-routes.js +28 -2
  14. package/dist/claude-login.d.ts +1 -0
  15. package/dist/claude-login.js +1 -1
  16. package/dist/cli-learning/cli.d.ts +3 -0
  17. package/dist/cli-learning/cli.js +17 -3
  18. package/dist/cli-learning/connections.js +3 -2
  19. package/dist/cli-learning/schema.js +2 -1
  20. package/dist/cli.js +70 -7
  21. package/dist/composio-preset.d.ts +2 -1
  22. package/dist/composio-preset.js +4 -3
  23. package/dist/composio-triggers.d.ts +4 -0
  24. package/dist/composio-triggers.js +4 -1
  25. package/dist/computer-needs.d.ts +32 -0
  26. package/dist/computer-needs.js +80 -0
  27. package/dist/computer-setting.d.ts +9 -0
  28. package/dist/computer-setting.js +19 -1
  29. package/dist/computers.d.ts +6 -2
  30. package/dist/computers.js +2 -2
  31. package/dist/console/assets/index-BFgyZzF_.js +734 -0
  32. package/dist/console/assets/index-DbilxljH.css +1 -0
  33. package/dist/console/index.html +2 -2
  34. package/dist/console-links.d.ts +1 -0
  35. package/dist/console-links.js +2 -0
  36. package/dist/env-switch.d.ts +14 -0
  37. package/dist/env-switch.js +23 -0
  38. package/dist/errors.d.ts +1 -0
  39. package/dist/errors.js +3 -0
  40. package/dist/eval-previous.js +4 -3
  41. package/dist/fal-price.d.ts +76 -0
  42. package/dist/fal-price.js +365 -0
  43. package/dist/handed-secret.d.ts +4 -0
  44. package/dist/handed-secret.js +10 -0
  45. package/dist/harness-archive.d.ts +15 -5
  46. package/dist/harness-archive.js +71 -34
  47. package/dist/harness-check.d.ts +2 -1
  48. package/dist/harness-check.js +36 -95
  49. package/dist/harness-egress.d.ts +23 -0
  50. package/dist/harness-egress.js +69 -0
  51. package/dist/harness-recipe-entry.d.ts +71 -0
  52. package/dist/harness-recipe-entry.js +184 -0
  53. package/dist/harness-recipe.d.ts +73 -6
  54. package/dist/harness-recipe.js +185 -31
  55. package/dist/harness-sign-in.d.ts +29 -0
  56. package/dist/harness-sign-in.js +122 -0
  57. package/dist/harness-table.d.ts +21 -0
  58. package/dist/harness-table.js +58 -3
  59. package/dist/harness-zip.d.ts +6 -0
  60. package/dist/harness-zip.js +203 -0
  61. package/dist/ids.d.ts +11 -0
  62. package/dist/ids.js +36 -0
  63. package/dist/learn/commit.d.ts +19 -1
  64. package/dist/learn/commit.js +160 -2
  65. package/dist/learn/compile.d.ts +13 -5
  66. package/dist/learn/compile.js +46 -15
  67. package/dist/learn/delete.d.ts +12 -6
  68. package/dist/learn/delete.js +17 -11
  69. package/dist/learn/folder.d.ts +16 -0
  70. package/dist/learn/folder.js +30 -4
  71. package/dist/learn/learning-of.d.ts +8 -0
  72. package/dist/learn/learning-of.js +8 -0
  73. package/dist/learn/learning.sh +29 -4
  74. package/dist/learn/promote.d.ts +51 -7
  75. package/dist/learn/promote.js +51 -8
  76. package/dist/learn/secrets.js +30 -7
  77. package/dist/learning-reset.d.ts +18 -0
  78. package/dist/learning-reset.js +115 -0
  79. package/dist/learning-routes.d.ts +23 -11
  80. package/dist/learning-routes.js +110 -20
  81. package/dist/learning-words.d.ts +5 -0
  82. package/dist/learning-words.js +5 -0
  83. package/dist/learning.d.ts +15 -10
  84. package/dist/learning.js +14 -8
  85. package/dist/llms.txt +1 -0
  86. package/dist/mcp-gateway.d.ts +39 -2
  87. package/dist/mcp-gateway.js +56 -12
  88. package/dist/mcp-pin-first.js +1 -1
  89. package/dist/mcp-probe.d.ts +3 -0
  90. package/dist/mcp-probe.js +7 -2
  91. package/dist/mcp-resources.d.ts +44 -0
  92. package/dist/mcp-resources.js +100 -0
  93. package/dist/mcp-servers-store.d.ts +17 -12
  94. package/dist/mcp-servers-store.js +2 -1
  95. package/dist/media-duration.d.ts +2 -0
  96. package/dist/media-duration.js +136 -0
  97. package/dist/model.d.ts +4 -4
  98. package/dist/model.js +6 -6
  99. package/dist/native/cli.js +9 -2
  100. package/dist/native/connection.d.ts +2 -2
  101. package/dist/native/connection.js +5 -2
  102. package/dist/native/discovery.d.ts +2 -0
  103. package/dist/native/discovery.js +10 -6
  104. package/dist/native/remote-worker-bridge.js +36 -4
  105. package/dist/native/remote.d.ts +18 -1
  106. package/dist/native/remote.js +126 -37
  107. package/dist/native/schema.d.ts +6 -0
  108. package/dist/native/schema.js +31 -6
  109. package/dist/native/source-account.d.ts +13 -0
  110. package/dist/native/source-account.js +114 -0
  111. package/dist/native/source-capture-hooks.d.ts +5 -0
  112. package/dist/native/source-capture-hooks.js +102 -0
  113. package/dist/native/source-mcp-selection.d.ts +13 -0
  114. package/dist/native/source-mcp-selection.js +72 -0
  115. package/dist/native/source-runtime-tools.d.ts +19 -0
  116. package/dist/native/source-runtime-tools.js +103 -0
  117. package/dist/native/source-snapshot-types.d.ts +138 -0
  118. package/dist/native/source-snapshot-types.js +12 -0
  119. package/dist/native/source-snapshot.d.ts +8 -0
  120. package/dist/native/source-snapshot.js +1201 -0
  121. package/dist/observation/learning.js +3 -2
  122. package/dist/openapi.js +211 -47
  123. package/dist/print.js +1 -1
  124. package/dist/provider.d.ts +8 -0
  125. package/dist/provider.js +14 -2
  126. package/dist/purged-workflow.d.ts +12 -0
  127. package/dist/purged-workflow.js +43 -0
  128. package/dist/refusal-words.d.ts +0 -3
  129. package/dist/refusal-words.js +0 -3
  130. package/dist/request-metadata.d.ts +20 -0
  131. package/dist/request-metadata.js +24 -0
  132. package/dist/run-keys.d.ts +46 -0
  133. package/dist/run-keys.js +109 -0
  134. package/dist/run-launch.d.ts +29 -5
  135. package/dist/run-launch.js +44 -4
  136. package/dist/run-learning-served.d.ts +2 -2
  137. package/dist/run-model-key.d.ts +2 -2
  138. package/dist/run-model-key.js +5 -5
  139. package/dist/run-secrets.d.ts +2 -0
  140. package/dist/run-secrets.js +7 -4
  141. package/dist/run-usage.d.ts +48 -4
  142. package/dist/run-usage.js +156 -39
  143. package/dist/run-view.d.ts +18 -1
  144. package/dist/run-view.js +28 -8
  145. package/dist/runner/adapter-loop.d.ts +14 -4
  146. package/dist/runner/adapter-loop.js +150 -31
  147. package/dist/runner/adapter-run-spec.d.ts +1 -1
  148. package/dist/runner/adapter-run-spec.js +35 -22
  149. package/dist/runner/audit.d.ts +10 -3
  150. package/dist/runner/audit.js +30 -7
  151. package/dist/runner/beside.js +2 -1
  152. package/dist/runner/claim-secrets.d.ts +31 -4
  153. package/dist/runner/claim-secrets.js +43 -7
  154. package/dist/runner/cli-run-spec.d.ts +1 -1
  155. package/dist/runner/cli-run-spec.js +32 -20
  156. package/dist/runner/conformance/harness.js +4 -2
  157. package/dist/runner/dispatch.js +4 -2
  158. package/dist/runner/harness-loops.d.ts +6 -0
  159. package/dist/runner/harness-loops.js +16 -3
  160. package/dist/runner/held.d.ts +4 -0
  161. package/dist/runner/journal-kinds.d.ts +5 -0
  162. package/dist/runner/learned-first.d.ts +2 -0
  163. package/dist/runner/learned-first.js +1 -1
  164. package/dist/runner/learning-end.d.ts +9 -3
  165. package/dist/runner/learning-end.js +66 -29
  166. package/dist/runner/learning-seed.d.ts +9 -3
  167. package/dist/runner/learning-seed.js +2 -2
  168. package/dist/runner/main.d.ts +1 -0
  169. package/dist/runner/main.js +20 -13
  170. package/dist/runner/mcp-claim.js +7 -2
  171. package/dist/runner/mcp-run.d.ts +12 -0
  172. package/dist/runner/mcp-run.js +14 -1
  173. package/dist/runner/model-route.js +7 -4
  174. package/dist/runner/monid-run.js +9 -11
  175. package/dist/runner/project-checkpoint.d.ts +35 -0
  176. package/dist/runner/project-checkpoint.js +116 -0
  177. package/dist/runner/project-drain.d.ts +8 -0
  178. package/dist/runner/project-drain.js +25 -0
  179. package/dist/runner/project-host.d.ts +10 -0
  180. package/dist/runner/project-host.js +52 -0
  181. package/dist/runner/promotion.d.ts +51 -24
  182. package/dist/runner/promotion.js +206 -78
  183. package/dist/runner/redact.d.ts +13 -0
  184. package/dist/runner/redact.js +67 -1
  185. package/dist/runner/run-channel.d.ts +9 -0
  186. package/dist/runner/run-channel.js +15 -2
  187. package/dist/runner/run-child-host.d.ts +8 -4
  188. package/dist/runner/run-child-host.js +174 -42
  189. package/dist/runner/run-errors.js +2 -2
  190. package/dist/runner/runner-check.js +5 -2
  191. package/dist/runner/runner.js +41 -12
  192. package/dist/runner/sdk-loop.d.ts +2 -2
  193. package/dist/runner/sdk-loop.js +3 -3
  194. package/dist/runner/store-port.d.ts +3 -0
  195. package/dist/runner/store-secrets.js +7 -3
  196. package/dist/runner/workflow-first.d.ts +4 -0
  197. package/dist/runner/workflow-first.js +13 -0
  198. package/dist/runner/workflow-loop.d.ts +2 -1
  199. package/dist/runner/workflow-loop.js +2 -1
  200. package/dist/runner/workflow-spec.js +4 -4
  201. package/dist/runs-over-store.d.ts +39 -8
  202. package/dist/runs-over-store.js +147 -32
  203. package/dist/sdk/check.d.ts +6 -5
  204. package/dist/sdk/check.js +17 -16
  205. package/dist/sdk/runs.d.ts +11 -1
  206. package/dist/sdk/runs.js +185 -78
  207. package/dist/sdk/schema.js +12 -2
  208. package/dist/sdk/workflows.d.ts +1 -1
  209. package/dist/server.d.ts +68 -32
  210. package/dist/server.js +678 -124
  211. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  212. package/dist/source-sync/adoption.d.ts +15 -0
  213. package/dist/source-sync/adoption.js +36 -0
  214. package/dist/source-sync/auxiliary.d.ts +23 -0
  215. package/dist/source-sync/auxiliary.js +64 -0
  216. package/dist/source-sync/capture-git.d.ts +5 -0
  217. package/dist/source-sync/capture-git.js +272 -0
  218. package/dist/source-sync/capture-project.d.ts +53 -0
  219. package/dist/source-sync/capture-project.js +206 -0
  220. package/dist/source-sync/capture-refusal.d.ts +7 -0
  221. package/dist/source-sync/capture-refusal.js +16 -0
  222. package/dist/source-sync/capture.d.ts +11 -0
  223. package/dist/source-sync/capture.js +22 -0
  224. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  225. package/dist/source-sync/checkpoint-gate.js +52 -0
  226. package/dist/source-sync/checkpoints.d.ts +66 -0
  227. package/dist/source-sync/checkpoints.js +168 -0
  228. package/dist/source-sync/claim.d.ts +11 -0
  229. package/dist/source-sync/claim.js +48 -0
  230. package/dist/source-sync/destination.d.ts +47 -0
  231. package/dist/source-sync/destination.js +239 -0
  232. package/dist/source-sync/io.d.ts +15 -0
  233. package/dist/source-sync/io.js +52 -0
  234. package/dist/source-sync/local.d.ts +43 -0
  235. package/dist/source-sync/local.js +229 -0
  236. package/dist/source-sync/prepare.d.ts +59 -0
  237. package/dist/source-sync/prepare.js +93 -0
  238. package/dist/source-sync/projects.d.ts +61 -0
  239. package/dist/source-sync/projects.js +130 -0
  240. package/dist/source-sync/registry.d.ts +95 -0
  241. package/dist/source-sync/registry.js +226 -0
  242. package/dist/source-sync/service.d.ts +33 -0
  243. package/dist/source-sync/service.js +118 -0
  244. package/dist/source-sync/skill-edits.d.ts +12 -0
  245. package/dist/source-sync/skill-edits.js +122 -0
  246. package/dist/source-sync/snapshots.d.ts +48 -0
  247. package/dist/source-sync/snapshots.js +448 -0
  248. package/dist/source-sync/types.d.ts +9 -0
  249. package/dist/source-sync/types.js +14 -0
  250. package/dist/source-sync/workspace.d.ts +66 -0
  251. package/dist/source-sync/workspace.js +273 -0
  252. package/dist/store/agent-body.d.ts +8 -0
  253. package/dist/store/agent-body.js +20 -6
  254. package/dist/store/index.d.ts +2 -2
  255. package/dist/store/index.js +1 -1
  256. package/dist/store/journal/storage.d.ts +2 -0
  257. package/dist/store/journal/storage.js +2 -1
  258. package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
  259. package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
  260. package/dist/store/schema.d.ts +15 -1
  261. package/dist/store/schema.js +43 -4
  262. package/dist/store/seal.d.ts +5 -1
  263. package/dist/store/seal.js +12 -3
  264. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  265. package/dist/store/sqlite/project-checkpoints.js +70 -0
  266. package/dist/store/sqlite/run-launch.d.ts +14 -0
  267. package/dist/store/sqlite/run-launch.js +58 -7
  268. package/dist/store/sqlite/run-patch.d.ts +2 -1
  269. package/dist/store/sqlite/run-patch.js +4 -3
  270. package/dist/store/sqlite/store.js +319 -153
  271. package/dist/store/store-schema.js +2 -2
  272. package/dist/store/store.d.ts +173 -33
  273. package/dist/store/store.js +14 -1
  274. package/dist/store-reads/learning.d.ts +12 -8
  275. package/dist/store-reads/learning.js +33 -24
  276. package/dist/store-reads/loop.d.ts +4 -3
  277. package/dist/store-reads/loop.js +7 -5
  278. package/dist/store-view.d.ts +3 -1
  279. package/dist/store-view.js +17 -5
  280. package/dist/template-eval.js +4 -4
  281. package/dist/template-import.d.ts +10 -2
  282. package/dist/template-import.js +116 -13
  283. package/dist/templates.d.ts +29 -5
  284. package/dist/templates.js +68 -14
  285. package/dist/timeline/index.d.ts +1 -1
  286. package/dist/timeline/index.js +1 -1
  287. package/dist/timeline/labels.js +1 -1
  288. package/dist/timeline/timeline.d.ts +5 -0
  289. package/dist/timeline/timeline.js +8 -0
  290. package/dist/tool-plane.d.ts +12 -12
  291. package/dist/tools.d.ts +8 -8
  292. package/dist/tools.js +1 -1
  293. package/dist/trigger-launch-hook.d.ts +47 -0
  294. package/dist/trigger-launch-hook.js +90 -0
  295. package/dist/trigger-targets.d.ts +14 -1
  296. package/dist/trigger-targets.js +20 -0
  297. package/dist/triggers.d.ts +54 -5
  298. package/dist/triggers.js +143 -8
  299. package/dist/uploads-archil.js +2 -1
  300. package/dist/uploads.d.ts +0 -3
  301. package/dist/uploads.js +2 -11
  302. package/dist/validate.js +4 -1
  303. package/dist/web-save.d.ts +3 -0
  304. package/dist/web-save.js +17 -2
  305. package/dist/workspace/archil-exec.js +1 -1
  306. package/dist/workspace/archil.js +1 -1
  307. package/dist/workspace/computer-for-claim.d.ts +2 -0
  308. package/dist/workspace/computer-for-claim.js +43 -0
  309. package/dist/workspace/paths.d.ts +6 -0
  310. package/dist/workspace/paths.js +6 -0
  311. package/dist/workspace/resolve-computer.d.ts +1 -0
  312. package/dist/workspace/revision-skills.js +24 -11
  313. package/dist/workspace/run-tools.d.ts +2 -0
  314. package/dist/workspace/run-tools.js +8 -0
  315. package/dist/workspace/synced-folder.d.ts +3 -3
  316. package/dist/workspace/synced-folder.js +7 -6
  317. package/launcher/agentrun-serve +1 -1
  318. package/package.json +10 -10
  319. package/skills/agentrun-serve/SKILL.md +2 -1
  320. package/templates/README.md +5 -2
  321. package/dist/console/assets/index-Bt1B51b7.js +0 -733
  322. package/dist/console/assets/index-sVftE9Ht.css +0 -1
@@ -0,0 +1,35 @@
1
+ /** The moved project's strict end hook: no effect dispatch while this runs, every tracked process stopped, then
2
+ * actual backend folder sync and stable capture. A failed/uncertain step leaves an explicit receipt, never a pointer. */
3
+ import type { Claim, Store } from "../store/store.js";
4
+ import type { RunLaunch } from "../run-launch.js";
5
+ import type { RunTools } from "../workspace/run-tools.js";
6
+ import type { ClaimComputer } from "../workspace/computer-for-claim.js";
7
+ import { type ProjectCheckpoint, type ProjectUncertain } from "../source-sync/checkpoints.js";
8
+ import { type SourceWorkspaceOptions } from "../source-sync/workspace.js";
9
+ export declare function runProjectCheckpoint(input: {
10
+ store: Store;
11
+ agentId: string;
12
+ claim: Claim;
13
+ launch: RunLaunch;
14
+ tools: Pick<RunTools, "workspace" | "settleProject">;
15
+ computer: ClaimComputer;
16
+ workspace: SourceWorkspaceOptions;
17
+ secrets(): Promise<readonly string[]>;
18
+ /** Trusted host capability already holds durable ownership through its remote-call drain and this capture. */
19
+ ioHeld?: true;
20
+ }): {
21
+ uncertain: () => ProjectUncertain;
22
+ /** Host-private evidence, never a field the child can supply in a checkpoint receipt. */
23
+ refusalSettled: () => boolean;
24
+ capture(signal: AbortSignal): Promise<ProjectCheckpoint>;
25
+ };
26
+ /** The isolated child asks only for its host-bound checkpoint; it receives no store/cache/credential capability. */
27
+ export declare function projectCheckpointForRun(input: Parameters<typeof runProjectCheckpoint>[0], dispatched: () => void): {
28
+ uncertain: () => ProjectUncertain;
29
+ /** Host-private evidence, never a field the child can supply in a checkpoint receipt. */
30
+ refusalSettled: () => boolean;
31
+ capture(signal: AbortSignal): Promise<ProjectCheckpoint>;
32
+ } | {
33
+ capture: (signal: AbortSignal) => Promise<ProjectCheckpoint>;
34
+ uncertain: () => ProjectUncertain;
35
+ };
@@ -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,10 +1,11 @@
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";
4
5
  import { type Store } from "../store/store.js";
5
6
  import { type Recorded, type ReplayCalls, type Skipped } from "../learn/replay-calls.js";
6
7
  import { type Json } from "../validate.js";
7
- import { type CheckBar, type Compared, type PromotionRecord, recordPromotion, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
8
+ import { type CheckBar, type CheckRecord, type CheckTurns, type Compared, type PromotionRecord, recordPromotion, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
8
9
  import { type FirstChoice, type Promoted, type ReplayOutcome } from "./workflow-first.js";
9
10
  import type { LearningFolder } from "../learn/folder.js";
10
11
  import type { Shown } from "../learning.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. */
@@ -97,8 +100,9 @@ export declare const DSL_REFUSES = "this release's workflow DSL refuses it";
97
100
  /** Which check of a compile a new revision's is: 2 when the workflow's newest record of another revision is a first
98
101
  * check's hold, an audit's hold or a hold by its reason alone (holdRefused: the DSL refuses a serving revision), or a
99
102
  * first compile's failed draft (this revision is its one recompile), else 1. A stop with nothing checked
100
- * (stopUnchecked) is no first check's hold: it spends no recompile. A workflow's first revision after a first compile
101
- * whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
103
+ * (stopUnchecked) is no first check's hold: it spends no recompile, and neither does a connected agent's hold on its
104
+ * give-backs (heldOnGiveBacks: the revision after it is the same attempt). A workflow's first revision after a first
105
+ * compile whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
102
106
  export declare function attemptOf(records: readonly PromotionRecord[], name: string, digest: string): 1 | 2;
103
107
  /** The words a stopped check's record starts with when it had nothing to check its draft on. */
104
108
  export declare const NOTHING_TO_CHECK = "nothing to check it on";
@@ -111,7 +115,7 @@ export declare const differentDecisionWords: (k: number, n: number, example: str
111
115
  * draft did: its answer when it answered alone, why it handed the input back, or failed (or skipped a write). A
112
116
  * reserved input whose replay run was never created, or never ended, by the check's deadline failed (`unstarted` for
113
117
  * the first). */
114
- type CheckRow = {
118
+ export type CheckRow = {
115
119
  readonly of: string;
116
120
  readonly input: string;
117
121
  readonly agent: string | null;
@@ -122,10 +126,8 @@ type CheckRow = {
122
126
  readonly unstarted?: true;
123
127
  readonly compared?: Compared;
124
128
  };
125
- /** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
126
- * with the agent's recorded answer (learn/promote.ts compareAnswers, the audit's one comparison: on the bar's agree_on
127
- * when it names fields, else equal, or the same decision by the grader's verdict its replay run kept), alone
128
- * when it answered it with no escalate and no failed step. Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
129
+ /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
130
+ * (scoreRows). Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
129
131
  * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
130
132
  * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
131
133
  * (the one write: of two claims at once, one decides). */
@@ -136,14 +138,25 @@ export declare function decideCheck(deps: DecideDeps, name: string, digest: stri
136
138
  unstarted: number;
137
139
  exactMismatchReason?: string;
138
140
  fresh_reads?: number;
141
+ before?: CheckTurns;
139
142
  }, still: Parameters<typeof recordPromotion>[3], extra: Partial<PromotionRecord>): Promise<import("../learn/promote.js").Recorded>;
140
- /** How many of a connected agent's reserved native turns its check gives back before it stops. A turn is given back
141
- * when it cannot be the check's baseline: cancelled or failed, a learned workflow or nested call in it, redacted
142
- * evidence, no shadow report, or a shadow that did not answer. One or two are ordinary (a person cancels a task, an
143
- * input carries a secret); five say the integration cannot give one (a client with no shadow check, inputs it never
144
- * resolves, a draft whose shadow always refuses), and each reserved turn runs without the champion. The fifth stops it
145
- * with nothing checked (stopUnchecked), which asks no recompile: a revision would have no baseline either. */
143
+ /** How many of a connected agent's reserved native turns its check gives back in a row (failed, a learned workflow or
144
+ * nested call in it, redacted evidence, no shadow report, or a shadow that did not answer; never a cancel, and a turn
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. */
146
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;
153
+ /** Which attempt a revision compile of `held` is when its draft fails its checks (runner/learning-end.ts
154
+ * recordDraftFailed): 2, the recompile, for any hold but a connected agent's on give-backs, which spends none: its
155
+ * check's own attempt, until a revise of it has failed once already (the workflow's newest record that failed draft). */
156
+ export declare function reviseAttemptOf(records: readonly PromotionRecord[], held: {
157
+ readonly workflow: string;
158
+ readonly check?: CheckRecord;
159
+ }): 1 | 2;
147
160
  /** A connected agent's draft reserved on one native turn: what its start hands the caller (sdk/runs.ts receipt). */
148
161
  export type SdkWorkflowCheck = {
149
162
  id: string;
@@ -157,7 +170,7 @@ export declare const sdkInputText: (launch: RunLaunch | undefined) => string;
157
170
  * check on the native turn `runId`: the first the turn takes (`takes`) with no decision yet, or one waiting for a turn,
158
171
  * while no other revision of its workflow is checked; the guarded write keeps one reservation per workflow across
159
172
  * concurrent starts. First each SDK check of a candidate's workflow is moved on: one whose turn is past
160
- * REPLAY_DEADLINE_MS is decided as one failed row (sdkCheckDeadline), and one waiting at a revision the folder moved
173
+ * REPLAY_DEADLINE_MS is one failed row of its turns (sdkCheckDeadline), and one waiting at a revision the folder moved
161
174
  * past is set aside. A managed replay's record (no `via`) is never touched here. */
162
175
  export declare function reserveSdkCheck(deps: DecideDeps, turn: {
163
176
  readonly runId: string;
@@ -166,15 +179,30 @@ export declare function reserveSdkCheck(deps: DecideDeps, turn: {
166
179
  readonly flows: readonly LearnedWorkflow[];
167
180
  readonly takes: (flow: LearnedWorkflow) => boolean;
168
181
  }): Promise<SdkWorkflowCheck | undefined>;
182
+ /** One native turn's row of a connected agent's check: its shadow answered or handed back (sdk/check.ts settleSdkCheck),
183
+ * or the turn did not settle by REPLAY_DEADLINE_MS, a failed row (sdkCheckDeadline). A managed check decides once, on
184
+ * its compile_after inputs, and so does this one: the turn that makes compile_after decides on every turn collected
185
+ * (decideCheck, the same bar); a turn before it is scored and kept (check.turns), the record gives back its reserved
186
+ * turn, and the check waits for the next turn the draft takes, nothing decided or promoted, the agent answering
187
+ * meanwhile. No turn holds it early, as no input of a managed check does. Its rows are never skipped (a shadow stopped
188
+ * at a write gives its turn back), so each is one of the n. Kept only while `still` holds of the digest's record; a
189
+ * check a newer revision overtook keeps no turn (it would hide the newer record), as a release does. */
190
+ export declare function sdkCheckTurn(deps: DecideDeps, record: PromotionRecord & {
191
+ readonly check: CheckRecord;
192
+ }, row: CheckRow, still: Parameters<typeof recordPromotion>[3], read?: {
193
+ exactMismatchReason?: string;
194
+ fresh_reads?: number;
195
+ }): Promise<import("../learn/promote.js").Recorded | undefined>;
169
196
  /** A connected agent's check whose native turn did not settle it by REPLAY_DEADLINE_MS (the backend never completed the
170
- * turn, or the server stopped before the run's end): decided as every check is (decideCheck), on one failed row. Its
171
- * hold asks the one recompile, and a recompile's check that ends here stops (`stopped`): an abandoned check never
172
- * restarts its budget. */
197
+ * turn, or the server stopped before the run's end): one failed row of its turns (sdkCheckTurn), as a managed check's
198
+ * replay run not ended by its deadline is a failed input. The hold the turns end in asks the one recompile, and a
199
+ * recompile's check held so stops (`stopped`): an abandoned check never restarts its budget. */
173
200
  export declare function sdkCheckDeadline(deps: DecideDeps, pending: PromotionRecord): Promise<import("../learn/promote.js").Recorded | undefined>;
174
201
  /** Gives back a connected agent's reserved native turn that cannot be its check's baseline (`cause`): the check waits for
175
- * the next turn the draft takes, nothing decided or promoted, and the turn counts toward SDK_CHECK_RELEASES, whose last
176
- * stops it with nothing checked (stopUnchecked: no recompile). `counted` false: no turn ran (its start was not
177
- * admitted). Kept only while the record is still this reservation. */
202
+ * the next turn the draft takes, nothing decided or promoted, the turns it checked kept on the record. A `counted` turn
203
+ * (not a cancel, not a start that was never admitted) counts toward SDK_CHECK_RELEASES in a row, whose last holds the
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. */
178
206
  export declare function releaseSdkCheck(deps: DecideDeps, record: PromotionRecord, cause: string, counted?: boolean): Promise<import("../learn/promote.js").Recorded | undefined>;
179
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,
180
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
@@ -185,8 +213,6 @@ export declare function answerRowOf(store: PromotionDeps["store"], runId: string
185
213
  } | null>;
186
214
  /** A run's final answer, whole (answerRowOf's text; `turn`: that row's), or null. */
187
215
  export declare const answerOf: (store: PromotionDeps["store"], runId: string, context: Context, turn?: string) => Promise<string | null>;
188
- /** Why a replay a person asked for (askReplay) or read (replayView) was refused: `missing`, no such workflow, revision or
189
- * replay of the agent (404); `conflict`, the revision cannot replay now (409), in words that say why. */
190
216
  export declare class ReplayRefused extends Error {
191
217
  readonly kind: "missing" | "conflict";
192
218
  constructor(kind: "missing" | "conflict", message: string);
@@ -196,6 +222,7 @@ export declare class ReplayRefused extends Error {
196
222
  * on: a replay run's is this one with its agent run's input (startReplay), at the revision's learning commit. */
197
223
  export interface ReplayAsk {
198
224
  readonly store: Store;
225
+ readonly admitAuxiliary?: AuxiliaryAdmitter;
199
226
  readonly agentId: string;
200
227
  readonly context: Context;
201
228
  readonly log: (line: string) => void;