@parcha/agentrun-serve 0.1.0-beta.52 → 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 (261) hide show
  1. package/CHANGELOG.md +122 -1
  2. package/README.md +213 -24
  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/agents-store.d.ts +26 -20
  8. package/dist/agents-store.js +41 -33
  9. package/dist/api-only.d.ts +26 -6
  10. package/dist/api-only.js +35 -13
  11. package/dist/claude-login.d.ts +1 -0
  12. package/dist/claude-login.js +1 -1
  13. package/dist/cli-learning/cli.d.ts +3 -0
  14. package/dist/cli-learning/cli.js +17 -3
  15. package/dist/cli-learning/connections.js +3 -2
  16. package/dist/cli-learning/schema.js +2 -1
  17. package/dist/cli.js +70 -7
  18. package/dist/composio-preset.d.ts +2 -1
  19. package/dist/composio-preset.js +4 -3
  20. package/dist/composio-triggers.d.ts +4 -0
  21. package/dist/composio-triggers.js +4 -1
  22. package/dist/computer-needs.d.ts +32 -0
  23. package/dist/computer-needs.js +80 -0
  24. package/dist/computer-setting.d.ts +1 -0
  25. package/dist/computer-setting.js +8 -1
  26. package/dist/console/assets/index-BFgyZzF_.js +734 -0
  27. package/dist/console/assets/index-DbilxljH.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/console-links.d.ts +1 -0
  30. package/dist/console-links.js +2 -0
  31. package/dist/env-switch.d.ts +14 -0
  32. package/dist/env-switch.js +23 -0
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +3 -0
  35. package/dist/eval-previous.js +4 -3
  36. package/dist/fal-price.js +10 -13
  37. package/dist/handed-secret.d.ts +4 -0
  38. package/dist/handed-secret.js +10 -0
  39. package/dist/harness-archive.d.ts +15 -5
  40. package/dist/harness-archive.js +71 -34
  41. package/dist/harness-check.d.ts +2 -1
  42. package/dist/harness-check.js +36 -95
  43. package/dist/harness-egress.d.ts +23 -0
  44. package/dist/harness-egress.js +69 -0
  45. package/dist/harness-recipe-entry.d.ts +71 -0
  46. package/dist/harness-recipe-entry.js +184 -0
  47. package/dist/harness-recipe.d.ts +73 -6
  48. package/dist/harness-recipe.js +185 -31
  49. package/dist/harness-sign-in.d.ts +29 -0
  50. package/dist/harness-sign-in.js +122 -0
  51. package/dist/harness-table.d.ts +21 -0
  52. package/dist/harness-table.js +58 -3
  53. package/dist/harness-zip.d.ts +6 -0
  54. package/dist/harness-zip.js +203 -0
  55. package/dist/ids.d.ts +11 -0
  56. package/dist/ids.js +36 -0
  57. package/dist/learn/commit.d.ts +14 -1
  58. package/dist/learn/commit.js +156 -1
  59. package/dist/learn/compile.js +22 -8
  60. package/dist/learn/folder.d.ts +5 -0
  61. package/dist/learn/folder.js +10 -1
  62. package/dist/learn/learning.sh +15 -3
  63. package/dist/learn/promote.d.ts +2 -2
  64. package/dist/learn/secrets.js +30 -7
  65. package/dist/learning-routes.d.ts +23 -11
  66. package/dist/learning-routes.js +110 -20
  67. package/dist/learning.d.ts +9 -6
  68. package/dist/learning.js +9 -4
  69. package/dist/mcp-gateway.js +15 -2
  70. package/dist/mcp-probe.d.ts +3 -0
  71. package/dist/mcp-probe.js +7 -2
  72. package/dist/mcp-resources.d.ts +44 -0
  73. package/dist/mcp-resources.js +100 -0
  74. package/dist/mcp-servers-store.d.ts +16 -12
  75. package/dist/model.d.ts +4 -4
  76. package/dist/model.js +6 -6
  77. package/dist/native/cli.js +9 -2
  78. package/dist/native/connection.d.ts +2 -2
  79. package/dist/native/connection.js +5 -2
  80. package/dist/native/discovery.d.ts +2 -0
  81. package/dist/native/discovery.js +10 -6
  82. package/dist/native/remote-worker-bridge.js +36 -4
  83. package/dist/native/remote.d.ts +18 -1
  84. package/dist/native/remote.js +126 -37
  85. package/dist/native/schema.d.ts +6 -0
  86. package/dist/native/schema.js +31 -6
  87. package/dist/native/source-account.d.ts +13 -0
  88. package/dist/native/source-account.js +114 -0
  89. package/dist/native/source-capture-hooks.d.ts +5 -0
  90. package/dist/native/source-capture-hooks.js +102 -0
  91. package/dist/native/source-mcp-selection.d.ts +13 -0
  92. package/dist/native/source-mcp-selection.js +72 -0
  93. package/dist/native/source-runtime-tools.d.ts +19 -0
  94. package/dist/native/source-runtime-tools.js +103 -0
  95. package/dist/native/source-snapshot-types.d.ts +138 -0
  96. package/dist/native/source-snapshot-types.js +12 -0
  97. package/dist/native/source-snapshot.d.ts +8 -0
  98. package/dist/native/source-snapshot.js +1201 -0
  99. package/dist/observation/learning.js +3 -2
  100. package/dist/openapi.js +167 -36
  101. package/dist/print.js +1 -1
  102. package/dist/purged-workflow.d.ts +12 -0
  103. package/dist/purged-workflow.js +43 -0
  104. package/dist/run-keys.d.ts +46 -0
  105. package/dist/run-keys.js +109 -0
  106. package/dist/run-launch.d.ts +16 -1
  107. package/dist/run-launch.js +30 -1
  108. package/dist/run-learning-served.d.ts +2 -2
  109. package/dist/run-model-key.d.ts +2 -2
  110. package/dist/run-model-key.js +5 -5
  111. package/dist/run-secrets.d.ts +2 -0
  112. package/dist/run-secrets.js +7 -4
  113. package/dist/run-view.d.ts +17 -0
  114. package/dist/run-view.js +25 -1
  115. package/dist/runner/adapter-loop.d.ts +11 -3
  116. package/dist/runner/adapter-loop.js +138 -22
  117. package/dist/runner/adapter-run-spec.js +25 -12
  118. package/dist/runner/audit.d.ts +2 -0
  119. package/dist/runner/audit.js +9 -1
  120. package/dist/runner/beside.js +2 -1
  121. package/dist/runner/claim-secrets.d.ts +29 -3
  122. package/dist/runner/claim-secrets.js +38 -4
  123. package/dist/runner/cli-run-spec.js +23 -12
  124. package/dist/runner/harness-loops.d.ts +6 -0
  125. package/dist/runner/harness-loops.js +11 -1
  126. package/dist/runner/held.d.ts +4 -0
  127. package/dist/runner/journal-kinds.d.ts +2 -0
  128. package/dist/runner/learned-first.d.ts +2 -0
  129. package/dist/runner/learned-first.js +1 -1
  130. package/dist/runner/learning-end.d.ts +7 -2
  131. package/dist/runner/learning-end.js +22 -10
  132. package/dist/runner/learning-seed.d.ts +9 -3
  133. package/dist/runner/learning-seed.js +2 -2
  134. package/dist/runner/main.d.ts +1 -0
  135. package/dist/runner/main.js +20 -13
  136. package/dist/runner/mcp-claim.js +6 -1
  137. package/dist/runner/mcp-run.d.ts +10 -7
  138. package/dist/runner/mcp-run.js +3 -5
  139. package/dist/runner/monid-run.js +9 -11
  140. package/dist/runner/project-checkpoint.d.ts +35 -0
  141. package/dist/runner/project-checkpoint.js +116 -0
  142. package/dist/runner/project-drain.d.ts +8 -0
  143. package/dist/runner/project-drain.js +25 -0
  144. package/dist/runner/project-host.d.ts +10 -0
  145. package/dist/runner/project-host.js +52 -0
  146. package/dist/runner/promotion.d.ts +14 -6
  147. package/dist/runner/promotion.js +98 -41
  148. package/dist/runner/redact.d.ts +13 -0
  149. package/dist/runner/redact.js +67 -1
  150. package/dist/runner/run-channel.d.ts +9 -0
  151. package/dist/runner/run-channel.js +15 -2
  152. package/dist/runner/run-child-host.d.ts +8 -4
  153. package/dist/runner/run-child-host.js +171 -41
  154. package/dist/runner/run-errors.js +2 -2
  155. package/dist/runner/runner-check.js +5 -2
  156. package/dist/runner/runner.js +26 -9
  157. package/dist/runner/store-secrets.js +7 -3
  158. package/dist/runner/workflow-first.d.ts +4 -0
  159. package/dist/runner/workflow-first.js +13 -0
  160. package/dist/runner/workflow-loop.d.ts +2 -1
  161. package/dist/runner/workflow-loop.js +2 -1
  162. package/dist/runner/workflow-spec.js +1 -1
  163. package/dist/runs-over-store.d.ts +34 -6
  164. package/dist/runs-over-store.js +133 -25
  165. package/dist/sdk/runs.d.ts +11 -1
  166. package/dist/sdk/runs.js +117 -26
  167. package/dist/sdk/schema.js +12 -2
  168. package/dist/sdk/workflows.d.ts +1 -1
  169. package/dist/server.d.ts +68 -32
  170. package/dist/server.js +600 -110
  171. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  172. package/dist/source-sync/adoption.d.ts +15 -0
  173. package/dist/source-sync/adoption.js +36 -0
  174. package/dist/source-sync/auxiliary.d.ts +23 -0
  175. package/dist/source-sync/auxiliary.js +64 -0
  176. package/dist/source-sync/capture-git.d.ts +5 -0
  177. package/dist/source-sync/capture-git.js +272 -0
  178. package/dist/source-sync/capture-project.d.ts +53 -0
  179. package/dist/source-sync/capture-project.js +206 -0
  180. package/dist/source-sync/capture-refusal.d.ts +7 -0
  181. package/dist/source-sync/capture-refusal.js +16 -0
  182. package/dist/source-sync/capture.d.ts +11 -0
  183. package/dist/source-sync/capture.js +22 -0
  184. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  185. package/dist/source-sync/checkpoint-gate.js +52 -0
  186. package/dist/source-sync/checkpoints.d.ts +66 -0
  187. package/dist/source-sync/checkpoints.js +168 -0
  188. package/dist/source-sync/claim.d.ts +11 -0
  189. package/dist/source-sync/claim.js +48 -0
  190. package/dist/source-sync/destination.d.ts +47 -0
  191. package/dist/source-sync/destination.js +239 -0
  192. package/dist/source-sync/io.d.ts +15 -0
  193. package/dist/source-sync/io.js +52 -0
  194. package/dist/source-sync/local.d.ts +43 -0
  195. package/dist/source-sync/local.js +229 -0
  196. package/dist/source-sync/prepare.d.ts +59 -0
  197. package/dist/source-sync/prepare.js +93 -0
  198. package/dist/source-sync/projects.d.ts +61 -0
  199. package/dist/source-sync/projects.js +130 -0
  200. package/dist/source-sync/registry.d.ts +95 -0
  201. package/dist/source-sync/registry.js +226 -0
  202. package/dist/source-sync/service.d.ts +33 -0
  203. package/dist/source-sync/service.js +118 -0
  204. package/dist/source-sync/skill-edits.d.ts +12 -0
  205. package/dist/source-sync/skill-edits.js +122 -0
  206. package/dist/source-sync/snapshots.d.ts +48 -0
  207. package/dist/source-sync/snapshots.js +448 -0
  208. package/dist/source-sync/types.d.ts +9 -0
  209. package/dist/source-sync/types.js +14 -0
  210. package/dist/source-sync/workspace.d.ts +66 -0
  211. package/dist/source-sync/workspace.js +273 -0
  212. package/dist/store/agent-body.d.ts +4 -0
  213. package/dist/store/agent-body.js +16 -5
  214. package/dist/store/index.d.ts +2 -2
  215. package/dist/store/index.js +1 -1
  216. package/dist/store/schema.d.ts +2 -1
  217. package/dist/store/schema.js +2 -1
  218. package/dist/store/seal.d.ts +5 -1
  219. package/dist/store/seal.js +12 -3
  220. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  221. package/dist/store/sqlite/project-checkpoints.js +70 -0
  222. package/dist/store/sqlite/run-launch.d.ts +4 -12
  223. package/dist/store/sqlite/run-launch.js +5 -19
  224. package/dist/store/sqlite/store.js +224 -170
  225. package/dist/store/store.d.ts +116 -39
  226. package/dist/store/store.js +14 -1
  227. package/dist/store-reads/learning.d.ts +2 -2
  228. package/dist/store-view.d.ts +3 -1
  229. package/dist/store-view.js +17 -5
  230. package/dist/template-import.d.ts +10 -2
  231. package/dist/template-import.js +116 -13
  232. package/dist/templates.d.ts +26 -5
  233. package/dist/templates.js +62 -10
  234. package/dist/timeline/index.d.ts +1 -1
  235. package/dist/timeline/index.js +1 -1
  236. package/dist/timeline/timeline.d.ts +5 -0
  237. package/dist/timeline/timeline.js +8 -0
  238. package/dist/tool-plane.d.ts +12 -12
  239. package/dist/tools.d.ts +8 -8
  240. package/dist/trigger-launch-hook.d.ts +47 -0
  241. package/dist/trigger-launch-hook.js +90 -0
  242. package/dist/trigger-targets.d.ts +14 -1
  243. package/dist/trigger-targets.js +20 -0
  244. package/dist/triggers.d.ts +54 -5
  245. package/dist/triggers.js +143 -8
  246. package/dist/uploads-archil.js +1 -1
  247. package/dist/uploads.js +1 -1
  248. package/dist/validate.js +1 -2
  249. package/dist/workspace/computer-for-claim.d.ts +2 -0
  250. package/dist/workspace/computer-for-claim.js +43 -0
  251. package/dist/workspace/paths.d.ts +6 -0
  252. package/dist/workspace/paths.js +6 -0
  253. package/dist/workspace/resolve-computer.d.ts +1 -0
  254. package/dist/workspace/run-tools.d.ts +2 -0
  255. package/dist/workspace/run-tools.js +8 -0
  256. package/launcher/agentrun-serve +1 -1
  257. package/package.json +10 -10
  258. package/skills/agentrun-serve/SKILL.md +2 -1
  259. package/templates/README.md +5 -2
  260. package/dist/console/assets/index-B-D0EM3j.js +0 -733
  261. package/dist/console/assets/index-DlQepP2J.css +0 -1
@@ -26,7 +26,7 @@ import { dockerPathsForRuns } from "../box-paths.js";
26
26
  import { hostCommandRefusals } from "../computers.js";
27
27
  import { hostAddressesOnce } from "../docker-host-addresses.js";
28
28
  import { claimInstallsStopped } from "../harness-install.js";
29
- import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_TABLE_ENV, harnessModulesEnv, harnessModulesOf, harnessTable } from "../harness-table.js";
29
+ import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_RECIPES_ENV, HARNESS_RECIPES_SETTING, HARNESS_TABLE_ENV, harnessModulesEnv, harnessModulesOf, harnessRecipesEnv, harnessRecipesOf, harnessTable } from "../harness-table.js";
30
30
  import { DEFAULT_PORT, maxRunsOf } from "../host.js";
31
31
  import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
32
32
  import { durationMs, runLine } from "../print.js";
@@ -35,6 +35,7 @@ import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
35
35
  import { migrationsIn, openStore, RunnerBelowFloor, SchemaVersionUnknown, StoreAwaitsServer, storePlace, storeTarget } from "../store/index.js";
36
36
  import { SCHEMA_VERSION } from "../store/schema.js";
37
37
  import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
38
+ import { LAUNCH_HOOK_SECRET_ENV } from "../trigger-launch-hook.js";
38
39
  import { FAUX_BROWSER_ENV } from "../tools.js";
39
40
  import { claimViewOpener } from "../computer-live.js";
40
41
  import { LOOPBACK as LIVE_LOOPBACK, runnerLiveOf } from "../live-reach.js";
@@ -46,6 +47,7 @@ import { envValue } from "../key-meta.js";
46
47
  import { fauxComputers } from "../faux-computers.js";
47
48
  import { computerDepsFrom } from "../workspace/computer-deps.js";
48
49
  import { startJanitor } from "../workspace/computer-janitor.js";
50
+ import { projectRunEnded } from "../source-sync/checkpoints.js";
49
51
  import { runEndComputers } from "../workspace/run-end-computers.js";
50
52
  import { createDispatchLoop } from "./dispatch.js";
51
53
  import { resolveRunnerLoop } from "./harness-loops.js";
@@ -91,9 +93,9 @@ export async function openRunnerStore(dataDir, env, warn, url) {
91
93
  }
92
94
  }
93
95
  /** The runner's own secrets, which a run never gets, not even in the runner's in-process environment: the server's
94
- * tokens (the token and the token list) and API key, the seal key (the runner holds it as its sealKey), and the store's connection (its URL holds a
95
- * database password). */
96
- const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_TOKENS" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name.startsWith("AGENTRUN_STORE_");
96
+ * tokens (the token and the token list) and API key, the seal key (the runner holds it as its sealKey), the store's connection (its URL holds a
97
+ * database password), and the launch hook's signing secret (the server's alone). */
98
+ const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_TOKENS" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name === LAUNCH_HOOK_SECRET_ENV || name.startsWith("AGENTRUN_STORE_");
97
99
  /** A run's environment as the runner hands its loops (AdapterSpecDeps.env): this process's, less the runner's own
98
100
  * secrets, with every other secret the launcher's pipe handed it (a model key, a tool key, a box key) readable by name
99
101
  * but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
@@ -129,7 +131,7 @@ computerDepsFrom({ env, store, sealKey, openComputerView: claimViewOpener(runner
129
131
  export function besideRunEnv(env, switches) {
130
132
  const out = runEnv(env);
131
133
  for (const name of Object.keys(out))
132
- if (name.startsWith(FAUX_PREFIX) || name === HARNESS_TABLE_ENV || name === HARNESS_MODULES_ENV)
134
+ if (name.startsWith(FAUX_PREFIX) || name === HARNESS_TABLE_ENV || name === HARNESS_MODULES_ENV || name === HARNESS_RECIPES_ENV)
133
135
  delete out[name];
134
136
  return Object.assign(out, switches);
135
137
  }
@@ -268,7 +270,7 @@ export async function startRunnerProcess(options) {
268
270
  // Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts), said as warnings.
269
271
  await sweepEndedScratch(store, options.dataDir, { log: warn });
270
272
  // A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts).
271
- const runEnded = typeof parts !== "function" ? runEndComputers({ store, computers: parts.computers, log: warn }) : undefined;
273
+ const runEnded = projectRunEnded(store, typeof parts !== "function" ? runEndComputers({ store, computers: parts.computers, log: warn }) : undefined);
272
274
  runner = startRunner({
273
275
  store,
274
276
  createLoop,
@@ -278,7 +280,7 @@ export async function startRunnerProcess(options) {
278
280
  ...(options.drainMs ? { drainMs: options.drainMs } : {}),
279
281
  memory,
280
282
  ...(options.onEvent ? { onEvent: options.onEvent } : {}),
281
- ...(runEnded ? { runEnded } : {}),
283
+ runEnded,
282
284
  // A runner on a disk of its own claims nothing while the server keeps runs' folders on the server's disk (Mode 1),
283
285
  // and says why on its presence row (disk-free.ts): those runs wait for a runner on the server's disk.
284
286
  claimGate: diskFreeGate(store, options.dataDir, env, kind),
@@ -425,9 +427,10 @@ export function runnerArgs(argv) {
425
427
  let fauxBrowser;
426
428
  let check = false;
427
429
  const harnessModules = [];
430
+ const harnessRecipes = [];
428
431
  for (let i = 0; i < argv.length; i++) {
429
432
  const given = argv[i];
430
- const equals = /^(--(?:data|loops|drain-timeout|name|faux|faux-browser|harness-module))=(.*)$/s.exec(given);
433
+ const equals = /^(--(?:data|loops|drain-timeout|name|faux|faux-browser|harness-module|harness-recipe))=(.*)$/s.exec(given);
431
434
  const arg = equals ? equals[1] : given;
432
435
  const value = () => {
433
436
  const next = equals ? equals[2] : argv[++i];
@@ -457,6 +460,8 @@ export function runnerArgs(argv) {
457
460
  fauxBrowser = value();
458
461
  else if (arg === "--harness-module")
459
462
  harnessModules.push(value());
463
+ else if (arg === "--harness-recipe")
464
+ harnessRecipes.push(value());
460
465
  else if (arg === "--check")
461
466
  check = true;
462
467
  else if (arg === "--env")
@@ -464,7 +469,7 @@ export function runnerArgs(argv) {
464
469
  else if (arg === "--heartbeat")
465
470
  heartbeatOnly = true;
466
471
  else
467
- throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]] [--harness-module M ...], or --check --data D [--name N], or --check --env [--data D], or --check --heartbeat --data D [--name N]`);
472
+ throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]] [--harness-module M ...] [--harness-recipe F ...], or --check --data D [--name N], or --check --env [--data D], or --check --heartbeat --data D [--name N]`);
468
473
  }
469
474
  if (envOnly && !check)
470
475
  throw new RunnerRefused("--env goes with --check: runner --check --env [--data D]");
@@ -474,14 +479,14 @@ export function runnerArgs(argv) {
474
479
  throw new RunnerRefused("--check takes --env (its environment alone) or --heartbeat (its heartbeat alone), not both: give neither to check both");
475
480
  // `--check --env` checks the environment alone, which needs no data directory where the store is AGENTRUN_STORE_URL's.
476
481
  if (envOnly)
477
- return { dataDir: dataDir ?? "", check: true, envOnly: true, ...(harnessModules.length ? { harnessModules } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }) };
482
+ return { dataDir: dataDir ?? "", check: true, envOnly: true, ...(harnessModules.length ? { harnessModules } : {}), ...(harnessRecipes.length ? { harnessRecipes } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }) };
478
483
  if (!dataDir)
479
484
  throw new RunnerRefused("a runner needs its data directory: --data D");
480
485
  if (heartbeatOnly)
481
486
  return { dataDir, check: true, heartbeatOnly: true, ...(name === undefined ? {} : { name }) };
482
487
  if (fauxBrowser !== undefined && faux === undefined)
483
488
  throw new RunnerRefused("--faux-browser goes with --faux");
484
- return { dataDir, ...(harnessModules.length ? { harnessModules } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(fauxBrowser === undefined ? {} : { fauxBrowser }), ...(check ? { check: true } : {}) };
489
+ return { dataDir, ...(harnessModules.length ? { harnessModules } : {}), ...(harnessRecipes.length ? { harnessRecipes } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(fauxBrowser === undefined ? {} : { fauxBrowser }), ...(check ? { check: true } : {}) };
485
490
  }
486
491
  /** Runs until SIGTERM or SIGINT, or until the store's runner floor rises above this runner (RunnerProcess.outdated),
487
492
  * then closes: nothing more claimed, the drain, its runs handed back. Answers the floor's words when that was the stop,
@@ -565,9 +570,10 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
565
570
  // here, as the server's start checks them (harness-table.ts harnessTable), before the runner opens the store or claims a
566
571
  // run: a module that names a built-in, repeats an id, gives an id the API does not carry or lacks a member refuses the
567
572
  // start in words naming the module and the id, never failing every run the runner would claim.
573
+ // Its harness recipes the same way: --harness-recipe, else AGENTRUN_SERVE_HARNESS_RECIPES, each loaded here.
568
574
  let modules;
569
575
  try {
570
- modules = harnessModulesEnv(harnessModulesOf(args.harnessModules, given), args.dataDir);
576
+ modules = { ...harnessModulesEnv(harnessModulesOf(args.harnessModules, given), args.dataDir), ...harnessRecipesEnv(harnessRecipesOf(args.harnessRecipes, given), args.dataDir) };
571
577
  harnessTable(modules);
572
578
  }
573
579
  catch (error) {
@@ -704,7 +710,8 @@ async function runnerCheck(args, env, name) {
704
710
  // Harness modules given as --harness-module hold what AGENTRUN_SERVE_HARNESS_MODULES would (harness-table.ts
705
711
  // harnessModulesOf): a runner started with the flag is checked with it.
706
712
  const flagged = "harnessModules" in args && args.harnessModules?.length ? args.harnessModules.join(",") : undefined;
707
- const read = (one) => (one === HARNESS_MODULES_SETTING && flagged !== undefined ? flagged : (secret(one) ?? env[one]));
713
+ const recipesFlagged = "harnessRecipes" in args && args.harnessRecipes?.length ? args.harnessRecipes.join(",") : undefined;
714
+ const read = (one) => (one === HARNESS_MODULES_SETTING && flagged !== undefined ? flagged : one === HARNESS_RECIPES_SETTING && recipesFlagged !== undefined ? recipesFlagged : (secret(one) ?? env[one]));
708
715
  const rows = args.heartbeatOnly ? [] : await checkRunnerEnv({ ...(args.dataDir ? { dataDir: args.dataDir } : {}), env, read });
709
716
  // What the runner's start refuses before it claims (runnerMain): its run slots, drain and free-model requests, the
710
717
  // Archil settings it is given, and its runs' isolation (the user each run runs as, and the image's helper that switches
@@ -56,6 +56,7 @@ import { mcpNameOf } from "../tool-names.js";
56
56
  import { composioMadeKey, composioPerRun } from "../composio-made.js";
57
57
  import { composioRunQuery } from "../composio-preset.js";
58
58
  import { META_REASON, metaToolOf } from "../mcp-meta.js";
59
+ import { resourceToolProblem } from "../mcp-resources.js";
59
60
  import { credentialInQuery, credentialInQueryWords, shownUrl } from "../mcp-probe.js";
60
61
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
61
62
  import { GITHUB_MCP_ONLY, GITHUB_MCP_ORIGIN, githubMcpUrl } from "../github.js";
@@ -479,9 +480,13 @@ async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN
479
480
  const saved = (found ?? {});
480
481
  // Every tool the revision pinned, granted or not, against the meta tools known now (the list grows after a save).
481
482
  for (const [server, { url, tools }] of Object.entries(saved)) {
482
- for (const tool of tools)
483
+ for (const tool of tools) {
483
484
  if (metaToolOf(url, tool.name))
484
485
  throw new McpClaimRefused(`mcp:${server}/${tool.name} can't be granted: ${META_REASON}`);
486
+ const problem = resourceToolProblem(tool);
487
+ if (problem)
488
+ throw new McpClaimRefused(`mcp:${server}/${tool.name} can't be granted: ${problem}. Save the agent again. Nothing was sent.`);
489
+ }
485
490
  }
486
491
  // The granted tools alone, keyed by server with no prototype (a server named `constructor` is a server like any other).
487
492
  const pinned = Object.create(null);
@@ -1,7 +1,6 @@
1
1
  import type { HostTool } from "@parcha/agentrun-kernel";
2
2
  import type { Harness } from "@earendil-works/pi-durable";
3
3
  import { type McpGatewayOptions } from "../mcp-gateway.js";
4
- import { type MediaReader } from "../fal-price.js";
5
4
  import { type WebFake } from "../web-fake.js";
6
5
  import type { SaveSlots } from "../web-save.js";
7
6
  import { type OAuthNetwork } from "../mcp-oauth.js";
@@ -59,9 +58,16 @@ export interface McpForClaimOptions {
59
58
  connectMs?: number;
60
59
  };
61
60
  readonly githubTimer?: GithubTimer;
62
- /** Whether the run has a spend cap, and the reader of a metered job's input media (McpGatewayOptions). */
63
- readonly capped?: McpGatewayOptions["capped"];
64
- readonly media?: McpGatewayOptions["media"];
61
+ /** Whether the run has a spend cap (its launch's max_cost_usd): under one, a metered job that can't be priced is refused
62
+ * unsent. None: it has. */
63
+ readonly capped?: boolean;
64
+ /** Where a metered job's input media are read from, through the guard web_save downloads by: an eval's web fake `web`,
65
+ * else the faux module or the public network by `env`, in web_save's `slots`. None: such a job can't be priced. */
66
+ readonly media?: {
67
+ readonly env: NodeJS.ProcessEnv;
68
+ readonly web?: WebFake;
69
+ readonly slots?: SaveSlots;
70
+ };
65
71
  /** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
66
72
  readonly hold?: (values: string[]) => void;
67
73
  }
@@ -89,9 +95,6 @@ export interface ClaimMcp {
89
95
  /** Drops every credential held: the pass ended, the claim is lost, or its signal aborted. */
90
96
  release(): void;
91
97
  }
92
- /** A claim's reader of a metered job's input media: through the guard web_save downloads by (an eval's web fake, a faux
93
- * module, else the public network), in `slots`. */
94
- export declare const mediaForClaim: (env: NodeJS.ProcessEnv, web?: WebFake, slots?: SaveSlots) => MediaReader;
95
98
  /** The wire names a subagent's `grant` gives of the run's MCP and monid tools, by the gate's keys; else the grant's own. */
96
99
  export declare function catalogSessionNames(catalog: Pick<ClaimMcp, "tools" | "catalogOf"> | undefined, grant: string): string[];
97
100
  /** The run's MCP for one claim: undefined when it grants no MCP tool. Throws McpClaimRefused (a granted tool its pin lacks,
@@ -13,9 +13,6 @@ import { mcpClaim } from "./mcp-claim.js";
13
13
  import { registryListing } from "../mcp-pin-first.js";
14
14
  import { heldOrThrow } from "./held.js";
15
15
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
16
- /** A claim's reader of a metered job's input media: through the guard web_save downloads by (an eval's web fake, a faux
17
- * module, else the public network), in `slots`. */
18
- export const mediaForClaim = (env, web, slots) => publicMedia(async () => (web ? fakeSaveOptions(web) : fetchOptions(env, FAUX_ENV)), slots);
19
16
  /** The wire names a subagent's `grant` gives of the run's MCP and monid tools, by the gate's keys; else the grant's own. */
20
17
  export function catalogSessionNames(catalog, grant) {
21
18
  const given = (catalog?.tools ?? []).flatMap((tool) => (permissionKeys(catalog.catalogOf(tool.name) ?? "").includes(grant) ? [tool.name] : []));
@@ -60,6 +57,7 @@ export async function mcpForClaim(options) {
60
57
  return undefined;
61
58
  }
62
59
  const network = options.network ?? systemNetwork;
60
+ const media = options.media;
63
61
  const gateway = mcpGateway({
64
62
  pin,
65
63
  credentials: step.credentials,
@@ -81,8 +79,8 @@ export async function mcpForClaim(options) {
81
79
  commit: () => (change) => options.harness.commit(change, BACKGROUND_CONTEXT),
82
80
  ...(options.fetch ? { fetch: options.fetch } : {}),
83
81
  ...(options.callBounds ? { bounds: options.callBounds } : {}),
84
- ...(options.capped ? { capped: options.capped } : {}),
85
- ...(options.media ? { media: options.media } : {}),
82
+ capped: () => options.capped !== false,
83
+ ...(media ? { media: publicMedia(async () => (media.web ? fakeSaveOptions(media.web) : fetchOptions(media.env, FAUX_ENV)), media.slots) } : {}),
86
84
  });
87
85
  const catalog = new Map();
88
86
  const declared = new Map();
@@ -25,21 +25,19 @@ export function monidForClaim(pin, env, work, runId, capped = () => false, fake)
25
25
  const faux = await fauxFetch(env, FAUX_MONID_ENV);
26
26
  return monidClient({ key: env[MONID_KEY_ENV] ?? "", ...(faux ? { fetch: faux } : {}) });
27
27
  };
28
- /** Stops the run when monid charged `name`'s call more than the `heldUsd` it was held at: maxCost checks only monid's
29
- * estimate, so such a charge is booked as charged (by its paid step), logged, and stops the run at once in words naming
30
- * both (stopRun). */
31
- const overHold = async (name, charged, heldUsd) => {
28
+ /** Logs a charge monid made for `name`'s call above the `heldUsd` it was held at: maxCost checks only monid's estimate,
29
+ * so such a charge is booked as charged (by its paid step), and the run's cap decides whether the run goes on
30
+ * (adapter-loop.ts paidUnder: it stops once its charges pass the cap). */
31
+ const overHold = (name, charged, heldUsd) => {
32
32
  if (typeof charged !== "number" || Math.round(charged * 1e6) <= Math.round(heldUsd * 1e6))
33
33
  return;
34
- const words = `monid charged ${money(charged)}, more than the ${money(heldUsd)} held; the run stopped`;
35
- console.error(`[runner] run ${runId ?? "(unnamed)"}: ${name}: ${words}`);
36
- await stopRun(words);
34
+ console.error(`[runner] run ${runId ?? "(unnamed)"}: ${name}: monid charged ${money(charged)}, more than the ${money(heldUsd)} held`);
37
35
  };
38
36
  // monid's estimate for the call `callId` priced by usage, read once the call may run, on the run's ledger `ledger`:
39
37
  // the call sent with maxCost 0, which monid refuses unrun and uncharged, naming the estimate, or runs when it estimates
40
38
  // the call at $0 (a free run). So the read is a paid step of the call, marked at $0 before it is sent (a crash while
41
39
  // monid holds it leaves its possible charge on record, unknown), given back when monid refused it unrun, else settled
42
- // at what monid charged, a charge above $0 stopping the run. One whose charge is unknown (no answer, FAILED with no
40
+ // at what monid charged, a charge above $0 left to the run's cap as any charge above its hold is. One whose charge is unknown (no answer, FAILED with no
43
41
  // cost) stops a capped run too: its $0 hold bounds nothing, so the cap can't be kept. One its call's signal cut off is
44
42
  // left as a crash leaves it: the run is stopping or its claim is going.
45
43
  const estimated = async (ledger, callId, name, at, input, signal) => {
@@ -61,7 +59,7 @@ export function monidForClaim(pin, env, work, runId, capped = () => false, fake)
61
59
  console.error(`[runner] run ${runId ?? "(unnamed)"}: ${name}: ${words}`);
62
60
  await stopRun(words);
63
61
  }
64
- await overHold(name, charged, 0);
62
+ overHold(name, charged, 0);
65
63
  return { answer: step.result };
66
64
  };
67
65
  /** A call of the fixed-price endpoint `at` (`name`) with `input`, held at its pinned `usd`: its price read again first
@@ -86,7 +84,7 @@ export function monidForClaim(pin, env, work, runId, capped = () => false, fake)
86
84
  return { answer: read.answer };
87
85
  };
88
86
  /** One paid step for the call `callId` of `name` on the run's ledger `ledger`: held at `held.usd`, `send` run, settled at
89
- * what monid says it charged; a charge above the hold stops the run (overHold). */
87
+ * what monid says it charged; a charge above the hold is logged (overHold) and left to the run's cap. */
90
88
  const paidCall = async (ledger, callId, name, held, send) => {
91
89
  const paid = await paidStep(ledger, callId, { name, holdUsd: held.usd, basis: held.basis, by: "monid", reported: true }, send, (outcome) => {
92
90
  if (!("result" in outcome))
@@ -96,7 +94,7 @@ export function monidForClaim(pin, env, work, runId, capped = () => false, fake)
96
94
  });
97
95
  if ("refused" in paid)
98
96
  return paid;
99
- await overHold(name, chargeOf(paid.result), held.usd);
97
+ overHold(name, chargeOf(paid.result), held.usd);
100
98
  return paid;
101
99
  };
102
100
  const tools = names.flatMap((name) => {
@@ -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,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;