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

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 (620) hide show
  1. package/CHANGELOG.md +700 -0
  2. package/README.md +441 -177
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +1 -3
  6. package/dist/agents-store.d.ts +35 -3
  7. package/dist/agents-store.js +48 -23
  8. package/dist/answer-json.d.ts +34 -1
  9. package/dist/answer-json.js +91 -9
  10. package/dist/api-only.d.ts +1 -1
  11. package/dist/api-only.js +2 -2
  12. package/dist/bash-read-only.js +2 -1
  13. package/dist/browser-cost.js +52 -93
  14. package/dist/cap-short.d.ts +12 -0
  15. package/dist/cap-short.js +60 -0
  16. package/dist/cap.d.ts +3 -400
  17. package/dist/cap.js +6 -942
  18. package/dist/catalog.d.ts +0 -5
  19. package/dist/catalog.js +2 -6
  20. package/dist/chatgpt-plan.d.ts +163 -0
  21. package/dist/chatgpt-plan.js +549 -0
  22. package/dist/cli.js +26 -6
  23. package/dist/composio-preset.d.ts +25 -0
  24. package/dist/composio-preset.js +51 -8
  25. package/dist/composio-triggers.d.ts +113 -0
  26. package/dist/composio-triggers.js +411 -0
  27. package/dist/computer-calls.d.ts +36 -24
  28. package/dist/computer-calls.js +110 -27
  29. package/dist/computer-commands.d.ts +2 -0
  30. package/dist/computer-commands.js +7 -3
  31. package/dist/computer-live.d.ts +12 -2
  32. package/dist/computer-live.js +21 -5
  33. package/dist/computer-routes.d.ts +2 -2
  34. package/dist/computer-routes.js +2 -2
  35. package/dist/computer-setting.d.ts +15 -2
  36. package/dist/computer-setting.js +20 -4
  37. package/dist/computer-view.d.ts +18 -2
  38. package/dist/computer-view.js +21 -6
  39. package/dist/computer-viewer.js +40 -13
  40. package/dist/computers.d.ts +8 -2
  41. package/dist/computers.js +18 -8
  42. package/dist/console/assets/index-BNhZs-jp.css +1 -0
  43. package/dist/console/assets/index-BQv5aOGB.js +700 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/console-links.d.ts +2 -0
  46. package/dist/console-links.js +6 -3
  47. package/dist/decision-cap.d.ts +2 -5
  48. package/dist/decision-cap.js +3 -6
  49. package/dist/decision-rows.js +11 -11
  50. package/dist/decisions.js +4 -0
  51. package/dist/email/account.d.ts +84 -0
  52. package/dist/email/account.js +159 -0
  53. package/dist/email/answer.d.ts +10 -0
  54. package/dist/email/answer.js +182 -0
  55. package/dist/email/email-faux.d.ts +95 -0
  56. package/dist/email/email-faux.js +849 -0
  57. package/dist/email/labels.d.ts +1 -0
  58. package/dist/email/labels.js +84 -0
  59. package/dist/email/mail.d.ts +186 -0
  60. package/dist/email/mail.js +380 -0
  61. package/dist/email/names.d.ts +20 -0
  62. package/dist/email/names.js +40 -0
  63. package/dist/email/routes.d.ts +9 -0
  64. package/dist/email/routes.js +50 -0
  65. package/dist/email/tools.d.ts +20 -0
  66. package/dist/email/tools.js +517 -0
  67. package/dist/environment.d.ts +17 -2
  68. package/dist/environment.js +36 -8
  69. package/dist/errors.d.ts +6 -0
  70. package/dist/errors.js +12 -0
  71. package/dist/eval-mailbox.d.ts +103 -0
  72. package/dist/eval-mailbox.js +236 -0
  73. package/dist/faux-computers.js +4 -2
  74. package/dist/graph-view.d.ts +9 -2
  75. package/dist/graph-view.js +6 -2
  76. package/dist/harness-install.d.ts +28 -2
  77. package/dist/harness-install.js +147 -59
  78. package/dist/harness-opencode/adapter.js +2 -22
  79. package/dist/harness-opencode/facts.js +5 -4
  80. package/dist/harness-opencode/host/policy.d.ts +4 -5
  81. package/dist/harness-opencode/host/policy.js +14 -33
  82. package/dist/harness-opencode/index.d.ts +1 -1
  83. package/dist/harness-opencode/index.js +1 -1
  84. package/dist/harness-opencode/versions.d.ts +6 -0
  85. package/dist/harness-opencode/versions.js +6 -0
  86. package/dist/harness-table.d.ts +0 -2
  87. package/dist/harness-table.js +8 -7
  88. package/dist/harness.d.ts +12 -0
  89. package/dist/harness.js +15 -3
  90. package/dist/host-tools.d.ts +1 -5
  91. package/dist/host-tools.js +7 -10
  92. package/dist/hosted-search.d.ts +3 -3
  93. package/dist/hosted-search.js +51 -32
  94. package/dist/import-sources.d.ts +1 -1
  95. package/dist/import-sources.js +3 -3
  96. package/dist/import.d.ts +21 -0
  97. package/dist/import.js +186 -1
  98. package/dist/key-check.d.ts +0 -2
  99. package/dist/key-check.js +3 -4
  100. package/dist/key-refusal.d.ts +8 -2
  101. package/dist/key-refusal.js +16 -13
  102. package/dist/key-words.d.ts +3 -2
  103. package/dist/key-words.js +4 -2
  104. package/dist/learn/check.d.ts +24 -4
  105. package/dist/learn/check.js +340 -7
  106. package/dist/learn/commit.d.ts +10 -0
  107. package/dist/learn/commit.js +18 -4
  108. package/dist/learn/compile.d.ts +250 -0
  109. package/dist/learn/compile.js +507 -0
  110. package/dist/learn/general.d.ts +3 -0
  111. package/dist/learn/general.js +4 -2
  112. package/dist/learn/grade.d.ts +5 -1
  113. package/dist/learn/grade.js +11 -7
  114. package/dist/learn/notes.d.ts +8 -0
  115. package/dist/learn/notes.js +18 -0
  116. package/dist/learn/promote.d.ts +308 -0
  117. package/dist/learn/promote.js +321 -0
  118. package/dist/learn/refit.d.ts +48 -0
  119. package/dist/learn/refit.js +264 -0
  120. package/dist/learn/reflect.d.ts +5 -25
  121. package/dist/learn/reflect.js +14 -131
  122. package/dist/learn/replay-calls.d.ts +63 -0
  123. package/dist/learn/replay-calls.js +158 -0
  124. package/dist/learn/skills.d.ts +19 -16
  125. package/dist/learn/skills.js +157 -53
  126. package/dist/learn/workflow-nodes.d.ts +15 -0
  127. package/dist/learn/workflow-nodes.js +44 -0
  128. package/dist/learned-nodes.d.ts +58 -2
  129. package/dist/learned-nodes.js +68 -5
  130. package/dist/learned-workflow.d.ts +58 -32
  131. package/dist/learned-workflow.js +215 -77
  132. package/dist/learning-batch.d.ts +2 -2
  133. package/dist/learning-batch.js +4 -4
  134. package/dist/learning-cost.d.ts +41 -11
  135. package/dist/learning-cost.js +31 -13
  136. package/dist/learning-routes.d.ts +12 -2
  137. package/dist/learning-routes.js +34 -6
  138. package/dist/learning-words.d.ts +8 -1
  139. package/dist/learning-words.js +11 -1
  140. package/dist/learning.d.ts +26 -1
  141. package/dist/learning.js +7 -4
  142. package/dist/link-check.d.ts +27 -0
  143. package/dist/link-check.js +164 -0
  144. package/dist/llm.js +0 -3
  145. package/dist/local-models.d.ts +33 -2
  146. package/dist/local-models.js +43 -5
  147. package/dist/mcp-gateway.d.ts +12 -20
  148. package/dist/mcp-gateway.js +16 -44
  149. package/dist/mcp-oauth.d.ts +5 -0
  150. package/dist/mcp-oauth.js +1 -1
  151. package/dist/mcp-pin-first.d.ts +37 -0
  152. package/dist/mcp-pin-first.js +113 -0
  153. package/dist/mcp-probe.d.ts +8 -9
  154. package/dist/mcp-probe.js +16 -33
  155. package/dist/mcp-secret-writes.js +3 -0
  156. package/dist/mcp-servers-store.d.ts +102 -26
  157. package/dist/mcp-servers-store.js +151 -25
  158. package/dist/mcp-sources.d.ts +39 -0
  159. package/dist/mcp-sources.js +74 -0
  160. package/dist/mcp-store.d.ts +11 -0
  161. package/dist/mcp-store.js +16 -2
  162. package/dist/mcp-wire.d.ts +22 -0
  163. package/dist/mcp-wire.js +36 -0
  164. package/dist/mcp.js +3 -3
  165. package/dist/meta-tool-names.d.ts +1 -0
  166. package/dist/meta-tool-names.js +3 -0
  167. package/dist/model-form.d.ts +11 -0
  168. package/dist/model-form.js +17 -1
  169. package/dist/model.d.ts +39 -6
  170. package/dist/model.js +171 -32
  171. package/dist/monid.d.ts +50 -29
  172. package/dist/monid.js +234 -143
  173. package/dist/native/binding.d.ts +13 -0
  174. package/dist/native/binding.js +57 -0
  175. package/dist/native/cli.d.ts +2 -0
  176. package/dist/native/cli.js +48 -0
  177. package/dist/native/connection.d.ts +8 -0
  178. package/dist/native/connection.js +94 -0
  179. package/dist/native/context.d.ts +6 -0
  180. package/dist/native/context.js +22 -0
  181. package/dist/native/discovery.d.ts +27 -0
  182. package/dist/native/discovery.js +404 -0
  183. package/dist/native/environment.d.ts +4 -0
  184. package/dist/native/environment.js +18 -0
  185. package/dist/native/history.d.ts +20 -0
  186. package/dist/native/history.js +147 -0
  187. package/dist/native/instructions.d.ts +21 -0
  188. package/dist/native/instructions.js +173 -0
  189. package/dist/native/remote-worker-bridge.d.ts +3 -0
  190. package/dist/native/remote-worker-bridge.js +278 -0
  191. package/dist/native/remote.d.ts +187 -0
  192. package/dist/native/remote.js +492 -0
  193. package/dist/native/runtime.d.ts +17 -0
  194. package/dist/native/runtime.js +316 -0
  195. package/dist/native/runtimes.d.ts +66 -0
  196. package/dist/native/runtimes.js +41 -0
  197. package/dist/native/schema.d.ts +46 -0
  198. package/dist/native/schema.js +41 -0
  199. package/dist/native/types.d.ts +87 -0
  200. package/dist/native/types.js +1 -0
  201. package/dist/observation/http.d.ts +4 -0
  202. package/dist/observation/http.js +140 -0
  203. package/dist/observation/observer.d.ts +301 -0
  204. package/dist/observation/observer.js +919 -0
  205. package/dist/observation/schema.d.ts +52 -0
  206. package/dist/observation/schema.js +154 -0
  207. package/dist/openapi.d.ts +1 -0
  208. package/dist/openapi.js +705 -126
  209. package/dist/paid-calls.d.ts +34 -32
  210. package/dist/paid-calls.js +52 -104
  211. package/dist/place-offers.d.ts +4 -8
  212. package/dist/place-offers.js +4 -9
  213. package/dist/port-models.d.ts +7 -2
  214. package/dist/port-models.js +5 -2
  215. package/dist/print.d.ts +4 -2
  216. package/dist/print.js +4 -3
  217. package/dist/propose.d.ts +8 -3
  218. package/dist/propose.js +28 -7
  219. package/dist/provider.d.ts +5 -1
  220. package/dist/provider.js +17 -2
  221. package/dist/push-handler.d.ts +3 -2
  222. package/dist/push-handler.js +20 -6
  223. package/dist/reflect-range.js +2 -1
  224. package/dist/refusal-words.d.ts +11 -0
  225. package/dist/refusal-words.js +13 -2
  226. package/dist/rows.d.ts +5 -3
  227. package/dist/rows.js +15 -4
  228. package/dist/run-launch.d.ts +23 -1
  229. package/dist/run-launch.js +17 -4
  230. package/dist/run-learning-served.d.ts +84 -0
  231. package/dist/run-manifest.d.ts +8 -0
  232. package/dist/run-manifest.js +33 -1
  233. package/dist/run-reads-over-store.d.ts +3 -3
  234. package/dist/run-reads-over-store.js +13 -10
  235. package/dist/run-secrets.js +2 -3
  236. package/dist/run-timeline-served.d.ts +3 -2
  237. package/dist/run-timeline-served.js +12 -10
  238. package/dist/run-view.d.ts +59 -41
  239. package/dist/run-view.js +128 -64
  240. package/dist/runnable.d.ts +13 -8
  241. package/dist/runnable.js +77 -60
  242. package/dist/runner/adapter-loop.d.ts +60 -15
  243. package/dist/runner/adapter-loop.js +1406 -464
  244. package/dist/runner/adapter-run-spec.d.ts +45 -14
  245. package/dist/runner/adapter-run-spec.js +200 -116
  246. package/dist/runner/adapters/pi.d.ts +40 -7
  247. package/dist/runner/adapters/pi.js +149 -38
  248. package/dist/runner/beside.d.ts +3 -1
  249. package/dist/runner/beside.js +24 -8
  250. package/dist/runner/claim-secrets.d.ts +3 -1
  251. package/dist/runner/claim-secrets.js +28 -4
  252. package/dist/runner/cli-run-spec.d.ts +30 -0
  253. package/dist/runner/cli-run-spec.js +150 -66
  254. package/dist/runner/computer-channel.d.ts +5 -2
  255. package/dist/runner/computer-channel.js +5 -3
  256. package/dist/runner/computer-journal.d.ts +6 -0
  257. package/dist/runner/computer-journal.js +8 -10
  258. package/dist/runner/conformance/harness.d.ts +3 -0
  259. package/dist/runner/conformance/harness.js +149 -5
  260. package/dist/runner/conformance/subject.d.ts +11 -4
  261. package/dist/runner/end-of-run.d.ts +8 -5
  262. package/dist/runner/end-of-run.js +11 -6
  263. package/dist/runner/feedback-round.d.ts +79 -0
  264. package/dist/runner/feedback-round.js +127 -0
  265. package/dist/runner/harness-loops.js +17 -0
  266. package/dist/runner/journal-kinds.d.ts +55 -13
  267. package/dist/runner/journal-kinds.js +19 -0
  268. package/dist/runner/learning-dispatch.d.ts +3 -2
  269. package/dist/runner/learning-dispatch.js +6 -6
  270. package/dist/runner/learning-end.d.ts +58 -19
  271. package/dist/runner/learning-end.js +316 -115
  272. package/dist/runner/learning-factory.d.ts +3 -0
  273. package/dist/runner/learning-factory.js +8 -2
  274. package/dist/runner/learning-loop.d.ts +21 -1
  275. package/dist/runner/learning-loop.js +24 -6
  276. package/dist/runner/learning-seed.d.ts +4 -0
  277. package/dist/runner/learning-seed.js +14 -0
  278. package/dist/runner/loop-contract.d.ts +19 -3
  279. package/dist/runner/loop.d.ts +34 -1
  280. package/dist/runner/loop.js +55 -1
  281. package/dist/runner/main.d.ts +6 -1
  282. package/dist/runner/main.js +26 -4
  283. package/dist/runner/mcp-claim.d.ts +5 -1
  284. package/dist/runner/mcp-claim.js +66 -50
  285. package/dist/runner/mcp-run.d.ts +20 -53
  286. package/dist/runner/mcp-run.js +22 -88
  287. package/dist/runner/meta-tools.d.ts +44 -0
  288. package/dist/runner/meta-tools.js +344 -0
  289. package/dist/runner/metrics.d.ts +80 -21
  290. package/dist/runner/metrics.js +128 -42
  291. package/dist/runner/model-route.d.ts +12 -3
  292. package/dist/runner/model-route.js +149 -19
  293. package/dist/runner/monid-run.d.ts +18 -0
  294. package/dist/runner/monid-run.js +170 -0
  295. package/dist/runner/native-loop.d.ts +11 -0
  296. package/dist/runner/native-loop.js +438 -0
  297. package/dist/runner/promotion.d.ts +146 -0
  298. package/dist/runner/promotion.js +803 -0
  299. package/dist/runner/redact.js +3 -0
  300. package/dist/runner/reflect-hook.d.ts +36 -21
  301. package/dist/runner/reflect-hook.js +147 -49
  302. package/dist/runner/runner.d.ts +7 -1
  303. package/dist/runner/runner.js +34 -8
  304. package/dist/runner/sdk-loop.d.ts +7 -0
  305. package/dist/runner/sdk-loop.js +470 -0
  306. package/dist/runner/sessions.d.ts +8 -3
  307. package/dist/runner/sessions.js +5 -1
  308. package/dist/runner/spec-holds.d.ts +16 -2
  309. package/dist/runner/spec-holds.js +42 -14
  310. package/dist/runner/step-guard.d.ts +62 -0
  311. package/dist/runner/step-guard.js +93 -0
  312. package/dist/runner/store-secrets.js +17 -2
  313. package/dist/runner/subagent.d.ts +0 -3
  314. package/dist/runner/subagent.js +7 -12
  315. package/dist/runner/workflow-first.d.ts +226 -0
  316. package/dist/runner/workflow-first.js +293 -0
  317. package/dist/runner/workflow-loop.d.ts +1 -1
  318. package/dist/runner/workflow-loop.js +32 -19
  319. package/dist/runner/workflow-spec.d.ts +5 -1
  320. package/dist/runner/workflow-spec.js +63 -48
  321. package/dist/runs-over-store.d.ts +41 -4
  322. package/dist/runs-over-store.js +64 -22
  323. package/dist/sdk/runs.d.ts +115 -0
  324. package/dist/sdk/runs.js +422 -0
  325. package/dist/sdk/schema.d.ts +175 -0
  326. package/dist/sdk/schema.js +138 -0
  327. package/dist/sdk/workflows.d.ts +22 -0
  328. package/dist/sdk/workflows.js +39 -0
  329. package/dist/secrets.d.ts +2 -0
  330. package/dist/secrets.js +19 -1
  331. package/dist/server.d.ts +108 -20
  332. package/dist/server.js +874 -157
  333. package/dist/settings-wake.d.ts +8 -6
  334. package/dist/settings-wake.js +13 -7
  335. package/dist/skill-route.d.ts +3 -0
  336. package/dist/skill-route.js +16 -0
  337. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  338. package/dist/stats.d.ts +10 -10
  339. package/dist/store/agent-body.d.ts +22 -7
  340. package/dist/store/agent-body.js +23 -14
  341. package/dist/store/command-wake.d.ts +3 -2
  342. package/dist/store/command-wake.js +4 -4
  343. package/dist/store/index.d.ts +1 -1
  344. package/dist/store/native-command-owner.d.ts +10 -0
  345. package/dist/store/native-command-owner.js +47 -0
  346. package/dist/store/postgres/connection.js +3 -1
  347. package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
  348. package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
  349. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  350. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  351. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  352. package/dist/store/postgres/store.js +3 -0
  353. package/dist/store/schema.d.ts +16 -0
  354. package/dist/store/schema.js +47 -8
  355. package/dist/store/sqlite/connection.d.ts +2 -2
  356. package/dist/store/sqlite/connection.js +2 -2
  357. package/dist/store/sqlite/run-patch.d.ts +8 -1
  358. package/dist/store/sqlite/run-patch.js +33 -10
  359. package/dist/store/sqlite/store.js +184 -28
  360. package/dist/store/store.d.ts +98 -21
  361. package/dist/store-reads/analytics.d.ts +7 -7
  362. package/dist/store-reads/analytics.js +23 -5
  363. package/dist/store-reads/cap.js +8 -6
  364. package/dist/store-reads/journal.d.ts +30 -1
  365. package/dist/store-reads/journal.js +141 -83
  366. package/dist/store-reads/learning.d.ts +179 -13
  367. package/dist/store-reads/learning.js +230 -68
  368. package/dist/store-reads/loop.d.ts +61 -0
  369. package/dist/store-reads/loop.js +111 -0
  370. package/dist/store-reads/runs.d.ts +5 -0
  371. package/dist/store-reads/runs.js +3 -2
  372. package/dist/store-view.d.ts +3 -2
  373. package/dist/store-view.js +109 -37
  374. package/dist/template-eval.d.ts +87 -16
  375. package/dist/template-eval.js +605 -120
  376. package/dist/template-github-permissions.d.ts +2 -2
  377. package/dist/template-github-permissions.js +2 -1
  378. package/dist/template-import.d.ts +31 -0
  379. package/dist/template-import.js +121 -0
  380. package/dist/template-source.d.ts +51 -0
  381. package/dist/template-source.js +371 -0
  382. package/dist/templates.d.ts +274 -52
  383. package/dist/templates.js +670 -201
  384. package/dist/text-urls.d.ts +38 -0
  385. package/dist/text-urls.js +170 -0
  386. package/dist/timeline/computer.d.ts +48 -0
  387. package/dist/timeline/computer.js +169 -0
  388. package/dist/timeline/index.d.ts +7 -5
  389. package/dist/timeline/index.js +7 -5
  390. package/dist/timeline/labels.d.ts +11 -4
  391. package/dist/timeline/labels.js +122 -8
  392. package/dist/timeline/origin.d.ts +20 -6
  393. package/dist/timeline/origin.js +13 -6
  394. package/dist/timeline/render-text.js +1 -1
  395. package/dist/timeline/timeline.d.ts +76 -20
  396. package/dist/timeline/timeline.js +184 -39
  397. package/dist/timeline/util.d.ts +5 -0
  398. package/dist/timeline/util.js +44 -8
  399. package/dist/timeline/web-calls.d.ts +17 -0
  400. package/dist/timeline/web-calls.js +106 -0
  401. package/dist/tool-gate.d.ts +103 -76
  402. package/dist/tool-gate.js +200 -127
  403. package/dist/tool-keys.d.ts +4 -1
  404. package/dist/tool-keys.js +8 -3
  405. package/dist/tool-list.d.ts +29 -0
  406. package/dist/tool-list.js +50 -0
  407. package/dist/tool-names.d.ts +76 -0
  408. package/dist/tool-names.js +101 -0
  409. package/dist/tool-plane.d.ts +34 -28
  410. package/dist/tool-plane.js +72 -37
  411. package/dist/tools.d.ts +59 -15
  412. package/dist/tools.js +46 -42
  413. package/dist/trigger-adapter.d.ts +85 -5
  414. package/dist/trigger-adapter.js +6 -0
  415. package/dist/trigger-adapters.js +3 -1
  416. package/dist/trigger-composio.d.ts +10 -0
  417. package/dist/trigger-composio.js +122 -0
  418. package/dist/trigger-email.d.ts +4 -0
  419. package/dist/trigger-email.js +228 -0
  420. package/dist/trigger-signatures.d.ts +6 -10
  421. package/dist/trigger-signatures.js +16 -16
  422. package/dist/trigger-targets.d.ts +1 -1
  423. package/dist/trigger-targets.js +4 -3
  424. package/dist/trigger-webhook.js +6 -4
  425. package/dist/triggers.d.ts +94 -9
  426. package/dist/triggers.js +263 -62
  427. package/dist/uploads.d.ts +9 -0
  428. package/dist/uploads.js +27 -0
  429. package/dist/validate.d.ts +15 -7
  430. package/dist/validate.js +91 -50
  431. package/dist/web-fake.d.ts +56 -0
  432. package/dist/web-fake.js +102 -0
  433. package/dist/web-fetch-direct.d.ts +3 -0
  434. package/dist/web-fetch-direct.js +4 -1
  435. package/dist/web-fetch.d.ts +6 -8
  436. package/dist/web-fetch.js +10 -53
  437. package/dist/web-search.d.ts +51 -2
  438. package/dist/web-search.js +116 -18
  439. package/dist/webhooks.d.ts +2 -1
  440. package/dist/webhooks.js +5 -1
  441. package/dist/workflow/node-runner.js +10 -2
  442. package/dist/workspace/archil-claim.d.ts +3 -0
  443. package/dist/workspace/archil-claim.js +9 -2
  444. package/dist/workspace/computer-deps.d.ts +25 -9
  445. package/dist/workspace/computer-deps.js +82 -38
  446. package/dist/workspace/computer-for-claim.d.ts +60 -4
  447. package/dist/workspace/computer-for-claim.js +203 -45
  448. package/dist/workspace/computer-hold.js +7 -1
  449. package/dist/workspace/computer-janitor.d.ts +10 -3
  450. package/dist/workspace/computer-janitor.js +96 -29
  451. package/dist/workspace/computer-kept.d.ts +82 -0
  452. package/dist/workspace/computer-kept.js +147 -0
  453. package/dist/workspace/computer-mcp.js +4 -3
  454. package/dist/workspace/computer-ports.d.ts +23 -3
  455. package/dist/workspace/computer-ports.js +115 -5
  456. package/dist/workspace/index.d.ts +2 -3
  457. package/dist/workspace/index.js +1 -2
  458. package/dist/workspace/kind-skills/desktop/SKILL.md +31 -11
  459. package/dist/workspace/kind-skills/phone/SKILL.md +29 -14
  460. package/dist/workspace/local.js +2 -2
  461. package/dist/workspace/resolve-computer.d.ts +33 -1
  462. package/dist/workspace/resolve-computer.js +37 -16
  463. package/dist/workspace/revision-skills.d.ts +6 -2
  464. package/dist/workspace/revision-skills.js +12 -5
  465. package/dist/workspace/run-end-computers.d.ts +30 -0
  466. package/dist/workspace/run-end-computers.js +137 -0
  467. package/dist/workspace/run-tools.d.ts +40 -23
  468. package/dist/workspace/run-tools.js +46 -19
  469. package/dist/wrap-up.d.ts +35 -0
  470. package/dist/wrap-up.js +48 -0
  471. package/launcher/agentrun-serve +4 -2
  472. package/package.json +13 -9
  473. package/skills/agentrun-serve/SKILL.md +248 -10
  474. package/templates/README.md +220 -60
  475. package/templates/TOOLS.md +168 -0
  476. package/templates/code-review/agent.md +46 -16
  477. package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
  478. package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
  479. package/templates/code-review/evals/injection/case.yaml +2 -1
  480. package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
  481. package/templates/code-review/evals/mentions-defused/case.yaml +3 -3
  482. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
  483. package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
  484. package/templates/code-review/evals/never-flag/case.yaml +2 -1
  485. package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
  486. package/templates/code-review/evals/null-name/case.yaml +2 -1
  487. package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
  488. package/templates/code-review/evals/off-by-one/case.yaml +2 -1
  489. package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
  490. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  491. package/templates/code-review/evals/other-repo/case.yaml +16 -0
  492. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
  493. package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
  494. package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
  495. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
  496. package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
  497. package/templates/code-review/evals/other-repo/prompt.md +10 -0
  498. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  499. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  500. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  501. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  502. package/templates/code-review/evals/re-review/case.yaml +2 -1
  503. package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
  504. package/templates/code-review/evals/re-review-open/case.yaml +2 -1
  505. package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
  506. package/templates/code-review/evals/repo-rule/case.yaml +2 -1
  507. package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
  508. package/templates/code-review/evals/two-defects/case.yaml +2 -1
  509. package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
  510. package/templates/code-review/rules/CODEREVIEW.md +1 -1
  511. package/templates/code-review/skills/review/DEEP.md +5 -4
  512. package/templates/code-review/skills/review/REVIEWER.md +5 -4
  513. package/templates/code-review/skills/review/SKILL.md +11 -6
  514. package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
  515. package/templates/inbound-lead/agent.md +26 -16
  516. package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
  517. package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
  518. package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
  519. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
  520. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
  521. package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
  522. package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
  523. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
  524. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
  525. package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
  526. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
  527. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
  528. package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
  529. package/templates/kyb/agent.md +15 -5
  530. package/templates/kyb/evals/adverse-media/prompt.md +2 -7
  531. package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
  532. package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
  533. package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
  534. package/templates/kyb/evals/name-collision/prompt.md +2 -6
  535. package/templates/kyb/evals/no-invention/prompt.md +2 -6
  536. package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
  537. package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
  538. package/templates/kyb/kyb.schema.json +8 -7
  539. package/templates/kyb/skills/kyb/SKILL.md +9 -6
  540. package/templates/market-monitor/agent.md +19 -12
  541. package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
  542. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
  543. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
  544. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
  545. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  546. package/templates/release-notes/agent.md +32 -10
  547. package/templates/release-notes/evals/draft-not-publish/case.yaml +5 -4
  548. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
  549. package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
  550. package/templates/release-notes/evals/issue-write-refused/case.yaml +5 -4
  551. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
  552. package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
  553. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
  554. package/templates/release-notes/evals/learned-style/case.yaml +2 -1
  555. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
  556. package/templates/release-notes/evals/other-repo/case.yaml +24 -0
  557. package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
  558. package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
  559. package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
  560. package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
  561. package/templates/release-notes/evals/other-repo/prompt.md +32 -0
  562. package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
  563. package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
  564. package/templates/release-notes/notes.schema.json +1 -1
  565. package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
  566. package/dist/console/assets/index-Cn6JX1uH.js +0 -563
  567. package/dist/console/assets/index-DRN62V5v.css +0 -1
  568. package/dist/host-calls.d.ts +0 -20
  569. package/dist/host-calls.js +0 -12
  570. package/dist/runner/adapters/pi-computer.d.ts +0 -7
  571. package/dist/runner/adapters/pi-computer.js +0 -43
  572. package/dist/tool-blurbs.d.ts +0 -4
  573. package/dist/tool-blurbs.js +0 -28
  574. package/dist/tool-budget.d.ts +0 -38
  575. package/dist/tool-budget.js +0 -62
  576. package/dist/workspace/computer-script.d.ts +0 -37
  577. package/dist/workspace/computer-script.js +0 -138
  578. package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
  579. package/templates/code-review/evals/injection/graders/schema.md +0 -5
  580. package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
  581. package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
  582. package/templates/code-review/evals/null-name/graders/schema.md +0 -5
  583. package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
  584. package/templates/code-review/evals/re-review/graders/schema.md +0 -5
  585. package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
  586. package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
  587. package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
  588. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
  589. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
  590. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
  591. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
  592. package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
  593. package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
  594. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
  595. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
  596. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
  597. package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
  598. package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
  599. package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
  600. package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
  601. package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
  602. package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
  603. package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
  604. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
  605. package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
  606. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
  607. package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
  608. package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
  609. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
  610. package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
  611. package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
  612. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
  613. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
  614. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
  615. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
  616. package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
  617. package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
  618. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
  619. package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
  620. package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
@@ -15,7 +15,7 @@ import { defineExtension, ROOT_CONVERSATION_ID, wrapTool } from "@earendil-works
15
15
  import { chargedCost, DecisionProviderError, EffectFailure, inspectWorkflow } from "@parcha/agentrun-dsl";
16
16
  import { modelPortFor } from "@parcha/agentrun-kernel";
17
17
  import { startModelProxy } from "@parcha/agentrun-kernel/host";
18
- import { CapRefused, checkRaise, DecisionPriceUnreadable, DECISION_SESSION, followUpOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
18
+ import { CapRefused, checkRaise, DecisionPriceUnreadable, DECISION_SESSION, followUpOf, freeCeilingMessage, freeModelRequestsOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
19
19
  import { completer } from "../llm.js";
20
20
  // The decision providers' list prices, the catalog's read and the replay check (decision-cap.ts), with holdOf, which the
21
21
  // parity tests hold this cap's figures to.
@@ -35,19 +35,20 @@ import { searchArgs, WEB_SEARCH_TOOL } from "../web-search.js";
35
35
  import { money, pricingOf, requestPrice, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
36
36
  import { claimSecrets, withModelKeys } from "./claim-secrets.js";
37
37
  import { routeOf } from "./model-route.js";
38
- import { PI_WIRES, storeSettings } from "./adapter-run-spec.js";
38
+ import { capModelOf, PI_WIRES, storeSettings } from "./adapter-run-spec.js";
39
39
  import { policyFor } from "./adapters/pi.js";
40
40
  import { sessionProvider } from "../port-models.js";
41
41
  import { journalSessions } from "./sessions.js";
42
42
  import { KINDS, NODE_LOG_SESSION, WORKFLOW_SESSION } from "./journal-kinds.js";
43
43
  import { cutStrings } from "../key-refusal.js";
44
- import { CLOSE_MS, entriesOf } from "./loop.js";
44
+ import { CLOSE_MS } from "./loop.js";
45
45
  import { PAUSED_WORDS } from "./workflow-loop.js";
46
46
  import { heldRedactor, holdClaimed } from "./redact.js";
47
47
  import { holdStored } from "./store-secrets.js";
48
48
  import { workflowHost } from "./workflow-host.js";
49
49
  import { SUBMIT_TOOL } from "../workflow/host-tools.js";
50
- import { bookedSpend } from "./metrics.js";
50
+ import { endCostOf, runCostOf } from "./metrics.js";
51
+ import { journalEntries } from "./journal-reader.js";
51
52
  /** The one session key the workflow's model requests book under (the run's one booking sums it, runBooking). */
52
53
  const SESSION = WORKFLOW_SESSION;
53
54
  /** A call node's tool failure and a cap-held effect, as the runner's effect completed them (the loop's `failing` reads the
@@ -76,8 +77,12 @@ export async function providerFromRoute(route) {
76
77
  ...(route.provider.headers ? { headers: route.provider.headers } : {}),
77
78
  policy: await policyFor(route.provider, route.model, []),
78
79
  price: (route.price ?? (() => null)),
79
- capModel: { id: route.model, api: route.provider.api, price: route.cost ?? null, outputCeiling: route.outputCeiling ?? null },
80
+ // As a pi turn's (capModelOf): a ChatGPT plan's route is billed to the plan (CapModel.plan), and a model serve has no
81
+ // price for (a router's zeros, a gateway model nothing prices) has none, never its placeholder's $0: a cap refuses it.
82
+ capModel: capModelOf(route),
80
83
  ...(route.fetch ? { fetch: route.fetch } : {}),
84
+ ...(route.provider.plan ? { plan: true } : {}),
85
+ ...(route.provider.refused ? { refused: route.provider.refused } : {}),
81
86
  };
82
87
  }
83
88
  /** The newest raise's cap on the run's root, else none: the effective cap after takeRaises wrote this claim's raise, read
@@ -116,7 +121,6 @@ function capRuleOf(capUsd) {
116
121
  /** The claim-time builder: `specOf(claim)` the loop calls. Reads the run's launch and revision, resolves each tier's
117
122
  * provider, and returns the spec. The model proxies and the booking are started per claim (release closes them). */
118
123
  export function workflowSpecOf(deps) {
119
- const now = deps.now ?? Date.now;
120
124
  // The proxies a claim started: closed by the spec's release once the claim is done, or here when the claim fails before
121
125
  // its spec is returned (the loop then has no spec to release), so a failed claim leaves no proxy listening.
122
126
  return async (claim, run) => {
@@ -183,7 +187,10 @@ export function workflowSpecOf(deps) {
183
187
  const offered = nodeOffer(claimed.workflow);
184
188
  for (const [tier, provider] of providers) {
185
189
  const proxy = await startModelProxy({
186
- policy: await policyFor({ api: provider.api, origin: provider.origin, credential: provider.credential, ...(provider.headers ? { headers: provider.headers } : {}) }, provider.modelId, offered),
190
+ // Each request names its tier's route (ModelRequest.route), so the cap prices it as that tier books it: two tiers
191
+ // on one model id (a plan's and a paid one) are held apart, never at the other's price (capModelOf).
192
+ route: providerId(tier),
193
+ policy: await policyFor({ api: provider.api, origin: provider.origin, credential: provider.credential, ...(provider.headers ? { headers: provider.headers } : {}), ...(provider.plan ? { plan: true } : {}) }, provider.modelId, offered),
187
194
  hooks: hooks.port,
188
195
  model: provider.modelId,
189
196
  origin: provider.origin,
@@ -191,6 +198,7 @@ export function workflowSpecOf(deps) {
191
198
  price: provider.price,
192
199
  ...(provider.headers ? { headers: provider.headers } : {}),
193
200
  ...(provider.fetch ? { fetch: provider.fetch } : {}),
201
+ ...(provider.refused ? { credentialRefused: provider.refused } : {}),
194
202
  }, randomBytes(32).toString("base64url"));
195
203
  proxies.push(proxy);
196
204
  // pi-ai's client of the provider's wire at its proxy (port-models.ts sessionProvider), as pi's session reaches its own.
@@ -203,11 +211,25 @@ export function workflowSpecOf(deps) {
203
211
  throw new Error(`the workflow names tier ${String(tier)}, which this run has no model for`);
204
212
  return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId, ...(provider.named ? { named: provider.named } : {}) };
205
213
  };
206
- const capModelOf = (id) => {
207
- for (const provider of providers.values())
208
- if (provider.capModel.id === id)
214
+ // The cap's model of a request, by the route its tier's proxy names (the key its request is routed by), never by its
215
+ // bare id: a ChatGPT plan's tier and a paid tier of one model id are priced apart. A request read with no route takes
216
+ // the paid model of its id over a plan's, so a clash is never priced at the plan's $0.
217
+ const capModelOf = (id, route) => {
218
+ if (route !== undefined) {
219
+ for (const [tier, provider] of providers)
220
+ if (providerId(tier) === route)
221
+ return provider.capModel.id === id ? provider.capModel : undefined;
222
+ return undefined;
223
+ }
224
+ let plan;
225
+ for (const provider of providers.values()) {
226
+ if (provider.capModel.id !== id)
227
+ continue;
228
+ if (!provider.capModel.plan)
209
229
  return provider.capModel;
210
- return undefined;
230
+ plan ??= provider.capModel;
231
+ }
232
+ return plan;
211
233
  };
212
234
  // The cap read against every request: the run's cap, raised in place once harnessReady reads this claim's raise.
213
235
  let effectiveCapUsd = claimed.capUsd;
@@ -262,7 +284,7 @@ export function workflowSpecOf(deps) {
262
284
  agentId: claimed.agentId,
263
285
  revisionId: claimed.revisionId,
264
286
  ...(claimed.capUsd !== undefined ? { cap: capRuleOf(() => effectiveCapUsd ?? claimed.capUsd) } : {}),
265
- endPatch: async () => endPatchOf(booking, decisionCap, paidTools, run?.journal),
287
+ endPatch: async () => endPatchOf(booking, run?.journal),
266
288
  build: (loopHooks) => {
267
289
  hooks.setPark(loopHooks);
268
290
  const hostDeps = {
@@ -307,9 +329,11 @@ export function workflowSpecOf(deps) {
307
329
  // The run's ONE cap over the journal's sessions: its model requests and its decisions admit by the one rule and
308
330
  // book on one ledger (runCap's runBooking over the sessions), so each is judged on the run's whole spend and a
309
331
  // refusal's figures are the run's. Wired now the Harness is open; the proxies' hooks forward to the model booking.
310
- const sessions = journalSessions(harness, context, { flush: () => deps.store.flush() });
332
+ const sessions = journalSessions(harness, context, { flush: () => deps.store.flush(), ...(claim.runner === undefined ? {} : { claim: { runId: claim.runId, runner: claim.runner } }) });
311
333
  const writer = await sessions.open(SESSION);
312
- const run = runCap({ sessions: sessions, capUsd: () => effectiveCapUsd, mode: claimed.mode, now, modelOf: capModelOf });
334
+ // Its model nodes' requests on free models count toward the run's limit of them, capped or not. A step waiting for
335
+ // room under it (a map's branch, beside its siblings' holds) leaves at the run's stop or park, unsent.
336
+ const run = runCap({ sessions: sessions, capUsd: () => effectiveCapUsd, modelOf: capModelOf, freeRequests: freeModelRequestsOf(deps.env ?? process.env), ...(context.abortSignal ? { stopped: context.abortSignal } : {}) });
313
337
  booking = await modelPortFor(writer, {
314
338
  key: SESSION,
315
339
  label: SESSION,
@@ -318,6 +342,10 @@ export function workflowSpecOf(deps) {
318
342
  onEvent: async (event) => { if (event.type === "request_start")
319
343
  await deps.store.flush(); },
320
344
  });
345
+ // An earlier claim's requests, before the workflow sends anything: one this runner's lost claim saw answer, its
346
+ // record refused, is booked at what it reported (waiting, bounded, for one still in flight); one a dead runner left
347
+ // is booked cut (the kernel's bookCut). Read as before for the cap: cut or open, a request counts at its hold and bound.
348
+ await booking.bookCut();
321
349
  // The run's decisions book on the same cap, under their own session (DECISION_SESSION); created now the Harness is
322
350
  // open, so a decision node (which runs after this) reaches it through the deferred reference. The flush makes each
323
351
  // decision's hold durable before it is sent, as a model request's is.
@@ -361,8 +389,11 @@ export function parkOnRefusal(before, hooks, flight = { count: 0 }, steps) {
361
389
  const verdict = await before(request);
362
390
  // A refusal parks the run, as main's does, unless the request is a call node's (an `llm` call's) in flight: that
363
391
  // effect is admitted, and parked unfinished it would be left unknown; refused unsent, its call fails in the cap's
364
- // words instead (the net under the call's hold, holdAtEffects).
365
- if (verdict && "refuse" in verdict && flight.count === 0) {
392
+ // words instead (the net under the call's hold, holdAtEffects). The limit on free-model requests (freeCeilingEnd)
393
+ // ends the run even there: it is for good, every free request after it is refused too, and the run never resumes,
394
+ // so no effect is left to resume; its call's failure would end the run as the call's ("failed at <node>"), not in
395
+ // the limit's words and code.
396
+ if (verdict && "refuse" in verdict && (flight.count === 0 || freeCeilingMessage(verdict.refuse) !== undefined)) {
366
397
  const refusal = verdict;
367
398
  // Its node: the one workflow step under way (every model request goes through the run's one port, which names no
368
399
  // node); none when several run at once, as a map's items do.
@@ -483,7 +514,7 @@ export function callHoldOf(tool, input, env, modelOfTier) {
483
514
  if (planeOf(env)[tool] !== "parallel")
484
515
  return NO_HOLD(tool);
485
516
  const fee = tool === "web_search" ? parallelSearchFee(searchArgs(input).n) : parallelExtractFee(1);
486
- // Who charges for it (main's charge row's charged_by), as paidOn names it: the hold is the record its request books under.
517
+ // Who charges for it (main's charge row's charged_by), as paidRequest names it: the hold is the record its request books under.
487
518
  return { usd: fee.usd, name: fee.name, basis: fee.basis, chargedBy: fee.by };
488
519
  }
489
520
  if (tool === "llm") {
@@ -493,7 +524,7 @@ export function callHoldOf(tool, input, env, modelOfTier) {
493
524
  const bytes = (text) => (typeof text === "string" ? Buffer.byteLength(text, "utf8") : 0);
494
525
  const bound = bytes(input.prompt) + bytes(input.system) + LLM_FRAMING_BYTES;
495
526
  const output = typeof input.maxTokens === "number" ? input.maxTokens : Math.max(LLM_DEFAULT_OUTPUT, model.outputCeiling ?? 0);
496
- const usd = requestPrice(pricingOf(model.price), bound, undefined, Date.now(), "strict", model.id).worst(output);
527
+ const usd = requestPrice(pricingOf(model.price), bound)(output);
497
528
  return { usd, name: `the ${model.id} answer`, basis: `${model.id}'s worst price for ${bound} input and ${output} output tokens`, llm: { price: model.price } };
498
529
  }
499
530
  return NO_HOLD(tool);
@@ -629,7 +660,7 @@ export function holdAtEffects(cap, deps) {
629
660
  // The net: an `llm` answer priced at its own usage above what was held for it.
630
661
  const usage = hold.llm?.price && value && typeof value === "object" ? value.usage : undefined;
631
662
  if (usage && hold.llm?.price) {
632
- const charged = pricingOf(hold.llm.price)({ cached: 0, fresh: usage.input_tokens ?? 0 }, usage.output_tokens ?? 0);
663
+ const charged = pricingOf(hold.llm.price)(usage.input_tokens ?? 0, usage.output_tokens ?? 0);
633
664
  if (charged > hold.usd + 1e-12)
634
665
  return failed(params.node.label, `its answer cost ${money(charged)}, above the ${money(hold.usd)} it held before it ran.`);
635
666
  }
@@ -736,32 +767,18 @@ function runEffectOf(claimed, complete, env, policy, paidTools, log) {
736
767
  }
737
768
  });
738
769
  }
739
- /** The end's cost and metrics: what every model request of the run cost (the booking) plus what its decisions and its
740
- * call nodes' paid requests cost (the decision cap, the paid tools), one spend for the run. Unknown (no figure) once any
741
- * part is unknown. */
742
- /** What the run's decisions cost by their booking (bookedSpend, "decisions"), read from only what that needs: the root's
743
- * session keys (journalSessions writes them there) and the decisions session's own conversation, never the run's model
744
- * or tool records, so the read stays small within the end patch's bound. No decisions session: none, $0. */
745
- async function decisionsBooked(journal) {
746
- const root = await entriesOf(journal, ROOT_CONVERSATION_ID, BACKGROUND_CONTEXT);
747
- const key = root.find((entry) => entry.kind === KINDS.sessionKey && entry.data?.key === DECISION_SESSION);
748
- const conversation = key?.data?.conversation;
749
- if (conversation == null)
750
- return 0;
751
- const decisions = await entriesOf(journal, conversation, BACKGROUND_CONTEXT);
752
- return bookedSpend([key, ...decisions], "decisions").usd;
753
- }
754
- async function endPatchOf(booking, decisionCap, paidTools, journalOf) {
770
+ /** The end's cost: its booking's, by the one rule every reader of an ended run's cost takes (metrics.ts runCostOf, as the
771
+ * pi and CLI specs store it): every model request of its sessions, its call nodes' paid requests and its decisions, each
772
+ * at what it was booked at, never the cap's figure for it (an answer with no price of its own is unknown, never its
773
+ * hold). Unknown once any one is, written as null, never left out (an end that says nothing leaves the $0 the run read
774
+ * before a response). With no journal to read, unknown. */
775
+ async function endPatchOf(booking, journalOf) {
755
776
  if (!booking)
756
777
  return {};
757
- const model = booking.spentUsd();
758
- // A decision's cost is what its booking says it charged (bookedSpend over the decisions session's records, as the pi and
759
- // CLI specs read it): one its provider reported no cost for is unknown, never the hold the cap counts it at
760
- // (decisionCap.spentUsd, which stays the cap's own figure). With no journal to read, any decision is unknown.
761
- const decision = !decisionCap ? 0 : journalOf ? await decisionsBooked(journalOf()) : null;
762
- const paid = paidTools ? paidTools.spentUsd() : 0;
763
- // Unknown is written as null, never left out (an end that says nothing leaves the $0 the run read before a response).
764
- return { costUsd: model === null || decision === null || paid === null ? null : model + decision + paid };
778
+ if (!journalOf)
779
+ return { costUsd: null };
780
+ // With whether the figure is the most it can have cost (a request cut at its hold counted in it), stored beside it.
781
+ return endCostOf(runCostOf((await journalEntries(journalOf(), BACKGROUND_CONTEXT))));
765
782
  }
766
783
  /** The run's one cap as a WorkflowCap: model nodes and call nodes pass through (their money is on the proxy), and a
767
784
  * decision node is priced before the DSL driver admits its request (`judge`) and held, sent and settled through the run's
@@ -882,9 +899,8 @@ export function decisionJudge(inner, deps) {
882
899
  async function decisionRequestOf(provider, params) {
883
900
  const id = params.decisionId ?? `decision:${params.executionPath ?? ""}:${params.label}${params.item ? `:${params.item.index}` : ""}`;
884
901
  const inputTokens = Buffer.byteLength(JSON.stringify({ state: params.state ?? null, questions: params.questions }), "utf8");
885
- const questions = Object.keys(params.questions).length;
886
902
  const images = Object.keys(params.images ?? {}).length;
887
- const base = { kind: "decision", id, inputTokens, questions, images };
903
+ const base = { kind: "decision", id, inputTokens, images };
888
904
  // Parallel charges by the request, nothing by the token: priced at $0 a token and its request price, never as a model
889
905
  // with no price (which the cap refuses, failing every capped workflow's Parallel decision).
890
906
  if (provider.id === "parallel")
@@ -989,7 +1005,7 @@ function bookedNodeTools(binding, paid, park) {
989
1005
  ...tool,
990
1006
  execute: (args, api, context) => {
991
1007
  const ledger = paid();
992
- return bookedIn(ledger ? { call: api.callId, record: async () => { }, paid: ledger, pause: async (refusal) => park({ message: refusal.refuse, forGood: false, ...(refusal.figures ? { figures: refusal.figures } : {}) }) } : undefined, () => tool.execute(args, api, context));
1008
+ return bookedIn(ledger ? { call: api.callId, paid: ledger, pause: async (refusal) => park({ message: refusal.refuse, forGood: false, ...(refusal.figures ? { figures: refusal.figures } : {}) }) } : undefined, () => tool.execute(args, api, context));
993
1009
  },
994
1010
  })),
995
1011
  };
@@ -1017,8 +1033,7 @@ async function readClaim(deps, runId) {
1017
1033
  const launch = launchRow.body;
1018
1034
  const input = launch && typeof launch.input === "object" && launch.input !== null ? launch.input : {};
1019
1035
  const capUsd = typeof launch?.max_cost_usd === "number" ? launch.max_cost_usd : undefined;
1020
- const mode = launch?.cap_mode === "strict" ? "strict" : "expected";
1021
1036
  const workRoot = typeof launch?.documents === "string" ? launch.documents : "/tmp";
1022
- return { agentId: run.agentId, revisionId: run.revisionId, revision: revision, workflow: revision.body.workflow, input, capUsd, mode, workRoot, plane: launch?.plane };
1037
+ return { agentId: run.agentId, revisionId: run.revisionId, revision: revision, workflow: revision.body.workflow, input, capUsd, workRoot, plane: launch?.plane };
1023
1038
  }
1024
1039
  export { BACKGROUND_CONTEXT };
@@ -2,12 +2,12 @@ import type { Revision } from "./agent-rows.js";
2
2
  import type { MessageOrigin } from "./timeline/index.js";
3
3
  import { type AgentEntry, type ExternalRef } from "./agents-store.js";
4
4
  import { ApiError, type InputIssue } from "./errors.js";
5
- import { type LearningMode, type Seed, type Shown } from "./learning.js";
5
+ import { type LearningMode, type NoteUsed, type Seed, type Shown } from "./learning.js";
6
6
  import { type Place } from "./place.js";
7
7
  import { type RepoBinding } from "./run-repo.js";
8
- import { type LaunchDisk, type RunLaunch } from "./run-launch.js";
8
+ import { type LaunchDisk, type RunLaunch, type SeedFailed } from "./run-launch.js";
9
9
  import { type ApprovalDecision, type RunMoment } from "./run-view.js";
10
- import { type NewRevision, type RunOrigin, type RunRow, type Store } from "./store/index.js";
10
+ import { type NewRevision, type RevisionRow, type RunOrigin, type RunRow, type Store } from "./store/index.js";
11
11
  import { type ToolSettingsMap } from "./tool-plane.js";
12
12
  import type { RunTrigger } from "./triggers.js";
13
13
  import { type Json } from "./validate.js";
@@ -85,7 +85,18 @@ export declare function raiseCap(store: RunsStore, moment: RunMoment, cap: numbe
85
85
  * again changes nothing, another is 409 already-answered — and a run with no such waiting call is 404. Two answers at once
86
86
  * each write or lose to the store's one-answer index, and the one that loses reads the one that won. The note is the
87
87
  * person's words, carried on the command for the run's gate. */
88
- export declare function approve(store: RunsStore, moment: RunMoment, id: string, decision: "allow" | "deny", note?: string): Promise<void>;
88
+ export declare function approve(store: RunsStore, moment: RunMoment, id: string, decision: "allow" | "deny", note?: string, confirmed?: boolean): Promise<void>;
89
+ /** A UUIDv7 run id: time-ordered, so a listing by start time is stable, and unique per run. */
90
+ export declare function uuidv7(now?: number): string;
91
+ /** The revision's body fields a start reads: its default cap, its place, and (agentic) its tools, for the place
92
+ * fallback. Read with the shapes the old start read them with. */
93
+ type StartBody = {
94
+ readonly maxCostUsd?: number;
95
+ readonly place?: unknown;
96
+ readonly tools?: readonly unknown[];
97
+ readonly learning?: boolean | "notes";
98
+ readonly thinking?: unknown;
99
+ };
89
100
  /** The pieces a start needs that live in the server's request layer, not here: the leaf validators (the create body's field
90
101
  * issues, the revision a run pins, a run's input against its schema, the hint told from the revision, a revision this host
91
102
  * cannot run), the uploads check, the place fallback, the title's redaction, the plane's settings and key environment, and
@@ -111,6 +122,10 @@ export interface StartDeps {
111
122
  runnable(revision: Revision, place: Place, options: {
112
123
  capped: boolean;
113
124
  }): Promise<void>;
125
+ /** The revision a run starts on, its MCP tools pinned: one that grants an MCP tool and was saved with no pin (before
126
+ * pins were made at save, or an inline agent's version stored then) is pinned once, at its first run (server.ts
127
+ * pinFirst); any other as it is. */
128
+ pinFirst?(revision: Revision): Promise<Revision>;
114
129
  /** The uploaded files named by file_ids, ready to copy; throws when one is not ready (server.ts uploads.readyFiles). The
115
130
  * copy into the run's work/ is the runner's at its claim; this only checks they are ready before the run starts. */
116
131
  readyFiles(ids: readonly unknown[]): Promise<unknown>;
@@ -183,6 +198,25 @@ export interface StartOptions {
183
198
  readonly capped?: boolean;
184
199
  readonly from?: MessageOrigin;
185
200
  }
201
+ /** The run's learning start as the old start decided it (learning-run.ts onStart): undefined when the run does not learn (the
202
+ * server's learning off, a workflow revision, or its revision does not say learning), else the notes its # Learned section
203
+ * names and the # Learned text (learnedParts, the one decision the runner puts in the prompt), the seed sha it starts
204
+ * from and the count of all the seed's notes before the budget picked `given` (seedNotes) — or given empty, seed null and no
205
+ * seedNotes when its seed cannot be read (a learning fault never refuses a run). `use`: the run's start said `learning:
206
+ * "use"`, so it starts from what its agent learned, its revision's own learning aside, and keeps nothing. */
207
+ export declare function learningStartFor(deps: StartDeps, entry: AgentEntry, revision: Revision, rbody: StartBody, input: unknown, use?: boolean): Promise<{
208
+ given: NoteUsed[];
209
+ seed: string | null;
210
+ section: string;
211
+ seedNotes?: number;
212
+ notesLeftOut?: string[];
213
+ skills?: string[];
214
+ workflows?: string[];
215
+ notesOnly?: true;
216
+ gradeModel?: string;
217
+ seedFailed?: SeedFailed;
218
+ use?: true;
219
+ } | undefined>;
186
220
  /** Starts a run of `entry`'s agent from a create body, as POST /agents/{id}/runs starts it: every check the old start made
187
221
  * before a run started (prepareLaunch), then an INSERT — a queued run and its launch body in one transaction
188
222
  * (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
@@ -200,6 +234,9 @@ export interface InlineAgent {
200
234
  readonly revision: NewRevision & {
201
235
  readonly note?: string;
202
236
  };
237
+ /** The revision its version already has here (Agents.externalRevision), when this is not the version's first run: the
238
+ * run starts on it, as a run of a stored agent starts on its revision. */
239
+ readonly stored?: RevisionRow;
203
240
  }
204
241
  /** Starts a run of an agent given inline, as POST /agents/{id}/runs starts a run of a stored one: the same checks over the
205
242
  * revision the definition makes (prepareLaunch), then ONE transaction (store.runs.createInline) that writes the agent on
@@ -1,3 +1,5 @@
1
+ import { nativeOf } from "./native/binding.js";
2
+ import { launchNative } from "./native/connection.js";
1
3
  // The write half of the run's server cut (design 2.1, "the runner takes every run"): the functions the v2 routes call to
2
4
  // start a run and to act on one (message, stop, raise, approve, archive), over the one store (A). The old per-run-process
3
5
  // model (runs.ts: a child process, an HTTP door, serve.json, carry-back) is gone; the server only writes rows. A start is an
@@ -25,7 +27,8 @@ import { repoOf } from "./run-repo.js";
25
27
  import { launchBody } from "./run-launch.js";
26
28
  import { raiseFollowUpId } from "./run-view.js";
27
29
  import { sendCommand } from "./runner/commands.js";
28
- import { AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint } from "./store/index.js";
30
+ import { AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
31
+ import { canonical } from "./store/agent-body.js";
29
32
  import { toolingOf } from "./tools.js";
30
33
  import { planeFor } from "./tool-plane.js";
31
34
  import { clip } from "./web-fetch-direct.js";
@@ -77,6 +80,7 @@ export async function stop(store, runId) {
77
80
  const row = await store.runs.get(runId);
78
81
  if (!row || row.importedFrom)
79
82
  return false;
83
+ await refuseSdkStop(store, runId);
80
84
  try {
81
85
  await sendCommand(store, runId, { kind: "stop", body: {} });
82
86
  return true;
@@ -94,6 +98,7 @@ export async function stop(store, runId) {
94
98
  export async function cancel(store, moment) {
95
99
  if (moment.importedSource !== undefined)
96
100
  return false;
101
+ await refuseSdkStop(store, moment.id);
97
102
  // Already ended, or already ending (an outcome being written, or a cancel in flight): a run's first end is its last.
98
103
  if (moment.terminal || moment.cancelled)
99
104
  return false;
@@ -107,6 +112,24 @@ export async function cancel(store, moment) {
107
112
  throw error;
108
113
  }
109
114
  }
115
+ /** Older rows can lack launch metadata. Only that typed absence leaves their controls unchanged; a failed read
116
+ * must still fail the command, since it could be hiding native or SDK execution constraints. */
117
+ async function controlLaunchBody(store, runId) {
118
+ try {
119
+ return (await store.runs.launch(runId)).body;
120
+ }
121
+ catch (error) {
122
+ if (error instanceof StoreLaunchMissing)
123
+ return undefined;
124
+ throw error;
125
+ }
126
+ }
127
+ /** Only the application can abort its SDK and tools. An HTTP acknowledgement must not pretend that it did. */
128
+ async function refuseSdkStop(store, runId) {
129
+ const launch = await controlLaunchBody(store, runId);
130
+ if (isObject(launch) && launch.sdk)
131
+ throw new ApiError("not_continuable", "This agent runs in your backend SDK. Cancel it using the original application's cancellation signal; its wrapper will report that outcome here.");
132
+ }
110
133
  /** Pauses a workflow run, or resumes it (pauseRun/resumeRun): a pause or resume command the run's runner reads and applies.
111
134
  * Verbatim from runs.ts pause: an agentic run has no pause here (501, a turn is stopped instead), an ended or cancelling one
112
135
  * takes none (409). Returns the run id and whether it is paused; the route adds the run's status from its view. The runner
@@ -133,6 +156,11 @@ export const resume = (store, moment) => pauseOrResume(store, moment, false);
133
156
  export async function message(store, moment, content, { requestId, answers = true, origin, queue, launchSealed, beforeSubmit } = {}) {
134
157
  if (moment.importedSource !== undefined)
135
158
  throw importedRefusal(moment);
159
+ const launchBody = await controlLaunchBody(store, moment.id);
160
+ if (isObject(launchBody) && launchBody.sdk)
161
+ throw new ApiError("not_continuable", "Backend SDK runs are single-task sessions. Start a new SDK call for another task.");
162
+ if (nativeOf(launchBody))
163
+ throw new ApiError("input_invalid", "Native jobs do not support in-session steering or follow-up messages. Start a new native run.");
136
164
  // Archiving closes a run: it, or a run of its archived agent, takes no message, said as archived (never as finished).
137
165
  if (moment.archived !== undefined)
138
166
  throw archivedRefusal(moment);
@@ -296,7 +324,7 @@ async function endBefore(store, runId, { before = Number.POSITIVE_INFINITY, take
296
324
  * again changes nothing, another is 409 already-answered — and a run with no such waiting call is 404. Two answers at once
297
325
  * each write or lose to the store's one-answer index, and the one that loses reads the one that won. The note is the
298
326
  * person's words, carried on the command for the run's gate. */
299
- export async function approve(store, moment, id, decision, note) {
327
+ export async function approve(store, moment, id, decision, note, confirmed = false) {
300
328
  const settle = (given) => {
301
329
  if (given.decision !== decision)
302
330
  throw alreadyAnswered(id, given.decision, given.ended === true);
@@ -315,6 +343,10 @@ export async function approve(store, moment, id, decision, note) {
315
343
  }
316
344
  if (!(moment.approvalIds?.has(id) ?? false))
317
345
  throw new ApiError("not_found", `The run ${moment.id} has no tool call ${id} waiting for approval.`);
346
+ // A call its run's pin marks destructive takes a second, explicit confirm to allow: nothing is written without it. The
347
+ // issue carries its own example, so the 422's telling (explain.ts) adds none to a sentence that already says what to send.
348
+ if (decision === "allow" && !confirmed && moment.destructiveIds?.has(id))
349
+ throw invalid([{ field: "confirm_destructive", reason: "missing", message: `The tool call ${id} is one its MCP server marks destructive. To allow it, confirm a second time and send the allow again with confirm_destructive: true.`, example: true }]);
318
350
  const ending = await endBefore(store, moment.id);
319
351
  if (ending)
320
352
  throw alreadyAnswered(id, ending.decision);
@@ -352,7 +384,7 @@ export async function approve(store, moment, id, decision, note) {
352
384
  }
353
385
  // ---- start -----------------------------------------------------------------------------------------------------------
354
386
  /** A UUIDv7 run id: time-ordered, so a listing by start time is stable, and unique per run. */
355
- function uuidv7(now = Date.now()) {
387
+ export function uuidv7(now = Date.now()) {
356
388
  const bytes = randomBytes(16);
357
389
  bytes.writeUIntBE(now, 0, 6);
358
390
  bytes[6] = (bytes[6] & 0x0f) | 0x70;
@@ -368,12 +400,12 @@ const noShown = { text: (text) => text, name: (name) => name, holds: () => false
368
400
  * from and the count of all the seed's notes before the budget picked `given` (seedNotes) — or given empty, seed null and no
369
401
  * seedNotes when its seed cannot be read (a learning fault never refuses a run). `use`: the run's start said `learning:
370
402
  * "use"`, so it starts from what its agent learned, its revision's own learning aside, and keeps nothing. */
371
- async function learningStartFor(deps, entry, revision, rbody, input, use) {
403
+ export async function learningStartFor(deps, entry, revision, rbody, input, use = false) {
372
404
  // A run started with `learning: "use"` starts from what its agent learned whatever its revision says, and keeps nothing
373
405
  // (no grade model: nothing is graded); the server's learning off still gives it nothing.
374
406
  const learns = deps.learning !== undefined && deps.learning !== "off" && revision.kind === "agentic" && (learnsOf(rbody.learning) || use);
375
407
  // `learning: "notes"`: its notes and skills, never a learned workflow (none offered, none asked for at its end).
376
- const notesOnly = rbody.learning === "notes" ? { notesOnly: true } : {};
408
+ const notesOnly = rbody.learning === "notes" || nativeOf(revision.body) ? { notesOnly: true } : {};
377
409
  if (!learns || !deps.seedFor)
378
410
  return undefined;
379
411
  const grade = use ? { use: true } : deps.gradeModel ? { gradeModel: deps.gradeModel } : {};
@@ -393,7 +425,7 @@ async function learningStartFor(deps, entry, revision, rbody, input, use) {
393
425
  const notesLeftOut = left.map((note) => options.shown.name(note.file));
394
426
  // The learned skills the seed offers the run, by name: each with its files (one over a run's skill budget at all is held
395
427
  // by its size and never laid) and no host secret in it, as chooseSkills leaves them out. The claim lays them; the
396
- // end-of-run turn counts the runs each served (runner/learning-end.ts draftForOf).
428
+ // agent's impact counts the runs each served.
397
429
  const skills = (seeded.seed.skills ?? []).flatMap(({ name, files }) => (files && !options.shown.holds(name) && !Object.entries(files).some(([path, text]) => options.shown.holds(path) || options.shown.holds(text)) ? [name] : []));
398
430
  // The learned workflows its learned_workflow tool runs, by name, as the claim chooses them (chooseWorkflows): what the
399
431
  // agent's impact counts a run as started from, beside its notes and skills.
@@ -410,6 +442,8 @@ async function learningStartFor(deps, entry, revision, rbody, input, use) {
410
442
  * runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
411
443
  * starts a second. */
412
444
  export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed } = {}) {
445
+ if (entry.revision?.body?.sdk)
446
+ throw new ApiError("agent_not_runnable", "This agent runs in your backend SDK. Start it through its SDK learning wrapper; AgentRun does not launch its tools or credentials.");
413
447
  const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
414
448
  const runId = (deps.newRunId ?? uuidv7)();
415
449
  try {
@@ -444,6 +478,8 @@ async function withHeldFiles(deps, runId, launch, write) {
444
478
  throw error;
445
479
  }
446
480
  }
481
+ /** 409 external_body_conflict: a version that already ran here, given with a different definition. */
482
+ const bodyConflict = ({ source, kind, id, version }) => new ApiError("external_body_conflict", `${source} ${kind} ${id} version ${version} already ran here with a different definition. A version's definition never changes here: publish a new version and run that.`, { details: { external: { source, kind, id, version } } });
447
483
  /** Starts a run of an agent given inline, as POST /agents/{id}/runs starts a run of a stored one: the same checks over the
448
484
  * revision the definition makes (prepareLaunch), then ONE transaction (store.runs.createInline) that writes the agent on
449
485
  * its reference's first run and the revision on its version's first run, or reads them, then the run and its launch. The
@@ -451,8 +487,11 @@ async function withHeldFiles(deps, runId, launch, write) {
451
487
  * earlier ones. A different definition under a version already run is 409 external_body_conflict, nothing written; under
452
488
  * `origin`, a key that already started a run gets that run, as startRun's. */
453
489
  export async function startInline(store, deps, inline, body, { origin, sealed } = {}) {
454
- const { external, revision } = inline;
490
+ const { external, revision, stored: storedRevision } = inline;
455
491
  const ref = externalKey(external);
492
+ // A version's body never changes here: a different one is refused before anything else is read or written.
493
+ if (storedRevision && canonical(storedRevision.body) !== canonical(revision.body))
494
+ throw bodyConflict(external);
456
495
  const mapped = await store.agents.byExternal(ref);
457
496
  const stored = mapped ? await getAgent(store, mapped.id) : null;
458
497
  // A version's first run brings the agent's name and description up to it, in the start's own transaction (createInline),
@@ -467,21 +506,19 @@ export async function startInline(store, deps, inline, body, { origin, sealed }
467
506
  };
468
507
  // A store revision is the revision the run path reads as a pi Revision (its body is the revision body), as pinnedOf hands
469
508
  // one across.
470
- const { launch } = await prepareLaunch(deps, entry, body, { revision: revision });
509
+ const { launch } = await prepareLaunch(deps, entry, body, { revision: (storedRevision ?? revision) });
471
510
  const runId = (deps.newRunId ?? uuidv7)();
472
511
  try {
473
512
  return await withHeldFiles(deps, runId, launch, () => store.runs.createInline({
474
513
  agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
475
- revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}) },
514
+ revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== undefined ? { monidPin: revision.monidPin } : {}) },
476
515
  run: { id: runId, ...(origin ? { origin } : {}) },
477
516
  launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) },
478
517
  }));
479
518
  }
480
519
  catch (error) {
481
- if (error instanceof ExternalBodyConflict) {
482
- const { source, kind, id, version } = external;
483
- throw new ApiError("external_body_conflict", `${source} ${kind} ${id} version ${version} already ran here with a different definition. A version's definition never changes here: publish a new version and run that.`, { details: { external: { source, kind, id, version } } });
484
- }
520
+ if (error instanceof ExternalBodyConflict)
521
+ throw bodyConflict(external);
485
522
  if (origin && error instanceof StoreConstraint) {
486
523
  const existing = await store.runOfOrigin(origin.key);
487
524
  const row = existing && (await store.runs.get(existing.runId));
@@ -511,12 +548,17 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
511
548
  // Each a ready file, before anything starts: checked ready here, then named in the launch (in order) for the runner to
512
549
  // copy into the run's work/inputs/ at its claim.
513
550
  const fileIds = Array.isArray(body.file_ids) ? body.file_ids : [];
514
- if (fileIds.length)
515
- await deps.readyFiles(fileIds);
516
551
  const pinned = await pinnedOf();
517
552
  if (!pinned)
518
553
  throw invalid([{ field: "revision", reason: "not_an_option", message: typeof body.revision === "string" ? `${body.revision} is not a revision of the agent ${entry.agent.id}` : `the agent ${entry.agent.id} has no current revision` }]);
519
554
  const { revision } = pinned;
555
+ const native = nativeOf(revision.body);
556
+ if (native && !nativeOf(entry.revision?.body)?.connected)
557
+ throw new ApiError("agent_not_runnable", "This native connection is disconnected. Reconnect its source project before starting any revision.");
558
+ if (native && (body.effort !== undefined || fileIds.length || body.archil_disk !== undefined))
559
+ throw new ApiError("input_invalid", "Native jobs use their original effort and project files. Run effort overrides, uploaded file_ids and Archil disks are unavailable; edit the native configuration or source project instead.");
560
+ if (fileIds.length)
561
+ await deps.readyFiles(fileIds);
520
562
  const rbody = revision.body;
521
563
  const input = body.input;
522
564
  const wrong = await deps.inputIssuesOf(revision, input);
@@ -526,12 +568,10 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
526
568
  const cap = typeof body.max_cost_usd === "number" ? body.max_cost_usd : rbody.maxCostUsd;
527
569
  if (capped && cap === undefined)
528
570
  throw invalid([{ field: "max_cost_usd", reason: "missing", message: "Every run a trigger starts is capped: give the trigger's target a max_cost_usd or set the agent's." }]);
529
- // How its cap prices a request: the run's own, else the agent's, else expected (cap.ts). Only a run with a cap has one.
530
- if (body.cap_mode !== undefined && cap === undefined)
531
- throw invalid([{ field: "cap_mode", reason: "not_allowed", message: "cap_mode says how a run's cap prices its requests, and this run has no cap: give it a max_cost_usd, or set the agent's." }]);
532
- const capMode = cap === undefined ? undefined : typeof body.cap_mode === "string" ? body.cap_mode : rbody.capMode;
533
571
  const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
534
- await deps.runnable(revision, place, { capped: cap !== undefined });
572
+ // Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
573
+ // its server could not be listed, is refused with the rest (runnable).
574
+ await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined });
535
575
  // A held computer (computer-held.ts): only one that speaks the protocol, its kind as the claim reads it (the
536
576
  // revision's computer, else its place's).
537
577
  const hold = holdOf(body, (settingOfDefinition(rbody)?.computer ?? computerOfPlace(place)).kind);
@@ -565,7 +605,8 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
565
605
  // The run's effort: its own, else its revision's saved thinking, else the host's AGENT_THINKING (each a thinking level,
566
606
  // else none). Nothing set: none, so the run gets no effort note and its harness's own default. Kept in its launch, so
567
607
  // its harness's thinking, its guidance and its metrics all read the one value.
568
- const effort = typeof body.effort === "string" ? body.effort : (thinkingLevel(rbody.thinking) ?? thinkingLevel(deps.planeEnv().AGENT_THINKING));
608
+ const effort = native ? undefined : typeof body.effort === "string" ? body.effort : (thinkingLevel(rbody.thinking) ?? thinkingLevel(deps.planeEnv().AGENT_THINKING));
609
+ const nativeLaunch = native?.remote ? native : native ? await launchNative(native) : undefined;
569
610
  // The repository a person's run reaches (run-repo.ts): the one the body names when the agent is bound to it, else the
570
611
  // agent's one repository when the first message names none. A trigger's run takes its repository from its event.
571
612
  const namedRepo = typeof body.repo === "string" ? body.repo : undefined;
@@ -575,6 +616,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
575
616
  if (picked.refused)
576
617
  throw invalid([{ field: "repo", reason: "not_allowed", message: picked.refused }]);
577
618
  const launch = {
619
+ ...(nativeLaunch ? { native: nativeLaunch } : {}),
578
620
  input,
579
621
  ...(picked.repo !== undefined ? { repo: picked.repo } : {}),
580
622
  title: clip(redacted(title.trim().replace(/\s+/g, " "), deps.serverSecrets()), 80),
@@ -582,7 +624,6 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
582
624
  harness: harnessOfBody(revision.body),
583
625
  ...(effort !== undefined ? { effort } : {}),
584
626
  ...(cap !== undefined ? { maxCostUsd: cap } : {}),
585
- ...(capMode !== undefined ? { capMode } : {}),
586
627
  ...(Object.keys(plane).length ? { plane } : {}),
587
628
  ...(deps.approvers !== undefined ? { approvers: deps.approvers } : {}),
588
629
  ...(deps.documents !== undefined ? { documents: deps.documents } : {}),
@@ -590,6 +631,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
590
631
  ...(deps.boxAllowSet ? { boxAllowSet: true } : {}),
591
632
  ...(fileIds.length ? { files: fileIds } : {}),
592
633
  ...(learning ? { learning } : {}),
634
+ ...(body.workflow_first === false ? { workflowFirst: false } : {}),
593
635
  ...(trigger ? { trigger } : {}),
594
636
  ...(from ? { inputOrigin: from } : {}),
595
637
  ...(model ? { model } : {}),