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

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