@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35

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 (466) hide show
  1. package/CHANGELOG.md +368 -0
  2. package/README.md +341 -208
  3. package/dist/adapters.d.ts +3 -4
  4. package/dist/adapters.js +18 -15
  5. package/dist/agent-rows.d.ts +99 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +75 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/archil-settings.d.ts +11 -1
  16. package/dist/archil-settings.js +10 -0
  17. package/dist/bash-read-only.d.ts +35 -0
  18. package/dist/bash-read-only.js +778 -0
  19. package/dist/box-settings.d.ts +3 -23
  20. package/dist/box-settings.js +7 -51
  21. package/dist/boxes.d.ts +17 -0
  22. package/dist/boxes.js +27 -20
  23. package/dist/browser-commands.d.ts +5 -2
  24. package/dist/browser-commands.js +4 -4
  25. package/dist/browser-computer.d.ts +5 -0
  26. package/dist/browser-computer.js +21 -0
  27. package/dist/browser-cost.d.ts +9 -6
  28. package/dist/browser-cost.js +95 -51
  29. package/dist/browser-live.d.ts +7 -20
  30. package/dist/browser-live.js +15 -93
  31. package/dist/browser-person.d.ts +18 -51
  32. package/dist/browser-person.js +94 -277
  33. package/dist/budget.d.ts +0 -5
  34. package/dist/budget.js +0 -5
  35. package/dist/cap.d.ts +14 -8
  36. package/dist/cap.js +19 -9
  37. package/dist/cli.js +71 -18
  38. package/dist/closed-pipes.d.ts +2 -0
  39. package/dist/closed-pipes.js +13 -0
  40. package/dist/computer-commands.d.ts +2 -0
  41. package/dist/computer-commands.js +2 -0
  42. package/dist/computer-keys.d.ts +20 -10
  43. package/dist/computer-keys.js +36 -54
  44. package/dist/computer-setting.d.ts +20 -3
  45. package/dist/computer-setting.js +58 -10
  46. package/dist/computers.d.ts +35 -2
  47. package/dist/computers.js +72 -11
  48. package/dist/confine.d.ts +120 -0
  49. package/dist/confine.js +436 -0
  50. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  51. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  52. package/dist/console/index.html +2 -2
  53. package/dist/content-filter.d.ts +7 -0
  54. package/dist/content-filter.js +23 -0
  55. package/dist/decision-cap.d.ts +7 -29
  56. package/dist/decision-cap.js +3 -94
  57. package/dist/decision-rows.d.ts +1 -1
  58. package/dist/decision-rows.js +1 -1
  59. package/dist/docker-daemon.d.ts +31 -0
  60. package/dist/docker-daemon.js +56 -0
  61. package/dist/effort-guidance.js +4 -3
  62. package/dist/environment.d.ts +0 -3
  63. package/dist/environment.js +3 -5
  64. package/dist/errors.d.ts +1 -2
  65. package/dist/errors.js +9 -9
  66. package/dist/explain.js +3 -1
  67. package/dist/filed-answer.d.ts +32 -0
  68. package/dist/filed-answer.js +160 -0
  69. package/dist/files.d.ts +1 -3
  70. package/dist/files.js +2 -4
  71. package/dist/github-connection.d.ts +1 -1
  72. package/dist/github-connection.js +25 -7
  73. package/dist/github-faux.d.ts +26 -0
  74. package/dist/github-faux.js +76 -0
  75. package/dist/github.d.ts +6 -2
  76. package/dist/github.js +5 -3
  77. package/dist/graph-served.d.ts +5 -3
  78. package/dist/graph-served.js +14 -6
  79. package/dist/graph-view.d.ts +3 -5
  80. package/dist/graph-view.js +9 -16
  81. package/dist/handed-values.d.ts +9 -0
  82. package/dist/handed-values.js +26 -0
  83. package/dist/harness-install.d.ts +1 -7
  84. package/dist/harness-install.js +1 -18
  85. package/dist/harness-opencode/adapter.d.ts +7 -0
  86. package/dist/harness-opencode/adapter.js +23 -6
  87. package/dist/harness-opencode/harness.js +0 -1
  88. package/dist/harness-opencode/host/policy.js +2 -2
  89. package/dist/harness-opencode/index.d.ts +1 -1
  90. package/dist/harness-opencode/index.js +1 -1
  91. package/dist/harness-opencode/verify.d.ts +17 -0
  92. package/dist/harness-opencode/verify.js +30 -10
  93. package/dist/harness-table.js +6 -1
  94. package/dist/heard.js +1 -1
  95. package/dist/held-fd.d.ts +5 -0
  96. package/dist/held-fd.js +14 -0
  97. package/dist/host-calls.d.ts +20 -0
  98. package/dist/host-calls.js +12 -0
  99. package/dist/host-tools.d.ts +4 -21
  100. package/dist/host-tools.js +4 -61
  101. package/dist/host.d.ts +2 -4
  102. package/dist/host.js +2 -7
  103. package/dist/import-summary.d.ts +1 -5
  104. package/dist/import-summary.js +0 -21
  105. package/dist/import.d.ts +6 -6
  106. package/dist/import.js +14 -15
  107. package/dist/index.d.ts +1 -0
  108. package/dist/index.js +1 -0
  109. package/dist/key-refusal.d.ts +5 -1
  110. package/dist/key-refusal.js +19 -4
  111. package/dist/learn/check.d.ts +8 -2
  112. package/dist/learn/check.js +85 -31
  113. package/dist/learn/folder.d.ts +11 -4
  114. package/dist/learn/folder.js +17 -19
  115. package/dist/learn/grade.d.ts +18 -1
  116. package/dist/learn/grade.js +108 -14
  117. package/dist/learn/index.d.ts +5 -5
  118. package/dist/learn/index.js +5 -5
  119. package/dist/learn/learning.sh +1 -14
  120. package/dist/learn/notes.d.ts +14 -3
  121. package/dist/learn/notes.js +16 -6
  122. package/dist/learn/reflect.d.ts +31 -2
  123. package/dist/learn/reflect.js +83 -6
  124. package/dist/learn/relevance.d.ts +24 -0
  125. package/dist/learn/relevance.js +91 -0
  126. package/dist/learn/secrets.d.ts +7 -1
  127. package/dist/learn/secrets.js +86 -19
  128. package/dist/learn/skills.d.ts +159 -18
  129. package/dist/learn/skills.js +644 -64
  130. package/dist/learned-nodes.d.ts +14 -0
  131. package/dist/learned-nodes.js +8 -0
  132. package/dist/learned-workflow.d.ts +41 -6
  133. package/dist/learned-workflow.js +153 -18
  134. package/dist/learning-routes.d.ts +49 -4
  135. package/dist/learning-routes.js +113 -31
  136. package/dist/learning-run.d.ts +16 -31
  137. package/dist/learning-run.js +31 -38
  138. package/dist/learning-words.d.ts +12 -5
  139. package/dist/learning-words.js +18 -9
  140. package/dist/learning.d.ts +91 -97
  141. package/dist/learning.js +176 -320
  142. package/dist/live/stream.js +1 -1
  143. package/dist/live/translate.js +12 -2
  144. package/dist/llm.d.ts +4 -1
  145. package/dist/llm.js +4 -2
  146. package/dist/local-models.d.ts +11 -5
  147. package/dist/local-models.js +13 -8
  148. package/dist/mcp-gateway.d.ts +17 -49
  149. package/dist/mcp-gateway.js +55 -136
  150. package/dist/mcp-oauth.d.ts +10 -14
  151. package/dist/mcp-oauth.js +14 -32
  152. package/dist/mcp-probe.d.ts +0 -7
  153. package/dist/mcp-probe.js +4 -10
  154. package/dist/mcp-servers-store.d.ts +18 -18
  155. package/dist/mcp-servers-store.js +12 -14
  156. package/dist/mcp-store.js +3 -4
  157. package/dist/mcp.js +4 -3
  158. package/dist/model.d.ts +9 -7
  159. package/dist/model.js +51 -27
  160. package/dist/monid.d.ts +0 -2
  161. package/dist/monid.js +3 -6
  162. package/dist/openapi.d.ts +8 -1
  163. package/dist/openapi.js +156 -58
  164. package/dist/page.d.ts +1 -3
  165. package/dist/page.js +6 -18
  166. package/dist/paid-calls.d.ts +21 -27
  167. package/dist/paid-calls.js +26 -61
  168. package/dist/pause.d.ts +2 -19
  169. package/dist/pause.js +5 -74
  170. package/dist/port-models.d.ts +10 -3
  171. package/dist/port-models.js +26 -6
  172. package/dist/propose.d.ts +2 -0
  173. package/dist/propose.js +80 -45
  174. package/dist/push-handler.d.ts +1 -1
  175. package/dist/reflect-range.d.ts +25 -0
  176. package/dist/reflect-range.js +30 -0
  177. package/dist/refusal-words.d.ts +5 -1
  178. package/dist/refusal-words.js +5 -1
  179. package/dist/rows.d.ts +1 -1
  180. package/dist/run-cut.d.ts +0 -6
  181. package/dist/run-cut.js +0 -6
  182. package/dist/run-db.d.ts +2 -11
  183. package/dist/run-db.js +2 -37
  184. package/dist/run-launch.d.ts +21 -2
  185. package/dist/run-launch.js +14 -5
  186. package/dist/run-learning-served.d.ts +21 -4
  187. package/dist/run-learning-served.js +23 -13
  188. package/dist/run-reads-over-store.d.ts +5 -3
  189. package/dist/run-reads-over-store.js +25 -14
  190. package/dist/run-secrets.d.ts +1 -1
  191. package/dist/run-timeline-served.d.ts +5 -1
  192. package/dist/run-timeline-served.js +27 -6
  193. package/dist/run-view.d.ts +37 -22
  194. package/dist/run-view.js +85 -38
  195. package/dist/runnable.d.ts +21 -10
  196. package/dist/runnable.js +35 -12
  197. package/dist/runner/adapter-loop.d.ts +36 -5
  198. package/dist/runner/adapter-loop.js +663 -69
  199. package/dist/runner/adapter-run-spec.d.ts +42 -8
  200. package/dist/runner/adapter-run-spec.js +186 -52
  201. package/dist/runner/adapters/index.js +11 -1
  202. package/dist/runner/adapters/pi.d.ts +40 -2
  203. package/dist/runner/adapters/pi.js +110 -27
  204. package/dist/runner/beside.d.ts +38 -3
  205. package/dist/runner/beside.js +54 -5
  206. package/dist/runner/claim-secrets.d.ts +16 -1
  207. package/dist/runner/claim-secrets.js +62 -14
  208. package/dist/runner/cli-run-spec.d.ts +5 -0
  209. package/dist/runner/cli-run-spec.js +159 -41
  210. package/dist/runner/commands.js +1 -1
  211. package/dist/runner/computer-journal.d.ts +15 -2
  212. package/dist/runner/computer-journal.js +41 -5
  213. package/dist/runner/conformance/harness.d.ts +1 -0
  214. package/dist/runner/conformance/harness.js +123 -13
  215. package/dist/runner/conformance/subject.d.ts +4 -1
  216. package/dist/runner/dispatch.d.ts +8 -1
  217. package/dist/runner/dispatch.js +81 -7
  218. package/dist/runner/end-of-run.d.ts +8 -2
  219. package/dist/runner/end-of-run.js +10 -4
  220. package/dist/runner/github-app.d.ts +7 -2
  221. package/dist/runner/github-app.js +47 -16
  222. package/dist/runner/harness-loops.d.ts +15 -2
  223. package/dist/runner/harness-loops.js +38 -2
  224. package/dist/runner/journal-kinds.d.ts +60 -6
  225. package/dist/runner/journal-kinds.js +43 -5
  226. package/dist/runner/journal-reader.d.ts +1 -1
  227. package/dist/runner/journal-reader.js +2 -2
  228. package/dist/runner/learning-ask.d.ts +4 -0
  229. package/dist/runner/learning-ask.js +15 -1
  230. package/dist/runner/learning-end.d.ts +18 -3
  231. package/dist/runner/learning-end.js +194 -20
  232. package/dist/runner/learning-loop.d.ts +7 -0
  233. package/dist/runner/learning-loop.js +36 -8
  234. package/dist/runner/learning-seed.d.ts +6 -0
  235. package/dist/runner/learning-seed.js +6 -0
  236. package/dist/runner/loop-contract.d.ts +4 -0
  237. package/dist/runner/main.d.ts +61 -9
  238. package/dist/runner/main.js +144 -20
  239. package/dist/runner/mcp-claim.d.ts +3 -0
  240. package/dist/runner/mcp-claim.js +7 -3
  241. package/dist/runner/mcp-github.d.ts +11 -2
  242. package/dist/runner/mcp-github.js +55 -4
  243. package/dist/runner/mcp-run.d.ts +2 -0
  244. package/dist/runner/mcp-run.js +16 -5
  245. package/dist/runner/memory-claim.d.ts +9 -0
  246. package/dist/runner/memory-claim.js +25 -0
  247. package/dist/runner/metrics.d.ts +46 -1
  248. package/dist/runner/metrics.js +156 -1
  249. package/dist/runner/model-route.d.ts +16 -0
  250. package/dist/runner/model-route.js +134 -10
  251. package/dist/runner/reflect-hook.d.ts +12 -1
  252. package/dist/runner/reflect-hook.js +33 -3
  253. package/dist/runner/runner.d.ts +20 -0
  254. package/dist/runner/runner.js +146 -18
  255. package/dist/runner/spec-holds.d.ts +7 -2
  256. package/dist/runner/spec-holds.js +4 -3
  257. package/dist/runner/store-port.d.ts +1 -1
  258. package/dist/runner/store-secrets.d.ts +3 -3
  259. package/dist/runner/store-secrets.js +8 -12
  260. package/dist/runner/text-tools.d.ts +44 -0
  261. package/dist/runner/text-tools.js +237 -0
  262. package/dist/runner/workflow-host.d.ts +7 -2
  263. package/dist/runner/workflow-host.js +3 -1
  264. package/dist/runner/workflow-loop.d.ts +10 -1
  265. package/dist/runner/workflow-loop.js +14 -6
  266. package/dist/runner/workflow-spec.d.ts +21 -0
  267. package/dist/runner/workflow-spec.js +217 -93
  268. package/dist/runs-over-store.d.ts +14 -3
  269. package/dist/runs-over-store.js +100 -23
  270. package/dist/seal-key.d.ts +0 -2
  271. package/dist/seal-key.js +5 -45
  272. package/dist/sealed-settings-store.d.ts +19 -4
  273. package/dist/sealed-settings-store.js +9 -9
  274. package/dist/sealing.d.ts +4 -0
  275. package/dist/sealing.js +20 -0
  276. package/dist/secret-cut.d.ts +1 -1
  277. package/dist/secret-cut.js +1 -1
  278. package/dist/secret-name.d.ts +9 -0
  279. package/dist/secret-name.js +15 -0
  280. package/dist/secret-writes.d.ts +0 -1
  281. package/dist/secret-writes.js +0 -1
  282. package/dist/server-fs.d.ts +4 -0
  283. package/dist/server-fs.js +8 -2
  284. package/dist/server-lock.d.ts +0 -24
  285. package/dist/server-lock.js +5 -85
  286. package/dist/server-secrets-store.d.ts +4 -4
  287. package/dist/server-secrets-store.js +9 -31
  288. package/dist/server-secrets.d.ts +4 -9
  289. package/dist/server-secrets.js +12 -36
  290. package/dist/server.d.ts +37 -56
  291. package/dist/server.js +322 -134
  292. package/dist/sign-ins-store.d.ts +34 -36
  293. package/dist/sign-ins-store.js +27 -38
  294. package/dist/sign-ins.d.ts +2 -119
  295. package/dist/sign-ins.js +5 -311
  296. package/dist/standard-webhooks.d.ts +1 -1
  297. package/dist/standard-webhooks.js +1 -1
  298. package/dist/stats.d.ts +3 -2
  299. package/dist/stats.js +1 -1
  300. package/dist/stop-signals.d.ts +4 -2
  301. package/dist/stop-signals.js +5 -3
  302. package/dist/store/agent-body.d.ts +12 -2
  303. package/dist/store/agent-body.js +22 -4
  304. package/dist/store/deadline.d.ts +18 -0
  305. package/dist/store/deadline.js +45 -0
  306. package/dist/store/index.d.ts +2 -2
  307. package/dist/store/index.js +2 -2
  308. package/dist/store/open.d.ts +6 -3
  309. package/dist/store/open.js +2 -2
  310. package/dist/store/postgres/connection.d.ts +22 -2
  311. package/dist/store/postgres/connection.js +211 -41
  312. package/dist/store/postgres/migrate.d.ts +4 -0
  313. package/dist/store/postgres/migrate.js +9 -2
  314. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  315. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  316. package/dist/store/postgres/store.d.ts +9 -2
  317. package/dist/store/postgres/store.js +9 -0
  318. package/dist/store/schema.js +1 -1
  319. package/dist/store/seal.js +2 -2
  320. package/dist/store/sqlite/connection.js +14 -5
  321. package/dist/store/sqlite/run-patch.d.ts +3 -0
  322. package/dist/store/sqlite/run-patch.js +3 -0
  323. package/dist/store/sqlite/store.js +41 -12
  324. package/dist/store/store.d.ts +35 -6
  325. package/dist/store/store.js +12 -2
  326. package/dist/store-reads/cap.d.ts +1 -1
  327. package/dist/store-reads/cap.js +22 -4
  328. package/dist/store-reads/journal.d.ts +9 -6
  329. package/dist/store-reads/journal.js +129 -18
  330. package/dist/store-reads/learning.d.ts +82 -8
  331. package/dist/store-reads/learning.js +184 -11
  332. package/dist/store-reads/workflow.d.ts +1 -1
  333. package/dist/store-reads/workflow.js +1 -1
  334. package/dist/store-view.d.ts +19 -1
  335. package/dist/store-view.js +95 -27
  336. package/dist/template-eval.d.ts +60 -4
  337. package/dist/template-eval.js +120 -54
  338. package/dist/templates.d.ts +33 -14
  339. package/dist/templates.js +82 -46
  340. package/dist/timeline/group.d.ts +33 -0
  341. package/dist/timeline/group.js +77 -0
  342. package/dist/timeline/index.d.ts +7 -0
  343. package/dist/timeline/index.js +7 -0
  344. package/dist/timeline/labels.d.ts +79 -0
  345. package/dist/timeline/labels.js +150 -0
  346. package/dist/timeline/origin.d.ts +56 -0
  347. package/dist/timeline/origin.js +92 -0
  348. package/dist/timeline/render-text.d.ts +11 -0
  349. package/dist/timeline/render-text.js +62 -0
  350. package/dist/timeline/timeline.d.ts +282 -0
  351. package/dist/timeline/timeline.js +1308 -0
  352. package/dist/timeline/util.d.ts +17 -0
  353. package/dist/timeline/util.js +49 -0
  354. package/dist/tool-budget.d.ts +18 -0
  355. package/dist/tool-budget.js +50 -0
  356. package/dist/tool-gate.d.ts +47 -218
  357. package/dist/tool-gate.js +87 -545
  358. package/dist/tool-keys-store.d.ts +11 -12
  359. package/dist/tool-keys-store.js +24 -31
  360. package/dist/tool-keys.d.ts +5 -101
  361. package/dist/tool-keys.js +8 -267
  362. package/dist/tool-plane.d.ts +23 -52
  363. package/dist/tool-plane.js +23 -81
  364. package/dist/tool-settings-store.d.ts +1 -2
  365. package/dist/tool-settings-store.js +5 -8
  366. package/dist/tools.d.ts +67 -25
  367. package/dist/tools.js +170 -119
  368. package/dist/trigger-adapter.d.ts +2 -2
  369. package/dist/trigger-targets.d.ts +13 -1
  370. package/dist/trigger-targets.js +31 -1
  371. package/dist/triggers.d.ts +2 -2
  372. package/dist/triggers.js +3 -3
  373. package/dist/turn-end.d.ts +1 -1
  374. package/dist/turn-end.js +1 -1
  375. package/dist/turns.d.ts +0 -6
  376. package/dist/turns.js +0 -19
  377. package/dist/uploads.d.ts +28 -5
  378. package/dist/uploads.js +83 -10
  379. package/dist/usage.d.ts +1 -49
  380. package/dist/usage.js +3 -84
  381. package/dist/validate.d.ts +4 -0
  382. package/dist/validate.js +33 -14
  383. package/dist/webhooks.d.ts +102 -76
  384. package/dist/webhooks.js +266 -233
  385. package/dist/workflow-run.d.ts +114 -0
  386. package/dist/workflow-run.js +144 -0
  387. package/dist/workspace/archil-claim.d.ts +2 -2
  388. package/dist/workspace/archil-claim.js +4 -3
  389. package/dist/workspace/archil-disk.d.ts +10 -1
  390. package/dist/workspace/archil-disk.js +4 -0
  391. package/dist/workspace/archil-exec.d.ts +12 -2
  392. package/dist/workspace/archil-exec.js +16 -0
  393. package/dist/workspace/archil.d.ts +2 -2
  394. package/dist/workspace/archil.js +25 -5
  395. package/dist/workspace/attach.js +2 -0
  396. package/dist/workspace/beneath.d.ts +19 -0
  397. package/dist/workspace/beneath.js +106 -0
  398. package/dist/workspace/computer-deps.d.ts +26 -9
  399. package/dist/workspace/computer-deps.js +144 -43
  400. package/dist/workspace/computer-for-claim.d.ts +17 -14
  401. package/dist/workspace/computer-for-claim.js +99 -26
  402. package/dist/workspace/computer-hold.d.ts +6 -1
  403. package/dist/workspace/computer-hold.js +6 -1
  404. package/dist/workspace/computer-janitor.d.ts +47 -0
  405. package/dist/workspace/computer-janitor.js +182 -0
  406. package/dist/workspace/computer-ledger.d.ts +1 -8
  407. package/dist/workspace/computer-ledger.js +0 -3
  408. package/dist/workspace/computer-providers.d.ts +5 -3
  409. package/dist/workspace/computer-providers.js +11 -9
  410. package/dist/workspace/grep-worker.d.ts +5 -0
  411. package/dist/workspace/grep-worker.js +9 -6
  412. package/dist/workspace/hands.d.ts +5 -2
  413. package/dist/workspace/hands.js +4 -3
  414. package/dist/workspace/index.d.ts +6 -5
  415. package/dist/workspace/index.js +4 -4
  416. package/dist/workspace/local.d.ts +14 -2
  417. package/dist/workspace/local.js +170 -43
  418. package/dist/workspace/paths.js +3 -2
  419. package/dist/workspace/pi-env.d.ts +4 -0
  420. package/dist/workspace/pi-env.js +3 -2
  421. package/dist/workspace/resolve-computer.d.ts +55 -10
  422. package/dist/workspace/resolve-computer.js +66 -14
  423. package/dist/workspace/run-tools.d.ts +15 -31
  424. package/dist/workspace/run-tools.js +19 -30
  425. package/dist/workspace/workspace.d.ts +5 -0
  426. package/dist/workspace-paths.d.ts +0 -17
  427. package/dist/workspace-paths.js +1 -41
  428. package/dist/workspace.d.ts +0 -17
  429. package/dist/workspace.js +4 -110
  430. package/package.json +14 -14
  431. package/skills/agentrun-serve/SKILL.md +1 -1
  432. package/templates/README.md +11 -5
  433. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  434. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  435. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  436. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  437. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  438. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  439. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  440. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  441. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  442. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  443. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  444. package/templates/market-monitor/agent.md +2 -2
  445. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  446. package/templates/release-notes/agent.md +11 -0
  447. package/dist/bound-files.d.ts +0 -4
  448. package/dist/bound-files.js +0 -164
  449. package/dist/coding-tools.d.ts +0 -47
  450. package/dist/coding-tools.js +0 -189
  451. package/dist/computer-adb.d.ts +0 -12
  452. package/dist/computer-adb.js +0 -14
  453. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  454. package/dist/console/assets/index-DvW6Aled.css +0 -1
  455. package/dist/grade.d.ts +0 -63
  456. package/dist/grade.js +0 -150
  457. package/dist/mcp-servers.d.ts +0 -269
  458. package/dist/mcp-servers.js +0 -456
  459. package/dist/packs.d.ts +0 -71
  460. package/dist/packs.js +0 -180
  461. package/dist/sealed-settings.d.ts +0 -60
  462. package/dist/sealed-settings.js +0 -171
  463. package/dist/sessions.d.ts +0 -6
  464. package/dist/sessions.js +0 -109
  465. package/dist/workspace/computer-serves.d.ts +0 -12
  466. package/dist/workspace/computer-serves.js +0 -15
@@ -0,0 +1,150 @@
1
+ import { cut, firstLine, json, list, obj, scrubUrls, str, where } from "./util.js";
2
+ const labels = new Map();
3
+ const folds = new Map();
4
+ const names = new Map();
5
+ /** Registers the label of one tool, in the past tense, and with `name` what the tool is called where calls are counted
6
+ * (a run's analytics). A host adds its own tools here. */
7
+ export function registerLabel(tool, label, fold, { name } = {}) {
8
+ labels.set(tool, label);
9
+ if (fold)
10
+ folds.set(tool, fold);
11
+ if (name)
12
+ names.set(tool, name);
13
+ }
14
+ /** A remote MCP server's tool as the harnesses name it, `mcp__<server>__<tool>` (a server's name has no `_`; `hands` is a
15
+ * harness's own tools'), read `<server> · <tool>`. */
16
+ const MCP_TOOL = /^mcp__([a-z][a-z0-9-]{0,31})__([A-Za-z0-9_-]{1,64})$/;
17
+ const mcpLabel = (tool) => {
18
+ const match = MCP_TOOL.exec(tool);
19
+ return match && match[1] !== "hands" ? `${match[1]} · ${match[2]}` : undefined;
20
+ };
21
+ /** What a tool is called where its calls are counted, in plain words: its registered name, else the name it was called by. */
22
+ export const nameOf = (tool) => names.get(tool) ?? mcpLabel(tool) ?? tool;
23
+ const outcomes = new Map();
24
+ /** Registers how one tool's result tells its outcome. A host adds its own tools here. */
25
+ export function registerOutcome(tool, outcome) {
26
+ outcomes.set(tool, outcome);
27
+ }
28
+ /** The outcome of a call that returned (not one that errored), when its tool tells one. */
29
+ export const outcomeOf = (tool, result) => (result.isError ? undefined : outcomes.get(tool)?.(result));
30
+ /** Whether a finished call failed: an error, or a result its tool's outcome reads as failed (a refused fetch). The one
31
+ * rule a call's row and a run's tool counts both read; `outcome` is the result's own (outcomeOf), so a caller that has
32
+ * read it already (a row, which also shows it) reads it once: a fetch's outcome parses its whole page. */
33
+ export const failedWith = (result, outcome) => result.isError || outcome?.failed === true;
34
+ /** failedWith, the outcome read here. */
35
+ export const callFailed = (tool, result) => failedWith(result, outcomeOf(tool, result));
36
+ const turnEnding = new Set();
37
+ /** Registers a tool that ends its turn (pi's `terminate`): what the person sends after a round of such tools is their
38
+ * next message, never a steer into a running turn. A host adds its own tools here. */
39
+ export function registerTurnEnding(tool) {
40
+ turnEnding.add(tool);
41
+ }
42
+ /** Whether `tool` ends its turn (registerTurnEnding). */
43
+ export const endsTurn = (tool) => turnEnding.has(tool);
44
+ /** The label of a call; `result` is given once the call has finished. Unknown tools get Grep's own fallback. */
45
+ export function labelOf(tool, args, result, extra) {
46
+ const own = extra && Object.hasOwn(extra, tool) ? extra[tool] : undefined;
47
+ return (own ?? labels.get(tool))?.(args, result) ?? mcpLabel(tool) ?? `Using tool: ${tool}`;
48
+ }
49
+ /** One line for several calls of one tool: `Read 4 pages: a.example, b.example, +2 more`. */
50
+ export function foldLabel(tool, calls, options = {}) {
51
+ const spec = folds.get(tool);
52
+ const head = spec ? spec.many(calls.length) : `Used ${tool} ${calls.length} times`;
53
+ // A file path is named as the host names it (`path`), as the call's own row is; the preview itself stays the call's.
54
+ const named = (input) => (input !== null && spec?.path && options.path ? options.path(input) : input);
55
+ const subjects = calls.flatMap((call) => spec?.subject?.(named(call.input), call.output) ?? []);
56
+ return subjects.length ? `${head}: ${list(subjects)}` : head;
57
+ }
58
+ /** The input worth showing: Grep's keys first, then the browser and file ones. */
59
+ export function inputPreview(args, max) {
60
+ for (const key of ["description", "command", "query", "file_path", "url", "path", "code"]) {
61
+ const value = str(args[key]);
62
+ if (value)
63
+ return cut(scrubUrls(value), max);
64
+ }
65
+ return null;
66
+ }
67
+ /** Files a finished call put in the workspace. */
68
+ export function savedPaths(tool, args, result) {
69
+ if (tool === "write" || tool === "edit") {
70
+ const file = str(args.path) ?? str(args.file_path);
71
+ return file ? [file] : [];
72
+ }
73
+ if (tool !== "browser_downloads")
74
+ return [];
75
+ const fetched = json(result.text)?.fetched;
76
+ return Array.isArray(fetched) ? fetched.flatMap((file) => str(obj(file)?.path) ?? []) : [];
77
+ }
78
+ /** Tools that use the browser session; the first of them opens one. */
79
+ export const BROWSER_OPENERS = new Set(["snapshot", "run", "screenshot", "browser_read", "browser_downloads"]);
80
+ /** Every tool of the browser (pi-browser's): the calls a browser charge with no call of its own may fold into. */
81
+ export const BROWSER_STEPS = new Set([...BROWSER_OPENERS, "browser_release", "browser_relaunch", "browser_upload", "browser_request_handoff"]);
82
+ const path = (args) => str(args.path) ?? str(args.file_path);
83
+ const GOTO = /page\.goto\(\s*["'`]([^"'`]+)/;
84
+ /** A call refused before it ran, in plain words: "Refused: " and the tool's name with what it would have acted on (the
85
+ * path it would have read or written, the command it would have run, the page it would have fetched), never a label's
86
+ * past tense ("Wrote deny.md"), which says it ran. Any tool: one with none of those reads as its name alone (an MCP
87
+ * server's tool as its server and name, "fake · send_message", as its label reads it). */
88
+ export function refusedLabel(tool, args) {
89
+ const command = str(args.command);
90
+ const subject = path(args) ?? (str(args.url) ? where(str(args.url)) : undefined) ?? (command ? `\`${cut(scrubUrls(firstLine(command)), 60)}\`` : undefined);
91
+ return `Refused: ${mcpLabel(tool) ?? tool}${subject ? ` ${subject}` : ""}`;
92
+ }
93
+ registerLabel("read", (a) => `Read ${path(a) ?? "a file"}`, { many: (n) => `Read ${n} files`, subject: (input) => input ?? undefined, path: true }, { name: "Read files" });
94
+ registerLabel("write", (a) => `Wrote ${path(a) ?? "a file"}`, { many: (n) => `Wrote ${n} files`, subject: (input) => input ?? undefined, path: true }, { name: "Write files" });
95
+ registerLabel("edit", (a) => `Edited ${path(a) ?? "a file"}`, { many: (n) => `Edited ${n} files`, subject: (input) => input ?? undefined, path: true }, { name: "Edit files" });
96
+ registerLabel("bash", (a) => `Ran \`${cut(scrubUrls(firstLine(str(a.command) ?? "")), 60)}\``, { many: (n) => `Ran ${n} commands` }, { name: "Run commands" });
97
+ /** A fetch that answered its page as a result with `ok: false`: refused (the public-host guard said no, `refused`) or
98
+ * failed (`error`, or a message). Undefined for a page it fetched. The page is the result's JSON, or its first line's
99
+ * when a line for the model follows it (serve's web_fetch, saying why a picked Parallel gave no page). */
100
+ const unfetched = (result) => {
101
+ const page = result && obj(json(result.text) ?? json(firstLine(result.text)));
102
+ if (page?.ok !== false)
103
+ return undefined;
104
+ const refused = str(page.refused);
105
+ return refused !== undefined ? { refused: true, detail: refused.replace(/^refused:\s*/, "") } : { refused: false, detail: str(page.error) ?? str(page.message) ?? "no detail" };
106
+ };
107
+ const fetchLabel = (a, result) => `${unfetched(result) ? "Tried to fetch" : "Fetched"} ${where(str(a.url) ?? "a page")}`;
108
+ const fetchFold = { many: (n) => `Fetched ${n} pages`, subject: (input) => (input ? where(input) : undefined) };
109
+ const fetchOutcome = (result) => {
110
+ const failure = unfetched(result);
111
+ return failure && { failed: true, text: `${failure.refused ? "refused" : "failed"}: ${failure.detail}` };
112
+ };
113
+ // web_fetch answers a page, `{ok, url, status, title, text, links, refused?, error?}`.
114
+ registerLabel("web_fetch", fetchLabel, fetchFold, { name: "Fetch web pages" });
115
+ registerOutcome("web_fetch", fetchOutcome);
116
+ registerLabel("web_search", (a) => {
117
+ const query = str(a.query);
118
+ return query ? `Searched the web for "${cut(scrubUrls(query), 60)}"` : "Searched the web";
119
+ }, { many: (n) => `Searched the web ${n} times`, subject: (input) => (input ? `"${cut(input, 40)}"` : undefined) }, { name: "Search the web" });
120
+ // web_search answers its results and a line asking for citations, or `{error}` when the search gave no answer: failed.
121
+ registerOutcome("web_search", (result) => {
122
+ const error = str(obj(json(result.text))?.error);
123
+ return error !== undefined ? { failed: true, text: `failed: ${error}` } : undefined;
124
+ });
125
+ registerLabel("browser_read", (_a, result) => {
126
+ const title = result && /^title: (.+)$/m.exec(result.text)?.[1];
127
+ return title ? `Read the page "${cut(scrubUrls(title), 60)}"` : "Read the page";
128
+ }, { many: (n) => `Read ${n} pages`, subject: (_input, output) => { const url = output && /^url: (\S+)/m.exec(output)?.[1]; return url ? where(url) : undefined; } }, { name: "Read the browser's page" });
129
+ registerLabel("snapshot", () => "Looked at the page structure", { many: (n) => `Looked at the page structure ${n} times` }, { name: "Look at the page structure" });
130
+ registerLabel("screenshot", () => "Took a screenshot", { many: (n) => `Took ${n} screenshots` }, { name: "Take screenshots" });
131
+ registerLabel("run", (a, result) => {
132
+ const goto = GOTO.exec(str(a.code) ?? "")?.[1];
133
+ if (goto)
134
+ return `Opened ${where(goto)}`;
135
+ const sent = obj(result?.details)?.sent;
136
+ const requests = Array.isArray(sent)
137
+ ? sent.flatMap((request) => { const r = obj(request); const [method, url] = [str(r?.method), str(r?.url)]; return method && url ? `${method} ${where(url)}` : []; })
138
+ : [];
139
+ return requests.length ? `Acted on the page (${requests.length} request${requests.length === 1 ? "" : "s"} sent: ${list(requests)})` : "Acted on the page";
140
+ }, { many: (n) => `Acted on the page ${n} times` }, { name: "Open or act on a page in the browser" });
141
+ registerLabel("browser_downloads", (_a, result) => {
142
+ const fetched = result && json(result.text)?.fetched;
143
+ const names = Array.isArray(fetched) ? fetched.flatMap((file) => str(obj(file)?.name) ?? []) : [];
144
+ return names.length === 1 ? `Downloaded ${names[0]}` : names.length ? `Downloaded ${names.length} files` : "Downloaded files";
145
+ }, { many: (n) => `Downloaded files ${n} times` }, { name: "Download files in the browser" });
146
+ registerLabel("browser_release", () => "Released the browser session", undefined, { name: "Release the browser session" });
147
+ registerLabel("browser_relaunch", () => "Started a fresh browser session", undefined, { name: "Start a fresh browser session" });
148
+ registerLabel("submit", () => "Submitted the answer", undefined, { name: "Submit the answer" });
149
+ registerLabel("codemode", () => "Ran a script", { many: (n) => `Ran ${n} scripts` }, { name: "Run scripts" });
150
+ registerLabel("request_sign_in", () => "Asked you to sign in", undefined, { name: "Ask you to sign in" });
@@ -0,0 +1,56 @@
1
+ import type { EntryLike } from "./timeline.js";
2
+ /** What fired a trigger: its definition's kind, never what its payload says. */
3
+ export declare const TRIGGER_SOURCES: readonly ["schedule", "webhook", "slack", "github"];
4
+ export type TriggerSource = (typeof TRIGGER_SOURCES)[number];
5
+ /** How a trigger's Timeline row names its source: "<label> <trigger>: <its first line>". */
6
+ export declare const TRIGGER_LABELS: Readonly<Record<TriggerSource, string>>;
7
+ /** Who wrote a user-role message that the person did not type. The model reads the message as it reads any; only its
8
+ * attribution differs, so the Timeline never shows it as "You".
9
+ * - `server`, for a reason. `approval_declined`: a person's message that declined a call waiting for approval, which the
10
+ * server's resume carries as the deny note; `said` is their words, whole, which the Timeline shows as theirs beside
11
+ * the server's row.
12
+ * - `trigger`: a trigger's firing (its first input, or its message), `trigger_id` the trigger's. `owner` is decided by
13
+ * the trigger's definition when it fires, never by its payload: true for a schedule (its owner wrote the words when
14
+ * they set it up), false for a webhook, Slack or GitHub firing, whose words come from outside. */
15
+ export type MessageOrigin = {
16
+ kind: "server";
17
+ reason: "cap_raised" | "approval";
18
+ } | {
19
+ kind: "server";
20
+ reason: "approval_declined";
21
+ said: string;
22
+ } | {
23
+ kind: "trigger";
24
+ trigger_id: string;
25
+ source: TriggerSource;
26
+ owner: boolean;
27
+ };
28
+ /** An entry kind that names the origin of the next user entry in its conversation whose text is exactly `text`: written
29
+ * just before the input it names (pi-durable writes a user entry with no data of its own), placed in the same queue.
30
+ * One with `withdrawn: true` takes back the last open marker of the same text and origin: its input was refused. */
31
+ export declare const MESSAGE_ORIGIN = "agentrun.message_origin";
32
+ /** `value` as an origin, or undefined when it is not one. */
33
+ export declare function originOf(value: unknown): MessageOrigin | undefined;
34
+ /** Whether `entry` is a user-role message the Timeline shows (a pi user entry, or a host's user entry). */
35
+ export declare const isUserEntry: (entry: EntryLike) => boolean;
36
+ /** Reads entries in order and says, for each user entry, its origin: its own `data.origin` (a host that writes the entry),
37
+ * else the first marker (MESSAGE_ORIGIN) still open in its conversation whose text is exactly the entry's. Each marker
38
+ * names one entry. Undefined for a person's own message. */
39
+ export declare function originMatcher(): (entry: EntryLike) => MessageOrigin | undefined;
40
+ /** Whether a Timeline row is a message its run took: a person's (`user_message`), the server's (`origin: "server"`), or a
41
+ * trigger's (`origin: "trigger"`); never the server's row beside the person's words (BESIDE_SUFFIX) or a note it told the
42
+ * model (NOTE_SUFFIX). A host that counts a run's messages (their arrival, where a stop stands) counts these, never the
43
+ * kind alone. */
44
+ export declare const isMessageRow: (row: {
45
+ id?: string;
46
+ kind: string;
47
+ origin?: string;
48
+ }) => boolean;
49
+ /** The id suffix of a server's row shown beside a person's message that its turn took (a declined approval's resume):
50
+ * the server's, as its origin says, and never a second message of that turn. */
51
+ export declare const BESIDE_SUFFIX = ":server";
52
+ /** The id suffix of the server's row for a note it told the run's model (the spend cap's wrap-up, CAP_WRAPUP): the
53
+ * server's, as its origin says, and never a message any turn took. */
54
+ export declare const NOTE_SUFFIX = ":note";
55
+ /** The user entries of `entries` that the server wrote, with their origin (originMatcher, read in order). */
56
+ export declare function messageOrigins(entries: readonly EntryLike[]): Map<EntryLike, MessageOrigin>;
@@ -0,0 +1,92 @@
1
+ import { obj, str } from "./util.js";
2
+ /** What fired a trigger: its definition's kind, never what its payload says. */
3
+ export const TRIGGER_SOURCES = ["schedule", "webhook", "slack", "github"];
4
+ /** How a trigger's Timeline row names its source: "<label> <trigger>: <its first line>". */
5
+ export const TRIGGER_LABELS = { schedule: "Schedule", webhook: "Webhook", slack: "Slack", github: "GitHub" };
6
+ const REASONS = new Set(["cap_raised", "approval"]);
7
+ const SOURCES = new Set(TRIGGER_SOURCES);
8
+ /** An entry kind that names the origin of the next user entry in its conversation whose text is exactly `text`: written
9
+ * just before the input it names (pi-durable writes a user entry with no data of its own), placed in the same queue.
10
+ * One with `withdrawn: true` takes back the last open marker of the same text and origin: its input was refused. */
11
+ export const MESSAGE_ORIGIN = "agentrun.message_origin";
12
+ /** `value` as an origin, or undefined when it is not one. */
13
+ export function originOf(value) {
14
+ const at = obj(value);
15
+ if (at?.kind === "trigger") {
16
+ const { trigger_id, source, owner } = at;
17
+ return typeof trigger_id === "string" && trigger_id !== "" && typeof source === "string" && SOURCES.has(source) && typeof owner === "boolean" ? { kind: "trigger", trigger_id, source: source, owner } : undefined;
18
+ }
19
+ if (!at || at.kind !== "server" || typeof at.reason !== "string")
20
+ return undefined;
21
+ if (at.reason === "approval_declined")
22
+ return typeof at.said === "string" && at.said.trim() ? { kind: "server", reason: "approval_declined", said: at.said } : undefined;
23
+ return REASONS.has(at.reason) ? { kind: "server", reason: at.reason } : undefined;
24
+ }
25
+ const textOf = (message) => {
26
+ const content = message?.content;
27
+ const blocks = Array.isArray(content) ? content.map((block) => obj(block)).filter((block) => block !== undefined) : typeof content === "string" ? [{ type: "text", text: content }] : [];
28
+ return blocks.filter((block) => block.type === "text").map((block) => str(block.text) ?? "").join("\n").trim();
29
+ };
30
+ /** Whether `entry` is a user-role message the Timeline shows (a pi user entry, or a host's user entry). */
31
+ export const isUserEntry = (entry) => obj(entry.model?.[0])?.role === "user" && (entry.kind === "pi.user" || !entry.kind.startsWith("pi."));
32
+ /** Reads entries in order and says, for each user entry, its origin: its own `data.origin` (a host that writes the entry),
33
+ * else the first marker (MESSAGE_ORIGIN) still open in its conversation whose text is exactly the entry's. Each marker
34
+ * names one entry. Undefined for a person's own message. */
35
+ export function originMatcher() {
36
+ const open = new Map();
37
+ return (entry) => {
38
+ const conv = entry.conversationId ?? 0;
39
+ if (entry.kind === MESSAGE_ORIGIN) {
40
+ const data = obj(entry.data);
41
+ const origin = originOf(data?.origin);
42
+ const text = str(data?.text);
43
+ if (!origin || text === undefined)
44
+ return undefined;
45
+ const markers = open.get(conv) ?? [];
46
+ if (data?.withdrawn === true) {
47
+ const at = markers.findLastIndex((marker) => marker.text === text.trim() && JSON.stringify(marker.origin) === JSON.stringify(origin));
48
+ if (at >= 0)
49
+ markers.splice(at, 1);
50
+ }
51
+ else
52
+ open.set(conv, [...markers, { text: text.trim(), origin }]);
53
+ return undefined;
54
+ }
55
+ if (!isUserEntry(entry))
56
+ return undefined;
57
+ const own = originOf(obj(entry.data)?.origin);
58
+ if (own)
59
+ return own;
60
+ const markers = open.get(conv);
61
+ if (!markers?.length)
62
+ return undefined;
63
+ const text = textOf(obj(entry.model?.[0]));
64
+ const at = markers.findIndex((marker) => marker.text === text);
65
+ if (at < 0)
66
+ return undefined;
67
+ const [{ origin }] = markers.splice(at, 1);
68
+ return origin;
69
+ };
70
+ }
71
+ /** Whether a Timeline row is a message its run took: a person's (`user_message`), the server's (`origin: "server"`), or a
72
+ * trigger's (`origin: "trigger"`); never the server's row beside the person's words (BESIDE_SUFFIX) or a note it told the
73
+ * model (NOTE_SUFFIX). A host that counts a run's messages (their arrival, where a stop stands) counts these, never the
74
+ * kind alone. */
75
+ export const isMessageRow = (row) => row.kind === "user_message" || ((row.origin === "server" || row.origin === "trigger") && !row.id?.endsWith(BESIDE_SUFFIX) && !row.id?.endsWith(NOTE_SUFFIX));
76
+ /** The id suffix of a server's row shown beside a person's message that its turn took (a declined approval's resume):
77
+ * the server's, as its origin says, and never a second message of that turn. */
78
+ export const BESIDE_SUFFIX = ":server";
79
+ /** The id suffix of the server's row for a note it told the run's model (the spend cap's wrap-up, CAP_WRAPUP): the
80
+ * server's, as its origin says, and never a message any turn took. */
81
+ export const NOTE_SUFFIX = ":note";
82
+ /** The user entries of `entries` that the server wrote, with their origin (originMatcher, read in order). */
83
+ export function messageOrigins(entries) {
84
+ const match = originMatcher();
85
+ const found = new Map();
86
+ for (const entry of entries) {
87
+ const origin = match(entry);
88
+ if (origin)
89
+ found.set(entry, origin);
90
+ }
91
+ return found;
92
+ }
@@ -0,0 +1,11 @@
1
+ import { type Group } from "./group.js";
2
+ import type { TimelineEvent } from "./timeline.js";
3
+ /** How the text names a file path a call gave: the host's own name for it (`TimelineOptions.path`). */
4
+ type PathName = {
5
+ path?: (path: string) => string;
6
+ };
7
+ /** Plain text, one line per row or group: `HH:MM:SS text`. `fold: false` shows every call on its own line. */
8
+ export declare function renderText(input: readonly (TimelineEvent | Group)[], options?: {
9
+ fold?: boolean;
10
+ } & PathName): string;
11
+ export {};
@@ -0,0 +1,62 @@
1
+ import { foldCalls, groupTimeline } from "./group.js";
2
+ import { foldLabel } from "./labels.js";
3
+ const clock = (row) => row.timestamp.slice(11, 19);
4
+ const statusOf = (call) => !call.result ? "running" : call.result.tool_status === "success" ? "ok" : call.result.tool_result_size_bytes === null ? "interrupted" : "failed";
5
+ function rowText(row) {
6
+ const summary = row.summary ?? row.kind;
7
+ return row.kind === "text_block" ? `Agent: ${summary}` : row.kind === "final_answer" ? `Answer: ${summary}` : summary;
8
+ }
9
+ function foldEntry(fold, options) {
10
+ const [only] = fold.calls;
11
+ if (fold.calls.length === 1 && only)
12
+ return { text: only.use.summary ?? fold.tool, status: statusOf(only), reasons: statusOf(only) === "failed" ? [only] : [] };
13
+ const counts = new Map();
14
+ for (const call of fold.calls)
15
+ counts.set(statusOf(call), (counts.get(statusOf(call)) ?? 0) + 1);
16
+ const status = [...counts].map(([name, count]) => `${count} ${name}`).join(", ");
17
+ const text = foldLabel(fold.tool, fold.calls.map((call) => ({ input: call.use.tool_input_preview, output: call.result?.tool_result_preview ?? null })), options);
18
+ return { text, status, reasons: fold.calls.filter((call) => statusOf(call) === "failed") };
19
+ }
20
+ /** What the calls' rows say their browser charges came to (TimelineEvent.usage on a call's row): " · $0.0018", or
21
+ * " · cost unknown" when one is; "" when none carries one. */
22
+ function chargeOf(calls) {
23
+ const usages = calls.flatMap((call) => (call.use.kind === "tool_use" && call.use.usage ? [call.use.usage] : []));
24
+ if (!usages.length)
25
+ return "";
26
+ if (usages.some((usage) => usage.usd === null))
27
+ return " · cost unknown";
28
+ const usd = usages.reduce((sum, usage) => sum + (usage.usd ?? 0), 0);
29
+ return ` · ${usd === 0 ? "$0" : `$${usd.toFixed(4)}`}`;
30
+ }
31
+ function linesOf(groups, depth, fold, options = {}) {
32
+ const lines = [];
33
+ for (const group of groups) {
34
+ if (group.type === "row") {
35
+ lines.push({ at: clock(group.row), depth, text: rowText(group.row) });
36
+ continue;
37
+ }
38
+ const folds = fold ? foldCalls(group.calls) : group.calls.map((call) => ({ tool: call.use.tool_name ?? "", calls: [call] }));
39
+ const at = clock(group.calls[0].use);
40
+ const nested = folds.length > 1;
41
+ if (nested)
42
+ lines.push({ at, depth, text: `Ran ${group.calls.length} tools` });
43
+ for (const entry of folds) {
44
+ const { text, status, reasons } = foldEntry(entry, options);
45
+ const inner = nested ? depth + 1 : depth;
46
+ lines.push({ at: nested ? undefined : at, depth: inner, text: `${(text + chargeOf(entry.calls)).padEnd(58)} ${status}` });
47
+ for (const call of reasons)
48
+ lines.push({ depth: inner + 1, text: call.result?.summary ?? statusOf(call) });
49
+ for (const call of entry.calls)
50
+ lines.push(...linesOf(call.inner, inner + 1, fold, options));
51
+ }
52
+ }
53
+ return lines;
54
+ }
55
+ const isRows = (input) => input.every((item) => "kind" in item);
56
+ /** Plain text, one line per row or group: `HH:MM:SS text`. `fold: false` shows every call on its own line. */
57
+ export function renderText(input, options = {}) {
58
+ const groups = isRows(input) ? groupTimeline(input) : input;
59
+ return linesOf(groups, 0, options.fold !== false, options)
60
+ .map((line) => `${(line.at ?? "").padEnd(8)} ${" ".repeat(line.depth)}${line.text}`.trimEnd())
61
+ .join("\n");
62
+ }