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

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 (816) hide show
  1. package/CHANGELOG.md +472 -0
  2. package/NOTICE +18 -0
  3. package/README.md +1042 -240
  4. package/dist/adapter-facts.d.ts +3 -0
  5. package/dist/adapter-facts.js +5 -0
  6. package/dist/adapters.d.ts +64 -140
  7. package/dist/adapters.js +153 -377
  8. package/dist/agents-store.d.ts +146 -0
  9. package/dist/agents-store.js +359 -0
  10. package/dist/agents.d.ts +12 -5
  11. package/dist/agents.js +40 -17
  12. package/dist/app.d.ts +2 -4
  13. package/dist/app.js +227 -97
  14. package/dist/approvals.d.ts +4 -0
  15. package/dist/approvals.js +7 -0
  16. package/dist/archil-routes.d.ts +45 -0
  17. package/dist/archil-routes.js +150 -0
  18. package/dist/archil-settings.d.ts +30 -0
  19. package/dist/archil-settings.js +34 -0
  20. package/dist/background.d.ts +2 -1
  21. package/dist/background.js +69 -29
  22. package/dist/bounds.d.ts +26 -0
  23. package/dist/bounds.js +137 -0
  24. package/dist/box-egress-vm.d.ts +126 -0
  25. package/dist/box-egress-vm.js +364 -0
  26. package/dist/box-egress.d.ts +19 -8
  27. package/dist/box-egress.js +27 -15
  28. package/dist/box-paths.d.ts +59 -0
  29. package/dist/box-paths.js +92 -0
  30. package/dist/box-relay-vm.d.ts +4 -0
  31. package/dist/box-relay-vm.js +103 -55
  32. package/dist/box-relay.d.ts +2 -0
  33. package/dist/box-relay.js +2 -2
  34. package/dist/boxes.d.ts +20 -3
  35. package/dist/boxes.js +67 -14
  36. package/dist/browser-commands.d.ts +43 -0
  37. package/dist/browser-commands.js +154 -0
  38. package/dist/browser-cost.d.ts +30 -3
  39. package/dist/browser-cost.js +276 -21
  40. package/dist/browser-live.d.ts +124 -0
  41. package/dist/browser-live.js +324 -0
  42. package/dist/browser-person.d.ts +168 -0
  43. package/dist/browser-person.js +769 -0
  44. package/dist/budget.d.ts +80 -0
  45. package/dist/budget.js +211 -0
  46. package/dist/cap.d.ts +274 -63
  47. package/dist/cap.js +599 -188
  48. package/dist/cli.js +226 -16
  49. package/dist/coding-tools.d.ts +13 -1
  50. package/dist/coding-tools.js +107 -5
  51. package/dist/computer-adb.d.ts +12 -0
  52. package/dist/computer-adb.js +14 -0
  53. package/dist/computer-commands.d.ts +103 -0
  54. package/dist/computer-commands.js +256 -0
  55. package/dist/computer-keys.d.ts +68 -0
  56. package/dist/computer-keys.js +148 -0
  57. package/dist/computer-routes.d.ts +38 -0
  58. package/dist/computer-routes.js +56 -0
  59. package/dist/computer-setting.d.ts +37 -0
  60. package/dist/computer-setting.js +47 -0
  61. package/dist/computer-view.d.ts +38 -0
  62. package/dist/computer-view.js +14 -0
  63. package/dist/computers.d.ts +137 -0
  64. package/dist/computers.js +197 -0
  65. package/dist/console/THIRD-PARTY-NOTICES.txt +25 -0
  66. package/dist/console/assets/index-35-7aeIZ.js +519 -0
  67. package/dist/console/assets/index-Cejbov-Y.css +1 -0
  68. package/dist/console/index.html +2 -2
  69. package/dist/console-links.d.ts +2 -0
  70. package/dist/console-links.js +6 -0
  71. package/dist/decision-cap.d.ts +63 -0
  72. package/dist/decision-cap.js +163 -0
  73. package/dist/decision-rows.d.ts +5 -2
  74. package/dist/decision-rows.js +8 -6
  75. package/dist/decisions.d.ts +31 -4
  76. package/dist/decisions.js +66 -8
  77. package/dist/disk.d.ts +33 -0
  78. package/dist/disk.js +85 -0
  79. package/dist/door-line.d.ts +23 -0
  80. package/dist/door-line.js +83 -0
  81. package/dist/egress-proxy.d.ts +45 -0
  82. package/dist/egress-proxy.js +416 -0
  83. package/dist/egress-table.d.ts +24 -0
  84. package/dist/egress-table.js +165 -0
  85. package/dist/errors.d.ts +15 -0
  86. package/dist/errors.js +22 -2
  87. package/dist/exa-keyless.js +1 -1
  88. package/dist/explain.d.ts +22 -0
  89. package/dist/explain.js +207 -0
  90. package/dist/faux-computers.d.ts +35 -0
  91. package/dist/faux-computers.js +126 -0
  92. package/dist/file-types.d.ts +4 -0
  93. package/dist/file-types.js +11 -0
  94. package/dist/files.d.ts +3 -32
  95. package/dist/files.js +9 -117
  96. package/dist/github-connection.d.ts +207 -0
  97. package/dist/github-connection.js +595 -0
  98. package/dist/github.d.ts +64 -0
  99. package/dist/github.js +119 -0
  100. package/dist/grade.d.ts +14 -44
  101. package/dist/grade.js +55 -233
  102. package/dist/graph-served.d.ts +23 -2
  103. package/dist/graph-served.js +44 -3
  104. package/dist/graph-view.d.ts +7 -3
  105. package/dist/graph-view.js +26 -15
  106. package/dist/handed-values.d.ts +23 -0
  107. package/dist/handed-values.js +36 -0
  108. package/dist/harness-app.d.ts +33 -4
  109. package/dist/harness-app.js +539 -85
  110. package/dist/harness-install.d.ts +120 -0
  111. package/dist/harness-install.js +359 -0
  112. package/dist/harness-opencode/adapter.js +42 -8
  113. package/dist/harness-opencode/facts.d.ts +2 -0
  114. package/dist/harness-opencode/facts.js +28 -0
  115. package/dist/harness-opencode/harness.d.ts +4 -0
  116. package/dist/harness-opencode/harness.js +38 -5
  117. package/dist/harness-opencode/host/policy.js +11 -3
  118. package/dist/harness-opencode/transcript.d.ts +25 -0
  119. package/dist/harness-opencode/transcript.js +81 -0
  120. package/dist/harness-table.d.ts +75 -0
  121. package/dist/harness-table.js +145 -0
  122. package/dist/harness.d.ts +7 -28
  123. package/dist/harness.js +15 -41
  124. package/dist/heard.d.ts +12 -0
  125. package/dist/heard.js +45 -0
  126. package/dist/helper-env.d.ts +4 -0
  127. package/dist/helper-env.js +14 -0
  128. package/dist/home-path.d.ts +0 -4
  129. package/dist/home-path.js +3 -17
  130. package/dist/host-check.d.ts +13 -0
  131. package/dist/host-check.js +35 -0
  132. package/dist/host-tools.d.ts +51 -8
  133. package/dist/host-tools.js +108 -117
  134. package/dist/host.d.ts +12 -6
  135. package/dist/host.js +30 -24
  136. package/dist/hosted-search.d.ts +3 -0
  137. package/dist/hosted-search.js +5 -3
  138. package/dist/import-proxy.d.ts +42 -0
  139. package/dist/import-proxy.js +105 -0
  140. package/dist/import-summary.js +4 -8
  141. package/dist/import-worker.d.ts +2 -3
  142. package/dist/import-worker.js +18 -16
  143. package/dist/import.d.ts +37 -17
  144. package/dist/import.js +208 -222
  145. package/dist/key-meta.d.ts +26 -0
  146. package/dist/key-meta.js +30 -0
  147. package/dist/key-refusal.d.ts +4 -1
  148. package/dist/key-refusal.js +20 -7
  149. package/dist/key-words.d.ts +37 -0
  150. package/dist/key-words.js +40 -0
  151. package/dist/learn/check.d.ts +3 -1
  152. package/dist/learn/check.js +2 -2
  153. package/dist/learn/commit.d.ts +86 -0
  154. package/dist/learn/commit.js +182 -0
  155. package/dist/learn/folder.d.ts +296 -0
  156. package/dist/learn/folder.js +796 -0
  157. package/dist/learn/grade.d.ts +25 -9
  158. package/dist/learn/grade.js +98 -50
  159. package/dist/learn/index.d.ts +2 -2
  160. package/dist/learn/index.js +2 -2
  161. package/dist/learn/learning.sh +366 -0
  162. package/dist/learn/reflect.d.ts +12 -5
  163. package/dist/learn/reflect.js +72 -41
  164. package/dist/learn/secrets.d.ts +15 -7
  165. package/dist/learn/secrets.js +66 -16
  166. package/dist/learn/seed-check.d.ts +74 -0
  167. package/dist/learn/seed-check.js +103 -0
  168. package/dist/learn/skills.d.ts +7 -1
  169. package/dist/learn/skills.js +21 -4
  170. package/dist/learned-workflow.d.ts +12 -2
  171. package/dist/learned-workflow.js +9 -5
  172. package/dist/learning-routes.d.ts +107 -31
  173. package/dist/learning-routes.js +358 -403
  174. package/dist/learning-run.d.ts +61 -54
  175. package/dist/learning-run.js +183 -205
  176. package/dist/learning-words.d.ts +10 -8
  177. package/dist/learning-words.js +29 -13
  178. package/dist/learning.d.ts +186 -113
  179. package/dist/learning.js +345 -381
  180. package/dist/live/stream.d.ts +30 -0
  181. package/dist/live/stream.js +175 -0
  182. package/dist/live/translate.d.ts +52 -0
  183. package/dist/live/translate.js +276 -0
  184. package/dist/llm.js +3 -0
  185. package/dist/llms.txt +1 -0
  186. package/dist/local-models.d.ts +23 -0
  187. package/dist/local-models.js +35 -0
  188. package/dist/mcp-gateway.d.ts +129 -0
  189. package/dist/mcp-gateway.js +508 -0
  190. package/dist/mcp-meta.d.ts +20 -0
  191. package/dist/mcp-meta.js +50 -0
  192. package/dist/mcp-oauth.d.ts +172 -0
  193. package/dist/mcp-oauth.js +403 -0
  194. package/dist/mcp-private-hosts.d.ts +48 -0
  195. package/dist/mcp-private-hosts.js +141 -0
  196. package/dist/mcp-probe.d.ts +101 -0
  197. package/dist/mcp-probe.js +359 -0
  198. package/dist/mcp-secret-writes.d.ts +23 -0
  199. package/dist/mcp-secret-writes.js +60 -0
  200. package/dist/mcp-servers-store.d.ts +251 -0
  201. package/dist/mcp-servers-store.js +447 -0
  202. package/dist/mcp-servers.d.ts +185 -34
  203. package/dist/mcp-servers.js +304 -298
  204. package/dist/mcp-store.d.ts +103 -0
  205. package/dist/mcp-store.js +123 -0
  206. package/dist/mcp.js +22 -21
  207. package/dist/model.d.ts +77 -59
  208. package/dist/model.js +237 -98
  209. package/dist/monid.d.ts +8 -6
  210. package/dist/monid.js +39 -25
  211. package/dist/openapi.d.ts +22 -1
  212. package/dist/openapi.js +965 -111
  213. package/dist/owner.d.ts +46 -10
  214. package/dist/owner.js +123 -43
  215. package/dist/page.d.ts +12 -0
  216. package/dist/page.js +28 -2
  217. package/dist/paid-calls.d.ts +71 -2
  218. package/dist/paid-calls.js +125 -5
  219. package/dist/pdf-pages.d.ts +16 -14
  220. package/dist/pdf-pages.js +88 -58
  221. package/dist/place.d.ts +18 -15
  222. package/dist/place.js +36 -18
  223. package/dist/port-models.d.ts +53 -0
  224. package/dist/port-models.js +93 -0
  225. package/dist/print.d.ts +7 -0
  226. package/dist/print.js +13 -0
  227. package/dist/propose.d.ts +9 -8
  228. package/dist/propose.js +82 -49
  229. package/dist/provider.d.ts +85 -0
  230. package/dist/provider.js +178 -0
  231. package/dist/push-handler.d.ts +52 -0
  232. package/dist/push-handler.js +165 -0
  233. package/dist/refusal-words.d.ts +23 -0
  234. package/dist/refusal-words.js +25 -0
  235. package/dist/request-start.d.ts +6 -1
  236. package/dist/request-start.js +41 -10
  237. package/dist/result.d.ts +13 -2
  238. package/dist/result.js +4 -5
  239. package/dist/run-box.d.ts +22 -3
  240. package/dist/run-box.js +91 -20
  241. package/dist/run-computer.d.ts +24 -0
  242. package/dist/run-computer.js +15 -0
  243. package/dist/run-cut.d.ts +33 -0
  244. package/dist/run-cut.js +42 -0
  245. package/dist/run-db.d.ts +64 -0
  246. package/dist/run-db.js +155 -0
  247. package/dist/run-files.d.ts +31 -0
  248. package/dist/run-files.js +125 -0
  249. package/dist/run-holder.d.ts +52 -0
  250. package/dist/run-holder.js +139 -0
  251. package/dist/run-launch.d.ts +72 -0
  252. package/dist/run-launch.js +108 -0
  253. package/dist/run-learning-served.d.ts +43 -0
  254. package/dist/run-learning-served.js +16 -0
  255. package/dist/run-manifest.d.ts +7 -6
  256. package/dist/run-manifest.js +20 -10
  257. package/dist/run-reads-over-store.d.ts +102 -0
  258. package/dist/run-reads-over-store.js +151 -0
  259. package/dist/run-timeline-served.d.ts +13 -0
  260. package/dist/run-timeline-served.js +69 -0
  261. package/dist/run-view.d.ts +436 -0
  262. package/dist/run-view.js +620 -0
  263. package/dist/runnable.d.ts +36 -4
  264. package/dist/runnable.js +157 -31
  265. package/dist/runner/adapter-loop.d.ts +237 -0
  266. package/dist/runner/adapter-loop.js +1625 -0
  267. package/dist/runner/adapter-run-spec.d.ts +216 -0
  268. package/dist/runner/adapter-run-spec.js +537 -0
  269. package/dist/runner/adapters/index.d.ts +37 -0
  270. package/dist/runner/adapters/index.js +66 -0
  271. package/dist/runner/adapters/pi.d.ts +99 -0
  272. package/dist/runner/adapters/pi.js +260 -0
  273. package/dist/runner/beside.d.ts +12 -0
  274. package/dist/runner/beside.js +30 -0
  275. package/dist/runner/claim-secrets.d.ts +30 -0
  276. package/dist/runner/claim-secrets.js +90 -0
  277. package/dist/runner/cli-run-spec.d.ts +17 -0
  278. package/dist/runner/cli-run-spec.js +371 -0
  279. package/dist/runner/commands.d.ts +23 -0
  280. package/dist/runner/commands.js +67 -0
  281. package/dist/runner/computer-journal.d.ts +38 -0
  282. package/dist/runner/computer-journal.js +120 -0
  283. package/dist/runner/conformance/child.d.ts +1 -0
  284. package/dist/runner/conformance/child.js +78 -0
  285. package/dist/runner/conformance/harness.d.ts +89 -0
  286. package/dist/runner/conformance/harness.js +928 -0
  287. package/dist/runner/conformance/subject.d.ts +83 -0
  288. package/dist/runner/conformance/subject.js +1 -0
  289. package/dist/runner/dispatch.d.ts +30 -0
  290. package/dist/runner/dispatch.js +99 -0
  291. package/dist/runner/end-of-run.d.ts +32 -0
  292. package/dist/runner/end-of-run.js +56 -0
  293. package/dist/runner/github-app.d.ts +16 -0
  294. package/dist/runner/github-app.js +37 -0
  295. package/dist/runner/hand-back.d.ts +43 -0
  296. package/dist/runner/hand-back.js +69 -0
  297. package/dist/runner/harness-loops.d.ts +10 -0
  298. package/dist/runner/harness-loops.js +70 -0
  299. package/dist/runner/journal-kinds.d.ts +211 -0
  300. package/dist/runner/journal-kinds.js +116 -0
  301. package/dist/runner/journal-reader.d.ts +44 -0
  302. package/dist/runner/journal-reader.js +127 -0
  303. package/dist/runner/learning-ask.d.ts +37 -0
  304. package/dist/runner/learning-ask.js +99 -0
  305. package/dist/runner/learning-dispatch.d.ts +38 -0
  306. package/dist/runner/learning-dispatch.js +75 -0
  307. package/dist/runner/learning-end.d.ts +31 -0
  308. package/dist/runner/learning-end.js +136 -0
  309. package/dist/runner/learning-factory.d.ts +13 -0
  310. package/dist/runner/learning-factory.js +37 -0
  311. package/dist/runner/learning-loop.d.ts +150 -0
  312. package/dist/runner/learning-loop.js +246 -0
  313. package/dist/runner/learning-seed.d.ts +30 -0
  314. package/dist/runner/learning-seed.js +41 -0
  315. package/dist/runner/live-ticker.d.ts +18 -0
  316. package/dist/runner/live-ticker.js +88 -0
  317. package/dist/runner/loop-contract.d.ts +153 -0
  318. package/dist/runner/loop-contract.js +26 -0
  319. package/dist/runner/loop.d.ts +79 -0
  320. package/dist/runner/loop.js +185 -0
  321. package/dist/runner/main.d.ts +89 -0
  322. package/dist/runner/main.js +282 -0
  323. package/dist/runner/mcp-claim.d.ts +67 -0
  324. package/dist/runner/mcp-claim.js +403 -0
  325. package/dist/runner/mcp-github.d.ts +53 -0
  326. package/dist/runner/mcp-github.js +91 -0
  327. package/dist/runner/mcp-run.d.ts +116 -0
  328. package/dist/runner/mcp-run.js +152 -0
  329. package/dist/runner/metrics.d.ts +18 -0
  330. package/dist/runner/metrics.js +24 -0
  331. package/dist/runner/model-route.d.ts +111 -0
  332. package/dist/runner/model-route.js +183 -0
  333. package/dist/runner/pi-stop.d.ts +6 -0
  334. package/dist/runner/pi-stop.js +8 -0
  335. package/dist/runner/redact.d.ts +26 -0
  336. package/dist/runner/redact.js +51 -0
  337. package/dist/runner/reflect-hook.d.ts +81 -0
  338. package/dist/runner/reflect-hook.js +111 -0
  339. package/dist/runner/runner.d.ts +114 -0
  340. package/dist/runner/runner.js +672 -0
  341. package/dist/runner/sessions.d.ts +9 -0
  342. package/dist/runner/sessions.js +145 -0
  343. package/dist/runner/side-effects.d.ts +19 -0
  344. package/dist/runner/side-effects.js +20 -0
  345. package/dist/runner/spec-holds.d.ts +41 -0
  346. package/dist/runner/spec-holds.js +58 -0
  347. package/dist/runner/store-port.d.ts +9 -0
  348. package/dist/runner/store-port.js +7 -0
  349. package/dist/runner/store-secrets.d.ts +11 -0
  350. package/dist/runner/store-secrets.js +105 -0
  351. package/dist/runner/workflow-adapters.d.ts +1 -0
  352. package/dist/runner/workflow-adapters.js +4 -0
  353. package/dist/runner/workflow-host.d.ts +88 -0
  354. package/dist/runner/workflow-host.js +66 -0
  355. package/dist/runner/workflow-loop.d.ts +126 -0
  356. package/dist/runner/workflow-loop.js +372 -0
  357. package/dist/runner/workflow-spec.d.ts +157 -0
  358. package/dist/runner/workflow-spec.js +801 -0
  359. package/dist/runs-over-store.d.ts +203 -0
  360. package/dist/runs-over-store.js +396 -0
  361. package/dist/runs.d.ts +360 -222
  362. package/dist/runs.js +1619 -536
  363. package/dist/seal-key.d.ts +30 -0
  364. package/dist/seal-key.js +141 -0
  365. package/dist/sealed-settings-store.d.ts +71 -0
  366. package/dist/sealed-settings-store.js +205 -0
  367. package/dist/sealed-settings.d.ts +60 -0
  368. package/dist/sealed-settings.js +178 -0
  369. package/dist/secret-writes.d.ts +147 -0
  370. package/dist/secret-writes.js +144 -0
  371. package/dist/secrets.d.ts +22 -0
  372. package/dist/secrets.js +37 -4
  373. package/dist/served-only.d.ts +5 -0
  374. package/dist/served-only.js +12 -0
  375. package/dist/server-approvers.d.ts +8 -0
  376. package/dist/server-approvers.js +12 -0
  377. package/dist/server-fs.d.ts +40 -0
  378. package/dist/server-fs.js +138 -0
  379. package/dist/server-keys.d.ts +18 -0
  380. package/dist/server-keys.js +31 -0
  381. package/dist/server-lock.js +1 -1
  382. package/dist/server-secrets-store.d.ts +18 -0
  383. package/dist/server-secrets-store.js +54 -0
  384. package/dist/server-secrets.d.ts +23 -0
  385. package/dist/server-secrets.js +73 -0
  386. package/dist/server.d.ts +152 -74
  387. package/dist/server.js +1757 -588
  388. package/dist/sessions.d.ts +3 -1
  389. package/dist/sessions.js +8 -4
  390. package/dist/sign-ins-secrets.d.ts +35 -0
  391. package/dist/sign-ins-secrets.js +109 -0
  392. package/dist/sign-ins-store.d.ts +200 -0
  393. package/dist/sign-ins-store.js +373 -0
  394. package/dist/sign-ins.d.ts +43 -7
  395. package/dist/sign-ins.js +94 -18
  396. package/dist/skills.d.ts +6 -5
  397. package/dist/skills.js +18 -14
  398. package/dist/standard-webhooks.d.ts +30 -0
  399. package/dist/standard-webhooks.js +72 -0
  400. package/dist/stats.d.ts +5 -7
  401. package/dist/stats.js +8 -24
  402. package/dist/stop-signals.d.ts +22 -0
  403. package/dist/stop-signals.js +38 -0
  404. package/dist/store/agent-body.d.ts +103 -0
  405. package/dist/store/agent-body.js +126 -0
  406. package/dist/store/dialect.d.ts +59 -0
  407. package/dist/store/dialect.js +32 -0
  408. package/dist/store/fence.d.ts +22 -0
  409. package/dist/store/fence.js +15 -0
  410. package/dist/store/index.d.ts +17 -0
  411. package/dist/store/index.js +17 -0
  412. package/dist/store/journal/storage.d.ts +137 -0
  413. package/dist/store/journal/storage.js +1021 -0
  414. package/dist/store/open.d.ts +34 -0
  415. package/dist/store/open.js +30 -0
  416. package/dist/store/postgres/connection.d.ts +74 -0
  417. package/dist/store/postgres/connection.js +532 -0
  418. package/dist/store/postgres/dialect.d.ts +9 -0
  419. package/dist/store/postgres/dialect.js +39 -0
  420. package/dist/store/postgres/migrate.d.ts +21 -0
  421. package/dist/store/postgres/migrate.js +106 -0
  422. package/dist/store/postgres/migrations/0001_initial.sql +418 -0
  423. package/dist/store/postgres/migrations/0002_external_agents.sql +14 -0
  424. package/dist/store/postgres/store.d.ts +37 -0
  425. package/dist/store/postgres/store.js +48 -0
  426. package/dist/store/prompts.d.ts +11 -0
  427. package/dist/store/prompts.js +112 -0
  428. package/dist/store/schema.d.ts +26 -0
  429. package/dist/store/schema.js +522 -0
  430. package/dist/store/seal.d.ts +48 -0
  431. package/dist/store/seal.js +69 -0
  432. package/dist/store/sqlite/connection.d.ts +105 -0
  433. package/dist/store/sqlite/connection.js +309 -0
  434. package/dist/store/sqlite/memory.d.ts +2 -0
  435. package/dist/store/sqlite/memory.js +4 -0
  436. package/dist/store/sqlite/run-launch.d.ts +8 -0
  437. package/dist/store/sqlite/run-launch.js +20 -0
  438. package/dist/store/sqlite/run-patch.d.ts +54 -0
  439. package/dist/store/sqlite/run-patch.js +114 -0
  440. package/dist/store/sqlite/store.d.ts +33 -0
  441. package/dist/store/sqlite/store.js +1337 -0
  442. package/dist/store/sqlite/worker.d.ts +78 -0
  443. package/dist/store/sqlite/worker.js +242 -0
  444. package/dist/store/store.d.ts +1253 -0
  445. package/dist/store/store.js +190 -0
  446. package/dist/store-reads/analytics.d.ts +55 -0
  447. package/dist/store-reads/analytics.js +135 -0
  448. package/dist/store-reads/cap.d.ts +17 -0
  449. package/dist/store-reads/cap.js +17 -0
  450. package/dist/store-reads/decisions.d.ts +5 -0
  451. package/dist/store-reads/decisions.js +31 -0
  452. package/dist/store-reads/import-summary.d.ts +6 -0
  453. package/dist/store-reads/import-summary.js +14 -0
  454. package/dist/store-reads/journal.d.ts +30 -0
  455. package/dist/store-reads/journal.js +120 -0
  456. package/dist/store-reads/learning.d.ts +93 -0
  457. package/dist/store-reads/learning.js +202 -0
  458. package/dist/store-reads/runs.d.ts +42 -0
  459. package/dist/store-reads/runs.js +84 -0
  460. package/dist/store-reads/stats.d.ts +30 -0
  461. package/dist/store-reads/stats.js +59 -0
  462. package/dist/store-reads/workflow.d.ts +7 -0
  463. package/dist/store-reads/workflow.js +14 -0
  464. package/dist/store-view.d.ts +37 -0
  465. package/dist/store-view.js +305 -0
  466. package/dist/template-eval.d.ts +239 -0
  467. package/dist/template-eval.js +1020 -0
  468. package/dist/template-github-permissions.d.ts +18 -0
  469. package/dist/template-github-permissions.js +32 -0
  470. package/dist/templates.d.ts +199 -0
  471. package/dist/templates.js +637 -0
  472. package/dist/tool-blurbs.d.ts +4 -0
  473. package/dist/tool-blurbs.js +27 -0
  474. package/dist/tool-gate.d.ts +183 -37
  475. package/dist/tool-gate.js +450 -99
  476. package/dist/tool-keys-store.d.ts +110 -0
  477. package/dist/tool-keys-store.js +291 -0
  478. package/dist/tool-keys.d.ts +27 -13
  479. package/dist/tool-keys.js +24 -10
  480. package/dist/tool-plane.d.ts +115 -25
  481. package/dist/tool-plane.js +251 -74
  482. package/dist/tool-settings-store.d.ts +30 -0
  483. package/dist/tool-settings-store.js +53 -0
  484. package/dist/tools.d.ts +95 -24
  485. package/dist/tools.js +344 -65
  486. package/dist/trigger-accept.d.ts +36 -0
  487. package/dist/trigger-accept.js +152 -0
  488. package/dist/trigger-adapter.d.ts +143 -0
  489. package/dist/trigger-adapter.js +31 -0
  490. package/dist/trigger-adapters.d.ts +2 -0
  491. package/dist/trigger-adapters.js +4 -0
  492. package/dist/trigger-github.d.ts +2 -0
  493. package/dist/trigger-github.js +85 -0
  494. package/dist/trigger-schedule.d.ts +6 -0
  495. package/dist/trigger-schedule.js +115 -0
  496. package/dist/trigger-secrets-shown.d.ts +66 -0
  497. package/dist/trigger-secrets-shown.js +77 -0
  498. package/dist/trigger-signatures.d.ts +58 -0
  499. package/dist/trigger-signatures.js +79 -0
  500. package/dist/trigger-targets.d.ts +46 -0
  501. package/dist/trigger-targets.js +95 -0
  502. package/dist/trigger-webhook.d.ts +2 -0
  503. package/dist/trigger-webhook.js +92 -0
  504. package/dist/triggers.d.ts +282 -237
  505. package/dist/triggers.js +720 -608
  506. package/dist/turn-end.d.ts +3 -0
  507. package/dist/turn-end.js +3 -0
  508. package/dist/uploads.d.ts +10 -8
  509. package/dist/uploads.js +45 -45
  510. package/dist/usage.d.ts +33 -3
  511. package/dist/usage.js +38 -4
  512. package/dist/validate.d.ts +6 -0
  513. package/dist/validate.js +42 -12
  514. package/dist/{fetch-page.d.ts → web-fetch-direct.d.ts} +2 -4
  515. package/dist/{fetch-page.js → web-fetch-direct.js} +2 -4
  516. package/dist/web-fetch.d.ts +17 -9
  517. package/dist/web-fetch.js +56 -21
  518. package/dist/web-search.d.ts +1 -1
  519. package/dist/web-search.js +1 -1
  520. package/dist/webhooks.d.ts +33 -23
  521. package/dist/webhooks.js +69 -56
  522. package/dist/wires.d.ts +11 -0
  523. package/dist/wires.js +7 -0
  524. package/dist/workspace/archil-claim.d.ts +57 -0
  525. package/dist/workspace/archil-claim.js +154 -0
  526. package/dist/workspace/archil-disk.d.ts +104 -0
  527. package/dist/workspace/archil-disk.js +254 -0
  528. package/dist/workspace/archil-exec.d.ts +59 -0
  529. package/dist/workspace/archil-exec.js +218 -0
  530. package/dist/workspace/archil-key.d.ts +17 -0
  531. package/dist/workspace/archil-key.js +30 -0
  532. package/dist/workspace/archil-mount-credential.d.ts +58 -0
  533. package/dist/workspace/archil-mount-credential.js +165 -0
  534. package/dist/workspace/archil.d.ts +59 -0
  535. package/dist/workspace/archil.js +676 -0
  536. package/dist/workspace/attach.d.ts +48 -0
  537. package/dist/workspace/attach.js +439 -0
  538. package/dist/workspace/computer-deps.d.ts +58 -0
  539. package/dist/workspace/computer-deps.js +113 -0
  540. package/dist/workspace/computer-for-claim.d.ts +115 -0
  541. package/dist/workspace/computer-for-claim.js +198 -0
  542. package/dist/workspace/computer-hold.d.ts +145 -0
  543. package/dist/workspace/computer-hold.js +258 -0
  544. package/dist/workspace/computer-ledger.d.ts +22 -0
  545. package/dist/workspace/computer-ledger.js +19 -0
  546. package/dist/workspace/computer-ports.d.ts +13 -0
  547. package/dist/workspace/computer-ports.js +108 -0
  548. package/dist/workspace/computer-providers.d.ts +12 -0
  549. package/dist/workspace/computer-providers.js +17 -0
  550. package/dist/workspace/computer-serves.d.ts +12 -0
  551. package/dist/workspace/computer-serves.js +15 -0
  552. package/dist/workspace/executors.d.ts +38 -0
  553. package/dist/workspace/executors.js +150 -0
  554. package/dist/workspace/glob.d.ts +2 -0
  555. package/dist/workspace/glob.js +25 -0
  556. package/dist/workspace/grep-worker.d.ts +11 -0
  557. package/dist/workspace/grep-worker.js +91 -0
  558. package/dist/workspace/hands.d.ts +25 -0
  559. package/dist/workspace/hands.js +121 -0
  560. package/dist/workspace/index.d.ts +23 -0
  561. package/dist/workspace/index.js +25 -0
  562. package/dist/workspace/kind-skills/desktop/SKILL.md +106 -0
  563. package/dist/workspace/kind-skills/phone/SKILL.md +116 -0
  564. package/dist/workspace/kind-skills.d.ts +11 -0
  565. package/dist/workspace/kind-skills.js +16 -0
  566. package/dist/workspace/learning-workspace.d.ts +24 -0
  567. package/dist/workspace/learning-workspace.js +107 -0
  568. package/dist/workspace/local.d.ts +6 -0
  569. package/dist/workspace/local.js +632 -0
  570. package/dist/workspace/paths.d.ts +48 -0
  571. package/dist/workspace/paths.js +134 -0
  572. package/dist/workspace/pi-env.d.ts +39 -0
  573. package/dist/workspace/pi-env.js +397 -0
  574. package/dist/workspace/place.d.ts +7 -0
  575. package/dist/workspace/place.js +3 -0
  576. package/dist/workspace/resolve-computer.d.ts +106 -0
  577. package/dist/workspace/resolve-computer.js +188 -0
  578. package/dist/workspace/revision-skills.d.ts +15 -0
  579. package/dist/workspace/revision-skills.js +42 -0
  580. package/dist/workspace/run-tools.d.ts +173 -0
  581. package/dist/workspace/run-tools.js +172 -0
  582. package/dist/workspace/run-workspace.d.ts +25 -0
  583. package/dist/workspace/run-workspace.js +56 -0
  584. package/dist/workspace/server-run-workspace.d.ts +24 -0
  585. package/dist/workspace/server-run-workspace.js +84 -0
  586. package/dist/workspace/workspace.d.ts +169 -0
  587. package/dist/workspace/workspace.js +54 -0
  588. package/dist/workspace-paths.d.ts +1 -10
  589. package/dist/workspace-paths.js +3 -37
  590. package/dist/workspace.d.ts +3 -17
  591. package/dist/workspace.js +6 -74
  592. package/harnesses/claude-agent/package-lock.json +1533 -0
  593. package/harnesses/claude-agent/package.json +7 -0
  594. package/harnesses/codex/package-lock.json +135 -0
  595. package/harnesses/codex/package.json +7 -0
  596. package/launcher/agentrun-serve +13 -3
  597. package/package.json +36 -25
  598. package/skills/agentrun-serve/SKILL.md +2 -0
  599. package/templates/README.md +211 -0
  600. package/templates/code-review/agent.md +50 -0
  601. package/templates/code-review/evals/clean-refactor/case.yaml +3 -0
  602. package/templates/code-review/evals/clean-refactor/graders/empty.md +5 -0
  603. package/templates/code-review/evals/clean-refactor/graders/schema.md +5 -0
  604. package/templates/code-review/evals/clean-refactor/prompt.md +31 -0
  605. package/templates/code-review/evals/injection/case.yaml +3 -0
  606. package/templates/code-review/evals/injection/graders/ignores.md +4 -0
  607. package/templates/code-review/evals/injection/graders/schema.md +5 -0
  608. package/templates/code-review/evals/injection/prompt.md +23 -0
  609. package/templates/code-review/evals/null-name/case.yaml +3 -0
  610. package/templates/code-review/evals/null-name/graders/finds.md +4 -0
  611. package/templates/code-review/evals/null-name/graders/schema.md +5 -0
  612. package/templates/code-review/evals/null-name/prompt.md +17 -0
  613. package/templates/code-review/evals/off-by-one/case.yaml +3 -0
  614. package/templates/code-review/evals/off-by-one/graders/finds.md +4 -0
  615. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +11 -0
  616. package/templates/code-review/evals/off-by-one/graders/schema.md +5 -0
  617. package/templates/code-review/evals/off-by-one/prompt.md +20 -0
  618. package/templates/code-review/evals/re-review/case.yaml +3 -0
  619. package/templates/code-review/evals/re-review/graders/resolves.md +4 -0
  620. package/templates/code-review/evals/re-review/graders/schema.md +5 -0
  621. package/templates/code-review/evals/re-review/prompt.md +23 -0
  622. package/templates/code-review/evals/repo-rule/case.yaml +3 -0
  623. package/templates/code-review/evals/repo-rule/graders/cites.md +4 -0
  624. package/templates/code-review/evals/repo-rule/graders/schema.md +5 -0
  625. package/templates/code-review/evals/repo-rule/prompt.md +31 -0
  626. package/templates/code-review/findings.schema.json +125 -0
  627. package/templates/code-review/rules/REVIEW.md +41 -0
  628. package/templates/code-review/skills/review/SKILL.md +162 -0
  629. package/templates/inbound-lead/agent.md +76 -0
  630. package/templates/inbound-lead/evals/clear-disqualifier/case.yaml +5 -0
  631. package/templates/inbound-lead/evals/clear-disqualifier/graders/action.md +5 -0
  632. package/templates/inbound-lead/evals/clear-disqualifier/graders/disqualifier.md +18 -0
  633. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +5 -0
  634. package/templates/inbound-lead/evals/clear-disqualifier/graders/score-formula.md +26 -0
  635. package/templates/inbound-lead/evals/clear-disqualifier/prompt.md +12 -0
  636. package/templates/inbound-lead/evals/injection-in-form/case.yaml +5 -0
  637. package/templates/inbound-lead/evals/injection-in-form/graders/flagged.md +5 -0
  638. package/templates/inbound-lead/evals/injection-in-form/graders/ignores-it.md +19 -0
  639. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +5 -0
  640. package/templates/inbound-lead/evals/injection-in-form/prompt.md +12 -0
  641. package/templates/inbound-lead/evals/learned-correction/case.yaml +8 -0
  642. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +1 -0
  643. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +14 -0
  644. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +21 -0
  645. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +5 -0
  646. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +5 -0
  647. package/templates/inbound-lead/evals/learned-correction/prompt.md +12 -0
  648. package/templates/inbound-lead/evals/strong-fit/case.yaml +5 -0
  649. package/templates/inbound-lead/evals/strong-fit/graders/book-call.md +5 -0
  650. package/templates/inbound-lead/evals/strong-fit/graders/fit.md +21 -0
  651. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +5 -0
  652. package/templates/inbound-lead/evals/strong-fit/graders/score-formula.md +26 -0
  653. package/templates/inbound-lead/evals/strong-fit/prompt.md +12 -0
  654. package/templates/inbound-lead/evals/thin-data/case.yaml +5 -0
  655. package/templates/inbound-lead/evals/thin-data/graders/personal-email.md +5 -0
  656. package/templates/inbound-lead/evals/thin-data/graders/schema.md +5 -0
  657. package/templates/inbound-lead/evals/thin-data/graders/unknowns.md +17 -0
  658. package/templates/inbound-lead/evals/thin-data/prompt.md +12 -0
  659. package/templates/inbound-lead/evals/write-back/case.yaml +16 -0
  660. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +266 -0
  661. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +22 -0
  662. package/templates/inbound-lead/evals/write-back/graders/schema.md +5 -0
  663. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +7 -0
  664. package/templates/inbound-lead/evals/write-back/prompt.md +12 -0
  665. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +18 -0
  666. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +266 -0
  667. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +7 -0
  668. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +18 -0
  669. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +5 -0
  670. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +12 -0
  671. package/templates/inbound-lead/lead.schema.json +587 -0
  672. package/templates/inbound-lead/rules/FLAGS.md +43 -0
  673. package/templates/inbound-lead/rules/RUBRIC.md +73 -0
  674. package/templates/inbound-lead/skills/lead/SKILL.md +130 -0
  675. package/templates/kyb/agent.md +44 -0
  676. package/templates/kyb/evals/adverse-media/case.yaml +4 -0
  677. package/templates/kyb/evals/adverse-media/graders/dated-and-graded.md +25 -0
  678. package/templates/kyb/evals/adverse-media/graders/schema.md +5 -0
  679. package/templates/kyb/evals/adverse-media/prompt.md +12 -0
  680. package/templates/kyb/evals/canada-active-filed/case.yaml +4 -0
  681. package/templates/kyb/evals/canada-active-filed/graders/no-boilerplate-flags.md +22 -0
  682. package/templates/kyb/evals/canada-active-filed/graders/schema.md +5 -0
  683. package/templates/kyb/evals/canada-active-filed/prompt.md +43 -0
  684. package/templates/kyb/evals/clean-public-company/case.yaml +4 -0
  685. package/templates/kyb/evals/clean-public-company/graders/cited-and-proceed.md +23 -0
  686. package/templates/kyb/evals/clean-public-company/graders/schema.md +5 -0
  687. package/templates/kyb/evals/clean-public-company/prompt.md +11 -0
  688. package/templates/kyb/evals/injection-in-page/case.yaml +4 -0
  689. package/templates/kyb/evals/injection-in-page/fixtures/compliance-page.html +29 -0
  690. package/templates/kyb/evals/injection-in-page/graders/ignores-it.md +35 -0
  691. package/templates/kyb/evals/injection-in-page/graders/schema.md +5 -0
  692. package/templates/kyb/evals/injection-in-page/prompt.md +47 -0
  693. package/templates/kyb/evals/name-collision/case.yaml +4 -0
  694. package/templates/kyb/evals/name-collision/graders/never-merges.md +24 -0
  695. package/templates/kyb/evals/name-collision/graders/schema.md +5 -0
  696. package/templates/kyb/evals/name-collision/prompt.md +11 -0
  697. package/templates/kyb/evals/no-invention/case.yaml +4 -0
  698. package/templates/kyb/evals/no-invention/graders/invents-nothing.md +22 -0
  699. package/templates/kyb/evals/no-invention/graders/schema.md +5 -0
  700. package/templates/kyb/evals/no-invention/prompt.md +11 -0
  701. package/templates/kyb/evals/sanctioned-entity/case.yaml +6 -0
  702. package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ADD.CSV.txt +13 -0
  703. package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ALT.CSV.txt +12 -0
  704. package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/SDN.CSV.txt +9 -0
  705. package/templates/kyb/evals/sanctioned-entity/graders/cites-the-entry.md +6 -0
  706. package/templates/kyb/evals/sanctioned-entity/graders/finds-the-hit.md +27 -0
  707. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +5 -0
  708. package/templates/kyb/evals/sanctioned-entity/prompt.md +65 -0
  709. package/templates/kyb/kyb.schema.json +274 -0
  710. package/templates/kyb/rules/ADVERSE-MEDIA.md +84 -0
  711. package/templates/kyb/rules/RED-FLAGS.md +68 -0
  712. package/templates/kyb/rules/SANCTIONS.md +140 -0
  713. package/templates/kyb/rules/SOURCES.md +92 -0
  714. package/templates/kyb/skills/kyb/SKILL.md +285 -0
  715. package/templates/market-monitor/agent.md +58 -0
  716. package/templates/market-monitor/digest.schema.json +194 -0
  717. package/templates/market-monitor/evals/blocked-source/case.yaml +4 -0
  718. package/templates/market-monitor/evals/blocked-source/graders/blocked-said.md +17 -0
  719. package/templates/market-monitor/evals/blocked-source/graders/schema.md +5 -0
  720. package/templates/market-monitor/evals/blocked-source/prompt.md +37 -0
  721. package/templates/market-monitor/evals/every-competitor-named/case.yaml +4 -0
  722. package/templates/market-monitor/evals/every-competitor-named/graders/every-company-named.md +16 -0
  723. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +5 -0
  724. package/templates/market-monitor/evals/every-competitor-named/prompt.md +44 -0
  725. package/templates/market-monitor/evals/learned-preference/case.yaml +7 -0
  726. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +1 -0
  727. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +8 -0
  728. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +17 -0
  729. package/templates/market-monitor/evals/learned-preference/graders/schema.md +5 -0
  730. package/templates/market-monitor/evals/learned-preference/prompt.md +25 -0
  731. package/templates/market-monitor/evals/no-repeats/case.yaml +4 -0
  732. package/templates/market-monitor/evals/no-repeats/graders/no-pulse-repeat.md +20 -0
  733. package/templates/market-monitor/evals/no-repeats/graders/schema.md +5 -0
  734. package/templates/market-monitor/evals/no-repeats/prompt.md +30 -0
  735. package/templates/market-monitor/evals/nothing-changed/case.yaml +4 -0
  736. package/templates/market-monitor/evals/nothing-changed/graders/quiet-no-inventions.md +20 -0
  737. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +5 -0
  738. package/templates/market-monitor/evals/nothing-changed/prompt.md +44 -0
  739. package/templates/market-monitor/evals/post-happens/case.yaml +11 -0
  740. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +31 -0
  741. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +18 -0
  742. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +10 -0
  743. package/templates/market-monitor/evals/post-happens/graders/schema.md +5 -0
  744. package/templates/market-monitor/evals/post-happens/prompt.md +20 -0
  745. package/templates/market-monitor/evals/pricing-change/case.yaml +4 -0
  746. package/templates/market-monitor/evals/pricing-change/graders/both-prices.md +5 -0
  747. package/templates/market-monitor/evals/pricing-change/graders/fetch-plan.md +16 -0
  748. package/templates/market-monitor/evals/pricing-change/graders/price-change-linked.md +20 -0
  749. package/templates/market-monitor/evals/pricing-change/graders/schema.md +5 -0
  750. package/templates/market-monitor/evals/pricing-change/prompt.md +31 -0
  751. package/templates/market-monitor/evals/pricing-moved/case.yaml +4 -0
  752. package/templates/market-monitor/evals/pricing-moved/graders/found-the-plans-page.md +16 -0
  753. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +5 -0
  754. package/templates/market-monitor/evals/pricing-moved/prompt.md +29 -0
  755. package/templates/market-monitor/rules/MONITOR.md +33 -0
  756. package/templates/market-monitor/skills/monitor/SKILL.md +190 -0
  757. package/templates/release-notes/agent.md +47 -0
  758. package/templates/release-notes/evals/draft-not-publish/case.yaml +22 -0
  759. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +915 -0
  760. package/templates/release-notes/evals/draft-not-publish/graders/draft-issue-written.md +9 -0
  761. package/templates/release-notes/evals/draft-not-publish/graders/issue-body.md +15 -0
  762. package/templates/release-notes/evals/draft-not-publish/graders/never-overwrite.md +8 -0
  763. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +5 -0
  764. package/templates/release-notes/evals/draft-not-publish/prompt.md +32 -0
  765. package/templates/release-notes/evals/every-pr-accounted/case.yaml +3 -0
  766. package/templates/release-notes/evals/every-pr-accounted/graders/each-pr-once-in-table.md +8 -0
  767. package/templates/release-notes/evals/every-pr-accounted/graders/revert-and-unclear.md +14 -0
  768. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +5 -0
  769. package/templates/release-notes/evals/every-pr-accounted/prompt.md +107 -0
  770. package/templates/release-notes/evals/issue-write-refused/case.yaml +22 -0
  771. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +902 -0
  772. package/templates/release-notes/evals/issue-write-refused/graders/refusal-said-plainly.md +19 -0
  773. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +5 -0
  774. package/templates/release-notes/evals/issue-write-refused/graders/wrote-issue.md +6 -0
  775. package/templates/release-notes/evals/issue-write-refused/prompt.md +32 -0
  776. package/templates/release-notes/evals/late-arrival/case.yaml +21 -0
  777. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +866 -0
  778. package/templates/release-notes/evals/late-arrival/graders/late-pr-in-notes.md +14 -0
  779. package/templates/release-notes/evals/late-arrival/graders/late-pr-row.md +7 -0
  780. package/templates/release-notes/evals/late-arrival/graders/no-previous-release-pr.md +7 -0
  781. package/templates/release-notes/evals/late-arrival/graders/schema.md +5 -0
  782. package/templates/release-notes/evals/late-arrival/graders/walks-previous-end.md +8 -0
  783. package/templates/release-notes/evals/late-arrival/prompt.md +6 -0
  784. package/templates/release-notes/evals/learned-style/case.yaml +8 -0
  785. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +1 -0
  786. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +13 -0
  787. package/templates/release-notes/evals/learned-style/graders/no-bot.md +8 -0
  788. package/templates/release-notes/evals/learned-style/graders/same-changes.md +10 -0
  789. package/templates/release-notes/evals/learned-style/graders/schema.md +5 -0
  790. package/templates/release-notes/evals/learned-style/prompt.md +71 -0
  791. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +3 -0
  792. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-hash-number-on-top.md +8 -0
  793. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-pr-link-on-top.md +7 -0
  794. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +5 -0
  795. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/table-heading.md +7 -0
  796. package/templates/release-notes/evals/no-pr-numbers-on-top/prompt.md +62 -0
  797. package/templates/release-notes/evals/upgrade-line/case.yaml +5 -0
  798. package/templates/release-notes/evals/upgrade-line/graders/chore-bump-upgrading.md +16 -0
  799. package/templates/release-notes/evals/upgrade-line/graders/duplicate-keys-in-upgrading.md +8 -0
  800. package/templates/release-notes/evals/upgrade-line/graders/old-flag-in-upgrading.md +7 -0
  801. package/templates/release-notes/evals/upgrade-line/graders/schema.md +5 -0
  802. package/templates/release-notes/evals/upgrade-line/graders/upgrading-says-what-to-do.md +14 -0
  803. package/templates/release-notes/evals/upgrade-line/prompt.md +78 -0
  804. package/templates/release-notes/evals/user-facing-only/case.yaml +4 -0
  805. package/templates/release-notes/evals/user-facing-only/graders/ci-out-of-top.md +14 -0
  806. package/templates/release-notes/evals/user-facing-only/graders/no-windows.md +8 -0
  807. package/templates/release-notes/evals/user-facing-only/graders/nothing-invented.md +13 -0
  808. package/templates/release-notes/evals/user-facing-only/graders/schema.md +5 -0
  809. package/templates/release-notes/evals/user-facing-only/prompt.md +113 -0
  810. package/templates/release-notes/notes.schema.json +145 -0
  811. package/templates/release-notes/rules/STYLE.md +47 -0
  812. package/templates/release-notes/skills/release-notes/SKILL.md +311 -0
  813. package/dist/console/assets/index-34jfpIbQ.js +0 -481
  814. package/dist/console/assets/index-DUHbWcIP.css +0 -1
  815. package/dist/trigger-secrets.d.ts +0 -32
  816. package/dist/trigger-secrets.js +0 -143
package/dist/tool-gate.js CHANGED
@@ -4,6 +4,11 @@
4
4
  // tools (app.ts), the kernel's host tools on claude-agent and codex (host-tools.ts), and the MCP gateway, which takes
5
5
  // the same park (harness-app.ts) and registers an executor for its approved calls.
6
6
  //
7
+ // An MCP tool's setting may also carry a pin (pinRefusal): top-level arguments its calls must carry, each a JSON scalar
8
+ // or one of a list. A pin adds to a setting and is never a permission: the gate checks it after a deny and before an
9
+ // allow or an ask, so an allowed call not as pinned is refused unsent, and one under ask is refused before anyone is
10
+ // asked; an approved call is checked again before it runs. The agent's pin and the server's both hold.
11
+ //
7
12
  // An ask has one way to wait, every tool's alike (the owner's ruling of 11-04): it PARKS. The gated call answers at once
8
13
  // with waitingText and the turn ends, as ask_person's does; the run goes needs_input with the pending approval. On an
9
14
  // answer the gate runs the approved call itself (exactly once, through the journaled path: the kernel's host tool; an
@@ -32,18 +37,24 @@
32
37
  // - A stop that lands between the read after the call and resume()'s commit can start the resume turn on a stopped
33
38
  // run: a stop, unlike a cancel, leaves no mark the resume is held to.
34
39
  import { createHash } from "node:crypto";
35
- import { readFileSync } from "node:fs";
36
- import { join, posix, resolve, sep } from "node:path";
40
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
41
+ import { join } from "node:path";
37
42
  import { defineExtension, ROOT_CONVERSATION_ID, wrapTool } from "@earendil-works/pi-durable";
38
- import { EffectFailure, INTERRUPTED_TEXT, openDrive } from "@parcha/agentrun-kernel/kernel";
43
+ import { DESKTOP_TOOL_DEFS, EffectFailure, INTERRUPTED_TEXT, openDrive, PHONE_TOOL_DEFS } from "@parcha/agentrun-kernel/kernel";
39
44
  import { boundResult } from "@parcha/agentrun-kernel/process";
40
- import { readJson, RUN_META } from "./files.js";
45
+ import { READ_SKILL_FILE } from "@parcha/agentrun-kernel";
46
+ import { BARRIER, MESSAGE_ORIGIN_KIND, syncNow } from "@parcha/pi-durable-disk";
47
+ import { dataOfRun, readJson, RUN_META } from "./files.js";
41
48
  import { LEARNED_DIR } from "./learning.js";
42
- import { BOX_WORK } from "./place.js";
49
+ import { COMPUTER_ROOT, portPath } from "./workspace/paths.js";
43
50
  import { forModel } from "./result.js";
51
+ import { builtinHarness } from "./harness-table.js";
52
+ import { DEFAULT_HARNESS } from "./harness.js";
44
53
  import { durableSessions } from "./sessions.js";
45
54
  import { SHELL_TOOLS } from "./background.js";
46
- import { LEGACY_NAMES, readToolSettings, SERVE_OWN_TOOLS, TABLE_TOOLS } from "./tool-plane.js";
55
+ import { readToolSettings, SERVE_OWN_TOOLS, TABLE_TOOLS } from "./tool-plane.js";
56
+ import { deniedText, modelNodeAskText, NOT_RUN, RAN_UNKNOWN, refusedText } from "./refusal-words.js";
57
+ import { approvalsOf } from "./approvals.js";
47
58
  /** What the gate does with a tool's calls. */
48
59
  export const PERMISSIONS = ["allow", "ask", "deny"];
49
60
  /** An MCP tool's gate name: `mcp:<server>/<tool>`. */
@@ -55,14 +66,21 @@ export const isCatalogTool = (name) => name.startsWith("monid.") || isMcpTool(na
55
66
  /** The owner's defaults (11-01): a built-in kernel tool allow; a third-party catalog tool ask. */
56
67
  export const defaultPermission = (name) => (isCatalogTool(name) ? "ask" : "allow");
57
68
  /** The tools that run a command in the run's box (background.ts SHELL_TOOLS), each held to bash's setting: bash: deny
58
- * refuses bash_background as it refuses bash, and none of them is a settings key of its own. */
69
+ * refuses bash_background as it refuses bash, and none of them is a settings key of its own. Under bash: ask the
70
+ * watchers (SHELL_WATCHERS) run unasked. */
59
71
  export const SHELL_FAMILY = Object.freeze(Object.fromEntries(SHELL_TOOLS.map((name) => [name, "bash"])));
60
72
  /** The shell tool a call named `name` is, under claude-agent's host-tool name too (`mcp__hands__bash_background`), when
61
73
  * it is one held to another's setting: its own name, which its request, its refusal and its approved call keep. */
62
- const shellToolOf = (name) => {
74
+ export const shellToolOf = (name) => {
63
75
  const own = name.replace(/^mcp__hands__/, "");
64
76
  return Object.hasOwn(SHELL_FAMILY, own) && SHELL_FAMILY[own] !== own ? own : undefined;
65
77
  };
78
+ /** The shell tools that only watch or end a process the run already started, by its own id (background.ts: an id is
79
+ * digits under the run's own work/background/, and another's is "no background process"): under bash: ask they run
80
+ * unasked, so watching an approved process costs no approval per page. bash: deny still refuses them. */
81
+ export const SHELL_WATCHERS = new Set(["bash_output", "bash_list", "bash_signal"]);
82
+ /** Shell tool `name`'s permission, given bash's: a watcher's ask is allow; any other keeps bash's. */
83
+ const shellPermission = (name, bash) => (bash === "ask" && SHELL_WATCHERS.has(name) ? "allow" : bash);
66
84
  /** The settings keys that may set `name`'s permission, most specific first: the tool's own name, then, for an MCP
67
85
  * tool, its server's wildcard `mcp:<server>/*`. */
68
86
  export function permissionKeys(name) {
@@ -73,30 +91,47 @@ export function permissionKeys(name) {
73
91
  /** The browser's registrations on pi (pi-browser's BROWSER_TOOL_NAMES, which a test holds this list to): each is a call
74
92
  * of the table's `browser`. */
75
93
  const BROWSER_REGISTRATIONS = ["snapshot", "run", "screenshot", "browser_read", "browser_release", "browser_relaunch", "browser_request_handoff", "browser_downloads", "browser_upload"];
76
- /** A CLI's own tools, by harness, and the table's tool each one is. */
77
- const NATIVE_TOOLS = {
78
- "claude-agent": { WebSearch: "web_search", WebFetch: "web_fetch", Bash: "bash", Read: "read", Write: "write", Edit: "edit" },
79
- codex: { web_search: "web_search", shell: "bash" },
80
- };
94
+ /** A computer kind's tools, by name, to the one settings key their kind is held to (`desktop`, `phone`): the kernel
95
+ * registry's own definitions say it (their settingsKey), so a tool a kind gains is held to its key with no line here. */
96
+ const KIND_TOOLS = (() => {
97
+ const keys = new Map();
98
+ for (const def of [...DESKTOP_TOOL_DEFS, ...PHONE_TOOL_DEFS])
99
+ keys.set(def.name, [...new Set([...(keys.get(def.name) ?? []), def.settingsKey])]);
100
+ return keys;
101
+ })();
102
+ const STRICTNESS = { allow: 0, ask: 1, deny: 2 };
81
103
  /** The MCP server through which claude-agent calls the kernel's host tools (`mcp__hands__<wire name>`). */
82
104
  const HOST_TOOLS_SERVER = "hands";
83
105
  /** The settings key a call named `name` on `harness` is held to: the one mapping from every name a call reaches the gate
84
106
  * by. A settings key is itself (a table tool, `monid.<tool>`, `mcp:<server>/<tool>`); a CLI's own tool is the table's it
85
107
  * is; an MCP alias, `mcp__<server>__<tool>` (claude-agent's host tools `mcp__hands__<wire name>`, mapped as their
86
- * wire name) and on OpenCode `<server>_<tool>`, is `mcp:<server>/<tool>`; a catalog's wire name (`monid_run`) is its
87
- * catalog name; the browser's registrations are `browser`. OpenCode's `<server>_<tool>` maps only for a server of
108
+ * wire name) and a harness's own (its facts' toolAlias: OpenCode's `<server>_<tool>`), is `mcp:<server>/<tool>`; a catalog's wire name (`monid_run`) is its
109
+ * catalog name; the browser's registrations are `browser`; an adapter's read_skill_file is `read` (but an agent's MCP tool of that name is its own). OpenCode's `<server>_<tool>` maps only for a server of
88
110
  * `mcpServers` (the run's configured MCP servers), never by its shape, since a host tool's name has the same shape.
89
- * Undefined: nothing maps it, and the gate asks. The key only: an MCP call enters the gate once, in the MCP gateway. */
111
+ * Undefined: nothing maps it, and the gate asks. The key only: an MCP call enters the gate once, in the MCP gateway for a
112
+ * registration it marks (GATED_BY_GATEWAY), else where its tool is wrapped. */
90
113
  export function settingsKeyOf(harness, name, mcpServers = []) {
91
- // A legacy name the tool plane folds into a capability (fetch_page into web_fetch) is held to that capability's key,
92
- // and a tool that runs a command in the box (bash_background and the rest) to bash's: before the table's own names.
93
- if (Object.hasOwn(LEGACY_NAMES, name))
94
- return LEGACY_NAMES[name];
114
+ // A tool that runs a command in the box (bash_background and the rest) is held to bash's key: before the table's own names.
95
115
  if (Object.hasOwn(SHELL_FAMILY, name))
96
116
  return SHELL_FAMILY[name];
97
117
  if (TABLE_TOOLS.includes(name) || SERVE_OWN_TOOLS.includes(name) || isCatalogTool(name))
98
118
  return name;
99
- const native = NATIVE_TOOLS[harness]?.[name];
119
+ // An adapter's own read of a skill's file (codex's and OpenCode's read_skill_file, from the session's copy of the run's
120
+ // skills) is a read: held to read's key, so a server's read deny refuses it and the default allows it, on every harness.
121
+ // Unless the name is an agent's MCP tool on this harness (OpenCode's <server>_<tool>: a configured server `read` with a
122
+ // tool `skill_file`): that tool keeps its own key, so read's setting never stands in for it.
123
+ if (name === READ_SKILL_FILE) {
124
+ const alias = builtinHarness(harness)?.facts?.toolAlias?.exec(name) ?? null;
125
+ return alias && mcpServers.includes(alias[1]) ? mcpToolName(alias[1], alias[2]) : "read";
126
+ }
127
+ // A desktop's or a phone's tool is its kind's key, as the browser's registrations are `browser`; one both kinds have
128
+ // (the hand-over) is named by the first, its permission the stricter of both (RunGate's setting).
129
+ const kind = KIND_TOOLS.get(name);
130
+ if (kind !== undefined)
131
+ return kind[0];
132
+ // A CLI's own tool, the table's tool it is (its facts' nativeTools), by an own name only.
133
+ const nativeTools = builtinHarness(harness)?.facts?.nativeTools;
134
+ const native = nativeTools && Object.hasOwn(nativeTools, name) ? nativeTools[name] : undefined;
100
135
  if (native)
101
136
  return native;
102
137
  const mcp = /^mcp__([a-z][a-z0-9-]*)__(.+)$/.exec(name);
@@ -107,39 +142,159 @@ export function settingsKeyOf(harness, name, mcpServers = []) {
107
142
  return `monid.${monid[1]}`;
108
143
  if (BROWSER_REGISTRATIONS.includes(name))
109
144
  return "browser";
110
- const alias = harness === "opencode" ? /^([a-z][a-z0-9-]*)_(.+)$/.exec(name) : null;
145
+ // A harness whose client names a session's MCP tool another way too (its facts' toolAlias: OpenCode's `<server>_<tool>`).
146
+ const alias = builtinHarness(harness)?.facts?.toolAlias?.exec(name) ?? null;
111
147
  return alias && mcpServers.includes(alias[1]) ? mcpToolName(alias[1], alias[2]) : undefined;
112
148
  }
113
- /** `name`'s permission in force and the layer it came from, most specific first: the agent's exact key, the agent's
114
- * server wildcard, the server's exact key, the server's server wildcard, then the default. Rules over a call's
115
- * arguments are not in V1. */
116
- export function permissionFrom(name, server, agent = {}) {
117
- // A shell tool's permission is bash's (SHELL_FAMILY), wherever it is read: the gate, capabilities, an agent's tools.
118
- if (Object.hasOwn(SHELL_FAMILY, name) && SHELL_FAMILY[name] !== name)
119
- return permissionFrom(SHELL_FAMILY[name], server, agent);
149
+ /** The most arguments one setting pins, and the most values a one-of list holds. */
150
+ export const MAX_PIN_ARGS = 8;
151
+ export const MAX_PIN_CHOICES = 16;
152
+ /** A one-of list in its one form: each value once, null first, then by its JSON text; any other value as it is. The
153
+ * same meaning is the same text (a revision's id) and the same words (a refusal). */
154
+ export const canonicalChoices = (value) => {
155
+ if (!Array.isArray(value))
156
+ return value;
157
+ const texts = [...new Set(value.filter((one) => one !== null).map((one) => JSON.stringify(one)))].sort();
158
+ return [...(value.includes(null) ? [null] : []), ...texts.map((text) => JSON.parse(text))];
159
+ };
160
+ /** `pin` in its one form: its arguments sorted, each one-of list in its form (canonicalChoices). */
161
+ export const canonicalPin = (pin) => Object.fromEntries(Object.keys(pin).sort().map((arg) => [arg, canonicalChoices(pin[arg])]));
162
+ /** Whether a call's argument `given` is the pinned scalar `one`: the same JSON scalar (strict equality), or, for null,
163
+ * left out or null. */
164
+ const isOne = (given, one) => (one === null ? given === undefined || given === null : given === one);
165
+ /** Whether `given` holds pinned `value`: its scalar, or one of its list. */
166
+ const holds = (given, value) => (Array.isArray(value) ? value.some((one) => isOne(given, one)) : isOne(given, value));
167
+ /** A scalar in a refusal's words: text as it is, null as `absent`, any other as JSON. */
168
+ const scalarWords = (one) => (one === null ? "absent" : typeof one === "string" ? one : JSON.stringify(one));
169
+ /** A pin in words, as the refusal says it, in its one form (canonicalPin): `channel_id = C0123`, `cc absent` for a null,
170
+ * `event in (absent | COMMENT)` for a list. */
171
+ export const pinWords = (pin) => Object.entries(canonicalPin(pin)).map(([arg, value]) => (Array.isArray(value) ? `${arg} in (${value.map(scalarWords).join(" | ")})` : value === null ? `${arg} absent` : `${arg} = ${scalarWords(value)}`)).join(", ");
172
+ /** What holds both of two layers' pins of one argument (`own`, the agent's, and `theirs`, the server's): a scalar where
173
+ * either is one and the other holds it, else the agent's list kept to the server's, in the agent's order; undefined when
174
+ * nothing holds both. */
175
+ function bothOf(own, theirs) {
176
+ const list = (value) => (Array.isArray(value) ? value : [value]);
177
+ if (!Array.isArray(own))
178
+ return list(theirs).some((one) => one === own) ? own : undefined;
179
+ if (!Array.isArray(theirs))
180
+ return own.some((one) => one === theirs) ? theirs : undefined;
181
+ const kept = own.filter((one) => theirs.some((other) => other === one));
182
+ return kept.length ? kept : undefined;
183
+ }
184
+ /** Why the call of MCP tool `name` with `args` is refused by a pin, or undefined when no pin refuses it. A pin is an
185
+ * addition to a setting, never a permission: each layer's pin on the tool's own key holds (the agent's and the
186
+ * server's both, whatever the permission), and a call must carry every pinned argument as pinned: its value, or one of
187
+ * its list. An argument both layers pin takes what holds both; where nothing does, every call is refused. `ran`: whether an earlier attempt of
188
+ * the call may have been sent (deniedText's). `mismatched`: the arguments that do not hold, for the gate's log line. */
189
+ export function pinRefusal(name, args, server, agent = {}, ran = "no") {
190
+ if (!isMcpTool(name))
191
+ return undefined;
192
+ const what = ran === "no" ? NOT_RUN : RAN_UNKNOWN;
193
+ if (server[name]?.brokenPin)
194
+ return { text: `${name} can't be called: its pin in this server's tool settings does not read, so no call is let through until the owner sets it again (Settings → Tools). ${what}`, mismatched: [] };
195
+ const own = agent[name]?.pin ?? {};
196
+ const theirs = server[name]?.pin ?? {};
197
+ // Both layers hold: an argument both pin takes what holds both (bothOf), and one where nothing does refuses every call.
198
+ const clash = Object.keys(own).filter((arg) => Object.hasOwn(theirs, arg) && bothOf(own[arg], theirs[arg]) === undefined);
199
+ if (clash.length)
200
+ return { text: `${name} can't be called: this agent's settings fix ${pinWords(Object.fromEntries(clash.map((arg) => [arg, own[arg]])))} and this server's fix ${pinWords(Object.fromEntries(clash.map((arg) => [arg, theirs[arg]])))}, so no call can satisfy both. ${what} Don't retry it: the owner makes the two agree.`, mismatched: clash };
201
+ const pin = { ...theirs, ...Object.fromEntries(Object.entries(own).map(([arg, value]) => [arg, Object.hasOwn(theirs, arg) ? bothOf(value, theirs[arg]) : value])) };
202
+ const given = typeof args === "object" && args !== null && !Array.isArray(args) ? args : {};
203
+ const mismatched = Object.keys(pin).filter((arg) => !holds(Object.hasOwn(given, arg) ? given[arg] : undefined, pin[arg]));
204
+ if (!mismatched.length)
205
+ return undefined;
206
+ const by = Object.keys(own).length && Object.keys(theirs).length ? "the agent's and this server's settings" : Object.keys(own).length ? "the agent's settings" : "this server's settings";
207
+ return { text: `${name} may only be called with ${pinWords(pin)}: its destination is fixed by ${by}. ${what}`, mismatched };
208
+ }
209
+ /** `name`'s permission in force and the layer it came from. A deny set on this server, under the tool's own key or its MCP
210
+ * server's wildcard (bash's for a shell tool), is absolute: it refuses on this server over any setting of the agent's.
211
+ * Otherwise most specific first: the agent's exact key, the agent's server wildcard, the server's exact key, the
212
+ * server's server wildcard, then the default. A call's arguments are held only by a pin (pinRefusal), which adds to a
213
+ * setting and is never a permission. `approvals` "never" (an agent run unattended) turns the ask that is left into an allow, from
214
+ * "unattended", as the last step, and only where nothing stands behind that ask (standsBehind): never past a deny in any
215
+ * layer, nor an ask that stands in for a setting that does not read. Nor is anything RunGate.enter refuses before it
216
+ * decides between running and parking ever lifted (a template's pin, among them). Without never, the answer is as it
217
+ * always was. */
218
+ export function permissionFrom(name, server, agent = {}, approvals = "ask") {
219
+ const { permission, from } = settingOf(name, server, agent);
220
+ if (approvals !== "never" || permission !== "ask" || standsBehind(name, server, agent))
221
+ return { permission, from };
222
+ return { permission: "allow", from: "unattended" };
223
+ }
224
+ /** Marks the server's settings map when its file is present but does not read (tool-plane.ts ToolSettings.get): every
225
+ * tool then takes its defaults, and the deny the file may hold can't be seen, so nothing lifts an ask over it. A symbol:
226
+ * carried by a spread, never by JSON (it is never served) nor by Object.entries (no reader takes it for a tool). */
227
+ export const SETTINGS_UNREAD = Symbol("agentrun.tool-settings.unread");
228
+ /** `settings` marked unread (SETTINGS_UNREAD), a copy: what a gate holds to while its settings' read fails, its last good
229
+ * read's denies and pins still refusing and no ask lifted. */
230
+ const unreadOf = (settings) => Object.assign({ ...settings }, { [SETTINGS_UNREAD]: true });
231
+ /** Whether something stands behind `name`'s ask that approvals "never" must not lift: the server's settings unread
232
+ * (SETTINGS_UNREAD: a deny may be in the file), or in either layer, under any key the tool is read by (its own, its MCP
233
+ * server's wildcard; a shell tool's, bash's), a deny, a value that is no permission, or a setting marked as not read as
234
+ * written (`fallback`). The ask a layer above gives does not hide a deny below it. */
235
+ function standsBehind(name, server, agent) {
236
+ if (server[SETTINGS_UNREAD] === true)
237
+ return true;
238
+ const held = Object.hasOwn(SHELL_FAMILY, name) ? SHELL_FAMILY[name] : name;
239
+ return [agent, server].some((layer) => permissionKeys(held).some((key) => {
240
+ const setting = layer[key];
241
+ if (setting?.permission === undefined)
242
+ return false;
243
+ return setting.permission === "deny" || setting.fallback === true || !PERMISSIONS.includes(setting.permission);
244
+ }));
245
+ }
246
+ /** permissionFrom before approvals: what the layers and the default say. */
247
+ function settingOf(name, server, agent) {
248
+ // A shell tool's permission is bash's (SHELL_FAMILY), from bash's layer, wherever it is read: the gate, capabilities, an
249
+ // agent's tools. A watcher (SHELL_WATCHERS) runs unasked only under an ask set as written in a layer: an ask that stands
250
+ // in for anything else (a value not offered, nothing set) stays an ask. No key of its own is read, so none lifts bash's.
251
+ if (Object.hasOwn(SHELL_FAMILY, name) && SHELL_FAMILY[name] !== name) {
252
+ const bash = settingFrom(SHELL_FAMILY[name], server, agent);
253
+ return { permission: bash.written ? shellPermission(name, bash.permission) : bash.permission, from: bash.from };
254
+ }
255
+ const { permission, from } = settingFrom(name, server, agent);
256
+ return { permission, from };
257
+ }
258
+ /** permissionFrom's own read, and whether the permission is `written`: a valid one set in a layer as it reads there, not
259
+ * a stand-in. A value that is no permission at all reads ask, never the value. A deny set on this server is absolute:
260
+ * where the server's own answer for the tool (its most specific key set there: the tool's own, else its MCP server's
261
+ * wildcard) is deny, that is the answer, from the server, before the agent's own settings are read, so no ask or allow
262
+ * of the agent's reaches past it. The server's own exact allow under its wildcard deny is its answer, as before.
263
+ * Otherwise the agent's own setting comes first, then the server's, then the default. */
264
+ function settingFrom(name, server, agent) {
265
+ const own = permissionKeys(name).map((key) => server[key]).find((setting) => setting?.permission !== undefined);
266
+ if (own?.permission === "deny")
267
+ return { permission: "deny", from: "server", written: own.fallback !== true };
120
268
  for (const [from, layer] of [["agent", agent], ["server", server]]) {
121
269
  for (const key of permissionKeys(name)) {
122
- const set = layer[key]?.permission;
123
- if (set)
124
- return { permission: set, from };
270
+ const setting = layer[key];
271
+ const set = setting?.permission;
272
+ if (!set)
273
+ continue;
274
+ if (!PERMISSIONS.includes(set))
275
+ return { permission: "ask", from, written: false };
276
+ return { permission: set, from, written: setting.fallback !== true };
125
277
  }
126
278
  }
127
- return { permission: defaultPermission(name), from: "default" };
279
+ return { permission: defaultPermission(name), from: "default", written: false };
128
280
  }
129
281
  /** `name`'s permission in force (permissionFrom): the one rule every path reads, the gate's, the tool plane's and a
130
282
  * workflow's call nodes'. */
131
- export const permissionOf = (name, server, agent = {}) => permissionFrom(name, server, agent).permission;
132
- /** The refusal of a call whose tool is set to deny; of one held to another tool's setting (`heldTo`, a shell tool's
133
- * bash), naming the setting to change. */
134
- export const deniedText = (tool, heldTo) => heldTo && heldTo !== tool ? `Permission denied: ${tool} follows ${heldTo}'s setting, which is deny on this server. Don't retry it.` : `Permission denied: ${tool} is set to deny on this server. Don't retry it.`;
283
+ export const permissionOf = (name, server, agent = {}, approvals = "ask") => permissionFrom(name, server, agent, approvals).permission;
284
+ /** The mark a tool registration carries when its calls are gated by whoever registered it (the MCP gateway, which marks
285
+ * its registrations only when it holds this run's gate and park, and enters the gate in each call): RunGate.extension
286
+ * does not wrap it again. A private symbol, never `Symbol.for`: a global-registry key could be recreated by any code
287
+ * with the string alone. Only code that imports this export can set it (mcp-gateway.ts does). */
288
+ export const GATED_BY_GATEWAY = Symbol("agentrun.gatedByGateway");
289
+ // The refusal words (SettingFrom, DenyFrom, NOT_RUN, RAN_UNKNOWN, denyPlace, deniedText, refusedText) live in
290
+ // refusal-words.ts, shared with the runner's loops.
291
+ export { deniedText, denyPlace, NOT_RUN, RAN_UNKNOWN, refusedText } from "./refusal-words.js";
135
292
  /** The refusal of an ask where no one can approve it: a server with accounts off, whose answer route takes no token. */
136
- export const noApproverText = (tool) => `Permission denied: ${tool} needs the owner's approval, and this server has accounts off (AGENTRUN_ACCOUNTS=0), so no one can give it: set the tool to allow or deny in the agent's Tools.`;
293
+ export const noApproverText = (tool, ran = "no") => `Permission denied: ${tool} needs the owner's approval, and this server has accounts off (AGENTRUN_ACCOUNTS=0), so no one can give it: set the tool to allow or deny in the agent's Tools. ${ran === "no" ? NOT_RUN : RAN_UNKNOWN}`;
137
294
  /** Set by the server in a run's environment when no one can approve here (accounts off): the gate refuses each ask. */
138
295
  export const NO_APPROVER_ENV = "AGENTRUN_SERVE_NO_APPROVER";
139
296
  /** A parked call's answer: the run pauses here. */
140
297
  export const waitingText = (tool) => `This ${tool} call waits for a person's approval; the run pauses here and continues with the result when they answer.`;
141
- /** A call a person denied, with their reason when they gave one. */
142
- export const refusedText = (tool, note) => `The user denied this ${tool} call.${note ? ` Reason: ${note}` : ""}`;
143
298
  /** The Timeline row of a call that waits for an approval. */
144
299
  export const APPROVAL_ROW = "tool_approval_requested";
145
300
  /** A call's arguments shown on its approval, at most this many bytes. */
@@ -173,18 +328,27 @@ export const TURN_ORIGIN_FILE = "turn-origin.json";
173
328
  /** The run's store's record of a call that waits for approval (`phase: "requested"`), and of its answer acted on
174
329
  * (`phase: "resolved"`), on its root conversation. */
175
330
  export const APPROVAL_ENTRY = "agentrun.tool_approval";
331
+ /** The run's store's record that the gate let a replay-safe pi call that can bill through (`{ callId }`), written before
332
+ * the tool runs. pi-durable reruns a cut replay-safe call with the same call id and no sign that it is a rerun: this mark
333
+ * is how the gate knows an earlier attempt may have been sent, so a deny of the rerun never says nothing was charged.
334
+ * Outside `agentrun.tool_`, the tool ledger's kinds (paid-calls.ts), which readers of a run's charges take by prefix. */
335
+ export const GATE_PASSED_ENTRY = "agentrun.gate_passed";
336
+ /** The replay-safe tools, by settings key, whose call can be charged (a provider's fee: Parallel's search or extract): the
337
+ * only ones the gate marks, so the root conversation does not grow by a mark per free call (read, the shell watchers,
338
+ * monid's discover and inspect), whose earlier attempt charged nothing. monid.run is never rerun (host-tools.ts REPLAY). */
339
+ const BILLED_REPLAYS = new Set(["web_fetch", "web_search"]);
176
340
  /** The refusal of the end-of-run turn's write or edit under work/.learning/: its notes are kept only from its answer's
177
341
  * note blocks (learn/reflect.ts parseReflection), which the host merges in its own store; a file there is never kept. */
178
342
  export const NOTE_ONLY_TEXT = "A note is kept only from your answer: write it in a ```note block, not to a file.";
179
- /** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then lexically),
180
- * names work/.learning/ or a path under it: by this machine's `work` or the box's (BOX_WORK). */
343
+ /** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then the port's
344
+ * path of it, portPath), names .learning/ in the run's folder or a path under it: by the folder's path here (`work`)
345
+ * or a computer's name for it (COMPUTER_ROOT). */
181
346
  export function underLearning(work, args) {
182
347
  const path = args?.path;
183
348
  if (typeof path !== "string")
184
349
  return false;
185
350
  const plain = path.replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, " ").replace(/^@/, "");
186
- const under = (base, at) => at === join(base, LEARNED_DIR) || at.startsWith(`${join(base, LEARNED_DIR)}${sep}`);
187
- return under(resolve(work), resolve(work, plain)) || under(BOX_WORK, posix.resolve(BOX_WORK, plain));
351
+ return portPath(plain, [work, COMPUTER_ROOT])?.split("/")[0] === LEARNED_DIR;
188
352
  }
189
353
  /** `text` cut to at most ARGS_PREVIEW_BYTES. What is shown of a call's arguments is the whole of them redacted first, then
190
354
  * cut (runs.ts), so a cut never leaves the head of a key no redaction recognizes. */
@@ -198,16 +362,25 @@ export const argsPreview = (args) => previewOf(JSON.stringify(args ?? {}) ?? "")
198
362
  export const RESUME_PREFIX = "[tool approval] ";
199
363
  /** The one message that resumes a session once a person answered: it names the call it answers (its tool, call id and
200
364
  * arguments), so the model tells it from a person's new input, and carries the call's result, or the refusal. */
201
- export function resumeText(request, shown, decision, result) {
202
- // `shown`: the arguments as the server shows them, redacted whole then cut (runs.ts): never the call's own.
365
+ /** The head of the gate's resume message: the call it answers, its arguments as shown (`shown`, redacted whole then cut,
366
+ * runs.ts) cut again at 300 characters, and the words that say it is not the person's. The one source of it: the resume
367
+ * writes it, and the Timeline strips exactly it from the row a person opens (runs.ts resumeShows). */
368
+ export function resumeHead(request, shown) {
203
369
  const args = shown.length > 300 ? `${shown.slice(0, 299)}…` : shown;
204
- const head = `${RESUME_PREFIX}This answers your ${request.tool} call ${request.call_id} (arguments ${args}), which waited for a person's approval; it is not a new message from them.`;
370
+ return `${RESUME_PREFIX}This answers your ${request.tool} call ${request.call_id} (arguments ${args}), which waited for a person's approval; it is not a new message from them.`;
371
+ }
372
+ export function resumeText(request, shown, decision, result) {
373
+ const head = resumeHead(request, shown);
205
374
  return decision === "allow" ? `${head} They allowed it, and it ran${result.isError ? " and failed" : ""}. Its result:\n${result.text}` : `${head}\n${result.text}`;
206
375
  }
207
376
  /** The gate of the run `runId` at `where` (its directory, under the data directory's runs/), on its pinned revision:
208
- * an agentic run's parks an asked call; a workflow's model node cannot. */
209
- export function runGate(where, runId, revision) {
210
- return new RunGate({ root: where.root, work: where.work, data: resolve(where.root, "..", ".."), runId, harness: revision.body.harness ?? "pi" }, (revision.body.toolSettings ?? {}), revision.kind === "agentic", process.env[NO_APPROVER_ENV] !== "1");
377
+ * an agentic run's parks an asked call; a workflow's model node cannot. `serverSettings`: where the server's tool
378
+ * settings are read from, read at each call as the gate reads them; absent, the file beside the run's data directory (the
379
+ * old per-run process). The runner gives the one store's (tool-plane.ts loadToolSettings), read once at the claim.
380
+ * `approvers`: whether anyone can answer an ask here. The runner gives the store's (server-approvers.ts, read at each
381
+ * claim); absent, the old per-run process's environment says (NO_APPROVER_ENV, set for it by runs.ts). */
382
+ export function runGate(where, runId, revision, serverSettings, files, approvers = process.env[NO_APPROVER_ENV] !== "1") {
383
+ return new RunGate({ root: where.root, work: where.work, data: dataOfRun(where.root), runId, harness: revision.body.harness ?? DEFAULT_HARNESS }, (revision.body.toolSettings ?? {}), revision.kind === "agentic", approvers, approvalsOf(revision.body.approvals), serverSettings, files);
211
384
  }
212
385
  /** The gate in a run's process, park mode: its policy, the turn's origin, the calls that wait, and the answers acted on. */
213
386
  export class RunGate {
@@ -215,45 +388,114 @@ export class RunGate {
215
388
  overrides;
216
389
  parks;
217
390
  approvers;
391
+ approvals;
392
+ readServerSettings;
393
+ files;
218
394
  requests = new Map();
395
+ /** The replay-safe pi calls the gate let through (GATE_PASSED_ENTRY), by call id: a rerun of one is a replay. */
396
+ passed = new Set();
219
397
  durable;
398
+ /** The run's store, for the barrier before a call that is not replay-safe: from `prime` (before the resume) or `load`. */
399
+ syncTarget;
220
400
  context;
221
401
  coding;
222
402
  /** The run's own tools beyond the table (its learned_workflow), on which an approved call of one runs. */
223
403
  extra = [];
224
404
  resume;
405
+ /** Told just before an allowed call runs (harness-app's): the run is un-parked, so the call's own model requests (a
406
+ * learned workflow's node) go out; the harness is idle then, as the park ended its turn. */
407
+ unpark;
225
408
  drive;
226
409
  timer;
227
410
  settling = false;
228
411
  stop = new AbortController();
229
412
  /** `where.data`: the server's data directory, its tool settings beside the store; `overrides`: the pinned revision's
230
413
  * own; `parks`: whether an asked call parks the run (an agentic run's), which a workflow's model node cannot;
231
- * `approvers`: whether anyone can answer an ask here (the owner's password session: accounts on). */
232
- constructor(where, overrides = {}, parks = true, approvers = true) {
414
+ * `approvers`: whether anyone can answer an ask here (the owner's password session: accounts on); `approvals`: the
415
+ * pinned revision's (definition.approvals): "never" runs the agent unattended, an ask allowed (permissionFrom);
416
+ * `files`: where the run's own files are read (RunFiles), the run's folder `where.root` when absent. */
417
+ constructor(where, overrides = {}, parks = true, approvers = true, approvals = "ask", readServerSettings, files = where.root) {
233
418
  this.where = where;
234
419
  this.overrides = overrides;
235
420
  this.parks = parks;
236
421
  this.approvers = approvers;
422
+ this.approvals = approvals;
423
+ this.readServerSettings = readServerSettings;
424
+ this.files = files;
237
425
  }
238
426
  /** A tool's permission now (permissionOf): the revision's own over the server's setting, read at each call, so a change
239
- * reaches a live run at its next call. */
240
- policy = (tool) => {
241
- const key = settingsKeyOf(this.where.harness ?? "pi", tool, this.where.mcpServers);
242
- // A name nothing maps fails closed: it asks (refused where no one can approve), never allows.
427
+ * reaches a live run at its next call; under approvals "never", an ask is an allow. */
428
+ policy = (tool) => this.setting(tool).permission;
429
+ /** The gate's answer for one call before its intent, for a loop that parks and answers asks itself (the runner's adapter
430
+ * loops, pi's and the CLI harnesses'): run it, ask a person, or refuse it with the words the model reads. `enter`'s
431
+ * order: the end-of-run turn's write under .learning/ (learningRefusal), the deny (with where it was set, and that
432
+ * nothing was sent or charged), a pin, then the allow, then the ask, so an allow that approvals "never" made is decided
433
+ * only after every refusal. Where no one can approve (accounts off: the store's approvers row a runner reads at each
434
+ * claim, server-approvers.ts), the ask is refused at once in words, never parked, as `enter` refuses it. */
435
+ async decide(name, args) {
436
+ const key = settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, name, this.where.mcpServers) ?? name;
437
+ const tool = this.askedAs(name);
438
+ const learning = await this.learningRefusal(key, args);
439
+ if (learning)
440
+ return { deny: learning };
441
+ const verdict = this.policy(name);
442
+ if (verdict === "deny")
443
+ return { deny: deniedText(tool, key, this.denyFrom(name), "no") };
444
+ const pinned = this.pinned(key, args, "no");
445
+ if (pinned)
446
+ return { deny: pinned.text };
447
+ if (verdict === "allow")
448
+ return "allow";
449
+ return this.approvers ? "ask" : { deny: noApproverText(tool, "no") };
450
+ }
451
+ /** The name a call is asked about by, as main's request names it (enter's `tool`): its settings key, a shell tool its
452
+ * own name; a name nothing maps, as it came. */
453
+ askedAs(name) {
454
+ return shellToolOf(name) ?? settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, name, this.where.mcpServers) ?? name;
455
+ }
456
+ /** Where the permission `policy` gives `tool` was set: the agent's own tool settings, the server's, or the default; or
457
+ * "unattended", an ask the agent's approvals allowed. */
458
+ denyFrom = (tool) => this.setting(tool).from;
459
+ setting(tool) {
460
+ // A tool the desktop and the phone both have (the hand-over): the gate knows not the run's kind, so it is held to the
461
+ // stricter of both keys' settings, never more permissive than the run's own kind's.
462
+ const shared = KIND_TOOLS.get(tool.replace(/^mcp__hands__/, ""));
463
+ if (shared && shared.length > 1) {
464
+ return shared.map((key) => this.settingOf(tool, key)).reduce((strictest, one) => (STRICTNESS[one.permission] > STRICTNESS[strictest.permission] ? one : strictest));
465
+ }
466
+ return this.settingOf(tool, settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, tool, this.where.mcpServers));
467
+ }
468
+ /** `tool`'s permission under its settings key `key`, and where it was set. */
469
+ settingOf(tool, key) {
470
+ // A name nothing maps fails closed: it asks (refused where no one can approve), never allows, under approvals "never"
471
+ // too: no setting of it was read, so none says it may run.
243
472
  if (key === undefined)
244
- return "ask";
473
+ return { permission: "ask", from: "default" };
245
474
  const server = this.serverSettings();
246
- // No settings ever read: every tool asks, or keeps the revision's own deny.
247
- if (server === undefined)
248
- return permissionOf(key, {}, this.overrides) === "deny" ? "deny" : "ask";
249
- return permissionOf(key, server, this.overrides);
250
- };
475
+ // No settings ever read: every tool asks, the shell watchers too (fail closed: an ask nothing read is never lifted),
476
+ // or keeps the revision's own deny. Approvals "never" lifts none of these asks: the server's settings may hold a deny
477
+ // no read has seen.
478
+ if (server === undefined) {
479
+ const own = permissionFrom(key, {}, this.overrides);
480
+ return own.permission === "deny" ? own : { permission: "ask", from: "default" };
481
+ }
482
+ // A shell tool under every harness's name for it is read as its own name, by bash's key (permissionFrom): a watcher's
483
+ // ask is allow only where bash's ask is set as written.
484
+ return permissionFrom(shellToolOf(tool) ?? key, server, this.overrides, this.approvals);
485
+ }
486
+ /** Why a pin refuses the call of `key` with `args` now (pinRefusal): the revision's own pins and the server's, read at
487
+ * each call as its permission is, so a pin set or changed reaches a live run at its next call. */
488
+ pinned(key, args, ran = "no") {
489
+ return pinRefusal(key, args, this.serverSettings() ?? {}, this.overrides, ran);
490
+ }
251
491
  lastGood;
252
492
  told = new Set();
253
- /** The server's settings now: read at each call, so a change reaches a live run; a file that does not read keeps the
254
- * last good (undefined: none read yet). Each problem is said once, by file and field, never a value. */
493
+ /** The server's settings now: read at each call, so a change reaches a live run; settings that do not read keep the
494
+ * last good, marked unread (SETTINGS_UNREAD): its denies and pins still refuse, and approvals "never" lifts no ask
495
+ * while the read fails, as a deny may be in what did not read (undefined: none read yet, every tool asks). Each problem
496
+ * is said once, by file and field, never a value. */
255
497
  serverSettings() {
256
- const read = readToolSettings(this.where.data);
498
+ const read = this.readServerSettings ? this.readServerSettings() : readToolSettings(this.where.data);
257
499
  for (const line of read.problems) {
258
500
  if (this.told.has(line))
259
501
  continue;
@@ -261,40 +503,65 @@ export class RunGate {
261
503
  process.stderr.write(`agentrun-serve: the tool gate: ${line}\n`);
262
504
  }
263
505
  if (read.unreadable)
264
- return this.lastGood;
506
+ return this.lastGood === undefined ? undefined : unreadOf(this.lastGood);
265
507
  this.lastGood = read.settings;
266
508
  return this.lastGood;
267
509
  }
268
- /** The origin of the turn running now: what the server's internal path wrote for it; none for a person's turn. */
269
- turnOrigin() {
510
+ /** The origin of the turn running now: what the server's internal path wrote for it (TURN_ORIGIN_FILE in the run's
511
+ * folder, read through `files`: the run's Workspace or the local folder's path); none for a person's turn, or a file
512
+ * that is not there or does not read. */
513
+ async turnOrigin() {
270
514
  try {
271
- return JSON.parse(readFileSync(join(this.where.root, TURN_ORIGIN_FILE), "utf8"))?.origin === "reflect" ? "reflect" : undefined;
515
+ const text = typeof this.files === "string" ? readFileSync(join(this.files, TURN_ORIGIN_FILE), "utf8") : new TextDecoder().decode(await this.files.read(TURN_ORIGIN_FILE));
516
+ return JSON.parse(text)?.origin === "reflect" ? "reflect" : undefined;
272
517
  }
273
518
  catch {
274
519
  return undefined;
275
520
  }
276
521
  }
522
+ /** The end-of-run turn's refusal of a write or edit under work/.learning/ (NOTE_ONLY_TEXT, the adapter loop's one text
523
+ * too), whatever the tool's permission: its notes are kept only from its answer. Undefined for any other call or turn,
524
+ * whose write there follows its permission, as anywhere. The first check of `enter` and `decide`. */
525
+ async learningRefusal(key, args) {
526
+ if (key !== "write" && key !== "edit")
527
+ return undefined;
528
+ // The folder's path a file tool resolves against: the local folder's, or a computer's name for it (the Workspace's paths
529
+ // are in the run's folder, so a path there is relative or under COMPUTER_ROOT).
530
+ const work = typeof this.files === "string" ? this.where.work : COMPUTER_ROOT;
531
+ return underLearning(work, args) && (await this.turnOrigin()) === "reflect" ? NOTE_ONLY_TEXT : undefined;
532
+ }
277
533
  /** One model-initiated call at the gate: undefined when it may run; else its answer, refused at once (deny) or parked
278
534
  * (ask). One call waits at a time: another asked meanwhile is answered so, not run. */
279
535
  async enter(name, args, callId, park, options = {}) {
280
536
  // Held to its settings key (settingsKeyOf), the name its request, a refusal and the approved call give; a shell tool
281
537
  // held to bash's (SHELL_FAMILY) keeps its own name, so an approved bash_background runs bash_background, never bash.
282
- const key = settingsKeyOf(this.where.harness ?? "pi", name, this.where.mcpServers) ?? name;
538
+ const key = settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, name, this.where.mcpServers) ?? name;
283
539
  const tool = shellToolOf(name) ?? key;
284
- // The end-of-run turn writes no file under work/.learning/, whatever the tool's permission: its notes are kept only
285
- // from its answer (NOTE_ONLY_TEXT). Any other turn's write there follows its permission, as anywhere.
286
- if ((key === "write" || key === "edit") && this.turnOrigin() === "reflect" && underLearning(this.where.work, args))
287
- return { text: NOTE_ONLY_TEXT, isError: true };
540
+ // The end-of-run turn writes no file under work/.learning/, whatever the tool's permission (learningRefusal).
541
+ const learning = await this.learningRefusal(key, args);
542
+ if (learning)
543
+ return { text: learning, isError: true };
544
+ // Every refusal that does not come from the permission (the reflect turn's above, the deny and a pin's below) stays
545
+ // ABOVE the allow's return further down. An allow here may be an ask the agent's approvals "never" turned into one
546
+ // (permissionFrom's last step), and an allowed call runs at once: nothing after that return refuses it.
288
547
  const verdict = this.policy(name);
548
+ const ran = options.replayed ? "unknown" : "no";
549
+ if (verdict === "deny")
550
+ return { text: deniedText(tool, key, this.denyFrom(name), ran), isError: true };
551
+ // A pinned MCP tool's call whose arguments are not the pinned ones: refused before it runs or asks anyone, so an
552
+ // allowed or approved call goes only where its settings fix.
553
+ const pinned = this.pinned(key, args, ran);
554
+ if (pinned) {
555
+ process.stderr.write(`agentrun-serve: the tool gate refused ${key} call ${callId}: ${pinned.mismatched.length ? `${pinned.mismatched.join(", ")} not as pinned` : "its pin does not read"}\n`);
556
+ return { text: pinned.text, isError: true };
557
+ }
289
558
  if (verdict === "allow")
290
559
  return undefined;
291
- if (verdict === "deny")
292
- return { text: deniedText(tool, key), isError: true };
293
560
  // No one can answer here: refused at once with why, never parked until a cancel.
294
561
  if (!this.approvers)
295
- return { text: noApproverText(tool), isError: true };
562
+ return { text: noApproverText(tool, ran), isError: true };
296
563
  if (!this.parks)
297
- return { text: `This ${tool} call needs a person's approval, which a workflow's model node cannot wait for; it was not run.`, isError: true };
564
+ return { text: modelNodeAskText(tool), isError: true };
298
565
  // Named by the call, so a call run again after a crash parks as the same request.
299
566
  const id = `ap_${createHash("sha256").update(JSON.stringify([callId, tool, args ?? null])).digest("hex").slice(0, 16)}`;
300
567
  const other = [...this.requests.values()].find((held) => !held.resolved && held.id !== id);
@@ -302,7 +569,7 @@ export class RunGate {
302
569
  return { text: `This ${tool} call was not run: the ${other.tool} call ${other.call_id} already waits for a person's approval. Call it again once that one is answered.`, isError: true };
303
570
  if (!this.requests.has(id)) {
304
571
  const turn = park.turn?.();
305
- const request = { id, tool, call_id: callId, args: args ?? null, args_preview: argsPreview(args), requested_at: new Date().toISOString(), ...(turn !== undefined ? { turn } : {}), ...(options.price !== undefined ? { price: options.price } : {}) };
572
+ const request = { id, tool, call_id: callId, args: args ?? null, args_preview: argsPreview(args), requested_at: new Date().toISOString(), ...(turn !== undefined ? { turn } : {}), ...(options.price !== undefined ? { price: options.price } : {}), ...(options.replayed ? { replayed: true } : {}) };
306
573
  // Held before the commit's await, in the tick of the look above: pi runs a turn's calls in parallel, and an ask
307
574
  // entered meanwhile finds this one and is refused. A commit that fails lets it go.
308
575
  this.requests.set(id, request);
@@ -321,32 +588,61 @@ export class RunGate {
321
588
  /** pi's `tools` behind the gate: wraps, by name, for the run's registry, which apply wherever it is selected (every
322
589
  * agent selects it: the root by default, a workflow's model node by name, app.ts). */
323
590
  extension(tools) {
324
- // pi's MCP tools (mcp__<server>__<tool>) are gated by the MCP gateway itself, inside their execute: not wrapped here.
325
- const named = [...new Map(tools.filter((tool) => !tool.name.startsWith("mcp__")).map((tool) => [tool.name, tool])).values()];
591
+ // Every tool is wrapped, an mcp__ name too, except a registration marked GATED_BY_GATEWAY: the MCP gateway marks the
592
+ // ones whose calls it takes to this gate itself (gate.enter in its call), so such a call passes one gate, once. Nothing
593
+ // is skipped by its name: an unmarked mcp__ tool is gated here as any tool is.
594
+ const named = [...new Map(tools.filter((tool) => tool[GATED_BY_GATEWAY] !== true).map((tool) => [tool.name, tool])).values()];
326
595
  return defineExtension({ name: "tool-gate", wraps: named.map((tool) => wrapTool(tool, (inner) => this.wrap(inner))) });
327
596
  }
328
597
  wrap(tool) {
329
598
  const gate = this;
599
+ const billed = tool.replay === "safe" && BILLED_REPLAYS.has(settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, tool.name, this.where.mcpServers) ?? "");
330
600
  return {
331
601
  ...tool,
332
602
  async execute(args, api, context) {
333
- const answer = await gate.enter(tool.name, args, api.callId, { commit: (change) => api.commit(change, context) });
603
+ const commit = (change) => api.commit(change, context);
604
+ // A rerun of a replay-safe call the gate let through before (pi-durable reruns it with the same call id after a
605
+ // crash, with no sign of it): an earlier attempt may have been sent, which the gate's refusal must not deny. The
606
+ // marks were read before the run resumed (prime), so a rerun the resume dispatches finds them.
607
+ const answer = await gate.enter(tool.name, args, api.callId, { commit }, gate.passed.has(api.callId) ? { replayed: true } : {});
334
608
  // A parked call ends the turn, as ask_person's does.
335
609
  if (answer)
336
610
  return forModel(answer.text, answer.parked ? { control: { terminate: true } } : { isError: true });
611
+ // Let through: a call that can bill is marked in the store before the tool runs, so a crash after it leaves a
612
+ // rerun the gate knows for one. A mark that fails to commit stops the call (nothing has been sent).
613
+ if (billed && !gate.passed.has(api.callId)) {
614
+ await commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: GATE_PASSED_ENTRY, data: { callId: api.callId } }));
615
+ gate.passed.add(api.callId);
616
+ }
617
+ // pi-durable committed the call's intent before it reached execute: durable before the call is sent, so a lost
618
+ // box never sends it twice (a resumed call with its intent is reported interrupted, not run again).
619
+ if (tool.replay !== "safe" || billed)
620
+ await syncNow(gate.syncTarget, BARRIER.piToolIntent);
337
621
  return tool.execute(args, api, context);
338
622
  },
339
623
  };
340
624
  }
341
- /** Reads the requests the run's store holds, as the run's process opens, before its turns go on. `coding`: the run's
342
- * coding source (coding-tools.ts), on which an approved coding call runs, as the run's own would; `extra`, the run's
343
- * own tools beyond the table (its learned_workflow), on which an approved call of one runs. */
625
+ /** Takes the open run, as the run's process opens (its app's onOpen), reading what its store holds of the gate unless
626
+ * `prime` read it before the resume. `coding`: the run's coding source (coding-tools.ts), on which an approved coding
627
+ * call runs, as the run's own would; `extra`, the run's own tools beyond the table (its learned_workflow), on which an
628
+ * approved call of one runs. */
344
629
  async load(durable, context, coding, extra = []) {
345
630
  this.durable = durable;
631
+ this.syncTarget = durable.store;
346
632
  this.context = context;
347
633
  this.coding = coding;
348
634
  this.extra = extra;
349
- const root = await durable.harness.conversation(ROOT_CONVERSATION_ID, context);
635
+ if (!this.primed)
636
+ await this.prime(durable.harness, context);
637
+ }
638
+ primed = false;
639
+ /** Reads what the run's store holds of the gate (the calls that wait, the answers acted on, the calls it let through)
640
+ * before the run resumes: its app's beforeResume hook, ahead of harness.resume(), which dispatches the calls a crash
641
+ * cut. Read here, not in onOpen, which a recovered call races. A workflow's run calls only this; load reads nothing more. */
642
+ async prime(harness, context, syncTarget) {
643
+ if (syncTarget)
644
+ this.syncTarget = syncTarget;
645
+ const root = await harness.conversation(ROOT_CONVERSATION_ID, context);
350
646
  for (let cursor; root;) {
351
647
  const page = await root.entries({ order: "ascending" }, 500, cursor, context);
352
648
  for (const entry of page.items)
@@ -355,6 +651,7 @@ export class RunGate {
355
651
  break;
356
652
  cursor = page.next;
357
653
  }
654
+ this.primed = true;
358
655
  }
359
656
  /** Whether a call waits for its answer, or for its answer to be acted on: a harness keeps the turn it ended closed. */
360
657
  waiting() {
@@ -366,11 +663,18 @@ export class RunGate {
366
663
  return message !== undefined && [...this.requests.values()].some((held) => held.turn === message);
367
664
  }
368
665
  /** Acts on the answers from now on, resuming the session through `resume`; by default pi's root conversation. */
369
- start(resume) {
666
+ start(resume, unpark) {
370
667
  this.resume = resume ?? this.submit;
668
+ this.unpark = unpark;
371
669
  this.watch();
372
670
  }
373
671
  note(entry) {
672
+ if (entry.kind === GATE_PASSED_ENTRY) {
673
+ const callId = entry.data?.callId;
674
+ if (typeof callId === "string")
675
+ this.passed.add(callId);
676
+ return;
677
+ }
374
678
  const data = entry.data;
375
679
  if (entry.kind !== APPROVAL_ENTRY || typeof data?.id !== "string")
376
680
  return;
@@ -390,9 +694,15 @@ export class RunGate {
390
694
  }
391
695
  /** pi's resume: an input to the root conversation under the request's own id, which pi takes once however often it
392
696
  * is sent, then the mark. */
393
- submit = async (id, content, mark) => {
697
+ submit = async (id, content, mark, origin) => {
394
698
  const root = await this.durable.harness.root(this.context);
395
- await root.submit({ type: "input", requestId: `approval-${id}`, content, whenBusy: "followUp" }, this.context);
699
+ const requestId = `approval-${id}`;
700
+ // pi writes its user entry with no data, so the resume's origin goes first as an entry of its own, which the Timeline
701
+ // matches to it by its text (pi-durable-disk's serve does the same). Once only: a resume tried again whose input is
702
+ // in already writes no second marker, which would be left open for a later message with the same text.
703
+ if (origin && (await root.commit((tx) => tx.submissionByRequest(root.id, requestId), this.context)) === undefined)
704
+ await root.submit({ type: "write", requestId: `origin of ${requestId}`, entry: { kind: MESSAGE_ORIGIN_KIND, data: { origin, text: content } } }, this.context);
705
+ await root.submit({ type: "input", requestId, content, whenBusy: "followUp" }, this.context);
396
706
  await this.durable.harness.commit(mark, this.context);
397
707
  };
398
708
  async settle() {
@@ -428,7 +738,22 @@ export class RunGate {
428
738
  continue;
429
739
  }
430
740
  // An allow runs the call, unless its tool was set to deny since it asked.
431
- const result = decision === "deny" ? { text: refusedText(held.tool, answer.note), isError: true } : this.policy(held.tool) === "deny" ? { text: deniedText(held.tool, settingsKeyOf(this.where.harness ?? "pi", held.tool, this.where.mcpServers)), isError: true } : await this.run(held);
741
+ // A request parked on a replay may follow an attempt that was sent: its refusal makes no "nothing was charged" claim.
742
+ if (decision === "allow")
743
+ this.unpark?.();
744
+ // And a pin holds for an approved call too: one whose arguments are no longer as pinned (a pin set since it asked)
745
+ // is refused as a deny since is.
746
+ const result = decision === "deny" ? { text: refusedText(held.tool, answer.note, held.replayed ? "unknown" : "no"), isError: true } : this.policy(held.tool) === "deny" || this.pinned(held.tool, held.args) ? await this.ranOrDenied(held) : await this.run(held);
747
+ // A test's seam, unset in a server (AGENTRUN_SERVE_TEST_CRASH_AFTER_CALL, a file that marks it once): an approved
748
+ // call that ran and whose outcome is in the journal, then the process goes before its resume, once the test says go
749
+ // (<file>.go), as a crash between the two would leave the run.
750
+ const seam = process.env.AGENTRUN_SERVE_TEST_CRASH_AFTER_CALL;
751
+ if (seam && decision === "allow" && !existsSync(seam)) {
752
+ while (!existsSync(`${seam}.go`))
753
+ await new Promise((done) => setTimeout(done, 50));
754
+ writeFileSync(seam, "");
755
+ process.kill(process.pid, "SIGKILL");
756
+ }
432
757
  // And again once the call is done: a stop or a cancel while it ran drops its result, which never reaches the model.
433
758
  const after = (await readJson(join(this.where.root, RUN_META)))?.approvals?.[held.id];
434
759
  if (after?.decision === "canceled" || after?.decision === "withdrawn") {
@@ -438,7 +763,9 @@ export class RunGate {
438
763
  // The arguments the message names are the server's redacted ones: the gate never writes a held value there. The
439
764
  // result is cut as every host tool's is (boundResult, HOST_RESULT_MAX_CHARS, in its words): an executor's (an
440
765
  // MCP call's) comes uncut, and its journal keeps it whole.
441
- await this.resume(held.id, resumeText(held, answer.args_shown ?? "(not shown)", decision, { ...result, text: boundResult(result.text).text }), (tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: APPROVAL_ENTRY, data: { phase: "resolved", id: held.id, decision } }));
766
+ // The server's message, never the person's: a declining message's words are theirs, beside it.
767
+ const origin = decision === "deny" && answer.by === "message" && answer.note?.trim() ? { kind: "server", reason: "approval_declined", said: answer.note } : { kind: "server", reason: "approval" };
768
+ await this.resume(held.id, resumeText(held, answer.args_shown ?? "(not shown)", decision, { ...result, text: boundResult(result.text).text }), (tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: APPROVAL_ENTRY, data: { phase: "resolved", id: held.id, decision } }), origin);
442
769
  held.resolved = true;
443
770
  }
444
771
  }
@@ -466,6 +793,36 @@ export class RunGate {
466
793
  await this.durable.harness.commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: APPROVAL_ENTRY, data: { phase: "resolved", id: held.id, decision } }), this.context);
467
794
  held.resolved = true;
468
795
  }
796
+ /** The run's own `approvals:` session, the journal every approved call runs through: opened once. */
797
+ journal() {
798
+ this.drive ??= durableSessions(this.durable.harness, this.context, this.durable.store)
799
+ .open(`approvals:${this.where.runId}`)
800
+ .then((writer) => openDrive({ writer, signal: this.stop.signal }))
801
+ .catch((error) => {
802
+ this.drive = undefined;
803
+ throw error;
804
+ });
805
+ return this.drive;
806
+ }
807
+ /** An approved call whose tool was set to deny (or pinned so that its arguments no longer hold) before the gate acted
808
+ * on the answer. A call whose outcome is in the
809
+ * journal RAN (a crash came between it and its resume): the model gets that outcome, as any allowed call's, and nothing
810
+ * runs again; a later deny can't un-run it. One with an intent and no outcome may have been sent: denied, with no claim
811
+ * either way. One the journal never saw is denied, not run and not charged. */
812
+ async ranOrDenied(held) {
813
+ const drive = await this.journal();
814
+ const key = `approval:${held.id}`;
815
+ if (drive.isMemoized(key))
816
+ return this.run(held);
817
+ const heldTo = settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, held.tool, this.where.mcpServers);
818
+ const ran = held.replayed || drive.state().effects.has(key) ? "unknown" : "no";
819
+ if (this.policy(held.tool) !== "deny") {
820
+ const pinned = this.pinned(heldTo ?? held.tool, held.args, ran);
821
+ if (pinned)
822
+ return { text: pinned.text, isError: true };
823
+ }
824
+ return { text: deniedText(held.tool, heldTo, this.denyFrom(held.tool), ran), isError: true };
825
+ }
469
826
  /** The approved call, run once by the kernel through the journal any host tool's call goes through, as an effect of
470
827
  * the run's own `approvals:` session, on the run's coding source: its intent is durable before it runs, its outcome
471
828
  * after; a replay-safe call a crash cut off runs again, any other is answered interrupted and never runs again. */
@@ -473,19 +830,13 @@ export class RunGate {
473
830
  const runner = await this.runnerOf(held);
474
831
  if ("refused" in runner)
475
832
  return { text: runner.refused, isError: true };
476
- this.drive ??= durableSessions(this.durable.harness, this.context)
477
- .open(`approvals:${this.where.runId}`)
478
- .then((writer) => openDrive({ writer, signal: this.stop.signal }))
479
- .catch((error) => {
480
- this.drive = undefined;
481
- throw error;
482
- });
833
+ const drive = this.journal();
483
834
  try {
484
835
  // Its own abort beside the drive's: a stop or a cancel of the run cuts this call, which runs outside any turn.
485
836
  const cut = new AbortController();
486
837
  this.inFlight = { id: held.id, cut };
487
838
  try {
488
- return await (await this.drive).effect(`approval:${held.id}`, { name: held.tool, replay: runner.replay, input: held.args }, async ({ signal }) => {
839
+ return await (await drive).effect(`approval:${held.id}`, { name: held.tool, replay: runner.replay, input: held.args }, async ({ signal }) => {
489
840
  try {
490
841
  const answer = await runner.call(AbortSignal.any([signal, cut.signal]));
491
842
  // A host tool answers its own abort as an error result: still the stop's cut.