@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
@@ -17,7 +17,9 @@
17
17
  // keeps sealed (store-secrets.ts storeSecrets), the runner's secrets, the keys its claim handed it, and the sign-in
18
18
  // pointers its row says it was handed, read back from the store (handed-values.ts handedValuesOf). A run whose
19
19
  // pointers can't be read back learns nothing (the hook drops it, saying why), never over a shorter list.
20
- // A run whose seed could not be read keeps that drop.
20
+ // A run whose seed could not be read keeps that drop. A run whose seed was read at or before a reset of its agent's
21
+ // learning learns nothing at all, dropped at its entry with reason `reset`. Every read of the agent's runs here reads
22
+ // only those after the reset (learn/compile.ts sinceReset).
21
23
  import { createHash } from "node:crypto";
22
24
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
23
25
  import { isMessageRow } from "../timeline/index.js";
@@ -25,10 +27,11 @@ import { correctionRefused, learningCommit } from "../learn/commit.js";
25
27
  import { CAPS, checkDraft, problemWords, unstorable } from "../learn/index.js";
26
28
  import { repickSiteOf } from "../learn/check.js";
27
29
  import { repickLabelOf, repickRewrite } from "../learn/repick.js";
28
- import { folderAt, readLearning, readSnapshot, runMergeOf, snapshotAt, textsAt } from "../learn/folder.js";
29
- import { completedRun, compileStoppedOf, lastOwnRuns, compileDue, compilePrompt, compileReference, COMPILE_TRACES, DRAFT_FAILED, heldNamesOf, newCompileAttempt } from "../learn/compile.js";
30
+ import { folderAt, holdsCommit, readLearning, readSnapshot, runMergeOf, snapshotAt, textsAt } from "../learn/folder.js";
31
+ import { completedRun, compileStoppedOf, lastOwnRuns, sinceReset, compileDue, compilePrompt, compileReference, COMPILE_TRACES, DRAFT_FAILED, draftFailedOf, heldNamesOf, newCompileAttempt } from "../learn/compile.js";
32
+ import { heldOnGiveBacks, reviseAttemptOf, sdkInputText } from "./promotion.js";
30
33
  import { loopOf, repickOf } from "../learning-setting.js";
31
- import { CHECK_TEXT_MAX, promotionOf, promotionsOf, recordPromotion } from "../learn/promote.js";
34
+ import { CHECK_TEXT_MAX, promotionOf, promotionsOf, recordPromotion, resetAtOf } from "../learn/promote.js";
32
35
  import { draftDecisionProviders, draftDryRun, draftFiles, draftMcpTools, unpricedCalls, WORKFLOWS_DIR } from "../learn/workflow-draft.js";
33
36
  import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
34
37
  import { handedValuesOf } from "../handed-values.js";
@@ -36,7 +39,7 @@ import { excerptShown, MIN_SECRET, redactSecrets } from "../learn/secrets.js";
36
39
  import { LEARNED_WORKFLOW_TOOL } from "../learned-workflow.js";
37
40
  import { META_TOOLS } from "../meta-tool-names.js";
38
41
  import { holdsSecret, LEARNING_LABEL, secretsShown } from "../learning.js";
39
- import { said, STOPPED } from "../learning-words.js";
42
+ import { said, seedStopped } from "../learning-words.js";
40
43
  import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
41
44
  import { FINAL_STATES } from "../store/store.js";
42
45
  import { shadowRunId } from "../learn/audit.js";
@@ -45,7 +48,7 @@ import { readApprovers } from "../server-approvers.js";
45
48
  import { isCliRecord, runEntries, runTimeline, withoutFeedbackRounds } from "../store-reads/journal.js";
46
49
  import { capNowOf, KINDS } from "./journal-kinds.js";
47
50
  import { bookedCapSpend, cliModelWorked, runCostOf } from "./metrics.js";
48
- import { fits, workflowDigest } from "./workflow-first.js";
51
+ import { fits, sdkTakes, workflowDigest } from "./workflow-first.js";
49
52
  import { pendingFeedbackOf } from "./feedback-round.js";
50
53
  import { createReflectHook } from "./reflect-hook.js";
51
54
  import { sdkDraftTools } from "../sdk/workflows.js";
@@ -64,7 +67,7 @@ export function learningEndOfRun(launch, deps) {
64
67
  if (held())
65
68
  return heldEndOfRun();
66
69
  const env = deps.env ?? process.env;
67
- const hookFor = (seed, round) => createReflectHook({
70
+ const hookFor = (seed, round, mustHold) => createReflectHook({
68
71
  round,
69
72
  // A run its cap stopped has no room left, and one whose spend is unknown under a cap cannot be kept within it. The cap
70
73
  // is the run's now (capNowOf: its newest raise's, else its launch's), the one its requests were admitted under. Its
@@ -104,7 +107,7 @@ export function learningEndOfRun(launch, deps) {
104
107
  correctionRefused: ({ runId, agentId, round: at, text, refuse }) => withFolder(deps, agentId, (folder) => correctionRefused(folder.workspace, text, refuse, { runId, round: at })),
105
108
  // A run with no workflow binding (an SDK run's `noWorkflows`) compiles nothing.
106
109
  ...(start.noWorkflows ? {} : {
107
- compileFacts: (input) => compileAskOf(deps, { ...input, input: launch.input, seedWorkflows: start.workflows?.length ?? 0, corrections: start.section }),
110
+ compileFacts: (input) => compileAskOf(deps, { ...input, input: launch.input, ...(launch.sdk ? { sdkTask: sdkInputText(launch) } : {}), seedWorkflows: start.workflows?.length ?? 0, corrections: start.section }),
108
111
  compileFailed: (input) => recordDraftFailed(deps, input),
109
112
  }),
110
113
  // The run's secrets, what the claim handed it, every secret the server keeps sealed, and the sign-in pointers it was
@@ -130,7 +133,7 @@ export function learningEndOfRun(launch, deps) {
130
133
  commit: async ({ runId, agentId, round: at, draft, correction, refuse }) => {
131
134
  const reason = draft ? `Compiled the job as workflow ${draft.name}${correction !== undefined ? ", with its owner's correction" : ""}.` : "Its owner's correction.";
132
135
  const done = await commitDirect({ folder: () => deps.learningFolder(agentId), log: deps.log ?? (() => undefined) }, {
133
- runId, round: at, reason, seed, files: draft ? draft.files.map((file) => ({ ...file })) : [],
136
+ runId, round: at, reason, seed, ...(mustHold ? { mustHold } : {}), files: draft ? draft.files.map((file) => ({ ...file })) : [],
134
137
  ...(draft?.held?.length ? { held: [...draft.held] } : {}), ...(draft?.bases ? { bases: draft.bases } : {}),
135
138
  ...(correction !== undefined ? { correction, refuseValues: refuse } : {}),
136
139
  });
@@ -142,15 +145,26 @@ export function learningEndOfRun(launch, deps) {
142
145
  // Why, as its start recorded it: a folder that could not be read, or a start that could not be made from it; a
143
146
  // start that records none names no reason.
144
147
  if (seedFailed(start)) {
145
- const failed = start.seedFailed;
146
- const why = failed === "unreadable" ? STOPPED.unreadable : failed === "not_copied" ? STOPPED.notCopied : STOPPED.noSeed;
148
+ const why = seedStopped(start.seedFailed);
147
149
  // Every end of it: the first's drop stands for a later one (the store keeps one a round, so it adds nothing new).
148
150
  return { also: [{ table: "learning_proposals", row: { turn: null, proposal: { state: "dropped", reason: "seed_failed", detail: said.stopped(why) } } }] };
149
151
  }
152
+ // The one check at the entry of a run's learning end, before any merge, look-back, compile, draft check or record: a
153
+ // run whose seed was read at or before a reset of its agent's learning (its watermark, learn/promote.ts resetAtOf; a
154
+ // start that records no time is read as before it) learns nothing, whole. Its corrections and compile would land on
155
+ // what the reset left. Read by time alone: a Mode 2 run's end writes the folder on its disk, which never held the
156
+ // seed the server read from its own folder, so a commit missing here says nothing of a reset.
157
+ const reset = await resetAtOf(deps.store.settings, input.agentId);
158
+ if (reset !== undefined && !(start.seededAt !== undefined && start.seededAt > reset)) {
159
+ return { also: [{ table: "learning_proposals", row: { turn: null, proposal: { state: "dropped", reason: "reset", detail: said.reset } } }] };
160
+ }
161
+ // The second wall, once the agent's learning was reset: a seed this folder holds now is one its merge must still
162
+ // find (commit.ts mustHold), so a reset after this check refuses the merge whole in the script.
163
+ const mustHold = reset !== undefined && (await withFolder(deps, input.agentId, (folder) => holdsCommit(folder.workspace, start.seed))) ? start.seed : undefined;
150
164
  // Which end of the run this is: the round after the newest it kept (a follow-up opened the run again after it), else
151
165
  // its first. A replayed end reads the same round: its rows are written only with the end that closes it.
152
166
  const prior = await deps.store.learning.proposal(input.runId);
153
- return hookFor(start.seed, prior ? prior.round + 1 : 1)(input);
167
+ return hookFor(start.seed, prior ? prior.round + 1 : 1, mustHold)(input);
154
168
  };
155
169
  }
156
170
  /** What every cap gate of run `runId` reads as spent beside it on its behalf (adapter-loop.ts RunCapConfig.beside): its
@@ -464,20 +478,23 @@ const workflowText = (doc) => {
464
478
  const text = `${JSON.stringify(doc, null, 2)}\n`;
465
479
  return Buffer.byteLength(text) <= CAPS.file ? text : `${JSON.stringify(doc)}\n`;
466
480
  };
481
+ /** The digest of the failed-draft record run `runId`'s compile keeps (recordDraftFailed): one per run. */
482
+ export const draftFailedDigest = (runId) => createHash("sha256").update(`draft-failed\n${runId}`).digest("hex").slice(0, 16);
467
483
  /** Compile once: run `runId`'s compile turn whose drafts all failed their checks is the compile's attempt, kept as a
468
484
  * promotion record of the shape a check's stop has (runner/promotion.ts stopUnchecked): a hold with nothing checked,
469
485
  * its reason (DRAFT_FAILED) naming the failed checks. A first compile's earns the one recompile, as a check's hold
470
486
  * does (the agent's next due run compiles once more: learn/compile.ts newCompileAttempt); a recompile's (a revision of
471
487
  * a held workflow, or a new one after a first compile's failed drafts) stops (compileStoppedOf, heldNamesOf): nothing
472
- * compiles it again. One record per run (its digest is the run's), written once: a claim that ends the run again
488
+ * compiles it again. A revision of a connected agent's hold on give-backs is no recompile (runner/promotion.ts
489
+ * reviseAttemptOf). One record per run (its digest is the run's), written once: a claim that ends the run again
473
490
  * writes none. */
474
491
  export async function recordDraftFailed(deps, input) {
475
492
  try {
476
493
  const records = await promotionsOf(deps.store.settings, input.agentId);
477
- const attempt = input.compile.mode === "revise" ? 2 : newCompileAttempt(records);
494
+ const attempt = input.compile.mode === "revise" ? reviseAttemptOf(records, input.compile.held) : newCompileAttempt(records);
478
495
  const { compile_after, agree_min, alone_min } = await loopOfRun(deps.store, input.runId);
479
496
  const workflow = input.compile.mode === "revise" ? input.compile.workflow : input.workflow;
480
- const digest = createHash("sha256").update(`draft-failed\n${input.runId}`).digest("hex").slice(0, 16);
497
+ const digest = draftFailedDigest(input.runId);
481
498
  const failed = input.errors.join("; ").slice(0, CHECK_TEXT_MAX) || "no draft passed";
482
499
  const reason = `${DRAFT_FAILED}: ${failed}. ${attempt === 2 ? "It was the recompile, so it stops: nothing compiles again until its owner acts" : "It is not promoted; the next due run compiles it once more"}`;
483
500
  const check = { compile_after, agree_min, alone_min, attempt, n: 0, agreed: 0, alone: 0, of: [], ...(attempt === 2 ? { stopped: true } : {}) };
@@ -518,7 +535,8 @@ export function traceFrom(timeline, refuse) {
518
535
  * that fits the run's input and whose promotion holds it at main's digest (runner/promotion.ts: its one check on the
519
536
  * agent's own runs fell under the bar; its champion served the run, or the agent did by hand), its text as main holds
520
537
  * it, with the check's numbers and the inputs it disagreed on, once per hold (none when any run since the hold compiled
521
- * it, read from the agent's kept learning; a stopped check's none); else, when the job is due (compileDue: the run
538
+ * it, read from the agent's kept learning; a stopped check's none; a connected agent's hold on give-backs only once it
539
+ * is due, as a first compile is, on its runs since the hold); else, when the job is due (compileDue: the run
522
540
  * completed, the agent has no learned workflow active or waiting, and it has its definition's compile_after completed
523
541
  * agent runs), a new one, compiled once: one more after a first compile whose drafts all failed their checks, and none
524
542
  * after a recompile's (recordDraftFailed). A draft that passes is on main at once (a learned workflow then), so nothing
@@ -528,22 +546,29 @@ export function traceFrom(timeline, refuse) {
528
546
  * run's input (`input`, its fields for the workflow's input schema), the agent's output schema when it has one (its
529
547
  * final output's shape) and the DSL's language with this host's addendum. An SDK run's compile, asked outside its
530
548
  * session, also carries the owner's standing corrections it was laid with (`corrections`, its # Learned section), as an
531
- * in-session compile reads them in its session. Undefined when it compiles nothing, or when the folder can't be read. */
549
+ * in-session compile reads them in its session; its held workflow is the one its task fits (`sdkTask`: sdkTakes, as its
550
+ * start reserves a check). Undefined when it compiles nothing, or when the folder can't be read. */
532
551
  export async function compileAskOf(deps, input) {
552
+ const { agentId } = input;
533
553
  // A revision is asked only of a workflow its promotion holds, once per hold. The workflows whose newest revision other
534
554
  // than their champion (learn/promote.ts championOf: it serves while that one is held) is held: the run's own may be one.
535
- const records = await promotionsOf(deps.store.settings, input.agentId).catch(() => []);
555
+ const records = await promotionsOf(deps.store.settings, agentId).catch(() => []);
536
556
  const heldNames = heldNamesOf(records);
537
557
  // The loop's numbers on the agent's definition (the revision this run runs): the first compile waits for compile_after
538
558
  // completed agent runs, the ending one counted.
539
559
  const { compile_after: compileAfter } = await loopOfRun(deps.store, input.runId);
540
- // The agent's latest runs, newest first: those after the ending one in the list started before it.
541
- const listed = await deps.store.runs.list({ agentId: input.agentId, limit: Math.max(200, 2 * compileAfter) });
560
+ // The agent's latest runs, newest first: those after the ending one in the list started before it, and after its
561
+ // learning's reset (sinceReset): a run before the reset is never a compile's trace. None on a named disk: it learns
562
+ // nothing (learn/learning-of.ts).
563
+ const listed = await deps.store.runs.list({ agentId, disk: null, limit: Math.max(200, 2 * compileAfter) });
542
564
  const at = listed.findIndex((run) => run.id === input.runId);
543
- const earlier = (at < 0 ? listed : listed.slice(at + 1)).filter((run) => run.agentId === input.agentId);
565
+ const since = await sinceReset(deps.store, agentId);
566
+ const earlier = (at < 0 ? listed : listed.slice(at + 1)).filter((run) => run.agentId === agentId && since(run));
544
567
  const done = earlier.filter(completedRun);
545
- const byHand = (await lastOwnRuns(deps.store, input.agentId, compileAfter, input.runId)).length;
546
- const dueWith = (workflows) => compileDue({ completed: input.outcome === "completed", runs: byHand + (input.outcome === "completed" ? 1 : 0), workflows, compileAfter });
568
+ const own = await lastOwnRuns(deps.store, agentId, compileAfter, input.runId);
569
+ // Due on the agent's own completed runs, the ending one counted.
570
+ const ending = input.outcome === "completed" ? 1 : 0;
571
+ const dueWith = (workflows) => compileDue({ completed: ending === 1, runs: own.length + ending, workflows, compileAfter });
547
572
  const compiledOf = (kept) => kept?.proposal?.compiled;
548
573
  // Compile once: a recompile whose drafts failed their checks stopped the agent's new compiles (recordDraftFailed).
549
574
  const stopped = compileStoppedOf(records);
@@ -575,7 +600,8 @@ export async function compileAskOf(deps, input) {
575
600
  let current;
576
601
  let held;
577
602
  if (heldNames.size) {
578
- // The one active workflow that fits the run's input (the one workflow-first would serve), held at main's digest.
603
+ // The one active workflow that fits the run's input (the one workflow-first would serve; an SDK run's, the one its
604
+ // task fits as its start reserves a check), held at main's digest.
579
605
  const active = [];
580
606
  for (const one of workflows)
581
607
  if (one.status === "active" && heldNames.has(one.name)) {
@@ -583,7 +609,8 @@ export async function compileAskOf(deps, input) {
583
609
  if (text !== undefined)
584
610
  active.push({ name: one.name, workflow: text });
585
611
  }
586
- const fitting = active.filter((one) => fits(one, input.input, dsl.resolveSchemaForWorkflow));
612
+ const resolve = dsl.resolveSchemaForWorkflow;
613
+ const fitting = active.filter((one) => input.sdkTask !== undefined ? sdkTakes(one, input.sdkTask, resolve) : fits(one, input.input, resolve));
587
614
  const record = fitting.length === 1 ? promotionOf(records, fitting[0].name, workflowDigest(fitting[0])) : undefined;
588
615
  if (record?.decided === "hold" && !record.check?.stopped && !record.audit?.stopped)
589
616
  [held, current] = [record, fitting[0].workflow];
@@ -615,12 +642,22 @@ export async function compileAskOf(deps, input) {
615
642
  };
616
643
  let held;
617
644
  if (read.held) {
645
+ // A give-back hold revises at a first compile's cadence: compile_after own completed runs started after the hold (the turn that wrote it is not one).
646
+ const heldAt = Date.parse(read.held.at);
647
+ const after = (run) => run !== undefined && run.startedAt > heldAt;
648
+ const sinceHold = own.filter(after).length + (after(listed[at]) ? ending : 0);
649
+ if (heldOnGiveBacks(read.held.check) && !(ending === 1 && sinceHold >= compileAfter))
650
+ return sayLeftOut(), undefined;
618
651
  // Once per hold: a run since it that compiled this workflow asked already, whatever came of it (its revision is on its
619
652
  // way to a replay, or its draft failed its checks), however many runs ago. Read from the agent's kept learning since
620
- // the hold, never a window of its last runs; one that can't be read asks nothing.
621
- const since = Date.parse(read.held.at);
622
- const kept = await deps.store.learning.proposals(input.agentId, { limit: HELD_ASKED_READ }).catch(() => undefined);
623
- if (!kept || kept.some((one) => !(one.createdAt < since) && compiledOf(one)?.workflow === read.held.workflow))
653
+ // the hold, never a window of its last runs; one that can't be read asks nothing. A draft that failed since, not stopped
654
+ // (only a revise of a connected agent's hold on give-backs: reviseAttemptOf), asks once more: counted from it, its own
655
+ // run's kept learning (written after its record, at the run's end) not counted.
656
+ const failed = records.findLast((one) => one.workflow === read.held.workflow && draftFailedOf(one) && !one.check?.stopped && !(one.at < read.held.at));
657
+ const since = Date.parse(failed?.at ?? read.held.at);
658
+ const kept = await deps.store.learning.proposals(agentId, { limit: HELD_ASKED_READ }).catch(() => undefined);
659
+ const asked = (one) => !(one.createdAt < since) && compiledOf(one)?.workflow === read.held.workflow && draftFailedDigest(one.runId) !== failed?.digest;
660
+ if (!kept || kept.some(asked))
624
661
  return sayLeftOut(), undefined;
625
662
  const { workflow, digest, reason, check, audit } = read.held;
626
663
  // A check's or an audit's disagreements are the agent's own inputs and answers: cut of the run's secrets as a trace is
@@ -1,11 +1,15 @@
1
1
  import { type LearnedWorkflow, type Seed, type Shown } from "../learning.js";
2
2
  import type { LearningFolder } from "../learn/folder.js";
3
+ import type { Store } from "../store/index.js";
3
4
  /** What a claim reads its seed with: the commit, the agent's learning folder where the run's place keeps it (opened for
4
- * the read and ended after it), the server's secrets as cuts (`shown`), its log, and `workflows: false` for a run that
5
- * takes none (an SDK run with no workflow binding). */
5
+ * the read and ended after it), the store whose runs say which are purged (a purged run's workflow is no seed's:
6
+ * learning.ts seedAt; null in a run's own process, which reads no other run: its lay only tells its runner whether it
7
+ * laid any, and the runner reads the seed again with its store, workflowsAt), the server's secrets as cuts (`shown`),
8
+ * its log, and `workflows: false` for a run that takes none (an SDK run with no workflow binding). */
6
9
  export interface LearningSeedLay {
7
10
  readonly seed: string | null;
8
11
  readonly folder: () => LearningFolder;
12
+ readonly store: Pick<Store, "runs"> | null;
9
13
  readonly shown: () => Promise<Shown>;
10
14
  readonly log: (line: string) => void;
11
15
  readonly workflows?: false;
@@ -28,4 +32,6 @@ export declare function layLearningSeed(lay: LearningSeedLay): Promise<LaidSeed
28
32
  * (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
29
33
  * what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
30
34
  * commit is gone. */
31
- export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown">, commit: string | null): Promise<LearnedWorkflow[]>;
35
+ export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown"> & {
36
+ readonly store: Pick<Store, "runs">;
37
+ }, commit: string | null): Promise<LearnedWorkflow[]>;
@@ -14,7 +14,7 @@ export async function layLearningSeed(lay) {
14
14
  let seed;
15
15
  const folder = lay.folder();
16
16
  try {
17
- seed = await seedAt(folder.workspace, lay.seed);
17
+ seed = await seedAt(folder.workspace, lay.seed, lay.store);
18
18
  }
19
19
  catch (error) {
20
20
  lay.log(`the run starts with no learned workflow: ${message(error)}`);
@@ -44,7 +44,7 @@ export async function workflowsAt(read, commit) {
44
44
  const folder = read.folder();
45
45
  let seed;
46
46
  try {
47
- seed = await seedAt(folder.workspace, commit);
47
+ seed = await seedAt(folder.workspace, commit, read.store);
48
48
  }
49
49
  finally {
50
50
  await folder.end().catch(() => undefined);
@@ -167,6 +167,7 @@ export declare function runnerArgs(argv: readonly string[]): {
167
167
  envOnly?: true;
168
168
  heartbeatOnly?: true;
169
169
  harnessModules?: string[];
170
+ harnessRecipes?: string[];
170
171
  };
171
172
  /** Runs until SIGTERM or SIGINT, or until the store's runner floor rises above this runner (RunnerProcess.outdated),
172
173
  * then closes: nothing more claimed, the drain, its runs handed back. Answers the floor's words when that was the stop,
@@ -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);
@@ -490,7 +495,7 @@ async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN
490
495
  const listed = at?.tools.find((one) => one.name === tool);
491
496
  if (!at || !listed)
492
497
  throw new McpClaimRefused(`The MCP tool ${name} was not pinned when this agent's revision was saved, so this run cannot call it. Save the agent again to pin it. Nothing was sent.`);
493
- const kept = (pinned[server] ??= { url: at.url, tools: [] });
498
+ const kept = (pinned[server] ??= { url: at.url, tools: [], ...(at.meter ? { meter: at.meter } : {}) });
494
499
  if (!kept.tools.some((one) => one.name === listed.name))
495
500
  kept.tools.push(listed);
496
501
  const price = at.prices && Object.hasOwn(at.prices, listed.name) ? at.prices[listed.name] : undefined;
@@ -1,6 +1,8 @@
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 WebFake } from "../web-fake.js";
5
+ import type { SaveSlots } from "../web-save.js";
4
6
  import { type OAuthNetwork } from "../mcp-oauth.js";
5
7
  import type { Store, TriggerSettings } from "../store/index.js";
6
8
  import { type ApprovalPrice, type ToolEffect } from "../tool-gate.js";
@@ -56,6 +58,16 @@ export interface McpForClaimOptions {
56
58
  connectMs?: number;
57
59
  };
58
60
  readonly githubTimer?: GithubTimer;
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
+ };
59
71
  /** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
60
72
  readonly hold?: (values: string[]) => void;
61
73
  }
@@ -1,6 +1,10 @@
1
1
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
2
  import { wireName } from "../catalog.js";
3
3
  import { mcpGateway } from "../mcp-gateway.js";
4
+ import { meterFor, publicMedia } from "../fal-price.js";
5
+ import { FAUX_ENV } from "../model.js";
6
+ import { fetchOptions } from "../web-fetch-direct.js";
7
+ import { fakeSaveOptions } from "../web-fake.js";
4
8
  import { dialAt, mcpServerAt, systemNetwork } from "../mcp-oauth.js";
5
9
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
6
10
  import { mcpNameOf } from "../tool-names.js";
@@ -53,6 +57,7 @@ export async function mcpForClaim(options) {
53
57
  return undefined;
54
58
  }
55
59
  const network = options.network ?? systemNetwork;
60
+ const media = options.media;
56
61
  const gateway = mcpGateway({
57
62
  pin,
58
63
  credentials: step.credentials,
@@ -68,9 +73,14 @@ export async function mcpForClaim(options) {
68
73
  },
69
74
  beforeCall: step.beforeCall,
70
75
  work: options.work,
76
+ // fal's submission keys are scoped to the run (fal-price.ts falKeys): the same on every claim of it, so a retry after
77
+ // a resume still dedupes.
78
+ run: options.claim.runId,
71
79
  commit: () => (change) => options.harness.commit(change, BACKGROUND_CONTEXT),
72
80
  ...(options.fetch ? { fetch: options.fetch } : {}),
73
81
  ...(options.callBounds ? { bounds: options.callBounds } : {}),
82
+ capped: () => options.capped !== false,
83
+ ...(media ? { media: publicMedia(async () => (media.web ? fakeSaveOptions(media.web) : fetchOptions(media.env, FAUX_ENV)), media.slots) } : {}),
74
84
  });
75
85
  const catalog = new Map();
76
86
  const declared = new Map();
@@ -105,7 +115,10 @@ export async function mcpForClaim(options) {
105
115
  const pinned = parsed && Object.hasOwn(pin, parsed.server) ? pin[parsed.server] : undefined;
106
116
  if (!pinned?.tools.some((tool) => tool.name === parsed.tool))
107
117
  return undefined;
108
- return pinned.prices && Object.hasOwn(pinned.prices, parsed.tool) ? pinned.prices[parsed.tool] : "not metered";
118
+ if (pinned.prices && Object.hasOwn(pinned.prices, parsed.tool))
119
+ return pinned.prices[parsed.tool];
120
+ // A metered server's job is priced from its input, when the call runs: no price to show before it.
121
+ return meterFor(pinned)?.bills(parsed.tool) ? undefined : "not metered";
109
122
  },
110
123
  effectOf: (name) => pinnedEffect(pin, name),
111
124
  fresh: () => step.fresh(),
@@ -17,7 +17,7 @@ import { randomUUID } from "node:crypto";
17
17
  import { calculateCost } from "@earendil-works/pi-ai";
18
18
  import { onOpenRouter, openRouterAttribution, ROUTE_ORIGIN, streamErrorOf } from "@parcha/agentrun-kernel/host";
19
19
  import { chooseModel, MODEL_PROVIDER, runModels } from "../model.js";
20
- import { providerFor } from "../provider.js";
20
+ import { gatewayHeadersAt, providerFor } from "../provider.js";
21
21
  import { keepText, runnerSecrets, secretRedactor } from "./redact.js";
22
22
  import { callsOfText, toolsAsText } from "./text-tools.js";
23
23
  /** The wires a caller of routeOf speaks when it names none: Anthropic's Messages alone. */
@@ -50,14 +50,17 @@ export async function routeOf(model, env = process.env, tier = "default", wires
50
50
  const settings = { ...sees, ...(target.reasoning !== undefined ? { reasoning: target.reasoning } : {}), ...(target.contextWindow ? { contextWindow: target.contextWindow } : {}), ...(target.maxTokens ? { maxTokens: target.maxTokens } : {}), ...(target.thinkingLevelMap ? { thinkingLevelMap: target.thinkingLevelMap } : {}) };
51
51
  const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, ...(unpriced.has(chosen.model.modelId) ? { unpriced: true } : {}), outputCeiling: target.maxTokens ?? null, like: sees };
52
52
  // An Anthropic model speaks Messages itself: the network, at its catalog origin, its key read by name per request.
53
+ // Its requests name the claim's run, turn and attempt only where that origin is serve's own gateway (gatewayHeadersAt).
53
54
  if (chosen.model.provider === "anthropic") {
54
- return { ...route, provider: { api: "anthropic-messages", origin: target.baseUrl ?? "https://api.anthropic.com", credential: () => env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_AUTH_TOKEN ?? "" } };
55
+ const origin = target.baseUrl ?? "https://api.anthropic.com";
56
+ const headers = gatewayHeadersAt(env, origin);
57
+ return { ...route, provider: { api: "anthropic-messages", origin, credential: () => env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_AUTH_TOKEN ?? "", ...(headers ? { headers } : {}) } };
55
58
  }
56
59
  // A Claude model of serve's gateway (model.ts gatewayWire), for a caller that speaks Messages: the gateway itself, on
57
60
  // Messages, so the prompt cache marks pi-ai puts on the request reach it (provider.ts).
58
61
  if (target.api === "anthropic-messages" && chosen.model.provider === MODEL_PROVIDER && wires.includes("anthropic-messages")) {
59
62
  const to = providerFor("anthropic-messages", env, chosen.model, "pi");
60
- return { ...route, model: to.modelId, provider: { api: "anthropic-messages", origin: to.origin, credential: to.credential, auth: to.auth }, like: settings };
63
+ return { ...route, model: to.modelId, provider: { api: "anthropic-messages", origin: to.origin, credential: to.credential, auth: to.auth, ...(to.headers ? { headers: to.headers } : {}) }, like: settings };
61
64
  }
62
65
  // A model pi-ai speaks Responses to, for a caller that speaks it: that wire itself, where main sends it (provider.ts).
63
66
  if (target.api === "openai-responses" && wires.includes("openai-responses")) {
@@ -68,7 +71,7 @@ export async function routeOf(model, env = process.env, tier = "default", wires
68
71
  const plan = onPlan ? { price: () => null, unpriced: true } : {};
69
72
  return {
70
73
  ...route, model: to.modelId, ...plan,
71
- provider: { api: "openai-responses", origin: to.origin, credential: to.credential, auth: to.auth, ...(onPlan ? { plan: true } : {}), ...(to.refused ? { refused: to.refused } : {}) },
74
+ provider: { api: "openai-responses", origin: to.origin, credential: to.credential, auth: to.auth, ...(to.headers ? { headers: to.headers } : {}), ...(onPlan ? { plan: true } : {}), ...(to.refused ? { refused: to.refused } : {}) },
72
75
  like: onPlan ? { ...settings, developerRole: true } : settings,
73
76
  };
74
77
  }
@@ -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) => {