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

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 (423) hide show
  1. package/CHANGELOG.md +455 -0
  2. package/README.md +376 -125
  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-B8Zn1Iqn.css +1 -0
  37. package/dist/console/assets/index-Jbxjcmdp.js +705 -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 +83 -0
  44. package/dist/email/account.js +159 -0
  45. package/dist/email/answer.d.ts +15 -0
  46. package/dist/email/answer.js +217 -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 +373 -0
  53. package/dist/email/names.d.ts +50 -0
  54. package/dist/email/names.js +74 -0
  55. package/dist/email/routes.d.ts +10 -0
  56. package/dist/email/routes.js +50 -0
  57. package/dist/email/tools.d.ts +27 -0
  58. package/dist/email/tools.js +562 -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 +12 -4
  93. package/dist/learn/compile.js +57 -20
  94. package/dist/learn/grade.d.ts +4 -0
  95. package/dist/learn/grade.js +4 -1
  96. package/dist/learn/promote.d.ts +130 -64
  97. package/dist/learn/promote.js +113 -202
  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 +35 -8
  109. package/dist/learning-cost.js +27 -9
  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 +39 -2
  118. package/dist/local-models.js +49 -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 +2 -1
  164. package/dist/openapi.js +404 -93
  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 +10 -2
  170. package/dist/port-models.js +6 -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 +14 -0
  180. package/dist/refusal-words.js +16 -2
  181. package/dist/run-launch.d.ts +12 -1
  182. package/dist/run-launch.js +13 -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 +44 -38
  191. package/dist/run-view.js +93 -56
  192. package/dist/runnable.d.ts +13 -5
  193. package/dist/runnable.js +69 -60
  194. package/dist/runner/adapter-loop.d.ts +48 -13
  195. package/dist/runner/adapter-loop.js +691 -254
  196. package/dist/runner/adapter-run-spec.d.ts +38 -12
  197. package/dist/runner/adapter-run-spec.js +175 -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 +95 -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 +59 -13
  217. package/dist/runner/journal-kinds.js +48 -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 +14 -3
  237. package/dist/runner/model-route.js +155 -19
  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 +76 -10
  243. package/dist/runner/promotion.js +476 -154
  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 +568 -137
  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/dialect.d.ts +3 -0
  278. package/dist/store/dialect.js +1 -0
  279. package/dist/store/index.d.ts +1 -1
  280. package/dist/store/native-command-owner.d.ts +10 -0
  281. package/dist/store/native-command-owner.js +47 -0
  282. package/dist/store/postgres/connection.d.ts +11 -5
  283. package/dist/store/postgres/connection.js +44 -17
  284. package/dist/store/postgres/dialect.js +5 -0
  285. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  286. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  287. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  288. package/dist/store/postgres/store.d.ts +7 -3
  289. package/dist/store/postgres/store.js +4 -0
  290. package/dist/store/schema.d.ts +7 -0
  291. package/dist/store/schema.js +20 -1
  292. package/dist/store/sqlite/connection.js +72 -8
  293. package/dist/store/sqlite/run-launch.d.ts +11 -0
  294. package/dist/store/sqlite/run-launch.js +8 -0
  295. package/dist/store/sqlite/run-patch.d.ts +8 -1
  296. package/dist/store/sqlite/run-patch.js +14 -3
  297. package/dist/store/sqlite/store.js +170 -34
  298. package/dist/store/sqlite/worker.d.ts +2 -0
  299. package/dist/store/sqlite/worker.js +13 -10
  300. package/dist/store/store.d.ts +67 -7
  301. package/dist/store-reads/analytics.d.ts +7 -7
  302. package/dist/store-reads/analytics.js +23 -5
  303. package/dist/store-reads/cap.js +8 -6
  304. package/dist/store-reads/journal.d.ts +5 -0
  305. package/dist/store-reads/journal.js +85 -41
  306. package/dist/store-reads/learning.d.ts +115 -18
  307. package/dist/store-reads/learning.js +170 -68
  308. package/dist/store-reads/runs.d.ts +5 -0
  309. package/dist/store-reads/runs.js +3 -2
  310. package/dist/store-view.js +75 -21
  311. package/dist/template-eval.d.ts +73 -11
  312. package/dist/template-eval.js +535 -75
  313. package/dist/templates.d.ts +84 -21
  314. package/dist/templates.js +254 -47
  315. package/dist/text-urls.d.ts +38 -0
  316. package/dist/text-urls.js +170 -0
  317. package/dist/timeline/index.d.ts +3 -2
  318. package/dist/timeline/index.js +3 -2
  319. package/dist/timeline/labels.d.ts +5 -2
  320. package/dist/timeline/labels.js +29 -6
  321. package/dist/timeline/origin.d.ts +1 -1
  322. package/dist/timeline/origin.js +2 -2
  323. package/dist/timeline/render-text.js +1 -1
  324. package/dist/timeline/timeline.d.ts +66 -4
  325. package/dist/timeline/timeline.js +160 -30
  326. package/dist/timeline/util.d.ts +5 -0
  327. package/dist/timeline/util.js +44 -8
  328. package/dist/timeline/web-calls.d.ts +17 -0
  329. package/dist/timeline/web-calls.js +106 -0
  330. package/dist/tool-gate.d.ts +46 -44
  331. package/dist/tool-gate.js +101 -92
  332. package/dist/tool-list.d.ts +4 -1
  333. package/dist/tool-list.js +8 -1
  334. package/dist/tool-names.d.ts +18 -13
  335. package/dist/tool-names.js +19 -17
  336. package/dist/tool-plane.d.ts +17 -13
  337. package/dist/tool-plane.js +12 -5
  338. package/dist/tools.d.ts +57 -16
  339. package/dist/tools.js +33 -28
  340. package/dist/trigger-adapter.d.ts +56 -5
  341. package/dist/trigger-adapter.js +6 -0
  342. package/dist/trigger-adapters.js +3 -1
  343. package/dist/trigger-composio.d.ts +10 -0
  344. package/dist/trigger-composio.js +122 -0
  345. package/dist/trigger-email.d.ts +4 -0
  346. package/dist/trigger-email.js +181 -0
  347. package/dist/trigger-signatures.d.ts +6 -10
  348. package/dist/trigger-signatures.js +16 -16
  349. package/dist/trigger-targets.d.ts +1 -1
  350. package/dist/trigger-targets.js +4 -3
  351. package/dist/trigger-webhook.js +6 -4
  352. package/dist/triggers.d.ts +105 -8
  353. package/dist/triggers.js +286 -62
  354. package/dist/uploads.d.ts +9 -0
  355. package/dist/uploads.js +27 -0
  356. package/dist/validate.js +1 -7
  357. package/dist/web-fake.d.ts +56 -0
  358. package/dist/web-fake.js +102 -0
  359. package/dist/web-fetch-direct.d.ts +3 -0
  360. package/dist/web-fetch-direct.js +4 -1
  361. package/dist/web-fetch.d.ts +5 -1
  362. package/dist/web-fetch.js +8 -31
  363. package/dist/web-search.d.ts +51 -2
  364. package/dist/web-search.js +116 -18
  365. package/dist/webhooks.d.ts +2 -1
  366. package/dist/webhooks.js +5 -1
  367. package/dist/workflow/decision-recovery.js +5 -2
  368. package/dist/workflow/decisions.d.ts +7 -0
  369. package/dist/workflow/node-runner.js +10 -2
  370. package/dist/workspace/archil-claim.d.ts +3 -0
  371. package/dist/workspace/archil-claim.js +9 -2
  372. package/dist/workspace/computer-deps.d.ts +22 -9
  373. package/dist/workspace/computer-deps.js +78 -37
  374. package/dist/workspace/computer-for-claim.d.ts +54 -4
  375. package/dist/workspace/computer-for-claim.js +179 -39
  376. package/dist/workspace/computer-janitor.d.ts +10 -3
  377. package/dist/workspace/computer-janitor.js +96 -29
  378. package/dist/workspace/computer-kept.d.ts +82 -0
  379. package/dist/workspace/computer-kept.js +147 -0
  380. package/dist/workspace/computer-mcp.js +4 -3
  381. package/dist/workspace/computer-ports.d.ts +23 -3
  382. package/dist/workspace/computer-ports.js +115 -5
  383. package/dist/workspace/index.d.ts +1 -2
  384. package/dist/workspace/index.js +1 -2
  385. package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
  386. package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
  387. package/dist/workspace/resolve-computer.d.ts +15 -3
  388. package/dist/workspace/resolve-computer.js +10 -7
  389. package/dist/workspace/revision-skills.d.ts +6 -2
  390. package/dist/workspace/revision-skills.js +12 -5
  391. package/dist/workspace/run-end-computers.d.ts +30 -0
  392. package/dist/workspace/run-end-computers.js +137 -0
  393. package/dist/workspace/run-tools.d.ts +28 -29
  394. package/dist/workspace/run-tools.js +29 -30
  395. package/dist/wrap-up.d.ts +19 -5
  396. package/dist/wrap-up.js +31 -4
  397. package/package.json +13 -9
  398. package/skills/agentrun-serve/SKILL.md +248 -10
  399. package/templates/README.md +117 -23
  400. package/templates/TOOLS.md +168 -0
  401. package/templates/code-review/agent.md +18 -4
  402. package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  404. package/templates/code-review/evals/other-repo/case.yaml +1 -1
  405. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  406. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  407. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  408. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  409. package/templates/code-review/skills/review/DEEP.md +2 -2
  410. package/templates/code-review/skills/review/REVIEWER.md +2 -2
  411. package/templates/code-review/skills/review/SKILL.md +7 -3
  412. package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
  413. package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
  414. package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
  415. package/templates/release-notes/evals/other-repo/case.yaml +1 -1
  416. package/dist/console/assets/index-CjqQirbo.css +0 -1
  417. package/dist/console/assets/index-b6-XY5A9.js +0 -576
  418. package/dist/host-calls.d.ts +0 -20
  419. package/dist/host-calls.js +0 -12
  420. package/dist/runner/adapters/pi-computer.d.ts +0 -9
  421. package/dist/runner/adapters/pi-computer.js +0 -51
  422. package/dist/workspace/computer-script.d.ts +0 -53
  423. 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">;
@@ -26,8 +27,22 @@ type KeptRow = {
26
27
  };
27
28
  /** What a kept row says of a run that looked back (learning-run.ts closeLearning's fields): none for one that did not. */
28
29
  declare function answeredOf(row: KeptRow): Pick<Learning, "answered_at" | "job_cost_usd" | "look_back_usd">;
29
- /** Run `runId`'s learning end (its newest round's, or round `round`'s); null when the run kept no learning. Proposed while its learning run has not ended. */
30
- export declare function runLearningEnd(store: Store, runId: string, round?: number): Promise<RunLearningEnd | null>;
30
+ /** The reads of a run's records a learning read makes: its launch, a round of its kept learning, a run's row (its
31
+ * learning run's). The store's own reads, one a run, or an agent's read at once (agentRecordsOf). */
32
+ export type RunRecords = {
33
+ /** `learningStart`: a run's learning start read from the agent's one narrow read (agentRecordsOf), when it was; absent, the run's launch is read. */
34
+ readonly runs: Pick<Store["runs"], "launch" | "get"> & {
35
+ readonly learningStart?: (runId: string) => Promise<RunLaunch["learning"]>;
36
+ };
37
+ readonly learning: Pick<Store["learning"], "proposal">;
38
+ };
39
+ /** Agent `agentId`'s runs' records read at once, whatever their number: its runs' launches (Store.runs.launches) and every
40
+ * round its runs' learning kept with the learning runs they name (Store.learning.kept), two reads beside `listed` (its
41
+ * runs, as runs.list read them). Each answers as the store's per-run read does: a run of `listed` with no launch row is
42
+ * StoreLaunchMissing, one that kept no learning has no round. A run not of `listed` is read from the store. */
43
+ export declare function agentRecordsOf(store: Store, agentId: string, listed: readonly RunRecord[]): Promise<RunRecords>;
44
+ /** Run `runId`'s learning end (its newest round's, or round `round`'s); null when the run kept no learning. Proposed while its learning run has not ended. `records`: where its rows are read (the store's per-run reads by default). */
45
+ export declare function runLearningEnd(store: Store, runId: string, round?: number, records?: RunRecords): Promise<RunLearningEnd | null>;
31
46
  /** How the runs that tried to learn fared (GET /stats's `learning`): `runs` with a learning end, `merged`, `dropped` by
32
47
  * reason, and `in_progress` (proposed, its learning run not ended). The shape today's counts give (learning-run.ts
33
48
  * learningStats). */
@@ -40,8 +55,9 @@ export type LearningCounts = {
40
55
  /** GET /stats's learning counts from the one store, over the runs `filter` picks as the analytics pick them (not archived,
41
56
  * their own or their agent's; started in [from, to); of `agent`): an agentic run with a learning end counts, its end
42
57
  * read as the run's view reads it (runLearningEnd). A workflow's run, and one with no learning, is not counted; nor is
43
- * one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. */
44
- export declare function learningCountsOverStore(store: Store, filter: AnalyticsFilter): Promise<LearningCounts>;
58
+ * one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. Each
59
+ * agent's runs' records are read at once (agentRecordsOf; `records`, already read for `filter.agent`), never a read a run. */
60
+ export declare function learningCountsOverStore(store: Store, filter: AnalyticsFilter, records?: RunRecords): Promise<LearningCounts>;
45
61
  /** What learning spent outside any run (GET /usage's `learning` meter) in [from, to) (ms), one entry per run whose
46
62
  * learning ended then, as the learning ledger's lines gave it: its agent, when its learning ended, and what its grade
47
63
  * cost: 0 for a run never graded, null when the grade's spend is unknown (a grade that failed), never $0 then. One read
@@ -57,13 +73,15 @@ export declare function learningSpendOverStore(store: Store, window: {
57
73
  /** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
58
74
  * counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
59
75
  * agentLearningOverStore's. */
60
- export declare function agentLearningCountsOverStore(store: Store, agentId: string): Promise<Omit<LearningCounts, "runs">>;
76
+ export declare function agentLearningCountsOverStore(store: Store, agentId: string, records?: RunRecords): Promise<Omit<LearningCounts, "runs">>;
61
77
  /** Agent `agentId`'s learning view from the one store (GET /agents/{id}/learning, learning-run.ts ofAgent): its counts
62
78
  * (agentLearningCountsOverStore), each note's runs given it and that read it (noteRuns over notesOf), and what learning
63
79
  * changed (learningImpact), never a run's files. Each run's part is read from its launch (the notes it was given,
64
80
  * learningStartOf), its journal once final (the notes its job read, notesReadOf) and its learning end (when its job
65
81
  * answered and what it and looking back cost, its grade's cost). `seed_notes`, the notes a run started from, is its
66
- * launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes). */
82
+ * launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes). Its runs'
83
+ * launches and learning are read at once (agentRecordsOf), and a settled run's journal once a server (settledCache):
84
+ * a read a run only the first time it is seen. */
67
85
  export declare function agentLearningOverStore(store: Store, agentId: string): Promise<{
68
86
  counts: Omit<LearningCounts, "runs">;
69
87
  impact: Impact;
@@ -86,6 +104,11 @@ export declare function agentCostOverStore(store: Store, agentId: string, limit?
86
104
  unknown_path_runs: number;
87
105
  workflows: ReturnType<typeof workflowCostsOf>;
88
106
  }>;
107
+ /** The replay the serving promotion was decided on, as the cost summary says it: the champion (championOf) of the learned
108
+ * workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's `replay` numbers
109
+ * and whether they cleared the bar (withinBar, promotion's own). Null when no run was served, nothing serves now (held,
110
+ * or never promoted), or it was promoted with no replay (a dry run). */
111
+ export declare function servingReplayOf(records: readonly PromotionRecord[], runs: readonly CostRun[]): CostReplay | null;
89
112
  /** What run `runId`'s learning spent, as its cost per run counts it, over every round a follow-up opened (roundsOf): what
90
113
  * it kept as it answered (`looked`: answeredOf), and its grades' spend (`grade`): each round's learning run's cost once
91
114
  * that run ended, stopped or failed (runner/learning-loop.ts keeps the grade's spend there, a paid grade a person stopped
@@ -93,28 +116,28 @@ export declare function agentCostOverStore(store: Store, agentId: string, limit?
93
116
  * (roundsSpendOf's figures): its job is what it had cost when its first round answered, and everything after (each
94
117
  * later round's follow-up turn and every round's look-back: feedback the run was given is learning, never the job) is
95
118
  * its look-back here, `rowUsd` (the run's row cost) less that job (roundsLooked). */
96
- export declare function learningSpendOf(store: Pick<Store, "learning" | "runs">, runId: string, rowUsd: number | null): Promise<{
119
+ export declare function learningSpendOf(store: RunRecords, runId: string, rowUsd: number | null): Promise<{
97
120
  looked: ReturnType<typeof answeredOf> | null;
98
121
  grade: number | null;
99
122
  }>;
100
123
  /** Every round run `runId` kept (one a follow-up opened again is a round past its first), oldest first: none when it kept
101
124
  * no learning. The store's proposal(runId) is the newest round alone; a read of what the run's learning did or spent
102
125
  * reads them all. */
103
- export declare function roundsOf(store: Pick<Store, "learning">, runId: string): Promise<LearningProposal[]>;
126
+ export declare function roundsOf(store: Pick<RunRecords, "learning">, runId: string): Promise<LearningProposal[]>;
104
127
  type RunRecord = NonNullable<Awaited<ReturnType<Store["runs"]["get"]>>>;
105
128
  /** A run's own cost and what learning added for it (runCostOf): its row's cost, every round of its learning (a run a
106
129
  * follow-up opened again, a review's or a person's, learned in rounds: every round's look-back and grade, roundsSpendOf,
107
130
  * never the newest round's alone), else its one round's (learningSpendOf). `total_usd` is the run's all-in cost, the one
108
131
  * the cost page shows and the money rule reads (pastRunsOverStore); null when any part is unknown. */
109
- export declare function allInOf(store: Store, run: RunRecord): Promise<ReturnType<typeof runCostOf>>;
132
+ export declare function allInOf(store: RunRecords, run: RunRecord): Promise<ReturnType<typeof runCostOf>>;
110
133
  /** One run of the cost series, as number `n` of it: its figures (allInOf) and its path (agentCostOverStore's loop body,
111
134
  * and a learning batch's row once the run's learning has settled). */
112
- export declare function costRunOf(store: Store, run: RunRecord, n: number): Promise<CostRun>;
135
+ export declare function costRunOf(store: RunRecords, run: RunRecord, n: number): Promise<CostRun>;
113
136
  /** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
114
137
  * and the cost page: of its newest PAST_RUNS runs, each that ended (ended, stopped or failed), is neither imported nor
115
138
  * archived nor a workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id
116
- * (the cost page's series), read again for no run. */
117
- export declare function pastRunsOverStore(store: Store, agentId: string, known?: ReadonlyMap<string, number | null>): Promise<PastRun[]>;
139
+ * (the cost page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
140
+ export declare function pastRunsOverStore(store: Store, agentId: string, known?: ReadonlyMap<string, number | null>, records?: RunRecords): Promise<PastRun[]>;
118
141
  /** The path run `runId` took and the learned workflow it ran, the one classifier its run record keeps (metrics.path,
119
142
  * metrics.workflow, metrics.workflow_digest: workflow-first.ts pathMetrics, written at the run's end) and its cost per run
120
143
  * reads (pathOfRow). A run its learned workflow served first (its WORKFLOW_FIRST entry, servedOf): `workflow` when it
@@ -127,6 +150,7 @@ export declare function runPathOverStore(store: Store, runId: string, started: R
127
150
  path: RunPath;
128
151
  workflow: string | null;
129
152
  digest?: string;
153
+ promotion?: number;
130
154
  }>;
131
155
  /** What a run's claim laid of its learning seed: the learned skills and workflows it was given, by name. */
132
156
  type Laid = {
@@ -136,11 +160,11 @@ type Laid = {
136
160
  /** What every claim of a run laid, from its learningLaid entries, each name once: a resumed claim finds an earlier
137
161
  * claim's skill folders there already and lays none of them again, though the run still has them. None laid when it has
138
162
  * no entry. */
139
- export declare function laidOf(entries: readonly EntryLike[]): Laid;
163
+ export declare function laidOf(entries: readonly Pick<EntryLike, "kind" | "data">[]): Laid;
140
164
  /** What every round of a run that a follow-up opened again spent (undefined for a run with one round): when its first
141
165
  * 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
166
  * figure that is unknown in any round is unknown (null). */
143
- export type RoundsSpend = {
167
+ type RoundsSpend = {
144
168
  answered_at: string;
145
169
  job_cost_usd: number | null;
146
170
  look_back_usd: number | null;
@@ -157,7 +181,7 @@ export declare function roundsLooked(rounds: RoundsSpend, rowUsd: number | null)
157
181
  job_cost_usd: number | null;
158
182
  look_back_usd: number | null;
159
183
  };
160
- export declare function roundsSpendOf(store: Pick<Store, "learning" | "runs">, runId: string): Promise<RoundsSpend | undefined>;
184
+ export declare function roundsSpendOf(store: RunRecords, runId: string): Promise<RoundsSpend | undefined>;
161
185
  /** What a run's learning end tells its impact, as ofAgent's learningOf read a held run: how it ended and when, the notes
162
186
  * 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
163
187
  * not); its grade's cost once it ended (0 when nothing was graded). */
@@ -275,8 +299,81 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
275
299
  skills?: import("../learning.js").LearnedFile[];
276
300
  workflows?: import("../learning.js").LearnedFile[];
277
301
  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;
302
+ state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
303
+ reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
304
+ detail: string | null;
305
+ at: string;
306
+ } | {
307
+ graded: {
308
+ workflow: string | null;
309
+ feedback_status: "running" | "ended" | "not_run" | null;
310
+ source: "feedback" | "eval";
311
+ graded_at: string;
312
+ path: "agent" | "workflow" | "handed_back" | "replay";
313
+ workflow_digest: string | null;
314
+ feedback: "revise" | "look_back" | null;
315
+ run_id: string;
316
+ correct: boolean;
317
+ };
318
+ seed: string | null;
319
+ merged: string | null;
320
+ pending: {
321
+ file: string;
322
+ name: string;
323
+ }[];
324
+ verdict: {
325
+ merge: boolean;
326
+ reason: string;
327
+ items: {
328
+ why: string;
329
+ question?: string | undefined;
330
+ origin?: "run" | "you" | undefined;
331
+ pending?: boolean | undefined;
332
+ file: string;
333
+ keep: boolean;
334
+ }[];
335
+ } | null;
336
+ problems: {
337
+ detail: string;
338
+ path?: string | undefined;
339
+ rule: import("../learn/check.js").Rule;
340
+ }[];
341
+ compiled: {
342
+ workflow: string;
343
+ from_notes: string[];
344
+ attempts: {
345
+ ok: boolean;
346
+ errors: string[];
347
+ }[];
348
+ digest: string | null;
349
+ promoted: boolean | null;
350
+ } | null;
351
+ draft_errors: string[];
352
+ cost_usd: {
353
+ grade: number | null;
354
+ };
355
+ tokens: {
356
+ grade: import("../learning.js").Tokens | null;
357
+ };
358
+ used: {
359
+ skills: {
360
+ name: string;
361
+ read: boolean;
362
+ }[];
363
+ workflows: {
364
+ name: string;
365
+ calls: number;
366
+ failed: number;
367
+ }[];
368
+ };
369
+ given?: NoteUsed[];
370
+ read?: NoteUsed[];
371
+ learned?: import("../learning.js").NoteLearned[];
372
+ skills?: import("../learning.js").LearnedFile[];
373
+ workflows?: import("../learning.js").LearnedFile[];
374
+ run: string;
375
+ state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
376
+ reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
280
377
  detail: string | null;
281
378
  at: string;
282
379
  } | null>;