@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.37

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 (522) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/README.md +417 -219
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-conformance-cli.d.ts +1 -0
  15. package/dist/attach-conformance-cli.js +18 -0
  16. package/dist/attach-conformance.d.ts +25 -0
  17. package/dist/attach-conformance.js +343 -0
  18. package/dist/attach-images.d.ts +15 -0
  19. package/dist/attach-images.js +59 -0
  20. package/dist/background.d.ts +0 -6
  21. package/dist/background.js +0 -28
  22. package/dist/box-image.d.ts +1 -97
  23. package/dist/box-image.js +4 -284
  24. package/dist/box-paths.d.ts +2 -7
  25. package/dist/box-paths.js +7 -13
  26. package/dist/box-settings.d.ts +0 -11
  27. package/dist/box-settings.js +4 -29
  28. package/dist/browser-commands.js +1 -1
  29. package/dist/browser-computer.d.ts +47 -3
  30. package/dist/browser-computer.js +286 -18
  31. package/dist/browser-cost.d.ts +1 -1
  32. package/dist/browser-live.d.ts +20 -8
  33. package/dist/browser-live.js +50 -27
  34. package/dist/browser-person.d.ts +19 -2
  35. package/dist/browser-person.js +55 -6
  36. package/dist/browser-wait-ended.d.ts +23 -0
  37. package/dist/browser-wait-ended.js +42 -0
  38. package/dist/cap.d.ts +12 -57
  39. package/dist/cap.js +20 -160
  40. package/dist/catalog.d.ts +1 -12
  41. package/dist/catalog.js +3 -33
  42. package/dist/cli.js +17 -26
  43. package/dist/composio-preset.d.ts +36 -0
  44. package/dist/composio-preset.js +179 -0
  45. package/dist/computer-attach.d.ts +125 -0
  46. package/dist/computer-attach.js +330 -0
  47. package/dist/computer-calls.d.ts +48 -0
  48. package/dist/computer-calls.js +126 -0
  49. package/dist/computer-channel.d.ts +57 -0
  50. package/dist/computer-channel.js +115 -0
  51. package/dist/computer-commands.d.ts +1 -1
  52. package/dist/computer-held-routes.d.ts +35 -0
  53. package/dist/computer-held-routes.js +106 -0
  54. package/dist/computer-held.d.ts +48 -0
  55. package/dist/computer-held.js +87 -0
  56. package/dist/computer-keys.d.ts +21 -1
  57. package/dist/computer-keys.js +53 -11
  58. package/dist/computer-live.d.ts +160 -0
  59. package/dist/computer-live.js +643 -0
  60. package/dist/computer-routes.d.ts +1 -4
  61. package/dist/computer-routes.js +3 -5
  62. package/dist/computer-setting.d.ts +2 -0
  63. package/dist/computer-setting.js +38 -1
  64. package/dist/computer-view.d.ts +24 -2
  65. package/dist/computer-view.js +51 -3
  66. package/dist/computer-viewer.d.ts +6 -0
  67. package/dist/computer-viewer.js +297 -0
  68. package/dist/computers.d.ts +79 -12
  69. package/dist/computers.js +147 -28
  70. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  71. package/dist/console/assets/index-DRN62V5v.css +1 -0
  72. package/dist/console/index.html +2 -2
  73. package/dist/docker-daemon.d.ts +2 -2
  74. package/dist/docker-daemon.js +2 -2
  75. package/dist/errors.js +5 -5
  76. package/dist/faux-computers.d.ts +9 -20
  77. package/dist/faux-computers.js +56 -24
  78. package/dist/files.d.ts +1 -9
  79. package/dist/files.js +1 -9
  80. package/dist/github-connection.d.ts +10 -2
  81. package/dist/github-connection.js +65 -2
  82. package/dist/github-faux.js +1 -1
  83. package/dist/github.d.ts +22 -2
  84. package/dist/github.js +42 -8
  85. package/dist/gpu-words.d.ts +14 -0
  86. package/dist/gpu-words.js +21 -0
  87. package/dist/graph-view.d.ts +3 -1
  88. package/dist/graph-view.js +25 -1
  89. package/dist/handed-values.d.ts +1 -1
  90. package/dist/handed-values.js +1 -1
  91. package/dist/harness-install.d.ts +60 -3
  92. package/dist/harness-install.js +322 -34
  93. package/dist/harness.d.ts +1 -0
  94. package/dist/harness.js +36 -2
  95. package/dist/host-tools.d.ts +9 -10
  96. package/dist/host-tools.js +7 -7
  97. package/dist/hosted-search.d.ts +5 -4
  98. package/dist/hosted-search.js +2 -7
  99. package/dist/import-sources.d.ts +10 -0
  100. package/dist/import-sources.js +44 -2
  101. package/dist/import.d.ts +3 -3
  102. package/dist/import.js +37 -6
  103. package/dist/index.d.ts +1 -3
  104. package/dist/index.js +1 -2
  105. package/dist/key-refusal.d.ts +1 -1
  106. package/dist/key-refusal.js +2 -2
  107. package/dist/learn/check.d.ts +11 -2
  108. package/dist/learn/check.js +124 -6
  109. package/dist/learn/commit.d.ts +43 -7
  110. package/dist/learn/commit.js +166 -22
  111. package/dist/learn/folder.d.ts +11 -0
  112. package/dist/learn/folder.js +37 -1
  113. package/dist/learn/general.d.ts +66 -0
  114. package/dist/learn/general.js +73 -0
  115. package/dist/learn/grade.d.ts +22 -1
  116. package/dist/learn/grade.js +107 -16
  117. package/dist/learn/index.d.ts +1 -1
  118. package/dist/learn/index.js +1 -1
  119. package/dist/learn/learning.sh +12 -1
  120. package/dist/learn/notes.d.ts +3 -0
  121. package/dist/learn/notes.js +3 -0
  122. package/dist/learn/reflect.d.ts +14 -2
  123. package/dist/learn/reflect.js +54 -30
  124. package/dist/learn/skills.d.ts +37 -5
  125. package/dist/learn/skills.js +60 -7
  126. package/dist/learned-nodes.d.ts +6 -2
  127. package/dist/learned-workflow.d.ts +43 -9
  128. package/dist/learned-workflow.js +128 -37
  129. package/dist/learning-batch.d.ts +283 -0
  130. package/dist/learning-batch.js +574 -0
  131. package/dist/learning-cost.d.ts +79 -0
  132. package/dist/learning-cost.js +69 -0
  133. package/dist/learning-evals.d.ts +33 -0
  134. package/dist/learning-evals.js +98 -0
  135. package/dist/learning-routes.d.ts +32 -4
  136. package/dist/learning-routes.js +48 -12
  137. package/dist/learning-words.d.ts +9 -0
  138. package/dist/learning-words.js +12 -2
  139. package/dist/learning.d.ts +39 -19
  140. package/dist/learning.js +88 -46
  141. package/dist/live/stream.js +6 -3
  142. package/dist/live/translate.d.ts +4 -3
  143. package/dist/live/translate.js +8 -4
  144. package/dist/live-reach.d.ts +37 -0
  145. package/dist/live-reach.js +62 -0
  146. package/dist/mcp-gateway.d.ts +9 -0
  147. package/dist/mcp-gateway.js +60 -11
  148. package/dist/mcp-oauth.d.ts +57 -7
  149. package/dist/mcp-oauth.js +133 -18
  150. package/dist/mcp-private-hosts.d.ts +4 -4
  151. package/dist/mcp-private-hosts.js +20 -12
  152. package/dist/mcp-probe.d.ts +27 -3
  153. package/dist/mcp-probe.js +106 -29
  154. package/dist/mcp-secret-writes.js +8 -0
  155. package/dist/mcp-servers-store.d.ts +38 -15
  156. package/dist/mcp-servers-store.js +120 -23
  157. package/dist/mcp-store.d.ts +10 -4
  158. package/dist/mcp-store.js +17 -6
  159. package/dist/model-form.d.ts +26 -0
  160. package/dist/model-form.js +80 -0
  161. package/dist/model.d.ts +5 -5
  162. package/dist/model.js +29 -16
  163. package/dist/openapi.d.ts +2 -0
  164. package/dist/openapi.js +586 -64
  165. package/dist/owner.d.ts +0 -1
  166. package/dist/owner.js +0 -2
  167. package/dist/page.d.ts +18 -0
  168. package/dist/page.js +48 -20
  169. package/dist/paid-calls.d.ts +1 -1
  170. package/dist/paid-calls.js +1 -1
  171. package/dist/place-offers.d.ts +96 -0
  172. package/dist/place-offers.js +202 -0
  173. package/dist/place.d.ts +9 -13
  174. package/dist/place.js +21 -32
  175. package/dist/port-models.d.ts +2 -1
  176. package/dist/port-models.js +5 -3
  177. package/dist/print.d.ts +16 -9
  178. package/dist/print.js +15 -17
  179. package/dist/propose.d.ts +4 -0
  180. package/dist/propose.js +34 -11
  181. package/dist/provider.js +3 -2
  182. package/dist/reflect-range.d.ts +8 -1
  183. package/dist/reflect-range.js +1 -1
  184. package/dist/run-cut.d.ts +5 -0
  185. package/dist/run-cut.js +19 -0
  186. package/dist/run-launch.d.ts +28 -3
  187. package/dist/run-launch.js +14 -4
  188. package/dist/run-learning-served.d.ts +2 -2
  189. package/dist/run-manifest.d.ts +2 -2
  190. package/dist/run-manifest.js +2 -2
  191. package/dist/run-reads-over-store.d.ts +1 -1
  192. package/dist/run-repo.d.ts +20 -0
  193. package/dist/run-repo.js +63 -0
  194. package/dist/run-secrets.js +3 -3
  195. package/dist/run-timeline-served.d.ts +1 -1
  196. package/dist/run-timeline-served.js +56 -44
  197. package/dist/run-view.d.ts +8 -5
  198. package/dist/run-view.js +18 -10
  199. package/dist/runnable.d.ts +2 -2
  200. package/dist/runnable.js +6 -2
  201. package/dist/runner/adapter-loop.d.ts +39 -8
  202. package/dist/runner/adapter-loop.js +770 -83
  203. package/dist/runner/adapter-run-spec.d.ts +36 -7
  204. package/dist/runner/adapter-run-spec.js +171 -37
  205. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  206. package/dist/runner/adapters/pi-computer.js +43 -0
  207. package/dist/runner/adapters/pi.d.ts +20 -7
  208. package/dist/runner/adapters/pi.js +111 -26
  209. package/dist/runner/beside.d.ts +7 -3
  210. package/dist/runner/beside.js +26 -12
  211. package/dist/runner/claim-secrets.d.ts +4 -0
  212. package/dist/runner/claim-secrets.js +6 -1
  213. package/dist/runner/cli-run-spec.d.ts +27 -3
  214. package/dist/runner/cli-run-spec.js +198 -74
  215. package/dist/runner/commands.d.ts +8 -2
  216. package/dist/runner/commands.js +31 -6
  217. package/dist/runner/computer-channel.d.ts +34 -0
  218. package/dist/runner/computer-channel.js +61 -0
  219. package/dist/runner/conformance/harness.d.ts +0 -1
  220. package/dist/runner/conformance/harness.js +87 -18
  221. package/dist/runner/conformance/subject.d.ts +1 -1
  222. package/dist/runner/dispatch.js +3 -0
  223. package/dist/runner/end-of-run.d.ts +22 -12
  224. package/dist/runner/end-of-run.js +38 -16
  225. package/dist/runner/github-app.d.ts +2 -1
  226. package/dist/runner/github-app.js +6 -4
  227. package/dist/runner/harness-loops.js +16 -2
  228. package/dist/runner/held-run.d.ts +65 -0
  229. package/dist/runner/held-run.js +158 -0
  230. package/dist/runner/journal-kinds.d.ts +35 -6
  231. package/dist/runner/journal-kinds.js +20 -1
  232. package/dist/runner/journal-reader.d.ts +5 -4
  233. package/dist/runner/journal-reader.js +12 -10
  234. package/dist/runner/learning-ask.d.ts +7 -1
  235. package/dist/runner/learning-ask.js +21 -6
  236. package/dist/runner/learning-dispatch.d.ts +22 -0
  237. package/dist/runner/learning-dispatch.js +77 -10
  238. package/dist/runner/learning-end.d.ts +37 -1
  239. package/dist/runner/learning-end.js +115 -14
  240. package/dist/runner/learning-factory.d.ts +1 -1
  241. package/dist/runner/learning-factory.js +15 -5
  242. package/dist/runner/learning-loop.d.ts +139 -7
  243. package/dist/runner/learning-loop.js +369 -32
  244. package/dist/runner/learning-seed.d.ts +9 -0
  245. package/dist/runner/learning-seed.js +14 -1
  246. package/dist/runner/live-ticker.js +1 -0
  247. package/dist/runner/loop-contract.d.ts +16 -1
  248. package/dist/runner/loop-contract.js +6 -0
  249. package/dist/runner/loop.d.ts +10 -2
  250. package/dist/runner/loop.js +22 -1
  251. package/dist/runner/main.d.ts +13 -1
  252. package/dist/runner/main.js +38 -6
  253. package/dist/runner/mcp-claim.d.ts +11 -4
  254. package/dist/runner/mcp-claim.js +140 -23
  255. package/dist/runner/mcp-github.d.ts +4 -2
  256. package/dist/runner/mcp-github.js +1 -8
  257. package/dist/runner/mcp-run.d.ts +6 -4
  258. package/dist/runner/mcp-run.js +16 -3
  259. package/dist/runner/metrics.d.ts +15 -2
  260. package/dist/runner/metrics.js +21 -2
  261. package/dist/runner/model-route.d.ts +3 -0
  262. package/dist/runner/model-route.js +5 -2
  263. package/dist/runner/pr-checkout.d.ts +60 -0
  264. package/dist/runner/pr-checkout.js +176 -0
  265. package/dist/runner/reflect-hook.d.ts +19 -0
  266. package/dist/runner/reflect-hook.js +20 -8
  267. package/dist/runner/runner.d.ts +26 -0
  268. package/dist/runner/runner.js +231 -27
  269. package/dist/runner/scratch-sweep.d.ts +13 -0
  270. package/dist/runner/scratch-sweep.js +62 -0
  271. package/dist/runner/sessions.d.ts +1 -1
  272. package/dist/runner/spec-holds.d.ts +8 -3
  273. package/dist/runner/spec-holds.js +12 -10
  274. package/dist/runner/store-port.d.ts +7 -2
  275. package/dist/runner/store-secrets.js +21 -4
  276. package/dist/runner/subagent.d.ts +44 -0
  277. package/dist/runner/subagent.js +190 -0
  278. package/dist/runner/workflow-host.d.ts +24 -3
  279. package/dist/runner/workflow-host.js +24 -4
  280. package/dist/runner/workflow-loop.d.ts +6 -3
  281. package/dist/runner/workflow-loop.js +9 -8
  282. package/dist/runner/workflow-spec.d.ts +39 -15
  283. package/dist/runner/workflow-spec.js +143 -40
  284. package/dist/runs-over-store.d.ts +16 -6
  285. package/dist/runs-over-store.js +145 -29
  286. package/dist/seal-key.js +3 -3
  287. package/dist/sealed-settings-store.d.ts +5 -2
  288. package/dist/sealed-settings-store.js +10 -4
  289. package/dist/sealing.js +1 -2
  290. package/dist/secret-cut.d.ts +1 -1
  291. package/dist/secret-cut.js +1 -1
  292. package/dist/secret-writes.d.ts +5 -4
  293. package/dist/secret-writes.js +5 -4
  294. package/dist/server-secrets-store.d.ts +4 -3
  295. package/dist/server-secrets-store.js +15 -9
  296. package/dist/server-secrets.js +3 -2
  297. package/dist/server.d.ts +75 -63
  298. package/dist/server.js +712 -316
  299. package/dist/settings-wake.d.ts +21 -0
  300. package/dist/settings-wake.js +59 -0
  301. package/dist/standard-webhooks.d.ts +4 -1
  302. package/dist/standard-webhooks.js +8 -4
  303. package/dist/store/agent-body.d.ts +9 -2
  304. package/dist/store/agent-body.js +16 -8
  305. package/dist/store/command-wake.d.ts +12 -0
  306. package/dist/store/command-wake.js +37 -0
  307. package/dist/store/deadline.js +9 -5
  308. package/dist/store/dialect.d.ts +6 -0
  309. package/dist/store/dialect.js +5 -0
  310. package/dist/store/index.d.ts +4 -4
  311. package/dist/store/index.js +2 -2
  312. package/dist/store/journal/storage.d.ts +3 -2
  313. package/dist/store/journal/storage.js +15 -6
  314. package/dist/store/postgres/connection.js +9 -4
  315. package/dist/store/postgres/dialect.js +4 -0
  316. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  317. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  318. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  319. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  320. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  321. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  322. package/dist/store/schema.d.ts +2 -1
  323. package/dist/store/schema.js +85 -13
  324. package/dist/store/seal.d.ts +13 -0
  325. package/dist/store/seal.js +19 -0
  326. package/dist/store/sqlite/connection.d.ts +5 -0
  327. package/dist/store/sqlite/connection.js +88 -47
  328. package/dist/store/sqlite/run-patch.d.ts +25 -7
  329. package/dist/store/sqlite/run-patch.js +58 -14
  330. package/dist/store/sqlite/store.js +331 -59
  331. package/dist/store/store.d.ts +330 -21
  332. package/dist/store/store.js +34 -2
  333. package/dist/store-reads/analytics.js +3 -2
  334. package/dist/store-reads/cap.d.ts +2 -4
  335. package/dist/store-reads/cap.js +16 -7
  336. package/dist/store-reads/decisions.d.ts +3 -3
  337. package/dist/store-reads/decisions.js +3 -6
  338. package/dist/store-reads/import-summary.d.ts +1 -1
  339. package/dist/store-reads/journal.d.ts +5 -4
  340. package/dist/store-reads/journal.js +118 -27
  341. package/dist/store-reads/learning.d.ts +34 -4
  342. package/dist/store-reads/learning.js +137 -23
  343. package/dist/store-reads/runs.d.ts +7 -5
  344. package/dist/store-reads/runs.js +17 -10
  345. package/dist/store-reads/stats.js +5 -1
  346. package/dist/store-reads/workflow.d.ts +1 -1
  347. package/dist/store-view.d.ts +5 -0
  348. package/dist/store-view.js +70 -29
  349. package/dist/template-eval.js +8 -5
  350. package/dist/template-github-permissions.d.ts +22 -8
  351. package/dist/template-github-permissions.js +35 -15
  352. package/dist/templates.d.ts +64 -0
  353. package/dist/templates.js +101 -16
  354. package/dist/timeline/timeline.d.ts +30 -1
  355. package/dist/timeline/timeline.js +29 -13
  356. package/dist/timeline/util.d.ts +4 -0
  357. package/dist/timeline/util.js +14 -0
  358. package/dist/tool-blurbs.js +1 -0
  359. package/dist/tool-budget.d.ts +27 -7
  360. package/dist/tool-budget.js +21 -9
  361. package/dist/tool-gate.d.ts +23 -10
  362. package/dist/tool-gate.js +60 -44
  363. package/dist/tool-plane.d.ts +46 -28
  364. package/dist/tool-plane.js +73 -31
  365. package/dist/tools.d.ts +31 -38
  366. package/dist/tools.js +117 -74
  367. package/dist/trigger-adapter.d.ts +4 -0
  368. package/dist/trigger-secrets-shown.d.ts +2 -2
  369. package/dist/trigger-secrets-shown.js +1 -1
  370. package/dist/trigger-signatures.d.ts +26 -6
  371. package/dist/trigger-signatures.js +44 -8
  372. package/dist/trigger-targets.d.ts +2 -0
  373. package/dist/trigger-targets.js +1 -0
  374. package/dist/trigger-webhook.js +5 -2
  375. package/dist/triggers.d.ts +10 -6
  376. package/dist/triggers.js +37 -7
  377. package/dist/turn-end.d.ts +0 -3
  378. package/dist/turn-end.js +0 -3
  379. package/dist/turns.js +16 -1
  380. package/dist/usage-lines.d.ts +1 -1
  381. package/dist/validate.d.ts +6 -0
  382. package/dist/validate.js +41 -4
  383. package/dist/web-fetch.d.ts +1 -1
  384. package/dist/web-search.d.ts +10 -5
  385. package/dist/web-search.js +7 -6
  386. package/dist/webhooks.d.ts +147 -103
  387. package/dist/webhooks.js +564 -324
  388. package/dist/workflow/decision-recovery.d.ts +23 -0
  389. package/dist/workflow/decision-recovery.js +80 -0
  390. package/dist/workflow/decisions.d.ts +134 -0
  391. package/dist/workflow/decisions.js +46 -0
  392. package/dist/workflow/host-session.d.ts +5 -0
  393. package/dist/workflow/host-session.js +85 -0
  394. package/dist/workflow/host-tools.d.ts +3 -0
  395. package/dist/workflow/host-tools.js +3 -0
  396. package/dist/workflow/node-runner.d.ts +113 -0
  397. package/dist/workflow/node-runner.js +270 -0
  398. package/dist/workflow/node.d.ts +89 -0
  399. package/dist/workflow/node.js +101 -0
  400. package/dist/workflow/operator-error.d.ts +4 -0
  401. package/dist/workflow/operator-error.js +4 -0
  402. package/dist/workflow/pi-versions.d.ts +32 -0
  403. package/dist/workflow/pi-versions.js +65 -0
  404. package/dist/workflow/record-file.d.ts +10 -0
  405. package/dist/workflow/record-file.js +56 -0
  406. package/dist/workflow/record-tool.d.ts +77 -0
  407. package/dist/workflow/record-tool.js +126 -0
  408. package/dist/workflow/record.d.ts +151 -0
  409. package/dist/workflow/record.js +401 -0
  410. package/dist/workflow/run-error.d.ts +16 -0
  411. package/dist/workflow/run-error.js +26 -0
  412. package/dist/workflow/runner.d.ts +6 -0
  413. package/dist/workflow/runner.js +240 -0
  414. package/dist/workflow/store.d.ts +23 -0
  415. package/dist/workflow/store.js +242 -0
  416. package/dist/workflow/task.d.ts +133 -0
  417. package/dist/workflow/task.js +412 -0
  418. package/dist/workflow/thinking.d.ts +3 -0
  419. package/dist/workflow/thinking.js +7 -0
  420. package/dist/workflow/tool-context.d.ts +21 -0
  421. package/dist/workflow/tool-context.js +13 -0
  422. package/dist/workflow/types.d.ts +126 -0
  423. package/dist/workflow/types.js +1 -0
  424. package/dist/workflow-run.d.ts +2 -2
  425. package/dist/workspace/agent-computer.d.ts +137 -0
  426. package/dist/workspace/agent-computer.js +292 -0
  427. package/dist/workspace/archil-claim.d.ts +11 -0
  428. package/dist/workspace/archil-claim.js +18 -10
  429. package/dist/workspace/archil-disks.d.ts +49 -0
  430. package/dist/workspace/archil-disks.js +185 -0
  431. package/dist/workspace/archil-exec.js +2 -3
  432. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  433. package/dist/workspace/archil-mount-credential.js +13 -4
  434. package/dist/workspace/attached-computers.d.ts +41 -0
  435. package/dist/workspace/attached-computers.js +114 -0
  436. package/dist/workspace/computer-deps.d.ts +32 -17
  437. package/dist/workspace/computer-deps.js +37 -14
  438. package/dist/workspace/computer-for-claim.d.ts +58 -13
  439. package/dist/workspace/computer-for-claim.js +267 -26
  440. package/dist/workspace/computer-hold.d.ts +11 -27
  441. package/dist/workspace/computer-hold.js +36 -56
  442. package/dist/workspace/computer-janitor.d.ts +3 -2
  443. package/dist/workspace/computer-janitor.js +43 -9
  444. package/dist/workspace/computer-ledger.d.ts +5 -1
  445. package/dist/workspace/computer-ledger.js +11 -0
  446. package/dist/workspace/computer-mcp.d.ts +25 -0
  447. package/dist/workspace/computer-mcp.js +41 -0
  448. package/dist/workspace/computer-ports.d.ts +4 -13
  449. package/dist/workspace/computer-ports.js +4 -107
  450. package/dist/workspace/computer-script.d.ts +37 -0
  451. package/dist/workspace/computer-script.js +138 -0
  452. package/dist/workspace/executors.d.ts +1 -1
  453. package/dist/workspace/index.d.ts +7 -4
  454. package/dist/workspace/index.js +4 -1
  455. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  456. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  457. package/dist/workspace/resolve-computer.d.ts +45 -11
  458. package/dist/workspace/resolve-computer.js +72 -14
  459. package/dist/workspace/run-disk.d.ts +34 -0
  460. package/dist/workspace/run-disk.js +91 -0
  461. package/dist/workspace/run-tools.d.ts +35 -18
  462. package/dist/workspace/run-tools.js +24 -29
  463. package/dist/workspace/server-run-workspace.d.ts +3 -2
  464. package/dist/workspace/server-run-workspace.js +17 -4
  465. package/dist/workspace.js +1 -1
  466. package/package.json +19 -21
  467. package/templates/README.md +9 -6
  468. package/templates/code-review/agent.md +27 -11
  469. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  470. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  471. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  472. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  473. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  474. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  475. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  476. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  477. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  478. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  479. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  480. package/templates/code-review/evals/re-review/prompt.md +1 -1
  481. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  482. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  483. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  484. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  485. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  486. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  487. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  488. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  489. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  490. package/templates/code-review/findings.schema.json +131 -27
  491. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  492. package/templates/code-review/skills/review/DEEP.md +130 -0
  493. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  494. package/templates/code-review/skills/review/SKILL.md +104 -154
  495. package/templates/market-monitor/agent.md +1 -1
  496. package/dist/box/record.d.ts +0 -6
  497. package/dist/box/record.js +0 -41
  498. package/dist/box/sweep.d.ts +0 -53
  499. package/dist/box/sweep.js +0 -193
  500. package/dist/box-egress-vm.d.ts +0 -118
  501. package/dist/box-egress-vm.js +0 -354
  502. package/dist/box-egress.d.ts +0 -105
  503. package/dist/box-egress.js +0 -256
  504. package/dist/box-relay-vm.d.ts +0 -84
  505. package/dist/box-relay-vm.js +0 -437
  506. package/dist/box-relay.d.ts +0 -36
  507. package/dist/box-relay.js +0 -207
  508. package/dist/boxes.d.ts +0 -109
  509. package/dist/boxes.js +0 -249
  510. package/dist/budget.d.ts +0 -71
  511. package/dist/budget.js +0 -199
  512. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  513. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  514. package/dist/daytona-api.d.ts +0 -10
  515. package/dist/daytona-api.js +0 -20
  516. package/dist/egress-proxy.d.ts +0 -45
  517. package/dist/egress-proxy.js +0 -416
  518. package/dist/egress-table.d.ts +0 -24
  519. package/dist/egress-table.js +0 -165
  520. package/dist/run-db.d.ts +0 -53
  521. package/dist/run-db.js +0 -116
  522. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -20,9 +20,9 @@
20
20
  // that directory, never a half install, and the next install removes it; a tree that is not whole (an install by hand
21
21
  // cut short) is never loaded, and the next install replaces it.
22
22
  import { spawn } from "node:child_process";
23
- import { existsSync, readFileSync, realpathSync } from "node:fs";
24
- import { chmod, copyFile, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
25
- import { createRequire } from "node:module";
23
+ import { randomUUID } from "node:crypto";
24
+ import { existsSync, readFileSync, readlinkSync, realpathSync, statSync } from "node:fs";
25
+ import { chmod, copyFile, link, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
26
26
  import { hostname } from "node:os";
27
27
  import { basename, dirname, join, sep } from "node:path";
28
28
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -50,22 +50,97 @@ export function installLine(dir, lock) {
50
50
  return `rm -rf ${next} && mkdir -p ${next} && cp ${shellWord(join(dirname(lock), "package.json"))} ${shellWord(lock)} ${next}/ && npm ci --prefix ${next} --ignore-scripts --include=optional && (chmod -R u+w ${at} 2>/dev/null || true) && rm -rf ${at} && mv ${next} ${at}`;
51
51
  }
52
52
  /** Where `specifier` (a package, or a file of one) resolves from `dir`'s node_modules, only when it is that package's own
53
- * file there: undefined when the package is not in `dir`, or its file resolves outside it (a node_modules above `dir`,
54
- * NODE_PATH, a global one). A package linked into `dir` counts by where its link points. */
53
+ * file there: undefined when the package is not in `dir`, does not export it, or its file resolves outside it (a link to
54
+ * a file elsewhere). A package linked into `dir` counts by where its link points. Its real path, as Node's resolver gives.
55
+ *
56
+ * Read from the tree as it is now, never through Node's resolver: a long-lived process (a runner) keeps what that
57
+ * resolver read for its whole life (its path cache, and the real path of each link it walked), so a package once linked
58
+ * into the tree, then replaced at the same path by an install, would read as the link's old target until the process
59
+ * restarts. The package's own package.json is read here, and real paths taken with no cache. */
55
60
  export function inTree(dir, specifier) {
56
61
  const parts = specifier.split("/");
57
62
  const name = parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
58
63
  const home = join(dir, "node_modules", name);
59
- if (!existsSync(join(home, "package.json")))
60
- return undefined;
61
64
  try {
62
- const found = createRequire(join(dir, "package.json")).resolve(specifier);
63
- return realpathSync(found).startsWith(realpathSync(home) + sep) ? found : undefined;
65
+ const manifest = JSON.parse(readFileSync(join(home, "package.json"), "utf8"));
66
+ const subpath = `.${specifier.slice(name.length)}`;
67
+ const target = manifest.exports !== undefined ? exportsTarget(manifest.exports, subpath) : (subpath === "." ? (typeof manifest.main === "string" ? manifest.main : "index.js") : subpath);
68
+ if (target === undefined)
69
+ return undefined;
70
+ const found = [target, `${target}.js`, join(target, "index.js")].map((path) => join(home, path)).find(statFile);
71
+ if (!found)
72
+ return undefined;
73
+ const real = realpathSync(found);
74
+ return real.startsWith(realpathSync(home) + sep) ? real : undefined;
64
75
  }
65
76
  catch {
66
77
  return undefined;
67
78
  }
68
79
  }
80
+ /** Whether `path` is a file (a link to one counts). */
81
+ const statFile = (path) => {
82
+ try {
83
+ return statSync(path).isFile();
84
+ }
85
+ catch {
86
+ return false;
87
+ }
88
+ };
89
+ /** The conditions Node's require() matches a package's exports by; a package's own key order decides among them. */
90
+ const REQUIRE_CONDITIONS = new Set(["require", "node", "node-addons", "module-sync", "default"]);
91
+ /** The file `exports` maps `subpath` (".", "./server/mcp.js") to, as Node's require() reads it: the subpath's own key,
92
+ * else the pattern ("./*") whose part before its "*" is longest, its "*" given the rest; within it, the first condition
93
+ * require() matches, in the package's own order (an array: its first target that is one). Undefined when the package
94
+ * does not export it. */
95
+ function exportsTarget(exportsField, subpath) {
96
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
97
+ const map = isObject(exportsField) && Object.keys(exportsField).some((key) => key.startsWith(".")) ? exportsField : { ".": exportsField };
98
+ let target = Object.hasOwn(map, subpath) ? map[subpath] : undefined;
99
+ let star;
100
+ if (target === undefined) {
101
+ let best;
102
+ for (const key of Object.keys(map)) {
103
+ const at = key.indexOf("*");
104
+ if (at < 0 || key.indexOf("*", at + 1) >= 0)
105
+ continue;
106
+ const [before, after] = [key.slice(0, at), key.slice(at + 1)];
107
+ if (subpath.length < key.length - 1 || !subpath.startsWith(before) || !subpath.endsWith(after))
108
+ continue;
109
+ if (!best || before.length > best.before || (before.length === best.before && key.length > best.key.length))
110
+ best = { key, before: before.length };
111
+ }
112
+ if (!best)
113
+ return undefined;
114
+ const at = best.key.indexOf("*");
115
+ star = subpath.slice(at, subpath.length - (best.key.length - at - 1));
116
+ target = map[best.key];
117
+ }
118
+ const chosen = (function pick(value) {
119
+ if (typeof value === "string" || value === null)
120
+ return value;
121
+ if (Array.isArray(value)) {
122
+ for (const one of value) {
123
+ const got = pick(one);
124
+ if (typeof got === "string")
125
+ return got;
126
+ }
127
+ return undefined;
128
+ }
129
+ if (isObject(value)) {
130
+ for (const [condition, inner] of Object.entries(value)) {
131
+ if (!REQUIRE_CONDITIONS.has(condition))
132
+ continue;
133
+ const got = pick(inner);
134
+ if (got !== undefined)
135
+ return got;
136
+ }
137
+ }
138
+ return undefined;
139
+ })(target);
140
+ if (typeof chosen !== "string" || !chosen.startsWith("./"))
141
+ return undefined;
142
+ return star === undefined ? chosen : chosen.replaceAll("*", star);
143
+ }
69
144
  /** The file at `path` inside `dir`'s package `name`, when it is that package's own file (where a link points counts). */
70
145
  function fileInPackage(dir, name, ...path) {
71
146
  const home = join(dir, "node_modules", ...name.split("/"));
@@ -331,8 +406,9 @@ export async function installSettled(entry, dir, pins, { signal, onWait, pollMs
331
406
  if (entry.lacking(dir, pins) === undefined)
332
407
  return "installed";
333
408
  const mark = await readMark(dir);
409
+ // No mark: an install that landed since the look above (its tree whole, then its mark gone) is installed, not none.
334
410
  if (mark === undefined)
335
- return "none";
411
+ return entry.lacking(dir, pins) === undefined ? "installed" : "none";
336
412
  if ("failed" in mark)
337
413
  return { failed: mark.failed };
338
414
  if (Date.now() - mark.startedAt > timeoutMs || (mark.host === host && !isAlive(mark.pid)))
@@ -356,8 +432,144 @@ export async function installSettled(entry, dir, pins, { signal, onWait, pollMs
356
432
  });
357
433
  }
358
434
  }
435
+ /** The file an installer holds while it installs into `dir`, beside the install's mark: made exclusively, so of every
436
+ * process on this data (the server, a runner beside it, one of its own) one installs at a time, and the others wait for
437
+ * that install. npm's staging directories beside `dir` are each install's own, and an install removes what an earlier one
438
+ * left there, so two at once would undo each other. */
439
+ export const installHoldOf = (dir) => `${installMarkOf(dir)}.hold`;
440
+ /** How young a hold that cannot be read is still taken as held (none is ever written part way: one left unreadable is a
441
+ * copy cut short, or a file of another's that this bound lets go of in time). */
442
+ const HOLD_WRITING_MS = 10_000;
443
+ /** How long past the install's timeout another host's hold is still taken as held: its npm's own timer starts after the
444
+ * hold is taken, then npm is given its grace to stop and to exit once killed (runNpm). A minute covers what comes
445
+ * before npm starts. */
446
+ const HOLD_STOP_MS = 60_000 + NPM_STOP_GRACE_MS + NPM_KILLED_WAIT_MS;
447
+ /** Process `pid`'s identity beyond its pid, where this system shows one (Linux's /proc): the boot it runs in and its start
448
+ * time in clock ticks since that boot. A pid reused by another process (a restarted container's, which may well be
449
+ * given the same one) never reads as the one that wrote a hold. Undefined where it can't be read (no such process, or
450
+ * no /proc). */
451
+ /** This process's pid namespace, where this system shows one (Linux's /proc/self/ns/pid: `pid:[<inode>]`): two
452
+ * containers on one data directory may share a hostname but not their pids, so a pid is asked of this process table only
453
+ * for a hold written in this namespace. Undefined where it can't be read. */
454
+ export function pidNamespace() {
455
+ try {
456
+ const ns = readlinkSync("/proc/self/ns/pid");
457
+ return /^pid:\[\d+\]$/.test(ns) ? ns : undefined;
458
+ }
459
+ catch {
460
+ return undefined;
461
+ }
462
+ }
463
+ export function processIdentity(pid) {
464
+ try {
465
+ const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
466
+ // The fields after the command (in parentheses, which may hold spaces): the state is the 3rd field, the start the 22nd.
467
+ const start = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
468
+ const boot = readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
469
+ return start && /^\d+$/.test(start) && boot ? `${boot}:${start}` : undefined;
470
+ }
471
+ catch {
472
+ return undefined;
473
+ }
474
+ }
475
+ /** The hold at `at` as written, or undefined when it cannot be read (gone, cut short, not one). */
476
+ async function readHold(at) {
477
+ try {
478
+ const held = JSON.parse(await readFile(at, "utf8"));
479
+ return held !== null && typeof held === "object" ? held : undefined;
480
+ }
481
+ catch {
482
+ return undefined;
483
+ }
484
+ }
485
+ /** Takes the hold on installs into `dir` for this process: its token when it holds it now, undefined while another
486
+ * installer does. One of this host's (and of this pid namespace, where it names one) is held while the process that wrote it lives, whatever its age (its npm may still
487
+ * be stopping): its pid alive and, where the system shows it, the same process (processIdentity), so a pid another
488
+ * process was given since never keeps it; where the identity can't be read, while its pid lives within INSTALL_TIMEOUT_MS
489
+ * and the time npm takes to stop (HOLD_STOP_MS). Another host's, whose process can't be asked, within that bound. The hold
490
+ * is written whole beside its place and linked into it, which fails when a hold is there, so no reader sees one part
491
+ * way. A hold its installer left (gone, or past that bound, or unreadable and older than HOLD_WRITING_MS) is taken over
492
+ * by one taker alone: the one that links it to a name of that very file's removes it, and only while it is still that
493
+ * file, so a hold another taker made meanwhile is never removed. */
494
+ export async function takeHold(dir, { isAlive = alive, identity = processIdentity, host = hostname(), pidns = pidNamespace(), timeoutMs = INSTALL_TIMEOUT_MS } = {}) {
495
+ const at = installHoldOf(dir);
496
+ await mkdir(dirname(at), { recursive: true });
497
+ const token = randomUUID();
498
+ const draft = `${at}.${token}`;
499
+ const own = identity(process.pid);
500
+ await writeFile(draft, JSON.stringify({ host, ...(pidns ? { pidns } : {}), pid: process.pid, ...(own ? { identity: own } : {}), startedAt: Date.now(), token }));
501
+ /** Whether a hold's pid can be asked of this process table: written on this host, in this pid namespace where both
502
+ * name one. Another namespace's (another container's on the same data, with the same hostname) is judged as another
503
+ * host's. */
504
+ const local = (held) => held.host === host && (typeof held.pidns !== "string" || pidns === undefined || held.pidns === pidns);
505
+ /** Whether a hold of this host's is still its installer's: that process alive, by its identity where both are known. */
506
+ const installing = (held) => {
507
+ if (!isAlive(held.pid))
508
+ return false;
509
+ const now = typeof held.identity === "string" ? identity(held.pid) : undefined;
510
+ return now !== undefined ? now === held.identity : Date.now() - held.startedAt <= timeoutMs + HOLD_STOP_MS;
511
+ };
512
+ try {
513
+ for (let tries = 0; tries < 3; tries++) {
514
+ try {
515
+ await link(draft, at);
516
+ return token;
517
+ }
518
+ catch (error) {
519
+ if (error.code !== "EEXIST")
520
+ throw error;
521
+ }
522
+ const judged = await lstat(at).catch(() => undefined);
523
+ if (!judged)
524
+ continue;
525
+ const held = await readHold(at);
526
+ const live = typeof held?.pid === "number" && typeof held.startedAt === "number"
527
+ ? local(held) ? installing(held) : Date.now() - held.startedAt <= timeoutMs + HOLD_STOP_MS
528
+ : Date.now() - judged.mtimeMs <= HOLD_WRITING_MS;
529
+ if (live)
530
+ return undefined;
531
+ // Left by its installer: reaped by one taker alone. The hold is never moved; a taker links it to a name of that very
532
+ // file's (its device and inode), which only one can make, and that one removes the hold, once the link shows it is
533
+ // still the hold judged left: its device, inode and token. An inode alone is not enough: once another taker removes
534
+ // the hold, a fresh hold can be given the same inode, and only its token tells it apart. The others wait. A reap a
535
+ // taker cut short left long ago is cleared for the next look.
536
+ const reap = `${at}.reap-${judged.dev}-${judged.ino}`;
537
+ try {
538
+ await link(at, reap);
539
+ }
540
+ catch (error) {
541
+ const code = error.code;
542
+ if (code === "ENOENT")
543
+ continue;
544
+ if (code !== "EEXIST")
545
+ throw error;
546
+ const since = (await lstat(reap).catch(() => undefined))?.ctimeMs;
547
+ if (since !== undefined && Date.now() - since > HOLD_WRITING_MS)
548
+ await rm(reap, { force: true });
549
+ return undefined;
550
+ }
551
+ const reaped = await lstat(reap);
552
+ const same = reaped.ino === judged.ino && reaped.dev === judged.dev && (await readHold(reap))?.token === held?.token;
553
+ if (same)
554
+ await rm(at, { force: true });
555
+ await rm(reap, { force: true });
556
+ }
557
+ return undefined;
558
+ }
559
+ finally {
560
+ await rm(draft, { force: true }).catch(() => undefined);
561
+ }
562
+ }
563
+ /** Lets go of the hold on installs into `dir` that `token` took; a hold of another's (one that took over this one past
564
+ * its bound) stays. */
565
+ export async function releaseHold(dir, token) {
566
+ const at = installHoldOf(dir);
567
+ if ((await readHold(at))?.token === token)
568
+ await rm(at, { force: true });
569
+ }
359
570
  /** The server's one installer of a harness into `dir`: `ensure()` resolves once it is installed whole, installing it first
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
571
+ * when it is not, and every caller while an install runs waits for that one. While another process installs it (it holds
572
+ * installHoldOf), this one waits for that install instead of starting its own. A failed install is not kept: the next call
361
573
  * tries again. `stop()` stops an install that runs (its npm) and waits, bounded, for it to end. `onInstalled` hears of an
362
574
  * install this server made, and how long it took. */
363
575
  export class HarnessInstall {
@@ -399,33 +611,54 @@ export class HarnessInstall {
399
611
  if (this.stopping.signal.aborted)
400
612
  return Promise.reject(new Error("the server is stopping"));
401
613
  this.running ??= (async () => {
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 });
412
- return void (this.done = true);
614
+ // One installer at a time on this data: while another process holds the install, wait for it to settle, then look
615
+ // again (installed: done; failed while this waited on it: so is this; let go with nothing in: take the hold). A
616
+ // failure read at once, with no wait, is the last install's: its holder may be retrying it and not yet have written
617
+ // its own mark, so this looks again rather than failing in that old install's words.
618
+ let token;
619
+ while (!(token = await takeHold(this.dir))) {
620
+ if (this.stopping.signal.aborted)
621
+ throw new Error("the server is stopping");
622
+ let waited = false;
623
+ const settled = await installSettled(this.entry, this.dir, await this.pins(), { signal: this.stopping.signal, onWait: () => (waited = true) });
624
+ if (settled === "installed")
625
+ return void (this.done = true);
626
+ if (typeof settled === "object" && waited)
627
+ throw new Error(settled.failed);
628
+ await new Promise((resolve) => setTimeout(resolve, 250));
413
629
  }
414
- const started = performance.now();
415
630
  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)
631
+ // The mark a run's claim reads, in this process or a runner's own (installSettled): installing now, then gone once
632
+ // it is in, or why it failed. Written first, before anything is read, so a claim made as this install starts (a run
633
+ // started just after the save that started it) finds it; gone at once when the harness is installed already.
634
+ await writeMark(this.dir, { host: hostname(), pid: process.pid, startedAt: Date.now() });
635
+ const pins = await this.pins().catch(async (error) => {
421
636
  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;
637
+ throw error;
638
+ });
639
+ if (this.entry.lacking(this.dir, pins) === undefined) {
640
+ await rm(installMarkOf(this.dir), { force: true });
641
+ return void (this.done = true);
642
+ }
643
+ const started = performance.now();
644
+ try {
645
+ await this.install(this.entry, this.dir, pins, this.stopping.signal);
646
+ }
647
+ catch (error) {
648
+ // Why it failed, for the runs that waited on it; a server that stops leaves no mark (its npm was stopped, not refused).
649
+ if (this.stopping.signal.aborted)
650
+ await rm(installMarkOf(this.dir), { force: true }).catch(() => undefined);
651
+ else
652
+ await writeMark(this.dir, { failed: error.message, at: Date.now() }).catch(() => undefined);
653
+ throw error;
654
+ }
655
+ await rm(installMarkOf(this.dir), { force: true });
656
+ this.done = true;
657
+ this.onInstalled?.(Math.round(performance.now() - started));
658
+ }
659
+ finally {
660
+ await releaseHold(this.dir, token).catch(() => undefined);
425
661
  }
426
- await rm(installMarkOf(this.dir), { force: true });
427
- this.done = true;
428
- this.onInstalled?.(Math.round(performance.now() - started));
429
662
  })().finally(() => (this.running = undefined));
430
663
  return this.running;
431
664
  }
@@ -435,3 +668,58 @@ export class HarnessInstall {
435
668
  await this.running?.catch(() => undefined);
436
669
  }
437
670
  }
671
+ /** A runner's installs, by the directory each goes into: one HarnessInstall per directory in this process, which every
672
+ * claim that needs it waits on, and how many wait now. */
673
+ const claimInstalls = new Map();
674
+ /** Where a run's claim stands on the install into `dir`, as installSettled says, except that an install this process's
675
+ * claims run (installForClaim) is never waited on from outside: it reads "none", so the claim joins it by installForClaim
676
+ * and counts among those that wait for it. Waited on from outside, it would stop once the claim that started it let go,
677
+ * though this one still needed it, and start again. An install the server runs is waited on as before. */
678
+ export function claimSettled(entry, dir, pins, options = {}) {
679
+ const isAlive = options.isAlive ?? alive;
680
+ return installSettled(entry, dir, pins, { ...options, isAlive: (pid) => !(pid === process.pid && claimInstalls.has(dir)) && isAlive(pid) });
681
+ }
682
+ /** Installs `entry` into `dir` for a run's claim when nothing installs it (no install runs, or the last one failed before
683
+ * this claim): the claim installs it itself, by `lock` (default the one AgentRun ships), or waits for the install this
684
+ * process or another runs for it already; it resolves once it is in and rejects with the install's own words when it
685
+ * fails. `signal` aborted (the run stopped, its claim lost, the runner closing): this claim stops waiting at once, and the
686
+ * install's npm is stopped once no claim waits for it. `install`: what runs the install in place of npm (a test's). */
687
+ export async function installForClaim(entry, dir, pins, { lock, signal, install } = {}) {
688
+ let held = claimInstalls.get(dir);
689
+ if (!held) {
690
+ held = { install: new HarnessInstall(entry, dir, pins, install ?? ((entry, dir, pins, stop) => npmInstall(entry, dir, pins, { signal: stop, ...(lock ? { lock } : {}) }))), waiting: 0 };
691
+ claimInstalls.set(dir, held);
692
+ }
693
+ const mine = held;
694
+ mine.waiting += 1;
695
+ try {
696
+ const installing = mine.install.ensure();
697
+ installing.catch(() => undefined);
698
+ if (!signal)
699
+ return await installing;
700
+ signal.throwIfAborted();
701
+ await new Promise((resolve, reject) => {
702
+ const stop = () => reject(signal.reason);
703
+ signal.addEventListener("abort", stop, { once: true });
704
+ installing.then(resolve, reject).finally(() => signal.removeEventListener("abort", stop));
705
+ });
706
+ }
707
+ finally {
708
+ mine.waiting -= 1;
709
+ if (mine.waiting === 0 && claimInstalls.get(dir) === mine) {
710
+ claimInstalls.delete(dir);
711
+ // Nothing waits for it any more: its npm stops (nothing to stop once it is in or has failed). The claim goes on at
712
+ // once; the stop is kept until it ends, for the runner's close to wait on (claimInstallsStopped).
713
+ const stopping = mine.install.stop();
714
+ claimStops.add(stopping);
715
+ void stopping.finally(() => claimStops.delete(stopping));
716
+ }
717
+ }
718
+ }
719
+ /** The stops of the claims' installs under way (installForClaim). */
720
+ const claimStops = new Set();
721
+ /** Resolves once every install a claim let go of has stopped (its npm ended, SIGTERM then SIGKILL past its grace, its
722
+ * staging directory and hold gone): a runner's close waits for it before the process can end, so no npm outlives it. */
723
+ export async function claimInstallsStopped() {
724
+ await Promise.all([...claimStops]);
725
+ }
package/dist/harness.d.ts CHANGED
@@ -23,6 +23,7 @@ export type HarnessOffer = {
23
23
  * the memory a run of it reserves (`run_memory_mib`). */
24
24
  export type HarnessCapability = HarnessOffer & {
25
25
  default_model: string | null;
26
+ models: string[];
26
27
  run_memory_mib: number;
27
28
  };
28
29
  /** What this server offers of each harness, checked once per environment: each one's entry in the harness table says
package/dist/harness.js CHANGED
@@ -1,4 +1,4 @@
1
- // The harness that runs a revision: pi (pi-durable-disk's, the default and the one a revision that names none gets) or
1
+ // The harness that runs a revision: pi (the default and the one a revision that names none gets) or
2
2
  // one of the run adapters. A revision keeps the harness it names; the default is never stored, so a revision written
3
3
  // before this field existed and one that names pi are the same revision. Which harnesses this server runs is said in
4
4
  // capabilities, and a revision naming one it does not run saves with a warning and is refused at run time.
@@ -53,9 +53,43 @@ export function harnessOffers(env) {
53
53
  // Each harness's model when a definition names none, as a save and a run resolve it (runnable.ts): none for a
54
54
  // harness that does not run here, or that no model here would run on.
55
55
  const { harnessModel } = await import("./runnable.js");
56
+ const { pickerCandidates } = await import("./model-form.js");
56
57
  return Promise.all(base.map(async (offer) => {
57
58
  const resolved = offer.available ? await harnessModel(env, offer.id, undefined, true) : undefined;
58
- return { ...offer, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, run_memory_mib: harnessOf(env, offer.id).runMib };
59
+ // The models a person may pick for it (model-form.ts), each in the form it takes: those its entry's own choice
60
+ // takes (the catalog it runs on knows the id, a key may still be missing: a save warns of that, never refuses),
61
+ // so the picker never offers one a save would refuse. None for a harness that does not run here.
62
+ const entry = harnessOf(env, offer.id);
63
+ const models = [];
64
+ if (offer.available) {
65
+ // Each choice passes what a save and a run ask, by construction: the save's own shape check (MODEL_REF), the
66
+ // harness's own choice of it, and, on an adapter's wire, providerFor, the function a run starts with. A model
67
+ // the wire cannot take (a vendor it does not run, an endpoint a key may not go to) is not offered; one that
68
+ // lacks only a key is (a save warns of that, never refuses).
69
+ const { MODEL_REF } = await import("./validate.js");
70
+ const { providerFor, HarnessUnavailable } = await import("./provider.js");
71
+ const { ADAPTER_FACTS } = await import("./adapter-facts.js");
72
+ const { FAUX_ENV } = await import("./model.js");
73
+ const facts = ADAPTER_FACTS.find((f) => f.id === offer.id);
74
+ for (const id of pickerCandidates(env, offer.id)) {
75
+ if (!MODEL_REF.test(id))
76
+ continue;
77
+ const chosen = await entry.model(env, id, true);
78
+ if (!chosen || !("model" in chosen || chosen.needs === "key"))
79
+ continue;
80
+ if (facts && "model" in chosen && !env[FAUX_ENV]) {
81
+ try {
82
+ providerFor(facts.wire, env, chosen.model, offer.id);
83
+ }
84
+ catch (error) {
85
+ if (!(error instanceof HarnessUnavailable && error.keys?.length))
86
+ continue;
87
+ }
88
+ }
89
+ models.push(id);
90
+ }
91
+ }
92
+ return { ...offer, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, models, run_memory_mib: entry.runMib };
59
93
  }));
60
94
  })();
61
95
  offered.set(env, offers);
@@ -1,4 +1,4 @@
1
- import type { Context } from "@earendil-works/chord";
1
+ import type { Context } from "@earendil-works/chord/context";
2
2
  import { type ToolExecutionApi, type ToolRegistration } from "@earendil-works/pi-durable";
3
3
  import type { HostTool } from "@parcha/agentrun-kernel";
4
4
  export { workspaceRelative } from "./workspace-paths.js";
@@ -18,14 +18,14 @@ export type ToolResults = Map<string, {
18
18
  * nested-tool members) belongs to the tool task pi runs a tool in, which a host tool, called by another harness, has
19
19
  * none of: the full type cannot be built here, so a read of any other member throws, naming it, rather than reading as
20
20
  * "is not a function". `conversationId` is the run's root conversation, where a host tool's calls are made: serve's
21
- * browser-cost `capped` reads it, now that the browser binds as a host tool on the runner. `snapshot`, `conversation`
22
- * and `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
23
- * document, a conversation or a task of this run, never another's. A remote executor (workspace/executors.ts
24
- * piExecutor) has no run Harness and gives none of these four (RUN_ONLY_MEMBERS); the coding tools it runs read none.
21
+ * browser-cost `capped` reads it, now that the browser binds as a host tool on the runner. `snapshot` and
22
+ * `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
23
+ * document or a task of this run, never another's. A remote executor (workspace/executors.ts
24
+ * piExecutor) has no run Harness and gives none of these three (RUN_ONLY_MEMBERS); the coding tools it runs read none.
25
25
  * `memo` and `taskId` are a pi tool task's own, which a host tool runs in none of: they are not given here. */
26
- export declare const HOST_API_MEMBERS: readonly ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "conversation", "waitForTask"];
26
+ export declare const HOST_API_MEMBERS: readonly ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "waitForTask"];
27
27
  /** The members a host tool's api gives only on a run's Harness: a remote executor's api has none of them. */
28
- export declare const RUN_ONLY_MEMBERS: readonly ["conversationId", "snapshot", "conversation", "waitForTask"];
28
+ export declare const RUN_ONLY_MEMBERS: readonly ["conversationId", "snapshot", "waitForTask"];
29
29
  /** What one host tool's call reads of the run: the run's environment (its file environment, the api's `env`), its
30
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
31
  * paid-call money seam, over the runner's claim Harness (runner/adapter-run-spec.ts). */
@@ -36,10 +36,9 @@ export interface HostToolCtx {
36
36
  env(): Promise<ToolExecutionApi["env"]>;
37
37
  readonly commit: ToolExecutionApi["commit"];
38
38
  readonly agent: ToolExecutionApi["agent"];
39
- /** The run's own Harness's snapshot, conversation and waitForTask (run.harness, the claim's journal on the runner), as
40
- * `commit` is: a document, conversation or task of this run only. */
39
+ /** The run's own Harness's snapshot and waitForTask (run.harness, the claim's journal on the runner), as
40
+ * `commit` is: a document or task of this run only. */
41
41
  readonly snapshot: ToolExecutionApi["snapshot"];
42
- readonly conversation: ToolExecutionApi["conversation"];
43
42
  readonly waitForTask: ToolExecutionApi["waitForTask"];
44
43
  /** 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,
45
44
  * 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
@@ -18,14 +18,14 @@ export { cutUtf8, MAX_BYTES, MAX_LINES } from "./workspace/executors.js";
18
18
  * nested-tool members) belongs to the tool task pi runs a tool in, which a host tool, called by another harness, has
19
19
  * none of: the full type cannot be built here, so a read of any other member throws, naming it, rather than reading as
20
20
  * "is not a function". `conversationId` is the run's root conversation, where a host tool's calls are made: serve's
21
- * browser-cost `capped` reads it, now that the browser binds as a host tool on the runner. `snapshot`, `conversation`
22
- * and `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
23
- * document, a conversation or a task of this run, never another's. A remote executor (workspace/executors.ts
24
- * piExecutor) has no run Harness and gives none of these four (RUN_ONLY_MEMBERS); the coding tools it runs read none.
21
+ * browser-cost `capped` reads it, now that the browser binds as a host tool on the runner. `snapshot` and
22
+ * `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
23
+ * document or a task of this run, never another's. A remote executor (workspace/executors.ts
24
+ * piExecutor) has no run Harness and gives none of these three (RUN_ONLY_MEMBERS); the coding tools it runs read none.
25
25
  * `memo` and `taskId` are a pi tool task's own, which a host tool runs in none of: they are not given here. */
26
- export const HOST_API_MEMBERS = ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "conversation", "waitForTask"];
26
+ export const HOST_API_MEMBERS = ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "waitForTask"];
27
27
  /** The members a host tool's api gives only on a run's Harness: a remote executor's api has none of them. */
28
- export const RUN_ONLY_MEMBERS = ["conversationId", "snapshot", "conversation", "waitForTask"];
28
+ export const RUN_ONLY_MEMBERS = ["conversationId", "snapshot", "waitForTask"];
29
29
  const hostApi = (given) => new Proxy(given, {
30
30
  get: (target, key) => {
31
31
  if (typeof key === "symbol" || key === "then" || Object.hasOwn(target, key))
@@ -68,7 +68,7 @@ export function hostToolOf(name, tool, ctx) {
68
68
  agent: ctx.agent,
69
69
  models: createModels(),
70
70
  conversationId: ROOT_CONVERSATION_ID,
71
- snapshot: ctx.snapshot, conversation: ctx.conversation, waitForTask: ctx.waitForTask,
71
+ snapshot: ctx.snapshot, waitForTask: ctx.waitForTask,
72
72
  });
73
73
  // A tool that throws (bash on a non-zero exit or a timeout) still answers with its output, as pi's harness does;
74
74
  // monid's answer a failure as an error result, which is kept as it is.
@@ -23,8 +23,9 @@ export declare const OPENAI_SEARCH_LIMIT: Readonly<{
23
23
  }>;
24
24
  /** $10 per 1,000 searches (Anthropic) or calls (OpenAI). */
25
25
  export declare const SEARCH_USD = 0.01;
26
- /** The run's models, marked and capped, handed over by the run's app before its tools are bound. */
27
- export declare function searchOn(models: Models): void;
26
+ /** What a hosted search asks: the run's models a search request goes through (on the runner, the session's port: its
27
+ * proxy, policy, key, price and cap), handed to each search by its run, never kept per process. */
28
+ export type SearchModels = Pick<Models, "getModel" | "completeSimple">;
28
29
  /** `query` searched by `ref`'s provider (`provider/model-id`, the model the server resolved web_search on) through the
29
- * run's models, at most `n` results: a Search. `models`: the run's (searchOn). */
30
- export declare function hostedSearch(query: string, n: number, ref: string | undefined, signal?: AbortSignal, models?: Models | undefined): Promise<Search>;
30
+ * run's models (`models`: its own, handed by the run; none, no model to search on), at most `n` results: a Search. */
31
+ export declare function hostedSearch(query: string, n: number, ref: string | undefined, signal: AbortSignal | undefined, models: SearchModels | undefined): Promise<Search>;
@@ -21,11 +21,6 @@ const BLOCK_BILLED = /^gpt-(?:4o|4\.1)-mini(?:-|$)/;
21
21
  const ANSWER_TOKENS = 2_048;
22
22
  /** As Exa's and Parallel's searches stop. */
23
23
  const TIMEOUT_MS = 60_000;
24
- let runModels;
25
- /** The run's models, marked and capped, handed over by the run's app before its tools are bound. */
26
- export function searchOn(models) {
27
- runModels = models;
28
- }
29
24
  const list = (value) => (Array.isArray(value) ? value.filter((item) => typeof item === "object" && item !== null) : []);
30
25
  const text = (value) => (typeof value === "string" ? value : undefined);
31
26
  /** What a provider's events say of the search: its results by URL, first seen first, and how many searches it ran. */
@@ -90,8 +85,8 @@ function reader(anthropic) {
90
85
  };
91
86
  }
92
87
  /** `query` searched by `ref`'s provider (`provider/model-id`, the model the server resolved web_search on) through the
93
- * run's models, at most `n` results: a Search. `models`: the run's (searchOn). */
94
- export async function hostedSearch(query, n, ref, signal, models = runModels) {
88
+ * run's models (`models`: its own, handed by the run; none, no model to search on), at most `n` results: a Search. */
89
+ export async function hostedSearch(query, n, ref, signal, models) {
95
90
  const slash = ref?.indexOf("/") ?? -1;
96
91
  const provider = ref && slash > 0 ? ref.slice(0, slash) : undefined;
97
92
  const id = ref && slash > 0 ? ref.slice(slash + 1) : undefined;
@@ -69,6 +69,12 @@ export type Session = {
69
69
  /** The whole session's cost, when the source records it; absent is unknown. */
70
70
  costUsd?: number;
71
71
  firstPrompt?: string;
72
+ /** The source's own title for the session, as Claude Code shows it: the person's (/rename's custom-title), else the one
73
+ * it wrote itself (ai-title; summary in older files, the one whose last message this session holds), the latest. */
74
+ sourceTitle?: string;
75
+ /** The first of the person's own words (personsWords): the first user text that is not a CLI's command, its output or
76
+ * its preamble. The run's title when the source wrote none. */
77
+ titleText?: string;
72
78
  /** A subagent's or another session's child: not imported as a run; its usage is its parent's. */
73
79
  child: boolean;
74
80
  /** A child's parent session, when its file names it (Codex's parent thread). */
@@ -102,3 +108,7 @@ export declare function readSession(file: string, source: Source, { turns: keep,
102
108
  }): Promise<Session>;
103
109
  /** The effort most of `turns`' requests ran at, as the model of most requests is a run's model: the first seen of a tie. */
104
110
  export declare function mostEffortOf(turns: readonly Turn[]): string | undefined;
111
+ /** The person's own words in a user message's text, as they wrote them (spaces and lines kept, so a cut still matches
112
+ * a secret in them): none when the CLI wrote all of it (a slash command, its output, its preamble), or when there are
113
+ * no words at all. */
114
+ export declare function personsWords(text: string): string | undefined;