@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
package/dist/cli.js CHANGED
@@ -17,6 +17,7 @@ import { parseTokens } from "./api-token.js";
17
17
  import { apiOnlyFrom } from "./api-only.js";
18
18
  import { harnessModulesOf } from "./harness-table.js";
19
19
  import { surviveClosedPipes } from "./closed-pipes.js";
20
+ import { installEnvProxy } from "./env-proxy.js";
20
21
  import { startTelemetry } from "./telemetry.js";
21
22
  // The rest of the server (server.js, the runner, the harness adapters) loads after the port is bound (listen-first.ts):
22
23
  // on a slow disk that load is most of a start. Nothing above loads more than a few files.
@@ -24,9 +25,13 @@ import { DEFAULT_HOST, DEFAULT_PORT, listenFirst, urlOf } from "./listen-first.j
24
25
  // A stdout or stderr its reader closed loses the lines written after, never the process (closed-pipes.ts): for every
25
26
  // command, the server and the runner alike.
26
27
  surviveClosedPipes();
27
- const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--faux-github] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL] [--no-runner] [--harness-module MODULE ...]
28
+ // Every outbound call through the proxy HTTPS_PROXY or HTTP_PROXY names, NO_PROXY's hosts and loopback direct
29
+ // (env-proxy.ts): for every command, before anything calls out. Neither set, nothing changes.
30
+ installEnvProxy();
31
+ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--faux-github] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--no-runner] [--harness-module MODULE ...]
28
32
  agentrun-serve reset-password [--data DIR]
29
33
  agentrun-serve validate-template DIR
34
+ agentrun-serve install-harness goose [--data DIR]
30
35
  agentrun-serve eval-template DIR [--case NAME ...] [--runs N] [--server URL | --on-data DIR] [--grader-model PROVIDER/MODEL] [--report FILE] [--faux MODULE]
31
36
  agentrun-serve import [--data DIR] [--from claude-code,codex,pi] [--dry-run] [--include-deleted] [--all] [--verbose] [--port N]
32
37
  agentrun-serve runner --data DIR [--loops N] [--drain-timeout D] [--name NAME]
@@ -58,11 +63,6 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
58
63
  resumes at the next start
59
64
  --learning on|off whether runs learn (default on, or AGENTRUN_SERVE_LEARNING): on, a run of an agent whose definition
60
65
  says learning: true starts from what that agent learned and adds to it; off, no run does
61
- --learning-budget BYTES how much of what an agent learned its run's instructions hold (default
62
- AGENTRUN_SERVE_LEARNING_BUDGET, else 8000): every note whole while they fit, else the index and the
63
- notes changed last, whole, while they fit
64
- --grade-model MODEL the model that grades what a run proposes to learn (default AGENTRUN_SERVE_GRADE_MODEL, else the
65
- strong tier, AGENT_MODEL_STRONG, else each run's own model), named as the strong tier takes one
66
66
  --harness-module MODULE
67
67
  a harness module to add harnesses from (repeatable; default AGENTRUN_SERVE_HARNESS_MODULES, comma-
68
68
  separated): a path, or a package installed with npm install --prefix DIR/harnesses PACKAGE, whose
@@ -155,6 +155,46 @@ if (process.argv[2] === "reset-password") {
155
155
  console.log(`The password is cleared and every browser is signed out (${target}). The next visit to the page sets a new one.`);
156
156
  process.exit(0);
157
157
  }
158
+ // A harness its owner installs (harness-goose.ts: Goose, the one there is), never a run: its pinned archive downloaded,
159
+ // checked and unpacked into DIR/harnesses/<name> (harness-archive.ts). 0 once it is there (now or already), 1 when the
160
+ // install failed (its code and the command to try again), 2 for a name it does not install. No provider key is read.
161
+ if (process.argv[2] === "install-harness") {
162
+ const usage = (message) => (console.error(`agentrun-serve install-harness: ${message}\n\n${USAGE}`), process.exit(2));
163
+ const read = () => {
164
+ try {
165
+ return parseArgs({ args: process.argv.slice(3), options: { data: { type: "string" } }, allowPositionals: true });
166
+ }
167
+ catch (error) {
168
+ return usage(error.message);
169
+ }
170
+ };
171
+ const { values, positionals } = read();
172
+ const { GOOSE_ID, installGoose } = await import("./harness-goose.js");
173
+ if (positionals.length !== 1)
174
+ usage(`it takes one harness: ${GOOSE_ID}.`);
175
+ if (positionals[0] !== GOOSE_ID)
176
+ usage(`it installs ${GOOSE_ID}, not ${positionals[0]}: claude-agent and codex install on first use, and pi and opencode come with AgentRun.`);
177
+ const [{ ArchiveInstallFailed }, { acpPackage, ACP_PACKAGE }] = await Promise.all([import("./harness-archive.js"), import("./acp-package.js")]);
178
+ if (!acpPackage()) {
179
+ console.error(`Goose's adapter (${ACP_PACKAGE}) is not installed beside this server, so it has no pinned release to install.`);
180
+ process.exit(1);
181
+ }
182
+ const data = resolve(values.data ?? defaultData());
183
+ try {
184
+ const said = { downloaded: "the archive is downloaded and its sha256 matches the pin", unpacked: "unpacked", verified: "the binary's sha256 matches the pin" };
185
+ const { version, installed, binary } = await installGoose(data, { onStep: (step) => console.error(`Goose: ${said[step]}`) });
186
+ console.log(installed === "already"
187
+ ? `Goose ${version} is installed in ${dirname(binary)} (already: the pinned binary is there, so nothing was downloaded).`
188
+ : `Goose ${version} is installed in ${dirname(binary)} (now). Restart AgentRun to pick it up.`);
189
+ process.exit(0);
190
+ }
191
+ catch (error) {
192
+ if (!(error instanceof ArchiveInstallFailed))
193
+ throw error;
194
+ console.error(error.message);
195
+ process.exit(1);
196
+ }
197
+ }
158
198
  // A template package folder checked by the one validator the server runs on the packages it ships (templates.ts): what
159
199
  // it holds as one JSON line and 0, or each problem and 1. Nothing in the package runs.
160
200
  if (process.argv[2] === "validate-template") {
@@ -300,8 +340,6 @@ try {
300
340
  documents: { type: "string" },
301
341
  "allow-code-nodes": { type: "boolean", default: false },
302
342
  learning: { type: "string" },
303
- "grade-model": { type: "string" },
304
- "learning-budget": { type: "string" },
305
343
  "no-runner": { type: "boolean", default: false },
306
344
  "harness-module": { type: "string", multiple: true, default: [] },
307
345
  help: { type: "boolean", short: "h", default: false },
@@ -341,11 +379,6 @@ if (values["faux-github"] && !values.faux) {
341
379
  console.error(`--faux-github goes with --faux\n\n${USAGE}`);
342
380
  process.exit(2);
343
381
  }
344
- const budget = values["learning-budget"];
345
- if (budget !== undefined && !/^\d+$/.test(budget)) {
346
- console.error(`--learning-budget takes a whole number of bytes\n\n${USAGE}`);
347
- process.exit(2);
348
- }
349
382
  const data = values.data ?? defaultData();
350
383
  const given = secret("AGENTRUN_TOKEN") || undefined;
351
384
  // More tokens, each with an id (api-token.ts), for a rotation with no caller refused; never printed. A list that cannot
@@ -415,7 +448,7 @@ try {
415
448
  ...(values["max-runs"] !== undefined ? { maxRuns: Number(values["max-runs"]) } : {}),
416
449
  // The owner's harness modules: --harness-module, else AGENTRUN_SERVE_HARNESS_MODULES (harness-table.ts).
417
450
  ...(harnessModulesOf(values["harness-module"], process.env).length ? { harnessModules: harnessModulesOf(values["harness-module"], process.env) } : {}),
418
- ...(values["drain-timeout"] ? { drainTimeout: values["drain-timeout"] } : {}), ...(values.documents ? { documents: values.documents } : {}), ...(values["allow-code-nodes"] ? { allowCodeNodes: true } : {}), ...(values.learning !== undefined ? { learning: values.learning } : {}), ...(values["grade-model"] ? { gradeModel: values["grade-model"] } : {}), ...(budget !== undefined ? { learningBudget: Number(budget) } : {}), log: (line) => void process.stdout.write(`${line}\n`),
451
+ ...(values["drain-timeout"] ? { drainTimeout: values["drain-timeout"] } : {}), ...(values.documents ? { documents: values.documents } : {}), ...(values["allow-code-nodes"] ? { allowCodeNodes: true } : {}), ...(values.learning !== undefined ? { learning: values.learning } : {}), log: (line) => void process.stdout.write(`${line}\n`),
419
452
  // The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
420
453
  ...(publicUrl ? { publicUrl } : {}),
421
454
  ...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}), ...(apiOnly ? { apiOnly } : {}),
@@ -423,6 +456,8 @@ try {
423
456
  ...(trustedProxies.length ? { trustedProxies } : {}),
424
457
  // A local install only as its operator says, never inferred: an MCP server on loopback is refused without it.
425
458
  ...(process.env.AGENTRUN_MCP_ALLOW_LOOPBACK === "1" ? { mcpLoopback: true } : {}),
459
+ // No runner beside this server: a paired computer's socket stays here, where no run reaches it, which the pairing says.
460
+ ...(values["no-runner"] ? { runnerApart: true } : {}),
426
461
  });
427
462
  }
428
463
  catch (error) {
@@ -438,7 +473,7 @@ let runnerProc;
438
473
  // Anonymous usage counts (telemetry.ts, docs/telemetry.md): off with AGENTRUN_TELEMETRY=0 or DO_NOT_TRACK=1, in CI and
439
474
  // under --faux. It hears each run's end from the runner beside the server; with --no-runner it counts no runs.
440
475
  const telemetry = startTelemetry({ data: resolve(data), ...(values.faux ? { faux: true } : {}) });
441
- const { loops, drainMs } = besideRunnerOptions(serveOptions, process.env);
476
+ const { loops, loopsTold, drainMs } = besideRunnerOptions(serveOptions, process.env);
442
477
  // A stop asked during the server's start starts no runner: nothing is claimed for the stop to cut.
443
478
  if (!values["no-runner"] && askedAt === undefined) {
444
479
  try {
@@ -451,12 +486,20 @@ if (!values["no-runner"] && askedAt === undefined) {
451
486
  // server's AttachHub: a paired computer's socket is in this process, so only this runner takes one (--no-runner's
452
487
  // separate runners refuse it in words). Its runs reach an MCP server on loopback only when this server is a local
453
488
  // install (Serve.localInstall).
454
- runnerProc = await runnerBeside(data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, onRunEnded: telemetry.runEnded });
489
+ // Each run a process of its own, as a user of its own where the image's helper can switch (run-child-host.ts).
490
+ runnerProc = await runnerBeside(data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true, ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, onRunEnded: telemetry.runEnded });
455
491
  }
456
492
  catch (error) {
457
- console.error(`agentrun-serve: the runner could not start: ${error.message}`);
458
- await serve.close();
459
- process.exit(1);
493
+ // A run isolation the runner cannot give (run-child-host.ts runIsolationOf) is said, and the server serves on with no
494
+ // runner, as the runner subcommand stays up claiming nothing (runner/main.ts): a platform that restarts a stopped
495
+ // container would otherwise loop on it.
496
+ const { RunIsolationRefused } = await import("./runner/run-child-host.js");
497
+ if (!(error instanceof RunIsolationRefused)) {
498
+ console.error(`agentrun-serve: the runner could not start: ${error.message}`);
499
+ await serve.close();
500
+ process.exit(1);
501
+ }
502
+ console.error(`agentrun-serve: ${error.message}`);
460
503
  }
461
504
  }
462
505
  // A token from the environment is the operator's already, and the stored one is printed by the start that made it only.
@@ -96,24 +96,71 @@ function needsNoAuth(kit) {
96
96
  return modes.length > 0 && modes.every((mode) => mode === "NO_AUTH");
97
97
  }
98
98
  const notFound = (toolkit) => `Composio has no toolkit ${toolkit}: use its slug (github, slack, gmail...).`;
99
- /** POST /settings/mcp-servers/composio/tools: a toolkit's actions, for the console's picker, and whether it needs no sign-in. */
100
- export async function composioTools(body, control, signal) {
101
- const { key, toolkit } = head(body);
102
- const ask = asking(control, key, signal);
103
- const kit = await ask("reading the toolkit", "GET", `/api/v3/toolkits/${encodeURIComponent(toolkit)}`, undefined, notFound(toolkit));
99
+ /** A toolkit's actions, every page (at most MAX_PAGES), at its latest version: without toolkit_versions Composio lists its
100
+ * base version (00000000_00), which leaves out the actions added since (linear 21 of 48, stripe 33 of 435, live 11-18),
101
+ * though its MCP servers serve them. `complete`: the list ended within MAX_PAGES. */
102
+ async function toolkitTools(ask, toolkit) {
104
103
  const tools = [];
105
104
  let cursor;
106
105
  for (let page = 0; page < MAX_PAGES; page++) {
107
- const listed = await ask("listing the toolkit's actions", "GET", `/api/v3/tools?toolkit_slug=${encodeURIComponent(toolkit)}&limit=${PAGE}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`, undefined, notFound(toolkit));
106
+ const listed = await ask("listing the toolkit's actions", "GET", `/api/v3/tools?toolkit_slug=${encodeURIComponent(toolkit)}&toolkit_versions=latest&limit=${PAGE}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`, undefined, notFound(toolkit));
108
107
  for (const item of Array.isArray(listed.items) ? listed.items : [])
109
108
  if (isObject(item) && text(item.slug))
110
109
  tools.push({ slug: text(item.slug), name: text(item.name) || text(item.slug), description: text(item.description) });
111
110
  cursor = text(listed.next_cursor) || undefined;
112
111
  if (!cursor)
113
- break;
112
+ return { tools, complete: true };
114
113
  }
114
+ return { tools, complete: false };
115
+ }
116
+ /** POST /settings/mcp-servers/composio/tools: a toolkit's actions, for the console's picker, and whether it needs no sign-in. */
117
+ export async function composioTools(body, control, signal) {
118
+ const { key, toolkit } = head(body);
119
+ const ask = asking(control, key, signal);
120
+ const kit = await ask("reading the toolkit", "GET", `/api/v3/toolkits/${encodeURIComponent(toolkit)}`, undefined, notFound(toolkit));
121
+ const { tools } = await toolkitTools(ask, toolkit);
115
122
  return { toolkit, no_auth: needsNoAuth(kit), tools };
116
123
  }
124
+ /** Edit distance (Levenshtein). */
125
+ function distance(a, b) {
126
+ let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
127
+ for (let i = 1; i <= a.length; i++) {
128
+ const row = [i];
129
+ for (let j = 1; j <= b.length; j++)
130
+ row[j] = Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
131
+ prev = row;
132
+ }
133
+ return prev[b.length];
134
+ }
135
+ /** The listed slug a missing one most likely means, when one is obvious: the same slug in another case, the one listed
136
+ * slug that only adds or drops a trailing _WORD, else the one within a typo's reach (an edit distance of at most
137
+ * max(2, length/10)). */
138
+ function likelySlug(slug, listed) {
139
+ const want = slug.toUpperCase();
140
+ const same = listed.find((s) => s.toUpperCase() === want);
141
+ if (same)
142
+ return same;
143
+ const extended = listed.filter((s) => s.toUpperCase().startsWith(`${want}_`) || want.startsWith(`${s.toUpperCase()}_`)).sort((a, b) => a.length - b.length);
144
+ if (extended.length === 1 || (extended.length > 1 && extended[0].length < extended[1].length))
145
+ return extended[0];
146
+ const reach = Math.max(2, Math.floor(want.length / 10));
147
+ let best;
148
+ let tie = false;
149
+ for (const s of listed) {
150
+ // An edit distance is at least the length difference: a slug that far off is skipped before the O(n·m) distance, so a
151
+ // huge pasted value against a big toolkit costs one length compare per action.
152
+ if (Math.abs(s.length - want.length) > reach)
153
+ continue;
154
+ const d = distance(want, s.toUpperCase());
155
+ if (d > reach)
156
+ continue;
157
+ if (!best || d < best.d)
158
+ [best, tie] = [{ slug: s, d }, false];
159
+ else if (d === best.d)
160
+ tie = true;
161
+ }
162
+ return best && !tie ? best.slug : undefined;
163
+ }
117
164
  /** The address Composio's generate answers, made one this server's client can use: the helper actions that connect an
118
165
  * account left off, and the path ended in /mcp (Composio redirects the bare one, which the client refuses on purpose). */
119
166
  export function composioAddress(generated) {
@@ -148,6 +195,21 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
148
195
  let url;
149
196
  try {
150
197
  const kit = await ask("reading the toolkit", "GET", `/api/v3/toolkits/${encodeURIComponent(toolkit)}`, undefined, notFound(toolkit));
198
+ // Every slug is one the toolkit lists (at its latest version), before anything is made: Composio makes a server
199
+ // allowing a slug it doesn't have, which then serves nothing under that name. A list longer than MAX_PAGES refuses
200
+ // nothing on what it didn't read; the check after the save (not_served) still names an action left out.
201
+ const offered = await toolkitTools(ask, toolkit);
202
+ const known = new Set(offered.tools.map((tool) => tool.slug));
203
+ const unknown = offered.complete ? [...new Set(tools)].filter((slug) => !known.has(slug)) : [];
204
+ if (unknown.length) {
205
+ // A slug past 128 characters is named by its first 64 and its length, so the refusal never carries a pasted megabyte back.
206
+ const names = unknown.map((slug) => {
207
+ const likely = likelySlug(slug, [...known]);
208
+ const shown = slug.length > 128 ? `${slug.slice(0, 64)}… (${slug.length} characters)` : slug;
209
+ return likely ? `${shown} (did you mean ${likely}?)` : shown;
210
+ });
211
+ throw invalid([issue("tools", "not_found", `Composio's ${toolkit} toolkit has no action ${names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} or ${names.at(-1)}`}: pick from its list (POST /settings/mcp-servers/composio/tools). Nothing was saved.`)]);
212
+ }
151
213
  const noAuth = needsNoAuth(kit);
152
214
  let authConfig;
153
215
  let madeConfig = false;
@@ -51,9 +51,23 @@ export declare class ComposioTriggers implements TriggerUpstream {
51
51
  private readonly queues;
52
52
  constructor(deps: ComposioTriggerDeps);
53
53
  make<T>(source: Source, id: string, enabled: boolean, keep: (source: Source) => Promise<T>): Promise<T>;
54
+ /** A source sent whole again for trigger `id` (`was`), as an apply with agent_id sends its package's, its credentials in
55
+ * the clear: each sealed field whose value it sends is the value sealed (compared in constant time) is left out, so the
56
+ * PATCH keeps it (patched); then patched's own check, so another value, or any other change to the config, is refused
57
+ * here, before the caller writes anything, in patched's words (none holds a value). The answer is the source to PATCH
58
+ * the trigger with: no sealed value is in it. */
59
+ resent(was: Source, id: string, given: Source): Source;
54
60
  patched(was: Source, given: Source): Source;
55
61
  turned(source: Source, id: string, on: boolean): Promise<Json | undefined>;
56
62
  removed(source: Source, id: string): Promise<Json | undefined>;
63
+ removedThere(source: Source, id: string, here: () => Promise<void>): Promise<Json | undefined>;
64
+ forgotten(source: Source, id: string): Promise<void>;
65
+ /** The trigger `id`'s instance on Composio deleted, or turned off while other triggers hold it (none of them on), or
66
+ * kept (one of them on): undefined when that is done, else what is left there, said. `values`: its sealed config's,
67
+ * withheld from Composio's words. `here`, once that is done, in the same step of the project's: the trigger's delete
68
+ * here, so the next removal of a trigger sharing the instance reads the holders without it (two removals at once
69
+ * never each keep the instance for the other); its refusal is thrown, never said as Composio's. */
70
+ private leftThere;
57
71
  /** GET /settings/mcp-servers/{name}/composio/events: its toolkit's events, every page. */
58
72
  events(name: string): Promise<{
59
73
  server: string;
@@ -12,7 +12,8 @@
12
12
  // resuming and deleting follow on Composio once the change holds here, and so does the server turning a trigger off
13
13
  // itself (triggers.ts); what Composio could not do is said, with what to do by hand.
14
14
  // - One project's steps run one at a time (serial): a create's setup, its save here and its undo, a pause, a delete, a
15
- // rotate, the subscription's delete and the saved server's delete. Each reads the triggers holding what it would undo,
15
+ // rotate, the subscription's delete and the saved server's delete; a template update's removal (removedThere) deletes
16
+ // its trigger here in the same step, once Composio is done. Each reads the triggers holding what it would undo,
16
17
  // turn off or delete as they are then, so it never removes what another holds, a pause or resume sets the instance as
17
18
  // its triggers now stand, and a create re-reads its saved server before it saves, so no trigger outlives its server.
18
19
  // - A config field named like a credential (trigger-composio.ts sealedConfigFields) is sealed at the create, each under
@@ -22,7 +23,7 @@
22
23
  // its key in the clear is answered masked all the same (shownSource), and sealed at the next start (sealKept).
23
24
  // No public address (AGENTRUN_PUBLIC_URL): Composio can't reach this server, so making one is refused before Composio is
24
25
  // asked anything.
25
- import { createHash, randomBytes } from "node:crypto";
26
+ import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
26
27
  import { ApiError, invalid } from "./errors.js";
27
28
  import { asking } from "./composio-preset.js";
28
29
  import { COMPOSIO_HOOK, COMPOSIO_SECRET, CONFIG_SECRET, CONFIG_UNLISTED, configScope, configSecrets, MOVE_FIELD, SEALED_FIELD, SEALED_MASK, sealableValue, sealedConfigFields, sealedKept, sealedSchemaFields, shownSource } from "./trigger-composio.js";
@@ -44,6 +45,18 @@ const sealedOf = (source) => (Array.isArray(source[SEALED_FIELD]) ? source[SEALE
44
45
  /** The settings field a sealed config value is kept under: one the list of the server's secrets can hold (8 bytes or
45
46
  * more, no whitespace), else the unlisted one. */
46
47
  const configFieldFor = (value) => (!/\s/.test(value) && Buffer.byteLength(value, "utf8") >= 8 ? CONFIG_SECRET : CONFIG_UNLISTED);
48
+ /** The keys of a sealed_config name's place in the config: a top-level name as it is, a JSON Pointer's unescaped. */
49
+ const placeOf = (name) => (name.startsWith("/") ? name.slice(1).split("/").map((key) => key.replace(/~1/g, "/").replace(/~0/g, "~")) : [name]);
50
+ /** The value at `path` in `config` where it is still kept in the clear (a trigger an earlier server saved), as text. */
51
+ const clearAt = (config, path) => {
52
+ let node = config;
53
+ for (const key of path)
54
+ node = isObject(node) ? node[key] : Array.isArray(node) ? node[Number(key)] : undefined;
55
+ return (typeof node === "string" || typeof node === "number") && node !== SEALED_MASK ? String(node) : undefined;
56
+ };
57
+ /** Whether two secrets are equal, in time that does not depend on where they differ: each digested first, so two of
58
+ * different lengths compare as two equal-length buffers. */
59
+ const sameSecret = (a, b) => timingSafeEqual(createHash("sha256").update(a, "utf8").digest(), createHash("sha256").update(b, "utf8").digest());
47
60
  /** `said` with each of `values` (sealed config values) put as the mask. */
48
61
  /** An error's words for a log line: none with sealed config values (`values`) in play, as a quote of one may be in a form
49
62
  * no match finds (JSON-escaped, encoded); its code alone then. */
@@ -150,6 +163,34 @@ export class ComposioTriggers {
150
163
  }
151
164
  });
152
165
  }
166
+ /** A source sent whole again for trigger `id` (`was`), as an apply with agent_id sends its package's, its credentials in
167
+ * the clear: each sealed field whose value it sends is the value sealed (compared in constant time) is left out, so the
168
+ * PATCH keeps it (patched); then patched's own check, so another value, or any other change to the config, is refused
169
+ * here, before the caller writes anything, in patched's words (none holds a value). The answer is the source to PATCH
170
+ * the trigger with: no sealed value is in it. */
171
+ resent(was, id, given) {
172
+ const config = isObject(given.config) ? structuredClone(given.config) : given.config;
173
+ if (isObject(config)) {
174
+ for (const name of sealedOf(shownSource(was))) {
175
+ const path = placeOf(name);
176
+ let node = config;
177
+ for (const key of path.slice(0, -1))
178
+ node = isObject(node) ? node[key] : undefined;
179
+ const last = path.at(-1);
180
+ if (!isObject(node))
181
+ continue;
182
+ const sent = node[last];
183
+ if (!(typeof sent === "string" || typeof sent === "number") || sent === SEALED_MASK)
184
+ continue;
185
+ const kept = this.deps.sealed.get(configScope(id, name), CONFIG_SECRET) ?? this.deps.sealed.get(configScope(id, name), CONFIG_UNLISTED) ?? clearAt(was.config, path);
186
+ if (kept !== undefined && sameSecret(String(sent), kept))
187
+ delete node[last];
188
+ }
189
+ }
190
+ const source = { ...given, config };
191
+ this.patched(was, source);
192
+ return source;
193
+ }
153
194
  patched(was, given) {
154
195
  const fixed = "A Composio trigger's server, event and config made its instance on Composio, so they stay: to change one (a sealed key too), delete the trigger and make a new one.";
155
196
  for (const field of ["server", "event", "instance_id", "hook"])
@@ -195,25 +236,48 @@ export class ComposioTriggers {
195
236
  // Its sealed config goes with it, whatever Composio says below; read first, so Composio's words about its instance are
196
237
  // withheld (asking).
197
238
  const values = this.sealedValues([{ id, source }]);
239
+ await this.forgotten(source, id);
240
+ return this.leftThere(source, id, values);
241
+ }
242
+ async removedThere(source, id, here) {
243
+ return this.leftThere(source, id, this.sealedValues([{ id, source }]), here);
244
+ }
245
+ async forgotten(source, id) {
198
246
  for (const name of sealedOf(source))
199
247
  await this.deps.sealed.remove(configScope(id, name)).catch((error) => this.deps.say({ condition: "composio_sealed_config_not_removed", trigger: id, field: name, error: String(error?.message ?? error) }));
248
+ }
249
+ /** The trigger `id`'s instance on Composio deleted, or turned off while other triggers hold it (none of them on), or
250
+ * kept (one of them on): undefined when that is done, else what is left there, said. `values`: its sealed config's,
251
+ * withheld from Composio's words. `here`, once that is done, in the same step of the project's: the trigger's delete
252
+ * here, so the next removal of a trigger sharing the instance reads the holders without it (two removals at once
253
+ * never each keep the instance for the other); its refusal is thrown, never said as Composio's. */
254
+ async leftThere(source, id, values, here) {
200
255
  const instance = instanceOf(source);
201
256
  let left = "delete";
202
- try {
203
- // Kept while another trigger holds it, and off once none of those is on, as a pause leaves it.
204
- const credential = await this.deps.credential(String(source.server), "field");
205
- await this.serial(credential.key, async () => this.leave(this.ask(credential, "nothing was changed", values), instance, (left = await this.leftWith(instance, id))));
206
- return undefined;
257
+ let failed = undefined;
258
+ // Kept while another trigger holds it, and off once none of those is on, as a pause leaves it.
259
+ const credential = await this.deps.credential(String(source.server), "field").catch((error) => void (failed = { error }));
260
+ if (credential) {
261
+ await this.serial(credential.key, async () => {
262
+ try {
263
+ await this.leave(this.ask(credential, "nothing was changed", values), instance, (left = await this.leftWith(instance, id)));
264
+ }
265
+ catch (error) {
266
+ failed = { error };
267
+ return;
268
+ }
269
+ await here?.();
270
+ });
207
271
  }
208
- catch (error) {
209
- const said = String(error?.message ?? error);
210
- if (left === "off") {
211
- this.deps.say({ condition: "composio_instance_not_turned", trigger: id, instance, on: "false", error: said });
212
- return { composio: { done: false, note: `Composio didn't turn the trigger instance ${instance} off, and no trigger left that holds it is on: turn it off there yourself: ${DASHBOARD}` } };
213
- }
214
- this.deps.say({ condition: "composio_instance_not_removed", trigger: id, instance, error: said });
215
- return { composio: { done: false, note: `Composio didn't delete the trigger instance ${instance}: remove it there yourself: ${DASHBOARD}` } };
272
+ if (failed === undefined)
273
+ return undefined;
274
+ const said = String(failed.error?.message ?? failed.error);
275
+ if (left === "off") {
276
+ this.deps.say({ condition: "composio_instance_not_turned", trigger: id, instance, on: "false", error: said });
277
+ return { composio: { done: false, note: `Composio didn't turn the trigger instance ${instance} off, and no trigger left that holds it is on: turn it off there yourself: ${DASHBOARD}` } };
216
278
  }
279
+ this.deps.say({ condition: "composio_instance_not_removed", trigger: id, instance, error: said });
280
+ return { composio: { done: false, note: `Composio didn't delete the trigger instance ${instance}: remove it there yourself: ${DASHBOARD}` } };
217
281
  }
218
282
  // ---- the routes of a saved Composio server ---------------------------------------------------------------------------
219
283
  /** GET /settings/mcp-servers/{name}/composio/events: its toolkit's events, every page. */
@@ -1,8 +1,9 @@
1
1
  import type { IncomingMessage } from "node:http";
2
2
  import type { Duplex } from "node:stream";
3
3
  import { type AttachHub, type AttachSocket, type HelloResult, type MachineTokens } from "@parcha/agentrun-computer";
4
- import { type WebSocket } from "ws";
5
- import type { MintedTokens, PairedComputerRow, PairedComputers } from "./store/index.js";
4
+ import { WebSocket } from "ws";
5
+ import { type LiveReach } from "./live-reach.js";
6
+ import type { MintedTokens, PairedComputerRow, PairedComputers, RunnerRelays } from "./store/index.js";
6
7
  /** The characters of a pairing code: no 0, O, 1 or I, so a person reads it off a screen without a doubt. */
7
8
  export declare const PAIRING_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
8
9
  /** A computer's token starts with this, so a secret scanner knows one. */
@@ -67,6 +68,9 @@ export type PairedView = {
67
68
  serves: string[];
68
69
  /** When it serves no kind, why, naming what its driver lacks (servesNoKind); null when it serves one. */
69
70
  unserved: string | null;
71
+ /** On a server whose runner runs in a process of its own, why no run here can use it and how to start the server
72
+ * instead (RUNNER_APART_WORDS); null where its runs can. */
73
+ runs_refused: string | null;
70
74
  os: string;
71
75
  os_version: string | null;
72
76
  device: {
@@ -93,7 +97,7 @@ export type PairedView = {
93
97
  /** Its last hello: the live socket's while it is attached (never null while online), else the last one kept. */
94
98
  seen_at: string | null;
95
99
  };
96
- export declare function pairedView(row: PairedComputerRow, hub: Pick<AttachHub, "online" | "since" | "hello" | "claimed" | "deadline">, serves: readonly string[]): PairedView;
100
+ export declare function pairedView(row: PairedComputerRow, hub: Pick<AttachHub, "online" | "since" | "hello" | "claimed" | "deadline">, serves: readonly string[], runnerApart?: boolean): PairedView;
97
101
  /** How the socket's liveness is timed: ATTACH_HEARTBEAT_MS and ATTACH_IDLE_MS, unless a test gives its own. */
98
102
  export type AttachTiming = {
99
103
  readonly heartbeatMs: number;
@@ -101,8 +105,10 @@ export type AttachTiming = {
101
105
  };
102
106
  /** One WebSocket as the hub takes it (attach.ts AttachSocket): text frames in and out; a ping each heartbeat; closed
103
107
  * with ATTACH_CLOSE.idle once nothing (no frame, ping or pong) is heard for idleMs, and with ATTACH_CLOSE.binary on a
104
- * binary frame. A frame over MAX_LINE_BYTES is the server's maxPayload, which closes it with 1009 itself. */
105
- export declare function attachSocketOf(ws: WebSocket, timing?: AttachTiming): AttachSocket;
108
+ * binary frame. A frame over MAX_LINE_BYTES is the server's maxPayload, which closes it with 1009 itself. `closing` is
109
+ * told each close this side starts, when it starts: a peer that does not answer it (an idle one) ends the socket only
110
+ * once ws gives up on it. */
111
+ export declare function attachSocketOf(ws: WebSocket, timing?: AttachTiming, closing?: (code: number, reason: string) => void): AttachSocket;
106
112
  export interface AttachRoutesOptions {
107
113
  readonly store: {
108
114
  readonly pairedComputers: PairedComputers;
@@ -115,13 +121,40 @@ export interface AttachRoutesOptions {
115
121
  /** An API-only server's (api-only.ts): the socket takes a hosted machine's minted token alone, and a paired computer's
116
122
  * (the console's) is 401 as one it does not know. */
117
123
  readonly machinesOnly?: boolean;
124
+ /** No runner in this server's process (ServeOptions.runnerApart): a pairing code and the pair answer say no run here
125
+ * can use a paired computer, and how to start the server so one can (RUNNER_APART_WORDS). */
126
+ readonly runnerApart?: boolean;
118
127
  /** The socket's liveness timing: the protocol's unless a test gives its own. */
119
128
  readonly timing?: AttachTiming;
120
129
  readonly now?: () => number;
121
130
  /** Told each socket taken, with its computer, before its hello: the binding's conformance run (attach-conformance.ts)
122
131
  * watches the raw socket to see how a driver answers a close, a drop and a frame it must refuse. */
123
132
  readonly onSocket?: (computer: string, ws: WebSocket) => void;
133
+ /** A runner in a process of its own (dial-relay.ts): the tokens it mints name it and this incarnation, and the socket
134
+ * takes a machine's token only where its row names both. */
135
+ readonly owner?: {
136
+ readonly runner: string;
137
+ readonly incarnation: string;
138
+ };
139
+ /** The server's relay of a dial whose token another runner minted: where each runner's attach listener answers, and
140
+ * the hosts it may dial with the proxy's proof (live-reach.ts). Without it such a dial is refused 503. */
141
+ readonly relay?: {
142
+ readonly relays: Pick<RunnerRelays, "get">;
143
+ readonly reach: LiveReach;
144
+ };
124
145
  }
146
+ /** A request's Bearer token, or undefined. */
147
+ export declare const bearerOf: (authorization: string | undefined) => string | undefined;
148
+ /** How often a runner's attach listener says it is there (its runner_relays row's seen_at), and how long after its last
149
+ * word the server takes it as gone. */
150
+ export declare const RELAY_RENEW_MS = 10000;
151
+ export declare const RELAY_STALE_MS: number;
152
+ /** How long the server waits for a runner's attach listener to take a relayed dial. */
153
+ export declare const RELAY_CONNECT_MS = 10000;
154
+ /** Two WebSockets joined frame by frame, each an attach socket with `timing` (attachSocketOf: its idle close, its binary
155
+ * refusal, the server's maxPayload), each closing the other with its code and reason: once it ended, or as soon as it
156
+ * starts a close of its own, so an idle peer's close reaches the other side at once. */
157
+ export declare function joinSockets(one: WebSocket, other: WebSocket, timing?: AttachTiming): void;
125
158
  /** The pairing routes, the attach socket and the daemon route over one store and one hub, and the tokens a dial
126
159
  * provider mints. */
127
160
  export declare function createAttachRoutes(options: AttachRoutesOptions): {
@@ -129,10 +162,12 @@ export declare function createAttachRoutes(options: AttachRoutesOptions): {
129
162
  id: string;
130
163
  code: string;
131
164
  expires_at: string;
165
+ runs_refused: string | null;
132
166
  }>;
133
167
  pair: (body: unknown, address: string) => Promise<{
134
168
  computer: string;
135
169
  token: string;
170
+ runs_refused: string | null;
136
171
  }>;
137
172
  remove: (id: string) => Promise<void>;
138
173
  upgrade: (req: IncomingMessage, socket: Duplex, head: Buffer, deny: (status: string, words?: string, headers?: Record<string, string>) => void) => void;