@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34

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 (444) hide show
  1. package/CHANGELOG.md +270 -0
  2. package/README.md +343 -246
  3. package/dist/adapters.d.ts +0 -7
  4. package/dist/adapters.js +11 -22
  5. package/dist/agent-rows.d.ts +98 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +60 -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 +14 -0
  14. package/dist/api-only.js +33 -0
  15. package/dist/archil-routes.d.ts +1 -1
  16. package/dist/bash-read-only.d.ts +22 -0
  17. package/dist/bash-read-only.js +701 -0
  18. package/dist/box-egress-vm.d.ts +0 -8
  19. package/dist/box-egress-vm.js +0 -10
  20. package/dist/box-egress.d.ts +0 -4
  21. package/dist/box-egress.js +1 -16
  22. package/dist/box-paths.d.ts +25 -2
  23. package/dist/box-paths.js +79 -11
  24. package/dist/box-relay.d.ts +0 -11
  25. package/dist/box-relay.js +0 -20
  26. package/dist/box-settings.d.ts +26 -0
  27. package/dist/box-settings.js +63 -0
  28. package/dist/boxes.d.ts +21 -1
  29. package/dist/boxes.js +27 -20
  30. package/dist/browser-commands.d.ts +5 -2
  31. package/dist/browser-commands.js +4 -4
  32. package/dist/browser-computer.d.ts +5 -0
  33. package/dist/browser-computer.js +21 -0
  34. package/dist/browser-cost.d.ts +9 -6
  35. package/dist/browser-cost.js +94 -51
  36. package/dist/browser-live.d.ts +7 -20
  37. package/dist/browser-live.js +15 -93
  38. package/dist/browser-person.d.ts +18 -53
  39. package/dist/browser-person.js +94 -279
  40. package/dist/budget.d.ts +0 -4
  41. package/dist/budget.js +0 -7
  42. package/dist/cap.d.ts +8 -12
  43. package/dist/cap.js +12 -27
  44. package/dist/cli.js +61 -20
  45. package/dist/closed-pipes.d.ts +2 -0
  46. package/dist/closed-pipes.js +13 -0
  47. package/dist/computer-commands.d.ts +2 -0
  48. package/dist/computer-commands.js +2 -0
  49. package/dist/computer-keys.js +5 -2
  50. package/dist/computer-setting.d.ts +20 -4
  51. package/dist/computer-setting.js +25 -5
  52. package/dist/computers.d.ts +31 -3
  53. package/dist/computers.js +70 -11
  54. package/dist/confine.d.ts +120 -0
  55. package/dist/confine.js +436 -0
  56. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  57. package/dist/console/assets/index-opTN5Naq.css +1 -0
  58. package/dist/console/index.html +2 -2
  59. package/dist/daytona-api.d.ts +0 -11
  60. package/dist/daytona-api.js +1 -82
  61. package/dist/decision-rows.d.ts +1 -1
  62. package/dist/decision-rows.js +1 -1
  63. package/dist/docker-daemon.d.ts +31 -0
  64. package/dist/docker-daemon.js +56 -0
  65. package/dist/docker-host-addresses.d.ts +37 -0
  66. package/dist/docker-host-addresses.js +110 -0
  67. package/dist/effort-guidance.js +4 -3
  68. package/dist/environment.d.ts +0 -3
  69. package/dist/environment.js +3 -5
  70. package/dist/errors.d.ts +0 -2
  71. package/dist/errors.js +6 -9
  72. package/dist/filed-answer.d.ts +32 -0
  73. package/dist/filed-answer.js +160 -0
  74. package/dist/files.d.ts +1 -11
  75. package/dist/files.js +2 -21
  76. package/dist/github-connection.d.ts +2 -2
  77. package/dist/github-connection.js +1 -1
  78. package/dist/graph-view.d.ts +3 -5
  79. package/dist/graph-view.js +4 -14
  80. package/dist/handed-values.d.ts +9 -0
  81. package/dist/handed-values.js +26 -0
  82. package/dist/harness-install.d.ts +22 -5
  83. package/dist/harness-install.js +98 -20
  84. package/dist/harness-opencode/adapter.d.ts +7 -0
  85. package/dist/harness-opencode/adapter.js +23 -6
  86. package/dist/harness-opencode/index.d.ts +1 -1
  87. package/dist/harness-opencode/index.js +1 -1
  88. package/dist/harness-opencode/verify.d.ts +17 -0
  89. package/dist/harness-opencode/verify.js +30 -10
  90. package/dist/harness-table.js +6 -1
  91. package/dist/harness.d.ts +4 -3
  92. package/dist/harness.js +16 -1
  93. package/dist/heard.js +1 -1
  94. package/dist/held-fd.d.ts +5 -0
  95. package/dist/held-fd.js +14 -0
  96. package/dist/host-calls.d.ts +20 -0
  97. package/dist/host-calls.js +12 -0
  98. package/dist/host-tools.d.ts +4 -21
  99. package/dist/host-tools.js +4 -61
  100. package/dist/host.d.ts +2 -4
  101. package/dist/host.js +2 -7
  102. package/dist/import-summary.d.ts +1 -5
  103. package/dist/import-summary.js +0 -21
  104. package/dist/import.d.ts +6 -6
  105. package/dist/import.js +62 -24
  106. package/dist/key-refusal.d.ts +5 -1
  107. package/dist/key-refusal.js +19 -4
  108. package/dist/learn/check.d.ts +6 -2
  109. package/dist/learn/check.js +83 -29
  110. package/dist/learn/folder.d.ts +5 -1
  111. package/dist/learn/folder.js +10 -3
  112. package/dist/learn/grade.d.ts +14 -0
  113. package/dist/learn/grade.js +68 -12
  114. package/dist/learn/index.d.ts +4 -4
  115. package/dist/learn/index.js +4 -4
  116. package/dist/learn/reflect.d.ts +31 -2
  117. package/dist/learn/reflect.js +79 -4
  118. package/dist/learn/relevance.d.ts +24 -0
  119. package/dist/learn/relevance.js +91 -0
  120. package/dist/learn/secrets.d.ts +8 -1
  121. package/dist/learn/secrets.js +95 -15
  122. package/dist/learn/skills.d.ts +112 -14
  123. package/dist/learn/skills.js +556 -52
  124. package/dist/learned-workflow.d.ts +37 -5
  125. package/dist/learned-workflow.js +106 -12
  126. package/dist/learning-routes.d.ts +16 -49
  127. package/dist/learning-routes.js +46 -36
  128. package/dist/learning-run.d.ts +6 -250
  129. package/dist/learning-run.js +11 -665
  130. package/dist/learning-words.d.ts +12 -5
  131. package/dist/learning-words.js +18 -9
  132. package/dist/learning.d.ts +93 -77
  133. package/dist/learning.js +176 -304
  134. package/dist/live/stream.js +1 -1
  135. package/dist/live/translate.js +13 -3
  136. package/dist/local-models.d.ts +11 -5
  137. package/dist/local-models.js +13 -8
  138. package/dist/mcp-gateway.d.ts +11 -52
  139. package/dist/mcp-gateway.js +44 -148
  140. package/dist/mcp-oauth.d.ts +10 -14
  141. package/dist/mcp-oauth.js +14 -32
  142. package/dist/mcp-probe.d.ts +0 -7
  143. package/dist/mcp-probe.js +4 -10
  144. package/dist/mcp-servers-store.d.ts +6 -6
  145. package/dist/mcp-servers-store.js +13 -15
  146. package/dist/mcp-store.js +3 -4
  147. package/dist/mcp.js +4 -3
  148. package/dist/model.d.ts +6 -7
  149. package/dist/model.js +43 -27
  150. package/dist/monid.d.ts +0 -2
  151. package/dist/monid.js +3 -6
  152. package/dist/openapi.d.ts +8 -1
  153. package/dist/openapi.js +124 -50
  154. package/dist/page.d.ts +1 -3
  155. package/dist/page.js +9 -19
  156. package/dist/paid-calls.d.ts +21 -27
  157. package/dist/paid-calls.js +28 -62
  158. package/dist/pause.d.ts +0 -2
  159. package/dist/pause.js +1 -8
  160. package/dist/place.d.ts +0 -5
  161. package/dist/place.js +0 -10
  162. package/dist/print.d.ts +2 -1
  163. package/dist/print.js +4 -2
  164. package/dist/propose.js +83 -39
  165. package/dist/push-handler.d.ts +1 -1
  166. package/dist/reflect-range.d.ts +25 -0
  167. package/dist/reflect-range.js +30 -0
  168. package/dist/refusal-words.d.ts +5 -1
  169. package/dist/refusal-words.js +5 -1
  170. package/dist/rows.d.ts +1 -1
  171. package/dist/run-cut.d.ts +0 -6
  172. package/dist/run-cut.js +0 -6
  173. package/dist/run-db.d.ts +2 -13
  174. package/dist/run-db.js +2 -41
  175. package/dist/run-launch.d.ts +19 -2
  176. package/dist/run-launch.js +13 -5
  177. package/dist/run-learning-served.d.ts +46 -2
  178. package/dist/run-learning-served.js +26 -7
  179. package/dist/run-reads-over-store.d.ts +1 -1
  180. package/dist/run-reads-over-store.js +15 -6
  181. package/dist/run-secrets.d.ts +33 -0
  182. package/dist/run-secrets.js +53 -0
  183. package/dist/run-timeline-served.d.ts +5 -1
  184. package/dist/run-timeline-served.js +19 -5
  185. package/dist/run-view.d.ts +12 -17
  186. package/dist/run-view.js +29 -28
  187. package/dist/runnable.d.ts +18 -10
  188. package/dist/runnable.js +21 -10
  189. package/dist/runner/adapter-loop.d.ts +14 -3
  190. package/dist/runner/adapter-loop.js +464 -62
  191. package/dist/runner/adapter-run-spec.d.ts +29 -8
  192. package/dist/runner/adapter-run-spec.js +96 -37
  193. package/dist/runner/adapters/index.js +11 -1
  194. package/dist/runner/adapters/pi.d.ts +15 -1
  195. package/dist/runner/adapters/pi.js +19 -5
  196. package/dist/runner/beside.d.ts +30 -3
  197. package/dist/runner/beside.js +54 -12
  198. package/dist/runner/claim-secrets.d.ts +10 -1
  199. package/dist/runner/claim-secrets.js +49 -15
  200. package/dist/runner/cli-run-spec.d.ts +2 -0
  201. package/dist/runner/cli-run-spec.js +60 -17
  202. package/dist/runner/commands.js +1 -1
  203. package/dist/runner/computer-journal.d.ts +15 -2
  204. package/dist/runner/computer-journal.js +41 -5
  205. package/dist/runner/conformance/harness.js +118 -8
  206. package/dist/runner/conformance/subject.d.ts +4 -1
  207. package/dist/runner/dispatch.d.ts +8 -1
  208. package/dist/runner/dispatch.js +81 -7
  209. package/dist/runner/end-of-run.d.ts +8 -2
  210. package/dist/runner/end-of-run.js +10 -4
  211. package/dist/runner/github-app.js +1 -1
  212. package/dist/runner/harness-loops.d.ts +9 -1
  213. package/dist/runner/harness-loops.js +15 -2
  214. package/dist/runner/journal-kinds.d.ts +30 -6
  215. package/dist/runner/journal-kinds.js +20 -5
  216. package/dist/runner/journal-reader.d.ts +1 -1
  217. package/dist/runner/journal-reader.js +2 -2
  218. package/dist/runner/learning-ask.d.ts +4 -0
  219. package/dist/runner/learning-ask.js +15 -1
  220. package/dist/runner/learning-end.d.ts +18 -3
  221. package/dist/runner/learning-end.js +113 -11
  222. package/dist/runner/learning-loop.d.ts +5 -0
  223. package/dist/runner/learning-loop.js +26 -6
  224. package/dist/runner/live-ticker.d.ts +1 -1
  225. package/dist/runner/live-ticker.js +28 -4
  226. package/dist/runner/loop-contract.d.ts +3 -2
  227. package/dist/runner/main.d.ts +64 -10
  228. package/dist/runner/main.js +165 -27
  229. package/dist/runner/mcp-claim.d.ts +1 -1
  230. package/dist/runner/mcp-claim.js +2 -3
  231. package/dist/runner/mcp-run.d.ts +2 -0
  232. package/dist/runner/mcp-run.js +15 -5
  233. package/dist/runner/memory-claim.d.ts +9 -0
  234. package/dist/runner/memory-claim.js +25 -0
  235. package/dist/runner/metrics.d.ts +33 -1
  236. package/dist/runner/metrics.js +85 -1
  237. package/dist/runner/model-route.d.ts +13 -0
  238. package/dist/runner/model-route.js +154 -11
  239. package/dist/runner/redact.d.ts +8 -2
  240. package/dist/runner/redact.js +11 -2
  241. package/dist/runner/reflect-hook.d.ts +12 -1
  242. package/dist/runner/reflect-hook.js +33 -3
  243. package/dist/runner/runner.d.ts +20 -0
  244. package/dist/runner/runner.js +56 -10
  245. package/dist/runner/store-port.d.ts +1 -1
  246. package/dist/runner/store-secrets.d.ts +3 -3
  247. package/dist/runner/store-secrets.js +8 -12
  248. package/dist/runner/text-tools.d.ts +44 -0
  249. package/dist/runner/text-tools.js +237 -0
  250. package/dist/runner/workflow-loop.d.ts +6 -0
  251. package/dist/runner/workflow-loop.js +6 -4
  252. package/dist/runner/workflow-spec.d.ts +18 -0
  253. package/dist/runner/workflow-spec.js +68 -26
  254. package/dist/runs-over-store.d.ts +8 -3
  255. package/dist/runs-over-store.js +76 -19
  256. package/dist/seal-key.d.ts +54 -15
  257. package/dist/seal-key.js +232 -82
  258. package/dist/sealed-settings-store.d.ts +19 -4
  259. package/dist/sealed-settings-store.js +9 -9
  260. package/dist/sealing.d.ts +4 -0
  261. package/dist/sealing.js +20 -0
  262. package/dist/secret-cut.d.ts +1 -1
  263. package/dist/secret-cut.js +1 -1
  264. package/dist/secret-name.d.ts +9 -0
  265. package/dist/secret-name.js +15 -0
  266. package/dist/secret-writes.d.ts +0 -1
  267. package/dist/secret-writes.js +0 -1
  268. package/dist/secrets.d.ts +2 -10
  269. package/dist/secrets.js +21 -17
  270. package/dist/server-fs.d.ts +4 -0
  271. package/dist/server-fs.js +8 -2
  272. package/dist/server-lock.d.ts +0 -24
  273. package/dist/server-lock.js +1 -80
  274. package/dist/server-secrets-store.d.ts +4 -4
  275. package/dist/server-secrets-store.js +10 -32
  276. package/dist/server-secrets.d.ts +4 -9
  277. package/dist/server-secrets.js +12 -33
  278. package/dist/server.d.ts +26 -44
  279. package/dist/server.js +229 -142
  280. package/dist/sign-ins-store.d.ts +34 -36
  281. package/dist/sign-ins-store.js +27 -38
  282. package/dist/sign-ins.d.ts +2 -119
  283. package/dist/sign-ins.js +5 -311
  284. package/dist/standard-webhooks.d.ts +1 -1
  285. package/dist/standard-webhooks.js +1 -1
  286. package/dist/stats.d.ts +3 -2
  287. package/dist/stats.js +1 -1
  288. package/dist/store/agent-body.d.ts +8 -2
  289. package/dist/store/agent-body.js +16 -4
  290. package/dist/store/index.d.ts +3 -3
  291. package/dist/store/index.js +3 -3
  292. package/dist/store/open.d.ts +18 -5
  293. package/dist/store/open.js +23 -3
  294. package/dist/store/postgres/connection.d.ts +18 -2
  295. package/dist/store/postgres/connection.js +156 -32
  296. package/dist/store/postgres/migrate.d.ts +4 -0
  297. package/dist/store/postgres/migrate.js +27 -3
  298. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  299. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  300. package/dist/store/postgres/store.d.ts +9 -2
  301. package/dist/store/postgres/store.js +9 -0
  302. package/dist/store/schema.js +1 -1
  303. package/dist/store/seal.js +2 -2
  304. package/dist/store/sqlite/connection.js +49 -5
  305. package/dist/store/sqlite/run-patch.d.ts +3 -0
  306. package/dist/store/sqlite/run-patch.js +3 -0
  307. package/dist/store/sqlite/store.js +64 -20
  308. package/dist/store/store.d.ts +38 -6
  309. package/dist/store/store.js +12 -2
  310. package/dist/store-reads/cap.d.ts +1 -1
  311. package/dist/store-reads/cap.js +22 -4
  312. package/dist/store-reads/journal.d.ts +25 -6
  313. package/dist/store-reads/journal.js +173 -21
  314. package/dist/store-reads/learning.d.ts +26 -8
  315. package/dist/store-reads/learning.js +12 -4
  316. package/dist/store-reads/workflow.d.ts +1 -1
  317. package/dist/store-reads/workflow.js +1 -1
  318. package/dist/store-view.d.ts +5 -1
  319. package/dist/store-view.js +91 -23
  320. package/dist/template-eval.d.ts +60 -4
  321. package/dist/template-eval.js +120 -54
  322. package/dist/templates.d.ts +24 -10
  323. package/dist/templates.js +69 -38
  324. package/dist/timeline/group.d.ts +33 -0
  325. package/dist/timeline/group.js +77 -0
  326. package/dist/timeline/index.d.ts +7 -0
  327. package/dist/timeline/index.js +7 -0
  328. package/dist/timeline/labels.d.ts +79 -0
  329. package/dist/timeline/labels.js +150 -0
  330. package/dist/timeline/origin.d.ts +56 -0
  331. package/dist/timeline/origin.js +92 -0
  332. package/dist/timeline/render-text.d.ts +11 -0
  333. package/dist/timeline/render-text.js +62 -0
  334. package/dist/timeline/timeline.d.ts +274 -0
  335. package/dist/timeline/timeline.js +1308 -0
  336. package/dist/timeline/util.d.ts +17 -0
  337. package/dist/timeline/util.js +49 -0
  338. package/dist/tool-gate.d.ts +41 -216
  339. package/dist/tool-gate.js +79 -540
  340. package/dist/tool-keys-store.d.ts +11 -12
  341. package/dist/tool-keys-store.js +24 -31
  342. package/dist/tool-keys.d.ts +9 -104
  343. package/dist/tool-keys.js +15 -271
  344. package/dist/tool-plane.d.ts +14 -42
  345. package/dist/tool-plane.js +23 -81
  346. package/dist/tool-settings-store.d.ts +1 -2
  347. package/dist/tool-settings-store.js +5 -8
  348. package/dist/tools.d.ts +31 -19
  349. package/dist/tools.js +101 -108
  350. package/dist/trigger-adapter.d.ts +2 -2
  351. package/dist/trigger-schedule.js +2 -1
  352. package/dist/trigger-secrets-shown.js +5 -1
  353. package/dist/trigger-targets.d.ts +13 -1
  354. package/dist/trigger-targets.js +31 -1
  355. package/dist/triggers.d.ts +2 -2
  356. package/dist/triggers.js +3 -3
  357. package/dist/turn-end.d.ts +1 -1
  358. package/dist/turn-end.js +1 -1
  359. package/dist/turns.d.ts +0 -6
  360. package/dist/turns.js +0 -19
  361. package/dist/uploads.js +1 -1
  362. package/dist/usage.d.ts +0 -2
  363. package/dist/usage.js +0 -2
  364. package/dist/validate.d.ts +2 -0
  365. package/dist/validate.js +23 -14
  366. package/dist/webhooks.d.ts +102 -76
  367. package/dist/webhooks.js +266 -233
  368. package/dist/workflow-run.d.ts +114 -0
  369. package/dist/workflow-run.js +144 -0
  370. package/dist/workspace/beneath.d.ts +19 -0
  371. package/dist/workspace/beneath.js +106 -0
  372. package/dist/workspace/computer-deps.d.ts +52 -5
  373. package/dist/workspace/computer-deps.js +154 -19
  374. package/dist/workspace/computer-for-claim.d.ts +19 -14
  375. package/dist/workspace/computer-for-claim.js +77 -16
  376. package/dist/workspace/computer-hold.d.ts +6 -1
  377. package/dist/workspace/computer-hold.js +6 -1
  378. package/dist/workspace/computer-janitor.d.ts +47 -0
  379. package/dist/workspace/computer-janitor.js +182 -0
  380. package/dist/workspace/computer-providers.d.ts +6 -2
  381. package/dist/workspace/computer-providers.js +1 -1
  382. package/dist/workspace/grep-worker.d.ts +5 -0
  383. package/dist/workspace/grep-worker.js +9 -6
  384. package/dist/workspace/index.d.ts +4 -3
  385. package/dist/workspace/index.js +4 -4
  386. package/dist/workspace/local.d.ts +11 -2
  387. package/dist/workspace/local.js +161 -43
  388. package/dist/workspace/resolve-computer.d.ts +50 -10
  389. package/dist/workspace/resolve-computer.js +46 -11
  390. package/dist/workspace/run-tools.d.ts +13 -31
  391. package/dist/workspace/run-tools.js +10 -27
  392. package/dist/workspace-paths.d.ts +0 -17
  393. package/dist/workspace-paths.js +1 -41
  394. package/dist/workspace.d.ts +0 -17
  395. package/dist/workspace.js +3 -99
  396. package/launcher/agentrun-serve +6 -33
  397. package/package.json +14 -14
  398. package/templates/README.md +9 -3
  399. package/templates/inbound-lead/agent.md +1 -1
  400. package/templates/kyb/agent.md +1 -1
  401. package/templates/market-monitor/agent.md +2 -2
  402. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  403. package/dist/app.d.ts +0 -5
  404. package/dist/app.js +0 -514
  405. package/dist/bound-files.d.ts +0 -4
  406. package/dist/bound-files.js +0 -164
  407. package/dist/bounds.d.ts +0 -26
  408. package/dist/bounds.js +0 -137
  409. package/dist/coding-tools.d.ts +0 -47
  410. package/dist/coding-tools.js +0 -189
  411. package/dist/computer-adb.d.ts +0 -12
  412. package/dist/computer-adb.js +0 -14
  413. package/dist/console/assets/index-35-7aeIZ.js +0 -519
  414. package/dist/console/assets/index-Cejbov-Y.css +0 -1
  415. package/dist/content-filter.d.ts +0 -7
  416. package/dist/content-filter.js +0 -23
  417. package/dist/disk.d.ts +0 -33
  418. package/dist/disk.js +0 -85
  419. package/dist/door-line.d.ts +0 -23
  420. package/dist/door-line.js +0 -83
  421. package/dist/grade.d.ts +0 -63
  422. package/dist/grade.js +0 -150
  423. package/dist/harness-app.d.ts +0 -69
  424. package/dist/harness-app.js +0 -1162
  425. package/dist/mcp-servers.d.ts +0 -269
  426. package/dist/mcp-servers.js +0 -456
  427. package/dist/packs.d.ts +0 -71
  428. package/dist/packs.js +0 -180
  429. package/dist/request-start.d.ts +0 -27
  430. package/dist/request-start.js +0 -381
  431. package/dist/run-box.d.ts +0 -205
  432. package/dist/run-box.js +0 -661
  433. package/dist/run-holder.d.ts +0 -52
  434. package/dist/run-holder.js +0 -139
  435. package/dist/runs.d.ts +0 -1200
  436. package/dist/runs.js +0 -4103
  437. package/dist/sealed-settings.d.ts +0 -60
  438. package/dist/sealed-settings.js +0 -178
  439. package/dist/served-only.d.ts +0 -5
  440. package/dist/served-only.js +0 -12
  441. package/dist/sessions.d.ts +0 -6
  442. package/dist/sessions.js +0 -109
  443. package/dist/workspace/computer-serves.d.ts +0 -12
  444. package/dist/workspace/computer-serves.js +0 -15
package/dist/templates.js CHANGED
@@ -11,10 +11,11 @@ import { parseDocument } from "yaml";
11
11
  import { invalid } from "./errors.js";
12
12
  import { HARNESSES } from "./harness.js";
13
13
  import { TOOL_KEY_ROWS } from "./key-words.js";
14
- import { MCP_SERVER_NAME } from "./mcp-servers.js";
14
+ import { MCP_SERVER_NAME } from "./mcp-probe.js";
15
15
  import { chooseModel, harnessRuns, hostModel, MODEL_KEYS, THINKING_LEVELS } from "./model.js";
16
16
  import { mcpToolName } from "./tool-gate.js";
17
- import { AGENT_LAYER_PINS, pinIssues, sortedPin } from "./tool-plane.js";
17
+ import { pinIssues, sortedPin } from "./tool-plane.js";
18
+ import { BASH_POLICIES } from "./bash-read-only.js";
18
19
  import { BOUND_TOOLS } from "./tools.js";
19
20
  import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
20
21
  import { triggerBodyIssues } from "./triggers.js";
@@ -25,8 +26,11 @@ export const MANIFEST = "agent.md";
25
26
  /** A package's model tier, mapped to the server's own (model.ts Tier: AGENT_MODEL_FAST, AGENT_MODEL, AGENT_MODEL_STRONG). */
26
27
  export const MODEL_TIERS = { fast: "fast", balanced: "default", strong: "strong" };
27
28
  export const PARAMETER_TYPES = ["string", "number", "integer", "boolean"];
29
+ /** What a string parameter's value is, for a form to ask for it as such: a schedule's cron line, or an IANA time zone
30
+ * (market-monitor's schedule). A form shows a schedule picker and a time-zone choice; the value is the same text. */
31
+ export const PARAMETER_FORMATS = ["cron", "timezone"];
28
32
  export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "schema"];
29
- const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "harness", "model", "effort", "tools", "mcp", "computer", "parameters", "secrets", "budget", "learning", "approvals", "triggers", "output", "checks"];
33
+ const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "harness", "model", "effort", "tools", "mcp", "tool_policy", "computer", "parameters", "secrets", "budget", "learning", "approvals", "triggers", "output", "checks"];
30
34
  const NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
31
35
  const PARAMETER = /^[a-z][a-z0-9_]{0,63}$/;
32
36
  /** The keys a package may need: those Settings saves (a tool's or a model provider's), each one a run is handed. */
@@ -37,6 +41,9 @@ const MCP_TOOL = /^[A-Za-z0-9_.-]{1,128}$/;
37
41
  export const MAX_FILE_BYTES = 256 << 10;
38
42
  export const MAX_PACKAGE_BYTES = 1 << 20;
39
43
  export const MAX_PACKAGE_FILES = 256;
44
+ /** A file of a package's evals/ (a case's fake MCP server fixture, say), which no agent is given: its own bound, apart
45
+ * from the agent's files' limits above. The answer's schema is given to the agent, so under evals/ too it keeps those. */
46
+ export const MAX_EVAL_FILE_BYTES = 32 << 20;
40
47
  /** A parameter's sample, of its type, for the check that compiles a package before any apply. */
41
48
  const SAMPLES = { string: "x", number: 1, integer: 1, boolean: true };
42
49
  /** An agent id in the shape an apply gives a trigger's target, for that check. */
@@ -208,12 +215,19 @@ export function readPackage(dir) {
208
215
  bad(`${entry.name}/`, "a package's folders are skills/, rules/ and evals/");
209
216
  }
210
217
  // Bounded before anything is read: a file, the files together, and how many there are.
211
- const all = files("");
218
+ // The agent's files' bytes (evals/ is the package's own test data, never part of an agent) under POST /v2/agents'
219
+ // limits, an eval's file under MAX_EVAL_FILE_BYTES alone; every file, evals/ too, counts toward MAX_PACKAGE_FILES. A
220
+ // file under evals/ an agent is given all the same (the answer's schema, which ships beside each SKILL.md) keeps the
221
+ // agent's limits: checked once the manifest names it, before it is read.
222
+ const listed = files("");
223
+ const all = listed.filter((path) => !path.startsWith("evals/"));
212
224
  const sizes = all.map((path) => [path, lstatSync(join(dir, path)).size]);
225
+ const agentBytes = sizes.reduce((sum, [, size]) => sum + size, 0);
213
226
  const limits = [
227
+ ...listed.filter((path) => path.startsWith("evals/") && lstatSync(join(dir, path)).size > MAX_EVAL_FILE_BYTES).map((path) => `${path}: is over ${MAX_EVAL_FILE_BYTES} bytes, an eval file's limit`),
214
228
  ...sizes.filter(([, size]) => size > MAX_FILE_BYTES).map(([path]) => `${path}: is over ${MAX_FILE_BYTES} bytes, a package file's limit`),
215
- ...(sizes.reduce((sum, [, size]) => sum + size, 0) > MAX_PACKAGE_BYTES ? [`the package's files are over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit`] : []),
216
- ...(all.length > MAX_PACKAGE_FILES ? [`the package holds over ${MAX_PACKAGE_FILES} files`] : []),
229
+ ...(agentBytes > MAX_PACKAGE_BYTES ? [`the package's files are over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit`] : []),
230
+ ...(listed.length > MAX_PACKAGE_FILES ? [`the package holds over ${MAX_PACKAGE_FILES} files`] : []),
217
231
  ];
218
232
  if (limits.length)
219
233
  throw new PackageError(dir, [...problems, ...limits]);
@@ -265,14 +279,26 @@ export function readPackage(dir) {
265
279
  mcp.push({ server: need.server, tools: names, required: need.required === true, allow: allow, pin: pinned });
266
280
  }
267
281
  }
282
+ // A policy by tool: bash's alone (bash-read-only.ts), on a package that grants bash or names no tools (a new agent's
283
+ // tools, the box's shell among them where there is one).
284
+ let toolPolicy;
285
+ if (f.tool_policy !== undefined) {
286
+ const given = f.tool_policy;
287
+ if (!isObject(given) || !Object.keys(given).length || unknownFields(given, ["bash"]).length || !BASH_POLICIES.includes(given.bash))
288
+ bad(MANIFEST, `tool_policy is {bash: ${BASH_POLICIES.join(" | ")}}: read-only refuses, before it runs, any command that could write, run code or read outside the run's folder`);
289
+ else if (tools && !tools.includes("bash"))
290
+ bad(MANIFEST, "tool_policy.bash: the package's tools grant no bash, so its policy would hold nothing: add bash to tools, or leave tool_policy out");
291
+ else
292
+ toolPolicy = { bash: given.bash };
293
+ }
268
294
  // Computers by name come with the computer protocol; until then a package runs where this server puts a new agent.
269
295
  if (f.computer !== undefined && f.computer !== "default")
270
296
  bad(MANIFEST, "computer is default (this server's own place): no other computer is known yet");
271
297
  const parameters = {};
272
298
  for (const [key, p] of Object.entries(f.parameters === undefined ? {} : isObject(f.parameters) ? f.parameters : (bad(MANIFEST, "parameters is a mapping of names"), {}))) {
273
- const ok = PARAMETER.test(key) && isObject(p) && !unknownFields(p, ["type", "required", "pattern", "enum", "description", "default"]).length && PARAMETER_TYPES.includes(p.type) && (p.required === undefined || typeof p.required === "boolean") && typeof p.description === "string" && p.description.trim() !== "" && (p.pattern === undefined || (p.type === "string" && typeof p.pattern === "string"));
299
+ const ok = PARAMETER.test(key) && isObject(p) && !unknownFields(p, ["type", "required", "pattern", "enum", "format", "description", "default"]).length && PARAMETER_TYPES.includes(p.type) && (p.required === undefined || typeof p.required === "boolean") && typeof p.description === "string" && p.description.trim() !== "" && (p.pattern === undefined || (p.type === "string" && typeof p.pattern === "string"));
274
300
  if (!ok) {
275
- bad(MANIFEST, `parameters.${key} is {type: ${PARAMETER_TYPES.join(" | ")}, required?, pattern? (strings), enum?, default?, description}, its name lowercase`);
301
+ bad(MANIFEST, `parameters.${key} is {type: ${PARAMETER_TYPES.join(" | ")}, required?, pattern? (strings), enum?, format? (strings), default?, description}, its name lowercase`);
276
302
  continue;
277
303
  }
278
304
  try {
@@ -282,6 +308,8 @@ export function readPackage(dir) {
282
308
  catch {
283
309
  bad(MANIFEST, `parameters.${key}.pattern is not a regular expression`);
284
310
  }
311
+ // What a string's value is (a cron line, a time zone), for a form to ask for it as such.
312
+ const format = p.format === undefined ? undefined : p.type === "string" && PARAMETER_FORMATS.includes(p.format) ? p.format : (bad(MANIFEST, `parameters.${key}.format is one of ${PARAMETER_FORMATS.join(", ")}, on a string parameter`), undefined);
285
313
  // A closed set of values (a form shows a choice, never a pattern): one or more, each of the parameter's type, once.
286
314
  const choices = p.enum === undefined ? undefined : Array.isArray(p.enum) && p.enum.length > 0 && p.enum.every((one) => ofType(p.type, one)) && new Set(p.enum).size === p.enum.length ? p.enum : (bad(MANIFEST, `parameters.${key}.enum is a list of one or more distinct ${p.type} values`), undefined);
287
315
  if (choices && typeof p.pattern === "string")
@@ -296,7 +324,7 @@ export function readPackage(dir) {
296
324
  if (p.required === true)
297
325
  bad(MANIFEST, `parameters.${key} is required and has a default: a default is for a parameter apply may leave out`);
298
326
  }
299
- parameters[key] = { type: p.type, required: p.required === true, description: p.description, ...(typeof p.pattern === "string" ? { pattern: p.pattern } : {}), ...(choices ? { enum: choices } : {}), ...(p.default !== undefined && ofType(p.type, p.default) ? { default: p.default } : {}) };
327
+ parameters[key] = { type: p.type, required: p.required === true, description: p.description, ...(typeof p.pattern === "string" ? { pattern: p.pattern } : {}), ...(choices ? { enum: choices } : {}), ...(format ? { format } : {}), ...(p.default !== undefined && ofType(p.type, p.default) ? { default: p.default } : {}) };
300
328
  }
301
329
  const secrets = list(f.secrets, "secrets", (secret) => /^[A-Z][A-Z0-9_]{0,127}$/.test(secret));
302
330
  for (const secret of secrets.filter((name) => !PACKAGE_SECRETS.includes(name)))
@@ -325,9 +353,16 @@ export function readPackage(dir) {
325
353
  if (triggers.length && f.budget === undefined)
326
354
  bad(MANIFEST, "budget is required when the package has triggers: {per_run_usd}, each run's cap");
327
355
  let outputSchema;
356
+ let schemaBounded = true;
328
357
  if (f.output !== undefined) {
329
- if (!isObject(f.output) || unknownFields(f.output, ["schema"]).length || !inside(f.output.schema))
358
+ const at = isObject(f.output) ? f.output.schema : undefined;
359
+ const evalSize = typeof at === "string" && at.startsWith("evals/") && inside(at) ? lstatSync(join(dir, at)).size : 0;
360
+ if (!isObject(f.output) || unknownFields(f.output, ["schema"]).length || !inside(at))
330
361
  bad(MANIFEST, "output is {schema: a JSON Schema file in the package}");
362
+ else if (evalSize > MAX_FILE_BYTES || agentBytes + evalSize > MAX_PACKAGE_BYTES) {
363
+ schemaBounded = false;
364
+ bad(at, evalSize > MAX_FILE_BYTES ? `is over ${MAX_FILE_BYTES} bytes, a package file's limit: the answer's schema ships beside each SKILL.md, so it keeps an agent file's limits, under evals/ too` : `takes the agent's files over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit: the answer's schema ships beside each SKILL.md, so it counts as an agent file, under evals/ too`);
365
+ }
331
366
  else {
332
367
  try {
333
368
  outputSchema = JSON.parse(text(f.output.schema));
@@ -415,7 +450,7 @@ export function readPackage(dir) {
415
450
  }
416
451
  }
417
452
  // The answer's schema ships beside each SKILL.md too, as a rule does: the agent reads it there, and the skill names it.
418
- const schemaFile = isObject(f.output) && inside(f.output.schema) ? f.output.schema : undefined;
453
+ const schemaFile = schemaBounded && isObject(f.output) && inside(f.output.schema) ? f.output.schema : undefined;
419
454
  for (const skill of schemaFile ? skillDirs.filter((d) => d.isDirectory()) : []) {
420
455
  const path = `${skill.name}/${basename(schemaFile)}`;
421
456
  if (Object.hasOwn(skills, path))
@@ -461,7 +496,7 @@ export function readPackage(dir) {
461
496
  name, ...(typeof f.display_name === "string" ? { displayName: f.display_name } : {}), version: f.version, description: f.description,
462
497
  ...(typeof f.license === "string" ? { license: f.license } : {}), ...(isObject(f.author) ? { author: f.author } : {}), ...(typeof f.repository === "string" ? { repository: f.repository } : {}),
463
498
  ...(harness ? { harness } : {}), ...(isObject(f.model) ? { model: f.model } : {}), ...(typeof f.effort === "string" ? { effort: f.effort } : {}),
464
- ...(tools ? { tools } : {}), mcp, parameters, secrets, ...(isObject(f.budget) ? { budget: { per_run_usd: f.budget.per_run_usd } } : {}), ...(typeof f.learning === "boolean" ? { learning: f.learning } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
499
+ ...(tools ? { tools } : {}), mcp, ...(toolPolicy ? { toolPolicy } : {}), parameters, secrets, ...(isObject(f.budget) ? { budget: { per_run_usd: f.budget.per_run_usd } } : {}), ...(typeof f.learning === "boolean" ? { learning: f.learning } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
465
500
  triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), checks, instructions, skills, evals,
466
501
  };
467
502
  // What an apply makes, made here with each parameter's default, else a sample of its type, and checked as POST
@@ -500,7 +535,7 @@ export function packageView(p) {
500
535
  return {
501
536
  name: p.name, display_name: p.displayName ?? null, version: p.version, description: p.description, license: p.license ?? null, author: p.author ?? null, repository: p.repository ?? null,
502
537
  output: p.output ? { schema: p.output.schema, json_schema: p.outputSchema ?? null } : null,
503
- harness: p.harness ?? null, model: p.model ?? null, effort: p.effort ?? null, tools: p.tools ?? null,
538
+ harness: p.harness ?? null, model: p.model ?? null, effort: p.effort ?? null, tools: p.tools ?? null, tool_policy: p.toolPolicy ?? null,
504
539
  mcp: p.mcp.map(({ server, tools, required, allow, pin }) => ({ server, required, tools: tools.map((name) => ({ name, tool: mcpToolName(server, name), asks: allow.includes(name) ? "allow" : "ask", ...(Object.hasOwn(pin, name) ? { pin: pin[name] } : {}) })) })), parameters: p.parameters, secrets: p.secrets,
505
540
  budget: p.budget ?? null, learning: p.learning ?? false, approvals_default: p.approvals ?? "ask", triggers: p.triggers, skills: Object.keys(p.skills).filter((path) => /^[^/]+\/SKILL\.md$/.test(path)).map((path) => path.slice(0, -"/SKILL.md".length)), evals: p.evals,
506
541
  };
@@ -592,38 +627,24 @@ export async function packageModel(env, model, harness) {
592
627
  * owner's own setting; `grants`, the owner's answer at apply, alone are set to allow. A tool the package pins gets its
593
628
  * pin, filled, in the agent's tool settings, whatever its permission; one whose pin fills empty (its parameter not
594
629
  * given) is set to deny instead, granted or not, and named in `unpinned` (by gate name, with the parameters not given):
595
- * a send with no destination set never runs. While an agent's own settings keep no pin (`pins`, AGENT_LAYER_PINS by
596
- * default) a filled pin is not written: it is named in `unkept`, with its values, for the server's settings, and the tool is
597
- * set to deny unless the server's settings already pin it (`serverPinned`, by gate name): a write a template grants
598
- * never runs without its pin, whatever the agent's approvals. */
630
+ * a send with no destination set never runs. */
599
631
  export function compiled(p, parameters, chosen, _deps) {
600
632
  const skills = Object.keys(p.skills).filter((path) => /^[^/]+\/SKILL\.md$/.test(path)).map((path) => path.slice(0, -"/SKILL.md".length));
601
633
  const granted = chosen.mcp.flatMap(({ server, tools }) => tools.map((tool) => mcpToolName(server, tool)));
602
634
  const allowed = chosen.grants.filter((tool) => granted.includes(tool));
603
635
  const tools = granted.length ? [...(p.tools ?? chosen.defaultTools), ...granted] : p.tools;
604
636
  const settings = Object.fromEntries(allowed.map((tool) => [tool, { permission: "allow" }]));
637
+ // A tool's policy (bash's read-only), written as its setting, whatever its permission: never one an apply grants.
638
+ if (p.toolPolicy)
639
+ settings.bash = { ...settings.bash, policy: p.toolPolicy.bash };
605
640
  const unpinned = [];
606
- const unkept = [];
607
- for (const { server, pin } of chosen.mcp) {
608
- for (const [tool, args] of Object.entries(pin)) {
609
- const name = mcpToolName(server, tool);
610
- const each = Object.entries(args).map(([arg, value]) => [arg, pinFilled(value, parameters)]);
611
- const empty = [...new Set(each.flatMap(([, one]) => one.empty))];
612
- if (empty.length) {
613
- settings[name] = { permission: "deny" };
614
- unpinned.push({ tool: name, parameters: empty });
615
- }
616
- else {
617
- const filledPin = Object.fromEntries(each.map(([arg, one]) => [arg, one.value]));
618
- if (chosen.pins ?? AGENT_LAYER_PINS)
619
- settings[name] = { ...settings[name], pin: sortedPin(filledPin) };
620
- else {
621
- unkept.push({ tool: name, pin: filledPin });
622
- if (!chosen.serverPinned?.has(name))
623
- settings[name] = { permission: "deny" };
624
- }
625
- }
641
+ for (const { tool: name, pin, empty } of filledPins(chosen.mcp, parameters)) {
642
+ if (empty.length) {
643
+ settings[name] = { permission: "deny" };
644
+ unpinned.push({ tool: name, parameters: empty });
626
645
  }
646
+ else
647
+ settings[name] = { ...settings[name], pin: sortedPin(pin) };
627
648
  }
628
649
  const definition = {
629
650
  name: p.displayName ? filled(p.displayName, parameters) : p.name, description: p.description, instructions: filled(p.instructions, parameters),
@@ -632,6 +653,16 @@ export function compiled(p, parameters, chosen, _deps) {
632
653
  ...(p.learning !== undefined ? { learning: p.learning } : {}), ...(p.budget ? { max_cost_usd: p.budget.per_run_usd } : {}), skills,
633
654
  // The apply's choice: unattended only when it says never (none given: the agent asks).
634
655
  ...(chosen.approvals === "never" ? { approvals: "never" } : {}),
656
+ // The package's answer schema (manifest `output`): each completed run's structured answer, checked, is its result.output.
657
+ ...(isObject(p.outputSchema) ? { output_schema: p.outputSchema } : {}),
635
658
  };
636
- return { agent: { definition, skills: { ...p.skills } }, triggers: p.triggers.map((trigger) => filled(trigger, parameters)), unpinned, unkept };
659
+ return { agent: { definition, skills: { ...p.skills } }, triggers: p.triggers.map((trigger) => filled(trigger, parameters)), unpinned };
660
+ }
661
+ /** Each pin the package's MCP servers (`mcp`) set, by the tool's gate name, its values filled from `parameters`, and the
662
+ * parameters it names that were not given (`empty`, none when it fills whole). */
663
+ export function filledPins(mcp, parameters) {
664
+ return mcp.flatMap(({ server, pin }) => Object.entries(pin).map(([tool, args]) => {
665
+ const each = Object.entries(args).map(([arg, value]) => [arg, pinFilled(value, parameters)]);
666
+ return { tool: mcpToolName(server, tool), pin: Object.fromEntries(each.map(([arg, one]) => [arg, one.value])), empty: [...new Set(each.flatMap(([, one]) => one.empty))] };
667
+ }));
637
668
  }
@@ -0,0 +1,33 @@
1
+ import type { TimelineEvent } from "./timeline.js";
2
+ /** One call: its row, the row that closed it (by `tool_use_id`, never by time), and what it spawned. */
3
+ export type Call = {
4
+ use: TimelineEvent;
5
+ result?: TimelineEvent;
6
+ inner: Group[];
7
+ };
8
+ export type Group = {
9
+ type: "row";
10
+ row: TimelineEvent;
11
+ }
12
+ /** `rounds` counts the assistant entries the calls came from; one call per round is what a later round may fold into. */
13
+ | {
14
+ type: "calls";
15
+ round?: number;
16
+ conv?: number;
17
+ rounds: number;
18
+ calls: Call[];
19
+ };
20
+ /** Adjacent calls of one tool, shown as one line. */
21
+ export type Fold = {
22
+ tool: string;
23
+ calls: Call[];
24
+ };
25
+ export declare const failedCall: (call: Call) => boolean;
26
+ /**
27
+ * Rows to groups. A round is the calls of one assistant entry, in the order written. A row that names a parent call (a
28
+ * nested call, a subagent's rows) sits inside that call. Adjacent rounds of one call of the same tool fold into one
29
+ * group; any other row, a failed call or a call with inner rows ends the fold. Calls are never deduped.
30
+ */
31
+ export declare function groupTimeline(rows: readonly TimelineEvent[]): Group[];
32
+ /** Adjacent calls of one tool inside a group, folded; a call with inner rows keeps its own line. */
33
+ export declare function foldCalls(calls: readonly Call[]): Fold[];
@@ -0,0 +1,77 @@
1
+ export const failedCall = (call) => call.result?.tool_status === "failed";
2
+ const plain = (call) => !failedCall(call) && call.inner.length === 0;
3
+ const foldable = (group) => group.type === "calls" && group.calls.length === group.rounds && group.calls.every(plain);
4
+ /**
5
+ * Rows to groups. A round is the calls of one assistant entry, in the order written. A row that names a parent call (a
6
+ * nested call, a subagent's rows) sits inside that call. Adjacent rounds of one call of the same tool fold into one
7
+ * group; any other row, a failed call or a call with inner rows ends the fold. Calls are never deduped.
8
+ */
9
+ export function groupTimeline(rows) {
10
+ const uses = new Map();
11
+ const results = new Map();
12
+ for (const row of rows) {
13
+ if (row.kind === "tool_use" && row.tool_use_id)
14
+ uses.set(row.tool_use_id, row);
15
+ else if (row.kind === "tool_result" && row.tool_use_id)
16
+ results.set(row.tool_use_id, row);
17
+ }
18
+ const inside = new Map();
19
+ const top = [];
20
+ for (const row of rows) {
21
+ const spawned = row.kind === "subagent_started" || row.kind === "subagent_completed";
22
+ const named = spawned ? row.tool_use_id : row.parent_tool_use_id;
23
+ const parent = named && uses.has(named) && !(row.kind === "tool_use" && named === row.tool_use_id) ? named : undefined;
24
+ if (parent)
25
+ inside.set(parent, [...(inside.get(parent) ?? []), row]);
26
+ else if (!(row.kind === "tool_result" && row.tool_use_id && uses.has(row.tool_use_id)))
27
+ top.push(row);
28
+ }
29
+ const order = new Map(rows.map((row, index) => [row, index]));
30
+ const lead = (row) => (row.kind === "subagent_started" ? 0 : row.kind === "subagent_completed" ? 2 : 1);
31
+ /** Every row under a call, at any depth, in log order: the rows of a nested call's own nested calls included. */
32
+ const within = (id, seen = new Set()) => {
33
+ if (seen.has(id))
34
+ return [];
35
+ seen.add(id);
36
+ const direct = inside.get(id) ?? [];
37
+ const all = [...direct, ...direct.flatMap((row) => (row.kind === "tool_use" && row.tool_use_id ? within(row.tool_use_id, seen) : []))];
38
+ return all.sort((a, b) => order.get(a) - order.get(b));
39
+ };
40
+ const groups = [];
41
+ for (const row of top) {
42
+ if (row.kind !== "tool_use" || !row.tool_use_id) {
43
+ groups.push({ type: "row", row });
44
+ continue;
45
+ }
46
+ const call = { use: row, result: results.get(row.tool_use_id), inner: groupTimeline(within(row.tool_use_id).sort((a, b) => lead(a) - lead(b))) };
47
+ const last = groups.at(-1);
48
+ if (last?.type === "calls" && row.round !== undefined && last.round === row.round && last.conv === row.conversation_id)
49
+ last.calls.push(call);
50
+ else
51
+ groups.push({ type: "calls", round: row.round, conv: row.conversation_id, rounds: 1, calls: [call] });
52
+ }
53
+ const folded = [];
54
+ for (const group of groups) {
55
+ const last = folded.at(-1);
56
+ if (last && foldable(last) && foldable(group) && last.conv === group.conv && last.calls[0].use.tool_name === group.calls[0].use.tool_name) {
57
+ last.calls.push(...group.calls);
58
+ last.rounds += group.rounds;
59
+ }
60
+ else
61
+ folded.push(group);
62
+ }
63
+ return folded;
64
+ }
65
+ /** Adjacent calls of one tool inside a group, folded; a call with inner rows keeps its own line. */
66
+ export function foldCalls(calls) {
67
+ const folds = [];
68
+ for (const call of calls) {
69
+ const tool = call.use.tool_name ?? "";
70
+ const last = folds.at(-1);
71
+ if (last && last.tool === tool && call.inner.length === 0 && last.calls.every((other) => other.inner.length === 0))
72
+ last.calls.push(call);
73
+ else
74
+ folds.push({ tool, calls: [call] });
75
+ }
76
+ return folds;
77
+ }
@@ -0,0 +1,7 @@
1
+ export { groupTimeline, foldCalls, failedCall, type Call, type Fold, type Group } from "./group.js";
2
+ export { callFailed, foldLabel, inputPreview, labelOf, nameOf, registerLabel, registerOutcome, registerTurnEnding, type FoldSpec, type LabelFn, type OutcomeFn, type ToolResultView } from "./labels.js";
3
+ export { renderText } from "./render-text.js";
4
+ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, TURN_END } from "./timeline.js";
5
+ export { isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES, type MessageOrigin, type TriggerSource } from "./origin.js";
6
+ export { cut, scrubUrls } from "./util.js";
7
+ export { BROWSER_CHARGE, CALL_REFUSED, CAP_WRAPUP, CAPS, chargedTool, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
@@ -0,0 +1,7 @@
1
+ export { groupTimeline, foldCalls, failedCall } from "./group.js";
2
+ export { callFailed, foldLabel, inputPreview, labelOf, nameOf, registerLabel, registerOutcome, registerTurnEnding } from "./labels.js";
3
+ export { renderText } from "./render-text.js";
4
+ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, TURN_END } from "./timeline.js";
5
+ export { isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES } from "./origin.js";
6
+ export { cut, scrubUrls } from "./util.js";
7
+ export { BROWSER_CHARGE, CALL_REFUSED, CAP_WRAPUP, CAPS, chargedTool, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
@@ -0,0 +1,79 @@
1
+ import { type Obj } from "./util.js";
2
+ /** A tool result as a label sees it: its text blocks joined, its `details`, its error flag. */
3
+ export type ToolResultView = {
4
+ text: string;
5
+ details: unknown;
6
+ isError: boolean;
7
+ };
8
+ export type LabelFn = (args: Obj, result?: ToolResultView) => string | undefined;
9
+ /** How calls of one tool fold into one line; `subject` names one call from its input and output previews. */
10
+ export type FoldSpec = {
11
+ many: (count: number) => string;
12
+ subject?: (input: string | null, output: string | null) => string | undefined;
13
+ /** The input preview is the call's file path: a host's `path` option names it, as the call's own row does. */
14
+ path?: boolean;
15
+ };
16
+ /** Registers the label of one tool, in the past tense, and with `name` what the tool is called where calls are counted
17
+ * (a run's analytics). A host adds its own tools here. */
18
+ export declare function registerLabel(tool: string, label: LabelFn, fold?: FoldSpec, { name }?: {
19
+ name?: string;
20
+ }): void;
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 declare const nameOf: (tool: string) => string;
23
+ /** A finished call's outcome, when its own result says more than that the call returned: a tool that answers a refusal
24
+ * or a failure as its result, not as an error (a fetch's `{ok: false, refused}`), reads as refused or failed. */
25
+ export type OutcomeFn = (result: {
26
+ text: string;
27
+ isError: boolean;
28
+ }) => {
29
+ failed: boolean;
30
+ text: string;
31
+ } | undefined;
32
+ /** Registers how one tool's result tells its outcome. A host adds its own tools here. */
33
+ export declare function registerOutcome(tool: string, outcome: OutcomeFn): void;
34
+ /** The outcome of a call that returned (not one that errored), when its tool tells one. */
35
+ export declare const outcomeOf: (tool: string, result: {
36
+ text: string;
37
+ isError: boolean;
38
+ }) => {
39
+ failed: boolean;
40
+ text: string;
41
+ } | undefined;
42
+ /** Whether a finished call failed: an error, or a result its tool's outcome reads as failed (a refused fetch). The one
43
+ * 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
44
+ * read it already (a row, which also shows it) reads it once: a fetch's outcome parses its whole page. */
45
+ export declare const failedWith: (result: {
46
+ isError: boolean;
47
+ }, outcome: ReturnType<OutcomeFn>) => boolean;
48
+ /** failedWith, the outcome read here. */
49
+ export declare const callFailed: (tool: string, result: {
50
+ text: string;
51
+ isError: boolean;
52
+ }) => boolean;
53
+ /** Registers a tool that ends its turn (pi's `terminate`): what the person sends after a round of such tools is their
54
+ * next message, never a steer into a running turn. A host adds its own tools here. */
55
+ export declare function registerTurnEnding(tool: string): void;
56
+ /** Whether `tool` ends its turn (registerTurnEnding). */
57
+ export declare const endsTurn: (tool: string) => boolean;
58
+ /** The label of a call; `result` is given once the call has finished. Unknown tools get Grep's own fallback. */
59
+ export declare function labelOf(tool: string, args: Obj, result?: ToolResultView, extra?: Record<string, LabelFn>): string;
60
+ /** One line for several calls of one tool: `Read 4 pages: a.example, b.example, +2 more`. */
61
+ export declare function foldLabel(tool: string, calls: readonly {
62
+ input: string | null;
63
+ output: string | null;
64
+ }[], options?: {
65
+ path?: (path: string) => string;
66
+ }): string;
67
+ /** The input worth showing: Grep's keys first, then the browser and file ones. */
68
+ export declare function inputPreview(args: Obj, max: number): string | null;
69
+ /** Files a finished call put in the workspace. */
70
+ export declare function savedPaths(tool: string, args: Obj, result: ToolResultView): string[];
71
+ /** Tools that use the browser session; the first of them opens one. */
72
+ export declare const BROWSER_OPENERS: ReadonlySet<string>;
73
+ /** Every tool of the browser (pi-browser's): the calls a browser charge with no call of its own may fold into. */
74
+ export declare const BROWSER_STEPS: ReadonlySet<string>;
75
+ /** A call refused before it ran, in plain words: "Refused: " and the tool's name with what it would have acted on (the
76
+ * path it would have read or written, the command it would have run, the page it would have fetched), never a label's
77
+ * past tense ("Wrote deny.md"), which says it ran. Any tool: one with none of those reads as its name alone (an MCP
78
+ * server's tool as its server and name, "fake · send_message", as its label reads it). */
79
+ export declare function refusedLabel(tool: string, args: Obj): string;
@@ -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" });