@parcha/agentrun-serve 0.1.0-beta.37 → 0.1.0-beta.38

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 (399) hide show
  1. package/CHANGELOG.md +282 -0
  2. package/README.md +155 -92
  3. package/dist/agent-rows.d.ts +1 -1
  4. package/dist/agents-store.d.ts +35 -3
  5. package/dist/agents-store.js +39 -14
  6. package/dist/answer-json.d.ts +34 -1
  7. package/dist/answer-json.js +91 -9
  8. package/dist/api-only.d.ts +1 -1
  9. package/dist/api-only.js +2 -2
  10. package/dist/browser-cost.js +52 -93
  11. package/dist/cap.d.ts +0 -390
  12. package/dist/cap.js +4 -937
  13. package/dist/catalog.js +1 -1
  14. package/dist/composio-preset.d.ts +17 -0
  15. package/dist/composio-preset.js +43 -1
  16. package/dist/computer-calls.d.ts +36 -24
  17. package/dist/computer-calls.js +110 -27
  18. package/dist/computer-live.d.ts +5 -0
  19. package/dist/computer-live.js +12 -0
  20. package/dist/computer-setting.d.ts +15 -2
  21. package/dist/computer-setting.js +20 -4
  22. package/dist/computer-view.d.ts +3 -2
  23. package/dist/computer-view.js +5 -4
  24. package/dist/computer-viewer.js +26 -12
  25. package/dist/computers.d.ts +4 -1
  26. package/dist/computers.js +12 -6
  27. package/dist/console/assets/index-CjqQirbo.css +1 -0
  28. package/dist/console/assets/index-b6-XY5A9.js +576 -0
  29. package/dist/console/index.html +2 -2
  30. package/dist/console-links.d.ts +2 -0
  31. package/dist/console-links.js +3 -0
  32. package/dist/decisions.js +4 -0
  33. package/dist/faux-computers.js +4 -2
  34. package/dist/harness-opencode/adapter.js +7 -3
  35. package/dist/harness-opencode/facts.js +0 -2
  36. package/dist/harness-opencode/host/policy.d.ts +2 -5
  37. package/dist/harness-opencode/host/policy.js +8 -32
  38. package/dist/harness-table.d.ts +0 -2
  39. package/dist/harness-table.js +0 -2
  40. package/dist/host-tools.d.ts +1 -5
  41. package/dist/host-tools.js +7 -10
  42. package/dist/hosted-search.d.ts +0 -2
  43. package/dist/hosted-search.js +0 -21
  44. package/dist/key-words.d.ts +3 -2
  45. package/dist/key-words.js +4 -2
  46. package/dist/learn/check.d.ts +6 -1
  47. package/dist/learn/check.js +12 -4
  48. package/dist/learn/commit.d.ts +10 -0
  49. package/dist/learn/commit.js +18 -4
  50. package/dist/learn/compile.d.ts +243 -0
  51. package/dist/learn/compile.js +471 -0
  52. package/dist/learn/general.d.ts +3 -0
  53. package/dist/learn/general.js +4 -2
  54. package/dist/learn/grade.d.ts +1 -1
  55. package/dist/learn/grade.js +7 -6
  56. package/dist/learn/notes.d.ts +8 -0
  57. package/dist/learn/notes.js +18 -0
  58. package/dist/learn/promote.d.ts +253 -0
  59. package/dist/learn/promote.js +428 -0
  60. package/dist/learn/refit.d.ts +39 -0
  61. package/dist/learn/refit.js +236 -0
  62. package/dist/learn/reflect.d.ts +5 -25
  63. package/dist/learn/reflect.js +14 -131
  64. package/dist/learn/replay-calls.d.ts +63 -0
  65. package/dist/learn/replay-calls.js +158 -0
  66. package/dist/learn/skills.d.ts +17 -9
  67. package/dist/learn/skills.js +132 -42
  68. package/dist/learn/workflow-nodes.d.ts +15 -0
  69. package/dist/learn/workflow-nodes.js +44 -0
  70. package/dist/learned-nodes.d.ts +50 -2
  71. package/dist/learned-nodes.js +41 -2
  72. package/dist/learned-workflow.d.ts +19 -3
  73. package/dist/learned-workflow.js +105 -26
  74. package/dist/learning-batch.d.ts +2 -2
  75. package/dist/learning-batch.js +1 -1
  76. package/dist/learning-cost.d.ts +18 -6
  77. package/dist/learning-cost.js +15 -7
  78. package/dist/learning-routes.d.ts +14 -2
  79. package/dist/learning-routes.js +14 -3
  80. package/dist/learning-words.d.ts +7 -0
  81. package/dist/learning-words.js +7 -0
  82. package/dist/learning.d.ts +31 -6
  83. package/dist/learning.js +7 -4
  84. package/dist/llm.js +0 -3
  85. package/dist/mcp-gateway.d.ts +12 -20
  86. package/dist/mcp-gateway.js +16 -44
  87. package/dist/mcp-oauth.d.ts +5 -0
  88. package/dist/mcp-oauth.js +1 -1
  89. package/dist/mcp-pin-first.d.ts +37 -0
  90. package/dist/mcp-pin-first.js +107 -0
  91. package/dist/mcp-probe.d.ts +8 -9
  92. package/dist/mcp-probe.js +16 -33
  93. package/dist/mcp-servers-store.d.ts +89 -22
  94. package/dist/mcp-servers-store.js +131 -25
  95. package/dist/mcp-sources.d.ts +39 -0
  96. package/dist/mcp-sources.js +74 -0
  97. package/dist/mcp-store.d.ts +11 -0
  98. package/dist/mcp-store.js +16 -2
  99. package/dist/mcp-wire.d.ts +22 -0
  100. package/dist/mcp-wire.js +36 -0
  101. package/dist/mcp.js +3 -3
  102. package/dist/meta-tool-names.d.ts +1 -0
  103. package/dist/meta-tool-names.js +3 -0
  104. package/dist/model.d.ts +13 -0
  105. package/dist/model.js +46 -15
  106. package/dist/monid.d.ts +51 -25
  107. package/dist/monid.js +226 -140
  108. package/dist/openapi.js +336 -66
  109. package/dist/paid-calls.d.ts +26 -29
  110. package/dist/paid-calls.js +46 -102
  111. package/dist/propose.d.ts +7 -1
  112. package/dist/propose.js +18 -6
  113. package/dist/provider.js +9 -2
  114. package/dist/reflect-range.js +2 -1
  115. package/dist/rows.d.ts +5 -3
  116. package/dist/rows.js +15 -4
  117. package/dist/run-launch.d.ts +13 -0
  118. package/dist/run-launch.js +6 -0
  119. package/dist/run-learning-served.d.ts +13 -2
  120. package/dist/run-manifest.d.ts +5 -0
  121. package/dist/run-manifest.js +20 -0
  122. package/dist/run-secrets.js +2 -3
  123. package/dist/run-timeline-served.js +5 -2
  124. package/dist/run-view.d.ts +17 -6
  125. package/dist/run-view.js +51 -22
  126. package/dist/runnable.d.ts +0 -3
  127. package/dist/runnable.js +37 -29
  128. package/dist/runner/adapter-loop.d.ts +24 -10
  129. package/dist/runner/adapter-loop.js +852 -314
  130. package/dist/runner/adapter-run-spec.d.ts +12 -6
  131. package/dist/runner/adapter-run-spec.js +97 -46
  132. package/dist/runner/adapters/pi-computer.d.ts +3 -1
  133. package/dist/runner/adapters/pi-computer.js +13 -5
  134. package/dist/runner/adapters/pi.d.ts +16 -7
  135. package/dist/runner/adapters/pi.js +94 -33
  136. package/dist/runner/cli-run-spec.js +67 -27
  137. package/dist/runner/computer-channel.js +2 -1
  138. package/dist/runner/conformance/harness.d.ts +3 -0
  139. package/dist/runner/conformance/harness.js +145 -4
  140. package/dist/runner/conformance/subject.d.ts +11 -4
  141. package/dist/runner/end-of-run.d.ts +6 -5
  142. package/dist/runner/end-of-run.js +9 -6
  143. package/dist/runner/feedback-round.d.ts +52 -0
  144. package/dist/runner/feedback-round.js +79 -0
  145. package/dist/runner/journal-kinds.d.ts +24 -6
  146. package/dist/runner/journal-kinds.js +15 -0
  147. package/dist/runner/learning-end.d.ts +54 -19
  148. package/dist/runner/learning-end.js +272 -99
  149. package/dist/runner/learning-loop.d.ts +19 -1
  150. package/dist/runner/learning-loop.js +5 -2
  151. package/dist/runner/learning-seed.d.ts +4 -0
  152. package/dist/runner/learning-seed.js +14 -0
  153. package/dist/runner/loop-contract.d.ts +19 -3
  154. package/dist/runner/loop.d.ts +16 -1
  155. package/dist/runner/loop.js +21 -1
  156. package/dist/runner/mcp-claim.d.ts +5 -1
  157. package/dist/runner/mcp-claim.js +66 -50
  158. package/dist/runner/mcp-run.d.ts +16 -52
  159. package/dist/runner/mcp-run.js +12 -84
  160. package/dist/runner/meta-tools.d.ts +37 -0
  161. package/dist/runner/meta-tools.js +268 -0
  162. package/dist/runner/metrics.js +14 -3
  163. package/dist/runner/model-route.js +12 -3
  164. package/dist/runner/monid-run.d.ts +16 -0
  165. package/dist/runner/monid-run.js +96 -0
  166. package/dist/runner/promotion.d.ts +80 -0
  167. package/dist/runner/promotion.js +562 -0
  168. package/dist/runner/reflect-hook.d.ts +36 -21
  169. package/dist/runner/reflect-hook.js +138 -49
  170. package/dist/runner/runner.js +26 -4
  171. package/dist/runner/sessions.d.ts +8 -3
  172. package/dist/runner/sessions.js +5 -1
  173. package/dist/runner/step-guard.d.ts +62 -0
  174. package/dist/runner/step-guard.js +93 -0
  175. package/dist/runner/subagent.d.ts +0 -3
  176. package/dist/runner/subagent.js +7 -12
  177. package/dist/runner/workflow-first.d.ts +216 -0
  178. package/dist/runner/workflow-first.js +303 -0
  179. package/dist/runner/workflow-loop.js +17 -10
  180. package/dist/runner/workflow-spec.d.ts +1 -0
  181. package/dist/runner/workflow-spec.js +7 -3
  182. package/dist/runs-over-store.d.ts +11 -2
  183. package/dist/runs-over-store.js +21 -11
  184. package/dist/server.d.ts +88 -16
  185. package/dist/server.js +380 -87
  186. package/dist/settings-wake.d.ts +8 -6
  187. package/dist/settings-wake.js +13 -7
  188. package/dist/store/agent-body.d.ts +14 -3
  189. package/dist/store/agent-body.js +14 -10
  190. package/dist/store/command-wake.d.ts +3 -2
  191. package/dist/store/command-wake.js +4 -4
  192. package/dist/store/postgres/connection.js +3 -1
  193. package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
  194. package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
  195. package/dist/store/schema.d.ts +9 -0
  196. package/dist/store/schema.js +28 -8
  197. package/dist/store/sqlite/connection.d.ts +2 -2
  198. package/dist/store/sqlite/connection.js +2 -2
  199. package/dist/store/sqlite/run-patch.js +19 -7
  200. package/dist/store/sqlite/store.js +59 -18
  201. package/dist/store/store.d.ts +46 -14
  202. package/dist/store-reads/journal.d.ts +25 -1
  203. package/dist/store-reads/journal.js +63 -49
  204. package/dist/store-reads/learning.d.ts +101 -15
  205. package/dist/store-reads/learning.js +195 -61
  206. package/dist/store-reads/loop.d.ts +61 -0
  207. package/dist/store-reads/loop.js +111 -0
  208. package/dist/store-view.d.ts +3 -2
  209. package/dist/store-view.js +35 -17
  210. package/dist/template-eval.d.ts +18 -9
  211. package/dist/template-eval.js +91 -66
  212. package/dist/template-github-permissions.d.ts +2 -2
  213. package/dist/template-github-permissions.js +2 -1
  214. package/dist/template-import.d.ts +31 -0
  215. package/dist/template-import.js +121 -0
  216. package/dist/template-source.d.ts +51 -0
  217. package/dist/template-source.js +371 -0
  218. package/dist/templates.d.ts +218 -46
  219. package/dist/templates.js +493 -181
  220. package/dist/timeline/computer.d.ts +48 -0
  221. package/dist/timeline/computer.js +169 -0
  222. package/dist/timeline/index.d.ts +4 -3
  223. package/dist/timeline/index.js +4 -3
  224. package/dist/timeline/labels.d.ts +6 -2
  225. package/dist/timeline/labels.js +93 -2
  226. package/dist/timeline/origin.d.ts +19 -5
  227. package/dist/timeline/origin.js +11 -4
  228. package/dist/timeline/timeline.d.ts +11 -17
  229. package/dist/timeline/timeline.js +24 -9
  230. package/dist/tool-gate.d.ts +73 -46
  231. package/dist/tool-gate.js +133 -66
  232. package/dist/tool-keys.d.ts +4 -1
  233. package/dist/tool-keys.js +8 -3
  234. package/dist/tool-list.d.ts +26 -0
  235. package/dist/tool-list.js +43 -0
  236. package/dist/tool-names.d.ts +71 -0
  237. package/dist/tool-names.js +99 -0
  238. package/dist/tool-plane.d.ts +29 -27
  239. package/dist/tool-plane.js +65 -37
  240. package/dist/tools.d.ts +22 -6
  241. package/dist/tools.js +24 -20
  242. package/dist/validate.d.ts +15 -7
  243. package/dist/validate.js +91 -44
  244. package/dist/web-fetch.d.ts +1 -7
  245. package/dist/web-fetch.js +2 -22
  246. package/dist/workspace/computer-deps.d.ts +3 -0
  247. package/dist/workspace/computer-deps.js +5 -2
  248. package/dist/workspace/computer-for-claim.d.ts +6 -0
  249. package/dist/workspace/computer-for-claim.js +32 -14
  250. package/dist/workspace/computer-hold.js +7 -1
  251. package/dist/workspace/computer-script.d.ts +23 -7
  252. package/dist/workspace/computer-script.js +48 -14
  253. package/dist/workspace/index.d.ts +2 -2
  254. package/dist/workspace/index.js +1 -1
  255. package/dist/workspace/kind-skills/desktop/SKILL.md +13 -0
  256. package/dist/workspace/kind-skills/phone/SKILL.md +4 -0
  257. package/dist/workspace/local.js +2 -2
  258. package/dist/workspace/resolve-computer.d.ts +21 -1
  259. package/dist/workspace/resolve-computer.js +32 -14
  260. package/dist/workspace/run-tools.d.ts +28 -10
  261. package/dist/workspace/run-tools.js +39 -11
  262. package/dist/{tool-budget.d.ts → wrap-up.d.ts} +1 -18
  263. package/dist/wrap-up.js +21 -0
  264. package/launcher/agentrun-serve +4 -2
  265. package/package.json +9 -9
  266. package/templates/README.md +111 -45
  267. package/templates/code-review/agent.md +30 -14
  268. package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
  269. package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
  270. package/templates/code-review/evals/injection/case.yaml +2 -1
  271. package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
  272. package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
  273. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
  274. package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
  275. package/templates/code-review/evals/never-flag/case.yaml +2 -1
  276. package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
  277. package/templates/code-review/evals/null-name/case.yaml +2 -1
  278. package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
  279. package/templates/code-review/evals/off-by-one/case.yaml +2 -1
  280. package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
  281. package/templates/code-review/evals/other-repo/case.yaml +16 -0
  282. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
  283. package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
  284. package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
  285. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
  286. package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
  287. package/templates/code-review/evals/other-repo/prompt.md +10 -0
  288. package/templates/code-review/evals/re-review/case.yaml +2 -1
  289. package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
  290. package/templates/code-review/evals/re-review-open/case.yaml +2 -1
  291. package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
  292. package/templates/code-review/evals/repo-rule/case.yaml +2 -1
  293. package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
  294. package/templates/code-review/evals/two-defects/case.yaml +2 -1
  295. package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
  296. package/templates/code-review/rules/CODEREVIEW.md +1 -1
  297. package/templates/code-review/skills/review/DEEP.md +3 -2
  298. package/templates/code-review/skills/review/REVIEWER.md +3 -2
  299. package/templates/code-review/skills/review/SKILL.md +4 -3
  300. package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
  301. package/templates/inbound-lead/agent.md +26 -16
  302. package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
  303. package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
  304. package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
  305. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
  306. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
  307. package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
  308. package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
  309. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
  310. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
  311. package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
  312. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
  313. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
  314. package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
  315. package/templates/kyb/agent.md +15 -5
  316. package/templates/kyb/evals/adverse-media/prompt.md +2 -7
  317. package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
  318. package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
  319. package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
  320. package/templates/kyb/evals/name-collision/prompt.md +2 -6
  321. package/templates/kyb/evals/no-invention/prompt.md +2 -6
  322. package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
  323. package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
  324. package/templates/kyb/kyb.schema.json +8 -7
  325. package/templates/kyb/skills/kyb/SKILL.md +9 -6
  326. package/templates/market-monitor/agent.md +19 -12
  327. package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
  328. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
  329. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
  330. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
  331. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  332. package/templates/release-notes/agent.md +32 -10
  333. package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
  334. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
  335. package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
  336. package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
  337. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
  338. package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
  339. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
  340. package/templates/release-notes/evals/learned-style/case.yaml +2 -1
  341. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
  342. package/templates/release-notes/evals/other-repo/case.yaml +24 -0
  343. package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
  344. package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
  345. package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
  346. package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
  347. package/templates/release-notes/evals/other-repo/prompt.md +32 -0
  348. package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
  349. package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
  350. package/templates/release-notes/notes.schema.json +1 -1
  351. package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
  352. package/dist/console/assets/index-Cn6JX1uH.js +0 -563
  353. package/dist/console/assets/index-DRN62V5v.css +0 -1
  354. package/dist/tool-blurbs.d.ts +0 -4
  355. package/dist/tool-blurbs.js +0 -28
  356. package/dist/tool-budget.js +0 -62
  357. package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
  358. package/templates/code-review/evals/injection/graders/schema.md +0 -5
  359. package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
  360. package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
  361. package/templates/code-review/evals/null-name/graders/schema.md +0 -5
  362. package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
  363. package/templates/code-review/evals/re-review/graders/schema.md +0 -5
  364. package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
  365. package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
  366. package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
  367. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
  368. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
  369. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
  370. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
  371. package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
  372. package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
  373. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
  374. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
  375. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
  376. package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
  377. package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
  378. package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
  379. package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
  380. package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
  381. package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
  382. package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
  383. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
  384. package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
  385. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
  386. package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
  387. package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
  388. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
  389. package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
  390. package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
  391. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
  392. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
  393. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
  394. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
  395. package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
  396. package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
  397. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
  398. package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
  399. package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
@@ -113,10 +113,9 @@ function revisionInputOf(definition, files) {
113
113
  ...(isObject(definition.model_tiers) ? { modelTiers: definition.model_tiers } : {}),
114
114
  ...(typeof definition.thinking === "string" ? { thinking: definition.thinking } : {}),
115
115
  ...(definition.approvals === "ask" || definition.approvals === "never" ? { approvals: definition.approvals } : {}),
116
+ ...(isObject(definition.input_schema) ? { inputSchema: definition.input_schema } : {}),
116
117
  ...(isObject(definition.output_schema) ? { outputSchema: definition.output_schema } : {}),
117
118
  ...(definition.checkout === "pull_request" ? { checkout: "pull_request" } : {}),
118
- // The tool-call budget (tool-budget.ts): 0 keeps none.
119
- ...(typeof definition.max_tool_calls === "number" && definition.max_tool_calls > 0 ? { maxToolCalls: definition.max_tool_calls } : {}),
120
119
  ...common,
121
120
  ...learning,
122
121
  ...capped,
@@ -141,10 +140,14 @@ function checkPast(definition, current) {
141
140
  }
142
141
  }
143
142
  /** Whether committing `next` would leave the agent's current revision unchanged: the same kind and body (skills are in the
144
- * body as their SHA-256, so equal files are an equal body — and equal pins an equal body, keys sorted by the validator). */
143
+ * body as their SHA-256, so equal files are an equal body — and equal pins an equal body, keys sorted by the validator),
144
+ * and the same MCP pin: a save after a server changed a granted tool is a new revision, pinned anew (that is how a person
145
+ * takes a server's changed tools). */
145
146
  function sameRevision(current, next) {
146
- return current.kind === next.kind && canonical(current.body) === canonical(next.body);
147
+ return current.kind === next.kind && canonical(current.body) === canonical(next.body) && canonical(current.mcpPin ?? null) === canonical(next.mcpPin ?? null);
147
148
  }
149
+ /** `revision` with what its check stamped. */
150
+ const stamped = (revision, stamp) => (stamp?.mcpPin === undefined ? revision : { ...revision, mcpPin: stamp.mcpPin });
148
151
  /** The byte size of each of the revision's skill files, by the SHA-256 the body keeps (from the texts on its row). */
149
152
  function sizesOf(revision) {
150
153
  const sizes = new Map();
@@ -168,7 +171,7 @@ export async function getAgent(store, id) {
168
171
  const revisions = await store.agents.revisions(id); // oldest first (created_at, id)
169
172
  const at = agent.currentRevision === null ? -1 : revisions.findIndex((r) => r.id === agent.currentRevision);
170
173
  const revision = at < 0 ? null : revisions[at];
171
- return { agent, revision, version: at < 0 ? 0 : at + 1, revisions: revisions.length, sizes: sizesOf(revision) };
174
+ return { agent, revision, version: at < 0 ? 0 : at + 1, revisions: revisions.length, sizes: sizesOf(revision), template: revisions[0]?.package ?? null };
172
175
  }
173
176
  /** Every agent here, newest first (its creation, then its id). Archived agents are left out by default. */
174
177
  export async function listAgents(store, options = {}) {
@@ -187,12 +190,14 @@ export async function createAgent(store, { definition, skills = {}, note }, opti
187
190
  if (given !== undefined && (await store.agents.get(given)))
188
191
  throw new ApiError("agent_exists", `an agent ${given} exists here`);
189
192
  // Stamped on the revision now, never resolved at run time: an agent saved with no place keeps running on the runner.
190
- const stamped = options.fresh && definition.place === undefined && definition.computer === undefined && !isObject(definition.workflow)
193
+ const placed = options.fresh && definition.place === undefined && definition.computer === undefined && !isObject(definition.workflow)
191
194
  ? { place: options.fresh.place, ...(definition.tools === undefined ? { tools: [...options.fresh.tools] } : {}) }
192
195
  : {};
193
- const revision = makeRevision({ ...definition, ...stamped }, skills, note);
196
+ // A template's agent keeps the package it was applied from on its first revision (store `revisions.package`).
197
+ const made = makeRevision({ ...definition, ...placed }, skills, note);
198
+ const packaged = options.template ? { ...made, package: options.template } : made;
194
199
  checkVersion(definition, 1);
195
- await options.check?.(revision);
200
+ const revision = stamped(packaged, await options.check?.(packaged, null));
196
201
  const id = given ?? uuidv7();
197
202
  const name = definition.name;
198
203
  try {
@@ -251,8 +256,8 @@ export async function commitAgent(store, read, { definition, skills, note }, { i
251
256
  for (let tries = 1;; tries++) {
252
257
  if (tries > 1)
253
258
  entry = held((await getAgent(store, agent.id)) ?? entry);
254
- const revision = editOn(entry, definition, skills, note);
255
- await check?.(revision);
259
+ const edit = editOn(entry, definition, skills, note);
260
+ const revision = stamped(edit, await check?.(edit, entry.revision));
256
261
  const base = entry.revision?.id ?? null;
257
262
  const now = held((await getAgent(store, agent.id)) ?? entry);
258
263
  if ((now.revision?.id ?? null) === base) {
@@ -299,10 +304,10 @@ function editOn(entry, definition, skills, note) {
299
304
  // No approvals here: an edit that leaves them out asks (openapi.ts DefinitionInput.approvals),
300
305
  // so no edit makes an agent unattended by saying nothing. The console's edit sends back the approvals it read.
301
306
  ...(definition.max_cost_usd === undefined && currentBody.maxCostUsd !== undefined ? { max_cost_usd: currentBody.maxCostUsd } : {}),
302
- // A tool-call budget is a limit too: an edit of an agentic revision that leaves it out keeps it.
303
- ...(definition.max_tool_calls === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.maxToolCalls !== undefined ? { max_tool_calls: currentBody.maxToolCalls } : {}),
304
307
  ...(definition.cap_mode === undefined && currentBody.capMode !== undefined ? { cap_mode: currentBody.capMode } : {}),
305
- // The structured answer's schema is the agent's contract with its callers: an edit that leaves it out keeps it.
308
+ // Its input's and its structured answer's schemas are the agent's contract with its callers: an edit that leaves
309
+ // one out keeps it.
310
+ ...(definition.input_schema === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.inputSchema !== undefined ? { input_schema: currentBody.inputSchema } : {}),
306
311
  ...(definition.output_schema === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.outputSchema !== undefined ? { output_schema: currentBody.outputSchema } : {}),
307
312
  // So is the checkout its runs start in (none clears it).
308
313
  ...(definition.checkout === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.checkout !== undefined ? { checkout: currentBody.checkout } : {}),
@@ -349,7 +354,7 @@ export function definitionOf(agent, revision, version) {
349
354
  ...(body.capMode !== undefined ? { cap_mode: body.capMode } : {}),
350
355
  };
351
356
  const kindBody = revision.kind === "agentic"
352
- ? { instructions: body.instructions, ...(body.model ? { model: body.model } : {}), ...(body.modelTiers ? { model_tiers: body.modelTiers } : {}), ...(body.thinking ? { thinking: body.thinking } : {}), ...(body.learning !== undefined ? { learning: body.learning } : {}), ...(body.outputSchema !== undefined ? { output_schema: body.outputSchema } : {}), ...(body.maxToolCalls !== undefined ? { max_tool_calls: body.maxToolCalls } : {}), ...(body.checkout !== undefined ? { checkout: body.checkout } : {}), ...common }
357
+ ? { instructions: body.instructions, ...(body.model ? { model: body.model } : {}), ...(body.modelTiers ? { model_tiers: body.modelTiers } : {}), ...(body.thinking ? { thinking: body.thinking } : {}), ...(body.learning !== undefined ? { learning: body.learning } : {}), ...(body.inputSchema !== undefined ? { input_schema: body.inputSchema } : {}), ...(body.outputSchema !== undefined ? { output_schema: body.outputSchema } : {}), ...(body.checkout !== undefined ? { checkout: body.checkout } : {}), ...common }
353
358
  : { workflow: body.workflow, ...common };
354
359
  return {
355
360
  id: agent.id,
@@ -381,9 +386,13 @@ export function agentView(entry, origin, extra = {}) {
381
386
  ...(external ? { external } : {}),
382
387
  definition: revision ? definitionOf(agent, revision, entry.version) : null,
383
388
  kind: revision?.kind ?? null,
389
+ mcp_pin: pinView(revision?.mcpPin),
384
390
  revision: revision?.id ?? null,
385
391
  revisions: entry.revisions,
386
392
  source: null,
393
+ // The template package it was applied from (its first revision keeps it): the package's id, version and the commit an
394
+ // imported one was read at (null for a bundled one). Null for an agent made otherwise.
395
+ template: entry.template ? { id: entry.template.id, version: entry.template.version, sha: entry.template.sha ?? null } : null,
387
396
  skills: Object.entries(body.skills ?? {}).map(([path, sha]) => ({ path, sha256: sha, size_bytes: entry.sizes.get(sha) ?? null })),
388
397
  sign_ins: extra.signIns ?? [],
389
398
  runs: extra.runs ?? { count: 0, live: 0 },
@@ -410,5 +419,21 @@ export function revisionView(agent, row) {
410
419
  note: row.note ?? null,
411
420
  created_at: new Date(row.createdAt).toISOString(),
412
421
  definition: definitionOf(agent, row, row.version),
422
+ mcp_pin: pinView(row.mcpPin),
413
423
  };
414
424
  }
425
+ /** A revision's MCP pin as the API shows it: per server, the granted tools as the server listed them when the revision was
426
+ * saved (name, title, description, input schema, annotations) and the prices its owner set for them; null when it grants
427
+ * no MCP tool. Never the server's URL, whose path or query may be a secret. */
428
+ export function pinView(pin) {
429
+ if (!isObject(pin))
430
+ return null;
431
+ const out = {};
432
+ for (const [server, pinned] of Object.entries(pin)) {
433
+ out[server] = {
434
+ tools: (pinned.tools ?? []).map((tool) => ({ name: tool.name, ...(tool.title ? { title: tool.title } : {}), ...(tool.description ? { description: tool.description } : {}), input_schema: tool.inputSchema ?? {}, ...(tool.annotations ? { annotations: tool.annotations } : {}) })),
435
+ ...(pinned.prices && Object.keys(pinned.prices).length ? { prices: { ...pinned.prices } } : {}),
436
+ };
437
+ }
438
+ return out;
439
+ }
@@ -1,3 +1,4 @@
1
+ import { Compile } from "typebox/schema";
1
2
  /** The text of the last fenced `json` block in `text` (```json or a longer fence, ~~~ too), or undefined. */
2
3
  export declare function lastJsonBlock(text: string): string | undefined;
3
4
  /** The answer's last fenced json block, parsed, or why there is none. */
@@ -8,12 +9,30 @@ export declare function answerJson(answer: string): {
8
9
  };
9
10
  /** A JSON Schema's checker: each problem of a value against it, by path, none for a value that meets it. */
10
11
  export type SchemaCheck = (value: unknown) => string[];
11
- /** `schema` compiled to its checker, or why it does not compile. */
12
+ type Validator = ReturnType<typeof Compile>;
13
+ /** `schema` compiled to its checker (and the compiled validator, for a caller that reads each error's keyword and path),
14
+ * or why it does not compile. The one wrapper of the compiler: the most recent 256 schemas are kept compiled. `misses`:
15
+ * the same problems as `check`, each with the JSON Pointer of the value it is about apart from its words. */
12
16
  export declare function schemaCheck(schema: unknown): {
13
17
  check: SchemaCheck;
18
+ misses: (value: unknown) => {
19
+ path: string;
20
+ words: string;
21
+ }[];
22
+ validator: Validator;
14
23
  } | {
15
24
  why: string;
16
25
  };
26
+ /** The section every harness's system prompt ends its instructions with when the agent has an output schema
27
+ * (definition.output_schema): the schema itself, so the model is told the shape it answers in, never left to find a file.
28
+ * Undefined for an agent with none (or a schema that is not an object, which a save refuses). */
29
+ export declare function outputContract(schema: unknown): string | undefined;
30
+ /** The one retry turn's message (the server's, never the person's): sent once, in the same session, when a run would end
31
+ * with an answer whose last json block misses its output schema. `why` is outputMiss's. */
32
+ export declare const outputRetryWords: (why: string) => string;
33
+ /** Why `answer` misses `schema`, in the retry's words (structuredAnswer's why, less MISSES), or undefined when it meets
34
+ * it. Undefined too when the schema does not compile (a save refuses one): asking the model again cannot mend a schema. */
35
+ export declare function outputMiss(answer: string, schema: unknown): string | undefined;
17
36
  /** A final answer's structured part against an agent's output schema: the value of its last fenced json block when it
18
37
  * meets the schema, else why not (no block, not JSON, the first problems against the schema). */
19
38
  export declare function structuredAnswer(answer: string, schema: unknown): {
@@ -21,3 +40,17 @@ export declare function structuredAnswer(answer: string, schema: unknown): {
21
40
  } | {
22
41
  why: string;
23
42
  };
43
+ /** A learned workflow's answer (`output`, as its tool hands it back: learned-workflow.ts learnedOutput) as a run serves it
44
+ * to an agent with output schema `schema`: the one function serving, a replay and the grade path read it through, so
45
+ * each sees the answer as the run presents it. No schema: the output as it is. With one: an output whose fenced json
46
+ * block already meets it, as it is; else its value shaped to the schema (the output as JSON when it parses, else its
47
+ * text; a value that is no object fills the schema's one field, oneFieldOf: a one-field workflow's bare "5462" is
48
+ * `{"mcc": "5462"}`, never the number; an object output is only itself), the first shape that meets the schema, fenced as the answer's one json block;
49
+ * `value` is what structuredAnswer reads back from `text`. None meets it: why, and the job goes back to the agent. */
50
+ export declare function answerAsServed(output: string, schema: unknown): {
51
+ text: string;
52
+ value: unknown;
53
+ } | {
54
+ why: string;
55
+ };
56
+ export {};
@@ -1,6 +1,8 @@
1
1
  // An answer's structured part: the last fenced `json` block of a final answer, parsed, and checked against an agent's
2
2
  // output schema (definition.output_schema). The one reader of it: a completed agentic run's result.output (store-view.ts)
3
- // and a template eval's schema and target graders (template-eval.ts) read an answer's JSON alike.
3
+ // and a template eval's target graders (template-eval.ts) read an answer's JSON alike. The runner tells the
4
+ // model the schema (outputContract, in every harness's system prompt) and asks once more on a miss (outputRetryWords,
5
+ // runner/adapter-loop.ts).
4
6
  import { Compile } from "typebox/schema";
5
7
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
6
8
  /** The text of the last fenced `json` block in `text` (```json or a longer fence, ~~~ too), or undefined. */
@@ -32,17 +34,51 @@ export function answerJson(answer) {
32
34
  return { why: `the answer's last json block is not JSON: ${error.message}` };
33
35
  }
34
36
  }
35
- /** `schema` compiled to its checker, or why it does not compile. */
37
+ /** Compiled schemas by their JSON: an agent's runs check against the same few schemas over and over. */
38
+ const compiledSchemas = new Map();
39
+ /** `schema` compiled to its checker (and the compiled validator, for a caller that reads each error's keyword and path),
40
+ * or why it does not compile. The one wrapper of the compiler: the most recent 256 schemas are kept compiled. `misses`:
41
+ * the same problems as `check`, each with the JSON Pointer of the value it is about apart from its words. */
36
42
  export function schemaCheck(schema) {
37
43
  if (!isObject(schema))
38
44
  return { why: "it is not a JSON object" };
39
- try {
40
- const validator = Compile(schema);
41
- return { check: (value) => validator.Errors(value)[1].map((e) => `${e.instancePath || "/"} ${e.message}`) };
42
- }
43
- catch (error) {
44
- return { why: `it does not compile as a JSON Schema: ${error.message}` };
45
+ const key = JSON.stringify(schema);
46
+ let validator = compiledSchemas.get(key);
47
+ if (!validator) {
48
+ try {
49
+ validator = Compile(schema);
50
+ }
51
+ catch (error) {
52
+ return { why: `it does not compile as a JSON Schema: ${error.message}` };
53
+ }
54
+ if (compiledSchemas.size >= 256)
55
+ compiledSchemas.delete(compiledSchemas.keys().next().value);
56
+ compiledSchemas.set(key, validator);
45
57
  }
58
+ const compiled = validator;
59
+ const misses = (value) => compiled.Errors(value)[1].map((e) => ({ path: e.instancePath, words: `${e.instancePath || "/"} ${e.message}` }));
60
+ return { validator: compiled, misses, check: (value) => misses(value).map((miss) => miss.words) };
61
+ }
62
+ /** The section every harness's system prompt ends its instructions with when the agent has an output schema
63
+ * (definition.output_schema): the schema itself, so the model is told the shape it answers in, never left to find a file.
64
+ * Undefined for an agent with none (or a schema that is not an object, which a save refuses). */
65
+ export function outputContract(schema) {
66
+ if (!isObject(schema))
67
+ return undefined;
68
+ return `End your final answer with exactly one \`\`\`json block that matches this JSON Schema:\n\n\`\`\`json\n${JSON.stringify(schema, null, 2)}\n\`\`\``;
69
+ }
70
+ /** The one retry turn's message (the server's, never the person's): sent once, in the same session, when a run would end
71
+ * with an answer whose last json block misses its output schema. `why` is outputMiss's. */
72
+ export const outputRetryWords = (why) => `Your final JSON did not match the output schema: ${why}. Reply again, ending with the corrected json block.`;
73
+ /** How structuredAnswer starts the why of a json block the schema refuses; the retry's own sentence already says it. */
74
+ const MISSES = "the answer's json does not meet the output schema: ";
75
+ /** Why `answer` misses `schema`, in the retry's words (structuredAnswer's why, less MISSES), or undefined when it meets
76
+ * it. Undefined too when the schema does not compile (a save refuses one): asking the model again cannot mend a schema. */
77
+ export function outputMiss(answer, schema) {
78
+ if ("why" in schemaCheck(schema))
79
+ return undefined;
80
+ const read = structuredAnswer(answer, schema);
81
+ return "why" in read ? read.why.replace(MISSES, "") : undefined;
46
82
  }
47
83
  /** A final answer's structured part against an agent's output schema: the value of its last fenced json block when it
48
84
  * meets the schema, else why not (no block, not JSON, the first problems against the schema). */
@@ -54,5 +90,51 @@ export function structuredAnswer(answer, schema) {
54
90
  if ("why" in json)
55
91
  return json;
56
92
  const problems = compiled.check(json.value);
57
- return problems.length ? { why: `the answer's json does not meet the output schema: ${problems.slice(0, 3).join("; ")}` } : { value: json.value };
93
+ return problems.length ? { why: `${MISSES}${problems.slice(0, 3).join("; ")}` } : { value: json.value };
94
+ }
95
+ /** A JSON object schema's one field a bare value fills: its only property, else its only required one; undefined for
96
+ * any other schema. */
97
+ function oneFieldOf(schema) {
98
+ if (!isObject(schema))
99
+ return undefined;
100
+ const properties = isObject(schema.properties) ? Object.keys(schema.properties) : [];
101
+ if (properties.length === 1)
102
+ return properties[0];
103
+ const required = Array.isArray(schema.required) ? schema.required.filter((key) => typeof key === "string") : [];
104
+ return required.length === 1 ? required[0] : undefined;
105
+ }
106
+ /** A learned workflow's answer (`output`, as its tool hands it back: learned-workflow.ts learnedOutput) as a run serves it
107
+ * to an agent with output schema `schema`: the one function serving, a replay and the grade path read it through, so
108
+ * each sees the answer as the run presents it. No schema: the output as it is. With one: an output whose fenced json
109
+ * block already meets it, as it is; else its value shaped to the schema (the output as JSON when it parses, else its
110
+ * text; a value that is no object fills the schema's one field, oneFieldOf: a one-field workflow's bare "5462" is
111
+ * `{"mcc": "5462"}`, never the number; an object output is only itself), the first shape that meets the schema, fenced as the answer's one json block;
112
+ * `value` is what structuredAnswer reads back from `text`. None meets it: why, and the job goes back to the agent. */
113
+ export function answerAsServed(output, schema) {
114
+ if (schema === undefined)
115
+ return { text: output, value: output };
116
+ const compiled = schemaCheck(schema);
117
+ if ("why" in compiled)
118
+ return { why: `the agent's output schema ${compiled.why}` };
119
+ const written = structuredAnswer(output, schema);
120
+ if ("value" in written)
121
+ return { text: output, value: written.value };
122
+ const field = oneFieldOf(schema);
123
+ const values = [];
124
+ try {
125
+ values.push(JSON.parse(output));
126
+ }
127
+ catch {
128
+ // Not JSON: its text alone.
129
+ }
130
+ // An object output is its own shape: one that fails the schema goes back to the agent, never as its own text in a field.
131
+ if (!isObject(values[0]))
132
+ values.push(output);
133
+ const shapes = values.flatMap((value) => (isObject(value) || field === undefined ? [value] : [value, { [field]: value }]));
134
+ const meets = shapes.find((shape) => !compiled.check(shape).length);
135
+ if (meets !== undefined)
136
+ return { text: `\`\`\`json\n${JSON.stringify(meets, null, 2)}\n\`\`\``, value: meets };
137
+ // Said against the object shape (the one-field object a bare value fills), else the first.
138
+ const problems = compiled.check(shapes.find(isObject) ?? shapes[0]);
139
+ return { why: `its answer does not meet the agent's output schema: ${problems.slice(0, 3).join("; ")}` };
58
140
  }
@@ -2,7 +2,7 @@ import type { Route } from "./server.js";
2
2
  /** The variable that turns the profile on. */
3
3
  export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
4
4
  /** The routes (server.ts ROUTES, by name) an API-only server serves: a run's launch, read, list, timeline, messages,
5
- * stop, cancel and cap raise; its files and the uploads a launch names; an agent's Archil disk, read and removed (the
5
+ * stop, cancel, cap raise and grade; its files and the uploads a launch names; an agent's Archil disk, read and removed (the
6
6
  * agent layer of a run's disk, archil-routes.ts); capabilities, health and usage. */
7
7
  export declare const API_ONLY_ROUTES: ReadonlySet<string>;
8
8
  /** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
package/dist/api-only.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /** The variable that turns the profile on. */
2
2
  export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
3
3
  /** The routes (server.ts ROUTES, by name) an API-only server serves: a run's launch, read, list, timeline, messages,
4
- * stop, cancel and cap raise; its files and the uploads a launch names; an agent's Archil disk, read and removed (the
4
+ * stop, cancel, cap raise and grade; its files and the uploads a launch names; an agent's Archil disk, read and removed (the
5
5
  * agent layer of a run's disk, archil-routes.ts); capabilities, health and usage. */
6
6
  export const API_ONLY_ROUTES = new Set([
7
7
  "createRun", "createInlineRun",
8
8
  "getAgentArchil", "deleteAgentArchil",
9
9
  "getRun", "listRuns", "listAllRuns", "getTimeline",
10
- "sendMessage", "stopRun", "cancelRun", "raiseRunCap",
10
+ "sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
11
11
  "listRunFiles", "readRunFile",
12
12
  "createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
13
13
  "getCapabilities", "getHealth", "getUsage",
@@ -1,8 +1,7 @@
1
1
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
2
2
  import { PROVIDERS } from "@parcha/agentrun-computer";
3
- import { TOOL_COST } from "./timeline/index.js";
4
- import { addSpend, BROWSER_CHARGED, keepHold, paidCall, runCap, SPEND_CAP_REACHED } from "./cap.js";
5
- import { paidStep } from "./paid-calls.js";
3
+ import { BROWSER_CHARGED, SPEND_CAP_REACHED } from "./cap.js";
4
+ import { paidStep, unbookedRefusal } from "./paid-calls.js";
6
5
  import { logLine } from "./print.js";
7
6
  import { forModel } from "./result.js";
8
7
  /** The run journal's record of a browser session about to be created at its provider: its tag (pi-browser's, which a
@@ -47,26 +46,26 @@ const BROWSER_TOOL = "browser";
47
46
  * a conversation's session (pi-browser's release, "close"). `log` takes the line that says a charge went uncounted
48
47
  * (default: the server's stderr). */
49
48
  export function browserSpend(provider, price, idleS, release, log = (line) => void process.stderr.write(`agentrun-serve: ${line}\n`), ledger = {}) {
50
- /** The runner's one ledger (the kernel cap's paidCalls), when the run has one. Its holds are hold-only steps (`hold`:
49
+ /** The runner's one ledger (the kernel cap's paidCalls); with none, every call and person's time is refused. Its holds
50
+ * are hold-only steps (`hold`:
51
51
  * money reserved, never spent, given back when let go or when a claim is lost): each browser call's, held at the hold
52
52
  * main takes for it, a session's reserve, a person's time. Its money is its charges: each one paid step of its own,
53
53
  * owed (its time is spent at the provider: never refused, however the run's spend stands), settled at the charge,
54
54
  * named by its session and time (`ref`) so it is booked once, and booked once its commit is in (booked); a reopen books
55
- * any the root holds and the ledger lacks (reopened). In place of this process's spend. Every step names its tool
55
+ * any the root holds and the ledger lacks (reopened). Every step names its tool
56
56
  * ("browser") and, where it has them, its call and session, so the run view folds it as main's charge. */
57
57
  const paid = ledger.paid;
58
58
  /** The ledger steps of charges and holds, until they are written (ledgerIdle). */
59
59
  const pending = new Set();
60
60
  let ledgerSeq = 0;
61
- /** A hold of `usd` under `name`: on the run's one ledger when it is given (a held paid step, given back when the hold is
62
- * let go, the time it held being booked by the session's own charge), else in this process's holds (keepHold). On the
63
- * ledger nothing is written to this process's holds or spend. `admitted`: the ledger's answer (refused in the cap's
64
- * words when it has no room). `owed`: time its provider is already owed, run outside any call (a person's carried
65
- * time, a session held from a reopen, a delayed release), held as main's keepHold holds it: never refused. A fresh
61
+ /** A hold of `usd` under `name` on the run's one ledger (a held paid step, given back when the hold is let go, the time
62
+ * it held being booked by the session's own charge). `admitted`: the ledger's answer (refused in the cap's words when
63
+ * it has no room; refused with no ledger, where nothing is held). `owed`: time its provider is already owed, run
64
+ * outside any call (a person's carried time, a session held from a reopen, a delayed release): never refused. A fresh
66
65
  * session's reserve and a person's time to come (personTime) are not owed: the cap may refuse them. */
67
66
  const holdOf = (name, usd, basis, options = {}) => {
68
67
  if (!paid)
69
- return { hold: keepHold(usd), admitted: Promise.resolve({}) };
68
+ return { hold: { usd, drop: () => { } }, admitted: Promise.resolve({ refused: unbookedRefusal(name) }) };
70
69
  const booking = paid;
71
70
  const id = `browser:${name}#${(ledgerSeq += 1)}`;
72
71
  const admitted = booking.admit({ id, name, holdUsd: usd, basis, chargedBy: provider, tool: BROWSER_TOOL, hold: true, ...(options.tag ? { tag: options.tag } : {}), ...(options.owed ? { owed: true } : {}) }).then(() => ({}), (error) => {
@@ -94,11 +93,6 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
94
93
  };
95
94
  return { hold, admitted };
96
95
  };
97
- /** A charge joins this process's spend only off the ledger: on it, the charge is the ledger's (its own paid step). */
98
- const spendIn = (usd) => {
99
- if (!paid)
100
- addSpend(usd);
101
- };
102
96
  const rate = price.usdPerHour;
103
97
  const usdOf = (seconds) => ((rate ?? 0) * seconds) / 3600;
104
98
  const stretchS = price.minimumS + idleS + RELEASE_ALLOWANCE_S;
@@ -147,18 +141,16 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
147
141
  /** Each call under way, by its id: its conversation and its hold. */
148
142
  const calls = new Map();
149
143
  const take = (hold, usd) => void (hold && (hold.usd = Math.max(0, hold.usd - usd)));
150
- /** Booked in the commit that bills it: a TOOL_COST under the call that ran it (a release's, under its session's last
151
- * call; on the runner's ledger, a BROWSER_CHARGED, its money the ledger step's), what it cost or null when its time
152
- * has no price, and the seconds it was for, with what `booked` needs. A free provider's time books nothing and holds
153
- * nothing. */
144
+ /** Recorded in the commit that bills it: a BROWSER_CHARGED under the call that ran it (a release's, under its session's
145
+ * last call), its money the ledger step's (booked), what it cost or null when its time has no price, and the seconds it
146
+ * was for, with what `booked` needs. A free provider's time books nothing and holds nothing. */
154
147
  async function onCharge(charge, tx, call) {
155
148
  if (rate === 0)
156
149
  return;
157
150
  const usd = charge.state === "priced" ? charge.usd : null;
158
151
  const data = { tool: "browser", charged_by: charge.provider, call: call?.callId ?? sessions.get(charge.tag)?.call ?? null, usd, seconds: charge.seconds, tag: charge.tag, conversation: charge.conversationId, at: charge.at, final: charge.final };
159
- // On the ledger, its money is the ledger's, booked once this commit is in (booked): the root keeps the record under a
160
- // kind no cost reads.
161
- await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: paid ? BROWSER_CHARGED : TOOL_COST, data });
152
+ // Its money is the ledger's, booked once this commit is in (booked): the root keeps the record under a kind no cost reads.
153
+ await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: BROWSER_CHARGED, data });
162
154
  }
163
155
  /** A charge on the run's one ledger, once its commit is in: one paid step of its own, owed (its time is spent at the
164
156
  * provider, so the cap never refuses it, however the run's spend stands), settled at the charge, under its call (the
@@ -174,14 +166,13 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
174
166
  void step.finally(() => pending.delete(step));
175
167
  return step;
176
168
  }
177
- /** A charge whose commit is in (watch): it joins what the run's process counts as spent, and moves the holds. Never
178
- * inside the commit, so one that fails changes neither. */
169
+ /** A charge whose commit is in (watch): booked on the ledger, and it moves the holds. Never inside the commit, so one
170
+ * that fails changes neither. */
179
171
  function booked(data) {
180
172
  if (paid)
181
173
  bookOnLedger(paid, data);
182
174
  const usd = data.usd ?? 0;
183
175
  const session = sessions.get(data.tag);
184
- spendIn(data.usd);
185
176
  const through = Date.parse(data.at);
186
177
  // The part of this charge that is a kept session's person time, run since its last charge up to the charge's own
187
178
  // through: that part is held elsewhere already (carried, or still under way) and the call's hold left it out
@@ -279,18 +270,15 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
279
270
  * `inventory`), once the commit is in: the charges first, so a release billed and ended in one commit is billed from
280
271
  * its reserve before it goes. */
281
272
  function watch(harness, inventory = "browser.inventory") {
282
- // pi 1.5 detaches an observer whose advance throws, for good: every later charge would then go uncounted, silently.
283
- // So nothing leaves advance. A charge it fails to count makes the run's spend unknown (spent null), which a capped
284
- // run's next paid request or call is refused on, as it refuses any unknown spend; an uncapped run goes on, with one
285
- // line that says so. pi ends a commit observer only when its Session closes (session.js close: a normal close ends
286
- // it `failed` with "session closed", a failed Session `failed` with its error), and the Session's own end
287
- // (`closed`, settled by that same close once its Storage closed) says which, tagged by kind: `closed` keeps the
288
- // count, silently, on every close path; `failed` (the store failed, or could not close) leaves it unknown. A
289
- // listener error, which only a throw out of advance could cause, is unknown at once.
273
+ // pi 1.5 detaches an observer whose advance throws, for good: every later charge would then go unbooked, silently.
274
+ // So nothing leaves advance; a charge it fails to book is said in one line, and the next claim's reopen books it from
275
+ // the root (bookRootCharges). pi ends a commit observer only when its Session closes (session.js close: a normal close
276
+ // ends it `failed` with "session closed", a failed Session `failed` with its error), and the Session's own end
277
+ // (`closed`, settled by that same close once its Storage closed) says which, tagged by kind: `closed` is said
278
+ // nothing, on every close path; `failed` (the store failed, or could not close) is said. A listener error, which only
279
+ // a throw out of advance could cause, is said at once.
290
280
  let said = false;
291
281
  const uncounted = (why) => {
292
- // On the run's one ledger a charge is booked in the commit that bills it (onCharge), never from here.
293
- spendIn(null);
294
282
  if (said)
295
283
  return;
296
284
  said = true;
@@ -300,7 +288,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
300
288
  advance: (publication) => {
301
289
  try {
302
290
  for (const change of publication.changes) {
303
- const data = change.type === "entry" && (change.value.kind === TOOL_COST || change.value.kind === BROWSER_CHARGED) ? change.value.data : undefined;
291
+ const data = change.type === "entry" && change.value.kind === BROWSER_CHARGED ? change.value.data : undefined;
304
292
  if (data?.tool === "browser" && typeof data.tag === "string")
305
293
  booked(data);
306
294
  }
@@ -321,14 +309,13 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
321
309
  },
322
310
  });
323
311
  }
324
- /** `tool` held under the run's cap before each call. */
312
+ /** `tool` held under the run's cap before each call, on the run's one ledger; with none, refused unsent. */
325
313
  function capped(tool) {
326
314
  return {
327
315
  ...tool,
328
316
  execute: async (args, api, context) => {
329
- const cap = runCap();
330
- if (cap !== undefined && rate === null)
331
- return refuse(`${SPEND_CAP_REACHED}: This browser call was not sent. ${provider}'s session time has no price here (${priceEnvOf(provider)} gives one), so the run's cap of $${cap} cannot be kept: the run is out of budget.`, api, context);
317
+ if (!paid)
318
+ return refuse(unbookedRefusal("this browser call"), api, context);
332
319
  const now = Date.now();
333
320
  const mine = [...sessions].filter(([, s]) => s.cid === api.conversationId);
334
321
  const ranS = mine.reduce((sum, [, s]) => sum + Math.max(0, now - s.at) / 1000, 0);
@@ -338,33 +325,19 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
338
325
  // Up to the millionth of a dollar, so the cap's words name a figure never below the hold.
339
326
  const usd = microUsd(Math.max(0, usdOf(ranS) - carriedUsd) + 2 * stretch);
340
327
  const basis = `${provider}'s session time at $${rate} an hour: the ${Math.round(ranS)} s its session ran since its last charge, and twice the next stretch of ${stretchS} s (its ${price.minimumS} s minimum, the ${idleS} s idle window and ${RELEASE_ALLOWANCE_S} s for its release)`;
341
- if (ledger.paid) {
342
- // On the runner's one ledger: one hold-only step, held at that same figure and given back when the call returns
343
- // (or its claim is lost): the call's charges are each their own step (booked).
344
- calls.set(api.callId, { cid: api.conversationId, hold: { usd, drop: () => { } } });
345
- try {
346
- // A provider whose time has no price is held at no figure: the cap's rule refuses it for good, as main does.
347
- // One refused for room pauses the run (ledger.pause, the run's own: a native tool task runs in no host tool
348
- // call's ledger), in the cap's words and figures, as an ask's person time does: its next request is refused
349
- // and the run parks for a raise.
350
- const stepped = await paidStep(ledger.paid, api.callId, { name: "this browser call", holdUsd: rate === null ? Number.NaN : usd, basis, by: provider, tool: BROWSER_TOOL, hold: true }, () => tool.execute(args, api, context), () => 0, ledger.pause);
351
- return "refused" in stepped ? await refuse(stepped.refused, api, context) : stepped.result;
352
- }
353
- finally {
354
- calls.delete(api.callId);
355
- }
356
- }
357
- const paid = await paidCall("this browser call", async () => keepHold(usd), () => undefined, { usd, basis });
358
- if ("refused" in paid)
359
- return refuse(paid.refused, api, context);
360
- const hold = paid.result;
361
- calls.set(api.callId, { cid: api.conversationId, hold });
328
+ // One hold-only step, held at that figure and given back when the call returns (or its claim is lost): the call's
329
+ // charges are each their own step (booked).
330
+ calls.set(api.callId, { cid: api.conversationId, hold: { usd, drop: () => { } } });
362
331
  try {
363
- return await tool.execute(args, api, context);
332
+ // A provider whose time has no price is held at no figure: the cap's rule refuses it for good, as main does.
333
+ // One refused for room pauses the run (ledger.pause, the run's own: a native tool task runs in no host tool
334
+ // call's ledger), in the cap's words and figures, as an ask's person time does: its next request is refused
335
+ // and the run parks for a raise.
336
+ const stepped = await paidStep(paid, api.callId, { name: "this browser call", holdUsd: rate === null ? Number.NaN : usd, basis, by: provider, tool: BROWSER_TOOL, hold: true }, () => tool.execute(args, api, context), () => 0, ledger.pause);
337
+ return "refused" in stepped ? await refuse(stepped.refused, api, context) : stepped.result;
364
338
  }
365
339
  finally {
366
340
  calls.delete(api.callId);
367
- hold.drop();
368
341
  }
369
342
  },
370
343
  };
@@ -391,37 +364,23 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
391
364
  * and `from` (ms, where the stretch it holds starts; now by default), the stretch is known while held: a call meanwhile
392
365
  * leaves out what of it has run, and a charge that books it takes it off the hold. */
393
366
  async function personTime(what, seconds, options = {}) {
394
- const cap = runCap();
395
- if (cap !== undefined && rate === null)
396
- return { refused: `${SPEND_CAP_REACHED}: ${what} did not start. ${provider}'s session time has no price here (${priceEnvOf(provider)} gives one), so the run's cap of $${cap} cannot be kept.` };
397
367
  // Up to the millionth of a dollar, so the cap's words name a figure never below the hold.
398
368
  const usd = Math.ceil(Math.round(usdOf(seconds) * 1e12) / 1e6) / 1e6;
399
369
  const basis = `${provider}'s session time at $${rate} an hour for the ${Math.round(seconds / 60)} minutes it may last`;
400
- // A refusal pauses the run at its next request (paidCall) only for the agent's own step (an ask); `pauses: false` for a
401
- // person's take-over, which is no step of the agent's.
402
- let hold;
403
- if (ledger.paid) {
404
- // On the run's one ledger: held there up front, refused in the cap's words when it has no room (an unpriced
405
- // provider's time held at no figure, which the rule refuses for good); let go at its end, the time itself booked by
406
- // the session's next charge.
407
- const held = holdOf(what, rate === null ? Number.NaN : usd, basis);
408
- const answer = await held.admitted;
409
- if (answer.refused !== undefined) {
410
- // The agent's own step (an ask) refused at the cap pauses the run, as main's paidCall pause does: its pause is
411
- // journaled now and the run's next request is refused in its words. A person's take-over (pauses: false) pauses
412
- // nothing.
413
- if (options.pauses !== false && answer.refusal && ledger.pause)
414
- await ledger.pause(answer.refusal);
415
- return { refused: answer.refused };
416
- }
417
- hold = held.hold;
418
- }
419
- else {
420
- const paidHere = await paidCall(what, async () => keepHold(usd), () => undefined, { usd, basis }, { pauses: options.pauses });
421
- if ("refused" in paidHere)
422
- return { refused: paidHere.refused };
423
- hold = paidHere.result;
370
+ // Held on the run's one ledger up front, refused in the cap's words when it has no room (an unpriced provider's time
371
+ // held at no figure, which the rule refuses for good; with no ledger, refused); let go at its end, the time itself
372
+ // booked by the session's next charge.
373
+ const held = holdOf(what, rate === null ? Number.NaN : usd, basis);
374
+ const answer = await held.admitted;
375
+ if (answer.refused !== undefined) {
376
+ // The agent's own step (an ask) refused at the cap pauses the run, as main's paidCall pause does: its pause is
377
+ // journaled now and the run's next request is refused in its words. A person's take-over (pauses: false) pauses
378
+ // nothing.
379
+ if (options.pauses !== false && answer.refusal && ledger.pause)
380
+ await ledger.pause(answer.refusal);
381
+ return { refused: answer.refused };
424
382
  }
383
+ const hold = held.hold;
425
384
  const tag = options.tag;
426
385
  if (tag === undefined || !rate)
427
386
  return hold;
@@ -448,11 +407,11 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
448
407
  const from = Math.max(to - seconds * 1000, sessions.get(tag)?.at ?? -Infinity);
449
408
  if (!(to > from))
450
409
  return;
451
- // Spent at the provider already: held on the run's ledger (or this process's holds) until a charge books it.
410
+ // Spent at the provider already: held on the run's ledger until a charge books it.
452
411
  const { hold } = holdOf("a person's time in the browser", microUsd(usdOf((to - from) / 1000)), `${provider}'s session time a person used, until the session's next charge books it`, { owed: true, tag });
453
412
  carried.set(tag, [...(carried.get(tag) ?? []), { hold, from, to }]);
454
413
  }
455
- /** Once every ledger step of a charge under no call is written (the runner's one ledger; nothing to wait for without). */
414
+ /** Once every ledger step of a charge under no call is written. */
456
415
  const ledgerIdle = async () => void (await Promise.all([...pending]));
457
416
  return { onCharge, watch, reopened, capped, opening, personTime, carry, stretch, ledgerIdle };
458
417
  }