@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46

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 (350) hide show
  1. package/CHANGELOG.md +148 -5
  2. package/README.md +385 -305
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +62 -19
  28. package/dist/composio-preset.js +69 -7
  29. package/dist/composio-triggers.d.ts +14 -0
  30. package/dist/composio-triggers.js +79 -15
  31. package/dist/computer-attach.d.ts +40 -5
  32. package/dist/computer-attach.js +130 -15
  33. package/dist/computer-keys.d.ts +3 -0
  34. package/dist/computer-keys.js +7 -1
  35. package/dist/computer-live.js +3 -2
  36. package/dist/computers.d.ts +21 -10
  37. package/dist/computers.js +39 -28
  38. package/dist/console/assets/index-C2MYaUBa.css +1 -0
  39. package/dist/console/assets/index-CZZeCReB.js +701 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/decisions.d.ts +1 -1
  42. package/dist/dial-relay.d.ts +29 -0
  43. package/dist/dial-relay.js +94 -0
  44. package/dist/email/tools.js +10 -5
  45. package/dist/env-proxy.d.ts +2 -0
  46. package/dist/env-proxy.js +35 -0
  47. package/dist/errors.d.ts +3 -1
  48. package/dist/errors.js +7 -4
  49. package/dist/faux-computers.d.ts +8 -2
  50. package/dist/faux-computers.js +83 -6
  51. package/dist/harness-archive.d.ts +67 -0
  52. package/dist/harness-archive.js +177 -0
  53. package/dist/harness-goose.d.ts +34 -0
  54. package/dist/harness-goose.js +87 -0
  55. package/dist/harness-install.d.ts +21 -0
  56. package/dist/harness-install.js +24 -11
  57. package/dist/harness-opencode/adapter.js +1 -1
  58. package/dist/harness-table.d.ts +9 -1
  59. package/dist/harness-table.js +20 -3
  60. package/dist/harness.d.ts +1 -2
  61. package/dist/harness.js +3 -4
  62. package/dist/host.js +2 -1
  63. package/dist/import.d.ts +10 -0
  64. package/dist/import.js +28 -8
  65. package/dist/key-check.js +3 -0
  66. package/dist/learn/audit.d.ts +6 -6
  67. package/dist/learn/audit.js +3 -7
  68. package/dist/learn/check.d.ts +23 -89
  69. package/dist/learn/check.js +57 -335
  70. package/dist/learn/commit.d.ts +63 -90
  71. package/dist/learn/commit.js +124 -316
  72. package/dist/learn/compile.d.ts +53 -50
  73. package/dist/learn/compile.js +89 -104
  74. package/dist/learn/corrections.d.ts +13 -0
  75. package/dist/learn/corrections.js +23 -0
  76. package/dist/learn/delete.d.ts +5 -5
  77. package/dist/learn/delete.js +8 -10
  78. package/dist/learn/folder.d.ts +35 -47
  79. package/dist/learn/folder.js +118 -134
  80. package/dist/learn/index.d.ts +3 -5
  81. package/dist/learn/index.js +6 -9
  82. package/dist/learn/learning.sh +45 -15
  83. package/dist/learn/promote.d.ts +23 -5
  84. package/dist/learn/promote.js +40 -2
  85. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
  86. package/dist/learn/{skills.js → workflow-draft.js} +48 -58
  87. package/dist/learn/workflow-nodes.js +1 -1
  88. package/dist/learned-workflow.js +2 -2
  89. package/dist/learning-cost.d.ts +38 -24
  90. package/dist/learning-cost.js +41 -24
  91. package/dist/learning-routes.d.ts +91 -170
  92. package/dist/learning-routes.js +183 -421
  93. package/dist/learning-run.d.ts +19 -40
  94. package/dist/learning-run.js +23 -93
  95. package/dist/learning-setting.d.ts +21 -10
  96. package/dist/learning-setting.js +47 -11
  97. package/dist/learning-words.d.ts +28 -74
  98. package/dist/learning-words.js +64 -162
  99. package/dist/learning.d.ts +61 -392
  100. package/dist/learning.js +101 -651
  101. package/dist/live-reach.d.ts +25 -2
  102. package/dist/live-reach.js +46 -4
  103. package/dist/llms.txt +1 -1
  104. package/dist/local-models.d.ts +3 -11
  105. package/dist/local-models.js +5 -6
  106. package/dist/mcp-servers-store.d.ts +4 -4
  107. package/dist/model-form.js +6 -5
  108. package/dist/model.d.ts +4 -0
  109. package/dist/model.js +26 -9
  110. package/dist/native/binding.js +1 -1
  111. package/dist/native/connection.js +1 -1
  112. package/dist/native/discovery.js +1 -1
  113. package/dist/native/instructions.d.ts +3 -0
  114. package/dist/native/instructions.js +5 -3
  115. package/dist/native/remote-worker-bridge.js +9 -43
  116. package/dist/native/remote.d.ts +8 -15
  117. package/dist/native/remote.js +3 -3
  118. package/dist/native/schema.js +1 -1
  119. package/dist/native/types.d.ts +2 -2
  120. package/dist/openapi.js +273 -319
  121. package/dist/paid-calls.d.ts +8 -0
  122. package/dist/paid-calls.js +20 -0
  123. package/dist/particle-provider.d.ts +11 -0
  124. package/dist/particle-provider.js +135 -0
  125. package/dist/port-models.d.ts +12 -4
  126. package/dist/port-models.js +28 -11
  127. package/dist/print.d.ts +27 -0
  128. package/dist/print.js +21 -0
  129. package/dist/provider.d.ts +7 -0
  130. package/dist/provider.js +15 -1
  131. package/dist/reflect-range.js +2 -3
  132. package/dist/run-launch.d.ts +14 -28
  133. package/dist/run-launch.js +9 -12
  134. package/dist/run-learning-served.d.ts +15 -89
  135. package/dist/run-listing.d.ts +34 -0
  136. package/dist/run-listing.js +128 -0
  137. package/dist/run-model-key.js +1 -1
  138. package/dist/run-timeline-served.js +5 -3
  139. package/dist/run-trace.d.ts +97 -0
  140. package/dist/run-trace.js +253 -0
  141. package/dist/run-view.d.ts +15 -0
  142. package/dist/run-view.js +9 -0
  143. package/dist/runnable.js +2 -1
  144. package/dist/runner/adapter-loop.d.ts +8 -6
  145. package/dist/runner/adapter-loop.js +16 -12
  146. package/dist/runner/adapter-run-spec.d.ts +16 -4
  147. package/dist/runner/adapter-run-spec.js +64 -58
  148. package/dist/runner/adapters/index.js +22 -0
  149. package/dist/runner/adapters/pi.d.ts +4 -12
  150. package/dist/runner/adapters/pi.js +2 -2
  151. package/dist/runner/audit.d.ts +1 -1
  152. package/dist/runner/audit.js +30 -13
  153. package/dist/runner/beside.d.ts +6 -2
  154. package/dist/runner/beside.js +38 -9
  155. package/dist/runner/claim-secrets.d.ts +18 -2
  156. package/dist/runner/claim-secrets.js +42 -18
  157. package/dist/runner/cli-run-spec.js +55 -51
  158. package/dist/runner/conformance/harness.d.ts +6 -0
  159. package/dist/runner/conformance/harness.js +35 -13
  160. package/dist/runner/conformance/subject.d.ts +6 -0
  161. package/dist/runner/dispatch.d.ts +2 -2
  162. package/dist/runner/end-of-run.d.ts +6 -14
  163. package/dist/runner/end-of-run.js +8 -33
  164. package/dist/runner/feedback-round.d.ts +2 -2
  165. package/dist/runner/feedback-round.js +7 -7
  166. package/dist/runner/github-app.js +3 -1
  167. package/dist/runner/harness-loops.d.ts +0 -8
  168. package/dist/runner/harness-loops.js +11 -59
  169. package/dist/runner/held.d.ts +170 -0
  170. package/dist/runner/held.js +57 -0
  171. package/dist/runner/journal-kinds.d.ts +2 -3
  172. package/dist/runner/journal-kinds.js +2 -3
  173. package/dist/runner/learned-first.d.ts +40 -0
  174. package/dist/runner/learned-first.js +32 -0
  175. package/dist/runner/learning-end.d.ts +77 -69
  176. package/dist/runner/learning-end.js +250 -303
  177. package/dist/runner/learning-seed.d.ts +15 -33
  178. package/dist/runner/learning-seed.js +24 -45
  179. package/dist/runner/loop-contract.d.ts +2 -3
  180. package/dist/runner/main.d.ts +17 -9
  181. package/dist/runner/main.js +82 -20
  182. package/dist/runner/mcp-run.d.ts +11 -0
  183. package/dist/runner/mcp-run.js +67 -0
  184. package/dist/runner/memory-claim.d.ts +10 -5
  185. package/dist/runner/memory-claim.js +12 -6
  186. package/dist/runner/model-route.d.ts +7 -4
  187. package/dist/runner/model-route.js +22 -10
  188. package/dist/runner/native-loop.d.ts +0 -7
  189. package/dist/runner/native-loop.js +9 -101
  190. package/dist/runner/promotion.d.ts +12 -8
  191. package/dist/runner/promotion.js +37 -28
  192. package/dist/runner/reflect-hook.d.ts +64 -95
  193. package/dist/runner/reflect-hook.js +112 -225
  194. package/dist/runner/run-channel.d.ts +43 -0
  195. package/dist/runner/run-channel.js +467 -0
  196. package/dist/runner/run-child-host.d.ts +169 -0
  197. package/dist/runner/run-child-host.js +1230 -0
  198. package/dist/runner/run-child.d.ts +1 -0
  199. package/dist/runner/run-child.js +254 -0
  200. package/dist/runner/run-errors.d.ts +2 -0
  201. package/dist/runner/run-errors.js +20 -0
  202. package/dist/runner/runner.js +1 -5
  203. package/dist/runner/sdk-ask.d.ts +78 -0
  204. package/dist/runner/sdk-ask.js +158 -0
  205. package/dist/runner/sdk-loop.d.ts +2 -4
  206. package/dist/runner/sdk-loop.js +29 -49
  207. package/dist/runner/store-secrets.d.ts +5 -3
  208. package/dist/runner/store-secrets.js +5 -1
  209. package/dist/runner/workflow-first.d.ts +5 -0
  210. package/dist/runner/workflow-first.js +4 -0
  211. package/dist/runner/workflow-spec.js +7 -2
  212. package/dist/runs-over-store.d.ts +16 -28
  213. package/dist/runs-over-store.js +31 -38
  214. package/dist/sdk/runs.d.ts +6 -11
  215. package/dist/sdk/runs.js +20 -41
  216. package/dist/sdk/schema.js +3 -4
  217. package/dist/seal-key.d.ts +5 -0
  218. package/dist/seal-key.js +7 -0
  219. package/dist/secrets.d.ts +3 -0
  220. package/dist/secrets.js +16 -3
  221. package/dist/server.d.ts +55 -33
  222. package/dist/server.js +689 -322
  223. package/dist/sign-ins-store.d.ts +8 -0
  224. package/dist/sign-ins-store.js +36 -1
  225. package/dist/skills.js +1 -1
  226. package/dist/store/index.d.ts +2 -2
  227. package/dist/store/index.js +1 -1
  228. package/dist/store/journal/storage.js +3 -0
  229. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  230. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  231. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  232. package/dist/store/schema.d.ts +53 -4
  233. package/dist/store/schema.js +137 -6
  234. package/dist/store/sqlite/connection.d.ts +2 -0
  235. package/dist/store/sqlite/connection.js +3 -1
  236. package/dist/store/sqlite/run-patch.d.ts +0 -17
  237. package/dist/store/sqlite/run-patch.js +4 -33
  238. package/dist/store/sqlite/store.js +246 -63
  239. package/dist/store/sqlite/worker.js +25 -0
  240. package/dist/store/store.d.ts +193 -36
  241. package/dist/store/store.js +25 -3
  242. package/dist/store-reads/learning.d.ts +102 -204
  243. package/dist/store-reads/learning.js +159 -321
  244. package/dist/store-reads/loop.d.ts +0 -1
  245. package/dist/store-reads/loop.js +1 -1
  246. package/dist/store-view.d.ts +29 -1
  247. package/dist/store-view.js +97 -31
  248. package/dist/template-eval.d.ts +3 -6
  249. package/dist/template-eval.js +22 -36
  250. package/dist/templates.d.ts +8 -4
  251. package/dist/templates.js +44 -6
  252. package/dist/timeline/index.d.ts +1 -1
  253. package/dist/timeline/index.js +1 -1
  254. package/dist/timeline/timeline.d.ts +5 -1
  255. package/dist/timeline/timeline.js +16 -0
  256. package/dist/tool-gate.d.ts +0 -7
  257. package/dist/tool-gate.js +1 -15
  258. package/dist/tool-keys-store.d.ts +1 -1
  259. package/dist/tool-keys.d.ts +6 -4
  260. package/dist/tool-keys.js +12 -6
  261. package/dist/tools.d.ts +2 -2
  262. package/dist/tools.js +11 -4
  263. package/dist/triggers.d.ts +65 -6
  264. package/dist/triggers.js +125 -19
  265. package/dist/validate.js +1 -1
  266. package/dist/webhooks.d.ts +7 -2
  267. package/dist/webhooks.js +12 -5
  268. package/dist/workspace/agent-computer.d.ts +2 -0
  269. package/dist/workspace/agent-computer.js +2 -0
  270. package/dist/workspace/archil-claim.d.ts +7 -0
  271. package/dist/workspace/archil-claim.js +29 -0
  272. package/dist/workspace/archil.d.ts +9 -1
  273. package/dist/workspace/archil.js +165 -3
  274. package/dist/workspace/attach.d.ts +3 -1
  275. package/dist/workspace/attach.js +2 -0
  276. package/dist/workspace/attached-computers.d.ts +16 -5
  277. package/dist/workspace/attached-computers.js +25 -9
  278. package/dist/workspace/computer-deps.js +1 -1
  279. package/dist/workspace/computer-for-claim.d.ts +7 -3
  280. package/dist/workspace/computer-for-claim.js +119 -22
  281. package/dist/workspace/computer-hold.js +2 -1
  282. package/dist/workspace/computer-kept.d.ts +11 -1
  283. package/dist/workspace/computer-kept.js +24 -3
  284. package/dist/workspace/resolve-computer.d.ts +33 -19
  285. package/dist/workspace/resolve-computer.js +172 -64
  286. package/dist/workspace/revision-skills.d.ts +1 -2
  287. package/dist/workspace/revision-skills.js +3 -4
  288. package/dist/workspace/run-workspace.d.ts +1 -1
  289. package/dist/workspace/run-workspace.js +5 -0
  290. package/dist/workspace/synced-folder.d.ts +85 -0
  291. package/dist/workspace/synced-folder.js +230 -0
  292. package/dist/workspace/workspace.d.ts +4 -0
  293. package/launcher/agentrun-serve +1 -1
  294. package/package.json +10 -10
  295. package/templates/README.md +8 -8
  296. package/templates/inbound-lead/agent.md +5 -4
  297. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  298. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  299. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  300. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  301. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  302. package/templates/inbound-lead/lead.schema.json +6 -5
  303. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  304. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  305. package/templates/kyb/agent.md +2 -1
  306. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  307. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  308. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  309. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  310. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  311. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  312. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  313. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  314. package/dist/console/assets/index-BUktRvS-.css +0 -1
  315. package/dist/console/assets/index-nB9kTfIN.js +0 -711
  316. package/dist/learn/grade.d.ts +0 -138
  317. package/dist/learn/grade.js +0 -682
  318. package/dist/learn/notes.d.ts +0 -81
  319. package/dist/learn/notes.js +0 -178
  320. package/dist/learn/reflect.d.ts +0 -77
  321. package/dist/learn/reflect.js +0 -228
  322. package/dist/learn/relevance.d.ts +0 -24
  323. package/dist/learn/relevance.js +0 -91
  324. package/dist/learn/seed-check.d.ts +0 -74
  325. package/dist/learn/seed-check.js +0 -103
  326. package/dist/learning-batch.d.ts +0 -291
  327. package/dist/learning-batch.js +0 -600
  328. package/dist/learning-evals.d.ts +0 -35
  329. package/dist/learning-evals.js +0 -99
  330. package/dist/native/context.d.ts +0 -6
  331. package/dist/native/context.js +0 -22
  332. package/dist/propose.d.ts +0 -52
  333. package/dist/propose.js +0 -224
  334. package/dist/runner/learning-ask.d.ts +0 -47
  335. package/dist/runner/learning-ask.js +0 -128
  336. package/dist/runner/learning-dispatch.d.ts +0 -45
  337. package/dist/runner/learning-dispatch.js +0 -99
  338. package/dist/runner/learning-factory.d.ts +0 -16
  339. package/dist/runner/learning-factory.js +0 -50
  340. package/dist/runner/learning-loop.d.ts +0 -273
  341. package/dist/runner/learning-loop.js +0 -521
  342. package/dist/usage.d.ts +0 -11
  343. package/dist/usage.js +0 -11
  344. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  345. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  346. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  347. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  348. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  349. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  350. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -6,8 +6,8 @@
6
6
  <meta name="color-scheme" content="light dark" />
7
7
  <title>AgentRun</title>
8
8
  <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23ff8000'/%3E%3Cpath d='M12 9l11 7-11 7z' fill='%23000'/%3E%3C/svg%3E" />
9
- <script type="module" crossorigin src="./assets/index-nB9kTfIN.js"></script>
10
- <link rel="stylesheet" crossorigin href="./assets/index-BUktRvS-.css">
9
+ <script type="module" crossorigin src="./assets/index-CZZeCReB.js"></script>
10
+ <link rel="stylesheet" crossorigin href="./assets/index-C2MYaUBa.css">
11
11
  </head>
12
12
  <body>
13
13
  <div id="root"></div>
@@ -44,7 +44,7 @@ export declare function jevKey(env: NodeJS.ProcessEnv): {
44
44
  key: string;
45
45
  } | undefined;
46
46
  /** How this server reaches Jev, when it does. */
47
- export declare const jevRoute: (env: NodeJS.ProcessEnv) => "openrouter" | "typesafe" | undefined;
47
+ export declare const jevRoute: (env: NodeJS.ProcessEnv) => "typesafe" | "openrouter" | undefined;
48
48
  /** The keys the server hands a workflow run's process, by name: Jev's, as TYPESAFE_API_KEY or, on the OpenRouter route,
49
49
  * as OPENROUTER_API_KEY whichever variable holds it; an OpenRouter key (openRouterKeyEnv) as OPENROUTER_API_KEY for
50
50
  * OpenRouter's Decisions models, on either Jev route; and Parallel's. */
@@ -0,0 +1,29 @@
1
+ import { type HostedDial } from "@parcha/agentrun-computer";
2
+ import { type AttachTiming } from "./computer-attach.js";
3
+ import type { Store } from "./store/index.js";
4
+ /** A runner's relay: its HostedDial for its providers, where its listener answers, and its close. */
5
+ export interface RunnerRelay {
6
+ readonly dial: HostedDial;
7
+ readonly incarnation: string;
8
+ readonly host: string;
9
+ readonly port: number;
10
+ /** Its listener and every socket it took closed, its row gone. */
11
+ close(): Promise<void>;
12
+ }
13
+ export interface RunnerRelayOptions {
14
+ readonly store: Pick<Store, "mintedTokens" | "pairedComputers" | "runnerRelays">;
15
+ readonly sealKey: Buffer;
16
+ /** The runner's name, as its claims and its row carry it. */
17
+ readonly runner: string;
18
+ /** AGENTRUN_PUBLIC_URL (or RENDER_EXTERNAL_URL), AGENTRUN_RUNNER_LIVE_HOST and AGENTRUN_RUNNER_LIVE_BIND. */
19
+ readonly env: NodeJS.ProcessEnv;
20
+ /** Told each line worth saying (a machine attached, refused); never a token. */
21
+ readonly log?: (line: string) => void;
22
+ /** For tests: the socket's liveness timing (the protocol's by default) and the clock. */
23
+ readonly timing?: AttachTiming;
24
+ readonly now?: () => number;
25
+ }
26
+ /** The server's public address as this runner's environment names it (cli.ts reads the same two), or undefined. */
27
+ export declare function publicUrlOf(env: NodeJS.ProcessEnv): string | undefined;
28
+ /** The runner's relay, started: undefined where its environment names no public address of the server's. */
29
+ export declare function startRunnerRelay(options: RunnerRelayOptions): Promise<RunnerRelay | undefined>;
@@ -0,0 +1,94 @@
1
+ // A dial computer under a runner in a process of its own (the image's server-and-runner, `agentrun-serve runner`): a
2
+ // hosted machine that dials (Fly Machines, Cloudflare, or E2B, Daytona or Modal set to dial) reaches the server's one
3
+ // public address, and the server relays its socket to the runner that made it.
4
+ //
5
+ // The runner builds its own HostedDial (the computer package's hosted/provider.ts): `url` is the server's public address
6
+ // (AGENTRUN_PUBLIC_URL, as the server reads it), `tokens` are minted into the shared store with the runner's name and
7
+ // this incarnation on each row (computer-attach.ts `owner`), and `hub` is the runner's own AttachHub. It serves that hub
8
+ // on a private attach listener: on loopback beside its server, or on its live host (AGENTRUN_RUNNER_LIVE_HOST,
9
+ // live-reach.ts) where it runs on another host, and keeps where in the store (runner_relays), renewed every
10
+ // RELAY_RENEW_MS. The server's attach upgrade looks a token up, sees another runner owns it, and opens a socket to that
11
+ // runner's listener (computer-attach.ts relayDial) with the proxy's proof under the seal key (live-reach.ts relayProof).
12
+ // The listener answers nothing without a good, fresh proof it has not taken before, for this token, this runner and
13
+ // this incarnation, on loopback too, and its attach routes take only a token whose row names this runner and
14
+ // incarnation. The daemon fetch stays the server's; nothing changes on the machine.
15
+ //
16
+ // A runner with no public address keeps no relay: its dial providers still refuse (hosted/provider.ts), and the server's
17
+ // Settings → Computers still says so (computers.ts runs_refused).
18
+ import { randomUUID } from "node:crypto";
19
+ import { createServer } from "node:http";
20
+ import { ATTACH_PATH, AttachHub } from "@parcha/agentrun-computer";
21
+ import { bearerOf, createAttachRoutes, RELAY_RENEW_MS, sha256Hex } from "./computer-attach.js";
22
+ import { LOOPBACK, relayKeyOf, relayProofs, runnerLiveOf } from "./live-reach.js";
23
+ import { logLine } from "./print.js";
24
+ /** The server's public address as this runner's environment names it (cli.ts reads the same two), or undefined. */
25
+ export function publicUrlOf(env) {
26
+ const given = env.AGENTRUN_PUBLIC_URL || env.RENDER_EXTERNAL_URL;
27
+ const parsed = given && URL.canParse(given) ? new URL(given) : undefined;
28
+ return parsed && /^https?:$/.test(parsed.protocol) ? parsed.href.replace(/\/+$/, "") : undefined;
29
+ }
30
+ /** The runner's relay, started: undefined where its environment names no public address of the server's. */
31
+ export async function startRunnerRelay(options) {
32
+ const url = publicUrlOf(options.env);
33
+ if (url === undefined)
34
+ return undefined;
35
+ const { store, runner, now = Date.now } = options;
36
+ const log = options.log ?? (() => { });
37
+ const incarnation = randomUUID();
38
+ const live = runnerLiveOf(options.env, options.sealKey);
39
+ const host = live?.host ?? LOOPBACK;
40
+ const hub = new AttachHub();
41
+ const routes = createAttachRoutes({
42
+ store, hub, machinesOnly: true, owner: { runner, incarnation }, now,
43
+ log: (event, fields) => log(logLine(event, fields)),
44
+ ...(options.timing ? { timing: options.timing } : {}),
45
+ });
46
+ const proven = relayProofs(relayKeyOf(options.sealKey), now);
47
+ const deny = (socket, status, words = "", headers = {}) => {
48
+ const lines = Object.entries({ ...headers, "content-type": "text/plain; charset=utf-8", "content-length": String(Buffer.byteLength(words)) }).map(([name, value]) => `${name}: ${value}\r\n`).join("");
49
+ socket.end(`HTTP/1.1 ${status}\r\nConnection: close\r\n${lines}\r\n${words}`);
50
+ };
51
+ // Nothing but the attach upgrade, and that only with the server's proof for its token, this runner and incarnation.
52
+ const server = createServer((_req, res) => void res.writeHead(404, { "content-length": "0" }).end());
53
+ server.on("upgrade", (req, socket, head) => {
54
+ socket.on("error", () => socket.destroy());
55
+ if ((req.url ?? "/").split("?")[0] !== ATTACH_PATH)
56
+ return deny(socket, "404 Not Found");
57
+ const bearer = bearerOf(req.headers.authorization);
58
+ if (bearer === undefined || !proven(req, { tokenSha256: sha256Hex(bearer), runner, incarnation }))
59
+ return deny(socket, "401 Unauthorized");
60
+ routes.upgrade(req, socket, head, (status, words, headers) => deny(socket, status, words, headers));
61
+ });
62
+ await new Promise((resolve, reject) => {
63
+ server.once("error", reject);
64
+ server.listen(0, live?.bind ?? LOOPBACK, () => (server.off("error", reject), resolve()));
65
+ });
66
+ const port = server.address().port;
67
+ const shut = async () => {
68
+ await routes.close();
69
+ server.closeAllConnections();
70
+ await new Promise((resolve) => server.close(() => resolve()));
71
+ };
72
+ try {
73
+ await store.runnerRelays.put({ runner, incarnation, host, port });
74
+ }
75
+ catch (error) {
76
+ await shut();
77
+ throw error;
78
+ }
79
+ // Said again on its interval, so the server takes a runner that died without its close as gone (RELAY_STALE_MS).
80
+ const renew = setInterval(() => void store.runnerRelays.seen(runner, incarnation).catch(() => undefined), RELAY_RENEW_MS);
81
+ renew.unref();
82
+ let closing;
83
+ return {
84
+ dial: { url, tokens: routes.machineTokens, hub },
85
+ incarnation,
86
+ host,
87
+ port,
88
+ close: () => (closing ??= (async () => {
89
+ clearInterval(renew);
90
+ await store.runnerRelays.remove(runner, incarnation).catch(() => undefined);
91
+ await shut();
92
+ })()),
93
+ };
94
+ }
@@ -17,6 +17,11 @@ import { defineExtension, defineTool } from "@earendil-works/pi-durable";
17
17
  import { forModel } from "../result.js";
18
18
  import { isObject } from "../validate.js";
19
19
  import { isGmailAccount, keepsSentCopy, keptAccount, NO_ACCOUNT, openAccount } from "./account.js";
20
+ import { held } from "../runner/held.js";
21
+ /** Whether this process can open the server's email account: with the seal key, or through its runner (held.ts). */
22
+ const opens = (host) => host.store !== undefined && (host.sealKey !== undefined || held() !== undefined);
23
+ /** The server's email account, opened here with the seal key, or by the runner for a run its revision grants it. */
24
+ const accountOf = async (host) => (host.sealKey ? openAccount(host.store, host.sealKey) : held()?.emailAccount());
20
25
  import { EMAIL_ANSWER_MAX_CHARS, emailError, emailText } from "./answer.js";
21
26
  import { archiveDescription, EMAIL_ADDRESS, EMAIL_DESCRIPTIONS, EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SEARCH, EMAIL_SEND, fileDescription, LIMIT_DEFAULT, LIMIT_MAX, OUTSIDE_THREAD, SEND_CAP } from "./names.js";
22
27
  import { composed, foundOf, inThread, involves, MailError, READ_BYTES, readOf, SEARCH_BYTES, SENT_HEADER, smtpSend, TOOL_SOCKET_TIMEOUT_MS, withImap } from "./mail.js";
@@ -393,7 +398,7 @@ export async function sendAsks(args, ctx) {
393
398
  /** The recipients of the send `args` outside the run's thread, in words; nothing on a run that reads the whole account. */
394
399
  async function outsideWords(host, args) {
395
400
  const scope = await scopeOf(host, EMAIL_READ);
396
- if (scope.kind === "mailbox" || !host.store || !host.sealKey)
401
+ if (scope.kind === "mailbox" || !opens(host))
397
402
  return undefined;
398
403
  let recipients;
399
404
  try {
@@ -404,7 +409,7 @@ async function outsideWords(host, args) {
404
409
  return undefined;
405
410
  }
406
411
  try {
407
- const account = await openAccount(host.store, host.sealKey);
412
+ const account = await accountOf(host);
408
413
  // No account, or one a template eval's run may not open: the send itself is refused in its own words.
409
414
  if (!account || !fakeHeld(host, account))
410
415
  return undefined;
@@ -530,9 +535,9 @@ function emailTool(name, host, kind) {
530
535
  replay: tool.replay,
531
536
  execute: async (args) => {
532
537
  try {
533
- if (!host.store || !host.sealKey)
538
+ if (!opens(host))
534
539
  return forModel(`${name}: the email tools run on the runner, which this run is not on.`, { isError: true });
535
- const account = await openAccount(host.store, host.sealKey);
540
+ const account = await accountOf(host);
536
541
  if (!account)
537
542
  return forModel(`${name}: ${NO_ACCOUNT}`, { isError: true });
538
543
  if (!fakeHeld(host, account))
@@ -554,7 +559,7 @@ function emailTool(name, host, kind) {
554
559
  * kind of server, read once at bind from the account's row (no connection; the password is never used); a template
555
560
  * eval's fake account says the kind it plays. */
556
561
  export async function bindEmail(name, host) {
557
- const kept = name === EMAIL_FILE && !host.emailFake && host.store && host.sealKey ? await keptAccount(host.store, host.sealKey) : undefined;
562
+ const kept = name === EMAIL_FILE && !host.emailFake && opens(host) ? (host.sealKey ? await keptAccount(host.store, host.sealKey) : await accountOf(host)) : undefined;
558
563
  const registration = emailTool(name, host, host.emailFake ? host.emailFake.kind : kept ? (isGmailAccount(kept) ? "gmail" : "folders") : undefined);
559
564
  const extension = defineExtension({ name: name.replaceAll("_", "-"), tools: [registration] });
560
565
  host.install(extension);
@@ -0,0 +1,2 @@
1
+ /** Installs the proxy the environment names for this process's fetch, WebSocket, http(s) and gRPC; nothing when none. */
2
+ export declare function installEnvProxy(env?: NodeJS.ProcessEnv): void;
@@ -0,0 +1,35 @@
1
+ // The process's outbound calls through the standard proxy variables, as curl and Node's own --use-env-proxy read them:
2
+ // https_proxy or HTTPS_PROXY, http_proxy or HTTP_PROXY (lowercase first), and no_proxy or NO_PROXY for the hosts that go
3
+ // direct. cli.ts calls it first, for every command, so the server and the runner make every vendor call through one
4
+ // proxy (a gateway that holds the allowlist). Neither proxy set: nothing changes.
5
+ //
6
+ // Node's http.setGlobalProxyFromEnv covers fetch, Node's global WebSocket (both undici's global dispatcher) and
7
+ // http(s).request on the global agent. gRPC (@grpc/grpc-js, under Modal's and boxd's SDKs) reads only its own lowercase
8
+ // names, so grpc_proxy and no_grpc_proxy are set from the same values, each unless already set. The two
9
+ // clients none of this reaches, E2B's SDK and Morph's SSH gateway, take the proxy installed here from Node's https
10
+ // global agent through @parcha/agentrun-computer's env-proxy.ts, which reads no environment. This machine's loopback and the server's own public address
11
+ // (AGENTRUN_PUBLIC_URL, RENDER_EXTERNAL_URL: where dialing computers reach the attach hub) always go direct.
12
+ import * as http from "node:http";
13
+ /** Installs the proxy the environment names for this process's fetch, WebSocket, http(s) and gRPC; nothing when none. */
14
+ export function installEnvProxy(env = process.env) {
15
+ const https = env.https_proxy || env.HTTPS_PROXY;
16
+ const plain = env.http_proxy || env.HTTP_PROXY;
17
+ if (!https && !plain)
18
+ return;
19
+ const given = (env.no_proxy || env.NO_PROXY || "").split(",").map((entry) => entry.trim()).filter(Boolean);
20
+ // grpc-js reads grpc_proxy (else a lowercase https_proxy or http_proxy) and no_grpc_proxy (else no_proxy) when it opens
21
+ // a channel, each no_grpc_proxy entry a suffix of the host, with no "*". Set in process.env, they reach this process's
22
+ // children too. A name already set is left as it is.
23
+ if (given.includes("*")) {
24
+ // Every host direct: nothing to install (undici takes "*" only as the whole list). gRPC gets an empty entry, which
25
+ // is a suffix of every host, so a lowercase https_proxy it reads by itself is not used either.
26
+ env.no_grpc_proxy ||= ",";
27
+ return;
28
+ }
29
+ const own = [env.AGENTRUN_PUBLIC_URL, env.RENDER_EXTERNAL_URL].flatMap((url) => (url && URL.canParse(url) ? [new URL(url).hostname] : []));
30
+ const direct = [...given, "localhost", "127.0.0.1", "::1", "[::1]", ...own];
31
+ const setGlobalProxyFromEnv = http.setGlobalProxyFromEnv;
32
+ setGlobalProxyFromEnv({ ...(https ? { HTTPS_PROXY: https } : {}), ...(plain ? { HTTP_PROXY: plain } : {}), NO_PROXY: direct.join(",") });
33
+ env.grpc_proxy ||= https || plain;
34
+ env.no_grpc_proxy ||= direct.map((entry) => entry.replace(/^\*\./, ".")).join(",");
35
+ }
package/dist/errors.d.ts CHANGED
@@ -52,8 +52,10 @@ export declare const ERROR_STATUS: {
52
52
  readonly composio_account_ambiguous: 409;
53
53
  readonly composio_in_use: 409;
54
54
  readonly external_body_conflict: 409;
55
- readonly learned_not_active: 409;
56
55
  readonly replay_conflict: 409;
56
+ readonly agent_not_external: 409;
57
+ readonly runs_in_flight: 409;
58
+ readonly learning_busy: 409;
57
59
  readonly model_key_required: 422;
58
60
  };
59
61
  export type ErrorCode = keyof typeof ERROR_STATUS;
package/dist/errors.js CHANGED
@@ -69,17 +69,20 @@ export const ERROR_STATUS = {
69
69
  // A run of an agent given inline (POST /runs) under a version of its source already run here with another definition: a
70
70
  // version's definition never changes here, so the source publishes a new version.
71
71
  external_body_conflict: 409,
72
- // A learned workflow made into an agent of its own while it waits for its owner's OK or is retired: only an active one
73
- // is (learning-routes.ts promotable).
74
- learned_not_active: 409,
75
72
  // A replay its owner asked of a learned workflow's revision that cannot start now (runner/promotion.ts askReplay): one
76
73
  // replays already, another revision of it replays, it is promoted, or no graded input fits it.
77
74
  replay_conflict: 409,
75
+ // DELETE /agents/{id} (agent-delete.ts): an agent made here, which is archived instead; an agent whose runs did not end
76
+ // by the delete's wait (or one only its application ends, an SDK run's); an agent whose learning refused its delete
77
+ // while learning work was in flight. The last two leave the agent refusing runs, and a DELETE sent again finishes it.
78
+ agent_not_external: 409,
79
+ runs_in_flight: 409,
80
+ learning_busy: 409,
78
81
  // A run start, or a message that would start a turn, with no model_key where the server holds no key for the run's
79
82
  // model (run-model-key.ts): nothing to spend, so refused before any model call.
80
83
  model_key_required: 422,
81
84
  };
82
- const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable", "github_failed"]);
85
+ const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable", "github_failed", "runs_in_flight", "learning_busy"]);
83
86
  export class ApiError extends Error {
84
87
  code;
85
88
  status;
@@ -1,3 +1,4 @@
1
+ import { type HostedDial } from "@parcha/agentrun-computer";
1
2
  import type { KeyTable, ProviderFactories } from "./computer-keys.js";
2
3
  import type { KindRegistry, ProviderEntry } from "./computers.js";
3
4
  import type { WatchOf } from "./workspace/computer-for-claim.js";
@@ -12,11 +13,16 @@ export interface FauxComputers {
12
13
  readonly kinds: KindRegistry;
13
14
  readonly factories: ProviderFactories;
14
15
  readonly keyTable: KeyTable;
15
- /** The claim's launch: a faux desktop; the faux sandboxes start nothing, in words. */
16
+ /** The claim's launch: a faux desktop, or a faux dial machine over `given.dial` (the runner's HostedDial), its token
17
+ * minted for the claim's run (`spec.run`) as a dial provider's create mints it; the faux sandboxes start nothing, in
18
+ * words. */
16
19
  launch(entry: ProviderEntry, spec: {
17
20
  readonly kind: ComputerSettingKind;
18
21
  readonly keys: Readonly<Record<string, string>>;
19
- }): Promise<FauxDesktop>;
22
+ readonly run?: string;
23
+ }, given?: {
24
+ readonly dial?: HostedDial;
25
+ }): Promise<FauxDesktop | LaunchedComputer>;
20
26
  /** Whether a provider id is one of these (the claim's launch takes it): any other is the package's. */
21
27
  owns(provider: string): boolean;
22
28
  }
@@ -2,14 +2,22 @@
2
2
  // faux model module stands in for a model. The console's real-browser flows drive Settings → Computers and a run's
3
3
  // desktop with it, with no Docker, no provider and no key that means anything. Only --faux reaches this module.
4
4
  //
5
- // Three providers, in the computer package's registry shape (SETTING_KINDS, PROVIDERS, servingRefusals):
5
+ // Four providers, in the computer package's registry shape (SETTING_KINDS, PROVIDERS, servingRefusals):
6
6
  // - faux-sandbox: a sandbox with one key, FAUX_SANDBOX_KEY. Ready once the key is saved; its test then passes. It starts
7
7
  // no computer.
8
8
  // - faux-broken: a sandbox with no key, whose test always fails: it is never reached. It starts no computer.
9
9
  // - faux-desktop: a desktop with no key. Its run computer answers screen.shot (a plain grey screen) and input.actions
10
10
  // (each action done, none performed). Its watch gives the run's live view grey frames and takes its input, so a --faux
11
11
  // run's desktop is watched and taken over through the same proxied viewer a real one's is; the release ends it.
12
+ // - faux-dial: a desktop with no key whose machine dials this server, as Fly Machines' and Cloudflare's do (its
13
+ // descriptor's connect is "dial"). Its launch mints the machine a token through the runner's HostedDial, and a machine
14
+ // in this process dials the dial's public address at /v2/computers/attach with it, as agentrun-dial does, answering
15
+ // hello, ping, screen.shot (a grey screen) and input.actions; the run's computer calls go over the socket the runner's
16
+ // hub took. No dial, or one with no public address: its launch refuses in words, as the computer package's does.
17
+ import { randomBytes } from "node:crypto";
12
18
  import { crc32, deflateSync } from "node:zlib";
19
+ import { ATTACH_PATH, ATTACH_SUBPROTOCOL, MAX_LINE_BYTES } from "@parcha/agentrun-computer";
20
+ import { WebSocket } from "ws";
13
21
  // The computer package's setting kinds and servingRefusals, as its kinds.ts gives them (the swap to its exports
14
22
  // replaces these two with the package's own).
15
23
  const SETTING_KINDS = {
@@ -43,15 +51,17 @@ const PROVIDERS = [
43
51
  entry({ id: "faux-sandbox", label: "Faux sandbox", keys: [{ name: "FAUX_SANDBOX_KEY", required: true }], mounts: ["bind"], metered: false, capabilities: [SANDBOX] }),
44
52
  entry({ id: "faux-broken", label: "Faux broken", keys: [], mounts: ["bind"], metered: false, capabilities: [SANDBOX] }),
45
53
  entry({ id: "faux-desktop", label: "Faux desktop", keys: [], mounts: [], metered: false, capabilities: [DESKTOP] }),
54
+ entry({ id: "faux-dial", label: "Faux dial", connect: "dial", keys: [], mounts: [], metered: false, capabilities: [DESKTOP] }),
46
55
  ];
47
56
  const KEYS = {
48
- keys: { "faux-sandbox": [{ name: "FAUX_SANDBOX_KEY", option: "apiKey", required: true }], "faux-broken": [], "faux-desktop": [] },
49
- labels: { "faux-sandbox": "Faux sandbox", "faux-broken": "Faux broken", "faux-desktop": "Faux desktop" },
57
+ keys: { "faux-sandbox": [{ name: "FAUX_SANDBOX_KEY", option: "apiKey", required: true }], "faux-broken": [], "faux-desktop": [], "faux-dial": [] },
58
+ labels: { "faux-sandbox": "Faux sandbox", "faux-broken": "Faux broken", "faux-desktop": "Faux desktop", "faux-dial": "Faux dial" },
50
59
  };
51
- /** Each faux provider's account test: faux-sandbox and faux-desktop answer, faux-broken is never reached. */
60
+ /** Each faux provider's account test: faux-sandbox, faux-desktop and faux-dial answer, faux-broken is never reached. */
52
61
  const FACTORIES = {
53
62
  "faux-sandbox": () => ({ testConnection: async () => ({ ok: true, value: { detail: "Faux sandbox: the faux account answered (no computer was made)" } }) }),
54
63
  "faux-desktop": () => ({ testConnection: async () => ({ ok: true, value: { detail: "Faux desktop: the faux account answered (no computer was made)" } }) }),
64
+ "faux-dial": () => ({ testConnection: async () => ({ ok: true, value: { detail: "Faux dial: the faux account answered (no computer was made)" } }) }),
55
65
  "faux-broken": () => ({ testConnection: async () => ({ ok: false, error: { code: "unreachable", message: "faux-broken is --faux's broken provider: it never answers" } }) }),
56
66
  };
57
67
  /** A PNG of one grey colour, `width` by `height`. */
@@ -77,6 +87,9 @@ const WIDTH = 1280;
77
87
  const HEIGHT = 800;
78
88
  /** How long a faux desktop's watch waits after a frame's ack before it gives the next. */
79
89
  const FRAME_MS = 1_000;
90
+ /** How long a faux dial machine's launch waits for its socket in the dial's hub; and its token's life. */
91
+ const DIAL_WAIT_MS = 10_000;
92
+ const DIAL_LIFE_MS = 60 * 60_000;
80
93
  /** --faux's computers: the server's Settings → Computers and start check read them, and its runner's claim launches them. */
81
94
  export function fauxComputers() {
82
95
  let started = 0;
@@ -146,14 +159,78 @@ export function fauxComputers() {
146
159
  },
147
160
  };
148
161
  }
162
+ /** A faux dial machine for a run: its token minted through `dial`, its socket dialled to the dial's public address, and
163
+ * the run's calls over the connection the dial's hub gives once it attached; its release revokes the token and ends
164
+ * the socket. Refused in words where the machine has nowhere to dial, or did not attach within DIAL_WAIT_MS. */
165
+ async function fauxDial(dial, run) {
166
+ // The computer package's words for a dial provider with no dial (hosted/provider.ts #dialed).
167
+ if (dial === undefined)
168
+ throw new Error("Faux dial machines dial in to this server, and this runner runs in a process of its own, with no attach hub to take their socket: start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)");
169
+ if (!dial.url)
170
+ throw new Error("Faux dial machines dial in to this server, which has no public address: set AGENTRUN_PUBLIC_URL");
171
+ const name = `faux-dial-${randomBytes(6).toString("hex")}`;
172
+ const token = await dial.tokens.mint(name, { kind: "desktop", os: "linux", arch: "amd64", expiresAt: new Date(Date.now() + DIAL_LIFE_MS), ...(run !== undefined ? { run } : {}) });
173
+ const png = greyPng(WIDTH, HEIGHT);
174
+ const hello = { protocol: "0.2", version: "faux", os: "linux", kind: "desktop", arch: "amd64", groups: [...DESKTOP_GROUPS], screen: { width: WIDTH, height: HEIGHT, scale: 1 } };
175
+ const machine = new WebSocket(`${dial.url.replace(/^http/, "ws")}${ATTACH_PATH}`, ATTACH_SUBPROTOCOL, { headers: { authorization: `Bearer ${token}` }, maxPayload: MAX_LINE_BYTES, perMessageDeflate: false });
176
+ let refused;
177
+ machine.on("error", (error) => void (refused ??= error.message));
178
+ machine.once("unexpected-response", (_req, res) => {
179
+ const words = [];
180
+ res.on("data", (chunk) => words.push(chunk));
181
+ res.on("end", () => void (refused ??= `HTTP ${res.statusCode}: ${Buffer.concat(words).toString("utf8")}`));
182
+ res.on("error", () => void (refused ??= `HTTP ${res.statusCode}`));
183
+ });
184
+ machine.on("message", (data, binary) => {
185
+ if (binary)
186
+ return;
187
+ let message;
188
+ try {
189
+ message = JSON.parse(String(data));
190
+ }
191
+ catch {
192
+ return;
193
+ }
194
+ if (message.id === undefined || typeof message.method !== "string")
195
+ return;
196
+ const answer = (reply) => machine.readyState === WebSocket.OPEN && machine.send(JSON.stringify({ jsonrpc: "2.0", id: message.id, ...reply }));
197
+ if (message.method === "hello")
198
+ return answer({ result: hello });
199
+ if (message.method === "ping")
200
+ return answer({ result: {} });
201
+ if (message.method === "screen.shot")
202
+ return answer({ result: { id: `${name}-shot`, data: png.toString("base64"), eof: true, size: png.length, width: WIDTH, height: HEIGHT } });
203
+ if (message.method === "input.actions")
204
+ return answer({ result: { done: Array.isArray(message.params?.actions) ? message.params.actions.length : 0 } });
205
+ return answer({ error: { code: -32601, message: `the faux dial machine has no ${message.method}` } });
206
+ });
207
+ const release = async () => {
208
+ machine.close(1000, "released");
209
+ await dial.tokens.revoke(name).catch(() => undefined);
210
+ dial.hub.revoke(name, `${name} was released`);
211
+ };
212
+ const until = Date.now() + DIAL_WAIT_MS;
213
+ for (;;) {
214
+ const connection = dial.hub.connection(name);
215
+ if (connection)
216
+ return { id: name, groups: [...DESKTOP_GROUPS], hello: connection.hello, client: connection.client, release };
217
+ if (refused !== undefined || Date.now() >= until) {
218
+ await release();
219
+ throw new Error(refused === undefined ? `the faux dial machine ${name} did not dial ${dial.url} within ${DIAL_WAIT_MS / 1000} s` : `the faux dial machine ${name}'s dial to ${dial.url} was refused: ${refused}`);
220
+ }
221
+ await new Promise((done) => setTimeout(done, 25));
222
+ }
223
+ }
149
224
  return {
150
225
  kinds: { SETTING_KINDS, PROVIDERS, servingRefusals },
151
226
  factories: FACTORIES,
152
227
  keyTable: KEYS,
153
- async launch(entryOf, spec) {
228
+ async launch(entryOf, spec, given = {}) {
154
229
  if (entryOf.id === "faux-desktop" && spec.kind === "desktop")
155
230
  return fauxDesktop();
156
- throw new Error(`${entryOf.label} starts no computer: under --faux, only Faux desktop does (set this agent's computer to desktop on Faux desktop, or none)`);
231
+ if (entryOf.id === "faux-dial" && spec.kind === "desktop")
232
+ return fauxDial(given.dial, spec.run);
233
+ throw new Error(`${entryOf.label} starts no computer: under --faux, only Faux desktop and Faux dial do (set this agent's computer to desktop on one of them, or none)`);
157
234
  },
158
235
  owns: (provider) => PROVIDERS.some((one) => one.id === provider),
159
236
  };
@@ -0,0 +1,67 @@
1
+ /** The codes an archive install's failures carry (ArchiveInstallFailed). */
2
+ export declare const ARCHIVE_CODES: Readonly<{
3
+ /** The pin has no archive for this platform, or no binary digest to check what it unpacks to. */
4
+ readonly platform: "HARNESS_PLATFORM_UNSUPPORTED";
5
+ /** The archive could not be downloaded: the network, a status other than 200, a size past the limit. */
6
+ readonly download: "HARNESS_DOWNLOAD_FAILED";
7
+ /** The archive downloaded is not the pin's: its sha256 differs. */
8
+ readonly archive: "HARNESS_ARCHIVE_MISMATCH";
9
+ /** tar could not unpack the verified archive, or it holds no binary at the pin's path. */
10
+ readonly unpack: "HARNESS_UNPACK_FAILED";
11
+ /** The binary the archive unpacked to is not the pin's: its sha256 differs. */
12
+ readonly binary: "HARNESS_BINARY_MISMATCH";
13
+ /** Another install into the same data directory is running. */
14
+ readonly busy: "HARNESS_INSTALL_BUSY";
15
+ }>;
16
+ export type ArchiveCode = (typeof ARCHIVE_CODES)[keyof typeof ARCHIVE_CODES];
17
+ /** One platform's release, as a pin holds it (the ACP registry's: acp's AcpArchivePin). */
18
+ export type ArchiveRelease = {
19
+ readonly url: string;
20
+ readonly format: string;
21
+ readonly sha256: string;
22
+ readonly cmd: string;
23
+ readonly binarySha256?: string;
24
+ };
25
+ /** A harness installed from an archive: its id and name, its pin, and the command that installs it (said on every failure). */
26
+ export type ArchiveHarness = {
27
+ readonly id: string;
28
+ readonly label: string;
29
+ readonly retry: string;
30
+ readonly pin: {
31
+ readonly version: string;
32
+ readonly archives: Readonly<Partial<Record<string, ArchiveRelease>>>;
33
+ };
34
+ };
35
+ /** A failed install, by its code (ARCHIVE_CODES): its message says why, and the command that tries again. */
36
+ export declare class ArchiveInstallFailed extends Error {
37
+ readonly code: ArchiveCode;
38
+ constructor(code: ArchiveCode, why: string, retry: string);
39
+ }
40
+ /** The largest archive an install takes: Goose's is about 60 MB. */
41
+ export declare const ARCHIVE_MAX_BYTES: number;
42
+ /** The most the download, and then tar, may each take. */
43
+ export declare const ARCHIVE_TIMEOUT_MS: number;
44
+ /** This host's platform as the ACP registry names it (`linux-x86_64`), or undefined for one it does not list. */
45
+ export declare function archivePlatform(platform?: string, arch?: string): string | undefined;
46
+ export interface ArchiveInstallOptions {
47
+ /** The platform, as the registry names it. Default this host's (archivePlatform). */
48
+ platform?: string;
49
+ /** For tests: the fetch the archive is downloaded with. */
50
+ fetch?: typeof fetch;
51
+ /** The tar that unpacks it. Default `tar` on PATH. */
52
+ tar?: string;
53
+ /** The environment tar's PATH is read from. Default process.env. Nothing else of it reaches tar. */
54
+ env?: NodeJS.ProcessEnv;
55
+ timeoutMs?: number;
56
+ maxBytes?: number;
57
+ /** Hears each step once it holds: `downloaded` (and its digest checked), `unpacked`, `verified` (the binary's digest). */
58
+ onStep?: (step: "downloaded" | "unpacked" | "verified") => void | Promise<void>;
59
+ }
60
+ /** Installs `harness` into `dir` (`<data>/harnesses/<id>`) from its pin's archive for this platform: downloaded, checked,
61
+ * unpacked beside `dir`, its binary checked, then renamed into place and made read-only. `already` when the pinned binary
62
+ * is in place (nothing is downloaded); `now` once this install put it there. Rejects with ArchiveInstallFailed, `dir` as it
63
+ * was. */
64
+ export declare function installArchive(harness: ArchiveHarness, dir: string, options?: ArchiveInstallOptions): Promise<{
65
+ installed: "already" | "now";
66
+ binary: string;
67
+ }>;