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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (444) hide show
  1. package/CHANGELOG.md +270 -0
  2. package/README.md +343 -246
  3. package/dist/adapters.d.ts +0 -7
  4. package/dist/adapters.js +11 -22
  5. package/dist/agent-rows.d.ts +98 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +60 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +14 -0
  14. package/dist/api-only.js +33 -0
  15. package/dist/archil-routes.d.ts +1 -1
  16. package/dist/bash-read-only.d.ts +22 -0
  17. package/dist/bash-read-only.js +701 -0
  18. package/dist/box-egress-vm.d.ts +0 -8
  19. package/dist/box-egress-vm.js +0 -10
  20. package/dist/box-egress.d.ts +0 -4
  21. package/dist/box-egress.js +1 -16
  22. package/dist/box-paths.d.ts +25 -2
  23. package/dist/box-paths.js +79 -11
  24. package/dist/box-relay.d.ts +0 -11
  25. package/dist/box-relay.js +0 -20
  26. package/dist/box-settings.d.ts +26 -0
  27. package/dist/box-settings.js +63 -0
  28. package/dist/boxes.d.ts +21 -1
  29. package/dist/boxes.js +27 -20
  30. package/dist/browser-commands.d.ts +5 -2
  31. package/dist/browser-commands.js +4 -4
  32. package/dist/browser-computer.d.ts +5 -0
  33. package/dist/browser-computer.js +21 -0
  34. package/dist/browser-cost.d.ts +9 -6
  35. package/dist/browser-cost.js +94 -51
  36. package/dist/browser-live.d.ts +7 -20
  37. package/dist/browser-live.js +15 -93
  38. package/dist/browser-person.d.ts +18 -53
  39. package/dist/browser-person.js +94 -279
  40. package/dist/budget.d.ts +0 -4
  41. package/dist/budget.js +0 -7
  42. package/dist/cap.d.ts +8 -12
  43. package/dist/cap.js +12 -27
  44. package/dist/cli.js +61 -20
  45. package/dist/closed-pipes.d.ts +2 -0
  46. package/dist/closed-pipes.js +13 -0
  47. package/dist/computer-commands.d.ts +2 -0
  48. package/dist/computer-commands.js +2 -0
  49. package/dist/computer-keys.js +5 -2
  50. package/dist/computer-setting.d.ts +20 -4
  51. package/dist/computer-setting.js +25 -5
  52. package/dist/computers.d.ts +31 -3
  53. package/dist/computers.js +70 -11
  54. package/dist/confine.d.ts +120 -0
  55. package/dist/confine.js +436 -0
  56. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  57. package/dist/console/assets/index-opTN5Naq.css +1 -0
  58. package/dist/console/index.html +2 -2
  59. package/dist/daytona-api.d.ts +0 -11
  60. package/dist/daytona-api.js +1 -82
  61. package/dist/decision-rows.d.ts +1 -1
  62. package/dist/decision-rows.js +1 -1
  63. package/dist/docker-daemon.d.ts +31 -0
  64. package/dist/docker-daemon.js +56 -0
  65. package/dist/docker-host-addresses.d.ts +37 -0
  66. package/dist/docker-host-addresses.js +110 -0
  67. package/dist/effort-guidance.js +4 -3
  68. package/dist/environment.d.ts +0 -3
  69. package/dist/environment.js +3 -5
  70. package/dist/errors.d.ts +0 -2
  71. package/dist/errors.js +6 -9
  72. package/dist/filed-answer.d.ts +32 -0
  73. package/dist/filed-answer.js +160 -0
  74. package/dist/files.d.ts +1 -11
  75. package/dist/files.js +2 -21
  76. package/dist/github-connection.d.ts +2 -2
  77. package/dist/github-connection.js +1 -1
  78. package/dist/graph-view.d.ts +3 -5
  79. package/dist/graph-view.js +4 -14
  80. package/dist/handed-values.d.ts +9 -0
  81. package/dist/handed-values.js +26 -0
  82. package/dist/harness-install.d.ts +22 -5
  83. package/dist/harness-install.js +98 -20
  84. package/dist/harness-opencode/adapter.d.ts +7 -0
  85. package/dist/harness-opencode/adapter.js +23 -6
  86. package/dist/harness-opencode/index.d.ts +1 -1
  87. package/dist/harness-opencode/index.js +1 -1
  88. package/dist/harness-opencode/verify.d.ts +17 -0
  89. package/dist/harness-opencode/verify.js +30 -10
  90. package/dist/harness-table.js +6 -1
  91. package/dist/harness.d.ts +4 -3
  92. package/dist/harness.js +16 -1
  93. package/dist/heard.js +1 -1
  94. package/dist/held-fd.d.ts +5 -0
  95. package/dist/held-fd.js +14 -0
  96. package/dist/host-calls.d.ts +20 -0
  97. package/dist/host-calls.js +12 -0
  98. package/dist/host-tools.d.ts +4 -21
  99. package/dist/host-tools.js +4 -61
  100. package/dist/host.d.ts +2 -4
  101. package/dist/host.js +2 -7
  102. package/dist/import-summary.d.ts +1 -5
  103. package/dist/import-summary.js +0 -21
  104. package/dist/import.d.ts +6 -6
  105. package/dist/import.js +62 -24
  106. package/dist/key-refusal.d.ts +5 -1
  107. package/dist/key-refusal.js +19 -4
  108. package/dist/learn/check.d.ts +6 -2
  109. package/dist/learn/check.js +83 -29
  110. package/dist/learn/folder.d.ts +5 -1
  111. package/dist/learn/folder.js +10 -3
  112. package/dist/learn/grade.d.ts +14 -0
  113. package/dist/learn/grade.js +68 -12
  114. package/dist/learn/index.d.ts +4 -4
  115. package/dist/learn/index.js +4 -4
  116. package/dist/learn/reflect.d.ts +31 -2
  117. package/dist/learn/reflect.js +79 -4
  118. package/dist/learn/relevance.d.ts +24 -0
  119. package/dist/learn/relevance.js +91 -0
  120. package/dist/learn/secrets.d.ts +8 -1
  121. package/dist/learn/secrets.js +95 -15
  122. package/dist/learn/skills.d.ts +112 -14
  123. package/dist/learn/skills.js +556 -52
  124. package/dist/learned-workflow.d.ts +37 -5
  125. package/dist/learned-workflow.js +106 -12
  126. package/dist/learning-routes.d.ts +16 -49
  127. package/dist/learning-routes.js +46 -36
  128. package/dist/learning-run.d.ts +6 -250
  129. package/dist/learning-run.js +11 -665
  130. package/dist/learning-words.d.ts +12 -5
  131. package/dist/learning-words.js +18 -9
  132. package/dist/learning.d.ts +93 -77
  133. package/dist/learning.js +176 -304
  134. package/dist/live/stream.js +1 -1
  135. package/dist/live/translate.js +13 -3
  136. package/dist/local-models.d.ts +11 -5
  137. package/dist/local-models.js +13 -8
  138. package/dist/mcp-gateway.d.ts +11 -52
  139. package/dist/mcp-gateway.js +44 -148
  140. package/dist/mcp-oauth.d.ts +10 -14
  141. package/dist/mcp-oauth.js +14 -32
  142. package/dist/mcp-probe.d.ts +0 -7
  143. package/dist/mcp-probe.js +4 -10
  144. package/dist/mcp-servers-store.d.ts +6 -6
  145. package/dist/mcp-servers-store.js +13 -15
  146. package/dist/mcp-store.js +3 -4
  147. package/dist/mcp.js +4 -3
  148. package/dist/model.d.ts +6 -7
  149. package/dist/model.js +43 -27
  150. package/dist/monid.d.ts +0 -2
  151. package/dist/monid.js +3 -6
  152. package/dist/openapi.d.ts +8 -1
  153. package/dist/openapi.js +124 -50
  154. package/dist/page.d.ts +1 -3
  155. package/dist/page.js +9 -19
  156. package/dist/paid-calls.d.ts +21 -27
  157. package/dist/paid-calls.js +28 -62
  158. package/dist/pause.d.ts +0 -2
  159. package/dist/pause.js +1 -8
  160. package/dist/place.d.ts +0 -5
  161. package/dist/place.js +0 -10
  162. package/dist/print.d.ts +2 -1
  163. package/dist/print.js +4 -2
  164. package/dist/propose.js +83 -39
  165. package/dist/push-handler.d.ts +1 -1
  166. package/dist/reflect-range.d.ts +25 -0
  167. package/dist/reflect-range.js +30 -0
  168. package/dist/refusal-words.d.ts +5 -1
  169. package/dist/refusal-words.js +5 -1
  170. package/dist/rows.d.ts +1 -1
  171. package/dist/run-cut.d.ts +0 -6
  172. package/dist/run-cut.js +0 -6
  173. package/dist/run-db.d.ts +2 -13
  174. package/dist/run-db.js +2 -41
  175. package/dist/run-launch.d.ts +19 -2
  176. package/dist/run-launch.js +13 -5
  177. package/dist/run-learning-served.d.ts +46 -2
  178. package/dist/run-learning-served.js +26 -7
  179. package/dist/run-reads-over-store.d.ts +1 -1
  180. package/dist/run-reads-over-store.js +15 -6
  181. package/dist/run-secrets.d.ts +33 -0
  182. package/dist/run-secrets.js +53 -0
  183. package/dist/run-timeline-served.d.ts +5 -1
  184. package/dist/run-timeline-served.js +19 -5
  185. package/dist/run-view.d.ts +12 -17
  186. package/dist/run-view.js +29 -28
  187. package/dist/runnable.d.ts +18 -10
  188. package/dist/runnable.js +21 -10
  189. package/dist/runner/adapter-loop.d.ts +14 -3
  190. package/dist/runner/adapter-loop.js +464 -62
  191. package/dist/runner/adapter-run-spec.d.ts +29 -8
  192. package/dist/runner/adapter-run-spec.js +96 -37
  193. package/dist/runner/adapters/index.js +11 -1
  194. package/dist/runner/adapters/pi.d.ts +15 -1
  195. package/dist/runner/adapters/pi.js +19 -5
  196. package/dist/runner/beside.d.ts +30 -3
  197. package/dist/runner/beside.js +54 -12
  198. package/dist/runner/claim-secrets.d.ts +10 -1
  199. package/dist/runner/claim-secrets.js +49 -15
  200. package/dist/runner/cli-run-spec.d.ts +2 -0
  201. package/dist/runner/cli-run-spec.js +60 -17
  202. package/dist/runner/commands.js +1 -1
  203. package/dist/runner/computer-journal.d.ts +15 -2
  204. package/dist/runner/computer-journal.js +41 -5
  205. package/dist/runner/conformance/harness.js +118 -8
  206. package/dist/runner/conformance/subject.d.ts +4 -1
  207. package/dist/runner/dispatch.d.ts +8 -1
  208. package/dist/runner/dispatch.js +81 -7
  209. package/dist/runner/end-of-run.d.ts +8 -2
  210. package/dist/runner/end-of-run.js +10 -4
  211. package/dist/runner/github-app.js +1 -1
  212. package/dist/runner/harness-loops.d.ts +9 -1
  213. package/dist/runner/harness-loops.js +15 -2
  214. package/dist/runner/journal-kinds.d.ts +30 -6
  215. package/dist/runner/journal-kinds.js +20 -5
  216. package/dist/runner/journal-reader.d.ts +1 -1
  217. package/dist/runner/journal-reader.js +2 -2
  218. package/dist/runner/learning-ask.d.ts +4 -0
  219. package/dist/runner/learning-ask.js +15 -1
  220. package/dist/runner/learning-end.d.ts +18 -3
  221. package/dist/runner/learning-end.js +113 -11
  222. package/dist/runner/learning-loop.d.ts +5 -0
  223. package/dist/runner/learning-loop.js +26 -6
  224. package/dist/runner/live-ticker.d.ts +1 -1
  225. package/dist/runner/live-ticker.js +28 -4
  226. package/dist/runner/loop-contract.d.ts +3 -2
  227. package/dist/runner/main.d.ts +64 -10
  228. package/dist/runner/main.js +165 -27
  229. package/dist/runner/mcp-claim.d.ts +1 -1
  230. package/dist/runner/mcp-claim.js +2 -3
  231. package/dist/runner/mcp-run.d.ts +2 -0
  232. package/dist/runner/mcp-run.js +15 -5
  233. package/dist/runner/memory-claim.d.ts +9 -0
  234. package/dist/runner/memory-claim.js +25 -0
  235. package/dist/runner/metrics.d.ts +33 -1
  236. package/dist/runner/metrics.js +85 -1
  237. package/dist/runner/model-route.d.ts +13 -0
  238. package/dist/runner/model-route.js +154 -11
  239. package/dist/runner/redact.d.ts +8 -2
  240. package/dist/runner/redact.js +11 -2
  241. package/dist/runner/reflect-hook.d.ts +12 -1
  242. package/dist/runner/reflect-hook.js +33 -3
  243. package/dist/runner/runner.d.ts +20 -0
  244. package/dist/runner/runner.js +56 -10
  245. package/dist/runner/store-port.d.ts +1 -1
  246. package/dist/runner/store-secrets.d.ts +3 -3
  247. package/dist/runner/store-secrets.js +8 -12
  248. package/dist/runner/text-tools.d.ts +44 -0
  249. package/dist/runner/text-tools.js +237 -0
  250. package/dist/runner/workflow-loop.d.ts +6 -0
  251. package/dist/runner/workflow-loop.js +6 -4
  252. package/dist/runner/workflow-spec.d.ts +18 -0
  253. package/dist/runner/workflow-spec.js +68 -26
  254. package/dist/runs-over-store.d.ts +8 -3
  255. package/dist/runs-over-store.js +76 -19
  256. package/dist/seal-key.d.ts +54 -15
  257. package/dist/seal-key.js +232 -82
  258. package/dist/sealed-settings-store.d.ts +19 -4
  259. package/dist/sealed-settings-store.js +9 -9
  260. package/dist/sealing.d.ts +4 -0
  261. package/dist/sealing.js +20 -0
  262. package/dist/secret-cut.d.ts +1 -1
  263. package/dist/secret-cut.js +1 -1
  264. package/dist/secret-name.d.ts +9 -0
  265. package/dist/secret-name.js +15 -0
  266. package/dist/secret-writes.d.ts +0 -1
  267. package/dist/secret-writes.js +0 -1
  268. package/dist/secrets.d.ts +2 -10
  269. package/dist/secrets.js +21 -17
  270. package/dist/server-fs.d.ts +4 -0
  271. package/dist/server-fs.js +8 -2
  272. package/dist/server-lock.d.ts +0 -24
  273. package/dist/server-lock.js +1 -80
  274. package/dist/server-secrets-store.d.ts +4 -4
  275. package/dist/server-secrets-store.js +10 -32
  276. package/dist/server-secrets.d.ts +4 -9
  277. package/dist/server-secrets.js +12 -33
  278. package/dist/server.d.ts +26 -44
  279. package/dist/server.js +229 -142
  280. package/dist/sign-ins-store.d.ts +34 -36
  281. package/dist/sign-ins-store.js +27 -38
  282. package/dist/sign-ins.d.ts +2 -119
  283. package/dist/sign-ins.js +5 -311
  284. package/dist/standard-webhooks.d.ts +1 -1
  285. package/dist/standard-webhooks.js +1 -1
  286. package/dist/stats.d.ts +3 -2
  287. package/dist/stats.js +1 -1
  288. package/dist/store/agent-body.d.ts +8 -2
  289. package/dist/store/agent-body.js +16 -4
  290. package/dist/store/index.d.ts +3 -3
  291. package/dist/store/index.js +3 -3
  292. package/dist/store/open.d.ts +18 -5
  293. package/dist/store/open.js +23 -3
  294. package/dist/store/postgres/connection.d.ts +18 -2
  295. package/dist/store/postgres/connection.js +156 -32
  296. package/dist/store/postgres/migrate.d.ts +4 -0
  297. package/dist/store/postgres/migrate.js +27 -3
  298. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  299. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  300. package/dist/store/postgres/store.d.ts +9 -2
  301. package/dist/store/postgres/store.js +9 -0
  302. package/dist/store/schema.js +1 -1
  303. package/dist/store/seal.js +2 -2
  304. package/dist/store/sqlite/connection.js +49 -5
  305. package/dist/store/sqlite/run-patch.d.ts +3 -0
  306. package/dist/store/sqlite/run-patch.js +3 -0
  307. package/dist/store/sqlite/store.js +64 -20
  308. package/dist/store/store.d.ts +38 -6
  309. package/dist/store/store.js +12 -2
  310. package/dist/store-reads/cap.d.ts +1 -1
  311. package/dist/store-reads/cap.js +22 -4
  312. package/dist/store-reads/journal.d.ts +25 -6
  313. package/dist/store-reads/journal.js +173 -21
  314. package/dist/store-reads/learning.d.ts +26 -8
  315. package/dist/store-reads/learning.js +12 -4
  316. package/dist/store-reads/workflow.d.ts +1 -1
  317. package/dist/store-reads/workflow.js +1 -1
  318. package/dist/store-view.d.ts +5 -1
  319. package/dist/store-view.js +91 -23
  320. package/dist/template-eval.d.ts +60 -4
  321. package/dist/template-eval.js +120 -54
  322. package/dist/templates.d.ts +24 -10
  323. package/dist/templates.js +69 -38
  324. package/dist/timeline/group.d.ts +33 -0
  325. package/dist/timeline/group.js +77 -0
  326. package/dist/timeline/index.d.ts +7 -0
  327. package/dist/timeline/index.js +7 -0
  328. package/dist/timeline/labels.d.ts +79 -0
  329. package/dist/timeline/labels.js +150 -0
  330. package/dist/timeline/origin.d.ts +56 -0
  331. package/dist/timeline/origin.js +92 -0
  332. package/dist/timeline/render-text.d.ts +11 -0
  333. package/dist/timeline/render-text.js +62 -0
  334. package/dist/timeline/timeline.d.ts +274 -0
  335. package/dist/timeline/timeline.js +1308 -0
  336. package/dist/timeline/util.d.ts +17 -0
  337. package/dist/timeline/util.js +49 -0
  338. package/dist/tool-gate.d.ts +41 -216
  339. package/dist/tool-gate.js +79 -540
  340. package/dist/tool-keys-store.d.ts +11 -12
  341. package/dist/tool-keys-store.js +24 -31
  342. package/dist/tool-keys.d.ts +9 -104
  343. package/dist/tool-keys.js +15 -271
  344. package/dist/tool-plane.d.ts +14 -42
  345. package/dist/tool-plane.js +23 -81
  346. package/dist/tool-settings-store.d.ts +1 -2
  347. package/dist/tool-settings-store.js +5 -8
  348. package/dist/tools.d.ts +31 -19
  349. package/dist/tools.js +101 -108
  350. package/dist/trigger-adapter.d.ts +2 -2
  351. package/dist/trigger-schedule.js +2 -1
  352. package/dist/trigger-secrets-shown.js +5 -1
  353. package/dist/trigger-targets.d.ts +13 -1
  354. package/dist/trigger-targets.js +31 -1
  355. package/dist/triggers.d.ts +2 -2
  356. package/dist/triggers.js +3 -3
  357. package/dist/turn-end.d.ts +1 -1
  358. package/dist/turn-end.js +1 -1
  359. package/dist/turns.d.ts +0 -6
  360. package/dist/turns.js +0 -19
  361. package/dist/uploads.js +1 -1
  362. package/dist/usage.d.ts +0 -2
  363. package/dist/usage.js +0 -2
  364. package/dist/validate.d.ts +2 -0
  365. package/dist/validate.js +23 -14
  366. package/dist/webhooks.d.ts +102 -76
  367. package/dist/webhooks.js +266 -233
  368. package/dist/workflow-run.d.ts +114 -0
  369. package/dist/workflow-run.js +144 -0
  370. package/dist/workspace/beneath.d.ts +19 -0
  371. package/dist/workspace/beneath.js +106 -0
  372. package/dist/workspace/computer-deps.d.ts +52 -5
  373. package/dist/workspace/computer-deps.js +154 -19
  374. package/dist/workspace/computer-for-claim.d.ts +19 -14
  375. package/dist/workspace/computer-for-claim.js +77 -16
  376. package/dist/workspace/computer-hold.d.ts +6 -1
  377. package/dist/workspace/computer-hold.js +6 -1
  378. package/dist/workspace/computer-janitor.d.ts +47 -0
  379. package/dist/workspace/computer-janitor.js +182 -0
  380. package/dist/workspace/computer-providers.d.ts +6 -2
  381. package/dist/workspace/computer-providers.js +1 -1
  382. package/dist/workspace/grep-worker.d.ts +5 -0
  383. package/dist/workspace/grep-worker.js +9 -6
  384. package/dist/workspace/index.d.ts +4 -3
  385. package/dist/workspace/index.js +4 -4
  386. package/dist/workspace/local.d.ts +11 -2
  387. package/dist/workspace/local.js +161 -43
  388. package/dist/workspace/resolve-computer.d.ts +50 -10
  389. package/dist/workspace/resolve-computer.js +46 -11
  390. package/dist/workspace/run-tools.d.ts +13 -31
  391. package/dist/workspace/run-tools.js +10 -27
  392. package/dist/workspace-paths.d.ts +0 -17
  393. package/dist/workspace-paths.js +1 -41
  394. package/dist/workspace.d.ts +0 -17
  395. package/dist/workspace.js +3 -99
  396. package/launcher/agentrun-serve +6 -33
  397. package/package.json +14 -14
  398. package/templates/README.md +9 -3
  399. package/templates/inbound-lead/agent.md +1 -1
  400. package/templates/kyb/agent.md +1 -1
  401. package/templates/market-monitor/agent.md +2 -2
  402. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  403. package/dist/app.d.ts +0 -5
  404. package/dist/app.js +0 -514
  405. package/dist/bound-files.d.ts +0 -4
  406. package/dist/bound-files.js +0 -164
  407. package/dist/bounds.d.ts +0 -26
  408. package/dist/bounds.js +0 -137
  409. package/dist/coding-tools.d.ts +0 -47
  410. package/dist/coding-tools.js +0 -189
  411. package/dist/computer-adb.d.ts +0 -12
  412. package/dist/computer-adb.js +0 -14
  413. package/dist/console/assets/index-35-7aeIZ.js +0 -519
  414. package/dist/console/assets/index-Cejbov-Y.css +0 -1
  415. package/dist/content-filter.d.ts +0 -7
  416. package/dist/content-filter.js +0 -23
  417. package/dist/disk.d.ts +0 -33
  418. package/dist/disk.js +0 -85
  419. package/dist/door-line.d.ts +0 -23
  420. package/dist/door-line.js +0 -83
  421. package/dist/grade.d.ts +0 -63
  422. package/dist/grade.js +0 -150
  423. package/dist/harness-app.d.ts +0 -69
  424. package/dist/harness-app.js +0 -1162
  425. package/dist/mcp-servers.d.ts +0 -269
  426. package/dist/mcp-servers.js +0 -456
  427. package/dist/packs.d.ts +0 -71
  428. package/dist/packs.js +0 -180
  429. package/dist/request-start.d.ts +0 -27
  430. package/dist/request-start.js +0 -381
  431. package/dist/run-box.d.ts +0 -205
  432. package/dist/run-box.js +0 -661
  433. package/dist/run-holder.d.ts +0 -52
  434. package/dist/run-holder.js +0 -139
  435. package/dist/runs.d.ts +0 -1200
  436. package/dist/runs.js +0 -4103
  437. package/dist/sealed-settings.d.ts +0 -60
  438. package/dist/sealed-settings.js +0 -178
  439. package/dist/served-only.d.ts +0 -5
  440. package/dist/served-only.js +0 -12
  441. package/dist/sessions.d.ts +0 -6
  442. package/dist/sessions.js +0 -109
  443. package/dist/workspace/computer-serves.d.ts +0 -12
  444. package/dist/workspace/computer-serves.js +0 -15
@@ -2,21 +2,25 @@ import type { Context } from "@earendil-works/chord";
2
2
  import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
3
3
  import type { HostTool, Wire } from "@parcha/agentrun-kernel";
4
4
  import type { Approvals } from "../approvals.js";
5
+ import type { installSettled } from "../harness-install.js";
5
6
  import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
6
- import type { PinnedModel, Tier } from "../model.js";
7
+ import { type PinnedModel, type Tier } from "../model.js";
7
8
  import { type RunLaunch } from "../run-launch.js";
8
9
  import type { Store } from "../store/store.js";
9
10
  import { type Permission, type RunFiles, type SettingFrom } from "../tool-gate.js";
11
+ import { loadToolSettings } from "../tool-plane.js";
10
12
  import { type ToolHost } from "../tools.js";
11
13
  import { type HostToolCtx } from "../host-tools.js";
12
14
  import { type LearnedWorkflow } from "../learning.js";
13
15
  import { type ToolResults } from "../workspace/run-tools.js";
16
+ import { type ClaimMcp } from "./mcp-run.js";
14
17
  import { type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
15
18
  import { type Claim, type Journal } from "./loop-contract.js";
16
19
  import type { ModelRoute } from "./model-route.js";
17
20
  import { type ArchilClaimOptions } from "../workspace/archil-claim.js";
18
21
  import { type claimComputer, type ComputerDeps } from "../workspace/computer-deps.js";
19
22
  import type { RunComputer } from "../workspace/run-tools.js";
23
+ import type { ShellPlace } from "../workspace/resolve-computer.js";
20
24
  import type { Workspace } from "../workspace/workspace.js";
21
25
  import { type HeldRedact } from "./redact.js";
22
26
  /** What a claim gives the shared computerForClaim: the run, its epoch, its revision, its place and any computer choice. */
@@ -50,10 +54,10 @@ export declare const PI_WIRES: readonly Wire[];
50
54
  /** Whether the runner offers the browser at all: on pi's native route (PiAdapterOptions.extensions), where pi-browser's
51
55
  * durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations). */
52
56
  export declare const BROWSER_ON_RUNNER = true;
53
- /** Whether the runner installs the browser for a run whose revision grants `granted`, fail closed: only on the native route
54
- * (BROWSER_ON_RUNNER), and only with the run's ledger booking on its ToolHost (host.ledger.paid), so no browser call is
55
- * held on this process's own spend. */
56
- export declare const browserListed: (host: Pick<ToolHost, "ledger">, granted: readonly string[]) => boolean;
57
+ /** Whether the runner installs the browser for a run whose revision grants `granted`, or whose computer is a browser
58
+ * (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
59
+ * booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
60
+ export declare const browserListed: (host: Pick<ToolHost, "ledger" | "browserComputer">, granted: readonly string[]) => boolean;
57
61
  /** What the runner hands the spec builder, beside the claim and the loop's own Harness (the AdapterRun): the store (its
58
62
  * agent and run reads, and the live-viewer seam the browser tool writes through), the data directory a Mode 1 run folder
59
63
  * sits in, the model route, and the key the live-viewer tokens are sealed under. One per runner, not per claim. */
@@ -73,6 +77,8 @@ export interface AdapterSpecDeps {
73
77
  readonly routeOf: (model: string | PinnedModel | undefined, env: NodeJS.ProcessEnv, tier?: Tier, wires?: readonly Wire[], upstream?: typeof fetch, redact?: (text: string) => string) => Promise<ModelRoute>;
74
78
  /** The run's log line (what its Workspace and computer have to say that is not a run failure). */
75
79
  readonly log?: (message: string) => void;
80
+ /** For tests: a learning run's grade bound, as a signal (learning-dispatch.ts gradeBound). Default: GRADE_TIMEOUT_MS. */
81
+ readonly gradeBound?: () => AbortSignal;
76
82
  /** The one shared claim-time computer (computer-for-claim.ts), for both the pi and the CLI spec: none for a runner place.
77
83
  * The runner gives it; a test gives its own. */
78
84
  readonly computerForClaim: ComputerForClaim;
@@ -87,6 +93,9 @@ export interface AdapterSpecDeps {
87
93
  readonly baseUrl?: string;
88
94
  readonly fetch?: typeof fetch;
89
95
  };
96
+ /** How a CLI run's claim waits for its harness's first-use install (harness-install.ts installSettled); a test wraps it
97
+ * to see the claim reach the wait. Absent, installSettled itself. */
98
+ readonly installSettled?: typeof installSettled;
90
99
  /** A test runner's fake GitHub API, where the GitHub App's installation tokens are minted (runner/github-app.ts). Absent,
91
100
  * https://api.github.com: the CLI's runner never sets it, and no environment variable, flag or setting maps onto it. */
92
101
  readonly githubApi?: string;
@@ -117,8 +126,8 @@ export declare function modelAskOf(pinned: {
117
126
  * The run's gate before a call's intent, as the adapter loop asks it: the revision's tool settings and approvals over the
118
127
  * server's, from the one store (loadToolSettings), through RunGate (decide: deny with its words, a pin, allow, ask). The
119
128
  * adapter loop handles the ask/park/answer on the journal itself, so only the answer is read here, never RunGate's own
120
- * file-based approval flow. `root`: the run's files, the run's Workspace (Mode 2: its folder on the run's disk; the turn's
121
- * origin is read through it, never a folder of this machine) or the local folder's path.
129
+ * file-based approval flow. `root`: the run's folder, the run's Workspace (Mode 2: its folder on the run's disk, never a
130
+ * folder of this machine) or the local folder's path, for the gate's path checks; nothing in it is read.
122
131
  *
123
132
  * The server's settings are read again at each call, from the store (a row of the local store: no cache, no signal from
124
133
  * the server, which may be another process), so a permission set while the run goes reaches its next call ("applies at the
@@ -134,6 +143,11 @@ export type RunPermissions = {
134
143
  readonly policy: (tool: string) => Permission;
135
144
  readonly denyFrom: (tool: string) => SettingFrom;
136
145
  readonly refresh: () => Promise<void>;
146
+ /** The gate's whole decision of one call with its arguments (RunGate.decide: its deny, its argument pins, its ask or a
147
+ * refusal where no one can approve), as the run's own call of the tool gets it: a learned workflow's MCP node's. */
148
+ readonly decide: (tool: string, args: unknown) => Promise<"allow" | "ask" | {
149
+ deny: string;
150
+ }>;
137
151
  };
138
152
  export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pick<Claim, "runId">, revision: {
139
153
  kind: string;
@@ -142,9 +156,13 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
142
156
  harness?: string;
143
157
  approvals?: Approvals;
144
158
  };
145
- }, root: RunFiles): Promise<NonNullable<AdapterRunSpec["gate"]> & {
159
+ }, root: RunFiles, shell?: ShellPlace): Promise<NonNullable<AdapterRunSpec["gate"]> & {
146
160
  readonly permissions: RunPermissions;
161
+ readonly learn: (flows: readonly LearnedWorkflow[]) => void;
147
162
  }>;
163
+ /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
164
+ * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
165
+ export declare function storeSettings(store: Pick<Store, "settings">): Promise<Awaited<ReturnType<typeof loadToolSettings>>>;
148
166
  /** pi's spec for a claimed run. What it makes for the run (its Archil mount credential, its Workspace, its computer, its
149
167
  * tools) is held until the spec's release; a build that throws part-way lets go what it made by then (spec-holds.ts). */
150
168
  export declare function adapterRunSpecFromLaunch(launch: RunLaunch, run: AdapterRun, deps: AdapterSpecDeps, claim: Claim): Promise<AdapterRunSpec>;
@@ -175,6 +193,9 @@ export declare function learnedWorkflowHostTool(opts: {
175
193
  /** The run's gate's permissions (adapterRunGate): each call node's tool is held to them, as main holds it. */
176
194
  readonly permissions: RunPermissions;
177
195
  readonly ctx: HostToolCtx;
196
+ /** The claim's MCP (mcp-run.ts mcpForClaim), when its revision grants an MCP tool: its call nodes may name its tools by
197
+ * catalog name, each run through the run's own MCP as the loop wraps it. */
198
+ readonly mcp?: Pick<ClaimMcp, "tools" | "catalogOf">;
178
199
  }): Promise<HostTool | undefined>;
179
200
  /** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
180
201
  * hostToolOf): web_fetch, web_search and monid, each by its catalog name under the adapter loop's one gate (`spec.gate`;
@@ -2,10 +2,11 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
2
  import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
3
3
  import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
4
4
  import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
5
+ import { thinkingLevel } from "../model.js";
5
6
  import { firstMessage } from "../run-manifest.js";
6
- import { learningStartOf } from "../run-launch.js";
7
+ import { learningStartOf, seedFailed } from "../run-launch.js";
7
8
  import { isObject } from "../validate.js";
8
- import { runGate } from "../tool-gate.js";
9
+ import { deniedText, noApproverText, runGate } from "../tool-gate.js";
9
10
  import { loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
10
11
  import { readApprovers } from "../server-approvers.js";
11
12
  import { ASK_TOOL, askPerson, toolOf } from "../tools.js";
@@ -18,7 +19,7 @@ import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
18
19
  import { layLearningSeed } from "./learning-seed.js";
19
20
  import { learningWorkspace } from "../learn/folder.js";
20
21
  import { learningEndOfRun } from "./learning-end.js";
21
- import { LEARNED_WORKFLOW_TOOL, learnedWorkflowTool } from "../learned-workflow.js";
22
+ import { learnedAskFits, learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpTools, learnedWorkflowTool } from "../learned-workflow.js";
22
23
  import { PORT_PROVIDER } from "../port-models.js";
23
24
  import { promptOf, readsFiles } from "../skills.js";
24
25
  import { openRunWorkspace } from "../workspace/run-workspace.js";
@@ -27,8 +28,8 @@ import { COMPUTER_ROOT, runFolder } from "../workspace/paths.js";
27
28
  import { runTools, withKindTools } from "../workspace/run-tools.js";
28
29
  import { INPUTS_DIR, UPLOADS_DIR, Uploads } from "../uploads.js";
29
30
  import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
30
- import { UNREADABLE_SIGN_IN } from "../runs.js";
31
- import { claimSecrets, withModelKeys } from "./claim-secrets.js";
31
+ import { UNREADABLE_SIGN_IN } from "../run-view.js";
32
+ import { claimSecrets, learnedDecisionKeys, withModelKeys } from "./claim-secrets.js";
32
33
  import { mcpForClaim } from "./mcp-run.js";
33
34
  import { join } from "node:path";
34
35
  import { hostLifecycle } from "./adapter-loop.js";
@@ -50,10 +51,10 @@ const BROWSER_TOOL = "browser";
50
51
  /** Whether the runner offers the browser at all: on pi's native route (PiAdapterOptions.extensions), where pi-browser's
51
52
  * durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations). */
52
53
  export const BROWSER_ON_RUNNER = true;
53
- /** Whether the runner installs the browser for a run whose revision grants `granted`, fail closed: only on the native route
54
- * (BROWSER_ON_RUNNER), and only with the run's ledger booking on its ToolHost (host.ledger.paid), so no browser call is
55
- * held on this process's own spend. */
56
- export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger?.paid !== undefined && granted.includes(BROWSER_TOOL);
54
+ /** Whether the runner installs the browser for a run whose revision grants `granted`, or whose computer is a browser
55
+ * (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
56
+ * booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
57
+ export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger?.paid !== undefined && (granted.includes(BROWSER_TOOL) || host.browserComputer !== undefined);
57
58
  /** A model as the cap prices it, from the route's catalog cost: its price WITH TIERS (the money rule — a request past a
58
59
  * model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
59
60
  * overhead its provider adds; the output ceiling is the route's when it carries one, else none. */
@@ -78,23 +79,63 @@ export function capModelOf(route) {
78
79
  export function modelAskOf(pinned, ref) {
79
80
  return pinned ? { pinned, ...(ref ? { ref } : {}) } : ref;
80
81
  }
81
- export async function adapterRunGate(store, claim, revision, root) {
82
+ export async function adapterRunGate(store, claim, revision, root, shell) {
82
83
  let current = await storeSettings(store);
83
84
  const approvers = await readApprovers(store.settings);
84
85
  // A Workspace's paths are in the run's folder: its folder named as a computer names it, for the gate's path checks.
85
86
  const folder = typeof root === "string" ? root : COMPUTER_ROOT;
86
- const gate = runGate({ root: folder, work: folder }, claim.runId, revision, () => current, root, approvers);
87
+ // Where the run's shell is (run-tools.ts shell): with no computer, a tool no setting names takes the kernel's ruled
88
+ // default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused.
89
+ const gate = runGate({ root: folder, work: folder, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
90
+ // The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
91
+ let learned = [];
87
92
  const decide = async (call) => {
88
93
  current = await storeSettings(store);
89
- return gate.decide(call.tool, call.args);
94
+ const decision = await gate.decide(call.tool, call.args);
95
+ // A learned workflow's MCP nodes are the run's own MCP calls, held to the same settings, decided for the whole call
96
+ // before any node runs, never mid-run: one set to deny refuses the call in the gate's words, nothing sent; one set to
97
+ // ask asks for the call, up front, on the run's one card (a running workflow can't park mid-call: it is never run
98
+ // again after a crash), and the person's allow lets that call's MCP nodes run, and only that call's.
99
+ // Checked whether the learned_workflow call is itself allowed or asked: a workflow that can't run is never put to a
100
+ // person.
101
+ if (call.tool !== LEARNED_WORKFLOW_TOOL || typeof decision === "object")
102
+ return decision;
103
+ const tools = await mcpOf(call.args);
104
+ const refused = (why) => ({ deny: `The learned workflow ${String(call.args.name)} was not run: ${why}` });
105
+ const denied = tools.find((tool) => gate.policy(tool) === "deny");
106
+ if (denied)
107
+ return refused(deniedText(denied, undefined, gate.denyFrom(denied)));
108
+ const asks = tools.filter((tool) => gate.policy(tool) === "ask");
109
+ // An ask no one can answer (the server's accounts off) is refused at once in the gate's words, never parked.
110
+ if (asks.length && !approvers)
111
+ return refused(noApproverText(asks[0], "no"));
112
+ // A card that could not name every MCP tool the person would approve (past its preview's bound) is never shown: the
113
+ // call is refused, so no allow covers a tool its approver did not see.
114
+ if (asks.length && !learnedAskFits(asks))
115
+ return refused(`its approval card can't name all ${asks.length} MCP tools it would call that are set to ask: set some of them to allow or deny for this agent.`);
116
+ return asks.length ? "ask" : decision;
117
+ };
118
+ /** The MCP tools the learned workflow a learned_workflow call names can call; none for another call or workflow. */
119
+ const mcpOf = async (args) => {
120
+ const flow = learned.find((one) => one.name === args?.name);
121
+ return flow ? learnedMcpTools(flow.workflow) : [];
90
122
  };
91
123
  // An ask is named as main's pending approval is (RunGate.askedAs: its settings key), beside the decision, which is
92
124
  // unchanged. The permissions are the learned workflow's (main's toolGate.policy and denyFrom), over the same settings.
93
- const permissions = { policy: (tool) => gate.policy(tool), denyFrom: (tool) => gate.denyFrom(tool), refresh: async () => { current = await storeSettings(store); } };
94
- return Object.assign(decide, { askedAs: (tool) => gate.askedAs(tool), permissions });
125
+ const permissions = { policy: (tool) => gate.policy(tool), denyFrom: (tool) => gate.denyFrom(tool), refresh: async () => { current = await storeSettings(store); }, decide: (tool, args) => gate.decide(tool, args) };
126
+ // What a learned_workflow call's card shows beside its own input: every MCP tool set to ask that the workflow can call,
127
+ // and that their arguments are decided while it runs, so the person sees what they approve.
128
+ const askedFor = async (tool, args) => {
129
+ if (tool !== LEARNED_WORKFLOW_TOOL)
130
+ return undefined;
131
+ const asks = (await mcpOf(args)).filter((one) => gate.policy(one) === "ask");
132
+ return asks.length ? learnedAskShown(asks) : undefined;
133
+ };
134
+ return Object.assign(decide, { askedAs: (tool) => gate.askedAs(tool), askedFor, permissions, learn: (flows) => void (learned = flows) });
95
135
  }
96
- /** The server's tool settings from the store now; a read that throws is unread (no value of it said). */
97
- async function storeSettings(store) {
136
+ /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
137
+ * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
138
+ export async function storeSettings(store) {
98
139
  try {
99
140
  return await loadToolSettings(store);
100
141
  }
@@ -220,9 +261,9 @@ async function adapterSpec(launch, run, deps, claim, holds) {
220
261
  // ask it leaves into an allow). The adapter loop asks `gate` and handles the ask/park/answer on the journal itself, so
221
262
  // only the permission is read here, never runGate's own file-based approval flow.
222
263
  const root = runFolder(deps.data, runRow.agentId, claim.runId);
223
- // The gate reads the run's own files (the turn's origin) through the run's Workspace: in Mode 2, its folder on the run's
224
- // disk, never this machine's folder at the same path.
225
- const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace);
264
+ // The gate names the run's folder by its Workspace (Mode 2: its folder on the run's disk, never this machine's folder at
265
+ // the same path), for its path checks; it reads nothing in it.
266
+ const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell);
226
267
  // The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
227
268
  // uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
228
269
  // launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
@@ -235,12 +276,12 @@ async function adapterSpec(launch, run, deps, claim, holds) {
235
276
  ...(launch.capMode === "strict" ? { mode: "strict" } : {}),
236
277
  };
237
278
  // The run's cap figure and what a refusal does to it (parkOf, with the kernel's raise rule): present only when the run
238
- // has a cap.
279
+ // has a cap. A park names the cap the loop holds the run to then (a raise's, else this one).
239
280
  const cap = capUsd === undefined
240
281
  ? undefined
241
282
  : {
242
283
  capUsd,
243
- park: (refusal) => parkOf(refusal, capUsd),
284
+ park: (refusal, capNow) => parkOf(refusal, capNow),
244
285
  checkRaise,
245
286
  followUpOf: (raised) => followUpOf(raised),
246
287
  };
@@ -262,47 +303,66 @@ async function adapterSpec(launch, run, deps, claim, holds) {
262
303
  // A learning run's seed, read once from its learning folder where the run's place keeps it: its notes in .learning/
263
304
  // and its learned skills beside the revision's own (runner/learning-seed.ts), cut of the server's secrets, the learned
264
305
  // skills then in the skill list the prompt names, its learned workflows the ones its learned_workflow tool runs. Laid
265
- // before the run's tools are bound. A learning fault lays nothing and the run goes on.
266
- const seedLaid = start
306
+ // before the run's tools are bound. A learning fault, or a seed that failed (seedFailed), lays nothing.
307
+ const seedLaid = start && !seedFailed(start)
267
308
  ? await layLearningSeed({
268
309
  work: ws.workspace,
269
310
  seed: start.seed,
270
311
  folder: () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil })),
271
312
  own: Object.keys(revisionRow.skills ?? {}),
272
- shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data))),
313
+ shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
273
314
  log,
274
315
  })
275
316
  : undefined;
317
+ // The decision keys its learned workflows' typed questions need (claim-secrets.ts learnedDecisionKeys), read once the lay
318
+ // chose them, scoped as the revision's own: each provider the run's gate does not deny, held by the run's one redactor,
319
+ // onto the tools' environment alone. The model's route was built on the revision's keys above, so a decision key never
320
+ // becomes its model's.
321
+ const workflows = seedLaid?.workflows ?? [];
322
+ if (learnsWorkflows(revision.kind, workflows)) {
323
+ const learnedKeys = await learnedDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, workflows, (provider) => gate.permissions.policy(provider) !== "deny");
324
+ holdClaimed(cut, learnedKeys);
325
+ Object.assign(toolEnv, learnedKeys);
326
+ }
276
327
  // The tool host's install lifecycle: what a binding registers to run in each conversation's creating commit, once the
277
328
  // Harness is open before the session, and at the run's end (the browser tool's reconcile and release hang off these). The
278
329
  // adapter loop runs them from the spec's `lifecycle` (adapter-loop.ts hostLifecycle).
279
330
  const life = hostLifecycle();
280
331
  // The ToolHost the non-hand tools (browser, web, MCP, decisions, monid) bind through (buildToolHost, the one the CLI
281
332
  // spec builds too), on the claim's keys and the run's one ledger and redactor.
282
- const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut });
333
+ // An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
334
+ const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
335
+ const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
283
336
  // The run's tools. The hands (read/write/edit/bash and the background tools) are the kernel registry's over the run's
284
337
  // Workspace and computer (runTools.hostTools); the gate is the adapter loop's own (spec.gate), so they run as asked.
285
338
  const results = new Map();
286
- const handTools = tools.hostTools(withKindTools(granted, tools), undefined, results);
339
+ const handTools = tools.hostTools(withKindTools(granted, tools), results);
287
340
  // The non-hand tools run on the claim's keys (host.env), so a vendor's error may echo one: each answer, and a throw's
288
341
  // words, pass the run's one redactor before the harness, the model or the record has them.
289
- const nonHandTools = (await bindNonHandTools(host, revision.kind, granted, run, context, results, root, launch.plane, seedLaid?.workflows ?? [], native, gate.permissions)).map((tool) => answersCut(tool, cut));
342
+ // The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate).
343
+ gate.learn(workflows);
344
+ const nonHandTools = (await bindNonHandTools(host, revision.kind, granted, run, context, results, root, launch.plane, workflows, native, gate.permissions, mcp)).map((tool) => answersCut(tool, cut));
290
345
  const sessionTools = [...handTools, ...nonHandTools];
291
346
  // The run's system prompt, as main's per-run process builds it (app.ts): the environment line first (environment.ts, as
292
347
  // pi installs it before every other section), then the revision's instructions with what the agent learned laid in
293
348
  // (learning.ts laidLearned, from the launch's learning start — the # Learned section decided once at launch, so the runner
294
- // reads no learning folder for it), its own skills through skills.ts promptOf, then the effort guidance (the launch's
295
- // effort, never this process's environment). The one path for every harness.
296
- const laid = start ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
349
+ // reads no learning folder), its own skills through skills.ts promptOf, then the effort guidance (the launch's effort,
350
+ // never this process's environment). The one path for every harness.
351
+ // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
352
+ const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
297
353
  const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, { onDemand: readsFiles(granted) });
298
354
  const guidance = effortGuidance(launch.effort);
299
355
  const system = [environmentLine(), instructions, guidance].filter((line) => Boolean(line));
356
+ // The level pi thinks at: the launch's effort (the run's own, else its revision's, else the host's), every level pi's
357
+ // agent takes; none, pi's default.
358
+ const thinking = thinkingLevel(launch.effort);
300
359
  const session = {
301
360
  key: `run:${claim.runId}`,
302
361
  label: runRow.agentId,
303
362
  system,
304
363
  tools: sessionTools,
305
364
  context: "fresh",
365
+ ...(thinking ? { thinking: thinking } : {}),
306
366
  };
307
367
  // The person's first message: the start body's content, with the run's file manifest beside it (run-manifest.ts), read
308
368
  // through the run's Workspace (Mode 2: its inputs/ on the disk, never a folder of this machine).
@@ -400,7 +460,8 @@ export async function learnedWorkflowHostTool(opts) {
400
460
  return undefined;
401
461
  const flows = opts.workflows;
402
462
  const models = await opts.run.ledger.models(LEARNED_WORKFLOW_TOOL);
403
- const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: models, modelOf: () => ({ provider: PORT_PROVIDER, modelId: "session" }), policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh });
463
+ const mcpTools = (opts.mcp?.tools ?? []).map((one) => opts.mcp.catalogOf(one.name)).filter((name) => typeof name === "string");
464
+ const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: models, modelOf: () => ({ provider: PORT_PROVIDER, modelId: "session" }), policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh, decide: opts.permissions.decide, mcpTools });
404
465
  return hostToolOf(LEARNED_WORKFLOW_TOOL, tool, opts.ctx) ?? undefined;
405
466
  }
406
467
  /** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
@@ -450,11 +511,10 @@ export function answersCut(tool, cut) {
450
511
  export function buildToolHost(opts) {
451
512
  const { root, claim, run, life } = opts;
452
513
  return {
453
- // The run's directory and its per-claim environment. `coding` is the runner's: the hands come from runTools, not from
454
- // a coding source, so the non-hand tools that read it get the run's environment only.
514
+ // The run's directory and its per-claim environment: the hands come from runTools, so the non-hand tools get the run's
515
+ // environment only.
455
516
  where: { root, work: root, ref: { id: claim.runId } },
456
517
  env: opts.env,
457
- coding: { tools: [], extension: { name: "coding", tools: [] } },
458
518
  install: (extension) => run.registry.install(extension),
459
519
  onConversation: life.register.onConversation,
460
520
  beforeResume: life.register.beforeResume,
@@ -462,7 +522,6 @@ export function buildToolHost(opts) {
462
522
  personWait: life.register.personWait,
463
523
  // The run row's summary staged on a commit of the run's (a hand-over's wait, its claim held: run.needs_input).
464
524
  ...(run.rowSummaryOn ? { rowSummaryOn: run.rowSummaryOn } : {}),
465
- handoverInJournal: true,
466
525
  store: opts.store,
467
526
  claim,
468
527
  sealKey: opts.sealKey,
@@ -499,7 +558,7 @@ export async function webHostTools(host, granted, ctx) {
499
558
  }
500
559
  return tools;
501
560
  }
502
- async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions) {
561
+ async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions, mcp) {
503
562
  // Fail closed (browserListed): the browser binds only on the native route (BROWSER_ON_RUNNER) and with the claim's
504
563
  // one-ledger booking on its ToolHost (host.ledger.paid); otherwise its extension is not installed. learned_workflow
505
564
  // binds below with no web tool, so a learned run with no web tool still lists it.
@@ -512,7 +571,7 @@ async function bindNonHandTools(host, kind, granted, run, context, results, root
512
571
  // the session's tools the harness is told of: its model nodes run on the session's proxied models (run.ledger.models),
513
572
  // each a request on the run's one route labelled learned_workflow. The agent's scoped keys (host.env) are its call
514
573
  // nodes'.
515
- const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx });
574
+ const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx, ...(mcp ? { mcp } : {}) });
516
575
  if (learned)
517
576
  tools.push(learned);
518
577
  // The browser (tl-browser), on pi's native route: tools.ts's own binding on this run's ToolHost (its store, claim and seal
@@ -19,6 +19,10 @@ export const RUNNER_HARNESSES = {
19
19
  record: "loop",
20
20
  adapter: async (launch, extra = {}) => {
21
21
  const claude = (await import(CLAUDE_PACKAGE));
22
+ // The CLI the adapter checks, checked first off the event loop: a pass is kept, and the adapter's own check answers
23
+ // from it; a failure is the adapter's to report (warm).
24
+ if (!extra.standIn)
25
+ await claude.verifyClaudeAgentCliAsync(extra.cliPath ?? claude.claudeAgentExecutable());
22
26
  return claude.claudeAgentAdapter({
23
27
  model: launch.model,
24
28
  provider: { origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}) },
@@ -33,6 +37,9 @@ export const RUNNER_HARNESSES = {
33
37
  record: "loop",
34
38
  adapter: async (launch, extra = {}) => {
35
39
  const codex = (await import(CODEX_PACKAGE));
40
+ // Its binary checked first off the event loop, as claude-agent's CLI is (warm): a failure is the adapter's to report.
41
+ if (!extra.standIn)
42
+ await codex.verifyCodexAsync(extra.binary).catch(() => undefined);
36
43
  // Codex's provider is its origin and credential, as serve gives it today (adapters.ts, codexOf): no headers.
37
44
  return codex.codexAdapter({
38
45
  model: launch.model,
@@ -48,7 +55,10 @@ export const RUNNER_HARNESSES = {
48
55
  record: "loop",
49
56
  adapter: async (launch, extra = {}) => {
50
57
  // OpenCode's adapter is serve's own (its pinned binary is checked when the adapter is made); loaded when first asked.
51
- const { openCodeAdapter } = await import("../../harness-opencode/index.js");
58
+ const { openCodeAdapter, verifyOpenCodeAsync } = await import("../../harness-opencode/index.js");
59
+ // Its binary checked first off the event loop, as codex's is (warm): a failure is the adapter's to report.
60
+ if (!extra.standIn)
61
+ await verifyOpenCodeAsync().catch(() => undefined);
52
62
  return openCodeAdapter({
53
63
  model: launch.model,
54
64
  provider: { origin: launch.provider.origin, credential: launch.provider.credential },
@@ -1,8 +1,9 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
2
  import type { Models } from "@earendil-works/pi-ai";
3
3
  import { type Extension, type Harness, type Registry } from "@earendil-works/pi-durable";
4
- import type { AgentAdapter, SessionIO, Wire } from "@parcha/agentrun-kernel";
4
+ import { type AgentAdapter, type SessionIO, type Wire } from "@parcha/agentrun-kernel";
5
5
  import { type ProviderPolicy } from "@parcha/agentrun-kernel/host";
6
+ import { CALL_REFUSED } from "../../timeline/index.js";
6
7
  /** What the adapter loop lends pi for one claim: the run's Harness, its registry, and where pi's models go. */
7
8
  export interface PiRun {
8
9
  readonly harness: Harness;
@@ -94,6 +95,19 @@ export declare function refusalWords(): {
94
95
  text: string;
95
96
  }[];
96
97
  isError: true;
98
+ details: {
99
+ [CALL_REFUSED]: true;
100
+ };
97
101
  } | undefined;
98
102
  readonly held: number;
99
103
  };
104
+ /** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
105
+ * characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
106
+ * default (50 KB or 2,000 lines, its head kept) would cut the end off a host tool's answer, where the answer says how to
107
+ * go on: an MCP answer's "[cut at ...; the whole answer is in the run's files at <path>]", a read's "Use offset=<n> to
108
+ * continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
109
+ * Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
110
+ export declare const HOST_TOOL_OUTPUT: Readonly<{
111
+ maxLines: number;
112
+ maxBytes: number;
113
+ }>;
@@ -2,11 +2,13 @@ import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/conte
2
2
  import { createModels } from "@earendil-works/pi-ai/models";
3
3
  import { defineExtension, defineTool, GenerationTask, hook, ToolTask } from "@earendil-works/pi-durable";
4
4
  import { anthropicPolicy } from "@parcha/agentrun-harness-claude";
5
+ import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
5
6
  import { startModelProxy } from "@parcha/agentrun-kernel/host";
6
7
  import { randomBytes } from "node:crypto";
7
8
  import { DEFAULT_HARNESS } from "../../harness.js";
8
9
  import { sessionProvider } from "../../port-models.js";
9
10
  import { KINDS } from "../journal-kinds.js";
11
+ import { CALL_REFUSED } from "../../timeline/index.js";
10
12
  const PROVIDER = "agentrun-session";
11
13
  const INPUT_REQUEST = "agentrun:input";
12
14
  /** pi as an AgentAdapter for one claim's run. */
@@ -137,7 +139,8 @@ async function sessionOn(proxy, options, spec, io, context) {
137
139
  // session's tools and the run's native extensions, on every open. A conversation a native tool opens takes this agent's
138
140
  // model (pi copies its owner's), so its requests go through this session's proxy.
139
141
  const instructions = spec.system.join("\n\n");
140
- const agent = { model: { provider: PROVIDER, modelId: model }, extensions: [extension, ...native], ...(instructions ? { instructions } : {}) };
142
+ // Its thinking level, the session's (the run's effort), on every open; none leaves pi's default.
143
+ const agent = { model: { provider: PROVIDER, modelId: model }, extensions: [extension, ...native], ...(instructions ? { instructions } : {}), ...(spec.thinking ? { thinkingLevel: spec.thinking } : {}) };
141
144
  const root = await run.harness.root(context, { agent });
142
145
  await root.configure(agent, context);
143
146
  // The run's input submission, if one was placed: its state says where the session is. Answered: idle. Open, or settled
@@ -227,22 +230,33 @@ export function refusalWords() {
227
230
  const blocked = result.diagnostics?.some((diagnostic) => diagnostic.code === "blocked");
228
231
  if (text === undefined || !blocked)
229
232
  return undefined;
230
- return { output: [{ type: "text", text }], isError: true };
233
+ // Marked refused in its details (which the model never reads): its Timeline rows say it was refused, never that it
234
+ // ran and failed.
235
+ return { output: [{ type: "text", text }], isError: true, details: { [CALL_REFUSED]: true } };
231
236
  },
232
237
  get held() {
233
238
  return words.size;
234
239
  },
235
240
  };
236
241
  }
237
- /** A host tool as a pi tool: replay-safe or at most once, its answer the host's text and any images it shows. Each call
238
- * gets what pi's own tool task gives a tool: the calling agent's model, resolved in the session's models (its input and
239
- * input limits, which a file read sizes an image by), and pi's output stream (the running tool's live slot). */
242
+ /** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
243
+ * characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
244
+ * default (50 KB or 2,000 lines, its head kept) would cut the end off a host tool's answer, where the answer says how to
245
+ * go on: an MCP answer's "[cut at ...; the whole answer is in the run's files at <path>]", a read's "Use offset=<n> to
246
+ * continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
247
+ * Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
248
+ export const HOST_TOOL_OUTPUT = Object.freeze({ maxLines: HOST_RESULT_MAX_CHARS + 1, maxBytes: HOST_RESULT_MAX_CHARS * 3 });
249
+ /** A host tool as a pi tool: replay-safe or at most once, its answer the host's text and any images it shows, passed
250
+ * whole within the host's bound (HOST_TOOL_OUTPUT). Each call gets what pi's own tool task gives a tool: the calling
251
+ * agent's model, resolved in the session's models (its input and input limits, which a file read sizes an image by),
252
+ * and pi's output stream (the running tool's live slot). */
240
253
  function piTool(tool, io) {
241
254
  return defineTool({
242
255
  name: tool.name,
243
256
  description: tool.description,
244
257
  parameters: tool.inputSchema,
245
258
  replay: tool.replay === "safe" ? "safe" : "unsafe",
259
+ outputLimits: HOST_TOOL_OUTPUT,
246
260
  execute: async (args, api, toolContext) => {
247
261
  io.onEvent({ type: "tool_start", callId: api.callId, name: tool.name, args });
248
262
  const ref = (await api.agent(toolContext)).model;
@@ -1,11 +1,38 @@
1
+ /** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
2
+ export declare const DRAIN_TIMEOUT = "30s";
3
+ /** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
4
+ * number maxRunsOf gives the capabilities' max_concurrent_runs: AGENTRUN_MAX_RUNS, else as many pi runs as this host's
5
+ * memory holds), and on its close lets each held run finish its turn for up to --drain-timeout (default DRAIN_TIMEOUT)
6
+ * before it stops the rest to resume. The server has checked both by the time this reads them (startServe). */
7
+ export declare function besideRunnerOptions(serve: {
8
+ maxRuns?: number;
9
+ drainTimeout?: string;
10
+ }, env: NodeJS.ProcessEnv): {
11
+ loops: number;
12
+ drainMs: number;
13
+ };
14
+ /** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
15
+ * and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
16
+ * the stop of the loops left: runnerCloseBoundMs), so the stop's deadline never cuts a run's end and release short. */
17
+ export declare function besideStopping(server: {
18
+ runs: number;
19
+ boundMs: number;
20
+ }, held: number, drainMs: number): {
21
+ runs: number;
22
+ boundMs: number;
23
+ };
1
24
  /** A runner beside the server on the same data directory (the CLI start's server-and-runner, and the `runner` subcommand):
2
25
  * its own store handle (role runner), and the runner's dispatch (dispatch.ts) for each claimed run — pi on the kernel's
3
26
  * adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
4
- * caller hands its own: the template eval's in-process server, its faux's). Returns the runner and a close() that
5
- * stops it and closes its store. */
6
- export declare function runnerBeside(dataDir: string, { loops, env }?: {
27
+ * caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
28
+ * (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
29
+ * too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
30
+ * closes its store. */
31
+ export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor }?: {
7
32
  loops?: number;
33
+ drainMs?: number;
8
34
  env?: NodeJS.ProcessEnv;
35
+ janitor?: boolean;
9
36
  }): Promise<{
10
37
  runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
11
38
  close: () => Promise<void>;