@parcha/agentrun-serve 0.1.0-beta.38 → 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 (410) hide show
  1. package/CHANGELOG.md +418 -0
  2. package/README.md +325 -124
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +0 -2
  6. package/dist/agents-store.d.ts +5 -5
  7. package/dist/agents-store.js +14 -14
  8. package/dist/bash-read-only.js +2 -1
  9. package/dist/cap-short.d.ts +12 -0
  10. package/dist/cap-short.js +60 -0
  11. package/dist/cap.d.ts +3 -10
  12. package/dist/cap.js +2 -5
  13. package/dist/catalog.d.ts +0 -5
  14. package/dist/catalog.js +1 -5
  15. package/dist/chatgpt-plan.d.ts +163 -0
  16. package/dist/chatgpt-plan.js +549 -0
  17. package/dist/cli.js +26 -6
  18. package/dist/composio-preset.d.ts +8 -0
  19. package/dist/composio-preset.js +8 -7
  20. package/dist/composio-triggers.d.ts +113 -0
  21. package/dist/composio-triggers.js +411 -0
  22. package/dist/computer-calls.js +2 -2
  23. package/dist/computer-commands.d.ts +2 -0
  24. package/dist/computer-commands.js +7 -3
  25. package/dist/computer-live.d.ts +7 -2
  26. package/dist/computer-live.js +9 -5
  27. package/dist/computer-routes.d.ts +2 -2
  28. package/dist/computer-routes.js +2 -2
  29. package/dist/computer-setting.d.ts +3 -3
  30. package/dist/computer-setting.js +5 -5
  31. package/dist/computer-view.d.ts +15 -0
  32. package/dist/computer-view.js +16 -2
  33. package/dist/computer-viewer.js +14 -1
  34. package/dist/computers.d.ts +5 -2
  35. package/dist/computers.js +9 -5
  36. package/dist/console/assets/index-BNhZs-jp.css +1 -0
  37. package/dist/console/assets/index-BQv5aOGB.js +700 -0
  38. package/dist/console/index.html +2 -2
  39. package/dist/console-links.js +3 -3
  40. package/dist/decision-cap.d.ts +2 -5
  41. package/dist/decision-cap.js +3 -6
  42. package/dist/decision-rows.js +11 -11
  43. package/dist/email/account.d.ts +84 -0
  44. package/dist/email/account.js +159 -0
  45. package/dist/email/answer.d.ts +10 -0
  46. package/dist/email/answer.js +182 -0
  47. package/dist/email/email-faux.d.ts +95 -0
  48. package/dist/email/email-faux.js +849 -0
  49. package/dist/email/labels.d.ts +1 -0
  50. package/dist/email/labels.js +84 -0
  51. package/dist/email/mail.d.ts +186 -0
  52. package/dist/email/mail.js +380 -0
  53. package/dist/email/names.d.ts +20 -0
  54. package/dist/email/names.js +40 -0
  55. package/dist/email/routes.d.ts +9 -0
  56. package/dist/email/routes.js +50 -0
  57. package/dist/email/tools.d.ts +20 -0
  58. package/dist/email/tools.js +517 -0
  59. package/dist/environment.d.ts +17 -2
  60. package/dist/environment.js +36 -8
  61. package/dist/errors.d.ts +6 -0
  62. package/dist/errors.js +12 -0
  63. package/dist/eval-mailbox.d.ts +103 -0
  64. package/dist/eval-mailbox.js +236 -0
  65. package/dist/graph-view.d.ts +9 -2
  66. package/dist/graph-view.js +6 -2
  67. package/dist/harness-install.d.ts +28 -2
  68. package/dist/harness-install.js +147 -59
  69. package/dist/harness-opencode/adapter.js +2 -26
  70. package/dist/harness-opencode/facts.js +5 -2
  71. package/dist/harness-opencode/host/policy.d.ts +2 -0
  72. package/dist/harness-opencode/host/policy.js +10 -5
  73. package/dist/harness-opencode/index.d.ts +1 -1
  74. package/dist/harness-opencode/index.js +1 -1
  75. package/dist/harness-opencode/versions.d.ts +6 -0
  76. package/dist/harness-opencode/versions.js +6 -0
  77. package/dist/harness-table.js +8 -5
  78. package/dist/harness.d.ts +12 -0
  79. package/dist/harness.js +15 -3
  80. package/dist/hosted-search.d.ts +3 -1
  81. package/dist/hosted-search.js +51 -11
  82. package/dist/import-sources.d.ts +1 -1
  83. package/dist/import-sources.js +3 -3
  84. package/dist/import.d.ts +21 -0
  85. package/dist/import.js +186 -1
  86. package/dist/key-check.d.ts +0 -2
  87. package/dist/key-check.js +3 -4
  88. package/dist/key-refusal.d.ts +8 -2
  89. package/dist/key-refusal.js +16 -13
  90. package/dist/learn/check.d.ts +18 -3
  91. package/dist/learn/check.js +328 -3
  92. package/dist/learn/compile.d.ts +9 -2
  93. package/dist/learn/compile.js +52 -16
  94. package/dist/learn/grade.d.ts +4 -0
  95. package/dist/learn/grade.js +4 -1
  96. package/dist/learn/promote.d.ts +106 -51
  97. package/dist/learn/promote.js +82 -189
  98. package/dist/learn/refit.d.ts +21 -12
  99. package/dist/learn/refit.js +51 -23
  100. package/dist/learn/replay-calls.js +1 -1
  101. package/dist/learn/skills.d.ts +2 -7
  102. package/dist/learn/skills.js +28 -14
  103. package/dist/learned-nodes.d.ts +15 -7
  104. package/dist/learned-nodes.js +29 -5
  105. package/dist/learned-workflow.d.ts +41 -31
  106. package/dist/learned-workflow.js +122 -63
  107. package/dist/learning-batch.js +3 -3
  108. package/dist/learning-cost.d.ts +26 -8
  109. package/dist/learning-cost.js +17 -7
  110. package/dist/learning-routes.d.ts +2 -4
  111. package/dist/learning-routes.js +20 -3
  112. package/dist/learning-words.d.ts +1 -1
  113. package/dist/learning-words.js +4 -1
  114. package/dist/learning.d.ts +5 -5
  115. package/dist/link-check.d.ts +27 -0
  116. package/dist/link-check.js +164 -0
  117. package/dist/local-models.d.ts +33 -2
  118. package/dist/local-models.js +43 -5
  119. package/dist/mcp-pin-first.js +6 -0
  120. package/dist/mcp-secret-writes.js +3 -0
  121. package/dist/mcp-servers-store.d.ts +25 -16
  122. package/dist/mcp-servers-store.js +23 -3
  123. package/dist/model-form.d.ts +11 -0
  124. package/dist/model-form.js +17 -1
  125. package/dist/model.d.ts +26 -6
  126. package/dist/model.js +126 -18
  127. package/dist/monid.d.ts +26 -31
  128. package/dist/monid.js +84 -79
  129. package/dist/native/binding.d.ts +13 -0
  130. package/dist/native/binding.js +57 -0
  131. package/dist/native/cli.d.ts +2 -0
  132. package/dist/native/cli.js +48 -0
  133. package/dist/native/connection.d.ts +8 -0
  134. package/dist/native/connection.js +94 -0
  135. package/dist/native/context.d.ts +6 -0
  136. package/dist/native/context.js +22 -0
  137. package/dist/native/discovery.d.ts +27 -0
  138. package/dist/native/discovery.js +404 -0
  139. package/dist/native/environment.d.ts +4 -0
  140. package/dist/native/environment.js +18 -0
  141. package/dist/native/history.d.ts +20 -0
  142. package/dist/native/history.js +147 -0
  143. package/dist/native/instructions.d.ts +21 -0
  144. package/dist/native/instructions.js +173 -0
  145. package/dist/native/remote-worker-bridge.d.ts +3 -0
  146. package/dist/native/remote-worker-bridge.js +278 -0
  147. package/dist/native/remote.d.ts +187 -0
  148. package/dist/native/remote.js +492 -0
  149. package/dist/native/runtime.d.ts +17 -0
  150. package/dist/native/runtime.js +316 -0
  151. package/dist/native/runtimes.d.ts +66 -0
  152. package/dist/native/runtimes.js +41 -0
  153. package/dist/native/schema.d.ts +46 -0
  154. package/dist/native/schema.js +41 -0
  155. package/dist/native/types.d.ts +87 -0
  156. package/dist/native/types.js +1 -0
  157. package/dist/observation/http.d.ts +4 -0
  158. package/dist/observation/http.js +140 -0
  159. package/dist/observation/observer.d.ts +301 -0
  160. package/dist/observation/observer.js +919 -0
  161. package/dist/observation/schema.d.ts +52 -0
  162. package/dist/observation/schema.js +154 -0
  163. package/dist/openapi.d.ts +1 -0
  164. package/dist/openapi.js +394 -85
  165. package/dist/paid-calls.d.ts +8 -3
  166. package/dist/paid-calls.js +6 -2
  167. package/dist/place-offers.d.ts +4 -8
  168. package/dist/place-offers.js +4 -9
  169. package/dist/port-models.d.ts +7 -2
  170. package/dist/port-models.js +5 -2
  171. package/dist/print.d.ts +4 -2
  172. package/dist/print.js +4 -3
  173. package/dist/propose.d.ts +1 -2
  174. package/dist/propose.js +10 -1
  175. package/dist/provider.d.ts +5 -1
  176. package/dist/provider.js +8 -0
  177. package/dist/push-handler.d.ts +3 -2
  178. package/dist/push-handler.js +20 -6
  179. package/dist/refusal-words.d.ts +11 -0
  180. package/dist/refusal-words.js +13 -2
  181. package/dist/run-launch.d.ts +10 -1
  182. package/dist/run-launch.js +11 -4
  183. package/dist/run-learning-served.d.ts +75 -2
  184. package/dist/run-manifest.d.ts +3 -0
  185. package/dist/run-manifest.js +13 -1
  186. package/dist/run-reads-over-store.d.ts +3 -3
  187. package/dist/run-reads-over-store.js +13 -10
  188. package/dist/run-timeline-served.d.ts +3 -2
  189. package/dist/run-timeline-served.js +8 -9
  190. package/dist/run-view.d.ts +42 -35
  191. package/dist/run-view.js +79 -44
  192. package/dist/runnable.d.ts +13 -5
  193. package/dist/runnable.js +69 -60
  194. package/dist/runner/adapter-loop.d.ts +42 -11
  195. package/dist/runner/adapter-loop.js +651 -247
  196. package/dist/runner/adapter-run-spec.d.ts +37 -12
  197. package/dist/runner/adapter-run-spec.js +139 -106
  198. package/dist/runner/adapters/pi.d.ts +24 -0
  199. package/dist/runner/adapters/pi.js +59 -9
  200. package/dist/runner/beside.d.ts +3 -1
  201. package/dist/runner/beside.js +24 -8
  202. package/dist/runner/claim-secrets.d.ts +3 -1
  203. package/dist/runner/claim-secrets.js +28 -4
  204. package/dist/runner/cli-run-spec.d.ts +30 -0
  205. package/dist/runner/cli-run-spec.js +94 -50
  206. package/dist/runner/computer-channel.d.ts +5 -2
  207. package/dist/runner/computer-channel.js +3 -2
  208. package/dist/runner/computer-journal.d.ts +6 -0
  209. package/dist/runner/computer-journal.js +8 -10
  210. package/dist/runner/conformance/harness.js +6 -3
  211. package/dist/runner/end-of-run.d.ts +2 -0
  212. package/dist/runner/end-of-run.js +3 -1
  213. package/dist/runner/feedback-round.d.ts +40 -13
  214. package/dist/runner/feedback-round.js +64 -16
  215. package/dist/runner/harness-loops.js +17 -0
  216. package/dist/runner/journal-kinds.d.ts +37 -13
  217. package/dist/runner/journal-kinds.js +9 -5
  218. package/dist/runner/learning-dispatch.d.ts +3 -2
  219. package/dist/runner/learning-dispatch.js +6 -6
  220. package/dist/runner/learning-end.d.ts +4 -0
  221. package/dist/runner/learning-end.js +64 -36
  222. package/dist/runner/learning-factory.d.ts +3 -0
  223. package/dist/runner/learning-factory.js +8 -2
  224. package/dist/runner/learning-loop.d.ts +2 -0
  225. package/dist/runner/learning-loop.js +19 -4
  226. package/dist/runner/loop.d.ts +18 -0
  227. package/dist/runner/loop.js +34 -0
  228. package/dist/runner/main.d.ts +6 -1
  229. package/dist/runner/main.js +26 -4
  230. package/dist/runner/mcp-run.d.ts +4 -1
  231. package/dist/runner/mcp-run.js +11 -5
  232. package/dist/runner/meta-tools.d.ts +10 -3
  233. package/dist/runner/meta-tools.js +112 -36
  234. package/dist/runner/metrics.d.ts +80 -21
  235. package/dist/runner/metrics.js +114 -39
  236. package/dist/runner/model-route.d.ts +12 -3
  237. package/dist/runner/model-route.js +139 -18
  238. package/dist/runner/monid-run.d.ts +8 -6
  239. package/dist/runner/monid-run.js +117 -43
  240. package/dist/runner/native-loop.d.ts +11 -0
  241. package/dist/runner/native-loop.js +438 -0
  242. package/dist/runner/promotion.d.ts +74 -8
  243. package/dist/runner/promotion.js +365 -124
  244. package/dist/runner/redact.js +3 -0
  245. package/dist/runner/reflect-hook.js +9 -0
  246. package/dist/runner/runner.d.ts +7 -1
  247. package/dist/runner/runner.js +8 -4
  248. package/dist/runner/sdk-loop.d.ts +7 -0
  249. package/dist/runner/sdk-loop.js +470 -0
  250. package/dist/runner/spec-holds.d.ts +16 -2
  251. package/dist/runner/spec-holds.js +42 -14
  252. package/dist/runner/store-secrets.js +17 -2
  253. package/dist/runner/workflow-first.d.ts +30 -20
  254. package/dist/runner/workflow-first.js +22 -32
  255. package/dist/runner/workflow-loop.d.ts +1 -1
  256. package/dist/runner/workflow-loop.js +18 -12
  257. package/dist/runner/workflow-spec.d.ts +4 -1
  258. package/dist/runner/workflow-spec.js +56 -45
  259. package/dist/runs-over-store.d.ts +30 -2
  260. package/dist/runs-over-store.js +46 -14
  261. package/dist/sdk/runs.d.ts +115 -0
  262. package/dist/sdk/runs.js +422 -0
  263. package/dist/sdk/schema.d.ts +175 -0
  264. package/dist/sdk/schema.js +138 -0
  265. package/dist/sdk/workflows.d.ts +22 -0
  266. package/dist/sdk/workflows.js +39 -0
  267. package/dist/secrets.d.ts +2 -0
  268. package/dist/secrets.js +19 -1
  269. package/dist/server.d.ts +48 -32
  270. package/dist/server.js +554 -130
  271. package/dist/skill-route.d.ts +3 -0
  272. package/dist/skill-route.js +16 -0
  273. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  274. package/dist/stats.d.ts +10 -10
  275. package/dist/store/agent-body.d.ts +12 -8
  276. package/dist/store/agent-body.js +9 -4
  277. package/dist/store/index.d.ts +1 -1
  278. package/dist/store/native-command-owner.d.ts +10 -0
  279. package/dist/store/native-command-owner.js +47 -0
  280. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  281. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  282. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  283. package/dist/store/postgres/store.js +3 -0
  284. package/dist/store/schema.d.ts +7 -0
  285. package/dist/store/schema.js +20 -1
  286. package/dist/store/sqlite/run-patch.d.ts +8 -1
  287. package/dist/store/sqlite/run-patch.js +14 -3
  288. package/dist/store/sqlite/store.js +133 -18
  289. package/dist/store/store.d.ts +52 -7
  290. package/dist/store-reads/analytics.d.ts +7 -7
  291. package/dist/store-reads/analytics.js +23 -5
  292. package/dist/store-reads/cap.js +8 -6
  293. package/dist/store-reads/journal.d.ts +5 -0
  294. package/dist/store-reads/journal.js +85 -41
  295. package/dist/store-reads/learning.d.ts +85 -5
  296. package/dist/store-reads/learning.js +45 -17
  297. package/dist/store-reads/runs.d.ts +5 -0
  298. package/dist/store-reads/runs.js +3 -2
  299. package/dist/store-view.js +75 -21
  300. package/dist/template-eval.d.ts +73 -11
  301. package/dist/template-eval.js +535 -75
  302. package/dist/templates.d.ts +70 -20
  303. package/dist/templates.js +191 -34
  304. package/dist/text-urls.d.ts +38 -0
  305. package/dist/text-urls.js +170 -0
  306. package/dist/timeline/index.d.ts +3 -2
  307. package/dist/timeline/index.js +3 -2
  308. package/dist/timeline/labels.d.ts +5 -2
  309. package/dist/timeline/labels.js +29 -6
  310. package/dist/timeline/origin.d.ts +1 -1
  311. package/dist/timeline/origin.js +2 -2
  312. package/dist/timeline/render-text.js +1 -1
  313. package/dist/timeline/timeline.d.ts +66 -4
  314. package/dist/timeline/timeline.js +160 -30
  315. package/dist/timeline/util.d.ts +5 -0
  316. package/dist/timeline/util.js +44 -8
  317. package/dist/timeline/web-calls.d.ts +17 -0
  318. package/dist/timeline/web-calls.js +106 -0
  319. package/dist/tool-gate.d.ts +42 -42
  320. package/dist/tool-gate.js +97 -91
  321. package/dist/tool-list.d.ts +4 -1
  322. package/dist/tool-list.js +8 -1
  323. package/dist/tool-names.d.ts +18 -13
  324. package/dist/tool-names.js +19 -17
  325. package/dist/tool-plane.d.ts +17 -13
  326. package/dist/tool-plane.js +12 -5
  327. package/dist/tools.d.ts +44 -16
  328. package/dist/tools.js +28 -28
  329. package/dist/trigger-adapter.d.ts +85 -5
  330. package/dist/trigger-adapter.js +6 -0
  331. package/dist/trigger-adapters.js +3 -1
  332. package/dist/trigger-composio.d.ts +10 -0
  333. package/dist/trigger-composio.js +122 -0
  334. package/dist/trigger-email.d.ts +4 -0
  335. package/dist/trigger-email.js +228 -0
  336. package/dist/trigger-signatures.d.ts +6 -10
  337. package/dist/trigger-signatures.js +16 -16
  338. package/dist/trigger-targets.d.ts +1 -1
  339. package/dist/trigger-targets.js +4 -3
  340. package/dist/trigger-webhook.js +6 -4
  341. package/dist/triggers.d.ts +94 -9
  342. package/dist/triggers.js +263 -62
  343. package/dist/uploads.d.ts +9 -0
  344. package/dist/uploads.js +27 -0
  345. package/dist/validate.js +1 -7
  346. package/dist/web-fake.d.ts +56 -0
  347. package/dist/web-fake.js +102 -0
  348. package/dist/web-fetch-direct.d.ts +3 -0
  349. package/dist/web-fetch-direct.js +4 -1
  350. package/dist/web-fetch.d.ts +5 -1
  351. package/dist/web-fetch.js +8 -31
  352. package/dist/web-search.d.ts +51 -2
  353. package/dist/web-search.js +116 -18
  354. package/dist/webhooks.d.ts +2 -1
  355. package/dist/webhooks.js +5 -1
  356. package/dist/workflow/node-runner.js +10 -2
  357. package/dist/workspace/archil-claim.d.ts +3 -0
  358. package/dist/workspace/archil-claim.js +9 -2
  359. package/dist/workspace/computer-deps.d.ts +22 -9
  360. package/dist/workspace/computer-deps.js +78 -37
  361. package/dist/workspace/computer-for-claim.d.ts +54 -4
  362. package/dist/workspace/computer-for-claim.js +179 -39
  363. package/dist/workspace/computer-janitor.d.ts +10 -3
  364. package/dist/workspace/computer-janitor.js +96 -29
  365. package/dist/workspace/computer-kept.d.ts +82 -0
  366. package/dist/workspace/computer-kept.js +147 -0
  367. package/dist/workspace/computer-mcp.js +4 -3
  368. package/dist/workspace/computer-ports.d.ts +23 -3
  369. package/dist/workspace/computer-ports.js +115 -5
  370. package/dist/workspace/index.d.ts +1 -2
  371. package/dist/workspace/index.js +1 -2
  372. package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
  373. package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
  374. package/dist/workspace/resolve-computer.d.ts +15 -3
  375. package/dist/workspace/resolve-computer.js +10 -7
  376. package/dist/workspace/revision-skills.d.ts +6 -2
  377. package/dist/workspace/revision-skills.js +12 -5
  378. package/dist/workspace/run-end-computers.d.ts +30 -0
  379. package/dist/workspace/run-end-computers.js +137 -0
  380. package/dist/workspace/run-tools.d.ts +28 -29
  381. package/dist/workspace/run-tools.js +29 -30
  382. package/dist/wrap-up.d.ts +19 -5
  383. package/dist/wrap-up.js +31 -4
  384. package/package.json +13 -9
  385. package/skills/agentrun-serve/SKILL.md +248 -10
  386. package/templates/README.md +117 -23
  387. package/templates/TOOLS.md +168 -0
  388. package/templates/code-review/agent.md +18 -4
  389. package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
  390. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  391. package/templates/code-review/evals/other-repo/case.yaml +1 -1
  392. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  393. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  394. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  395. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  396. package/templates/code-review/skills/review/DEEP.md +2 -2
  397. package/templates/code-review/skills/review/REVIEWER.md +2 -2
  398. package/templates/code-review/skills/review/SKILL.md +7 -3
  399. package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
  400. package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
  401. package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
  402. package/templates/release-notes/evals/other-repo/case.yaml +1 -1
  403. package/dist/console/assets/index-CjqQirbo.css +0 -1
  404. package/dist/console/assets/index-b6-XY5A9.js +0 -576
  405. package/dist/host-calls.d.ts +0 -20
  406. package/dist/host-calls.js +0 -12
  407. package/dist/runner/adapters/pi-computer.d.ts +0 -9
  408. package/dist/runner/adapters/pi-computer.js +0 -51
  409. package/dist/workspace/computer-script.d.ts +0 -53
  410. package/dist/workspace/computer-script.js +0 -172
@@ -12,9 +12,17 @@
12
12
  // once (or is refused), its outcome is the script's output, and the rest of the script does not run. A refusal of any
13
13
  // nested call ends the script with the refusal's words. The script sees the tools and the answers its calls get, nothing
14
14
  // else of the run: no environment, no key, no file.
15
+ //
16
+ // On a run with a desktop or a phone, a script has `computer` too (the computer package's bindComputer over its card,
17
+ // its declarations in codemode's description): each of its calls is a nested call of the run's computer tools
18
+ // (computer_observe, computer_act, computer_screenshot, computer_op), so the gate holds a command it runs to bash's
19
+ // setting and a file it touches to write's or read's (tool-gate.ts heldAs), and a rerun answers it from its record.
15
20
  import { randomBytes } from "node:crypto";
16
21
  import { CodemodeSandbox, toCodemodeIdentifier } from "@earendil-works/pi-codemode";
22
+ import { computerOver, withoutImageData } from "@parcha/agentrun-computer/surface";
23
+ import { COMPUTER_OP_TOOL, computerDeclarations, STEP_TOOL_OPS } from "@parcha/agentrun-kernel/kernel";
17
24
  import { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH } from "../meta-tool-names.js";
25
+ import { NO_PROGRAMS_WORDS } from "../workspace/computer-ports.js";
18
26
  export { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH };
19
27
  /** How many tools a search answers with when its call names no limit, and the most it may name. */
20
28
  export const SEARCH_DEFAULT_LIMIT = 8;
@@ -44,28 +52,44 @@ export async function searchTools(query, tools, granted, limit = SEARCH_DEFAULT_
44
52
  });
45
53
  }
46
54
  /** The run's tool a model's name for it names: its own name, or one a harness gives it on its tool channel (claude-agent's
47
- * `mcp__hands__<name>`, OpenCode's `hands_<name>`, Codex's `mcp_<server>__<tool>` for an MCP tool). */
48
- export function toolNamed(name, tools) {
49
- const candidates = [name, name.replace(/^mcp__hands__/, ""), name.replace(/^hands_/, ""), name.replace(/^mcp_(?!_)/, "mcp__")];
50
- for (const candidate of candidates) {
51
- const tool = tools.find((one) => one.name === candidate);
52
- if (tool)
53
- return tool;
54
- }
55
- return undefined;
55
+ * `mcp__hands__<name>`, OpenCode's `hands_<name>`, Codex's `mcp_<server>__<tool>` for an MCP tool): `hostName` is the
56
+ * harness's own map from that name to the host's (AdapterFacts.hostName). */
57
+ export function toolNamed(name, tools, hostName = (given) => given) {
58
+ const host = hostName(name);
59
+ return tools.find((one) => one.name === name) ?? tools.find((one) => one.name === host);
56
60
  }
57
61
  /** Why `name` can't be called through tools_call or a script, or undefined: one of the three, or no tool of this run. */
58
- export function refusedName(caller, name, tools) {
59
- const own = name.replace(/^mcp__hands__/, "").replace(/^hands_/, "");
62
+ export function refusedName(caller, name, tools, hostName = (given) => given) {
63
+ const own = hostName(name);
60
64
  if (META_TOOLS.has(own))
61
65
  return `${caller} can't call ${own}: ${TOOLS_SEARCH}, ${TOOLS_CALL} and ${CODEMODE} are called by the model itself, never through each other. Nothing was run.`;
62
- if (!toolNamed(name, tools))
66
+ if (!toolNamed(name, tools, hostName))
63
67
  return `${caller} can't call ${JSON.stringify(name).slice(0, 120)}: this run has no tool by that name. Find the run's tools with ${TOOLS_SEARCH}. Nothing was run.`;
64
68
  return undefined;
65
69
  }
66
70
  const NO_NESTED = (caller) => `${caller} can't run here: this harness gives it no way to call the run's tools. Nothing was run.`;
67
71
  /** A nested answer as a tool's answer. */
68
72
  const answered = (result) => ({ text: result.text, ...(result.isError ? { isError: true } : {}), ...(result.images?.length ? { images: result.images } : {}), ...(result.structured !== undefined ? { structured: result.structured } : {}) });
73
+ /** A script's `computer` (the computer package's bindComputer, over its card) as one expression of the script's isolate
74
+ * over its `tools`: an observe, an act or a screenshot calls its own step tool, every other op computer_op, so each is a
75
+ * nested call of the run's tool, asked about and recorded as that tool's. On an agent whose exec is off, reaching for
76
+ * computer.shell or computer.processes throws NO_PROGRAMS_WORDS rather than reading undefined. */
77
+ function scriptComputer(computer, tools) {
78
+ const ident = (name) => `${tools}[${JSON.stringify(toCodemodeIdentifier(name))}]`;
79
+ const steps = Object.entries(STEP_TOOL_OPS).map(([op, tool]) => `op === ${JSON.stringify(op)} ? ${ident(tool)}(args) : `).join("");
80
+ const bound = computerOver(computer.card, `(op, args) => (${steps}${ident(COMPUTER_OP_TOOL)}({ op, args }))`);
81
+ if (computer.exec !== false)
82
+ return bound;
83
+ return `new Proxy(${bound}, { get(target, key, receiver) { if (key === "shell" || key === "processes") throw new Error(${JSON.stringify(NO_PROGRAMS_WORDS)}); return Reflect.get(target, key, receiver); } })`;
84
+ }
85
+ /** What codemode's description adds for a run with a computer: the script's `computer`, and the declarations of what its
86
+ * card offers. */
87
+ function computerWords(computer) {
88
+ return [
89
+ `The script has this run's computer as \`computer\`, typed by the declarations below. Each of its calls is a call of the run's own computer tools, asked about and recorded as that tool's: a command it runs is held to bash's setting, a file it writes to write's, a file it reads, lists or stats to read's.`,
90
+ computerDeclarations(computer.card.groups),
91
+ ].join("\n");
92
+ }
69
93
  /** The three tools for a session: each `nests` (but the search, which calls nothing). */
70
94
  export function metaTools(options) {
71
95
  const own = () => options.tools().filter((tool) => !META_TOOLS.has(tool.name));
@@ -96,12 +120,12 @@ export function metaTools(options) {
96
120
  if (given !== undefined && (given === null || typeof given !== "object" || Array.isArray(given)))
97
121
  return { text: `${TOOLS_CALL}'s args must be an object of the tool's arguments.`, isError: true };
98
122
  const tools = own();
99
- const refused = refusedName(TOOLS_CALL, name, tools);
123
+ const refused = refusedName(TOOLS_CALL, name, tools, options.hostName);
100
124
  if (refused)
101
125
  return { text: refused, isError: true };
102
126
  if (!context.nested)
103
127
  return { text: NO_NESTED(TOOLS_CALL), isError: true };
104
- return answered(await context.nested.call(toolNamed(name, tools).name, (given ?? {}), "call"));
128
+ return answered(await context.nested.call(toolNamed(name, tools, options.hostName).name, (given ?? {}), "call"));
105
129
  },
106
130
  };
107
131
  // A few of the run's tools as the script writes them (`tools.<name>`): names that resolve, as the model's own tool list
@@ -113,7 +137,7 @@ export function metaTools(options) {
113
137
  `Run a JavaScript script (the body of an async function: top-level await and return work) that calls this run's tools as \`await tools.<name>(args)\`; ${options.discovery.search ? `find them with ${TOOLS_SEARCH}, and ` : ""}\`ALL_TOOLS\` lists them. A call answers its value, and a call that fails throws. A tool is called by its own name, exactly as \`ALL_TOOLS\`${options.discovery.search ? ` and ${TOOLS_SEARCH}` : ""} give it${examples.length ? ` (here: ${examples.join(", ")})` : ""}, never by the name your own tool list may show for it with a harness's prefix (\`hands_\`, \`mcp__hands__\`): leave the prefix off.`,
114
138
  "The script's text(...) and console output, and its returned value, are the answer. It has no timers, network or files of its own: only the tools.",
115
139
  "Each call is asked about and recorded as that tool's own. A call that needs a person's approval stops the script: once they answer, that call runs (or is refused), its outcome is the answer, and the rest of the script does not run. A refused call ends the script with the refusal.",
116
- ].join(" "),
140
+ ].join(" ") + (options.computer ? `\n${computerWords(options.computer)}` : ""),
117
141
  inputSchema: { type: "object", properties: { script: { type: "string", description: "The script: the body of an async function." } }, required: ["script"], additionalProperties: false },
118
142
  replay: "safe",
119
143
  nests: true,
@@ -123,36 +147,86 @@ export function metaTools(options) {
123
147
  return { text: `${CODEMODE} needs a script: the body of an async function.`, isError: true };
124
148
  if (!context.nested)
125
149
  return { text: NO_NESTED(CODEMODE), isError: true };
126
- return runScript(script, own(), context.nested, context.signal);
150
+ return runScript(script, own(), context.nested, context.signal, options.hostName, options.computer);
127
151
  },
128
152
  };
129
153
  return [...(options.discovery.search ? [search] : []), ...(options.discovery.call ? [call] : []), ...(options.codemode ? [codemode] : [])];
130
154
  }
131
- /** One nested call's line in a script's stopped answer, as Codex's code mode words its recovered calls. */
155
+ /** One nested call's line in a script's stopped answer, as Codex's code mode words its recovered calls. A completed call's
156
+ * result is its value as the script read it (scriptValue): JSON as itself where it parsed, so it reads as the object it
157
+ * is, never as a string holding it, and an image in it named without its data; else that string, quoted. A call whose
158
+ * value is null (an op that answers none: a computer's files.write) is told by its answer's words ("wrote <path>"), as
159
+ * it answered, never as null. */
132
160
  function lineOf(index, name, result) {
133
- const said = JSON.stringify(result.text.length > 2_000 ? `${result.text.slice(0, 2_000)}…` : result.text);
161
+ const quoted = (text) => JSON.stringify(text.length > 2_000 ? `${text.slice(0, 2_000)}…` : text);
134
162
  const label = `${index}. ${name}`;
135
163
  if (result.refused)
136
- return `${label} was refused: ${said}. It did not run.`;
164
+ return `${label} was refused: ${quoted(result.text)}. It did not run.`;
137
165
  if (result.interrupted)
138
166
  return `${label} was started and did not report a result, so it may have taken effect: check before calling it again. It was not run again.`;
139
167
  if (result.isError)
140
- return `${label} failed: ${said}. It was not run again.`;
168
+ return `${label} failed: ${quoted(result.text)}. It was not run again.`;
169
+ const value = result.structured === null ? result.text : scriptValue(result);
170
+ const json = typeof value === "string" ? undefined : JSON.stringify(withoutImageData(value));
171
+ const said = json === undefined ? quoted(value) : json.length > 2_000 ? `${json.slice(0, 2_000)}…` : json;
141
172
  return `${label} completed: ${said}. Its effect is done; it was not run again.`;
142
173
  }
143
- /** The script's output and value, as the model reads them, and the images it showed. */
174
+ /** The script's output and value, as the model reads them, and the images: the returned value's own first, then the ones
175
+ * it showed with image(...). The text names an image without its data. */
144
176
  function shownOf(output, value) {
145
177
  const words = [];
146
- const images = [];
178
+ const shown = [];
147
179
  for (const item of output) {
148
180
  if (item.type === "text")
149
181
  words.push(item.text);
150
182
  else
151
- images.push({ data: item.data, mimeType: item.mimeType });
183
+ shown.push({ data: item.data, mimeType: item.mimeType });
152
184
  }
153
185
  if (value !== undefined)
154
- words.push(typeof value === "string" ? value : JSON.stringify(value));
155
- return { text: words.join("\n"), images };
186
+ words.push(typeof value === "string" ? value : JSON.stringify(withoutImageData(value)));
187
+ return { text: words.join("\n"), images: [...imagesIn(value), ...shown] };
188
+ }
189
+ /** Every image in `value` (`{ type: "image", data }`), in order. */
190
+ function imagesIn(value) {
191
+ if (Array.isArray(value))
192
+ return value.flatMap(imagesIn);
193
+ if (value === null || typeof value !== "object")
194
+ return [];
195
+ const record = value;
196
+ if (record.type === "image" && typeof record.data === "string")
197
+ return [{ data: record.data, mimeType: typeof record.mimeType === "string" ? record.mimeType : "image/png" }];
198
+ return Object.values(record).flatMap(imagesIn);
199
+ }
200
+ /** `value` with each image in it that has no data (`{ type: "image" }`, as a tool's structured value keeps an image whose
201
+ * data travels in the answer's images) given the data of the next of `images`, in order. */
202
+ function withImageData(value, images) {
203
+ let next = 0;
204
+ const fill = (entry) => {
205
+ if (Array.isArray(entry))
206
+ return entry.map(fill);
207
+ if (entry === null || typeof entry !== "object")
208
+ return entry;
209
+ const record = entry;
210
+ if (record.type === "image" && record.data === undefined && next < images.length) {
211
+ const image = images[next++];
212
+ return { ...record, mimeType: record.mimeType ?? image.mimeType, data: image.data };
213
+ }
214
+ return Object.fromEntries(Object.entries(record).map(([key, inner]) => [key, fill(inner)]));
215
+ };
216
+ return fill(value);
217
+ }
218
+ /**
219
+ * What the sandbox runs for `script`: the script as the body of a function whose `tools` answers `undefined` for a name the
220
+ * run has no tool by (pi-codemode's own `tools` throws on it), so `typeof tools.<name>` and `"<name>" in tools` work. Each
221
+ * such name the script reads is kept, and when the script then fails with a TypeError, or an error naming one, the error
222
+ * gets one line saying so and listing the run's tools. The script is never read: it stays line 1 on, and its declarations
223
+ * can't reach the names around it. With the run's `computer`, the function gets it too (scriptComputer), over `tools`.
224
+ */
225
+ function scriptBody(script, toolNames, computer) {
226
+ const known = JSON.stringify(` Its tools are: ${toolNames.join(", ")}.`);
227
+ const params = computer ? "tools, console, computer" : "tools, console";
228
+ const bound = computer ? `, ${scriptComputer(computer, "tools")}` : "";
229
+ return `const read = new Set(), get = Reflect.get, proto = Object.prototype; try { return await (async (${params}) => {${script}\n})(new Proxy(tools, { get(target, key, receiver) { if (typeof key !== "string" || key in target || key in proto || key === "then" || key === "toJSON") return get(target, key, receiver); read.add(key); } }), console${bound}); } catch (error) { const names = [...read]; if (names.length && error !== null && typeof error === "object" && (error.name === "TypeError" || names.some((name) => String(error.message).includes(name)))) error.message += "\\nThe script read " + names.map((name) => "tools." + name).join(", ") + ", which this run doesn't have." + ${known}; throw error; }`;
156
230
  }
157
231
  /**
158
232
  * Run `script` deterministically (pi-codemode's `start`: its clock, its randomness and its tools fixed by the call's first
@@ -160,7 +234,7 @@ function shownOf(output, value) {
160
234
  * of the call (after a park or a crash) makes the same calls: the recorded ones are answered from their records, and the
161
235
  * first one that runs now ends the script with its outcome (Codex's rule), as does any refusal or interrupted call.
162
236
  */
163
- async function runScript(script, tools, nested, signal) {
237
+ async function runScript(script, tools, nested, signal, hostName, computer) {
164
238
  const nonce = randomBytes(8).toString("hex");
165
239
  const first = await nested.memo("start", { startedAt: Date.now(), seed: randomBytes(4).readUInt32BE(0), nonce, tools: tools.map((tool) => [tool.name, toCodemodeIdentifier(tool.name)]) });
166
240
  const start = first;
@@ -174,11 +248,12 @@ async function runScript(script, tools, nested, signal) {
174
248
  let failed;
175
249
  let wake = () => { };
176
250
  try {
177
- const run = sandbox.start(script, {
251
+ // The tools the first run declared, by the names it gave them, that this run still has.
252
+ const kept = start.tools.filter(([name]) => declared.has(name)).map(([name, jsName]) => ({ name, jsName, description: declared.get(name).description }));
253
+ const run = sandbox.start(scriptBody(script, kept.map((tool) => tool.jsName), computer), {
178
254
  startedAt: start.startedAt,
179
255
  seed: start.seed,
180
- // The tools the first run declared, by the names it gave them, that this run still has.
181
- tools: start.tools.filter(([name]) => declared.has(name)).map(([name, jsName]) => ({ name, jsName, description: declared.get(name).description })),
256
+ tools: kept,
182
257
  signal: AbortSignal.any([signal, stop.signal]),
183
258
  timeoutMs: CODEMODE_MS,
184
259
  onCall: (call) => {
@@ -198,8 +273,8 @@ async function runScript(script, tools, nested, signal) {
198
273
  });
199
274
  continue;
200
275
  }
201
- const tool = toolNamed(call.name, tools);
202
- const refused = call.target !== "tool" ? `${call.name} is no tool of this run.` : refusedName(CODEMODE, call.name, tools);
276
+ const tool = toolNamed(call.name, tools, hostName);
277
+ const refused = call.target !== "tool" ? `${call.name} is no tool of this run.` : refusedName(CODEMODE, call.name, tools, hostName);
203
278
  const args = call.args && typeof call.args === "object" && !Array.isArray(call.args) ? call.args : {};
204
279
  const result = refused || !tool ? { text: refused ?? `${call.name} is no tool of this run.`, isError: true, refused: true, fresh: true } : await nested.call(tool.name, args, `s${call.id}`);
205
280
  told.push({ name: tool?.name ?? call.name, result });
@@ -232,18 +307,19 @@ async function runScript(script, tools, nested, signal) {
232
307
  const why = result.error.kind === "timeout" ? `the script ran past ${CODEMODE_MS} ms: ${result.error.message}` : result.error.message;
233
308
  return { text: [shown.text, `The script failed: ${why}`].filter(Boolean).join("\n"), isError: true, ...(shown.images.length ? { images: shown.images } : {}) };
234
309
  }
235
- return { text: shown.text || "(the script returned nothing and showed nothing)", ...(shown.images.length ? { images: shown.images } : {}), ...(result.value !== undefined ? { structured: result.value } : {}) };
310
+ return { text: shown.text || "(the script returned nothing and showed nothing)", ...(shown.images.length ? { images: shown.images } : {}), ...(result.value !== undefined ? { structured: withoutImageData(result.value) } : {}) };
236
311
  }
237
312
  finally {
238
313
  await sandbox.close();
239
314
  }
240
315
  }
241
- /** A nested call's value in a script: its structured value (an MCP result's structuredContent) when it has one; else, when
242
- * its answer is one text part (no image beside it) whose text parses as a JSON object or array, that value (a Composio
243
- * answer comes as one); else its text. The text the model reads of the call is its text either way. */
316
+ /** A nested call's value in a script: its structured value (an MCP result's structuredContent; a computer tool's value)
317
+ * when it has one, each image in it given its data back from the answer's images, so a screenshot is pixels the script
318
+ * can show; else, when its answer is one text part (no image beside it) whose text parses as a JSON object or array,
319
+ * that value (a Composio answer comes as one); else its text. The text the model reads of the call is its text either way. */
244
320
  function scriptValue(result) {
245
321
  if (result.structured !== undefined)
246
- return result.structured;
322
+ return result.images?.length ? withImageData(result.structured, result.images) : result.structured;
247
323
  const text = result.text.trim();
248
324
  if (result.images?.length || !(text.startsWith("{") || text.startsWith("[")))
249
325
  return result.text;
@@ -1,12 +1,19 @@
1
1
  import { type DecisionLike, type EntryLike, type RunMetrics } from "../timeline/index.js";
2
- /** What a run's booking says one of its sessions spent: its requests (a hold given back unused is none), their known
3
- * sum, how many have no known cost, their tokens, and how many of the requests have no known tokens (`unmetered`: booked
2
+ import { type CostParts } from "@parcha/agentrun-kernel";
3
+ /** What a run's booking says one of its sessions spent: its requests (a hold given back unused is none), its cost's parts
4
+ * (the kernel's CostParts: `known`, the sum of the requests' own figures; `bounded` and `atMost`, the sum and count of
5
+ * cut requests booked at their hold, each the most it can have cost; `unpriced`, how many have no figure), `usd` their
6
+ * sum (null while one is unpriced), their tokens, and how many of the requests have no known tokens (`unmetered`: booked
4
7
  * with no usage, or sent and never answered), in no token sum; and its requests by the model each was sent on (`models`:
5
- * its runner.request's model, "" for one that names none). */
8
+ * its runner.request's model, "" for one that names none). `free`: it booked requests, every one on a free model (its
9
+ * runner.turn's `free`: its known price $0 for every token), so its $0 says why. A reader that joins sessions, or says
10
+ * what is known of an unknown cost, takes the parts through costOfParts, never `usd` and `known` alone. */
6
11
  export type BookedSpend = {
7
12
  readonly usd: number | null;
8
13
  readonly known: number;
14
+ readonly bounded: number;
9
15
  readonly unpriced: number;
16
+ readonly atMost: number;
10
17
  readonly requests: number;
11
18
  readonly unmetered: number;
12
19
  readonly models: Readonly<Record<string, number>>;
@@ -16,6 +23,7 @@ export type BookedSpend = {
16
23
  cacheRead: number;
17
24
  cacheWrite: number;
18
25
  };
26
+ readonly free?: true;
19
27
  };
20
28
  /** What the run's booking (the kernel's runner.request and runner.turn records, the model proxy's own) says its requests
21
29
  * cost, over `entries`, every conversation of the run's journal: its model requests (`model`: every session but the
@@ -28,14 +36,63 @@ export type BookedSpend = {
28
36
  * booking's. `side`: of the model requests, those booked as side calls (another model than the session's, or the host's
29
37
  * own, as a learned workflow's node is: the proxy's `side`/`host`), which no answer of a pi run carries. */
30
38
  export declare function bookedSpend(entries: readonly EntryLike[], which: "model" | "paid" | "decisions" | "side"): BookedSpend;
31
- /** An agent run's cost as its end commit stores it: its model requests' (`model`), its paid tool calls' (`paid`, the
32
- * run's ledger.paid) and its decisions' (`decisions`, a learned workflow's decision nodes, LS-07: bookedSpend over
33
- * their own session's records, so one that reported no cost is unknown, never the cap's hold for it), summed; null (unknown) when any of them is. Never a known figure that leaves an unknown part out. */
34
- export declare function runEndCost(parts: {
35
- readonly model: number | null;
36
- readonly paid: number | null;
37
- readonly decisions: number | null;
38
- }): number | null;
39
+ /** A cost of charges as a usage row or a run's cost block says it (costsofar/1, cutathold/1), by the kernel's one rule
40
+ * (costOfParts) over `parts`, its float noise rounded off (floatNoiseOff): `usd` their sum, `upper_bound` when it counts
41
+ * a cut request at its hold, with `so_far_usd` the charges' own figures alone and `unpriced` how many it counts at their
42
+ * hold beside it; or, while one has no known cost, `usd` null, `so_far_usd` the charges' own figures alone and `unpriced`
43
+ * how many have none, held ones included. A bound always says its exact part, so whatever joins these words with more
44
+ * charges (usageParts, then this again) never has to take the bound for spend. A part that is null is a cost no one
45
+ * knows that says nothing of itself (a usage row of an older run with no costsofar/1 fields, decisions that could not be
46
+ * read): the cost is unknown and nothing is said beside it. `extraUnpriced`: charges with no figure beside the parts' (a
47
+ * CLI's model work no booking read). This is the one join: every reader that combines a usage row with more charges
48
+ * goes through it. */
49
+ export type CostWords = {
50
+ readonly usd: number | null;
51
+ readonly so_far_usd?: number;
52
+ readonly unpriced?: number;
53
+ readonly upper_bound?: true;
54
+ };
55
+ export declare function costWordsOf(parts: readonly (CostParts | null)[], extraUnpriced?: number): CostWords;
56
+ /** A usage row's cost (TimelineEvent.usage, or a cost block in the same words) as the kernel's parts, for a join
57
+ * (costWordsOf): an exact figure is `known`; a bound is its exact part (`so_far_usd`) known and the rest bounded over its
58
+ * `unpriced` holds, or, from a row that says no exact part, the whole bounded over one hold, never spend; an unknown cost
59
+ * is its known part and its unpriced count. Null: an unknown cost that says neither. No row (undefined): nothing spent. */
60
+ export declare function usageParts(usage: {
61
+ readonly usd: number | null;
62
+ readonly so_far_usd?: number;
63
+ readonly unpriced?: number;
64
+ readonly upper_bound?: true;
65
+ } | undefined): CostParts | null;
66
+ /** A run's cost, by the one rule every reader of it takes (the end's stored cost_usd, GET /runs/{id} and the runs list of
67
+ * an ended run): from its booking alone, over `entries`, every conversation of its journal: its model requests, its paid
68
+ * tool calls and its decisions, each request at what it was booked at (bookedSpend), joined by the kernel's costOfParts.
69
+ * `usd` is their sum, its float noise rounded off (floatNoiseOff); null (unknown) when any request has no known cost, with what is known of
70
+ * it (`known`: the requests' own figures alone, never a cut request's hold) and how many have none (`unpriced`, held ones
71
+ * included) beside it. `atMost`, while `usd` is known: how many of its figures are a cut request's hold, so the cost is at
72
+ * most `usd`. `requests`: how many requests the run booked (0: it booked none, and its cost is not this booking's to say).
73
+ * `unbooked`: a CLI harness's model worked with no request booked (cliModelWorked: its requests went past its model
74
+ * proxy), one charge with no price, so the cost is unknown, never the $0 an empty booking sums to. */
75
+ export type RunCost = CostParts & {
76
+ readonly usd: number | null;
77
+ readonly requests: number;
78
+ };
79
+ export declare function runCostOf(entries: readonly EntryLike[], { unbooked }?: {
80
+ readonly unbooked?: boolean;
81
+ }): RunCost;
82
+ /** A run's cost as its end stores it (the run row's cost_usd and cost_upper_bound): its figure, and whether that is the most
83
+ * it can have cost (a request cut at its hold counted in it). An unknown cost is never a bound. */
84
+ export type EndCost = {
85
+ readonly costUsd: number | null;
86
+ readonly costUpperBound: boolean;
87
+ };
88
+ export declare const endCostOf: (cost: RunCost) => EndCost;
89
+ /** The run's model requests billed to a ChatGPT plan (runner.turn `billing` "plan", booked at no price, chatgpt-plan.ts):
90
+ * how many and their tokens (input, output and cache, as each booking reported them). Each is $0 to the run by the
91
+ * kernel's one rule (turnCostOf), however it ended: the plan pays for it, so no reader counts it unpriced. */
92
+ export declare function planSpend(entries: readonly EntryLike[]): {
93
+ readonly requests: number;
94
+ readonly tokens: number;
95
+ };
39
96
  /** Whether a CLI harness's record (`entries`, its root's) shows the model at work: a model message, a tool call it made, or
40
97
  * its end-of-run turn's answer. Each took a model request, so a run that shows one and booked none (its requests went
41
98
  * past its model proxy) spent what no booking read: its cost is unknown, never $0. */
@@ -44,15 +101,14 @@ export declare function cliModelWorked(entries: readonly EntryLike[]): boolean;
44
101
  * harness's record (`cli`), or a workflow's (its model nodes' answers carry pi-ai's $0). A pi run's answers carry their
45
102
  * booking (adapters/pi.ts afterResponse). */
46
103
  export declare function costIsBooked(entries: readonly EntryLike[], cli: boolean): boolean;
47
- /** What the run has spent as its cap reads it (the kernel's sessionSpendOf over every session's records: a request still
48
- * out at its hold and bound), for a run whose cost is its booking: the runs list's figure while it runs. Null when one
49
- * session's is unknown, never 0 for it. */
104
+ /** What the run has spent and holds as its cap reads it (the kernel's sessionSpendOf over every session's records: a
105
+ * request still out at its hold and bound), for a run whose cost is its booking: the figure a gate holds it to (the
106
+ * runs list says bookedListSpend). Null when one session's is unknown, never 0 for it. */
50
107
  export declare function bookedCapSpend(entries: readonly EntryLike[]): number | null;
51
- /** The bound of a run's requests since its spend last fit under `capUsd`, as the kernel's overCapOf reads it: each model
52
- * request, in each model session's order, at the figure the cap counts it at, after what the paid tools and decisions
53
- * spent; reset to 0 whenever the spend fits, else grown by each request's bound. What its over-cap row (run-view.ts
54
- * withOverCap) reads to tell a cache miss within that bound from a run that spent past its cap. 0 when nothing ran. */
55
- export declare function overCapBound(entries: readonly EntryLike[], capUsd: number): number;
108
+ /** What a run whose cost is its booking has spent, as the runs list says it while the run goes on: every booked request at
109
+ * what it was booked at, never the hold of a request still out (a hold is no spend: the request settles at what it cost,
110
+ * which the cap's own reading, bookedCapSpend, holds it to meanwhile). Null when a booked request's figure is unknown. */
111
+ export declare function bookedListSpend(entries: readonly EntryLike[]): number | null;
56
112
  /** A run's metrics as the end commit writes them (the StoredMetrics JSON on the run row): the timeline's count, with the
57
113
  * effort the run ran at and, on a harness other than pi, the model its revision named. */
58
114
  export type RunMetricsStored = RunMetrics & {
@@ -60,12 +116,14 @@ export type RunMetricsStored = RunMetrics & {
60
116
  model?: string;
61
117
  };
62
118
  /** The run's metrics and cost from its journal `entries`. `decisions`: a workflow run's receipts (none for pi).
63
- * `effort`/`model`: the enrichment the old storedMetrics added. `costUsd` is the usage row's cost: null when a
64
- * response's cost is unknown, 0 before any request (costOf). */
119
+ * `effort`/`model`: the enrichment the old storedMetrics added. `catalog`: the run's MCP tools called by a hashed wire
120
+ * name, each counted under its catalog name (catalogKeyed). `costUsd` is the usage row's cost: null when a response's
121
+ * cost is unknown, 0 before any request (costOf). */
65
122
  export declare function runMetrics(entries: readonly EntryLike[], options?: {
66
123
  readonly decisions?: readonly DecisionLike[];
67
124
  readonly effort?: string;
68
125
  readonly model?: string;
126
+ readonly catalog?: ReadonlyMap<string, string>;
69
127
  }): {
70
128
  metrics: RunMetricsStored;
71
129
  costUsd: number | null;
@@ -73,4 +131,5 @@ export declare function runMetrics(entries: readonly EntryLike[], options?: {
73
131
  export declare function cliRunMetrics(rootEntries: readonly EntryLike[], booked: BookedSpend, options: {
74
132
  readonly effort?: string;
75
133
  readonly model: string;
134
+ readonly catalog?: ReadonlyMap<string, string>;
76
135
  }): RunMetricsStored;