@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
@@ -1,10 +0,0 @@
1
- /** Daytona's API and this server's key for it (boxes.ts daytonaApi). `fetch`: for tests. */
2
- export type DaytonaApi = {
3
- apiUrl: string;
4
- apiKey: string;
5
- fetch?: typeof fetch;
6
- };
7
- /** The redirect `fetch` refused (`redirect: "error"`): said plainly, as nothing follows one. */
8
- export declare function redirectRefusal(cause: unknown): string | undefined;
9
- /** One call to Daytona's API at `path` (below its base), with the key; a redirect throws, saying so. */
10
- export declare function daytonaCall(api: DaytonaApi, method: string, path: string): Promise<Response>;
@@ -1,20 +0,0 @@
1
- // The few calls this server makes of Daytona's API itself, beside its provider's (pi-transport's daytonaBoxes): with
2
- // the server's key, and never through a redirect, which would carry the key to wherever it points. The box relay
3
- // (box-relay.ts) reads a sandbox's labels and toolbox with them.
4
- const CALL_MS = 30_000;
5
- /** The redirect `fetch` refused (`redirect: "error"`): said plainly, as nothing follows one. */
6
- export function redirectRefusal(cause) {
7
- const inner = cause?.cause;
8
- return /redirect/i.test(`${cause?.message ?? ""} ${inner?.message ?? ""}`) ? "Daytona answered with a redirect, which is never followed: it would carry the key" : undefined;
9
- }
10
- /** One call to Daytona's API at `path` (below its base), with the key; a redirect throws, saying so. */
11
- export async function daytonaCall(api, method, path) {
12
- const base = api.apiUrl.replace(/\/+$/, "");
13
- try {
14
- return await (api.fetch ?? fetch)(`${base}${path}`, { method, headers: { authorization: `Bearer ${api.apiKey}`, "x-daytona-source": "pi-transport" }, redirect: "error", signal: AbortSignal.timeout(CALL_MS) });
15
- }
16
- catch (error) {
17
- const refused = redirectRefusal(error);
18
- throw refused ? new Error(`${method} ${new URL(`${base}${path}`).pathname}: ${refused}`) : error;
19
- }
20
- }
@@ -1,45 +0,0 @@
1
- import { type Socket } from "node:net";
2
- /** `dns.lookup` with `{ all: true }`: every address a name resolves to. */
3
- export type EgressLookup = (hostname: string, options: {
4
- all: true;
5
- verbatim: true;
6
- }, callback: (error: NodeJS.ErrnoException | null, addresses: {
7
- address: string;
8
- family: number;
9
- }[]) => void) => void;
10
- export interface EgressProxyOptions {
11
- /** Where the socket is made: a path in the session's LOCAL runtime directory (the machine's runtimeDir), never the
12
- * run's directory, which may sit on a disk other hosts mount. A socket there that refuses a connection (its proxy died
13
- * without removing it) is replaced; one that answers is a live proxy's, and the start is refused
14
- * (`egress_socket_in_use`); anything else there is refused and left as it is (`egress_socket_path_taken`). */
15
- socketPath: string;
16
- /** Connections open at once (tunnels and forwarded requests), past which a new one is refused. */
17
- maxTunnels: number;
18
- /** Connections in all, for the proxy's life, past which a new one is refused. */
19
- maxConnections: number;
20
- /** One line per decision: the host, the port, the address and the class. */
21
- log: (line: string) => void;
22
- /** How a name is resolved (a test's seam). Default: `dns.lookup`. */
23
- lookup?: EgressLookup;
24
- /** How a connection is opened to an address the table passed, in its canonical text (a test's seam). Default:
25
- * `net.connect`. Only an address that was checked ever reaches it. */
26
- dial?: (address: string, port: number) => Socket;
27
- /** More addresses to refuse as this host's, beside the interfaces read at each dial (a test's seam: it can only refuse
28
- * more). */
29
- alsoLocal?: () => readonly string[];
30
- /** The only hosts reached, as parseAllow takes them: exact names, or `*.suffix` for the names below one. Set, every
31
- * other host, any IP literal and any port but 80 and 443 are refused 403 (SOCKS reply 2, class `not-listed`) before
32
- * any lookup. Absent, every public host is reached. */
33
- allow?: string | readonly string[];
34
- /** What a refusal for a host off the list says to do, after its words (the caller's, which knows its settings): printable
35
- * ASCII, since it goes into the status line; anything else refuses the start. */
36
- allowHint?: string;
37
- }
38
- /** A host list from its entries, or a comma list of them: each lowercased, its trailing dot dropped, the repeats gone.
39
- * Throws for an entry that is not a name of two labels or more, or `*.` and one (an address, a port, a URL, a bare `*`). */
40
- export declare function parseAllow(entries: string | readonly string[]): string[];
41
- export interface EgressProxy {
42
- readonly socketPath: string;
43
- close(): Promise<void>;
44
- }
45
- export declare function startEgressProxy(options: EgressProxyOptions): Promise<EgressProxy>;
@@ -1,416 +0,0 @@
1
- // A box's egress proxy, written for AgentRun: the one way out of a box whose network namespace has only its own loopback.
2
- // It listens on a Unix socket (0600) in the session's local runtime directory, bound into the box, and speaks HTTP CONNECT, plain HTTP
3
- // forwarding and SOCKS5 CONNECT (told apart by the first byte), each to the public internet only (egress-table.ts):
4
- // - a host is resolved once, every address in the answer is checked, and the connection goes to exactly the address
5
- // that was checked, so a name cannot point elsewhere between the check and the dial; an IP literal is checked the
6
- // same way, by its bytes, whatever form the client wrote it in;
7
- // - a refusal is an answer, sent before any socket opens: 403 (or SOCKS reply 2) with the class in its reason;
8
- // - plain HTTP goes to the request URI's host, and a Host header that names another host is refused (400);
9
- // - a redirect is never followed here: it reaches the client as the origin sent it, and the client's next request is
10
- // one more request through this proxy, checked the same way;
11
- // - SOCKS5 BIND and UDP ASSOCIATE are refused by name, and so is an HTTP upgrade;
12
- // - a run has a cap on connections open at once and a budget of connections in all, each refused by name;
13
- // - a log line holds the host, the port, the address and the class, never a path, a query, a header or a body;
14
- // - with a host list (`allow`), a host off it, an IP literal and any port but 80 and 443 are refused before any lookup,
15
- // so a name off the list never leaves the host (no DNS channel out); a listed name then meets the address rule as
16
- // any other does.
17
- // It holds no key. `close()` ends every connection and removes the socket.
18
- import { randomBytes } from "node:crypto";
19
- import { lookup as dnsLookup } from "node:dns";
20
- import { chmod, link, lstat, unlink } from "node:fs/promises";
21
- import { createServer as createHttpServer, request as httpRequest } from "node:http";
22
- import { connect as netConnect, createServer } from "node:net";
23
- import { networkInterfaces } from "node:os";
24
- import { dirname, join } from "node:path";
25
- import { addressBytes, checkAddress } from "./egress-table.js";
26
- /** A host list's entry: a name of two labels or more, or `*.` and such a name. */
27
- const ENTRY = /^(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/;
28
- /** A host list from its entries, or a comma list of them: each lowercased, its trailing dot dropped, the repeats gone.
29
- * Throws for an entry that is not a name of two labels or more, or `*.` and one (an address, a port, a URL, a bare `*`). */
30
- export function parseAllow(entries) {
31
- const list = (typeof entries === "string" ? entries.split(/[\s,]+/) : entries).map((entry) => entry.trim()).filter((entry) => entry !== "");
32
- const out = [];
33
- for (const entry of list) {
34
- const name = entry.toLowerCase().replace(/\.$/, "");
35
- if (!ENTRY.test(name) || addressBytes(name.replace(/^\*\./, "")) !== undefined) {
36
- throw new Error(`the network list's entry ${JSON.stringify(entry)} is not a name with at least two labels, or *. and one`);
37
- }
38
- if (!out.includes(name))
39
- out.push(name);
40
- }
41
- return out;
42
- }
43
- /** Whether `host` is on `list`: an exact name, or below a `*.suffix`; in any case, and without a trailing dot. */
44
- const listedHost = (list, host) => {
45
- const name = host.toLowerCase().replace(/\.$/, "");
46
- return list.some((entry) => (entry.startsWith("*.") ? name.endsWith(entry.slice(1)) && name.length > entry.length - 1 : name === entry));
47
- };
48
- /** The ports a host list opens: plain HTTP and HTTPS. */
49
- const LISTED_PORTS = [80, 443];
50
- const HOP = new Set(["connection", "proxy-connection", "keep-alive", "proxy-authorization", "proxy-authenticate", "te", "trailer", "upgrade", "transfer-encoding"]);
51
- /** The headers that stay on this hop: the fixed hop-by-hop names, and every name a Connection header lists. */
52
- function hopHeaders(headers) {
53
- const listed = [headers.connection ?? []].flat().flatMap((value) => String(value).split(",")).map((name) => name.trim().toLowerCase()).filter(Boolean);
54
- return new Set([...HOP, ...listed]);
55
- }
56
- /** The canonical text of an address's bytes: what is dialled. */
57
- function addressText(bytes) {
58
- if (bytes.length === 4)
59
- return [...bytes].join(".");
60
- const groups = [];
61
- for (let i = 0; i < 16; i += 2)
62
- groups.push(((bytes[i] << 8) | bytes[i + 1]).toString(16));
63
- return groups.join(":");
64
- }
65
- const hostOf = (text) => JSON.stringify(text.slice(0, 255));
66
- export async function startEgressProxy(options) {
67
- const { socketPath, maxTunnels, maxConnections, log } = options;
68
- const allow = options.allow === undefined ? undefined : parseAllow(options.allow);
69
- // The hint goes into a status line, which carries printable ASCII only: Node refuses anything else there (an em dash
70
- // included), and a control character would end the line.
71
- if (options.allowHint !== undefined && !/^[\x20-\x7e]*$/.test(options.allowHint))
72
- throw new Error("the egress proxy's allowHint holds a character a status line cannot carry: printable ASCII only");
73
- const hinted = (words) => (options.allowHint ? `${words}: ${options.allowHint}` : words);
74
- /** The refusal of a target off the host list, or undefined: checked before any lookup. */
75
- const offList = (host, port) => {
76
- if (allow === undefined)
77
- return undefined;
78
- // A phrase holds only a plain host: anything else is named as such.
79
- const shown = /^[A-Za-z0-9._:-]+$/.test(host) ? host : "the host";
80
- const words = addressBytes(host) !== undefined
81
- ? hinted(`${shown} is an address, not a name on this box's network list`)
82
- : !listedHost(allow, host)
83
- ? hinted(`${shown} is not on this box's network list`)
84
- : !LISTED_PORTS.includes(port)
85
- ? `${shown}:${port} is not open on this box's network list, which takes ports 80 and 443 only`
86
- : undefined;
87
- return words === undefined ? undefined : { status: 403, reason: "not-listed", socks: 2, words };
88
- };
89
- const lookup = options.lookup ?? ((hostname, opts, callback) => dnsLookup(hostname, opts, callback));
90
- const dial = options.dial ?? ((address, port) => netConnect({ host: address, port }));
91
- const sockets = new Set();
92
- let open = 0;
93
- let used = 0;
94
- let closed = false;
95
- const track = (socket) => {
96
- sockets.add(socket);
97
- socket.once("close", () => sockets.delete(socket));
98
- if (closed)
99
- socket.destroy();
100
- };
101
- /** The host's addresses at this moment: every interface's, and the seam's. */
102
- const local = () => [
103
- ...Object.values(networkInterfaces()).flatMap((list) => (list ?? []).map((entry) => entry.address)),
104
- ...(options.alsoLocal?.() ?? []),
105
- ];
106
- /** Resolves `host` once and checks every answer: the address to dial, or the refusal. */
107
- const resolve = async (host) => {
108
- const literal = addressBytes(host);
109
- let answers;
110
- if (literal)
111
- answers = [literal];
112
- else {
113
- if (!/^[A-Za-z0-9._-]+$/.test(host) || host.length > 253)
114
- return { refused: { status: 400, reason: "invalid host", socks: 4 } };
115
- try {
116
- const found = await new Promise((ok, fail) => lookup(host, { all: true, verbatim: true }, (error, list) => (error ? fail(error) : ok(list))));
117
- answers = found.map((entry) => addressBytes(entry.address)).filter((bytes) => bytes !== undefined);
118
- }
119
- catch {
120
- return { refused: { status: 502, reason: "name not resolved", socks: 4 } };
121
- }
122
- if (answers.length === 0)
123
- return { refused: { status: 502, reason: "name not resolved", socks: 4 } };
124
- }
125
- const here = local();
126
- for (const bytes of answers) {
127
- const verdict = checkAddress(bytes, here);
128
- if (!verdict.ok)
129
- return { refused: { status: 403, reason: verdict.class, socks: 2 }, address: addressText(bytes) };
130
- }
131
- return { address: addressText(answers[0]) };
132
- };
133
- /** A connection may open now: the cap and the budget. Takes a slot; `release` gives it back. */
134
- const admit = () => {
135
- if (open >= maxTunnels)
136
- return { status: 429, reason: "tunnel cap", socks: 2 };
137
- if (used >= maxConnections)
138
- return { status: 429, reason: "connection budget", socks: 2 };
139
- open++;
140
- used++;
141
- return undefined;
142
- };
143
- /** Resolve, check, admit and dial: the upstream socket once it connects, or the refusal. */
144
- const reach = async (kind, host, port) => {
145
- const unlisted = offList(host, port);
146
- if (unlisted) {
147
- log(`egress ${kind} host=${hostOf(host)} port=${port} ip=- class=${unlisted.reason}`);
148
- return { refused: unlisted };
149
- }
150
- const target = await resolve(host);
151
- if ("refused" in target) {
152
- log(`egress ${kind} host=${hostOf(host)} port=${port} ip=${target.address ?? "-"} class=${target.refused.reason}`);
153
- return target;
154
- }
155
- const full = admit();
156
- if (full) {
157
- log(`egress ${kind} host=${hostOf(host)} port=${port} ip=${target.address} class=${full.reason}`);
158
- return { refused: full };
159
- }
160
- log(`egress ${kind} host=${hostOf(host)} port=${port} ip=${target.address} class=ok`);
161
- const upstream = dial(target.address, port);
162
- track(upstream);
163
- upstream.once("close", () => open--);
164
- return await new Promise((ok) => {
165
- upstream.once("connect", () => ok({ socket: upstream, address: target.address }));
166
- upstream.once("error", () => ok({ refused: { status: 502, reason: "dial failed", socks: 5 } }));
167
- });
168
- };
169
- // HTTP: CONNECT, and plain requests in absolute form.
170
- const http = createHttpServer();
171
- const refuseRaw = (socket, refusal) => {
172
- const body = `${refusal.words ?? `egress refused: ${refusal.reason}`}\n`;
173
- socket.end(`HTTP/1.1 ${refusal.status} ${refusal.words ?? `Egress refused: ${refusal.reason}`}\r\nx-egress-refused: ${refusal.reason}\r\ncontent-type: text/plain\r\ncontent-length: ${Buffer.byteLength(body)}\r\nconnection: close\r\n\r\n${body}`);
174
- };
175
- const refuse = (res, refusal) => {
176
- const body = `${refusal.words ?? `egress refused: ${refusal.reason}`}\n`;
177
- res.writeHead(refusal.status, refusal.words ?? `Egress refused: ${refusal.reason}`, { "x-egress-refused": refusal.reason, "content-type": "text/plain", "content-length": Buffer.byteLength(body), connection: "close" });
178
- res.end(body);
179
- };
180
- http.on("connect", (req, client, head) => {
181
- void (async () => {
182
- const target = /^\[([0-9A-Fa-f:.%a-zA-Z]+)\]:(\d{1,5})$/.exec(req.url ?? "") ?? /^([^:[\]/@\s]+):(\d{1,5})$/.exec(req.url ?? "");
183
- const port = Number(target?.[2]);
184
- if (!target || !(port >= 1 && port <= 65535))
185
- return refuseRaw(client, { status: 400, reason: "invalid target", socks: 1 });
186
- const reached = await reach("connect", target[1], port);
187
- if ("refused" in reached)
188
- return refuseRaw(client, reached.refused);
189
- // A client that left during the lookup or the dial gets no tunnel: its socket goes, and so does its slot.
190
- if (client.destroyed)
191
- return void reached.socket.destroy();
192
- client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
193
- if (head.length)
194
- reached.socket.write(head);
195
- reached.socket.pipe(client).pipe(reached.socket);
196
- reached.socket.on("error", () => client.destroy());
197
- client.on("error", () => reached.socket.destroy());
198
- reached.socket.on("close", () => client.destroy());
199
- client.on("close", () => reached.socket.destroy());
200
- })();
201
- });
202
- http.on("upgrade", (_req, client) => refuseRaw(client, { status: 400, reason: "upgrade not supported", socks: 7 }));
203
- http.on("request", (req, res) => {
204
- // Watched from the start: a client that leaves during the lookup or the dial is gone before any listener below exists.
205
- let gone = false;
206
- res.once("close", () => (gone = true));
207
- void (async () => {
208
- let url;
209
- try {
210
- url = new URL(req.url ?? "");
211
- }
212
- catch {
213
- return refuse(res, { status: 400, reason: "not an absolute URI", socks: 1 });
214
- }
215
- if (url.protocol !== "http:")
216
- return refuse(res, { status: 400, reason: "not an http URI", socks: 1 });
217
- const host = url.hostname.replace(/^\[|\]$/g, "");
218
- const port = url.port === "" ? 80 : Number(url.port);
219
- if (req.headers.host !== undefined) {
220
- let named;
221
- try {
222
- named = new URL(`http://${req.headers.host}`);
223
- }
224
- catch { }
225
- if (!named || named.hostname !== url.hostname || (named.port === "" ? 80 : Number(named.port)) !== port) {
226
- log(`egress http host=${hostOf(host)} port=${port} ip=- class=host mismatch`);
227
- return refuse(res, { status: 400, reason: "host mismatch", socks: 1 });
228
- }
229
- }
230
- const reached = await reach("http", host, port);
231
- if ("refused" in reached)
232
- return refuse(res, reached.refused);
233
- if (gone)
234
- return void reached.socket.destroy();
235
- const headers = {};
236
- const hop = hopHeaders(req.headers);
237
- for (const [name, value] of Object.entries(req.headers))
238
- if (!hop.has(name))
239
- headers[name] = value;
240
- headers.host = url.host;
241
- headers.connection = "close";
242
- // The request goes over the socket already dialled to the checked address. Its host and port name that address too,
243
- // so nothing else is reached even if the socket were not used (with `agent: false`, Node ignores createConnection
244
- // and dials host and port itself).
245
- const upstream = httpRequest({ host: reached.address, port, method: req.method, path: `${url.pathname}${url.search}`, headers, createConnection: () => reached.socket });
246
- upstream.on("response", (answer) => {
247
- const out = {};
248
- const back = hopHeaders(answer.headers);
249
- for (const [name, value] of Object.entries(answer.headers))
250
- if (!back.has(name) && value !== undefined)
251
- out[name] = value;
252
- res.writeHead(answer.statusCode ?? 502, answer.statusMessage, out);
253
- answer.pipe(res);
254
- });
255
- upstream.on("error", () => (res.headersSent ? res.destroy() : refuse(res, { status: 502, reason: "upstream failed", socks: 1 })));
256
- req.pipe(upstream);
257
- res.on("close", () => reached.socket.destroy());
258
- })();
259
- });
260
- // SOCKS5: a greeting offering "no authentication", then one CONNECT.
261
- const socks = (client) => {
262
- let buffer = Buffer.alloc(0);
263
- let stage = "greet";
264
- const reply = (code) => Buffer.from([5, code, 0, 1, 0, 0, 0, 0, 0, 0]);
265
- const onData = (chunk) => {
266
- buffer = Buffer.concat([buffer, chunk]);
267
- if (buffer.length > 1024)
268
- return client.destroy();
269
- if (stage === "greet") {
270
- if (buffer.length < 2 || buffer.length < 2 + buffer[1])
271
- return;
272
- const methods = buffer.subarray(2, 2 + buffer[1]);
273
- buffer = buffer.subarray(2 + buffer[1]);
274
- if (!methods.includes(0))
275
- return client.end(Buffer.from([5, 0xff]));
276
- client.write(Buffer.from([5, 0]));
277
- stage = "request";
278
- }
279
- if (stage !== "request" || buffer.length < 5)
280
- return;
281
- const [version, command, , type] = buffer;
282
- if (version !== 5)
283
- return client.destroy();
284
- const length = type === 1 ? 4 : type === 4 ? 16 : type === 3 ? 1 + buffer[4] : -1;
285
- if (length < 0)
286
- return client.end(reply(8));
287
- if (buffer.length < 4 + length + 2)
288
- return;
289
- stage = "done";
290
- client.off("data", onData);
291
- client.setTimeout(0);
292
- const raw = buffer.subarray(4, 4 + length);
293
- const host = type === 3 ? raw.subarray(1).toString("latin1") : addressText(raw);
294
- const port = buffer.readUInt16BE(4 + length);
295
- const rest = buffer.subarray(4 + length + 2);
296
- if (command !== 1) {
297
- const name = command === 2 ? "socks bind" : command === 3 ? "socks udp associate" : "socks command";
298
- log(`egress socks host=${hostOf(host)} port=${port} ip=- class=${name}`);
299
- return client.end(reply(7));
300
- }
301
- void (async () => {
302
- const reached = await reach("socks", host, port);
303
- if ("refused" in reached)
304
- return client.end(reply(reached.refused.socks));
305
- if (client.destroyed)
306
- return void reached.socket.destroy();
307
- client.write(reply(0));
308
- if (rest.length)
309
- reached.socket.write(rest);
310
- reached.socket.pipe(client).pipe(reached.socket);
311
- reached.socket.on("error", () => client.destroy());
312
- client.on("error", () => reached.socket.destroy());
313
- reached.socket.on("close", () => client.destroy());
314
- client.on("close", () => reached.socket.destroy());
315
- })();
316
- };
317
- client.on("data", onData);
318
- };
319
- const server = createServer((client) => {
320
- track(client);
321
- client.on("error", () => client.destroy());
322
- client.setTimeout(30_000, () => client.destroy());
323
- client.once("data", (first) => {
324
- client.pause();
325
- client.unshift(first);
326
- if (first[0] === 5) {
327
- socks(client);
328
- client.resume();
329
- }
330
- else {
331
- client.setTimeout(0);
332
- http.emit("connection", client);
333
- client.resume();
334
- }
335
- });
336
- });
337
- // A socket already at the path belongs to another proxy while it answers, and is never taken from it. The socket's
338
- // directory is local; a connect refused there means nothing listens. So only a socket that refuses a connection is
339
- // removed; any other failure of the probe (EACCES, say) is thrown and the socket left, and anything that is not a socket
340
- // is left where it is. (On a disk shared between hosts, a live proxy's socket on another host would refuse this host's
341
- // connection: that is why the directory must be local.) Two starts that both find the same dead socket could each
342
- // remove it in turn, the second after the first has linked its live socket there; that needs two starters in one
343
- // session's runtime directory, which its single claim holder rules out, so nothing here guards it (moving the socket
344
- // aside to check it would leave a live one briefly missing from its path instead).
345
- const taken = (code, what) => Object.assign(new Error(`egress proxy: ${socketPath} ${what}`), { code });
346
- let found;
347
- try {
348
- found = await lstat(socketPath);
349
- }
350
- catch (error) {
351
- if (error.code !== "ENOENT")
352
- throw error;
353
- }
354
- if (found) {
355
- if (!found.isSocket())
356
- throw taken("egress_socket_path_taken", "exists and is not a socket");
357
- const answer = await new Promise((ok) => {
358
- const probe = netConnect(socketPath);
359
- probe.once("connect", () => {
360
- probe.destroy();
361
- ok(true);
362
- });
363
- probe.once("error", (error) => ok(error));
364
- });
365
- if (answer === true)
366
- throw taken("egress_socket_in_use", "is a live egress proxy's socket");
367
- if (answer.code !== "ECONNREFUSED")
368
- throw answer;
369
- await unlink(socketPath);
370
- }
371
- // Made under a name of its own and made 0600 before it gets its path, so it is never reachable there with a wider
372
- // mode. The path is a hard link, never a rename. Between the check above and this link, another start can put a socket
373
- // at the path: a link then fails (EEXIST, refused as egress_socket_in_use), where a rename would replace that socket
374
- // silently. No test can hold that window open, so this comment is its record. The temporary name is removed once linked.
375
- const making = join(dirname(socketPath), `.egress-${randomBytes(6).toString("hex")}.sock`);
376
- await new Promise((ok, fail) => {
377
- server.once("error", fail);
378
- server.listen(making, () => {
379
- server.off("error", fail);
380
- ok();
381
- });
382
- });
383
- try {
384
- await chmod(making, 0o600);
385
- await link(making, socketPath);
386
- }
387
- catch (error) {
388
- server.close();
389
- await unlink(making).catch(() => { });
390
- if (error.code === "EEXIST")
391
- throw taken("egress_socket_in_use", "was taken while this proxy started");
392
- throw error;
393
- }
394
- // This socket's inode: close removes the path only while it still holds it, never a socket another start put there.
395
- const mine = await lstat(making);
396
- await unlink(making).catch(() => { });
397
- return {
398
- socketPath,
399
- async close() {
400
- if (closed)
401
- return;
402
- closed = true;
403
- const done = new Promise((ok) => server.close(() => ok()));
404
- for (const socket of sockets)
405
- socket.destroy();
406
- http.close();
407
- await done;
408
- const now = await lstat(socketPath).catch((error) => {
409
- if (error.code !== "ENOENT")
410
- throw error;
411
- });
412
- if (now && now.dev === mine.dev && now.ino === mine.ino)
413
- await unlink(socketPath);
414
- },
415
- };
416
- }
@@ -1,24 +0,0 @@
1
- /** Why an address is refused. */
2
- export type EgressClass = "loopback" | "unspecified" | "private" | "cgnat" | "link-local" | "metadata" | "multicast" | "broadcast" | "reserved" | "benchmarking" | "this-host" | "invalid";
3
- export type EgressVerdict = {
4
- ok: true;
5
- } | {
6
- ok: false;
7
- class: EgressClass;
8
- };
9
- /** The table's ranges as written, in order: what the no-drift test pins. */
10
- export declare const EGRESS_RANGES: readonly string[];
11
- /**
12
- * An IP address's bytes (4 or 16), or undefined when `text` is not one. Takes what a socket or a URL could carry for a
13
- * host: a dotted IPv4 address, or the forms the classic resolver reads as one (a single number, 0x hex and 0 octal
14
- * parts, fewer than four parts with the last filling the rest), and an IPv6 address, bracketed or not, with or without a
15
- * zone. Never a name.
16
- */
17
- export declare function addressBytes(text: string): Uint8Array | undefined;
18
- /**
19
- * Whether a box may reach `address` (its bytes, or an address's text: never a name). `local` is the host's own interface
20
- * addresses, read by the caller at the dial: an address equal to one of them is refused as "this-host". An IPv6 address
21
- * that carries an IPv4 one is judged by the IPv4 inside, and is then still the host's own if the host holds that IPv6
22
- * address itself (the dial goes to the IPv6 address, not to the IPv4 inside it).
23
- */
24
- export declare function checkAddress(address: Uint8Array | string, local: readonly string[]): EgressVerdict;