@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
@@ -1,3 +1,9 @@
1
+ // GET /v2/stats' analytics over the one store (design 2.1): the runs' metrics summed, the same StoreAnalytics the old store
2
+ // gave, from A's run rows — each run's metrics as its end commit wrote them (the StoredMetrics JSON on the row), its cost,
3
+ // and its revision's harness. The runs not archived (their own or their agent's), started in [from, to) and of `agent` when
4
+ // given. A pending run (its end on the caller's way, not yet in the store) is counted at the state its end will have, in
5
+ // the totals alone; its metrics, cost and effort wait for its end. No journal is read: the figures are the row's.
6
+ import { sdkOf } from "../sdk/runs.js";
1
7
  import { DEFAULT_HARNESS } from "../harness.js";
2
8
  import { runReadState } from "./runs.js";
3
9
  const PENDING_ENDS = new Set(["completed", "escalated", "failed", "stopped"]);
@@ -29,7 +35,7 @@ export async function analytics(store, filter = {}) {
29
35
  continue;
30
36
  if (!harnessOf.has(run.revisionId)) {
31
37
  const revision = await store.agents.revision(run.revisionId);
32
- harnessOf.set(run.revisionId, revision?.kind === "workflow" ? "workflow" : (revision?.body?.harness ?? DEFAULT_HARNESS));
38
+ harnessOf.set(run.revisionId, revision?.kind === "workflow" ? "workflow" : (sdkOf(revision?.body)?.runtime ?? revision?.body?.harness ?? DEFAULT_HARNESS));
33
39
  }
34
40
  const read = runReadState(run, harnessOf.get(run.revisionId) === "workflow" ? "workflow" : "agentic");
35
41
  const running = read === "running";
@@ -51,6 +57,7 @@ export async function analytics(store, filter = {}) {
51
57
  });
52
58
  }
53
59
  const counted = (group) => {
60
+ let unknownTokens = false;
54
61
  let runsN = 0, completed = 0, needsReview = 0, failed = 0, metered = 0, tokens = 0, costUsd = 0, known = 0, pend = 0;
55
62
  for (const f of group) {
56
63
  runsN += 1;
@@ -60,20 +67,31 @@ export async function analytics(store, filter = {}) {
60
67
  needsReview += 1;
61
68
  if (f.state === "failed")
62
69
  failed += 1;
63
- if (f.metered)
64
- (metered += 1, (tokens += tokensOf(f.metrics)));
70
+ if (f.metered) {
71
+ metered += 1;
72
+ tokens += tokensOf(f.metrics);
73
+ if (['input', 'cacheRead', 'cacheWrite', 'output'].some(key => f.metrics?.[key] === null))
74
+ unknownTokens = true;
75
+ }
65
76
  if (!f.running && !f.pending && f.costUsd !== null)
66
77
  (costUsd += f.costUsd, (known += 1));
67
78
  if (f.pending)
68
79
  pend += 1;
69
80
  }
70
- return { runs: runsN, completed, needsReview, failed, runsWithMetrics: metered, tokens, costUsd: known > 0 ? costUsd : null, unknownCostRuns: runsN - known - pend };
81
+ return { runs: runsN, completed, needsReview, failed, runsWithMetrics: metered, tokens: unknownTokens ? null : tokens, costUsd: known > 0 ? costUsd : null, unknownCostRuns: runsN - known - pend };
71
82
  };
72
83
  // Totals over the whole scope: the group counts, the token sums, and the time figures.
73
84
  let input = 0, cacheRead = 0, cacheWrite = 0, output = 0, requests = 0, unmetered = 0;
85
+ let unknownRequests = false;
86
+ const unknownTokens = new Set();
74
87
  let endedRuns = 0, wallMs = 0, activeRuns = 0, activeMs = 0;
75
88
  for (const f of facts) {
76
89
  if (f.metered && f.metrics) {
90
+ if (f.metrics.requests === null)
91
+ unknownRequests = true;
92
+ for (const key of ['input', 'cacheRead', 'cacheWrite', 'output'])
93
+ if (f.metrics[key] === null)
94
+ unknownTokens.add(key);
77
95
  input += num(f.metrics.input);
78
96
  cacheRead += num(f.metrics.cacheRead);
79
97
  cacheWrite += num(f.metrics.cacheWrite);
@@ -126,7 +144,7 @@ export async function analytics(store, filter = {}) {
126
144
  const tools = [...calls.entries()].map(([tool, c]) => ({ tool, calls: c.calls, errors: c.errors })).sort((a, b) => b.calls - a.calls || (a.tool < b.tool ? -1 : a.tool > b.tool ? 1 : 0)).slice(0, 20);
127
145
  const totalsGroup = counted(facts);
128
146
  return {
129
- totals: { ...totalsGroup, input, cacheRead, cacheWrite, output, requests, unmetered },
147
+ totals: { ...totalsGroup, input: unknownTokens.has('input') ? null : input, cacheRead: unknownTokens.has('cacheRead') ? null : cacheRead, cacheWrite: unknownTokens.has('cacheWrite') ? null : cacheWrite, output: unknownTokens.has('output') ? null : output, requests: unknownRequests ? null : requests, unmetered: unknownRequests ? null : unmetered },
130
148
  time: { endedRuns, wallMs, activeRuns, activeMs },
131
149
  byHarnessEffort: harnessEffort,
132
150
  byDay,
@@ -1,5 +1,5 @@
1
1
  import { meterFiguresFrom, spentFrom } from "../cap.js";
2
- import { bookedCapSpend, bookedSpend, cliModelWorked, costIsBooked } from "../runner/metrics.js";
2
+ import { bookedListSpend, bookedSpend, cliModelWorked, costIsBooked } from "../runner/metrics.js";
3
3
  import { isCliRecord, runEntries, withPaidCosts } from "./journal.js";
4
4
  /** A CLI run whose model answered or called a tool with no model request booked (metrics.ts cliModelWorked): what it
5
5
  * spent no booking read, so its spend is unknown. */
@@ -7,12 +7,12 @@ const unbookedCli = (entries) => isCliRecord(entries) && bookedSpend(entries, "m
7
7
  /** What a run has spent, as the cap reads it, from the one store's journal: its model requests and its paid tool calls. */
8
8
  export async function spentOverStore(store, runId, context) {
9
9
  const entries = await runEntries(store, runId, context);
10
- // A run whose record carries no cost of its own (a CLI harness's, a workflow's) reads what its sessions booked, the
11
- // figure its cap holds it to (metrics.ts bookedCapSpend), its record's answers reading $0: 0 before any request, an
12
- // unknown booked spend unknown (null).
10
+ // A run whose record carries no cost of its own (a CLI harness's, a workflow's) reads what its sessions booked for the
11
+ // requests that answered (metrics.ts bookedListSpend), its record's answers reading $0: 0 before any request, an
12
+ // unknown booked spend unknown (null). A request still out is held, not spent: its hold never shows as spend.
13
13
  // A CLI run whose model worked with no request booked (its requests went past its model proxy) reads unknown, never $0.
14
14
  if (costIsBooked(entries, isCliRecord(entries)))
15
- return unbookedCli(entries) ? null : bookedCapSpend(entries);
15
+ return unbookedCli(entries) ? null : bookedListSpend(entries);
16
16
  // A pi run's paid tool calls (a browser's time, a search, a monid call) are booked on the run's one ledger, not its root:
17
17
  // folded back as the charges the file-backed root held (withPaidCosts), as metersOverStore reads them, so a live run's
18
18
  // listed spend counts them.
@@ -40,5 +40,7 @@ export async function metersOverStore(store, runId, context) {
40
40
  const model = bookedSpend(raw, "model");
41
41
  if (!model.requests)
42
42
  return unbookedCli(raw) ? { ...figures, tokens: null } : figures;
43
- return { ...figures, tokens: model.usd, known: { ...figures.known, tokens: model.known } };
43
+ // /usage says no "at most": a request booked at its hold (`bounded`) is no spend there, so its meter is unknown, as for
44
+ // a request of no known cost, and its known dollars are the exact charges alone.
45
+ return { ...figures, tokens: model.bounded > 0 ? null : model.usd, known: { ...figures.known, tokens: model.known } };
44
46
  }
@@ -53,6 +53,11 @@ export declare function withoutFeedbackRounds<Row extends {
53
53
  * run's usage row counts them; its decisions' rows and cost come from their receipts (decision-rows.ts withDecisions),
54
54
  * once. The end-of-run turn's rows are labelled as the server labels them (reflect-range.ts labelled). */
55
55
  export declare function runTimeline(store: Store, runId: string, context: Context, options?: TimelineOptions): Promise<TimelineEvent[]>;
56
+ /** The run's MCP tools called by a hashed wire name, by that name (hashedMcp over its pin): what its end's metrics count
57
+ * each one's calls under its catalog name by (runner/metrics.ts runMetrics's `catalog`), as its timeline names them. */
58
+ export declare const hashedMcpOf: (store: Store, runId: string) => Promise<ReadonlyMap<string, string>>;
59
+ /** A usage row's cost when every model request went to a free model (its known price $0 for every token): $0, and why. */
60
+ export declare const FREE_COST = "$0 \u00B7 free model";
56
61
  /** How a reader serves an answer whole: its redactor over the whole text (key-refusal.ts redactedAnswer with the run's
57
62
  * values), and a key for those values (their digest), so an answer is read once per held value set. */
58
63
  export type WholeAnswer = {
@@ -3,19 +3,20 @@
3
3
  // its own database file ("SELECT record FROM entries ORDER BY id") and fed the same pure renderer; these read the one store instead.
4
4
  // The renderer and the hearing keep their words; only where the entries come from changes.
5
5
  import { createHash } from "node:crypto";
6
- import { CALL_REFUSED, CAPS, costLabel, endedOnTurnEndingTool, FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, timelineOf, TOOL_COST, toolCallWords } from "../timeline/index.js";
6
+ import { CALL_ENDED_WITH_RUN, CALL_REFUSED, CAPS, costLabel, endedOnTurnEndingTool, FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, timelineOf, TOOL_COST, toolCallWords } from "../timeline/index.js";
7
7
  import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
8
8
  import { wireName } from "../catalog.js";
9
9
  import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
10
10
  import { Hearing } from "../heard.js";
11
11
  import { redactedAnswer } from "../key-refusal.js";
12
- import { LEARNED_NODES, LEARNED_NODES_MAX } from "../learned-nodes.js";
12
+ import { LEARNED_NODES_MAX, learnedCallEntries } from "../learned-nodes.js";
13
13
  import { computerCallsOf, shownName } from "../computer-calls.js";
14
14
  import { labelled, reflects } from "../reflect-range.js";
15
15
  import { reflectRanges } from "../runner/end-of-run.js";
16
16
  import { journalEntries, journalRecords, recordOf } from "../runner/journal-reader.js";
17
17
  import { endedAnswer, KINDS } from "../runner/journal-kinds.js";
18
- import { bookedSpend, cliModelWorked, costIsBooked } from "../runner/metrics.js";
18
+ import { bookedSpend, cliModelWorked, costIsBooked, costWordsOf } from "../runner/metrics.js";
19
+ import { mcpNameOf, mcpToolName } from "../tool-names.js";
19
20
  import { Turns } from "../turns.js";
20
21
  /** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
21
22
  * entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
@@ -64,7 +65,7 @@ export function piShaped(entries) {
64
65
  }
65
66
  // A call: shown as a model's call, never counted as a model request (the booking counts those: bookedUsage).
66
67
  if (entry.kind === KINDS.callStart) {
67
- return { ...entry, kind: "pi.assistant", recordedCall: true, model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }], ...timestamp }] };
68
+ return { ...entry, kind: "pi.assistant", recordedCall: true, ...(typeof data.parent === "string" ? { parentCall: data.parent } : {}), model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }], ...timestamp }] };
68
69
  }
69
70
  if (entry.kind === KINDS.callEnd) {
70
71
  // A call that did not finish done is an error result, as a failed pi tool call is; its output is the result's text. One
@@ -75,7 +76,10 @@ export function piShaped(entries) {
75
76
  // One refused before it ran (its gate's deny, a person's, an approval the run ended without) carries pi's refusal
76
77
  // mark, so its rows read refused, as pi's do, never as a call that ran and failed.
77
78
  const refused = data.status === "refused" ? { details: { [CALL_REFUSED]: true } } : {};
78
- return { ...entry, kind: "pi.tool-result", model: [{ role: "tool", toolCallId: String(data.callId ?? ""), content, ...(failed ? { isError: true } : {}), ...refused, ...timestamp }] };
79
+ // One the run's end closed, nothing having ended it (`withRun`), carries that mark: it reads interrupted with no
80
+ // outcome, never as a call that failed.
81
+ const withRun = data.status === "interrupted" && data.withRun === true ? { details: { [CALL_ENDED_WITH_RUN]: true } } : {};
82
+ return { ...entry, kind: "pi.tool-result", model: [{ role: "tool", toolCallId: String(data.callId ?? ""), content, ...(failed ? { isError: true } : {}), ...refused, ...withRun, ...timestamp }] };
79
83
  }
80
84
  return entry;
81
85
  });
@@ -215,14 +219,49 @@ export async function runTimeline(store, runId, context, options = {}) {
215
219
  // settles that turn's message aborted, before the runner books what the abort cut (its request's end mark comes once the
216
220
  // session's proxy sees its upstream end). Its cost reads that turn the same way, the request it cut a charge with no
217
221
  // price, never one in flight: never the known sum as its cost while the run reads stopped.
218
- const read = { ...options, ...(cwd ? { path: inWorkspace(cwd.cwd) } : {}), ...(!options.settled && turnCutOf(records, reflect) ? { turnCut: true } : {}) };
222
+ // A pi run's side calls join its usage row's count and cost in the renderer, by the rule its answers are counted by
223
+ // (sideOf); a run whose cost is its booking's (costIsBooked) has its usage row from that booking (bookedUsage).
224
+ const booked = costIsBooked(entries, cli);
225
+ const side = booked ? undefined : sideOf(entries);
226
+ const read = { ...options, ...(cwd ? { path: inWorkspace(cwd.cwd) } : {}), ...(!options.settled && turnCutOf(records, reflect) ? { turnCut: true } : {}), ...(side ? { side } : {}) };
219
227
  // Shaped on pi too: its own entries pass through as they are, and the calls its tools nested (on the loop's record) read
220
228
  // as a CLI's calls do. A grade's feedback round's words read as the reviewer's message (withFeedback), marked as no
221
229
  // message of the job's (feedbackMarked).
222
- const rendered = feedbackMarked(timelineOf(withPaidCosts(withFeedback(piShaped(entries))), read), entries);
223
- const rows = costIsBooked(entries, cli) ? bookedUsage(rendered, entries, options) : withSideUsage(rendered, entries);
224
- return labelled(reflect, withComputerCalls(withLearnedNodes(await datedRows(store, runId, rows), entries, options.redact), entries, options.redact));
230
+ const render = (catalog) => feedbackMarked(timelineOf(withPaidCosts(withFeedback(piShaped(entries))), catalog ? { ...read, catalog } : read), entries);
231
+ const first = render();
232
+ const catalog = await runCatalog(store, runId, first);
233
+ // An MCP tool whose `mcp__<server>__<tool>` is too long is called by its hashed wire name, which reads as no tool's own:
234
+ // the run's rows are rendered again with those names' catalog names, so each is labelled by its own.
235
+ const hashed = hashedMcp(catalog?.values() ?? []);
236
+ const rendered = hashed.size ? render(hashed) : first;
237
+ const rows = booked ? bookedUsage(rendered, entries, options) : withFreeUsage(rendered, entries);
238
+ return labelled(reflect, withComputerCalls(withLearnedNodes(await datedRows(store, runId, catalogNamed(rows, catalog)), entries, options.redact), entries, options.redact));
225
239
  }
240
+ /** The run's MCP tools and monid endpoints by the wire name its harness called each (catalog.ts wireName of each pinned
241
+ * tool), read from the run's pins by lookup, never parsed back; undefined when no row names one by a wire name. */
242
+ async function runCatalog(store, runId, rows) {
243
+ if (!rows.some((row) => row.tool_name !== null && /^(?:mcp|monid)_/.test(row.tool_name)))
244
+ return undefined;
245
+ const run = await store.runs.get(runId);
246
+ const pinned = await pinnedMcp(store, runId);
247
+ const monid = Object.keys((run && (await store.agents.revision(run.revisionId)))?.monidPin ?? {});
248
+ return new Map([...pinned, ...monid].map((name) => [wireName(name), name]));
249
+ }
250
+ /** The catalog names (`mcp:<server>/<tool>`) of the MCP tools the run pinned, from its pin. */
251
+ const pinnedMcp = async (store, runId) => Object.entries((await store.mcp.pin(runId))?.body ?? {}).flatMap(([server, one]) => (one.tools ?? []).map((tool) => mcpToolName(server, tool.name)));
252
+ /** Of `names` (catalog names), each MCP tool whose `mcp__<server>__<tool>` is too long, by the hashed wire name its harness
253
+ * calls it (catalog.ts wireName): a name that reads as no tool of its own, so a reader names its calls by the catalog name. */
254
+ const hashedMcp = (names) => new Map([...names].flatMap((name) => {
255
+ const mcp = mcpNameOf(name);
256
+ return mcp !== undefined && wireName(name) !== `mcp__${mcp.server}__${mcp.tool}` ? [[wireName(name), name]] : [];
257
+ }));
258
+ /** The run's MCP tools called by a hashed wire name, by that name (hashedMcp over its pin): what its end's metrics count
259
+ * each one's calls under its catalog name by (runner/metrics.ts runMetrics's `catalog`), as its timeline names them. */
260
+ export const hashedMcpOf = async (store, runId) => hashedMcp(await pinnedMcp(store, runId));
261
+ /** `rows` with each tool row of an MCP tool or a monid endpoint named as its settings and its notices name it, by catalog
262
+ * name (`mcp:<server>/<tool>`, from the run's `catalog`), never the wire name the harness called it by, so one call reads
263
+ * one way. A row of any other tool is as it was. */
264
+ const catalogNamed = (rows, catalog) => catalog ? rows.map((row) => (row.tool_name !== null && catalog.has(row.tool_name) ? { ...row, tool_name: catalog.get(row.tool_name) } : row)) : rows;
226
265
  /** Whether the run's newest turn is over, cut (turns.ts: no message of the run's open, the newest one's end interrupted),
227
266
  * its end-of-run turn's entries apart, as the run's view reads its status. */
228
267
  function turnCutOf(records, reflect) {
@@ -246,18 +285,17 @@ function withComputerCalls(rows, entries, redact) {
246
285
  });
247
286
  }
248
287
  /** `rows` with each learned_workflow call's result row carrying the nodes its workflow ran (`learned_nodes`), from the
249
- * LEARNED_NODES entry the call kept beside itself (learned-workflow.ts), joined by the call's id: each label through
250
- * `redact` when given (the run's cut), as every text a row shows; never a node's error text. Rows of a run that ran none are as they were. */
288
+ * LEARNED_NODES entry that counts for the call (learned-nodes.ts learnedCallEntries: a rerun refused before any node ran
289
+ * leaves the attempt before it showing), joined by the call's id: each label through `redact` when given (the run's cut),
290
+ * as every text a row shows; never a node's error text. Rows of a run that ran none are as they were. */
251
291
  function withLearnedNodes(rows, entries, redact) {
252
292
  const traces = new Map();
253
293
  const said = (text) => (redact ? redact(text) : text);
254
- for (const entry of entries) {
255
- if (entry.kind !== LEARNED_NODES)
256
- continue;
257
- const data = (entry.data ?? {});
258
- if (typeof data.call !== "string" || !Array.isArray(data.nodes))
294
+ for (const [call, index] of learnedCallEntries(entries)) {
295
+ const data = (entries[index].data ?? {});
296
+ if (!Array.isArray(data.nodes))
259
297
  continue;
260
- traces.set(data.call, data.nodes.slice(0, LEARNED_NODES_MAX).flatMap((node) => {
298
+ traces.set(call, data.nodes.slice(0, LEARNED_NODES_MAX).flatMap((node) => {
261
299
  const one = (node ?? {});
262
300
  if (typeof one.label !== "string" || typeof one.status !== "string")
263
301
  return [];
@@ -270,26 +308,24 @@ function withLearnedNodes(rows, entries, redact) {
270
308
  return rows;
271
309
  return rows.map((row) => (row.kind === "tool_result" && row.tool_use_id && traces.has(row.tool_use_id) ? { ...row, learned_nodes: traces.get(row.tool_use_id) } : row));
272
310
  }
273
- /** A pi run's `rows` with its side calls in its usage row: the requests its session booked that no answer of pi's carries
274
- * (a learned workflow's nodes, a request on another model: runner/metrics.ts bookedSpend "side"), at what they were
275
- * booked at, unknown when one's price is, beside the answers the renderer counted. Their requests join its count; its
276
- * words are the renderer's, figures changed. A run with none is as rendered. */
277
- function withSideUsage(rows, entries) {
311
+ /** A usage row's cost when every model request went to a free model (its known price $0 for every token): $0, and why. */
312
+ export const FREE_COST = "$0 · free model";
313
+ /** A pi run's side calls, for its usage row: the requests its session booked that no answer of pi's carries (a learned
314
+ * workflow's nodes, a request on another model: runner/metrics.ts bookedSpend "side"), their count and their cost's
315
+ * parts, which the renderer joins to the answers it counts by the one rule (timeline SideSpend). None: undefined. */
316
+ function sideOf(entries) {
278
317
  const side = bookedSpend(entries, "side");
318
+ return side.requests ? { requests: side.requests, known: side.known, bounded: side.bounded, atMost: side.atMost, unpriced: side.unpriced } : undefined;
319
+ }
320
+ /** A pi run's `rows` whose every request its booking marked free (bookedSpend's `free`) and that cost $0: its usage row
321
+ * says why (FREE_COST). Any other is as rendered. */
322
+ function withFreeUsage(rows, entries) {
279
323
  const at = rows.findLastIndex((row) => row.kind === "usage");
280
- if (!side.requests || at < 0)
281
- return [...rows];
282
324
  const row = rows[at];
283
- const own = row.usage ?? { usd: 0, requests: 0 };
284
- const known = (own.usd ?? own.so_far_usd ?? 0) + side.known;
285
- const unpriced = (own.usd === null ? (own.unpriced ?? 0) : 0) + side.unpriced;
286
- const usd = unpriced ? null : Math.round(known * 1e6) / 1e6;
287
- const requests = own.requests + side.requests;
288
- const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
289
- const spent = usd !== null ? dollars(usd) : `${dollars(Math.round(known * 1e6) / 1e6)} known, ${unpriced} not priced,`;
290
- const summary = (row.summary ?? "").replace(/^([^:]+): .+? over \d+ model requests?/, `$1: ${spent} over ${requests} model request${requests === 1 ? "" : "s"}`);
291
- const usage = { usd, requests, ...(usd === null ? { so_far_usd: Math.round(known * 1e6) / 1e6, unpriced } : {}), ...(own.not_metered ? { not_metered: own.not_metered } : {}) };
292
- return rows.map((each, i) => (i === at ? { ...row, summary, usage } : each));
325
+ if (!row || row.usage?.usd !== 0 || bookedSpend(entries, "model").free !== true)
326
+ return [...rows];
327
+ const summary = (row.summary ?? "").replace(/^([^:]+): .+? over /, `$1: ${FREE_COST} over `);
328
+ return rows.map((each, i) => (i === at ? { ...row, summary, usage: { ...row.usage, free: true } } : each));
293
329
  }
294
330
  /** A CLI or workflow run's `rows` with its usage row in its booking's words (runner/metrics.ts bookedSpend over every
295
331
  * session of the run but its decisions'): its model requests and its paid tool calls, their sum (unknown while one's cost is, with what is known so far,
@@ -299,6 +335,7 @@ function withSideUsage(rows, entries) {
299
335
  * past its model proxy): its usage row says its cost is unknown, its model's work one charge with no price, so its view,
300
336
  * live or ended, reads unknown, never $0. */
301
337
  function bookedUsage(rows, entries, options) {
338
+ const nativeAggregate = entries.some(entry => entry.kind === 'runner.request' && entry.data?.aggregate);
302
339
  const model = bookedSpend(entries, "model");
303
340
  const paid = bookedSpend(entries, "paid");
304
341
  const at = rows.findIndex((row) => row.kind === "usage");
@@ -312,17 +349,24 @@ function bookedUsage(rows, entries, options) {
312
349
  const last = kept[kept.length - 1];
313
350
  return [...kept, { ...last, id: `${last.conversation_id ?? 0}:usage`, kind: "usage", summary: "no model request sent", agent_label: null, text: null, tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null, usage: { usd: 0, requests: 0 } }];
314
351
  }
315
- const usd = unbooked || model.usd === null || paid.usd === null ? null : model.usd + paid.usd;
316
- const unpriced = model.unpriced + paid.unpriced + (unbooked ? 1 : 0);
352
+ // Its model requests' and paid tool calls' parts, joined by the kernel's one rule (costWordsOf): a cut request at its
353
+ // hold keeps its bound on a known sum ("at most"), and joins no known part of an unknown one.
354
+ const cost = costWordsOf([model, paid], unbooked ? 1 : 0);
355
+ const usd = cost.usd;
356
+ // Every model request on a free model, booked so, and nothing else charged: its $0 says why.
357
+ const free = usd === 0 && model.free === true;
317
358
  const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
318
- const spent = usd !== null ? dollars(usd) : `${dollars(model.known + paid.known)} known, ${unpriced} not priced,`;
359
+ const spent = free ? FREE_COST : usd !== null ? `${cost.upper_bound ? "at most " : ""}${dollars(usd)}` : `${dollars(cost.so_far_usd ?? 0)} known, ${cost.unpriced ?? 0} not priced,`;
319
360
  // Its tool calls with no price as the renderer counted them from the journal (TOOL_UNMETERED), as on a pi run's row.
320
361
  const notMetered = at >= 0 ? (rows[at].usage?.not_metered ?? 0) : 0;
321
362
  const calls = toolCallWords(paid.requests, notMetered);
322
- const summary = unbooked
323
- ? `${costLabel(options.ended === true)}: unknown, its model's requests were not metered${calls}`
324
- : `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${calls}`;
325
- const usage = { usd, requests: model.requests, ...(usd === null ? { so_far_usd: model.known + paid.known, unpriced } : {}), ...(notMetered ? { not_metered: notMetered } : {}) };
363
+ const summary = nativeAggregate
364
+ ? `${costLabel(options.ended === true)}: ${spent}; native model request count unavailable${calls}`
365
+ : unbooked
366
+ ? `${costLabel(options.ended === true)}: unknown, its model's requests were not metered${calls}`
367
+ : `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${calls}`;
368
+ // Its so-far figures whenever the words say them: while the cost is unknown, and beside a bound (its exact part and holds).
369
+ const usage = { usd, requests: nativeAggregate ? null : model.requests, ...(cost.so_far_usd !== undefined && cost.unpriced !== undefined ? { so_far_usd: cost.so_far_usd, unpriced: cost.unpriced } : {}), ...(notMetered ? { not_metered: notMetered } : {}), ...(free ? { free: true } : {}), ...(cost.upper_bound ? { upper_bound: true } : {}) };
326
370
  const last = rows[rows.length - 1];
327
371
  const base = at >= 0 ? rows[at] : {
328
372
  ...last, id: `${last?.conversation_id ?? 0}:usage`, agent_label: null, text: null,
@@ -1,13 +1,14 @@
1
1
  import { type ItemStatus, type Learning, type NoteUsed, type Shown } from "../learning.js";
2
2
  import { type RunLaunch } from "../run-launch.js";
3
3
  import { type Impact, type ImpactLearning } from "../learning-run.js";
4
- import { type CostRun, type CostSummary, type RunPath, runCostOf } from "../learning-cost.js";
4
+ import { type CostReplay, type CostRun, type CostSummary, type RunPath, runCostOf } from "../learning-cost.js";
5
5
  import { type PastRun, workflowCostsOf } from "../runner/workflow-first.js";
6
6
  import { type Reflect } from "../reflect-range.js";
7
7
  import type { NoteRuns } from "../learning.js";
8
8
  import type { EntryLike, TimelineEvent } from "../timeline/index.js";
9
9
  import type { AnalyticsFilter } from "./analytics.js";
10
10
  import { type KeptProposal } from "../runner/learning-loop.js";
11
+ import { type PromotionRecord } from "../learn/promote.js";
11
12
  import type { LearningProposal, Store } from "../store/store.js";
12
13
  /** A run's learning end: the Learning fields its end sets. */
13
14
  export type RunLearningEnd = Pick<Learning, "state" | "reason" | "detail" | "at" | "problems" | "verdict" | "graded" | "merged" | "cost_usd" | "tokens" | "learned" | "pending" | "skills" | "workflows" | "lost" | "answered_at" | "job_cost_usd" | "look_back_usd" | "compiled" | "draft_errors">;
@@ -86,6 +87,11 @@ export declare function agentCostOverStore(store: Store, agentId: string, limit?
86
87
  unknown_path_runs: number;
87
88
  workflows: ReturnType<typeof workflowCostsOf>;
88
89
  }>;
90
+ /** The replay the serving promotion was decided on, as the cost summary says it: the champion (championOf) of the learned
91
+ * workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's `replay` numbers
92
+ * and whether they cleared the bar (withinBar, promotion's own). Null when no run was served, nothing serves now (held,
93
+ * or never promoted), or it was promoted with no replay (a dry run). */
94
+ export declare function servingReplayOf(records: readonly PromotionRecord[], runs: readonly CostRun[]): CostReplay | null;
89
95
  /** What run `runId`'s learning spent, as its cost per run counts it, over every round a follow-up opened (roundsOf): what
90
96
  * it kept as it answered (`looked`: answeredOf), and its grades' spend (`grade`): each round's learning run's cost once
91
97
  * that run ended, stopped or failed (runner/learning-loop.ts keeps the grade's spend there, a paid grade a person stopped
@@ -127,6 +133,7 @@ export declare function runPathOverStore(store: Store, runId: string, started: R
127
133
  path: RunPath;
128
134
  workflow: string | null;
129
135
  digest?: string;
136
+ promotion?: number;
130
137
  }>;
131
138
  /** What a run's claim laid of its learning seed: the learned skills and workflows it was given, by name. */
132
139
  type Laid = {
@@ -136,11 +143,11 @@ type Laid = {
136
143
  /** What every claim of a run laid, from its learningLaid entries, each name once: a resumed claim finds an earlier
137
144
  * claim's skill folders there already and lays none of them again, though the run still has them. None laid when it has
138
145
  * no entry. */
139
- export declare function laidOf(entries: readonly EntryLike[]): Laid;
146
+ export declare function laidOf(entries: readonly Pick<EntryLike, "kind" | "data">[]): Laid;
140
147
  /** What every round of a run that a follow-up opened again spent (undefined for a run with one round): when its first
141
148
  * round's job answered and what the job cost to then, the look-backs of every round added up, and every round's grade. A
142
149
  * figure that is unknown in any round is unknown (null). */
143
- export type RoundsSpend = {
150
+ type RoundsSpend = {
144
151
  answered_at: string;
145
152
  job_cost_usd: number | null;
146
153
  look_back_usd: number | null;
@@ -275,8 +282,81 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
275
282
  skills?: import("../learning.js").LearnedFile[];
276
283
  workflows?: import("../learning.js").LearnedFile[];
277
284
  run: string;
278
- state: "proposed" | "dropped" | "merged" | "seeded" | "reflecting";
279
- reason: "cancelled" | "no_budget" | "empty" | "unparsed" | "use" | "seed_failed" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
285
+ state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
286
+ reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
287
+ detail: string | null;
288
+ at: string;
289
+ } | {
290
+ graded: {
291
+ workflow: string | null;
292
+ feedback_status: "running" | "ended" | "not_run" | null;
293
+ source: "feedback" | "eval";
294
+ graded_at: string;
295
+ path: "agent" | "workflow" | "handed_back" | "replay";
296
+ workflow_digest: string | null;
297
+ feedback: "revise" | "look_back" | null;
298
+ run_id: string;
299
+ correct: boolean;
300
+ };
301
+ seed: string | null;
302
+ merged: string | null;
303
+ pending: {
304
+ file: string;
305
+ name: string;
306
+ }[];
307
+ verdict: {
308
+ merge: boolean;
309
+ reason: string;
310
+ items: {
311
+ why: string;
312
+ question?: string | undefined;
313
+ origin?: "run" | "you" | undefined;
314
+ pending?: boolean | undefined;
315
+ file: string;
316
+ keep: boolean;
317
+ }[];
318
+ } | null;
319
+ problems: {
320
+ detail: string;
321
+ path?: string | undefined;
322
+ rule: import("../learn/check.js").Rule;
323
+ }[];
324
+ compiled: {
325
+ workflow: string;
326
+ from_notes: string[];
327
+ attempts: {
328
+ ok: boolean;
329
+ errors: string[];
330
+ }[];
331
+ digest: string | null;
332
+ promoted: boolean | null;
333
+ } | null;
334
+ draft_errors: string[];
335
+ cost_usd: {
336
+ grade: number | null;
337
+ };
338
+ tokens: {
339
+ grade: import("../learning.js").Tokens | null;
340
+ };
341
+ used: {
342
+ skills: {
343
+ name: string;
344
+ read: boolean;
345
+ }[];
346
+ workflows: {
347
+ name: string;
348
+ calls: number;
349
+ failed: number;
350
+ }[];
351
+ };
352
+ given?: NoteUsed[];
353
+ read?: NoteUsed[];
354
+ learned?: import("../learning.js").NoteLearned[];
355
+ skills?: import("../learning.js").LearnedFile[];
356
+ workflows?: import("../learning.js").LearnedFile[];
357
+ run: string;
358
+ state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
359
+ reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
280
360
  detail: string | null;
281
361
  at: string;
282
362
  } | null>;
@@ -13,7 +13,8 @@ import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
13
13
  import { said, STOPPED } from "../learning-words.js";
14
14
  import { learningImpact, noteRuns, notesRead } from "../learning-run.js";
15
15
  import { costSummary, RUN_PATHS, runCostOf } from "../learning-cost.js";
16
- import { runPathOf, workflowNameOf } from "../runner/learning-end.js";
16
+ import { modelsOwn, runPathOf, workflowNameOf } from "../runner/learning-end.js";
17
+ import { feedbackStatus } from "../runner/feedback-round.js";
17
18
  import { PAST_RUNS, servedAnswerOf, servedAnswerStands, servedOf, workflowCostsOf } from "../runner/workflow-first.js";
18
19
  import { reflects } from "../reflect-range.js";
19
20
  import { notesOf } from "../usage.js";
@@ -23,7 +24,7 @@ import { journalEntries } from "../runner/journal-reader.js";
23
24
  import { KINDS } from "../runner/journal-kinds.js";
24
25
  import { keptOf, learnedOf, lostOf } from "../runner/learning-loop.js";
25
26
  import { promotedOf } from "../learn/compile.js";
26
- import { promotionsOf } from "../learn/promote.js";
27
+ import { championOf, gradesOf, gradeView, promotionsOf, withinBar } from "../learn/promote.js";
27
28
  import { GENERAL_NO_BUDGET, GENERAL_NO_ROOM, GENERAL_UNCHECKED } from "../learn/general.js";
28
29
  const timeOf = (ms) => new Date(ms).toISOString();
29
30
  const usdOrNull = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
@@ -223,7 +224,20 @@ export async function agentCostOverStore(store, agentId, limit = Infinity) {
223
224
  // the runs the run's launch reads (pastRunsOverStore) at the all-in cost this series shows: a workflow over the line
224
225
  // shows `needs_revision` with its two numbers, so the page and the launch's decision agree.
225
226
  const workflows = workflowCostsOf(await pastRunsOverStore(store, agentId, new Map(runs.map((run) => [run.run_id, run.total_usd]))));
226
- return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length, unknown_path_runs: unknownPath, workflows };
227
+ const replay = servingReplayOf(await promotionsOf(store.settings, agentId), runs);
228
+ return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs, replay), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length, unknown_path_runs: unknownPath, workflows };
229
+ }
230
+ /** The replay the serving promotion was decided on, as the cost summary says it: the champion (championOf) of the learned
231
+ * workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's `replay` numbers
232
+ * and whether they cleared the bar (withinBar, promotion's own). Null when no run was served, nothing serves now (held,
233
+ * or never promoted), or it was promoted with no replay (a dry run). */
234
+ export function servingReplayOf(records, runs) {
235
+ const name = runs.findLast((run) => (run.path === "workflow" || run.path === "handed_back") && run.workflow !== null)?.workflow;
236
+ const score = name ? championOf(records, name)?.replay : undefined;
237
+ if (!score)
238
+ return null;
239
+ const pct = (acc) => Math.round(acc * 1000) / 10;
240
+ return { n: score.n, workflow_pct: pct(score.wf_acc), agent_pct: pct(score.agent_acc), cleared: withinBar(score) };
227
241
  }
228
242
  /** What run `runId`'s learning spent, as its cost per run counts it, over every round a follow-up opened (roundsOf): what
229
243
  * it kept as it answered (`looked`: answeredOf), and its grades' spend (`grade`): each round's learning run's cost once
@@ -237,10 +251,8 @@ export async function learningSpendOf(store, runId, rowUsd) {
237
251
  if (!rounds.length)
238
252
  return { looked: null, grade: 0 };
239
253
  const spent = await roundsSpentOf(store, rounds);
240
- const first = spent.first;
241
- if (rounds.length > 1 && first && typeof first.answered_at === "string")
242
- return { looked: roundsLooked({ answered_at: first.answered_at, job_cost_usd: first.job_cost_usd ?? null, look_back_usd: spent.look, grade_usd: spent.grade }, rowUsd), grade: spent.grade };
243
- return { looked: answeredOf((rounds.at(-1).proposal ?? {})), grade: spent.grade };
254
+ const more = roundsSpendIn(rounds, spent);
255
+ return { looked: more ? roundsLooked(more, rowUsd) : answeredOf((rounds.at(-1).proposal ?? {})), grade: spent.grade };
244
256
  }
245
257
  /** Every round run `runId` kept (one a follow-up opened again is a round past its first), oldest first: none when it kept
246
258
  * no learning. The store's proposal(runId) is the newest round alone; a read of what the run's learning did or spent
@@ -291,7 +303,10 @@ export async function costRunOf(store, run, n) {
291
303
  const started = await learningStartOfRun(store, run.id);
292
304
  // Its figures are what the batch reads: a run with no path named is placed as the agent's here, and left out by the series.
293
305
  const { path, workflow } = pathOfRow(run.metrics, started) ?? { path: "agent", workflow: null };
294
- return { n, run_id: run.id, started_at: new Date(run.startedAt).toISOString(), path, workflow, learned_revision: started?.seed ?? null, ...(await allInOf(store, run)) };
306
+ const { cost_usd, learning_usd, total_usd } = await allInOf(store, run);
307
+ // The run row's stored bound (RunRow.costAtMostUsd, written with a null cost_usd): its cost counts a request cut at what its cap held.
308
+ const cost_upper_bound = typeof run.costAtMostUsd === "number";
309
+ return { n, run_id: run.id, started_at: new Date(run.startedAt).toISOString(), path, workflow, learned_revision: started?.seed ?? null, cost_usd, cost_upper_bound, learning_usd, total_usd };
295
310
  }
296
311
  /** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
297
312
  * and the cost page: of its newest PAST_RUNS runs, each that ended (ended, stopped or failed), is neither imported nor
@@ -338,7 +353,7 @@ export async function runPathOverStore(store, runId, started, redact) {
338
353
  // runner's `redact`, adapter-loop.ts servedAnswerText): an agent that says it again leaves the path the workflow's.
339
354
  const answer = servedAnswerOf(entries)?.answer ?? "";
340
355
  const alone = served.outcome === "answered" && servedAnswerStands(answer, rows, redact ? redact(answer) : undefined);
341
- return { path: alone ? "workflow" : "handed_back", workflow: served.workflow, ...(served.digest ? { digest: served.digest } : {}) };
356
+ return { path: alone ? "workflow" : "handed_back", workflow: served.workflow, ...(served.digest ? { digest: served.digest } : {}), ...(served.promotion !== undefined ? { promotion: served.promotion } : {}) };
342
357
  }
343
358
  const path = runPathOf(rows);
344
359
  // Only a name the launch offered: a call's raw `name` (a failed call's included) is the model's text, never shown.
@@ -423,13 +438,11 @@ export function roundsLooked(rounds, rowUsd) {
423
438
  }
424
439
  export async function roundsSpendOf(store, runId) {
425
440
  const rounds = await roundsOf(store, runId);
426
- if (rounds.length < 2)
427
- return undefined;
428
- const { first, look, grade } = await roundsSpentOf(store, rounds);
429
- if (!first || typeof first.answered_at !== "string")
430
- return undefined;
431
- return { answered_at: first.answered_at, job_cost_usd: first.job_cost_usd ?? null, look_back_usd: look, grade_usd: grade };
441
+ return rounds.length < 2 ? undefined : roundsSpendIn(rounds, await roundsSpentOf(store, rounds));
432
442
  }
443
+ /** The one reader of a run's rounds' spend (roundsSpendOf, learningSpendOf): undefined for fewer than two rounds, or when
444
+ * the first one's answer time is unknown. */
445
+ const roundsSpendIn = (rounds, { first, look, grade }) => rounds.length > 1 && first && typeof first.answered_at === "string" ? { answered_at: first.answered_at, job_cost_usd: first.job_cost_usd ?? null, look_back_usd: look, grade_usd: grade } : undefined;
433
446
  /** What a run's learning end tells its impact, as ofAgent's learningOf read a held run: how it ended and when, the notes
434
447
  * it started from; when its job answered and its costs once it looked back (a look-back of 0 for an ended one that did
435
448
  * not); its grade's cost once it ended (0 when nothing was graded). */
@@ -549,7 +562,8 @@ function readsSkill(call, name) {
549
562
  export function learnedUseOf(started, reflect, rows, args = new Map(), laid = { skills: [] }, loads = []) {
550
563
  const job = rows.filter((row) => !reflects(reflect, row.id));
551
564
  const results = new Map(job.flatMap((row) => (row.kind === "tool_result" && row.tool_use_id ? [[row.tool_use_id, row.tool_status]] : [])));
552
- const calls = job.filter((row) => row.kind === "tool_use" && !row.parent_tool_use_id && row.tool_use_id).flatMap((row) => {
565
+ const models = modelsOwn(job);
566
+ const calls = job.filter((row) => row.kind === "tool_use" && models(row) && row.tool_use_id).flatMap((row) => {
553
567
  const call = args.get(row.tool_use_id);
554
568
  return call ? [{ id: row.tool_use_id, ...call }] : [];
555
569
  });
@@ -619,5 +633,19 @@ export async function runLearningOverStore(store, runId, shown, secrets, statuse
619
633
  const read = started?.given.length ? notesReadOf(started.given, reflect, rows) : [];
620
634
  const learning = withNotes(end, started, read);
621
635
  const current = holdsForOk(learning) && row && statuses ? currentLearning(learning, await statuses(row.agentId)) : learning;
622
- return runLearningBody({ id: runId, learning: current, seed: started?.seed ?? null, settled, used: learnedUseOf(started, reflect, rows, callArgsOf(entries), laidOf(entries), nativeSkillLoads(entries)) }, shown, secrets);
636
+ const body = runLearningBody({ id: runId, learning: current, seed: started?.seed ?? null, settled, used: learnedUseOf(started, reflect, rows, callArgsOf(entries), laidOf(entries), nativeSkillLoads(entries)) }, shown, secrets);
637
+ // The run's own grade (PUT /runs/{id}/grade), as its agent keeps it and the PUT answered it, with the round it opened.
638
+ // Never its `expected` (a person's words, uncut), nor its label (not kept). Its workflow's name is cut as every other
639
+ // learning name is (`shown.name`): a secret registered after the grade never shows here.
640
+ const grade = row ? (await gradesOf(store.settings, row.agentId).catch(() => [])).find((one) => one.run === runId) : undefined;
641
+ if (!grade)
642
+ return body;
643
+ const { expected: _, ...graded } = gradeView(grade);
644
+ // How that round stands, from the run's journal and its steer's row (feedbackStatus: its words taken, then the run's
645
+ // end; or the steer refused by an end that came first), never the API server's `graded_at` against the runner's
646
+ // `ended_at`. A journal or a row that can't be read fails the read (the console retries it), never says running.
647
+ // null for a grade that opened none.
648
+ const command = grade.feedback ? grade.feedbackCommand : undefined;
649
+ const status = command === undefined ? null : feedbackStatus(used ? entries : await runEntries(store, runId, BACKGROUND_CONTEXT), await store.commands(runId, command - 1).then((rows) => rows.find((one) => one.id === command)));
650
+ return { ...body, graded: { ...graded, workflow: graded.workflow === null ? null : shown.name(graded.workflow), feedback_status: status } };
623
651
  }
@@ -14,7 +14,12 @@ export interface RunRowView {
14
14
  readonly state: RunReadState;
15
15
  readonly startedAt: string;
16
16
  readonly endedAt?: string;
17
+ /** What the run cost (a run still going: its booked-so-far spend); absent when unknown, and absent when an ended run's
18
+ * stored cost is only the most it can have cost (`costAtMostUsd`), as the store's row reads it (RunRow.costUsd). */
17
19
  readonly costUsd?: number;
20
+ /** An ended run's stored cost when that is the most it can have cost, not its cost (RunRow.costAtMostUsd): said "at
21
+ * most", never summed as spend. Absent otherwise. */
22
+ readonly costAtMostUsd?: number;
18
23
  readonly summary?: string;
19
24
  readonly archivedAt?: string;
20
25
  readonly importedFrom?: ImportedFrom;