@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45

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 (388) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +580 -320
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +92 -22
  28. package/dist/composio-preset.d.ts +4 -3
  29. package/dist/composio-preset.js +81 -11
  30. package/dist/composio-triggers.d.ts +34 -2
  31. package/dist/composio-triggers.js +261 -31
  32. package/dist/computer-attach.d.ts +40 -5
  33. package/dist/computer-attach.js +130 -15
  34. package/dist/computer-keys.d.ts +3 -0
  35. package/dist/computer-keys.js +7 -1
  36. package/dist/computer-live.js +3 -2
  37. package/dist/computer-lost.d.ts +11 -0
  38. package/dist/computer-lost.js +19 -0
  39. package/dist/computer-record.d.ts +10 -2
  40. package/dist/computer-record.js +50 -18
  41. package/dist/computer-setting.d.ts +1 -0
  42. package/dist/computer-setting.js +2 -2
  43. package/dist/computers.d.ts +21 -10
  44. package/dist/computers.js +39 -28
  45. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  46. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decisions.d.ts +1 -1
  49. package/dist/dial-relay.d.ts +29 -0
  50. package/dist/dial-relay.js +94 -0
  51. package/dist/email/tools.js +10 -5
  52. package/dist/env-proxy.d.ts +2 -0
  53. package/dist/env-proxy.js +35 -0
  54. package/dist/errors.d.ts +4 -1
  55. package/dist/errors.js +10 -4
  56. package/dist/faux-computers.d.ts +8 -2
  57. package/dist/faux-computers.js +83 -6
  58. package/dist/harness-archive.d.ts +67 -0
  59. package/dist/harness-archive.js +177 -0
  60. package/dist/harness-goose.d.ts +34 -0
  61. package/dist/harness-goose.js +87 -0
  62. package/dist/harness-install.d.ts +21 -0
  63. package/dist/harness-install.js +24 -11
  64. package/dist/harness-opencode/adapter.js +1 -1
  65. package/dist/harness-table.d.ts +59 -3
  66. package/dist/harness-table.js +119 -14
  67. package/dist/harness.d.ts +17 -1
  68. package/dist/harness.js +22 -11
  69. package/dist/host.d.ts +12 -10
  70. package/dist/host.js +19 -16
  71. package/dist/import-worker.d.ts +3 -0
  72. package/dist/import-worker.js +7 -5
  73. package/dist/import.d.ts +22 -1
  74. package/dist/import.js +141 -28
  75. package/dist/key-check.js +3 -0
  76. package/dist/learn/audit.d.ts +6 -6
  77. package/dist/learn/audit.js +3 -7
  78. package/dist/learn/check.d.ts +26 -89
  79. package/dist/learn/check.js +58 -336
  80. package/dist/learn/commit.d.ts +63 -90
  81. package/dist/learn/commit.js +124 -316
  82. package/dist/learn/compile.d.ts +53 -50
  83. package/dist/learn/compile.js +88 -103
  84. package/dist/learn/corrections.d.ts +13 -0
  85. package/dist/learn/corrections.js +23 -0
  86. package/dist/learn/delete.d.ts +17 -0
  87. package/dist/learn/delete.js +42 -0
  88. package/dist/learn/folder.d.ts +35 -47
  89. package/dist/learn/folder.js +118 -134
  90. package/dist/learn/index.d.ts +3 -5
  91. package/dist/learn/index.js +6 -9
  92. package/dist/learn/learning.sh +45 -15
  93. package/dist/learn/promote.d.ts +20 -2
  94. package/dist/learn/promote.js +17 -4
  95. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
  96. package/dist/learn/{skills.js → workflow-draft.js} +65 -59
  97. package/dist/learn/workflow-nodes.d.ts +22 -1
  98. package/dist/learn/workflow-nodes.js +29 -10
  99. package/dist/learned-workflow.js +2 -2
  100. package/dist/learning-cost.d.ts +127 -13
  101. package/dist/learning-cost.js +142 -10
  102. package/dist/learning-routes.d.ts +99 -170
  103. package/dist/learning-routes.js +199 -420
  104. package/dist/learning-run.d.ts +19 -40
  105. package/dist/learning-run.js +23 -93
  106. package/dist/learning-setting.d.ts +4 -4
  107. package/dist/learning-setting.js +6 -6
  108. package/dist/learning-words.d.ts +28 -74
  109. package/dist/learning-words.js +64 -162
  110. package/dist/learning.d.ts +62 -393
  111. package/dist/learning.js +101 -651
  112. package/dist/listen-first.d.ts +30 -0
  113. package/dist/listen-first.js +115 -0
  114. package/dist/live-reach.d.ts +25 -2
  115. package/dist/live-reach.js +46 -4
  116. package/dist/llms.txt +2 -1
  117. package/dist/local-models.d.ts +3 -11
  118. package/dist/local-models.js +5 -6
  119. package/dist/mcp-servers-store.d.ts +16 -16
  120. package/dist/model-form.js +6 -5
  121. package/dist/model.d.ts +12 -4
  122. package/dist/model.js +41 -16
  123. package/dist/native/binding.js +1 -1
  124. package/dist/native/connection.js +1 -1
  125. package/dist/native/discovery.js +1 -1
  126. package/dist/native/instructions.d.ts +3 -0
  127. package/dist/native/instructions.js +5 -3
  128. package/dist/native/remote-worker-bridge.js +9 -43
  129. package/dist/native/remote.d.ts +8 -15
  130. package/dist/native/remote.js +3 -3
  131. package/dist/native/schema.js +1 -1
  132. package/dist/native/types.d.ts +2 -2
  133. package/dist/openapi.js +375 -347
  134. package/dist/owner.d.ts +8 -0
  135. package/dist/owner.js +11 -0
  136. package/dist/paid-calls.d.ts +14 -0
  137. package/dist/paid-calls.js +31 -1
  138. package/dist/particle-provider.d.ts +11 -0
  139. package/dist/particle-provider.js +135 -0
  140. package/dist/place.d.ts +8 -3
  141. package/dist/place.js +13 -9
  142. package/dist/port-models.d.ts +12 -4
  143. package/dist/port-models.js +28 -11
  144. package/dist/print.d.ts +27 -0
  145. package/dist/print.js +21 -0
  146. package/dist/provider.d.ts +7 -0
  147. package/dist/provider.js +30 -2
  148. package/dist/reflect-range.js +2 -3
  149. package/dist/run-launch.d.ts +14 -28
  150. package/dist/run-launch.js +9 -12
  151. package/dist/run-learning-served.d.ts +16 -90
  152. package/dist/run-listing.d.ts +34 -0
  153. package/dist/run-listing.js +128 -0
  154. package/dist/run-model-key.d.ts +64 -0
  155. package/dist/run-model-key.js +147 -0
  156. package/dist/run-timeline-served.js +5 -3
  157. package/dist/run-trace.d.ts +97 -0
  158. package/dist/run-trace.js +253 -0
  159. package/dist/run-view.d.ts +15 -0
  160. package/dist/run-view.js +9 -0
  161. package/dist/runnable.js +2 -1
  162. package/dist/runner/adapter-loop.d.ts +14 -6
  163. package/dist/runner/adapter-loop.js +25 -14
  164. package/dist/runner/adapter-run-spec.d.ts +22 -7
  165. package/dist/runner/adapter-run-spec.js +130 -77
  166. package/dist/runner/adapters/index.d.ts +4 -2
  167. package/dist/runner/adapters/index.js +35 -4
  168. package/dist/runner/adapters/pi.d.ts +4 -12
  169. package/dist/runner/adapters/pi.js +2 -2
  170. package/dist/runner/audit.d.ts +5 -1
  171. package/dist/runner/audit.js +31 -12
  172. package/dist/runner/beside.d.ts +7 -2
  173. package/dist/runner/beside.js +41 -9
  174. package/dist/runner/claim-secrets.d.ts +66 -1
  175. package/dist/runner/claim-secrets.js +136 -3
  176. package/dist/runner/cli-run-spec.d.ts +2 -1
  177. package/dist/runner/cli-run-spec.js +82 -59
  178. package/dist/runner/commands.d.ts +3 -6
  179. package/dist/runner/conformance/harness.d.ts +6 -0
  180. package/dist/runner/conformance/harness.js +16 -5
  181. package/dist/runner/dispatch.d.ts +2 -2
  182. package/dist/runner/end-of-run.d.ts +6 -14
  183. package/dist/runner/end-of-run.js +8 -33
  184. package/dist/runner/feedback-round.d.ts +5 -4
  185. package/dist/runner/feedback-round.js +14 -10
  186. package/dist/runner/github-app.js +3 -1
  187. package/dist/runner/harness-loops.d.ts +0 -8
  188. package/dist/runner/harness-loops.js +30 -56
  189. package/dist/runner/held.d.ts +170 -0
  190. package/dist/runner/held.js +57 -0
  191. package/dist/runner/journal-kinds.d.ts +7 -3
  192. package/dist/runner/journal-kinds.js +2 -3
  193. package/dist/runner/learned-first.d.ts +40 -0
  194. package/dist/runner/learned-first.js +32 -0
  195. package/dist/runner/learning-end.d.ts +77 -66
  196. package/dist/runner/learning-end.js +250 -299
  197. package/dist/runner/learning-seed.d.ts +15 -33
  198. package/dist/runner/learning-seed.js +24 -45
  199. package/dist/runner/loop-contract.d.ts +8 -3
  200. package/dist/runner/loop-contract.js +4 -0
  201. package/dist/runner/loop.js +6 -2
  202. package/dist/runner/main.d.ts +18 -9
  203. package/dist/runner/main.js +82 -22
  204. package/dist/runner/mcp-run.d.ts +11 -0
  205. package/dist/runner/mcp-run.js +67 -0
  206. package/dist/runner/memory-claim.d.ts +14 -6
  207. package/dist/runner/memory-claim.js +18 -9
  208. package/dist/runner/model-route.d.ts +7 -4
  209. package/dist/runner/model-route.js +22 -10
  210. package/dist/runner/native-loop.d.ts +0 -7
  211. package/dist/runner/native-loop.js +9 -101
  212. package/dist/runner/promotion.d.ts +13 -6
  213. package/dist/runner/promotion.js +63 -17
  214. package/dist/runner/reflect-hook.d.ts +64 -91
  215. package/dist/runner/reflect-hook.js +112 -206
  216. package/dist/runner/run-channel.d.ts +43 -0
  217. package/dist/runner/run-channel.js +467 -0
  218. package/dist/runner/run-child-host.d.ts +169 -0
  219. package/dist/runner/run-child-host.js +1222 -0
  220. package/dist/runner/run-child.d.ts +1 -0
  221. package/dist/runner/run-child.js +254 -0
  222. package/dist/runner/run-errors.d.ts +2 -0
  223. package/dist/runner/run-errors.js +20 -0
  224. package/dist/runner/runner.js +58 -9
  225. package/dist/runner/sdk-ask.d.ts +78 -0
  226. package/dist/runner/sdk-ask.js +158 -0
  227. package/dist/runner/sdk-loop.d.ts +2 -4
  228. package/dist/runner/sdk-loop.js +29 -49
  229. package/dist/runner/store-secrets.d.ts +5 -3
  230. package/dist/runner/store-secrets.js +14 -6
  231. package/dist/runner/workflow-first.d.ts +5 -0
  232. package/dist/runner/workflow-first.js +4 -0
  233. package/dist/runner/workflow-spec.js +17 -4
  234. package/dist/runs-over-store.d.ts +21 -32
  235. package/dist/runs-over-store.js +44 -41
  236. package/dist/sdk/runs.d.ts +6 -11
  237. package/dist/sdk/runs.js +20 -41
  238. package/dist/sdk/schema.js +3 -4
  239. package/dist/sdk/workflows.d.ts +1 -1
  240. package/dist/seal-key.d.ts +5 -0
  241. package/dist/seal-key.js +7 -0
  242. package/dist/secrets.d.ts +3 -0
  243. package/dist/secrets.js +16 -3
  244. package/dist/server.d.ts +119 -83
  245. package/dist/server.js +1121 -419
  246. package/dist/sign-ins-store.d.ts +8 -0
  247. package/dist/sign-ins-store.js +36 -1
  248. package/dist/skills.js +1 -1
  249. package/dist/store/index.d.ts +3 -3
  250. package/dist/store/index.js +2 -2
  251. package/dist/store/journal/storage.js +3 -0
  252. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  253. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  254. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  255. package/dist/store/schema.d.ts +53 -4
  256. package/dist/store/schema.js +137 -6
  257. package/dist/store/seal.d.ts +20 -2
  258. package/dist/store/seal.js +24 -8
  259. package/dist/store/sqlite/connection.d.ts +2 -0
  260. package/dist/store/sqlite/connection.js +3 -1
  261. package/dist/store/sqlite/run-launch.d.ts +4 -1
  262. package/dist/store/sqlite/run-launch.js +12 -0
  263. package/dist/store/sqlite/run-patch.d.ts +0 -17
  264. package/dist/store/sqlite/run-patch.js +4 -33
  265. package/dist/store/sqlite/store.d.ts +3 -2
  266. package/dist/store/sqlite/store.js +360 -75
  267. package/dist/store/sqlite/worker.js +25 -0
  268. package/dist/store/store.d.ts +231 -39
  269. package/dist/store/store.js +25 -3
  270. package/dist/store-reads/analytics.js +11 -1
  271. package/dist/store-reads/learning.d.ts +131 -194
  272. package/dist/store-reads/learning.js +292 -301
  273. package/dist/store-reads/loop.d.ts +0 -1
  274. package/dist/store-reads/loop.js +1 -1
  275. package/dist/store-reads/stats.js +13 -3
  276. package/dist/store-view.d.ts +34 -2
  277. package/dist/store-view.js +108 -41
  278. package/dist/telemetry.d.ts +59 -0
  279. package/dist/telemetry.js +153 -0
  280. package/dist/template-eval.d.ts +3 -6
  281. package/dist/template-eval.js +22 -36
  282. package/dist/templates.d.ts +2 -1
  283. package/dist/templates.js +6 -3
  284. package/dist/timeline/index.d.ts +1 -1
  285. package/dist/timeline/index.js +1 -1
  286. package/dist/timeline/timeline.d.ts +5 -1
  287. package/dist/timeline/timeline.js +16 -0
  288. package/dist/tool-gate.d.ts +0 -7
  289. package/dist/tool-gate.js +1 -15
  290. package/dist/tool-keys-store.d.ts +1 -1
  291. package/dist/tool-keys.d.ts +6 -4
  292. package/dist/tool-keys.js +12 -6
  293. package/dist/tool-plane.d.ts +12 -12
  294. package/dist/tools.d.ts +13 -13
  295. package/dist/tools.js +29 -9
  296. package/dist/trigger-adapter.d.ts +3 -0
  297. package/dist/trigger-adapters.d.ts +4 -0
  298. package/dist/trigger-adapters.js +13 -0
  299. package/dist/trigger-composio.d.ts +58 -1
  300. package/dist/trigger-composio.js +160 -6
  301. package/dist/triggers.d.ts +64 -5
  302. package/dist/triggers.js +141 -17
  303. package/dist/validate.d.ts +11 -7
  304. package/dist/validate.js +9 -8
  305. package/dist/webhooks.d.ts +4 -1
  306. package/dist/webhooks.js +11 -4
  307. package/dist/workspace/agent-computer.d.ts +2 -0
  308. package/dist/workspace/agent-computer.js +2 -0
  309. package/dist/workspace/archil-claim.d.ts +7 -0
  310. package/dist/workspace/archil-claim.js +29 -0
  311. package/dist/workspace/archil.d.ts +9 -1
  312. package/dist/workspace/archil.js +165 -3
  313. package/dist/workspace/attach.d.ts +3 -1
  314. package/dist/workspace/attach.js +2 -0
  315. package/dist/workspace/attached-computers.d.ts +16 -5
  316. package/dist/workspace/attached-computers.js +25 -9
  317. package/dist/workspace/computer-deps.js +1 -1
  318. package/dist/workspace/computer-for-claim.d.ts +22 -8
  319. package/dist/workspace/computer-for-claim.js +339 -46
  320. package/dist/workspace/computer-hold.js +2 -1
  321. package/dist/workspace/computer-kept.d.ts +11 -1
  322. package/dist/workspace/computer-kept.js +24 -3
  323. package/dist/workspace/resolve-computer.d.ts +41 -21
  324. package/dist/workspace/resolve-computer.js +172 -64
  325. package/dist/workspace/revision-skills.d.ts +1 -2
  326. package/dist/workspace/revision-skills.js +3 -4
  327. package/dist/workspace/run-workspace.d.ts +1 -1
  328. package/dist/workspace/run-workspace.js +5 -0
  329. package/dist/workspace/synced-folder.d.ts +85 -0
  330. package/dist/workspace/synced-folder.js +230 -0
  331. package/dist/workspace/workspace.d.ts +4 -0
  332. package/launcher/agentrun-serve +1 -1
  333. package/package.json +10 -9
  334. package/templates/README.md +7 -7
  335. package/templates/inbound-lead/agent.md +3 -3
  336. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  337. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  338. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  339. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  340. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  341. package/templates/inbound-lead/lead.schema.json +6 -5
  342. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  343. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  344. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  345. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  346. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  347. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  348. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  349. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  350. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  351. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  352. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  353. package/dist/console/assets/index-Bz6IWncl.js +0 -711
  354. package/dist/learn/grade.d.ts +0 -138
  355. package/dist/learn/grade.js +0 -682
  356. package/dist/learn/notes.d.ts +0 -81
  357. package/dist/learn/notes.js +0 -178
  358. package/dist/learn/reflect.d.ts +0 -77
  359. package/dist/learn/reflect.js +0 -228
  360. package/dist/learn/relevance.d.ts +0 -24
  361. package/dist/learn/relevance.js +0 -91
  362. package/dist/learn/seed-check.d.ts +0 -74
  363. package/dist/learn/seed-check.js +0 -103
  364. package/dist/learning-batch.d.ts +0 -291
  365. package/dist/learning-batch.js +0 -600
  366. package/dist/learning-evals.d.ts +0 -33
  367. package/dist/learning-evals.js +0 -98
  368. package/dist/native/context.d.ts +0 -6
  369. package/dist/native/context.js +0 -22
  370. package/dist/propose.d.ts +0 -52
  371. package/dist/propose.js +0 -224
  372. package/dist/runner/learning-ask.d.ts +0 -47
  373. package/dist/runner/learning-ask.js +0 -128
  374. package/dist/runner/learning-dispatch.d.ts +0 -45
  375. package/dist/runner/learning-dispatch.js +0 -99
  376. package/dist/runner/learning-factory.d.ts +0 -16
  377. package/dist/runner/learning-factory.js +0 -50
  378. package/dist/runner/learning-loop.d.ts +0 -273
  379. package/dist/runner/learning-loop.js +0 -521
  380. package/dist/usage.d.ts +0 -11
  381. package/dist/usage.js +0 -11
  382. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  383. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  384. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  385. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  386. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  387. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  388. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -15,7 +15,9 @@ import { ClaimRefused } from "./loop-contract.js";
15
15
  import { readSnapshot } from "../learn/folder.js";
16
16
  import { fits, laidFor, servedOf, workflowDigest } from "./workflow-first.js";
17
17
  import { excerptShown } from "../learn/secrets.js";
18
+ import { dslRefusalOf } from "../learn/workflow-draft.js";
18
19
  import { workflowsAt } from "./learning-seed.js";
20
+ import { held } from "./held.js";
19
21
  /** A replay run still not ended this long after its replay started counts as failed (no evidence), and is cancelled once
20
22
  * the replay is decided without it. */
21
23
  export const REPLAY_DEADLINE_MS = 60 * 60 * 1000;
@@ -134,7 +136,7 @@ export const promotionGate = (deps) => {
134
136
  if (kept)
135
137
  return { workflow: kept };
136
138
  await decide(deps, workflow, digest);
137
- return await servingNow(deps, workflow, digest, true);
139
+ return await holdRefused(deps, await servingNow(deps, workflow, digest, true));
138
140
  }
139
141
  catch (error) {
140
142
  return failed(workflow, error);
@@ -144,7 +146,7 @@ export const promotionGate = (deps) => {
144
146
  const champion = async (workflow, digest) => {
145
147
  try {
146
148
  const kept = await keptFor(deps, workflow, digest);
147
- return kept ? { workflow: kept } : await servingNow(deps, workflow, digest, false);
149
+ return kept ? { workflow: kept } : await holdRefused(deps, await servingNow(deps, workflow, digest, false));
148
150
  }
149
151
  catch (error) {
150
152
  return failed(workflow, error);
@@ -178,6 +180,35 @@ async function servingNow(deps, workflow, digest, laid) {
178
180
  deps.log(`workflow-first: ${workflow.name}'s champion at ${champion.digest} serves this run while ${digest} ${own?.decided === "promote" ? "is a revision promoted before it" : "is not promoted"}`);
179
181
  return { workflow: text };
180
182
  }
183
+ /** The words a hold of a serving revision this release's workflow DSL refuses starts with (holdRefused). */
184
+ export const DSL_REFUSES = "this release's workflow DSL refuses it";
185
+ /** `serving` as it serves this run, once a serving revision this release's workflow DSL refuses is held. The refusal is of
186
+ * the text alone (learn/workflow-draft.ts dslRefusalOf: the DSL's own validation, no tool list), never of a host setting (a tool
187
+ * gated, denied or missing, no adapter), which the run's own check still refuses as before. The hold is a promotion
188
+ * record of its digest, `hold` by its reason alone ("this release's workflow DSL refuses it: <code> at <path>: <its
189
+ * words>", cut of the host's secrets as a check's texts are), written only while the digest's newest record is still the
190
+ * promotion this claim read: of two claims at once one writes it, and a later claim finds it (nothing serves). The run
191
+ * still runs it, refused before any node runs, and hands back as before: the agent answers. The hold follows compile
192
+ * once as a check's does: the agent's next due run asks the one recompile with the reason as data (learn/compile.ts
193
+ * heldNamesOf), and that revision's check is the compile's second (attemptOf). */
194
+ async function holdRefused(deps, serving) {
195
+ if (!serving)
196
+ return serving;
197
+ const refused = dslRefusalOf(await import("@parcha/agentrun-dsl"), serving.workflow.workflow);
198
+ if (refused === undefined)
199
+ return serving;
200
+ const { name } = serving.workflow;
201
+ const digest = workflowDigest(serving.workflow);
202
+ const current = promotionOf(await promotionsOf(deps.store.settings, deps.agentId), name, digest);
203
+ if (current?.decided !== "promote")
204
+ return serving;
205
+ const reason = excerptShown(`${DSL_REFUSES}: ${refused}`, await deps.shown(), CHECK_TEXT_MAX);
206
+ const record = { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, ...(current.commit ? { commit: current.commit } : {}) };
207
+ const kept = await recordPromotion(deps.store.settings, deps.agentId, record, (was) => was?.decided === "promote" && was.at === current.at);
208
+ if (kept.won)
209
+ deps.log(`workflow-first: ${name} at ${digest} is held: ${reason}; the agent's next run recompiles it once`);
210
+ return serving;
211
+ }
181
212
  /** A run already executing keeps its revision: when an earlier claim of it served `workflow` first (its WORKFLOW_FIRST
182
213
  * entry, answered or handed back: `deps.kept`), a re-claim serves the same digest, whoever the champion is now (the loop
183
214
  * recovers that outcome as it is, never runs it again). The laid text at that digest, else its text at its record's
@@ -230,17 +261,19 @@ async function loopOfRevision(deps) {
230
261
  }
231
262
  }
232
263
  /** Which check of a compile a new revision's is: 2 when the workflow's newest record of another revision is a first
233
- * check's hold or an audit's hold, or a first compile's failed draft (this revision is its one recompile), else 1. A
234
- * stop with nothing checked (stopUnchecked) is no first check's hold: it spends no recompile. A workflow's first
235
- * revision after a first compile whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that
236
- * compile's recompile too. */
264
+ * check's hold, an audit's hold or a hold by its reason alone (holdRefused: the DSL refuses a serving revision), or a
265
+ * first compile's failed draft (this revision is its one recompile), else 1. A stop with nothing checked
266
+ * (stopUnchecked) is no first check's hold: it spends no recompile. A workflow's first revision after a first compile
267
+ * whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
237
268
  function attemptOf(records, name, digest) {
238
269
  const before = records.findLast((one) => one.workflow === name && one.digest !== digest);
239
270
  if (!before)
240
271
  return newCompileAttempt(records.filter((one) => one.digest !== digest));
241
272
  if (before.decided !== "hold")
242
273
  return 1;
243
- return before.audit ? (before.audit.stopped ? 1 : 2) : before.check?.attempt === 1 && !before.check.stopped ? 2 : 1;
274
+ if (before.audit)
275
+ return before.audit.stopped ? 1 : 2;
276
+ return !before.check || (before.check.attempt === 1 && !before.check.stopped) ? 2 : 1;
244
277
  }
245
278
  /** The shadow runs a recompile's check runs on beside the agent's last runs: the disagreeing audit rows the workflow's
246
279
  * newest audit hold names (a grade's row has no answer of the agent's to check against), when that hold is the
@@ -291,6 +324,11 @@ async function checkInputs(deps, workflow, pick, audited = []) {
291
324
  * it fits), it is decided at once: never promoted, it stops with nothing checked (stopUnchecked). */
292
325
  async function startCheck(deps, workflow, digest) {
293
326
  const { store, agentId, log } = deps;
327
+ // Its replay runs are runs the runner starts, on no caller's key: skipped where the claimed run brought its own key or
328
+ // the server holds none (claimSpendOff).
329
+ const off = deps.spendOff?.("A learned workflow's replay check");
330
+ if (off)
331
+ return void log(`workflow-first: ${off} ${workflow.name} at ${digest} is not checked and does not serve this run`);
294
332
  // Only the learning folder's newest revision is checked: a run pinned to an older commit lays an older text.
295
333
  const newest = deps.newest ? await deps.newest(workflow.name) : undefined;
296
334
  if (newest !== undefined && newest !== digest) {
@@ -508,7 +546,7 @@ function replayLaunchOf(deps) {
508
546
  ...(launch.learning ? { learning: launch.learning } : {}),
509
547
  ...(launch.archilDisk ? { archilDisk: launch.archilDisk } : {}),
510
548
  };
511
- return { revision: deps.revisionId, body: launchBody(base), ...(deps.sealKey && deps.runId ? { handed_from: deps.runId } : {}) };
549
+ return { revision: deps.revisionId, body: launchBody(base), ...((deps.sealKey || held()) && deps.runId ? { handed_from: deps.runId } : {}) };
512
550
  }
513
551
  /** Whether `was`, a digest's newest record now, is still the replay `record` reserved: replaying, under the same replay
514
552
  * id. A replay settled meanwhile, and a newer replay of the same revision its owner started since (a held revision may
@@ -543,8 +581,11 @@ async function cancelUnended(deps, record) {
543
581
  * logged. */
544
582
  async function handedTo(deps, launch, id) {
545
583
  const from = launch.handed_from;
546
- if (!deps.sealKey || !from)
584
+ if (!from)
547
585
  return undefined;
586
+ // A run's own process holds no seal key: its runner seals them again, from its own run alone (held.ts handOn).
587
+ if (!deps.sealKey)
588
+ return held()?.handOn(from, id);
548
589
  const sealed = await deps.store.runs.launch(from).then((one) => one.sealed ?? null, () => null);
549
590
  const handed = sealed === null ? undefined : openRunMcpAuth(deps.sealKey, from, sealed);
550
591
  return handed && Object.keys(handed).length ? sealRunMcpAuth(deps.sealKey, id, handed) : undefined;
@@ -578,6 +619,8 @@ async function startReplay(deps, workflow, digest, of, from, id, launch) {
578
619
  * this claim created. */
579
620
  async function relaunch(deps, workflow, digest, record) {
580
621
  const { store } = deps;
622
+ if (deps.spendOff?.("A replay"))
623
+ return 0;
581
624
  const since = (deps.now ?? Date.now)() - Date.parse(record.at);
582
625
  const launch = record.launch;
583
626
  if (!launch || since <= REPLAY_LAUNCH_GRACE_MS || since > REPLAY_DEADLINE_MS)
@@ -721,8 +764,8 @@ export async function askReplay(ask, name, digest, inputs) {
721
764
  if (!picked.length)
722
765
  throw new ReplayRefused("conflict", `${name} at ${digest} has no input to replay on: none of ${typeof inputs === "number" ? `the agent's newest ${plural(inputs, "completed run")}` : last ? "the runs it was last checked on" : "the agent's last completed runs"} has an input it fits. Nothing was started.`);
723
766
  const { launch, revisionId } = await ask.launchOf(picked[0].launch.input);
724
- if (!launch.learning || launch.learning.notesOnly)
725
- throw new ReplayRefused("conflict", `A replay runs ${name} as a run of the agent that learns does, and the agent's runs do not take learned workflows here (its learning is off, notes only, or this server's is off).`);
767
+ if (!launch.learning || launch.learning.noWorkflows)
768
+ throw new ReplayRefused("conflict", `A replay runs ${name} as a run of the agent that learns does, and the agent's runs do not take learned workflows here (its learning is off, it takes no workflows, or this server's is off).`);
726
769
  const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, ...(ask.now ? { now: ask.now } : {}) };
727
770
  const bar = { compile_after: loop.compile_after, agree_min: loop.agree_min, alone_min: loop.alone_min, attempt: attemptOf(records, name, digest) };
728
771
  const said = `checking it on ${plural(picked.length, "input")} of the agent's own runs, as its owner asked`;
@@ -779,15 +822,18 @@ export async function replayView(ask, name, digest, id) {
779
822
  }
780
823
  return checkView(ask, record, id, name, digest);
781
824
  }
782
- /** A replay run's call nodes (launch.replay; learn/replay-calls.ts): the agent run's recorded calls, read from its journal
783
- * (a CLI's record shaped as pi's), and each tool classed by the claim's MCP pin (`runId`'s, its servers' annotations as
784
- * they listed them) or the built-in list. Undefined for any other run. A recording that cannot be read is an empty one:
785
- * every write is then skipped, never run. */
786
- export async function replayCallsFor(store, runId, launch, context) {
825
+ /** A replay run's recording (launch.replay; learn/replay-calls.ts): the agent run's recorded calls, read from its journal
826
+ * (a CLI's record shaped as pi's; another run's, which only a runner reads: learned-first.ts). Undefined for any other
827
+ * run. A recording that cannot be read is an empty one: every write is then skipped, never run. */
828
+ export async function replayRecordedFor(store, launch, context) {
787
829
  if (!launch.replay)
788
830
  return undefined;
789
831
  const entries = await runEntries(store, launch.replay.of, context).catch(() => []);
790
- const recorded = recordedCalls(isCliRecord(entries) ? piShaped(entries) : entries);
832
+ return recordedCalls(isCliRecord(entries) ? piShaped(entries) : entries);
833
+ }
834
+ /** The replay's call nodes over `recorded`, each tool classed by run `runId`'s own MCP pin (its servers' annotations as
835
+ * they listed them) or the built-in list. */
836
+ export async function replayCallsOver(store, runId, recorded) {
791
837
  const pin = (await store.mcp.pin(runId).catch(() => undefined))?.body;
792
838
  const annotations = pinAnnotations(pin);
793
839
  return replayCalls(recorded, (tool) => toolClassOf(tool, annotations));
@@ -1,56 +1,38 @@
1
- import { type CompileAsk } from "../learn/compile.js";
1
+ import { type Problem } from "../learn/index.js";
2
+ import { type CompileAsk, type DraftChecked } from "../learn/compile.js";
2
3
  import type { EndOfRunTurn } from "./loop-contract.js";
3
- /** How long a run's end-of-run turn may take before it is aborted and the run ends without it. */
4
- export declare const REFLECT_TIMEOUT_MS: number;
5
4
  /** A turn the spend cap refused (the cap's refusal words, cap.ts CAP_REFUSAL_PREFIX). */
6
5
  export declare const CAP_REFUSAL: RegExp;
7
- /** What a run's turn answered, and what the person and a trigger said in the run (learning.ts Turn). */
8
- export interface ReflectTurn {
9
- readonly answer: string;
10
- readonly asked: readonly string[];
11
- readonly triggered?: readonly {
12
- readonly source: string;
6
+ /** A draft the checks passed, as it is committed: its files whole, the README held for its owner's OK when it calls an
7
+ * unpriced tool (`held`), and the commit a revision was read at (`bases`, its conflict base). */
8
+ export type DraftCommit = {
9
+ readonly name: string;
10
+ readonly files: readonly {
11
+ readonly path: string;
13
12
  readonly text: string;
14
13
  }[];
15
- }
16
- /** What the checks made of a turn (propose.ts Proposed), with the proposal they kept. */
17
- export type Checked = {
18
- readonly state: "proposed";
19
- readonly notes: number;
20
- readonly skills: number;
21
- readonly workflows: number;
22
- readonly left?: readonly unknown[];
23
- readonly proposal: unknown;
24
- } | {
25
- readonly state: "dropped";
26
- readonly reason: "empty";
27
- } | {
28
- readonly state: "dropped";
29
- readonly reason: "unparsed";
30
- readonly detail: string;
14
+ readonly held?: readonly string[];
15
+ readonly bases?: Readonly<Record<string, string>>;
16
+ };
17
+ /** What a merge landed: the commit (and the correction it left out beside its draft, learn/commit.ts
18
+ * LearningCommitResult `refusedCorrection`), or why it did not. */
19
+ export type Committed = {
20
+ readonly ok: true;
21
+ readonly commit: string;
22
+ readonly refusedCorrection?: readonly Problem[];
31
23
  } | {
32
- readonly state: "dropped";
33
- readonly reason: "checker";
34
- readonly problems: readonly {
35
- readonly rule: string;
36
- readonly path?: string;
37
- }[];
24
+ readonly ok: false;
25
+ readonly reason: "conflict" | "refused" | "unavailable";
26
+ readonly problems: readonly Problem[];
38
27
  };
39
- /** What the hook reads of the run and the host. */
28
+ /** What the step reads of the run and the host. */
40
29
  export interface ReflectDeps {
41
- /** Whether the run's job gave nothing new to look back on: its only tool work was its learned workflows, each of them
42
- * answering, with no error, no refused call, no approval and nothing said after its first message. Such a run is not
43
- * asked its end-of-run turn (no model request, nothing spent looking back), and its learning is dropped `empty` in
44
- * said.onlyWorkflow's words. Absent, or a read that throws: every run is asked. */
30
+ /** Whether the run's job gave nothing new to learn from: its only tool work was its learned workflows, each answering,
31
+ * with nothing said after its first message. Such a run compiles nothing unless a compile is due, and its learning is
32
+ * dropped `empty` in said.onlyWorkflow's words. Absent, or a read that throws: none. */
45
33
  readonly nothingNew?: (runId: string) => Promise<boolean>;
46
- /** For a job that compiles workflows: whether the run carries its owner's feedback (learning-end.ts ownerSaid: a grade's
47
- * words, or a message after its first). A run without it is not asked its look-back (no model request, $0 looking
48
- * back), and its compile turn, when one is due, is asked alone; with nothing due its learning is dropped `empty` in
49
- * said.noFeedback's words. Absent (a notes job), or a read that throws: the run is asked its look-back. */
50
- readonly ownerSaid?: (runId: string) => Promise<boolean>;
51
- /** The run's facts for reflectSkip: whether it learns, a person's cancel, its cap reached, its cap, its cost so far as a
52
- * person is shown it (`costUsd`, kept as the job's), and under a cap its spend as the cap's gates read it (`spentUsd`,
53
- * learning-end.ts capSpendOf: a request with no price of its own at its held figure; null: unknown). */
34
+ /** The run's facts: whether it learns, a person's cancel, its cap reached, its cap, its cost so far as a person is shown
35
+ * it (`costUsd`, kept as the job's), and under a cap its spend as the cap's gates read it (`spentUsd`; null: unknown). */
54
36
  readonly facts: (runId: string) => Promise<{
55
37
  learns: boolean;
56
38
  cancelled?: boolean;
@@ -62,18 +44,25 @@ export interface ReflectDeps {
62
44
  capUsd: number;
63
45
  spentUsd: number | null;
64
46
  })>;
65
- /** The prompt's facts: how many notes the run started from. */
66
- readonly promptFacts: (runId: string, agentId: string) => Promise<{
67
- active: number;
68
- }>;
69
- /** The compile turn's facts (learn/compile.ts CompileAsk), read once the look-back's answer is checked, `refuse` cut
70
- * from what they quote: undefined when the run compiles nothing (its job not due, a notes-only agent, a workflow
71
- * that answered). Absent, or a read that throws: no compile turn. */
47
+ /** What the run's owner said of it: a grade's words, and each message they sent after its first, in order. */
48
+ readonly feedback: (runId: string) => Promise<readonly string[]>;
49
+ /** Why the owner's words would be refused as a line of corrections.md on main now (learn/commit.ts correctionRefused);
50
+ * empty when they would be taken. */
51
+ readonly correctionRefused: (input: {
52
+ runId: string;
53
+ agentId: string;
54
+ round: number;
55
+ text: string;
56
+ refuse: readonly string[];
57
+ }) => Promise<readonly Problem[]>;
58
+ /** The compile turn's facts (learn/compile.ts CompileAsk), `refuse` cut from what they quote: undefined when the run
59
+ * compiles nothing (its job not due, a workflow that answered). Absent, or a read that throws: no compile turn. */
72
60
  readonly compileFacts?: (input: {
73
61
  runId: string;
74
62
  agentId: string;
75
63
  outcome: "completed" | "failed";
76
64
  refuse: readonly string[];
65
+ round: number;
77
66
  }) => Promise<CompileAsk | undefined>;
78
67
  /** Compile once: a compile turn whose drafts all failed their checks (one answered, none passed) is the compile's
79
68
  * attempt, kept on a promotion record (learning-end.ts recordDraftFailed) that compileFacts reads. Its `workflow` and
@@ -87,55 +76,39 @@ export interface ReflectDeps {
87
76
  }) => Promise<void>;
88
77
  /** The compile turn's deadline, every attempt in it. Default learn/compile.ts COMPILE_TIMEOUT_MS. */
89
78
  readonly compileDeadlineMs?: number;
90
- /** What the person said in the run, and a trigger's input, as the checks and the grader read them. */
91
- readonly asked: (runId: string) => Promise<{
92
- asked: readonly string[];
93
- triggered?: ReflectTurn["triggered"];
94
- }>;
95
- /** Every value the run must never learn (learning-run.ts refused): the host's secrets and what the run was handed, its
96
- * sign-in pointer among them; `unreadable` when what it was handed can't be read back, and the run learns nothing.
97
- * Absent, none. */
98
- readonly refuse?: (runId: string) => Promise<readonly string[] | "unreadable">;
99
- /** proposeRun's checks over the turn, against the seed the run started from, refusing `refuse`. `revised`: in the
100
- * compile turn's checks, the workflow it revises from main's text and the commit of main it was first asked at (its
101
- * CompileAsk's `base`, as the turn's first ask kept it), that workflow's conflict base. */
102
- readonly check: (input: {
79
+ /** One compile draft through the checks (learning-end.ts checkDraftOf): its errors, else what is committed and its
80
+ * digest. `revised`: a revision's workflow and the commit of main it was read at, its conflict base. */
81
+ readonly checkDraft: (input: {
103
82
  runId: string;
104
83
  agentId: string;
105
- turn: ReflectTurn;
106
- outcome: "completed" | "failed";
84
+ draft: {
85
+ name: string;
86
+ text: string;
87
+ };
107
88
  refuse: readonly string[];
108
89
  revised?: {
109
90
  readonly workflow: string;
110
91
  readonly base: string;
111
92
  };
112
- }) => Promise<Checked>;
113
- /** A new run's id, for the learning run. */
114
- readonly newRunId: () => string;
115
- /** The grade model the server names (learning.ts gradeModelOf: --grade-model, AGENTRUN_SERVE_GRADE_MODEL, else
116
- * AGENT_MODEL_STRONG), carried on the learning run's launch; none, the agent's own model grades it, as main's. */
117
- readonly gradeModel?: string;
118
- /** The turn's deadline. Default REFLECT_TIMEOUT_MS. Its re-ask is inside it. */
119
- readonly deadlineMs?: number;
120
- /** For tests: the clock the turn's deadline is measured by. Default Date.now. */
93
+ }) => Promise<DraftChecked<DraftCommit>>;
94
+ /** The round's merge on the agent's learning folder (learning-end.ts commitDirect): its draft and its owner's
95
+ * correction, one commit by the run. */
96
+ readonly commit: (input: {
97
+ runId: string;
98
+ agentId: string;
99
+ round: number;
100
+ draft?: DraftCommit;
101
+ correction?: string;
102
+ refuse: readonly string[];
103
+ }) => Promise<Committed>;
104
+ /** Every value the run must never learn: the host's secrets and what the run was handed, its sign-in pointer among
105
+ * them; `unreadable` when what it was handed can't be read back, and the run learns nothing. Absent, none. */
106
+ readonly refuse?: (runId: string) => Promise<readonly string[] | "unreadable">;
107
+ /** For tests: the clock. Default Date.now. */
121
108
  readonly now?: () => number;
122
- /** The cap the learning run's grade runs under, read once the turn closed (learning-end.ts gradeCapOf): what the run's
123
- * cap leaves once everything the run spent is counted, carried on the learning run's launch as its own cap, so the
124
- * grade never takes the run past its cap. Null when what the run spent under its cap is unknown: the grade is not
125
- * run, said so (said.gradeUnknownSpend). Undefined for an uncapped run: its grade is capped by nothing. */
126
- readonly gradeCap?: (runId: string) => Promise<number | null | undefined>;
127
109
  /** Which end of the run this is: 1, its first (the default); an end after a follow-up opened the run again is the next
128
- * round, asked anew (its prompt says it looked back before), kept as a proposal of its own beside the earlier rounds'
129
- * (every row the hook gives carries it), graded and merged by a learning run of its own. */
110
+ * round, kept beside the earlier rounds' (every row the step gives carries it), with a merge of its own. */
130
111
  readonly round?: number;
131
- /** A later round's: what the round before it kept of the run's spend (its job's and its look-back's), so the follow-up's
132
- * own share, between that look-back and this one, is kept apart (`follow_up_usd`); and whether it was asked its turn
133
- * (`looked`: a round cut before it was asked says nothing of looking back before). */
134
- readonly before?: {
135
- readonly job_cost_usd?: number | null;
136
- readonly look_back_usd?: number | null;
137
- readonly looked?: boolean;
138
- };
139
112
  }
140
- /** The end-of-run turn for runs that learn. */
113
+ /** The end-of-run step for runs that learn. */
141
114
  export declare function createReflectHook(deps: ReflectDeps): EndOfRunTurn;