@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
@@ -21,8 +21,9 @@
21
21
  // cut short) is never loaded, and the next install replaces it.
22
22
  import { spawn } from "node:child_process";
23
23
  import { existsSync, readFileSync, realpathSync } from "node:fs";
24
- import { chmod, copyFile, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm } from "node:fs/promises";
24
+ import { chmod, copyFile, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
25
25
  import { createRequire } from "node:module";
26
+ import { hostname } from "node:os";
26
27
  import { basename, dirname, join, sep } from "node:path";
27
28
  import { fileURLToPath, pathToFileURL } from "node:url";
28
29
  import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
@@ -214,22 +215,6 @@ export async function npmInstall(entry, dir, pins, { lock = entry.lock, env = pr
214
215
  throw error instanceof HarnessNotInstalled ? error : fail(error.message);
215
216
  }
216
217
  }
217
- /** What an earlier build left at the top of `<data>/harnesses`, when it installed Claude Code there itself: its
218
- * package.json, its lock and its node_modules, and nothing else. */
219
- const FLAT_INSTALL = new Set(["package.json", "package-lock.json", "node_modules"]);
220
- /** Removes Claude Code as an earlier build installed it, at the top of `harnesses` (read-only, as it left it), so the
221
- * per-harness installs can go in beside nothing: only when the directory holds that layout and nothing else (any other
222
- * entry, a per-harness install among them, and it is left as it is). Nothing of the old tree is read or kept. Resolves
223
- * true when it removed one. */
224
- export async function removeFlatInstall(harnesses) {
225
- const entries = await readdir(harnesses).catch((error) => (error.code === "ENOENT" ? [] : Promise.reject(error)));
226
- if (!entries.length || !entries.every((name) => FLAT_INSTALL.has(name)) || !(entries.includes("package.json") || entries.includes("node_modules")))
227
- return false;
228
- await chmod(harnesses, (await lstat(harnesses)).mode | 0o700);
229
- for (const name of entries)
230
- await writable(join(harnesses, name), true).then(() => rm(join(harnesses, name), { recursive: true, force: true }));
231
- return true;
232
- }
233
218
  /** Every file and directory under `dir` (no link followed) made writable by its owner, or read-only for everyone. */
234
219
  async function writable(dir, on) {
235
220
  const walk = async (path) => {
@@ -298,6 +283,79 @@ function runNpm(args, env, timeoutMs, signal, onKilled) {
298
283
  });
299
284
  });
300
285
  }
286
+ /** The file an install of a harness into `dir` (`<data>/harnesses/<harness>`) keeps in the data directory while it runs,
287
+ * for every process on this data (a runner beside the server, one of its own, or one in another container on the same
288
+ * volume): the installing host and process, and since when. A failed install leaves why in it until the next install;
289
+ * one that lands removes it. In the data directory, beside `<data>/harnesses`: that directory holds the installs alone. */
290
+ export const installMarkOf = (dir) => join(dirname(dirname(dir)), `.harness-install-${basename(dir)}.json`);
291
+ /** The mark written whole, beside it then renamed over it: a claim reading it while it changes reads the last mark or the
292
+ * new one, never part of one (which would read as no install). */
293
+ async function writeMark(dir, mark) {
294
+ const at = installMarkOf(dir);
295
+ await mkdir(dirname(at), { recursive: true });
296
+ const next = `${at}.${process.pid}.next`;
297
+ await writeFile(next, JSON.stringify(mark));
298
+ await rename(next, at);
299
+ }
300
+ async function readMark(dir) {
301
+ try {
302
+ const mark = JSON.parse(await readFile(installMarkOf(dir), "utf8"));
303
+ if (typeof mark.failed === "string")
304
+ return { failed: mark.failed, at: Number(mark.at) };
305
+ return typeof mark.host === "string" && typeof mark.pid === "number" && typeof mark.startedAt === "number" ? { host: mark.host, pid: mark.pid, startedAt: mark.startedAt } : undefined;
306
+ }
307
+ catch {
308
+ return undefined;
309
+ }
310
+ }
311
+ /** Whether process `pid` is alive (signal 0: one of another user's reads as alive too, by EPERM). */
312
+ const alive = (pid) => {
313
+ try {
314
+ process.kill(pid, 0);
315
+ return true;
316
+ }
317
+ catch (error) {
318
+ return error.code === "EPERM";
319
+ }
320
+ };
321
+ /** Where a run's claim stands on a harness that installs on first use, in `dir`: "installed" once it is whole; while an
322
+ * install runs (its mark started within INSTALL_TIMEOUT_MS, by a live process when it names this host; another host's
323
+ * process can't be read from here, so its mark is trusted within that bound), it waits for that install, polling, never
324
+ * past that bound; `{ failed }` with the install's own words when the last install failed; "none" when nothing installs
325
+ * it (no mark, one past the bound, or one this host's installer that is gone left), so the caller says what is missing
326
+ * as before. `onWait`: told once, as it starts to wait. `signal` aborted (the run stopped, or its claim lost): it stops
327
+ * waiting and rejects; the install goes on. */
328
+ export async function installSettled(entry, dir, pins, { signal, onWait, pollMs = 250, timeoutMs = INSTALL_TIMEOUT_MS, isAlive = alive, host = hostname() } = {}) {
329
+ let waiting = false;
330
+ for (;;) {
331
+ if (entry.lacking(dir, pins) === undefined)
332
+ return "installed";
333
+ const mark = await readMark(dir);
334
+ if (mark === undefined)
335
+ return "none";
336
+ if ("failed" in mark)
337
+ return { failed: mark.failed };
338
+ if (Date.now() - mark.startedAt > timeoutMs || (mark.host === host && !isAlive(mark.pid)))
339
+ return "none";
340
+ signal?.throwIfAborted();
341
+ if (!waiting) {
342
+ waiting = true;
343
+ onWait?.();
344
+ }
345
+ await new Promise((resolve, reject) => {
346
+ const timer = setTimeout(done, pollMs);
347
+ function done() {
348
+ signal?.removeEventListener("abort", stop);
349
+ resolve();
350
+ }
351
+ function stop() {
352
+ clearTimeout(timer);
353
+ reject(signal.reason);
354
+ }
355
+ signal?.addEventListener("abort", stop, { once: true });
356
+ });
357
+ }
358
+ }
301
359
  /** The server's one installer of a harness into `dir`: `ensure()` resolves once it is installed whole, installing it first
302
360
  * when it is not, and every caller while an install runs waits for that one. A failed install is not kept: the next call
303
361
  * tries again. `stop()` stops an install that runs (its npm) and waits, bounded, for it to end. `onInstalled` hears of an
@@ -341,11 +399,31 @@ export class HarnessInstall {
341
399
  if (this.stopping.signal.aborted)
342
400
  return Promise.reject(new Error("the server is stopping"));
343
401
  this.running ??= (async () => {
344
- const pins = await this.pins();
345
- if (this.entry.lacking(this.dir, pins) === undefined)
402
+ // The mark a run's claim reads, in this process or a runner's own (installSettled): installing now, then gone once
403
+ // it is in, or why it failed. Written first, before anything is read, so a claim made as this install starts (a run
404
+ // started just after the save that started it) finds it; gone at once when the harness is installed already.
405
+ await writeMark(this.dir, { host: hostname(), pid: process.pid, startedAt: Date.now() });
406
+ const pins = await this.pins().catch(async (error) => {
407
+ await rm(installMarkOf(this.dir), { force: true }).catch(() => undefined);
408
+ throw error;
409
+ });
410
+ if (this.entry.lacking(this.dir, pins) === undefined) {
411
+ await rm(installMarkOf(this.dir), { force: true });
346
412
  return void (this.done = true);
413
+ }
347
414
  const started = performance.now();
348
- await this.install(this.entry, this.dir, pins, this.stopping.signal);
415
+ try {
416
+ await this.install(this.entry, this.dir, pins, this.stopping.signal);
417
+ }
418
+ catch (error) {
419
+ // Why it failed, for the runs that waited on it; a server that stops leaves no mark (its npm was stopped, not refused).
420
+ if (this.stopping.signal.aborted)
421
+ await rm(installMarkOf(this.dir), { force: true }).catch(() => undefined);
422
+ else
423
+ await writeMark(this.dir, { failed: error.message, at: Date.now() }).catch(() => undefined);
424
+ throw error;
425
+ }
426
+ await rm(installMarkOf(this.dir), { force: true });
349
427
  this.done = true;
350
428
  this.onInstalled?.(Math.round(performance.now() - started));
351
429
  })().finally(() => (this.running = undefined));
@@ -42,4 +42,11 @@ export interface OpenCodeAdapterOptions {
42
42
  /** For tests: the fetch the model proxy forwards with. */
43
43
  fetch?: typeof fetch;
44
44
  }
45
+ /** The skills as the instructions list them: each by name and description, read with `read_skill_file`. The
46
+ * description as YAML reads it (learnedFront, the one front-matter reader: a quoted one's escapes decoded), so a quote
47
+ * in it reaches the model as a quote, never as `\"`; on one line. A SKILL.md that reader can't read whole is a
48
+ * revision's own skill the adapter's check accepted (skillProblems reads its name and description lines alone; a
49
+ * learned one never reaches a run unread, as the learning checker refuses it): its description is that line's
50
+ * (descriptionLine). */
51
+ export declare function skillsNote(skills: readonly Pick<HostSkill, "name" | "files">[]): string;
45
52
  export declare function openCodeAdapter(options: OpenCodeAdapterOptions): AgentAdapter;
@@ -10,13 +10,14 @@
10
10
  // skill's files with `read_skill_file`: OpenCode's own skills are off.
11
11
  import { createHash, randomBytes, randomUUID } from "node:crypto";
12
12
  import { join } from "node:path";
13
- import { READ_SKILL_FILE, readSkillFileTool, skillProblems, toolSchemaProblems } from "@parcha/agentrun-kernel";
13
+ import { READ_SKILL_FILE, hostedTool, readSkillFileTool, skillProblems, toolSchemaProblems } from "@parcha/agentrun-kernel";
14
14
  import { abortedOutcome, openDrive, pendingSubmissions, SessionHalt } from "@parcha/agentrun-kernel/kernel";
15
15
  import { recoveryNote, settleTurn, transcriptOf } from "@parcha/agentrun-kernel/process";
16
16
  import { serialWriter, startModelProxy } from "@parcha/agentrun-kernel/host";
17
17
  import { openCodeHarness, sentSubmissions } from "./harness.js";
18
18
  import { openCodePolicy, TOOL_PREFIX } from "./host/policy.js";
19
19
  import { verifyOpenCode } from "./verify.js";
20
+ import { learnedFront } from "../learn/skills.js";
20
21
  /** A name OpenCode keeps whole for an MCP tool (it turns anything else into `_`), short enough that `hands_<name>` is a
21
22
  * function name the Responses API takes (at most 64). */
22
23
  const TOOL_NAME = new RegExp(`^[A-Za-z0-9_-]{1,${64 - TOOL_PREFIX.length}}$`);
@@ -56,16 +57,32 @@ function adapterEvent(event) {
56
57
  return undefined;
57
58
  }
58
59
  const turnsIn = (drive) => transcriptOf(drive.state()).filter((r) => r.data?.type === "turn");
59
- /** The skills as the instructions list them: each by name and description, read with `read_skill_file`. */
60
- function skillsNote(skills) {
60
+ /** The skills as the instructions list them: each by name and description, read with `read_skill_file`. The
61
+ * description as YAML reads it (learnedFront, the one front-matter reader: a quoted one's escapes decoded), so a quote
62
+ * in it reaches the model as a quote, never as `\"`; on one line. A SKILL.md that reader can't read whole is a
63
+ * revision's own skill the adapter's check accepted (skillProblems reads its name and description lines alone; a
64
+ * learned one never reaches a run unread, as the learning checker refuses it): its description is that line's
65
+ * (descriptionLine). */
66
+ export function skillsNote(skills) {
61
67
  const lines = ["You have these skills. Read a skill's SKILL.md with read_skill_file before you use it, and the files it names the same way."];
62
68
  for (const skill of skills) {
63
- const head = /^---\n([\s\S]*?)\n---/.exec(skill.files["SKILL.md"] ?? "")?.[1] ?? "";
64
- const description = /^description:\s*(.+)$/m.exec(head)?.[1]?.trim().replace(/^["']|["']$/g, "") ?? "";
69
+ const md = skill.files["SKILL.md"] ?? "";
70
+ const front = learnedFront(md);
71
+ const description = ((front ? front.description : descriptionLine(md)) ?? "").replace(/\s+/g, " ").trim();
65
72
  lines.push(`- ${skill.name}: ${description}`);
66
73
  }
67
74
  return lines.join("\n");
68
75
  }
76
+ /** A SKILL.md's `description:` line as the adapter's check reads it (skillProblems: the front matter's first
77
+ * `description:` line), its value without one pair of surrounding quotes; undefined with none. */
78
+ function descriptionLine(md) {
79
+ const front = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/.exec(md)?.[1];
80
+ const value = front === undefined ? undefined : /^description:[ \t]*(\S.*?)\s*$/m.exec(front)?.[1];
81
+ if (value === undefined)
82
+ return undefined;
83
+ const quoted = /^(['"])(.*)\1$/.exec(value);
84
+ return quoted ? quoted[2] : value;
85
+ }
69
86
  export function openCodeAdapter(options) {
70
87
  const skills = options.skills ?? [];
71
88
  const skillsWrong = skillProblems(skills);
@@ -120,7 +137,7 @@ export function openCodeAdapter(options) {
120
137
  throw new Error("opencode: a session needs a private directory: the host lends one (io.dir), or pass sessionsDir");
121
138
  // With skills the model also reads their files (read_skill_file), from the session's own copy of them.
122
139
  const skillsDir = join(dir, "skills");
123
- const tools = skills.length ? [...spec.tools, readSkillFileTool(skillsDir, skills.map((skill) => ({ name: skill.name, files: Object.keys(skill.files) })))] : spec.tools;
140
+ const tools = skills.length ? [...spec.tools, hostedTool(io, readSkillFileTool(skillsDir, skills.map((skill) => ({ name: skill.name, files: Object.keys(skill.files) }))))] : spec.tools;
124
141
  if (skills.length) {
125
142
  const { mkdirSync, writeFileSync } = await import("node:fs");
126
143
  const { dirname } = await import("node:path");
@@ -5,5 +5,5 @@ export type { HostSkill } from "@parcha/agentrun-kernel";
5
5
  export type { OpenCodeAdapterOptions, OpenCodeProvider } from "./adapter.js";
6
6
  export type { ChildCommand, ConfineChild } from "./host/server.js";
7
7
  export { OPENCODE_VERSION, findOpenCode, openCodeBinary } from "./binary.js";
8
- export { verifyOpenCode, verifyOpenCodeBinary } from "./verify.js";
8
+ export { verifyOpenCode, verifyOpenCodeAsync, verifyOpenCodeBinary, verifyOpenCodeBinaryAsync } from "./verify.js";
9
9
  export { OPENCODE_BINARY_SHA256, OPENCODE_INSTALL, OPENCODE_NPM_INTEGRITY, OpenCodeNotInstalled, OpenCodePinMismatch } from "./versions.js";
@@ -2,5 +2,5 @@ export { openCodeAdapter } from "./adapter.js";
2
2
  /** The check the adapter runs on the host's skills when it is made: @parcha/agentrun-kernel's own, as the other adapters'. */
3
3
  export { skillProblems } from "@parcha/agentrun-kernel";
4
4
  export { OPENCODE_VERSION, findOpenCode, openCodeBinary } from "./binary.js";
5
- export { verifyOpenCode, verifyOpenCodeBinary } from "./verify.js";
5
+ export { verifyOpenCode, verifyOpenCodeAsync, verifyOpenCodeBinary, verifyOpenCodeBinaryAsync } from "./verify.js";
6
6
  export { OPENCODE_BINARY_SHA256, OPENCODE_INSTALL, OPENCODE_NPM_INTEGRITY, OpenCodeNotInstalled, OpenCodePinMismatch } from "./versions.js";
@@ -22,6 +22,14 @@ export declare function verifyOpenCodeBinary(found: {
22
22
  } | undefined, pins?: OpenCodePins): {
23
23
  path: string;
24
24
  } | OpenCodePinMismatch | OpenCodeNotInstalled;
25
+ /** verifyOpenCodeBinary without holding the event loop (the kernel's checkedOnceAsync), its pass kept for it too. */
26
+ export declare function verifyOpenCodeBinaryAsync(found: {
27
+ path: string;
28
+ pkg?: string;
29
+ packageVersion?: string;
30
+ } | undefined, pins?: OpenCodePins): Promise<{
31
+ path: string;
32
+ } | OpenCodePinMismatch | OpenCodeNotInstalled>;
25
33
  /** This machine's OpenCode checked against the pins: its path, or the typed error thrown. */
26
34
  export declare function verifyOpenCode(found?: {
27
35
  path: string;
@@ -30,3 +38,12 @@ export declare function verifyOpenCode(found?: {
30
38
  } | undefined, pins?: OpenCodePins): {
31
39
  path: string;
32
40
  };
41
+ /** verifyOpenCode without holding the event loop: what a host awaits before it makes the adapter, whose own check then
42
+ * answers from what this kept. */
43
+ export declare function verifyOpenCodeAsync(found?: {
44
+ path: string;
45
+ pkg?: string;
46
+ packageVersion?: string;
47
+ } | undefined, pins?: OpenCodePins): Promise<{
48
+ path: string;
49
+ }>;
@@ -1,11 +1,10 @@
1
1
  // The installed OpenCode checked against the pins (src/versions.ts) before anything runs, with the typed errors a host
2
2
  // maps to a run's failure line. Written for AgentRun.
3
- import { execFileSync } from "node:child_process";
4
3
  import { existsSync, mkdtempSync, rmSync } from "node:fs";
5
4
  import { tmpdir } from "node:os";
6
5
  import { join, resolve } from "node:path";
7
6
  import { env } from "node:process";
8
- import { checkedOnce, sha256OfFile } from "@parcha/agentrun-kernel/host";
7
+ import { checkedOnce, checkedOnceAsync } from "@parcha/agentrun-kernel/host";
9
8
  import { findOpenCode, openCodePackages } from "./binary.js";
10
9
  import { OPENCODE_BINARY_SHA256, OPENCODE_VERSION, OpenCodeNotInstalled, OpenCodePinMismatch } from "./versions.js";
11
10
  /** The pins this package holds. */
@@ -19,6 +18,21 @@ export const openCodePins = () => ({ version: OPENCODE_VERSION, sha256: OPENCODE
19
18
  * directory, where a relative `OPENCODE_BIN` names nothing.
20
19
  */
21
20
  export function verifyOpenCodeBinary(found, pins = openCodePins()) {
21
+ const at = located(found, pins);
22
+ // Hashed a chunk at a time, and checked once per binary in this process while it stays the same file, unchanged (the
23
+ // kernel's checkedOnce): a host that checks it for each model it resolves, and a run's process that makes its adapter,
24
+ // check it once. Its reads hold the event loop: a host checks with verifyOpenCodeBinaryAsync first.
25
+ return at instanceof Error ? at : checkedOnce(at.path, at.key, () => checkBinary(at.path, pins.version, at.expected), passed);
26
+ }
27
+ /** verifyOpenCodeBinary without holding the event loop (the kernel's checkedOnceAsync), its pass kept for it too. */
28
+ export async function verifyOpenCodeBinaryAsync(found, pins = openCodePins()) {
29
+ const at = located(found, pins);
30
+ return at instanceof Error ? at : checkedOnceAsync(at.path, at.key, () => checkBinary(at.path, pins.version, at.expected), passed);
31
+ }
32
+ const passed = (result) => !(result instanceof Error);
33
+ /** The absolute path of `found`, there and of the pinned version, with the sha256 values it may have and the pins' key;
34
+ * or why not. */
35
+ function located(found, pins) {
22
36
  if (!found)
23
37
  return new OpenCodeNotInstalled("no OpenCode binary found for this platform, and OPENCODE_BIN is not set");
24
38
  const path = resolve(found.path);
@@ -29,17 +43,15 @@ export function verifyOpenCodeBinary(found, pins = openCodePins()) {
29
43
  // A binary from a platform package is checked against that package's pin; one named by OPENCODE_BIN (no package) against
30
44
  // the pins of every package this machine may run.
31
45
  const expected = (found.pkg ? [found.pkg] : openCodePackages()).map((pkg) => pins.sha256[pkg]).filter((sha) => typeof sha === "string");
32
- // Hashed a chunk at a time, and checked once per binary in this process while it stays the same file, unchanged (the
33
- // kernel's checkedOnce): a host that checks it for each model it resolves, and a run's process that makes its adapter,
34
- // check it once.
35
- return checkedOnce(path, JSON.stringify({ version: pins.version, expected }), () => checkBinary(path, pins.version, expected), (result) => !(result instanceof Error));
46
+ return { path, expected, key: JSON.stringify({ version: pins.version, expected }) };
36
47
  }
37
- /** The binary at `path` (absolute, there) against the sha256 values it may have and the version it must report. */
38
- function checkBinary(path, version, expected) {
48
+ /** The binary at `path` (absolute, there) against the sha256 values it may have and the version it must report, as the
49
+ * steps it reads (the kernel's BinaryCheck). */
50
+ function* checkBinary(path, version, expected) {
39
51
  if (expected.length) {
40
52
  let sha256;
41
53
  try {
42
- sha256 = sha256OfFile(path);
54
+ sha256 = yield { kind: "sha256", path };
43
55
  }
44
56
  catch (error) {
45
57
  return new OpenCodeNotInstalled(`${path} could not be read: ${String(error?.message ?? error).slice(0, 120)}`);
@@ -53,7 +65,7 @@ function checkBinary(path, version, expected) {
53
65
  const home = mkdtempSync(join(tmpdir(), "agentrun-opencode-version-"));
54
66
  try {
55
67
  const dirs = { HOME: home, XDG_CONFIG_HOME: join(home, "config"), XDG_DATA_HOME: join(home, "data"), XDG_CACHE_HOME: join(home, "cache"), XDG_STATE_HOME: join(home, "state") };
56
- reported = execFileSync(path, ["--version"], { env: { PATH: env.PATH ?? "/usr/bin:/bin", ...dirs, OPENCODE_DISABLE_AUTOUPDATE: "1" }, cwd: home, encoding: "utf8", timeout: 20_000 }).trim();
68
+ reported = (yield { kind: "run", path, args: ["--version"], env: { PATH: env.PATH ?? "/usr/bin:/bin", ...dirs, OPENCODE_DISABLE_AUTOUPDATE: "1" }, cwd: home, timeoutMs: 20_000 }).trim();
57
69
  }
58
70
  catch (error) {
59
71
  return new OpenCodeNotInstalled(`${path} could not be run: ${String(error?.message ?? error).slice(0, 120)}`);
@@ -73,3 +85,11 @@ export function verifyOpenCode(found = findOpenCode(), pins = openCodePins()) {
73
85
  throw result;
74
86
  return result;
75
87
  }
88
+ /** verifyOpenCode without holding the event loop: what a host awaits before it makes the adapter, whose own check then
89
+ * answers from what this kept. */
90
+ export async function verifyOpenCodeAsync(found = findOpenCode(), pins = openCodePins()) {
91
+ const result = await verifyOpenCodeBinaryAsync(found, pins);
92
+ if (result instanceof Error)
93
+ throw result;
94
+ return result;
95
+ }
@@ -111,7 +111,12 @@ const BUILTIN = Object.freeze({
111
111
  pins: async () => (await import("./adapters.js")).codexPins(),
112
112
  }),
113
113
  [openCodeFacts.id]: adapterEntry(openCodeFacts, async (env, needs) => (await import("./adapters.js")).opencodeOf(env, needs), {
114
- skillCheck: async () => (await import("./adapters.js")).packageSkillCheck(() => import("./harness-opencode/index.js")),
114
+ // Checked as OpenCode is handed them (servedSkills, opencodeOf's): one size check on what it gets.
115
+ skillCheck: async () => {
116
+ const [{ packageSkillCheck }, { servedSkills }] = await Promise.all([import("./adapters.js"), import("./learn/skills.js")]);
117
+ const check = await packageSkillCheck(() => import("./harness-opencode/index.js"));
118
+ return check && ((skills) => check(servedSkills(skills)));
119
+ },
115
120
  }),
116
121
  });
117
122
  const loaded = new Map();
package/dist/harness.d.ts CHANGED
@@ -4,9 +4,10 @@ export declare const DEFAULT_HARNESS: HarnessId;
4
4
  /** One harness as capabilities lists it: whether this server runs it, and when not, why; and whether it takes a message
5
5
  * mid-turn (`steer`), or queues it for the turn's end. */
6
6
  /** `default_model`: the model this server runs for the harness when a definition names none (`provider/model-id`), or
7
- * null when it runs none there; harnessOffers sets it. `keys`, on one unavailable only for want of a model key: the keys
8
- * any one of which, saved, lets it run here, so a key's row names it before it is saved (tool-keys.ts' rowUnlocks).
9
- * The server's own: capabilities never serve it. */
7
+ * null when it runs none there; harnessOffers sets it. `keys`: the model keys any one of which runs it here, on one
8
+ * unavailable only for want of a model key (any one, saved, lets it run) and on an available one alike (which of the
9
+ * keys it runs on), so a key's row names it before and after any key is saved (tool-keys.ts' rowUnlocks). The
10
+ * server's own: capabilities never serve it. */
10
11
  /** `installs`: `on_first_use` on claude-agent or codex while its CLI is not installed in this server's data: its first run
11
12
  * (or the first agent made on it) installs it (harness-install.ts). */
12
13
  export type HarnessOffer = {
package/dist/harness.js CHANGED
@@ -5,6 +5,16 @@
5
5
  export const HARNESSES = ["pi", "claude-agent", "codex", "opencode"];
6
6
  export const DEFAULT_HARNESS = "pi";
7
7
  const offered = new WeakMap();
8
+ /** `env` with every model key taken out (each provider's, model.ts PROVIDER_KEYS, and the gateway's), its other
9
+ * properties kept as they are: what a harness would ask for with no model key. */
10
+ async function withoutModelKeys(env) {
11
+ // model.ts imports this module: read late, as the other modules here are.
12
+ const { GATEWAY_KEY_ENV, PROVIDER_KEYS } = await import("./model.js");
13
+ const descriptors = Object.getOwnPropertyDescriptors(env);
14
+ for (const name of [...Object.values(PROVIDER_KEYS).flat(), GATEWAY_KEY_ENV])
15
+ delete descriptors[name];
16
+ return Object.defineProperties({}, descriptors);
17
+ }
8
18
  /** What this server offers of each harness, checked once per environment: each one's entry in the harness table says
9
19
  * why it does not run here (harness-table.ts: an adapter's package, pins and endpoint, on a model of its wire's vendor),
10
20
  * and whether one of its runs fits in this host's memory at all (host.ts). Whether a revision's model fits its harness
@@ -23,7 +33,12 @@ export function harnessOffers(env) {
23
33
  // Claude Code not installed yet says so (its install probes the offers again).
24
34
  const firstUse = entry.installs && !(await harnessInstalled(entry, env)) ? { installs: "on_first_use" } : {};
25
35
  const refused = await entry.refusal(env, undefined, { atStart: true });
26
- return refused === undefined ? { id, available: true, steer: entry.steer, ...firstUse } : { id, available: false, steer: entry.steer, ...refused, ...firstUse };
36
+ if (refused !== undefined)
37
+ return { id, available: false, steer: entry.steer, ...refused, ...firstUse };
38
+ // Available: which model keys run it here is what it would ask for with none of them (a key's row names it only
39
+ // when that key is one), so a row reads the same before and after another provider's key is saved.
40
+ const keyless = await entry.refusal(await withoutModelKeys(env), undefined, { atStart: true });
41
+ return { id, available: true, steer: entry.steer, ...(keyless?.keys?.length ? { keys: keyless.keys } : {}), ...firstUse };
27
42
  }));
28
43
  // A harness that runs here but whose one run is more than this host's memory for runs never starts: said here, so
29
44
  // a save warns and a run is refused at once with why (runnable.ts), never a 429 to try again. One that lacks only a
package/dist/heard.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // - a trigger's firing whose words come from outside (a webhook body, a Slack or GitHub event): a trigger's input,
7
7
  // with its source, never the user's;
8
8
  // - any other message the server wrote (a raised cap's follow-up, an approval's resume): left out.
9
- import { isUserEntry, originMatcher } from "@parcha/pi-durable-agent/timeline";
9
+ import { isUserEntry, originMatcher } from "./timeline/index.js";
10
10
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
11
11
  /** A user message's text parts, joined as the timeline joins them: an image or a file the message carries is no words. */
12
12
  const textOf = (message) => {
@@ -0,0 +1,5 @@
1
+ import type { FileHandle } from "node:fs/promises";
2
+ /** Keeps `handle` reachable until it is closed. A handle held and never closed stays open until the process exits. */
3
+ export declare function hold(handle: FileHandle): FileHandle;
4
+ /** `/proc/self/fd/<n>` for `handle`, held until it is closed (`hold`). */
5
+ export declare function fdPath(handle: FileHandle): string;
@@ -0,0 +1,14 @@
1
+ const HELD = new Set();
2
+ /** Keeps `handle` reachable until it is closed. A handle held and never closed stays open until the process exits. */
3
+ export function hold(handle) {
4
+ if (!HELD.has(handle)) {
5
+ HELD.add(handle);
6
+ // A FileHandle is an EventEmitter that emits `close` once closed (Node's typings leave that out).
7
+ handle.once("close", () => HELD.delete(handle));
8
+ }
9
+ return handle;
10
+ }
11
+ /** `/proc/self/fd/<n>` for `handle`, held until it is closed (`hold`). */
12
+ export function fdPath(handle) {
13
+ return `/proc/self/fd/${hold(handle).fd}`;
14
+ }
@@ -0,0 +1,20 @@
1
+ /** A host tool's answer, as HostTool.call gives it. */
2
+ export type HostAnswer = {
3
+ text: string;
4
+ isError?: boolean;
5
+ };
6
+ /** What the loop lends a call it runs: an MCP tool of the run by its catalog name (`mcp:<server>/<tool>`), as the loop
7
+ * wrapped it, or undefined when the run has no such tool; and, when a person approved the call it runs, the arguments
8
+ * its approval card showed them (the call's ask as journaled: what they saw, never what the gate would show now);
9
+ * undefined when no person approved it. */
10
+ export type HostCalls = {
11
+ readonly mcp: (tool: string) => ((args: unknown, ctx: {
12
+ callId: string;
13
+ signal: AbortSignal;
14
+ }) => Promise<HostAnswer>) | undefined;
15
+ readonly approved: Readonly<Record<string, unknown>> | undefined;
16
+ };
17
+ /** `work` with `lent` as the calls its tool may make. */
18
+ export declare const withHostCalls: <T>(lent: HostCalls, work: () => Promise<T>) => Promise<T>;
19
+ /** The calls the tool running now may make; undefined outside a loop's call (a server-side run, a test calling a tool). */
20
+ export declare const hostCalls: () => HostCalls | undefined;
@@ -0,0 +1,12 @@
1
+ // A call the run's own tools make of another tool of the run, through the same path the harness's calls take: the
2
+ // adapter loop sets it around each host tool's call (runner/adapter-loop.ts hosted), so a learned workflow's call node
3
+ // that names an MCP tool (learned-workflow.ts runEffect) runs that tool as the loop wrapped it: its flush before the side
4
+ // effect, its paid requests booked on the run's one ledger under the call id given, its record on a CLI's timeline, and
5
+ // the stop's abort. The gate is the caller's to ask first, with the run's own permissions; the loop says only what card
6
+ // a person approved the call it runs inside with (`approved`), so an approval covers what that card named and no more.
7
+ import { AsyncLocalStorage } from "node:async_hooks";
8
+ const calls = new AsyncLocalStorage();
9
+ /** `work` with `lent` as the calls its tool may make. */
10
+ export const withHostCalls = (lent, work) => calls.run(lent, work);
11
+ /** The calls the tool running now may make; undefined outside a loop's call (a server-side run, a test calling a tool). */
12
+ export const hostCalls = () => calls.getStore();
@@ -1,8 +1,6 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
2
  import { type ToolExecutionApi, type ToolRegistration } from "@earendil-works/pi-durable";
3
3
  import type { HostTool } from "@parcha/agentrun-kernel";
4
- import type { DurableRun } from "@parcha/pi-durable-disk";
5
- import type { Park, RunGate } from "./tool-gate.js";
6
4
  export { workspaceRelative } from "./workspace-paths.js";
7
5
  /** Each tool a harness other than pi runs here, by catalog name, and whether a call a crash cut off may run again.
8
6
  * `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL, named here as a string so the modules do not import
@@ -28,10 +26,9 @@ export type ToolResults = Map<string, {
28
26
  export declare const HOST_API_MEMBERS: readonly ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "conversation", "waitForTask"];
29
27
  /** The members a host tool's api gives only on a run's Harness: a remote executor's api has none of them. */
30
28
  export declare const RUN_ONLY_MEMBERS: readonly ["conversationId", "snapshot", "conversation", "waitForTask"];
31
- /** What one host tool's call reads of the run, beside the gate: the run's environment (its file environment, the api's
32
- * `env`), its harness's commit and its root agent (a paid call's booking and pi's read), the context and the results map,
33
- * and the paid-call money seam. The same over a DurableRun (hostTools below) and over the runner's claim Harness
34
- * (runner/adapter-run-spec.ts), so a tool runs and answers one way on both. */
29
+ /** What one host tool's call reads of the run: the run's environment (its file environment, the api's `env`), its
30
+ * harness's commit and its root agent (a paid call's booking and pi's read), the context and the results map, and the
31
+ * paid-call money seam, over the runner's claim Harness (runner/adapter-run-spec.ts). */
35
32
  export interface HostToolCtx {
36
33
  readonly context: Context;
37
34
  readonly results: ToolResults;
@@ -44,12 +41,6 @@ export interface HostToolCtx {
44
41
  readonly snapshot: ToolExecutionApi["snapshot"];
45
42
  readonly conversation: ToolExecutionApi["conversation"];
46
43
  readonly waitForTask: ToolExecutionApi["waitForTask"];
47
- /** The run's tool gate and the park it takes; none for the gate's own run of an approved call (the adapter loop's own
48
- * gate, which gates every host-tool call before its intent). */
49
- readonly gated?: {
50
- gate: RunGate;
51
- park: Park;
52
- };
53
44
  /** A gate for a tool that cannot be run on the runner yet: undefined to run the call, else the refusal that is its answer,
54
45
  * so the tool is listed but never run as a stub. No tool sets it now (learned_workflow runs for real on every session's
55
46
  * model port); it stays the seam a not-yet-runnable tool refuses through. The paid tools the loop can book
@@ -59,15 +50,7 @@ export interface HostToolCtx {
59
50
  } | undefined;
60
51
  }
61
52
  /** One pi ToolRegistration `tool` (named `name` by its catalog name) as the kernel's HostTool an adapter session takes:
62
- * the gate before the call, the paid-call seam, then the tool on the run's environment and harness, its answer the text a
53
+ * the paid-call seam, then the tool on the run's environment and harness, its answer the text a
63
54
  * model reads (the output or the failure, a write's or an error's path named relative to the run's folder). Undefined when
64
55
  * `name` is not one a host runs (REPLAY). */
65
56
  export declare function hostToolOf(name: string, tool: ToolRegistration, ctx: HostToolCtx): HostTool | undefined;
66
- /** The host tools `names` names, on the run's coding source `coding`. `gated`: the run's tool gate, which every call
67
- * passes, and the park it takes (harness-app.ts), told of a call it parked, whose turn the harness ends; none (the
68
- * gate's own run of an approved call), each call runs as asked. `extra`: the run's own tools beyond the table (its
69
- * learned_workflow, learned-workflow.ts), which the gate passes like the rest. */
70
- export declare function hostTools(run: DurableRun, names: readonly string[], context: Context, results: ToolResults, coding?: readonly ToolRegistration[], gated?: {
71
- gate: RunGate;
72
- park: Park;
73
- }, extra?: readonly ToolRegistration[]): HostTool[];
@@ -1,15 +1,9 @@
1
1
  import { withAbortSignal } from "@earendil-works/chord/context";
2
2
  import { createModels } from "@earendil-works/pi-ai/models";
3
3
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
4
- import { wireName } from "./catalog.js";
5
- import { BOXED_TOOLS, CodingTools } from "./coding-tools.js";
6
- import { monidTools } from "./monid.js";
7
- import { booking } from "./paid-calls.js";
8
- import { withSecrets } from "./secrets.js";
9
- import { WEB_FETCH_TOOL, webFetchTool } from "./web-fetch.js";
10
- import { WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
4
+ import { WEB_FETCH_TOOL } from "./web-fetch.js";
5
+ import { WEB_SEARCH_TOOL } from "./web-search.js";
11
6
  import { realOf, workspaceRelative } from "./workspace-paths.js";
12
- import { localWorkspace } from "./workspace/index.js";
13
7
  import { bounded, imagesOf, textOf } from "./workspace/executors.js";
14
8
  export { workspaceRelative } from "./workspace-paths.js";
15
9
  /** Each tool a harness other than pi runs here, by catalog name, and whether a call a crash cut off may run again.
@@ -42,7 +36,7 @@ const hostApi = (given) => new Proxy(given, {
42
36
  /** The tools whose result is pi's own words about a path (`Successfully wrote to <path>`), never a file's text. */
43
37
  const SAYS_PATH = new Set(["write", "edit"]);
44
38
  /** One pi ToolRegistration `tool` (named `name` by its catalog name) as the kernel's HostTool an adapter session takes:
45
- * the gate before the call, the paid-call seam, then the tool on the run's environment and harness, its answer the text a
39
+ * the paid-call seam, then the tool on the run's environment and harness, its answer the text a
46
40
  * model reads (the output or the failure, a write's or an error's path named relative to the run's folder). Undefined when
47
41
  * `name` is not one a host runs (REPLAY). */
48
42
  export function hostToolOf(name, tool, ctx) {
@@ -54,15 +48,7 @@ export function hostToolOf(name, tool, ctx) {
54
48
  description: tool.description,
55
49
  inputSchema: tool.parameters,
56
50
  replay,
57
- async call(args, { callId, signal, attempt }) {
58
- // A replay (the kernel's attempt above 0) may follow an attempt that was sent: the gate's refusal then says so.
59
- const refused = await ctx.gated?.gate.enter(name, args, callId, ctx.gated.park, (attempt ?? 0) > 0 ? { replayed: true } : {});
60
- if (refused) {
61
- const answer = { text: refused.text, isError: refused.isError };
62
- ctx.results.set(callId, answer);
63
- // A parked call did not run: the harness's session records it so (HostTool's `parked`).
64
- return refused.parked ? { ...answer, parked: true } : answer;
65
- }
51
+ async call(args, { callId, signal }) {
66
52
  // The unready-tool seam: a tool that cannot be run on the runner yet is refused in words, never run as a stub.
67
53
  const unsettled = ctx.settle?.(name, args, callId);
68
54
  if (unsettled) {
@@ -100,46 +86,3 @@ export function hostToolOf(name, tool, ctx) {
100
86
  },
101
87
  };
102
88
  }
103
- /** The host tools `names` names, on the run's coding source `coding`. `gated`: the run's tool gate, which every call
104
- * passes, and the park it takes (harness-app.ts), told of a call it parked, whose turn the harness ends; none (the
105
- * gate's own run of an approved call), each call runs as asked. `extra`: the run's own tools beyond the table (its
106
- * learned_workflow, learned-workflow.ts), which the gate passes like the rest. */
107
- export function hostTools(run, names, context, results, coding = CodingTools.tools ?? [], gated, extra = []) {
108
- // The coding source gives the coding tools and nothing else: the network tools are this machine's own, below.
109
- const stray = coding.map((tool) => tool.name).filter((name) => !BOXED_TOOLS.includes(name));
110
- if (stray.length)
111
- throw new Error(`the coding source holds ${stray.join(", ")}, which is no coding tool`);
112
- // Their paid requests (Parallel's) are booked under the call, in the run's store, as pi's are (paid-calls.ts).
113
- const web = [webFetchTool(process.env), webSearchTool(process.env)].map(booking);
114
- // monid's, only for a run that names one: its key is the one this process was handed over its pipe (secrets.ts),
115
- // never in its environment, and its long answers go in the run's work/, the claim's as pi's (`where.work`), read at
116
- // the call. They are outside the coding source, which holds the coding tools only.
117
- const monid = names.some((name) => name.startsWith("monid.")) ? monidTools(withSecrets(process.env), () => localWorkspace(run.claim.work)) : [];
118
- // `extra`: the run's own tools beyond the table, its learned_workflow (learned-workflow.ts) when its pin names one.
119
- const tools = new Map([...coding, ...web, ...monid, ...extra].map((tool) => [tool.name, tool]));
120
- // What each call reads of the run: its environment, its harness's commit and root agent (pi's read asks the calling
121
- // agent for its model, for an image's limits; a non-pi run's root agent has no pi model, so read uses its default).
122
- const ctx = {
123
- context,
124
- results,
125
- ...(gated ? { gated } : {}),
126
- env: async () => await run.env({ conversationId: ROOT_CONVERSATION_ID, read: undefined }, context),
127
- commit: (change, at, options) => run.harness.commit(change, at, options),
128
- // The run's own Harness, read at the call as commit's is: a document, conversation or task of this run only.
129
- snapshot: ((...args) => Reflect.apply(run.harness.snapshot, run.harness, args)),
130
- conversation: ((id, at) => run.harness.conversation(id, at)),
131
- waitForTask: (id, at) => run.harness.waitForTask(id, at),
132
- agent: async (at) => {
133
- const root = await run.harness.conversation(ROOT_CONVERSATION_ID, at);
134
- if (!root)
135
- throw new Error("the run has no root conversation");
136
- return root.agent(at);
137
- },
138
- };
139
- // The registrations are keyed by their wire names: the same name for every tool here but monid's.
140
- return names.flatMap((name) => {
141
- const tool = tools.get(wireName(name));
142
- const host = tool ? hostToolOf(name, tool, ctx) : undefined;
143
- return host ? [host] : [];
144
- });
145
- }