@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
package/dist/catalog.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // The tool catalog's names, and the one mapping between a catalog name and the wire name a harness calls. A catalog name
2
2
  // is what a revision writes (`read`, later `monid.discover`, `mcp:<server>/<tool>`); the wire name is what a CLI adapter
3
3
  // registers and the model API sees, and both adapters refuse anything outside /^[A-Za-z0-9_-]{1,64}$/. The map is one
4
- // deterministic, reversible function here, never in an adapter, so every harness gets the same wire name; the journal
5
- // records the wire name (recovery matches a call by it), and a reader maps it back to the catalog name on the way out.
4
+ // deterministic function here, never in an adapter, so every harness gets the same wire name; the journal records the
5
+ // wire name (recovery matches a call by it), and a reader maps it back to the catalog name by a lookup, never a parse.
6
6
  import { createHash } from "node:crypto";
7
7
  /** A wire name: at most 52 characters, not the adapter's 64. One CLI gives the model the name with a 12-character
8
8
  * `mcp__hands__` prefix, and the model API's 64-character limit is on the name the model sees, so 52 is the budget that
@@ -11,8 +11,7 @@ import { createHash } from "node:crypto";
11
11
  export const WIRE_NAME = /^[A-Za-z0-9_-]{1,52}$/;
12
12
  /** A catalog name's wire name: itself when it already is one within the budget, else `:` and `/` to `__`, `.` to `_`,
13
13
  * any other character to `_`, and a `-<8 hex of the catalog name>` suffix (prefix trimmed to fit) when the result is
14
- * too long. The suffix makes a long name unique; a collision between two names is refused at the save (collisions,
15
- * reverseOf), never suffixed away. The reverse is a lookup, never a parse. */
14
+ * too long. The suffix makes a long name unique. */
16
15
  export function wireName(catalog) {
17
16
  if (WIRE_NAME.test(catalog))
18
17
  return catalog;
@@ -22,32 +21,3 @@ export function wireName(catalog) {
22
21
  const tag = `-${createHash("sha256").update(catalog).digest("hex").slice(0, 8)}`;
23
22
  return base.slice(0, 52 - tag.length) + tag;
24
23
  }
25
- /** The reverse of {@link wireName} over `names`: a map from each name's wire name back to the catalog name. A collision
26
- * (two catalog names with one wire name) throws here, so a catalog that would shadow a name never loads; the save path
27
- * reports the same collision as a 422 before it reaches this. */
28
- export function reverseOf(names) {
29
- const reverse = new Map();
30
- for (const name of names) {
31
- const wire = wireName(name);
32
- const had = reverse.get(wire);
33
- if (had !== undefined && had !== name)
34
- throw new Error(`the tools ${had} and ${name} both map to the wire name ${wire}`);
35
- reverse.set(wire, name);
36
- }
37
- return reverse;
38
- }
39
- /** The catalog names in `names` whose wire names collide, each paired with the name it clashes with: a definition that
40
- * holds a pair is refused (a 422 on the second one), so {@link reverseOf} never throws for a loaded catalog. */
41
- export function collisions(names) {
42
- const seen = new Map();
43
- const clashes = [];
44
- for (const name of names) {
45
- const wire = wireName(name);
46
- const had = seen.get(wire);
47
- if (had !== undefined && had !== name)
48
- clashes.push({ name, clashesWith: had });
49
- else
50
- seen.set(wire, name);
51
- }
52
- return clashes;
53
- }
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ import { startedWith } from "./adapters.js";
14
14
  import { REPEAT_MS, stopOnSignals } from "./stop-signals.js";
15
15
  import { canOpen } from "./host.js";
16
16
  import { resetPassword } from "./owner.js";
17
- import { banner, boxImageLine } from "./print.js";
17
+ import { banner } from "./print.js";
18
18
  import { DEFAULT_PORT, fauxEnvOf, startServe } from "./server.js";
19
19
  import { besideRunnerOptions, besideStopping, runnerBeside } from "./runner/beside.js";
20
20
  import { apiOnlyFrom } from "./api-only.js";
@@ -65,7 +65,9 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
65
65
  more \`agentrun-serve runner --data DIR\` processes on the same data directory to claim and run runs;
66
66
  each holds at most --loops N runs (default AGENTRUN_MAX_RUNS, else as many pi runs as its host's
67
67
  memory holds; the rest wait queued) and on SIGTERM lets each busy run finish its turn for up to
68
- --drain-timeout D (default AGENTRUN_DRAIN_TIMEOUT, else 6s), then hands the rest back to resume
68
+ --drain-timeout D (default AGENTRUN_DRAIN_TIMEOUT, else 6s), then hands the rest back to resume.
69
+ A paired computer (Settings → Computers → Pair a computer) dials the server's process, so only the
70
+ runner beside it can use one: separate runners refuse a run whose agent names one
69
71
 
70
72
  Without --faux, a revision's model ("provider/model-id", or AGENT_MODEL when it names none; a workflow node's tier maps
71
73
  to AGENT_MODEL_FAST or AGENT_MODEL_STRONG, each falling back to AGENT_MODEL) is served by pi-ai's providers with their
@@ -76,8 +78,9 @@ published port, or a proxy's URL), and the link printed uses it; with none, Rend
76
78
  end, and per refused credential; AGENTRUN_LOG=quiet leaves out the request lines.
77
79
 
78
80
  AGENTRUN_API_ONLY=1 serves the run routes alone, for a server behind its caller's backend: a run's launch, read, list,
79
- timeline, messages, stop, cancel, kill and cap raise, its files and uploads, capabilities, health and usage. Every other
80
- address (the page, sign-in, setup, settings, MCP, triggers and their hooks, agents) is a 404, and there are no accounts.
81
+ timeline, messages, stop, cancel, kill and cap raise, its files and uploads, an agent's Archil disk, capabilities, health
82
+ and usage. Every other address (the page, sign-in, setup, settings, MCP, triggers and their hooks, the rest of agents)
83
+ is a 404, and there are no accounts.
81
84
 
82
85
  The page is for one person, who signs in with a password (AGENTRUN_ACCOUNTS=0 turns this off; the token works for
83
86
  scripts and the CLI either way). With no AGENTRUN_PUBLIC_URL, listening on loopback, the first visit to the page sets the
@@ -86,6 +89,8 @@ per address (an IPv6 one by its /64) and wrong passwords per server; past the li
86
89
  Behind a proxy, set AGENTRUN_TRUSTED_PROXIES to its addresses or ranges (comma-separated; or loopback, linklocal,
87
90
  uniquelocal) so each visitor counts by the address its X-Forwarded-For names; unset, that header is never read. Forgot the password: \`agentrun-serve reset-password --data DIR\` where the
88
91
  data directory is (inside the container) clears it and signs every browser out, and the next visit sets a new one.
92
+ An MCP server on loopback (a 127.0.0.1 or localhost address) is refused unless AGENTRUN_MCP_ALLOW_LOOPBACK=1 is set at the
93
+ start: set it only on a machine you alone use, since loopback is this machine's other services too.
89
94
 
90
95
  \`agentrun-serve import\` reads the Claude Code, Codex and pi sessions in your own home (~/.claude/projects,
91
96
  ~/.codex/sessions, ~/.pi/agent/sessions) into the data directory, once: each project directory an agent, with its
@@ -332,21 +337,6 @@ catch (error) {
332
337
  process.exit(2);
333
338
  }
334
339
  const accounts = !apiOnly && process.env.AGENTRUN_ACCOUNTS !== "0";
335
- // The Docker box image's first build said in words, as it starts and as it ends (print.ts boxImageLine); a line told
336
- // before the banner is printed waits for it.
337
- let imageSaid = false;
338
- let bannered = false;
339
- const early = [];
340
- const onBoxImage = (state) => {
341
- const line = boxImageLine(state, imageSaid);
342
- if (line === undefined)
343
- return;
344
- imageSaid = true;
345
- if (bannered)
346
- console.log(line);
347
- else
348
- early.push(line);
349
- };
350
340
  // How it was started, for the hints that start it again (adapters.ts npxLine): itself and its runs read it.
351
341
  Object.assign(process.env, startedWith({ ...(values.port !== undefined ? { port: values.port } : {}), open: values.open === true }));
352
342
  let serve;
@@ -354,7 +344,6 @@ let serveOptions;
354
344
  const trustedProxies = (process.env.AGENTRUN_TRUSTED_PROXIES ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
355
345
  try {
356
346
  serve = await startServe(serveOptions = {
357
- onBoxImage,
358
347
  // The owner lock on a Postgres store lost for good: this server can serve nothing more, so it exits non-zero and its
359
348
  // platform starts it again, rather than answer 503 for as long as it runs.
360
349
  onStoreLost: (error) => {
@@ -369,6 +358,8 @@ try {
369
358
  ...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}), ...(apiOnly ? { apiOnly } : {}),
370
359
  // The proxies whose X-Forwarded-For the sign-in limit reads (comma-separated); none unless set.
371
360
  ...(trustedProxies.length ? { trustedProxies } : {}),
361
+ // A local install only as its operator says, never inferred: an MCP server on loopback is refused without it.
362
+ ...(process.env.AGENTRUN_MCP_ALLOW_LOOPBACK === "1" ? { mcpLoopback: true } : {}),
372
363
  });
373
364
  }
374
365
  catch (error) {
@@ -390,8 +381,11 @@ if (!values["no-runner"] && askedAt === undefined) {
390
381
  // model up in pi-ai's own catalog and every run fails on its first request. A test switch this process inherited from
391
382
  // its shell is taken out first, as the server's own environment drops it (runner/main.ts besideRunEnv).
392
383
  const { besideRunEnv } = await import("./runner/main.js");
393
- // With the computer janitor: what a crashed runner of this server left is ended (never under --faux).
394
- runnerProc = await runnerBeside(data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true });
384
+ // With the computer janitor: what a crashed runner of this server left is ended (never under --faux). With the
385
+ // server's AttachHub: a paired computer's socket is in this process, so only this runner takes one (--no-runner's
386
+ // separate runners refuse it in words). Its runs reach an MCP server on loopback only when this server is a local
387
+ // install (Serve.localInstall).
388
+ runnerProc = await runnerBeside(data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true, hub: serve.attachHub, mcpLoopback: serve.localInstall });
395
389
  }
396
390
  catch (error) {
397
391
  console.error(`agentrun-serve: the runner could not start: ${error.message}`);
@@ -401,15 +395,12 @@ if (!values["no-runner"] && askedAt === undefined) {
401
395
  }
402
396
  // A token from the environment is the operator's already, and the stored one is printed by the start that made it only.
403
397
  const source = given ? "env" : serve.tokenMade ? "made" : "file";
404
- for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token: serve.token, source, accounts, ...(apiOnly ? { apiOnly } : {}), boxes: serve.boxesLine, ...(values.listen ? { listen: values.listen } : {}), ...(publicUrl ? { publicUrl } : {}) }))
398
+ for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token: serve.token, source, accounts, ...(apiOnly ? { apiOnly } : {}), ...(serve.launchCode ? { launchCode: serve.launchCode } : {}), boxes: serve.boxesLine, ...(values.listen ? { listen: values.listen } : {}), ...(publicUrl ? { publicUrl } : {}) }))
405
399
  console.log(line);
406
400
  // Open setup (no public address, a loopback listener): the link that sets the password. Any other start printed the
407
401
  // setup link with its code as the code was made (owner.ts).
408
402
  if (serve.setupUrl && serve.setupOpen)
409
403
  console.log(`Set your password: ${serve.setupUrl} (the first visit sets it)`);
410
- bannered = true;
411
- for (const line of early.splice(0))
412
- console.log(line);
413
404
  // The console's page, once the server listens: never its sign-in link, whose token would sit in the opener's arguments
414
405
  // and the browser's history.
415
406
  // API-only: there is no console, so nothing to open.
@@ -0,0 +1,36 @@
1
+ /** Another Composio than the real one, and its fetch: a test's fake (the same seam as `archilControl`). */
2
+ export type ComposioControl = {
3
+ readonly baseUrl?: string;
4
+ readonly fetch?: typeof fetch;
5
+ };
6
+ export type ComposioTool = {
7
+ slug: string;
8
+ name: string;
9
+ description: string;
10
+ };
11
+ /** POST /settings/mcp-servers/composio/tools: a toolkit's actions, for the console's picker, and whether it needs no sign-in. */
12
+ export declare function composioTools(body: unknown, control: ComposioControl, signal?: AbortSignal): Promise<{
13
+ toolkit: string;
14
+ no_auth: boolean;
15
+ tools: ComposioTool[];
16
+ }>;
17
+ /** The address Composio's generate answers, made one this server's client can use: the helper actions that connect an
18
+ * account left off, and the path ended in /mcp (Composio redirects the bare one, which the client refuses on purpose). */
19
+ export declare function composioAddress(generated: string): string;
20
+ /** PUT /settings/mcp-servers/{name}/composio: Composio makes the managed MCP server, `save` keeps it as a saved MCP server
21
+ * (`{url, auth}`: the key a sealed header), and a toolkit that needs the person's account says where to connect it. */
22
+ export declare function composioSave<T extends {
23
+ tools?: readonly {
24
+ name: string;
25
+ }[];
26
+ }>(body: unknown, control: ComposioControl, save: (mcp: {
27
+ url: string;
28
+ auth: {
29
+ type: "headers";
30
+ headers: Record<string, string>;
31
+ };
32
+ }) => Promise<T>, name: string, signal?: AbortSignal, savedUrl?: () => Promise<string | undefined>): Promise<{
33
+ server: T;
34
+ connect_url?: string;
35
+ not_served?: string[];
36
+ }>;
@@ -0,0 +1,179 @@
1
+ // The Composio preset in Settings → MCP servers. Composio is an MCP server like any other: the owner gives an API key, a
2
+ // toolkit and the actions to grant, this file has Composio make a managed MCP server for them (plain fetch, its REST API),
3
+ // and the result is saved through the one MCP save (mcp-servers-store.ts) with the key as a sealed x-api-key header. No
4
+ // adapter, no auth type, no key row of its own: after the save a Composio server is a saved MCP server, gated and
5
+ // metered like every other. The four meta tools Composio adds (serve/src/mcp-meta.ts) stay refused; the helper actions
6
+ // that connect an account are left off the server's address. The key goes only to Composio and into the sealed header: it
7
+ // is never logged, echoed or put in an error.
8
+ import { randomBytes } from "node:crypto";
9
+ import { ApiError, invalid } from "./errors.js";
10
+ import { isObject } from "./validate.js";
11
+ const BASE = "https://backend.composio.dev";
12
+ /** The one Composio user a server's actions run as, unless the owner names another. */
13
+ const USER = "agentrun";
14
+ const TOOLKIT = /^[a-z0-9][a-z0-9_-]{0,63}$/;
15
+ const USER_ID = /^[A-Za-z0-9._@-]{1,128}$/;
16
+ const PAGE = 200;
17
+ const MAX_PAGES = 10;
18
+ const MAX_TOOLS = 500;
19
+ const WAIT_MS = 20_000;
20
+ const text = (value) => (typeof value === "string" ? value : "");
21
+ const issue = (field, reason, message) => ({ field, reason, message });
22
+ /** A Composio call as `key`: its JSON answer, or an error in words that name `step` and never the key. */
23
+ function asking(control, key, signal) {
24
+ const base = (control.baseUrl ?? BASE).replace(/\/+$/, "");
25
+ const send = control.fetch ?? fetch;
26
+ const scrub = (said) => said.split(key).join("[the key]").slice(0, 300);
27
+ return async (step, method, path, body, missing) => {
28
+ let res;
29
+ let raw;
30
+ try {
31
+ // No redirect is followed: it would carry the key to wherever it points.
32
+ res = await send(`${base}${path}`, {
33
+ method, redirect: "error", signal: AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(WAIT_MS)]),
34
+ headers: { "x-api-key": key, accept: "application/json", ...(body === undefined ? {} : { "content-type": "application/json" }) },
35
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
36
+ });
37
+ raw = await res.text();
38
+ }
39
+ catch {
40
+ throw new ApiError("upstream_failed", `Composio did not answer while ${step}: nothing was saved.`);
41
+ }
42
+ let json;
43
+ try {
44
+ json = JSON.parse(raw);
45
+ }
46
+ catch { /* not JSON: said below */ }
47
+ if (res.ok) {
48
+ if (isObject(json))
49
+ return json;
50
+ throw new ApiError("upstream_failed", `Composio's answer while ${step} was not JSON: nothing was saved.`);
51
+ }
52
+ const said = isObject(json) && isObject(json.error) ? text(json.error.message) : isObject(json) ? text(json.message) : "";
53
+ if (res.status === 401 || res.status === 403)
54
+ throw invalid([issue("api_key", "refused", `Composio refused the API key while ${step}: check it in Composio's dashboard.`)]);
55
+ if (res.status === 404 && missing)
56
+ throw invalid([issue("toolkit", "not_found", missing)]);
57
+ if (res.status >= 400 && res.status < 500)
58
+ throw invalid([issue("body", "refused", `Composio refused the request while ${step} (${res.status})${said ? `: ${scrub(said)}` : ""}.`)]);
59
+ throw new ApiError("upstream_failed", `Composio failed while ${step} (${res.status}): nothing was saved.`);
60
+ };
61
+ }
62
+ /** The key and toolkit of a body, checked. */
63
+ function head(body) {
64
+ if (!isObject(body))
65
+ throw invalid([issue("body", "invalid", "The body is {api_key, toolkit}.")]);
66
+ const key = typeof body.api_key === "string" ? body.api_key.trim() : "";
67
+ const toolkit = typeof body.toolkit === "string" ? body.toolkit.trim().toLowerCase() : "";
68
+ const issues = [];
69
+ if (!key || key.length > 8192)
70
+ issues.push(issue("api_key", "missing", "Send your Composio API key."));
71
+ if (!TOOLKIT.test(toolkit))
72
+ issues.push(issue("toolkit", "invalid", "Send the toolkit's slug as Composio names it (github, slack, gmail...)."));
73
+ if (issues.length)
74
+ throw invalid(issues);
75
+ return { key, toolkit, rest: body };
76
+ }
77
+ /** Whether a toolkit needs no sign-in. Composio's answer for one toolkit has no `no_auth` field (only its toolkit list
78
+ * does): it says so as every auth mode in `auth_config_details` being NO_AUTH. */
79
+ function needsNoAuth(kit) {
80
+ if (kit.no_auth === true)
81
+ return true;
82
+ const modes = Array.isArray(kit.auth_config_details) ? kit.auth_config_details.map((d) => (isObject(d) ? text(d.mode) : "")) : [];
83
+ return modes.length > 0 && modes.every((mode) => mode === "NO_AUTH");
84
+ }
85
+ const notFound = (toolkit) => `Composio has no toolkit ${toolkit}: use its slug (github, slack, gmail...).`;
86
+ /** POST /settings/mcp-servers/composio/tools: a toolkit's actions, for the console's picker, and whether it needs no sign-in. */
87
+ export async function composioTools(body, control, signal) {
88
+ const { key, toolkit } = head(body);
89
+ const ask = asking(control, key, signal);
90
+ const kit = await ask("reading the toolkit", "GET", `/api/v3/toolkits/${encodeURIComponent(toolkit)}`, undefined, notFound(toolkit));
91
+ const tools = [];
92
+ let cursor;
93
+ for (let page = 0; page < MAX_PAGES; page++) {
94
+ const listed = await ask("listing the toolkit's actions", "GET", `/api/v3/tools?toolkit_slug=${encodeURIComponent(toolkit)}&limit=${PAGE}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`, undefined, notFound(toolkit));
95
+ for (const item of Array.isArray(listed.items) ? listed.items : [])
96
+ if (isObject(item) && text(item.slug))
97
+ tools.push({ slug: text(item.slug), name: text(item.name) || text(item.slug), description: text(item.description) });
98
+ cursor = text(listed.next_cursor) || undefined;
99
+ if (!cursor)
100
+ break;
101
+ }
102
+ return { toolkit, no_auth: needsNoAuth(kit), tools };
103
+ }
104
+ /** The address Composio's generate answers, made one this server's client can use: the helper actions that connect an
105
+ * account left off, and the path ended in /mcp (Composio redirects the bare one, which the client refuses on purpose). */
106
+ export function composioAddress(generated) {
107
+ const url = new URL(generated);
108
+ url.searchParams.delete("include_composio_helper_actions");
109
+ const path = url.pathname.replace(/\/+$/, "");
110
+ url.pathname = path.endsWith("/mcp") ? path : `${path}/mcp`;
111
+ return url.href;
112
+ }
113
+ /** PUT /settings/mcp-servers/{name}/composio: Composio makes the managed MCP server, `save` keeps it as a saved MCP server
114
+ * (`{url, auth}`: the key a sealed header), and a toolkit that needs the person's account says where to connect it. */
115
+ export async function composioSave(body, control, save, name, signal, savedUrl) {
116
+ const { key, toolkit, rest } = head(body);
117
+ const tools = Array.isArray(rest.tools) ? rest.tools : [];
118
+ const user = rest.user_id === undefined ? USER : typeof rest.user_id === "string" ? rest.user_id : "";
119
+ const issues = [];
120
+ if (!tools.length || tools.length > MAX_TOOLS || !tools.every((t) => typeof t === "string" && t))
121
+ issues.push(issue("tools", "invalid", `Send the slugs of the actions to grant: 1 to ${MAX_TOOLS} of them.`));
122
+ if (!USER_ID.test(user))
123
+ issues.push(issue("user_id", "invalid", "A user_id is letters, digits and . _ @ - (at most 128)."));
124
+ if (issues.length)
125
+ throw invalid(issues);
126
+ const ask = asking(control, key, signal);
127
+ const kit = await ask("reading the toolkit", "GET", `/api/v3/toolkits/${encodeURIComponent(toolkit)}`, undefined, notFound(toolkit));
128
+ const noAuth = needsNoAuth(kit);
129
+ let authConfig;
130
+ if (!noAuth) {
131
+ const configs = await ask("finding the toolkit's auth config", "GET", `/api/v3/auth_configs?toolkit_slug=${encodeURIComponent(toolkit)}`);
132
+ const managed = (Array.isArray(configs.items) ? configs.items : []).find((c) => isObject(c) && c.is_composio_managed === true && c.status !== "DISABLED" && text(c.id));
133
+ authConfig = managed ? text(managed.id) : undefined;
134
+ if (!authConfig) {
135
+ const made = await ask("making the toolkit's auth config", "POST", "/api/v3/auth_configs", { toolkit: { slug: toolkit }, auth_config: { type: "use_composio_managed_auth" } });
136
+ authConfig = isObject(made.auth_config) ? text(made.auth_config.id) : "";
137
+ if (!authConfig)
138
+ throw new ApiError("upstream_failed", "Composio made no auth config: nothing was saved.");
139
+ }
140
+ }
141
+ const made = await ask("making the MCP server", "POST", "/api/v3.1/mcp/servers/custom", {
142
+ name: `ar-${name.slice(0, 18)}-${randomBytes(3).toString("hex")}`, toolkits: [toolkit], ...(authConfig ? { auth_config_ids: [authConfig] } : {}), allowed_tools: tools, managed_auth_via_composio: true,
143
+ });
144
+ const id = text(made.id);
145
+ if (!id)
146
+ throw new ApiError("upstream_failed", "Composio made no MCP server: nothing was saved.");
147
+ // From here a failure deletes the server Composio just made, so a failed save leaves nothing in the person's account
148
+ // (best effort: the save's own error is the one answered). Not when the local entry was written before the save failed
149
+ // (its flush, say): `savedUrl` reads the name's saved address, and one that is this server's keeps it.
150
+ let url;
151
+ try {
152
+ const generated = await ask("making the MCP server's address", "POST", "/api/v3.1/mcp/servers/generate", { mcp_server_id: id, user_ids: [user], managed_auth_by_composio: true });
153
+ const address = Array.isArray(generated.user_ids_url) ? text(generated.user_ids_url[0]) : "";
154
+ if (!address)
155
+ throw new ApiError("upstream_failed", "Composio gave no address for the MCP server: nothing was saved.");
156
+ let connect;
157
+ if (authConfig) {
158
+ // Only an account under this server's auth config serves it: one ACTIVE under another config (a custom one) doesn't.
159
+ const accounts = await ask("checking the connected account", "GET", `/api/v3/connected_accounts?user_ids=${encodeURIComponent(user)}&toolkit_slugs=${encodeURIComponent(toolkit)}&auth_config_ids=${encodeURIComponent(authConfig)}`);
160
+ if (!(Array.isArray(accounts.items) ? accounts.items : []).some((a) => isObject(a) && a.status === "ACTIVE" && isObject(a.auth_config) && a.auth_config.id === authConfig)) {
161
+ const link = await ask("making the connect link", "POST", "/api/v3/connected_accounts/link", { auth_config_id: authConfig, user_id: user });
162
+ connect = text(link.redirect_url) || undefined;
163
+ }
164
+ }
165
+ url = composioAddress(address);
166
+ const server = await save({ url, auth: { type: "headers", headers: { "x-api-key": key } } });
167
+ // Composio's server can leave out an action it was allowed (HACKERNEWS_GET_FRONTPAGE, live 11-13): say which, so a grant
168
+ // doesn't vanish without a word. A toolkit with no account yet still lists its actions, so this holds before the connect.
169
+ const listed = new Set((server.tools ?? []).map((tool) => tool.name));
170
+ const missing = tools.filter((slug) => !listed.has(slug));
171
+ return { server, ...(connect ? { connect_url: connect } : {}), ...(missing.length ? { not_served: missing } : {}) };
172
+ }
173
+ catch (error) {
174
+ if (url && savedUrl && (await savedUrl().catch(() => undefined)) === url)
175
+ throw error;
176
+ await ask("deleting the MCP server it made", "DELETE", `/api/v3.1/mcp/${encodeURIComponent(id)}`).catch(() => undefined);
177
+ throw error;
178
+ }
179
+ }
@@ -0,0 +1,125 @@
1
+ import type { IncomingMessage } from "node:http";
2
+ import type { Duplex } from "node:stream";
3
+ import { type AttachHub, type AttachSocket, type HelloResult } from "@parcha/agentrun-computer";
4
+ import { type WebSocket } from "ws";
5
+ import type { PairedComputerRow, PairedComputers } from "./store/index.js";
6
+ /** The characters of a pairing code: no 0, O, 1 or I, so a person reads it off a screen without a doubt. */
7
+ export declare const PAIRING_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
8
+ /** A computer's token starts with this, so a secret scanner knows one. */
9
+ export declare const ATTACH_TOKEN_PREFIX = "art_";
10
+ /** Pair tries a source address makes in a minute; the next waits. */
11
+ export declare const PAIR_TRIES_PER_MINUTE = 10;
12
+ /** The longest name a person gives a computer, in characters. */
13
+ export declare const PAIRED_NAME_MAX = 100;
14
+ /** What the store keeps of a secret: its SHA-256, in hex. */
15
+ export declare const sha256Hex: (value: string) => string;
16
+ /** A new pairing code: eight characters of PAIRING_ALPHABET in two groups of four ("K7PD-W3QX"). */
17
+ export declare function newPairingCode(pick?: (below: number) => number): string;
18
+ /** A code as a person typed it, in its one form ("k7pd w3qx" is "K7PD-W3QX"), or undefined when it is not one. */
19
+ export declare function pairingCodeOf(typed: unknown): string | undefined;
20
+ /** A new paired computer's id: PAIRED_ID_PREFIX and 16 lowercase letters and digits. */
21
+ export declare const newPairedId: (pick?: (below: number) => number) => string;
22
+ /** A new computer token: ATTACH_TOKEN_PREFIX and 32 random bytes. */
23
+ export declare const newAttachToken: () => string;
24
+ /** `reason` cut to what a close frame holds (123 bytes of UTF-8), never inside a character. */
25
+ export declare function closeReason(reason: string): string;
26
+ /** The pair route's limit: PAIR_TRIES_PER_MINUTE tries a minute by source address (peerKey: an IPv6 one by its /64). */
27
+ export declare class PairTries {
28
+ #private;
29
+ private readonly now;
30
+ private readonly peers;
31
+ constructor(now?: () => number, peers?: number);
32
+ /** Counts a try from `address`: ok, or how long until the next is let in. */
33
+ allow(address: string): {
34
+ ok: true;
35
+ } | {
36
+ ok: false;
37
+ retryAfterMs: number;
38
+ };
39
+ }
40
+ /** POST /v2/computers/pair's body checked: its code in its one form, the name, and the driver's hello; or input_invalid
41
+ * naming each field that is wrong. The protocol version is the caller's next check (pairRefusal), not this one's. */
42
+ export declare function pairBodyOf(body: unknown): {
43
+ code: string;
44
+ name: string;
45
+ hello: HelloResult;
46
+ };
47
+ /** Why a driver's hello may not pair here, in the version rule's words (attach.ts helloMismatch), or undefined: its
48
+ * protocol version must be this server's. The code stays good, for the driver once it is updated. */
49
+ export declare function pairRefusal(name: string, hello: HelloResult): string | undefined;
50
+ /** A paired computer as GET /v2/computers lists it under `paired`: whatever its hello says it is (its os and version, its
51
+ * device, its screen, its groups and features: the live hello's while it is attached, else its last one), the
52
+ * setting kinds it serves and why it serves none, whether it is attached now, its driver's build, and the run that holds it and until when.
53
+ * Nothing here is any one OS's: a driver on any OS is shown by the same fields. */
54
+ export type PairedView = {
55
+ id: string;
56
+ name: string;
57
+ kind: string;
58
+ serves: string[];
59
+ /** When it serves no kind, why, naming what its driver lacks (servesNoKind); null when it serves one. */
60
+ unserved: string | null;
61
+ os: string;
62
+ os_version: string | null;
63
+ device: {
64
+ maker: string;
65
+ model: string;
66
+ } | null;
67
+ arch: string;
68
+ screen: {
69
+ width: number;
70
+ height: number;
71
+ scale: number;
72
+ } | null;
73
+ groups: string[];
74
+ features: Record<string, true | {
75
+ off: string;
76
+ }>;
77
+ driver: string;
78
+ online: boolean;
79
+ held_by_run: string | null;
80
+ held_until: string | null;
81
+ /** The pairing (createPairing's id) whose code paired it. */
82
+ pairing: string;
83
+ created_at: string;
84
+ seen_at: string | null;
85
+ };
86
+ export declare function pairedView(row: PairedComputerRow, hub: Pick<AttachHub, "online" | "hello" | "claimed" | "deadline">, serves: readonly string[]): PairedView;
87
+ /** How the socket's liveness is timed: ATTACH_HEARTBEAT_MS and ATTACH_IDLE_MS, unless a test gives its own. */
88
+ export type AttachTiming = {
89
+ readonly heartbeatMs: number;
90
+ readonly idleMs: number;
91
+ };
92
+ /** One WebSocket as the hub takes it (attach.ts AttachSocket): text frames in and out; a ping each heartbeat; closed
93
+ * with ATTACH_CLOSE.idle once nothing (no frame, ping or pong) is heard for idleMs, and with ATTACH_CLOSE.binary on a
94
+ * binary frame. A frame over MAX_LINE_BYTES is the server's maxPayload, which closes it with 1009 itself. */
95
+ export declare function attachSocketOf(ws: WebSocket, timing?: AttachTiming): AttachSocket;
96
+ export interface AttachRoutesOptions {
97
+ readonly store: {
98
+ readonly pairedComputers: PairedComputers;
99
+ };
100
+ readonly hub: AttachHub;
101
+ /** Told each event worth a line: a computer paired, attached, refused at its hello, removed. Never a code or a token. */
102
+ readonly log?: (event: string, fields: Record<string, string>) => void;
103
+ /** The socket's liveness timing: the protocol's unless a test gives its own. */
104
+ readonly timing?: AttachTiming;
105
+ readonly now?: () => number;
106
+ /** Told each socket taken, with its computer, before its hello: the binding's conformance run (attach-conformance.ts)
107
+ * watches the raw socket to see how a driver answers a close, a drop and a frame it must refuse. */
108
+ readonly onSocket?: (computer: string, ws: WebSocket) => void;
109
+ }
110
+ /** The pairing routes and the attach socket over one store and one hub. */
111
+ export declare function createAttachRoutes(options: AttachRoutesOptions): {
112
+ createPairing: () => Promise<{
113
+ id: string;
114
+ code: string;
115
+ expires_at: string;
116
+ }>;
117
+ pair: (body: unknown, address: string) => Promise<{
118
+ computer: string;
119
+ token: string;
120
+ }>;
121
+ remove: (id: string) => Promise<void>;
122
+ upgrade: (req: IncomingMessage, socket: Duplex, head: Buffer, deny: (status: string, words?: string, headers?: Record<string, string>) => void) => void;
123
+ close: () => Promise<void>;
124
+ };
125
+ export type AttachRoutes = ReturnType<typeof createAttachRoutes>;