@parcha/agentrun-serve 0.1.0-beta.57 → 0.1.0-beta.59

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 (404) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/README.md +393 -118
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/api-only.d.ts +2 -4
  11. package/dist/api-only.js +2 -4
  12. package/dist/attach-conformance.js +5 -4
  13. package/dist/box-paths.d.ts +7 -5
  14. package/dist/box-paths.js +12 -8
  15. package/dist/browser-computer.d.ts +3 -8
  16. package/dist/browser-computer.js +12 -35
  17. package/dist/browser-cost.js +94 -20
  18. package/dist/capacity.d.ts +1 -1
  19. package/dist/capacity.js +3 -3
  20. package/dist/chatgpt-plan.d.ts +5 -0
  21. package/dist/chatgpt-plan.js +25 -11
  22. package/dist/claude-login-token.d.ts +121 -0
  23. package/dist/claude-login-token.js +797 -0
  24. package/dist/claude-login.d.ts +119 -34
  25. package/dist/claude-login.js +551 -79
  26. package/dist/claude-sign-in.d.ts +3 -0
  27. package/dist/claude-sign-in.js +10 -1
  28. package/dist/cli.js +325 -328
  29. package/dist/composio-made.d.ts +1 -6
  30. package/dist/composio-made.js +1 -6
  31. package/dist/composio-owners.d.ts +26 -0
  32. package/dist/composio-owners.js +36 -0
  33. package/dist/composio-preset.d.ts +56 -23
  34. package/dist/composio-preset.js +173 -77
  35. package/dist/composio-triggers.d.ts +4 -4
  36. package/dist/composio-triggers.js +6 -7
  37. package/dist/compute-cost.js +11 -2
  38. package/dist/computer-attach.d.ts +40 -19
  39. package/dist/computer-attach.js +326 -62
  40. package/dist/computer-held-routes.d.ts +1 -1
  41. package/dist/computer-held-routes.js +9 -4
  42. package/dist/computer-keys.d.ts +11 -1
  43. package/dist/computer-keys.js +26 -1
  44. package/dist/computer-record.js +3 -1
  45. package/dist/computer-view.d.ts +5 -3
  46. package/dist/computer-view.js +10 -6
  47. package/dist/computer-viewer.js +36 -7
  48. package/dist/computers.d.ts +12 -11
  49. package/dist/computers.js +11 -8
  50. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  51. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  52. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  53. package/dist/console/assets/share-L84tlUDW.js +6 -0
  54. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  55. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  56. package/dist/console/index.html +4 -3
  57. package/dist/console/share.html +17 -0
  58. package/dist/decisions.d.ts +17 -7
  59. package/dist/decisions.js +41 -15
  60. package/dist/dial-relay.d.ts +25 -4
  61. package/dist/dial-relay.js +139 -5
  62. package/dist/docker-daemon.js +4 -5
  63. package/dist/docker-host-addresses.js +29 -11
  64. package/dist/email/account.d.ts +6 -0
  65. package/dist/email/account.js +6 -0
  66. package/dist/email/authentication.d.ts +21 -0
  67. package/dist/email/authentication.js +106 -0
  68. package/dist/email/email-faux.d.ts +11 -2
  69. package/dist/email/email-faux.js +21 -5
  70. package/dist/email/mail.d.ts +25 -0
  71. package/dist/email/mail.js +58 -2
  72. package/dist/email/names.js +2 -2
  73. package/dist/email/tools.d.ts +9 -4
  74. package/dist/email/tools.js +95 -13
  75. package/dist/env-switch.d.ts +13 -5
  76. package/dist/env-switch.js +24 -6
  77. package/dist/errors.d.ts +1 -0
  78. package/dist/errors.js +2 -0
  79. package/dist/fal-price.d.ts +12 -4
  80. package/dist/fal-price.js +110 -26
  81. package/dist/faux-computers.js +1 -1
  82. package/dist/filed-answer.d.ts +2 -2
  83. package/dist/filed-answer.js +2 -2
  84. package/dist/graph-served.d.ts +10 -5
  85. package/dist/graph-served.js +40 -10
  86. package/dist/handed-values.js +1 -2
  87. package/dist/harness-check.d.ts +2 -1
  88. package/dist/harness-check.js +45 -12
  89. package/dist/harness-keys.js +9 -6
  90. package/dist/harness-opencode/facts.js +2 -0
  91. package/dist/harness-recipe-entry.d.ts +9 -3
  92. package/dist/harness-recipe-entry.js +18 -9
  93. package/dist/harness-recipe.d.ts +21 -0
  94. package/dist/harness-recipe.js +25 -3
  95. package/dist/harness-table.d.ts +8 -0
  96. package/dist/harness-table.js +17 -6
  97. package/dist/helper-env.d.ts +4 -1
  98. package/dist/helper-env.js +4 -1
  99. package/dist/host-check.d.ts +2 -3
  100. package/dist/host-check.js +13 -7
  101. package/dist/hosted-search.js +1 -1
  102. package/dist/import.d.ts +11 -8
  103. package/dist/import.js +437 -186
  104. package/dist/key-refusal.d.ts +9 -2
  105. package/dist/key-refusal.js +86 -32
  106. package/dist/learn/audit.d.ts +8 -5
  107. package/dist/learn/audit.js +15 -7
  108. package/dist/learn/compile.d.ts +5 -2
  109. package/dist/learn/compile.js +45 -21
  110. package/dist/learn/field-check.d.ts +111 -0
  111. package/dist/learn/field-check.js +174 -0
  112. package/dist/learn/ledger.d.ts +173 -0
  113. package/dist/learn/ledger.js +225 -0
  114. package/dist/learn/promote.d.ts +82 -39
  115. package/dist/learn/promote.js +61 -66
  116. package/dist/learn/secrets.d.ts +4 -0
  117. package/dist/learn/secrets.js +12 -0
  118. package/dist/learned-nodes.d.ts +8 -5
  119. package/dist/learned-nodes.js +8 -5
  120. package/dist/learned-workflow.d.ts +2 -1
  121. package/dist/learned-workflow.js +13 -10
  122. package/dist/learning-cost.d.ts +40 -21
  123. package/dist/learning-cost.js +30 -21
  124. package/dist/learning-setting.d.ts +6 -0
  125. package/dist/learning-setting.js +11 -1
  126. package/dist/listen-first.d.ts +5 -4
  127. package/dist/listen-first.js +4 -5
  128. package/dist/live-reach.d.ts +9 -0
  129. package/dist/live-reach.js +9 -0
  130. package/dist/mcp-api-only-origins.d.ts +23 -3
  131. package/dist/mcp-api-only-origins.js +57 -17
  132. package/dist/mcp-gateway.d.ts +16 -2
  133. package/dist/mcp-gateway.js +41 -3
  134. package/dist/mcp-oauth.d.ts +1 -1
  135. package/dist/mcp-oauth.js +3 -2
  136. package/dist/mcp-probe.d.ts +3 -0
  137. package/dist/mcp-probe.js +3 -0
  138. package/dist/mcp-secret-writes.d.ts +24 -2
  139. package/dist/mcp-secret-writes.js +30 -2
  140. package/dist/mcp-servers-store.d.ts +52 -14
  141. package/dist/mcp-servers-store.js +165 -61
  142. package/dist/mcp-sources.d.ts +1 -2
  143. package/dist/mcp-sources.js +1 -2
  144. package/dist/mcp-store.d.ts +5 -5
  145. package/dist/mcp-store.js +3 -3
  146. package/dist/mcp.js +1 -1
  147. package/dist/micro.d.ts +2 -0
  148. package/dist/micro.js +2 -0
  149. package/dist/model-gateway.d.ts +1 -1
  150. package/dist/model-gateway.js +20 -36
  151. package/dist/model.d.ts +5 -4
  152. package/dist/model.js +7 -6
  153. package/dist/monid.d.ts +14 -1
  154. package/dist/monid.js +103 -26
  155. package/dist/ollama-provider.d.ts +23 -9
  156. package/dist/ollama-provider.js +49 -20
  157. package/dist/openapi.js +234 -61
  158. package/dist/otel/genai.d.ts +83 -7
  159. package/dist/otel/genai.js +69 -9
  160. package/dist/otel/tracer.d.ts +42 -13
  161. package/dist/otel/tracer.js +241 -56
  162. package/dist/page.d.ts +7 -1
  163. package/dist/page.js +76 -22
  164. package/dist/paid-calls.d.ts +6 -4
  165. package/dist/paid-calls.js +15 -7
  166. package/dist/place-offers.d.ts +59 -34
  167. package/dist/place-offers.js +100 -58
  168. package/dist/place.d.ts +13 -14
  169. package/dist/place.js +56 -41
  170. package/dist/print.js +1 -1
  171. package/dist/provider.d.ts +5 -4
  172. package/dist/provider.js +26 -13
  173. package/dist/redact/match.d.ts +27 -9
  174. package/dist/redact/match.js +266 -57
  175. package/dist/run-census.d.ts +1 -1
  176. package/dist/run-census.js +4 -5
  177. package/dist/run-cut.js +4 -5
  178. package/dist/run-export-store.d.ts +15 -0
  179. package/dist/run-export-store.js +30 -0
  180. package/dist/run-export.d.ts +139 -0
  181. package/dist/run-export.js +379 -0
  182. package/dist/run-file-cut.d.ts +5 -0
  183. package/dist/run-file-cut.js +13 -0
  184. package/dist/run-launch.js +16 -3
  185. package/dist/run-learning-served.d.ts +2 -2
  186. package/dist/run-model-key.d.ts +15 -6
  187. package/dist/run-model-key.js +30 -31
  188. package/dist/run-reads-over-store.js +4 -4
  189. package/dist/run-secrets.js +3 -5
  190. package/dist/run-timeline-served.js +3 -1
  191. package/dist/run-view.d.ts +1 -2
  192. package/dist/run-view.js +2 -1
  193. package/dist/runnable.js +2 -2
  194. package/dist/runner/adapter-loop.d.ts +35 -18
  195. package/dist/runner/adapter-loop.js +97 -63
  196. package/dist/runner/adapter-run-spec.d.ts +34 -14
  197. package/dist/runner/adapter-run-spec.js +120 -75
  198. package/dist/runner/adapters/pi.js +4 -2
  199. package/dist/runner/audit.d.ts +8 -5
  200. package/dist/runner/audit.js +37 -17
  201. package/dist/runner/beside.d.ts +9 -2
  202. package/dist/runner/beside.js +29 -13
  203. package/dist/runner/claim-secrets.d.ts +27 -18
  204. package/dist/runner/claim-secrets.js +61 -47
  205. package/dist/runner/cli-run-spec.d.ts +18 -0
  206. package/dist/runner/cli-run-spec.js +93 -46
  207. package/dist/runner/compare-end.d.ts +2 -1
  208. package/dist/runner/compare-end.js +25 -10
  209. package/dist/runner/conformance/harness.js +2 -3
  210. package/dist/runner/conformance/subject.d.ts +4 -1
  211. package/dist/runner/harness-loops.js +3 -3
  212. package/dist/runner/held.d.ts +19 -4
  213. package/dist/runner/journal-kinds.d.ts +4 -1
  214. package/dist/runner/journal-kinds.js +22 -4
  215. package/dist/runner/learned-first.js +20 -4
  216. package/dist/runner/learning-end.d.ts +2 -8
  217. package/dist/runner/learning-end.js +11 -19
  218. package/dist/runner/live-ticker.js +7 -5
  219. package/dist/runner/loop-contract.d.ts +0 -2
  220. package/dist/runner/loop.d.ts +7 -0
  221. package/dist/runner/loop.js +1 -0
  222. package/dist/runner/main.d.ts +11 -6
  223. package/dist/runner/main.js +24 -18
  224. package/dist/runner/mcp-claim.js +24 -7
  225. package/dist/runner/mcp-run.d.ts +3 -6
  226. package/dist/runner/mcp-run.js +3 -4
  227. package/dist/runner/meta-tools.js +3 -2
  228. package/dist/runner/metrics.d.ts +7 -0
  229. package/dist/runner/metrics.js +19 -0
  230. package/dist/runner/model-route.d.ts +10 -7
  231. package/dist/runner/model-route.js +79 -15
  232. package/dist/runner/native-loop.js +10 -8
  233. package/dist/runner/presence.d.ts +11 -4
  234. package/dist/runner/presence.js +11 -6
  235. package/dist/runner/promotion.d.ts +25 -13
  236. package/dist/runner/promotion.js +125 -50
  237. package/dist/runner/redact.d.ts +3 -1
  238. package/dist/runner/redact.js +5 -3
  239. package/dist/runner/reflect-hook.js +1 -1
  240. package/dist/runner/responses-fetch.d.ts +36 -0
  241. package/dist/runner/responses-fetch.js +511 -0
  242. package/dist/runner/run-child-host.d.ts +38 -12
  243. package/dist/runner/run-child-host.js +231 -83
  244. package/dist/runner/run-child.js +11 -4
  245. package/dist/runner/runner-check.js +5 -1
  246. package/dist/runner/runner.d.ts +5 -3
  247. package/dist/runner/runner.js +14 -10
  248. package/dist/runner/save-slots.js +2 -1
  249. package/dist/runner/sdk-loop.js +8 -8
  250. package/dist/runner/spec-holds.d.ts +8 -1
  251. package/dist/runner/spec-holds.js +9 -4
  252. package/dist/runner/subagent.d.ts +11 -0
  253. package/dist/runner/subagent.js +17 -3
  254. package/dist/runner/workflow-calls.d.ts +9 -0
  255. package/dist/runner/workflow-calls.js +150 -0
  256. package/dist/runner/workflow-first.d.ts +138 -37
  257. package/dist/runner/workflow-first.js +230 -99
  258. package/dist/runner/workflow-spec.js +2 -2
  259. package/dist/runs-over-store.js +8 -7
  260. package/dist/save-once.d.ts +14 -0
  261. package/dist/save-once.js +31 -0
  262. package/dist/scrub-command.d.ts +34 -31
  263. package/dist/scrub-command.js +116 -147
  264. package/dist/sdk/runs.d.ts +6 -0
  265. package/dist/sdk/runs.js +89 -10
  266. package/dist/seal-key.js +4 -4
  267. package/dist/secret-cut.d.ts +3 -0
  268. package/dist/secret-cut.js +7 -1
  269. package/dist/secret-rules.d.ts +8 -1
  270. package/dist/secret-rules.js +482 -53
  271. package/dist/secrets.d.ts +51 -9
  272. package/dist/secrets.js +311 -21
  273. package/dist/server-keys.d.ts +4 -3
  274. package/dist/server-keys.js +4 -3
  275. package/dist/server-secrets-store.js +2 -4
  276. package/dist/server.d.ts +33 -10
  277. package/dist/server.js +454 -136
  278. package/dist/share-context.d.ts +22 -0
  279. package/dist/share-context.js +76 -0
  280. package/dist/shell-lex.d.ts +105 -0
  281. package/dist/shell-lex.js +646 -0
  282. package/dist/sign-ins-store.d.ts +5 -7
  283. package/dist/sign-ins-store.js +12 -16
  284. package/dist/sign-ins.d.ts +7 -11
  285. package/dist/sign-ins.js +40 -41
  286. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  287. package/dist/slots.d.ts +9 -0
  288. package/dist/slots.js +45 -0
  289. package/dist/start-switches.d.ts +6 -5
  290. package/dist/start-switches.js +8 -4
  291. package/dist/stats.d.ts +5 -1
  292. package/dist/stats.js +1 -1
  293. package/dist/store/agent-body.js +2 -2
  294. package/dist/store/dialect.d.ts +4 -0
  295. package/dist/store/dialect.js +1 -0
  296. package/dist/store/index.d.ts +2 -2
  297. package/dist/store/index.js +1 -1
  298. package/dist/store/mcp-record-keys.d.ts +10 -0
  299. package/dist/store/mcp-record-keys.js +13 -0
  300. package/dist/store/postgres/dialect.js +2 -0
  301. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  302. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  303. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  304. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  305. package/dist/store/postgres/store.js +4 -0
  306. package/dist/store/schema.d.ts +44 -4
  307. package/dist/store/schema.js +111 -11
  308. package/dist/store/seal.d.ts +4 -1
  309. package/dist/store/sqlite/run-launch.d.ts +3 -10
  310. package/dist/store/sqlite/run-launch.js +12 -23
  311. package/dist/store/sqlite/run-patch.d.ts +19 -2
  312. package/dist/store/sqlite/run-patch.js +67 -2
  313. package/dist/store/sqlite/store.d.ts +3 -0
  314. package/dist/store/sqlite/store.js +177 -32
  315. package/dist/store/store-schema.js +3 -4
  316. package/dist/store/store.d.ts +74 -25
  317. package/dist/store/store.js +14 -11
  318. package/dist/store-reads/analytics.d.ts +2 -1
  319. package/dist/store-reads/analytics.js +7 -5
  320. package/dist/store-reads/learning.d.ts +102 -136
  321. package/dist/store-reads/learning.js +251 -302
  322. package/dist/store-reads/stats.d.ts +2 -2
  323. package/dist/store-reads/stats.js +13 -7
  324. package/dist/store-view.js +10 -7
  325. package/dist/suggestions.d.ts +1 -1
  326. package/dist/suggestions.js +29 -13
  327. package/dist/template-eval.d.ts +91 -9
  328. package/dist/template-eval.js +448 -105
  329. package/dist/template-import.d.ts +0 -10
  330. package/dist/template-import.js +5 -10
  331. package/dist/timeline/labels.d.ts +1 -1
  332. package/dist/timeline/labels.js +4 -3
  333. package/dist/timeline/timeline.d.ts +23 -11
  334. package/dist/timeline/timeline.js +115 -31
  335. package/dist/timeline/web-calls.d.ts +14 -14
  336. package/dist/timeline/web-calls.js +18 -30
  337. package/dist/tool-gate.d.ts +13 -1
  338. package/dist/tool-gate.js +43 -3
  339. package/dist/tool-keys-store.js +2 -4
  340. package/dist/tool-keys.d.ts +11 -0
  341. package/dist/tool-keys.js +16 -0
  342. package/dist/tool-plane.d.ts +50 -11
  343. package/dist/tool-plane.js +94 -30
  344. package/dist/tools.d.ts +5 -1
  345. package/dist/tools.js +7 -7
  346. package/dist/trigger-email.js +12 -6
  347. package/dist/triggers.d.ts +15 -34
  348. package/dist/triggers.js +119 -126
  349. package/dist/validate.d.ts +8 -1
  350. package/dist/validate.js +163 -23
  351. package/dist/web-fake.d.ts +2 -1
  352. package/dist/web-fake.js +8 -6
  353. package/dist/web-fetch.d.ts +8 -6
  354. package/dist/web-fetch.js +13 -11
  355. package/dist/web-holds.d.ts +32 -0
  356. package/dist/web-holds.js +86 -0
  357. package/dist/web-run.d.ts +32 -5
  358. package/dist/web-run.js +75 -28
  359. package/dist/web-save.d.ts +4 -9
  360. package/dist/web-save.js +27 -55
  361. package/dist/web-search.js +14 -25
  362. package/dist/wires.d.ts +4 -3
  363. package/dist/wires.js +5 -4
  364. package/dist/workspace/archil-claim.d.ts +12 -5
  365. package/dist/workspace/archil-claim.js +45 -5
  366. package/dist/workspace/attach.js +52 -19
  367. package/dist/workspace/attached-computers.d.ts +38 -11
  368. package/dist/workspace/attached-computers.js +81 -16
  369. package/dist/workspace/computer-deps.d.ts +29 -7
  370. package/dist/workspace/computer-deps.js +36 -18
  371. package/dist/workspace/computer-for-claim.d.ts +21 -4
  372. package/dist/workspace/computer-for-claim.js +166 -57
  373. package/dist/workspace/computer-intervals.d.ts +2 -0
  374. package/dist/workspace/computer-intervals.js +1 -1
  375. package/dist/workspace/computer-janitor.d.ts +48 -14
  376. package/dist/workspace/computer-janitor.js +153 -44
  377. package/dist/workspace/computer-kept.d.ts +158 -32
  378. package/dist/workspace/computer-kept.js +288 -63
  379. package/dist/workspace/computer-providers.d.ts +8 -3
  380. package/dist/workspace/computer-providers.js +12 -5
  381. package/dist/workspace/index.d.ts +1 -1
  382. package/dist/workspace/index.js +1 -1
  383. package/dist/workspace/local.js +41 -1
  384. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  385. package/dist/workspace/mount-revoke-left.js +72 -0
  386. package/dist/workspace/paired-route.d.ts +91 -0
  387. package/dist/workspace/paired-route.js +152 -0
  388. package/dist/workspace/resolve-computer.d.ts +5 -2
  389. package/dist/workspace/resolve-computer.js +9 -3
  390. package/dist/workspace/run-end-computers.d.ts +11 -5
  391. package/dist/workspace/run-end-computers.js +153 -28
  392. package/dist/workspace/run-tools.d.ts +22 -3
  393. package/dist/workspace/run-tools.js +17 -5
  394. package/dist/workspace/run-workspace.d.ts +14 -1
  395. package/dist/workspace/run-workspace.js +34 -1
  396. package/dist/workspace/workspace.d.ts +6 -0
  397. package/dist/wrapped.d.ts +8 -2
  398. package/dist/wrapped.js +21 -6
  399. package/package.json +12 -13
  400. package/skills/agentrun-serve/SKILL.md +5 -2
  401. package/templates/README.md +25 -9
  402. package/dist/console/assets/backend-DVhHzJX2.js +0 -166
  403. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  404. package/dist/console/assets/index-okP-y8PK.js +0 -747
@@ -51,6 +51,10 @@ export type AcpPackage = {
51
51
  cursorRootOf(binary: string, cmd: string): string | undefined;
52
52
  /** The form a model id an ACP agent lists takes (Cursor's `gpt-5.4-nano[reasoning=medium]` among them). */
53
53
  readonly MODEL_ID: RegExp;
54
+ /** The forms a recipe's allowFile may take (`goose-permission`). */
55
+ readonly ALLOW_FILE_FORMS: readonly string[];
56
+ /** What is wrong with a recipe's announces field, and with a title tie without it, each in words. */
57
+ announcesProblems(announces: unknown, permissionTie: unknown): string[];
54
58
  /** The form a sign-in method's id an ACP agent lists takes (`gemini-api-key`): a recipe's keyMethod is checked by it. */
55
59
  readonly AUTH_METHOD: RegExp;
56
60
  acpPlatform(): string | undefined;
@@ -73,5 +77,5 @@ export type AcpPackage = {
73
77
  verifyPinnedTree(root: string, sha256: string): Promise<void>;
74
78
  };
75
79
  /** The package, or undefined where it is not installed beside serve. Only its absence is: a package that is there and
76
- * fails to load throws. */
80
+ * fails to load throws. Its adapter factories take serve's debug switch (withDebug). */
77
81
  export declare function acpPackage(): AcpPackage | undefined;
@@ -6,8 +6,25 @@ import { createRequire } from "node:module";
6
6
  export const ACP_PACKAGE = "@parcha/agentrun-harness-acp";
7
7
  const requireHere = createRequire(import.meta.url);
8
8
  let loaded;
9
+ /** serve's one debug switch for the ACP adapter, AGENTRUN_LOG=debug, read as each adapter is made: it logs each call the
10
+ * agent announces, by its ids and names only (the package's AcpHarnessOptions.debug). Serve owns the variable, so the
11
+ * package never reads it. */
12
+ const debugOption = () => (process.env.AGENTRUN_LOG === "debug" ? { debug: true } : {});
13
+ /** `pkg` with each adapter factory it exports (every function named `...Adapter`: acpAdapter, gooseAdapter,
14
+ * cursorAdapter) handed serve's debug switch at each call. Here, where serve loads the package, so no place that builds
15
+ * an ACP agent's adapter has to remember it. */
16
+ function withDebug(pkg) {
17
+ const made = { ...pkg };
18
+ for (const [name, value] of Object.entries(pkg)) {
19
+ if (typeof value !== "function" || !name.endsWith("Adapter"))
20
+ continue;
21
+ const factory = value;
22
+ made[name] = (options) => factory({ ...options, ...debugOption() });
23
+ }
24
+ return Object.freeze(made);
25
+ }
9
26
  /** The package, or undefined where it is not installed beside serve. Only its absence is: a package that is there and
10
- * fails to load throws. */
27
+ * fails to load throws. Its adapter factories take serve's debug switch (withDebug). */
11
28
  export function acpPackage() {
12
29
  if (loaded === undefined) {
13
30
  let found = true;
@@ -17,7 +34,7 @@ export function acpPackage() {
17
34
  catch {
18
35
  found = false;
19
36
  }
20
- loaded = found ? requireHere(ACP_PACKAGE) : null;
37
+ loaded = found ? withDebug(requireHere(ACP_PACKAGE)) : null;
21
38
  }
22
39
  return loaded ?? undefined;
23
40
  }
@@ -22,6 +22,10 @@ export declare function installedHere(name: string, from?: string): string | und
22
22
  * (~/.agentrun) is not the server's default, and after the server's own command when the store is not its default.
23
23
  */
24
24
  export declare function npxLine(spec: string, env?: NodeJS.ProcessEnv, installed?: (name: string) => string | undefined): string;
25
+ /** Set by the agentrun launcher (start.mjs) on the server it starts when the installer's command (install.sh's
26
+ * <root>/bin/agentrun) is what runs it: that command's path. The person's login shell has that command, never npx or
27
+ * the installer's Node, so a refusal names it. */
28
+ export declare const INSTALLED_COMMAND_ENV = "AGENTRUN_INSTALLED_COMMAND";
25
29
  /**
26
30
  * A start the agentrun launcher made (NPX_PACKAGE_ENV: by npx, or by the installer's bin/agentrun and its service, the
27
31
  * same launcher) that a data directory refused because an earlier version wrote it (store.ts StoreFromEarlierVersion,
@@ -29,8 +33,14 @@ export declare function npxLine(spec: string, env?: NodeJS.ProcessEnv, installed
29
33
  * then the two ways on as commands to paste. That command keeps its data in ~/.agentrun wherever it is run, so a new
30
34
  * folder alone is not a new AgentRun. First, the old folder moved aside whole, so the same command starts this version
31
35
  * where it was, and the earlier version still opens what it holds; then this version on a new, empty folder: the same
32
- * command with --data. Nothing is deleted either way. Any other error, or a start the launcher did not
33
- * make, is undefined: the refusal's own words stand.
36
+ * command with --data. Nothing is deleted either way. The command is the one that started this server, as the launcher
37
+ * says (INSTALLED_COMMAND_ENV): the installer's, else npx's; never read from what the folder holds.
38
+ *
39
+ * The installer keeps its Node, its packages and its command in the folder beside the data (install.sh: node/, lib/,
40
+ * bin/agentrun). When that command started this from the folder refused, it or its service has no npx at hand, moving
41
+ * the folder takes the command, and the service starts on the refused folder whatever another command says. So there the
42
+ * one way on is the folder moved aside, then the installer run again for this same version (by default it installs the
43
+ * latest). Any other error, or a start the launcher did not make, is undefined: the refusal's own words stand.
34
44
  */
35
45
  export declare function earlierDataRefusal(error: unknown, data: string, env?: NodeJS.ProcessEnv, exists?: (path: string) => boolean): string | undefined;
36
46
  /** The port the server was started on when `--port` named one, and whether `--open` was given (1 or 0): set by its CLI
@@ -94,6 +104,8 @@ export type AdapterNeeds = {
94
104
  models: {
95
105
  getModel(provider: string, id: string): {
96
106
  cost?: Partial<ModelCost>;
107
+ contextWindow?: number;
108
+ maxTokens?: number;
97
109
  } | undefined;
98
110
  };
99
111
  confine?: ConfineChild;
@@ -103,6 +115,15 @@ export type AdapterNeeds = {
103
115
  zone?: string;
104
116
  heldRefusal?: string;
105
117
  };
118
+ /** The limits of a model the route translates onto a harness's wire (`provider.fetch`: provider.ts routedProvider), for
119
+ * an adapter that takes them: its window and its most output tokens, from the model's pi-ai entry in the run's models
120
+ * (`needs.models`), the entry the route's own model is. Its window is what every request asks Ollama for
121
+ * (options.num_ctx: ollama-provider.ts contextOf, at most 64k), and its output ceiling half that, at most 16,384. None
122
+ * for a model not routed, or one with no entry: its adapter's own defaults. */
123
+ export declare function routedLimits(provider: Pick<Provider, "fetch">, needs: AdapterNeeds): {
124
+ contextWindow?: number;
125
+ maxOutputTokens?: number;
126
+ };
106
127
  /** Where a run's adapter sends its model's requests (providerFor), or, for a held run its model kept from running at its
107
128
  * create, the stand-in (heldRefusedProvider): no key is read, and its proxy refuses every request in the create's words,
108
129
  * sending none. */
package/dist/adapters.js CHANGED
@@ -4,14 +4,14 @@
4
4
  // Claude Agent SDK and codex's Codex are installed on first use into the data's harnesses directory and loaded from there
5
5
  // alone (harness-install.ts); opencode's pinned CLI that is missing says so with the one line that installs it: an npm
6
6
  // install beside serve, or, when serve runs from npx, the npx line that runs it with the missing package.
7
- import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
8
- import { homedir } from "node:os";
7
+ import { accessSync, constants, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
9
8
  import { dirname, join, resolve, sep } from "node:path";
10
9
  import { fileURLToPath } from "node:url";
11
10
  import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
12
11
  import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
13
12
  import { facts as openCodeFacts } from "./harness-opencode/facts.js";
14
- import { CLAUDE_SDK, codexBinaryIn, HarnessNotInstalled, installDirOf, installLine, loadSdk } from "./harness-install.js";
13
+ import { CLAUDE_SDK, codexBinaryIn, HarnessNotInstalled, installDirOf, installLine, loadSdk, shellWord } from "./harness-install.js";
14
+ import { commandData } from "./harness-owned.js";
15
15
  import { DATA_ENV, defaultData } from "./files.js";
16
16
  import { harnessOf, onAdapter } from "./harness-table.js";
17
17
  import { HarnessUnavailable, heldRefusedProvider, providerFor } from "./provider.js";
@@ -48,7 +48,20 @@ export function installedHere(name, from = fileURLToPath(import.meta.url)) {
48
48
  return undefined;
49
49
  }
50
50
  }
51
- const shellWord = (word) => (/^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`);
51
+ /**
52
+ * How the person started this server, for a command that starts it the same way again: the agentrun launcher's package
53
+ * when it made the start (NPX_PACKAGE_ENV, `@parcha/agentrun@<version>`), npx's `-y ` as they ran it, and the flags after
54
+ * any --data (startedWith): the port they named, and the browser as they had it (`npx @parcha/agentrun` opens it unless
55
+ * --no-open, agentrun-serve only with --open).
56
+ */
57
+ function startedAs(env) {
58
+ const door = env[NPX_PACKAGE_ENV];
59
+ const launcher = door !== undefined && /^@parcha\/agentrun@\d[\w.+-]*$/.test(door) ? door : undefined;
60
+ const port = env[STARTED_PORT_ENV];
61
+ const open = env[STARTED_OPEN_ENV];
62
+ const flags = [...(port && /^\d{1,5}$/.test(port) ? [`--port ${port}`] : []), ...(launcher ? (open === "0" ? ["--no-open"] : []) : open === "1" ? ["--open"] : [])];
63
+ return { launcher, yes: env.npm_config_yes === "true" ? "-y " : "", flags: flags.map((flag) => ` ${flag}`).join("") };
64
+ }
52
65
  /**
53
66
  * The one command that starts this same AgentRun again with `spec` beside it: the command the person ran
54
67
  * (`npx @parcha/agentrun`, which NPX_PACKAGE_ENV names, or the server's own), this server's version, every other
@@ -57,8 +70,7 @@ const shellWord = (word) => (/^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.rep
57
70
  * (~/.agentrun) is not the server's default, and after the server's own command when the store is not its default.
58
71
  */
59
72
  export function npxLine(spec, env = {}, installed = installedHere) {
60
- const door = env[NPX_PACKAGE_ENV];
61
- const command = door !== undefined && /^@parcha\/agentrun@\d[\w.+-]*$/.test(door) ? door : undefined;
73
+ const { launcher: command, yes, flags } = startedAs(env);
62
74
  const own = spec.slice(0, spec.lastIndexOf("@"));
63
75
  const kept = HARNESS_PACKAGES.filter((name) => name !== own).flatMap((name) => {
64
76
  const version = installed(name);
@@ -68,12 +80,7 @@ export function npxLine(spec, env = {}, installed = installedHere) {
68
80
  const packages = [...(command ? [command] : []), `@parcha/agentrun-serve@${SERVE_VERSION}`, ...kept, spec];
69
81
  const data = env[DATA_ENV];
70
82
  const named = data && (command || resolve(data) !== resolve(defaultData(env))) ? ` --data ${shellWord(resolve(data))}` : "";
71
- // And how the person started it (startedWith): npx's -y, the port they named, and the browser as they had it:
72
- // `npx @parcha/agentrun` opens it unless --no-open, agentrun-serve only with --open.
73
- const yes = env.npm_config_yes === "true" ? "-y " : "";
74
- const port = env[STARTED_PORT_ENV];
75
- const flags = [...(port && /^\d{1,5}$/.test(port) ? [`--port ${port}`] : []), ...(command && env[STARTED_OPEN_ENV] === "0" ? ["--no-open"] : []), ...(!command && env[STARTED_OPEN_ENV] === "1" ? ["--open"] : [])];
76
- return `npx ${yes}${packages.map((name) => `-p ${name}`).join(" ")} ${command ? "agentrun" : "agentrun-serve"}${named}${flags.map((flag) => ` ${flag}`).join("")}`;
83
+ return `npx ${yes}${packages.map((name) => `-p ${name}`).join(" ")} ${command ? "agentrun" : "agentrun-serve"}${named}${flags}`;
77
84
  }
78
85
  /** The first of `base`, `base-2`, `base-3`… that is not there. */
79
86
  const freeName = (base, exists) => {
@@ -82,6 +89,42 @@ const freeName = (base, exists) => {
82
89
  name = `${base}-${n}`;
83
90
  return name;
84
91
  };
92
+ /** Set by the agentrun launcher (start.mjs) on the server it starts when the installer's command (install.sh's
93
+ * <root>/bin/agentrun) is what runs it: that command's path. The person's login shell has that command, never npx or
94
+ * the installer's Node, so a refusal names it. */
95
+ export const INSTALLED_COMMAND_ENV = "AGENTRUN_INSTALLED_COMMAND";
96
+ /** Whether `a` and `b` name one file through any symlink (a home folder reached by a link): their real paths when both
97
+ * are there, else the paths as given. */
98
+ const sameFile = (a, b) => {
99
+ try {
100
+ return realpathSync(a) === realpathSync(b);
101
+ }
102
+ catch {
103
+ return resolve(a) === resolve(b);
104
+ }
105
+ };
106
+ /** The file a shell runs for `agentrun` on `path`: the first executable one in its folders, in order, or undefined. */
107
+ const agentrunOnPath = (path) => {
108
+ for (const dir of path.split(":")) {
109
+ if (!dir)
110
+ continue;
111
+ const found = join(dir, "agentrun");
112
+ try {
113
+ if (statSync(found).isFile()) {
114
+ accessSync(found, constants.X_OK);
115
+ return found;
116
+ }
117
+ }
118
+ catch { }
119
+ }
120
+ return undefined;
121
+ };
122
+ /** The installer's command as the person types it: `agentrun` when that is what their PATH runs (the installer adds its
123
+ * folder to the login shell's), else its path, so a paste never starts another install's copy found earlier on PATH. */
124
+ const typedCommand = (command, env) => {
125
+ const first = agentrunOnPath(env.PATH ?? "");
126
+ return first !== undefined && sameFile(first, command) ? "agentrun" : shellWord(command);
127
+ };
85
128
  /**
86
129
  * A start the agentrun launcher made (NPX_PACKAGE_ENV: by npx, or by the installer's bin/agentrun and its service, the
87
130
  * same launcher) that a data directory refused because an earlier version wrote it (store.ts StoreFromEarlierVersion,
@@ -89,38 +132,51 @@ const freeName = (base, exists) => {
89
132
  * then the two ways on as commands to paste. That command keeps its data in ~/.agentrun wherever it is run, so a new
90
133
  * folder alone is not a new AgentRun. First, the old folder moved aside whole, so the same command starts this version
91
134
  * where it was, and the earlier version still opens what it holds; then this version on a new, empty folder: the same
92
- * command with --data. Nothing is deleted either way. Any other error, or a start the launcher did not
93
- * make, is undefined: the refusal's own words stand.
135
+ * command with --data. Nothing is deleted either way. The command is the one that started this server, as the launcher
136
+ * says (INSTALLED_COMMAND_ENV): the installer's, else npx's; never read from what the folder holds.
137
+ *
138
+ * The installer keeps its Node, its packages and its command in the folder beside the data (install.sh: node/, lib/,
139
+ * bin/agentrun). When that command started this from the folder refused, it or its service has no npx at hand, moving
140
+ * the folder takes the command, and the service starts on the refused folder whatever another command says. So there the
141
+ * one way on is the folder moved aside, then the installer run again for this same version (by default it installs the
142
+ * latest). Any other error, or a start the launcher did not make, is undefined: the refusal's own words stand.
94
143
  */
95
144
  export function earlierDataRefusal(error, data, env = {}, exists = existsSync) {
96
145
  const refused = error;
97
146
  const earlier = refused?.name === "StoreFromEarlierVersion" || (refused?.name === "SchemaVersionUnknown" && typeof refused.found === "number" && typeof refused.known === "number" && refused.found < refused.known);
98
- const door = env[NPX_PACKAGE_ENV];
99
- if (!earlier || typeof refused?.message !== "string" || door === undefined || !/^@parcha\/agentrun@\d[\w.+-]*$/.test(door))
147
+ const { launcher, yes, flags } = startedAs(env);
148
+ if (!earlier || typeof refused?.message !== "string" || launcher === undefined)
100
149
  return undefined;
101
150
  const dir = resolve(data);
102
- const yes = env.npm_config_yes === "true" ? "-y " : "";
103
- const port = env[STARTED_PORT_ENV];
104
- const flags = `${port && /^\d{1,5}$/.test(port) ? ` --port ${port}` : ""}${env[STARTED_OPEN_ENV] === "0" ? " --no-open" : ""}`;
105
- const command = `npx ${yes}${door}`;
151
+ const installed = env[INSTALLED_COMMAND_ENV] ? resolve(env[INSTALLED_COMMAND_ENV]) : undefined;
152
+ const command = installed === undefined ? `npx ${yes}${launcher}` : typedCommand(installed, env);
106
153
  // The launcher's own folder when --data names none (agentrun start.mjs): this same command opens `dir` again with no
107
154
  // --data only when `dir` is it.
108
- const launcherData = resolve(env.HOME || homedir(), ".agentrun");
109
- const again = `${command}${dir === launcherData ? "" : ` --data ${shellWord(dir)}`}${flags}`;
110
- const fresh = freeName(`${dir}-new`, exists);
155
+ const launcherData = resolve(commandData(env));
111
156
  const aside = freeName(`${dir}-earlier`, exists);
112
- // install.sh keeps its Node, its packages and the command in the folder beside the data (node/, lib/, bin/agentrun):
113
- // that command, or the service that runs it, may be what started this. Moved, they go too, whichever version they are.
114
- const installed = exists(join(dir, "bin", "agentrun")) ? " That takes the agentrun the installer put there with it (its Node in node/, lib/ and bin/agentrun): run the installer again to put this version's back." : "";
157
+ const mv = `mv ${shellWord(dir)} ${shellWord(aside)}`;
158
+ const back = `The earlier version opens the old data with --data ${shellWord(aside)}.`;
159
+ // The store's own refusal already says to add them again; an earlier release's schema says it only in the lines cut here.
160
+ const again = refused.name === "SchemaVersionUnknown" ? " Add your agents, MCP servers, keys and sign-ins again in this version." : "";
161
+ // Through real paths: a home folder reached by a link names the same command.
162
+ if (installed !== undefined && sameFile(installed, join(dir, "bin", "agentrun"))) {
163
+ const version = launcher.slice(launcher.lastIndexOf("@") + 1);
164
+ return [
165
+ refused.message.split("\n")[0],
166
+ `To keep all of it and start this version in ${dir}: ${mv}, then run the installer again for this version: curl -fsSL https://agentrun.ai/install | sh -s -- --version ${version}. Moving the folder takes the installer's Node, packages and command with it (node/, lib/, bin/agentrun); the installer puts this version's back.`,
167
+ back,
168
+ `Nothing is deleted.${again}`,
169
+ ].join("\n");
170
+ }
171
+ const fresh = freeName(`${dir}-new`, exists);
115
172
  return [
116
173
  refused.message.split("\n")[0],
117
- // Moved aside first: every later command (doctor, the harness commands, the service) then finds this version where it
118
- // looks with nothing more to remember; a new folder means the same --data on each of them.
119
- `To keep all of it where the earlier version still opens it and start this version in ${dir}: mv ${shellWord(dir)} ${shellWord(aside)}, then ${again}. The earlier version opens the old data with --data ${shellWord(aside)}.${installed}`,
174
+ // Moved aside first: every later command (doctor, the harness commands) then finds this version where it looks with
175
+ // nothing more to remember; a new folder means the same --data on each of them.
176
+ `To keep all of it where the earlier version still opens it and start this version in ${dir}: ${mv}, then ${command}${dir === launcherData ? "" : ` --data ${shellWord(dir)}`}${flags}. ${back}`,
120
177
  `Or start this version on a new, empty folder: ${command} --data ${shellWord(fresh)}${flags}`,
121
178
  ` (every later agentrun command then takes the same --data: without it, they open ${launcherData})`,
122
- // The store's own refusal already says to add them again; an earlier release's schema says it only in the lines cut here.
123
- `Either way, nothing is deleted.${refused.name === "SchemaVersionUnknown" ? " Add your agents, MCP servers, keys and sign-ins again in this version." : ""}`,
179
+ `Either way, nothing is deleted.${again}`,
124
180
  ].join("\n");
125
181
  }
126
182
  /** The port the server was started on when `--port` named one, and whether `--open` was given (1 or 0): set by its CLI
@@ -211,6 +267,19 @@ function unavailable(facts, error, npx, env) {
211
267
  const hinted = installHint(said, facts.install.npmLine, facts.install.spec, npx, env);
212
268
  return new HarnessUnavailable(hinted, hinted === said ? fixOf(facts, error) : undefined);
213
269
  }
270
+ /** The limits of a model the route translates onto a harness's wire (`provider.fetch`: provider.ts routedProvider), for
271
+ * an adapter that takes them: its window and its most output tokens, from the model's pi-ai entry in the run's models
272
+ * (`needs.models`), the entry the route's own model is. Its window is what every request asks Ollama for
273
+ * (options.num_ctx: ollama-provider.ts contextOf, at most 64k), and its output ceiling half that, at most 16,384. None
274
+ * for a model not routed, or one with no entry: its adapter's own defaults. */
275
+ export function routedLimits(provider, needs) {
276
+ if (!provider.fetch)
277
+ return {};
278
+ const entry = needs.models.getModel(needs.model.provider, needs.model.modelId);
279
+ const whole = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0;
280
+ const [window, ceiling] = [entry?.contextWindow, entry?.maxTokens];
281
+ return { ...(whole(window) ? { contextWindow: window } : {}), ...(whole(ceiling) ? { maxOutputTokens: ceiling } : {}) };
282
+ }
214
283
  /** Where a run's adapter sends its model's requests (providerFor), or, for a held run its model kept from running at its
215
284
  * create, the stand-in (heldRefusedProvider): no key is read, and its proxy refuses every request in the create's words,
216
285
  * sending none. */
@@ -400,7 +469,9 @@ export async function codexOf(env, needs, load = () => import("@parcha/agentrun-
400
469
  // On a ChatGPT plan: the plan's rules on its route (no output limit, no input count), billed to it, never priced here.
401
470
  const provider = providerOf(codexFacts.wire, env, needs, codexFacts.id);
402
471
  const plan = provider.billing === "plan";
403
- return codex.codexAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential, ...(plan ? { plan } : {}), ...(provider.refused ? { refused: provider.refused } : {}) }, price: plan ? () => null : priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(codexFacts.id, env), ...(nativeOptions(codexFacts, env).webSearch === "live" ? { webSearch: "live" } : {}), ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(standIn ? { standIn } : binary ? { binary } : {}) });
472
+ // A model the route translates onto the wire (an Ollama model): both of its proxies forward with the route's own fetch,
473
+ // Codex's live web search, which the translation cannot run, is not offered, and its window and output ceiling are the route's (routedLimits).
474
+ return codex.codexAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential, ...(plan ? { plan } : {}), ...(provider.refused ? { refused: provider.refused } : {}) }, price: plan ? () => null : priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(codexFacts.id, env), ...routedLimits(provider, needs), ...(provider.fetch ? { fetch: provider.fetch } : nativeOptions(codexFacts, env).webSearch === "live" ? { webSearch: "live" } : {}), ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(standIn ? { standIn } : binary ? { binary } : {}) });
404
475
  }
405
476
  /** opencode's adapter, from `load` (this server's own, src/harness-opencode; a test gives its own). Its model goes where
406
477
  * its wire's do (providerFor): serve's gateway (AGENT_MODEL_BASE_URL), OpenAI or OpenRouter, on the Responses API,
@@ -427,7 +498,9 @@ export async function opencodeOf(env, needs, load = () => import("./harness-open
427
498
  // adapter reads: each SKILL.md goes as servedSkill writes it (its name and description, as a prompt reads them, on one
428
499
  // line each), so a CRLF file or a folded description is listed by its own words.
429
500
  const skills = needs.skills && servedSkills(needs.skills);
430
- return opencode.openCodeAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential }, price: priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(openCodeFacts.id, env), ...(needs.confine ? { confine: needs.confine } : {}), ...(skills?.length ? { skills } : {}), ...(standIn ? { standIn } : {}) });
501
+ // A model the route translates onto the wire (an Ollama model): its proxies forward with the route's own fetch, and its
502
+ // window and output ceiling are the route's (routedLimits).
503
+ return opencode.openCodeAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential }, price: priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(openCodeFacts.id, env), ...routedLimits(provider, needs), ...(provider.fetch ? { fetch: provider.fetch } : {}), ...(needs.confine ? { confine: needs.confine } : {}), ...(skills?.length ? { skills } : {}), ...(standIn ? { standIn } : {}) });
431
504
  }
432
505
  /** Why `harness` cannot run here, or undefined when it can (its entry's refusal): its package and pins, its provider, and
433
506
  * the adapter's own check of the model `given` names (with none, a model of its wire's vendor: whether it runs here at
@@ -86,7 +86,7 @@ function revisionInputOf(definition, files) {
86
86
  if (isObject(definition.workflow))
87
87
  return { kind: "workflow", workflow: definition.workflow, ...(definition.approvals === "never" ? { approvals: "never" } : {}), ...common, ...capped };
88
88
  // true, false or the loop's numbers (learning-setting.ts), checked by validate.ts and again by the body.
89
- const learning = definition.learning !== undefined && learningSettingIssue(definition.learning) === undefined ? { learning: definition.learning } : {};
89
+ const learning = definition.learning !== undefined && learningSettingIssue(definition.learning, "learning") === undefined ? { learning: definition.learning } : {};
90
90
  return {
91
91
  kind: "agentic",
92
92
  instructions: definition.instructions,
@@ -0,0 +1,3 @@
1
+ /** `answer`'s body as text, read up to `max` bytes; undefined once it is longer (the rest is cancelled, never read). A
2
+ * body that breaks off while it is read throws, as `answer.text()` would. */
3
+ export declare function textUpTo(answer: Response, max: number): Promise<string | undefined>;
@@ -0,0 +1,22 @@
1
+ // An answer's body read with a cap: what a call to another service reads of its answer, so no answer is held whole in
2
+ // memory however long it is.
3
+ /** `answer`'s body as text, read up to `max` bytes; undefined once it is longer (the rest is cancelled, never read). A
4
+ * body that breaks off while it is read throws, as `answer.text()` would. */
5
+ export async function textUpTo(answer, max) {
6
+ const reader = answer.body?.getReader();
7
+ if (!reader)
8
+ return "";
9
+ const chunks = [];
10
+ let size = 0;
11
+ for (;;) {
12
+ const { done, value } = await reader.read();
13
+ if (done)
14
+ return Buffer.concat(chunks).toString("utf8");
15
+ size += value.byteLength;
16
+ if (size > max) {
17
+ await reader.cancel().catch(() => { });
18
+ return undefined;
19
+ }
20
+ chunks.push(value);
21
+ }
22
+ }
@@ -27,10 +27,8 @@ import type { Route } from "./server.js";
27
27
  * its key by api_key_env (COMPOSIO_API_KEY, on the launcher's list of secrets, read at each use through secrets.ts
28
28
  * secret, sent to Composio's origin alone: composio-made.ts composioEnvKey), and its body names no address or headers.
29
29
  * There is no list or read of the servers here (listMcpServerNames above is the listing). The generic save
30
- * (saveMcpServer) is served only when the operator names MCP origins (API_ONLY_MCP_ORIGINS_ENV), and then saves a
31
- * per_run server (which keeps no credential) at one of those origins alone (apiOnlyMcpSave); unset, it is refused as
32
- * any other route, so the token saves no server at an address or with headers of its own. Previews, refreshes,
33
- * sign-ins and Composio's triggers stay refused;
30
+ * (saveMcpServer) is apiOnlyMcpSave: the serve README's API-only section states it. Previews, refreshes, sign-ins
31
+ * and Composio's triggers stay refused;
34
32
  * - the launch hook's host (the backend in front of this server) releases a firing it took and will start no run for
35
33
  * (releaseTriggerFiring, triggers.ts release), so its trigger's room frees at once; with no launch hook the route is
36
34
  * the route's own 422. */
package/dist/api-only.js CHANGED
@@ -34,10 +34,8 @@ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-ho
34
34
  * its key by api_key_env (COMPOSIO_API_KEY, on the launcher's list of secrets, read at each use through secrets.ts
35
35
  * secret, sent to Composio's origin alone: composio-made.ts composioEnvKey), and its body names no address or headers.
36
36
  * There is no list or read of the servers here (listMcpServerNames above is the listing). The generic save
37
- * (saveMcpServer) is served only when the operator names MCP origins (API_ONLY_MCP_ORIGINS_ENV), and then saves a
38
- * per_run server (which keeps no credential) at one of those origins alone (apiOnlyMcpSave); unset, it is refused as
39
- * any other route, so the token saves no server at an address or with headers of its own. Previews, refreshes,
40
- * sign-ins and Composio's triggers stay refused;
37
+ * (saveMcpServer) is apiOnlyMcpSave: the serve README's API-only section states it. Previews, refreshes, sign-ins
38
+ * and Composio's triggers stay refused;
41
39
  * - the launch hook's host (the backend in front of this server) releases a firing it took and will start no run for
42
40
  * (releaseTriggerFiring, triggers.ts release), so its trigger's room frees at once; with no launch hook the route is
43
41
  * the route's own 422. */
@@ -16,7 +16,7 @@ import { mkdtempSync, rmSync } from "node:fs";
16
16
  import { createServer } from "node:http";
17
17
  import { tmpdir } from "node:os";
18
18
  import { join } from "node:path";
19
- import { ATTACH_CLOSE, ATTACH_HEARTBEAT_MS, ATTACH_IDLE_MS, ATTACH_PATH, ATTACH_REDIAL_MAX_MS, ATTACH_SUBPROTOCOL, AttachHub, MAX_LINE_BYTES, PROTOCOL_VERSION } from "@parcha/agentrun-computer";
19
+ import { ATTACH_CLOSE, ATTACH_HEARTBEAT_MS, ATTACH_IDLE_MS, ATTACH_PATH, ATTACH_REDIAL_MAX_MS, ATTACH_SUBPROTOCOL, AttachHub, attachSubprotocolOf, helloProblem, MAX_LINE_BYTES } from "@parcha/agentrun-computer";
20
20
  import WebSocket from "ws";
21
21
  import { createAttachRoutes } from "./computer-attach.js";
22
22
  import { ApiError } from "./errors.js";
@@ -226,10 +226,11 @@ export async function runAttachConformance(options) {
226
226
  await until(() => paired, options.pairMs ?? 600_000, "the driver did not pair with the code");
227
227
  const dial = await until(() => live(), ms(30_000) + 2_000, "the driver paired but did not dial the attach socket and answer hello");
228
228
  const hello = dial.hello;
229
- if (dial.ws.protocol !== ATTACH_SUBPROTOCOL)
229
+ if (attachSubprotocolOf([dial.ws.protocol]) === undefined)
230
230
  fail(`it asked for ${dial.ws.protocol || "no subprotocol"}, not ${ATTACH_SUBPROTOCOL}`);
231
- if (hello.protocol !== PROTOCOL_VERSION)
232
- fail(`its hello says protocol ${hello.protocol}, not ${PROTOCOL_VERSION}`);
231
+ const problem = helloProblem(hello.protocol, "server");
232
+ if (problem)
233
+ fail(`its driver ${problem}`);
233
234
  if (hello.kind !== paired.hello.kind || hello.os !== paired.hello.os)
234
235
  fail(`it paired as ${paired.hello.os} ${paired.hello.kind} and its hello says ${hello.os} ${hello.kind}`);
235
236
  if (!Array.isArray(hello.groups) || hello.groups.length === 0)
@@ -33,9 +33,10 @@ export declare function remoteDockerOnce(env: NodeJS.ProcessEnv): Promise<string
33
33
  /** Why this server can't run a Docker computer, or undefined when it can: on its Docker's own host (`here`), or in a
34
34
  * container of that Docker's with its data on a named volume (`paths`: the computer mounts the run's folder and its
35
35
  * daemon as that volume's subpaths, workspace/computer-deps.ts dockerVolumeOf). Any other layout says why (`reason`,
36
- * dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint). The one check every
37
- * reader of Docker's offer takes. */
38
- export declare function dockerComputerRefusal(paths: DockerPaths, remote: string | undefined): string | undefined;
36
+ * dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint), and then a computerd
37
+ * build missing for Docker's architecture (`noDaemon`: the computer package's dockerDaemonOf words, the ones its
38
+ * create() would fail with). The one check every reader of Docker's offer takes. */
39
+ export declare function dockerComputerRefusal(paths: DockerPaths, remote: string | undefined, noDaemon?: string): string | undefined;
39
40
  /** Where a runner's Docker has the data directory `data`, read once by the runner that makes a Docker computer: as the
40
41
  * server reads it at its start (dockerPathsOf), on Linux alone; under `--faux` from the mountinfo file the tests name
41
42
  * (FAUX_MOUNTINFO_ENV), else as a host. */
@@ -67,8 +68,9 @@ export type DockerCall = (args: readonly string[]) => Promise<{
67
68
  }>;
68
69
  /**
69
70
  * Where the Docker this server runs boxes on has `data` (see the head of this file), resolved once at its start. A
70
- * server with no container id in its mountinfo and none of a container's marks (`inContainer`: /.dockerenv, Podman's
71
- * /run/.containerenv) is on a host: `here`, and nothing is asked. `mountinfo`, `inContainer` and `docker` are the tests'.
71
+ * server with no container id in its mountinfo that computer's containerSigns sees in no container either (`inContainer`:
72
+ * a runtime's mark, or a container's cgroup, as a Kubernetes pod's) is on a host: `here`, and nothing is asked. One it sees
73
+ * is in a container this way can't map onto Docker's paths: IN_COMPOSE. `mountinfo`, `inContainer` and `docker` are the tests'.
72
74
  */
73
75
  export declare function dockerPathsOf(env: NodeJS.ProcessEnv, data: string, options?: {
74
76
  mountinfo?: string;
package/dist/box-paths.js CHANGED
@@ -9,8 +9,8 @@
9
9
  // computer-deps.ts dockerVolumeOf, the Docker provider's `volume`). Any other layout, or an older engine, is a reason,
10
10
  // said once at the start, and docker is unavailable: a guess would make every computer fail at its create.
11
11
  import { execFile } from "node:child_process";
12
- import { existsSync } from "node:fs";
13
12
  import { readFile } from "node:fs/promises";
13
+ import { containerSigns } from "@parcha/agentrun-computer";
14
14
  import { FAUX_ENV } from "./model.js";
15
15
  import { withoutSecrets } from "./secrets.js";
16
16
  /** The one way a server in a container runs Docker computers. */
@@ -74,12 +74,15 @@ export function remoteDockerOnce(env) {
74
74
  /** Why this server can't run a Docker computer, or undefined when it can: on its Docker's own host (`here`), or in a
75
75
  * container of that Docker's with its data on a named volume (`paths`: the computer mounts the run's folder and its
76
76
  * daemon as that volume's subpaths, workspace/computer-deps.ts dockerVolumeOf). Any other layout says why (`reason`,
77
- * dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint). The one check every
78
- * reader of Docker's offer takes. */
79
- export function dockerComputerRefusal(paths, remote) {
77
+ * dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint), and then a computerd
78
+ * build missing for Docker's architecture (`noDaemon`: the computer package's dockerDaemonOf words, the ones its
79
+ * create() would fail with). The one check every reader of Docker's offer takes. */
80
+ export function dockerComputerRefusal(paths, remote, noDaemon) {
80
81
  if ("reason" in paths)
81
82
  return paths.reason;
82
- return remote !== undefined ? remoteDockerWords(remote) : undefined;
83
+ if (remote !== undefined)
84
+ return remoteDockerWords(remote);
85
+ return noDaemon === undefined ? undefined : `${noDaemon}, then restart AgentRun`;
83
86
  }
84
87
  /** Where a runner's Docker has the data directory `data`, read once by the runner that makes a Docker computer: as the
85
88
  * server reads it at its start (dockerPathsOf), on Linux alone; under `--faux` from the mountinfo file the tests name
@@ -130,14 +133,15 @@ const dockerCall = (env) => (args) => new Promise((resolve) => {
130
133
  });
131
134
  /**
132
135
  * Where the Docker this server runs boxes on has `data` (see the head of this file), resolved once at its start. A
133
- * server with no container id in its mountinfo and none of a container's marks (`inContainer`: /.dockerenv, Podman's
134
- * /run/.containerenv) is on a host: `here`, and nothing is asked. `mountinfo`, `inContainer` and `docker` are the tests'.
136
+ * server with no container id in its mountinfo that computer's containerSigns sees in no container either (`inContainer`:
137
+ * a runtime's mark, or a container's cgroup, as a Kubernetes pod's) is on a host: `here`, and nothing is asked. One it sees
138
+ * is in a container this way can't map onto Docker's paths: IN_COMPOSE. `mountinfo`, `inContainer` and `docker` are the tests'.
135
139
  */
136
140
  export async function dockerPathsOf(env, data, options = {}) {
137
141
  const mountinfo = options.mountinfo ?? (await readFile("/proc/self/mountinfo", "utf8").catch(() => ""));
138
142
  const id = ownContainerOf(mountinfo);
139
143
  if (!id)
140
- return (options.inContainer ?? (existsSync("/.dockerenv") || existsSync("/run/.containerenv"))) ? { reason: IN_COMPOSE } : { here: true };
144
+ return (options.inContainer ?? containerSigns() !== undefined) ? { reason: IN_COMPOSE } : { here: true };
141
145
  const docker = options.docker ?? dockerCall(env);
142
146
  // A container this Docker does not have is another Docker's: its socket is not the one that runs this server.
143
147
  const inspected = await docker(["inspect", "--type", "container", "--format", "{{json .Mounts}}", id]);
@@ -10,15 +10,13 @@ export interface BrowserComputerOptions {
10
10
  };
11
11
  /** A headless browser where the provider offers one. */
12
12
  readonly headless?: boolean;
13
- /** Where a server behind a browser gateway holds the sockets of Browserbase's connect hosts (BROWSERBASE_CONNECT_BASE_URL). */
14
- readonly connectBaseUrl?: string;
15
13
  readonly sleep?: (ms: number) => Promise<void>;
16
14
  }
17
15
  /** pi-browser's provider over `computer`, a browser computer the claim or the plane opened. */
18
16
  export declare function claimBrowserProvider(computer: ClaimBrowser, options?: BrowserComputerOptions): BrowserProvider;
19
- /** The plane's vendor as a computer provider of the registry, made with the run's tool keys by the registry's names
20
- * (computer-keys.ts providerOptions): the same provider an agent's browser computer is, on the keys the tool plane
21
- * resolved it by. */
17
+ /** The plane's vendor as a computer provider of the registry, made with the run's tool keys and the server's own variables
18
+ * its descriptor names (computer-keys.ts providerFromEnv): the same provider an agent's browser computer is, on the keys
19
+ * the tool plane resolved it by, through the gateway the key checks and sign-ins go through. */
22
20
  export declare function planeComputer(vendor: string, env: NodeJS.ProcessEnv): Promise<ComputerProvider>;
23
21
  /** The run's browser sessions of a lower claim epoch released, as a computer's are when a claim starts it (the janitor's
24
22
  * releaseOlder): a runner that died after the vendor made a session and before its id was kept left one this claim's
@@ -31,9 +29,6 @@ export declare function releaseOlderBrowsers(provider: ComputerProvider, run: {
31
29
  readonly signal?: AbortSignal;
32
30
  readonly sleep?: (ms: number) => Promise<void>;
33
31
  }): Promise<void>;
34
- /** A Browserbase connect URL moved onto the credential proxy that fronts its sockets: only `*.browserbase.com` hosts, with
35
- * the signing query kept. */
36
- export declare function rewriteConnectUrl(connectUrl: string, connectBaseUrl: string | undefined): string;
37
32
  /** A run's browser over `provider`, a browser computer provider (the plane's vendor, or a test's stand-in), as the claim
38
33
  * opens an agent's browser computer: each session made under the run's labels (`run`, when the run holds a claim, so a
39
34
  * sweep finds what it left), for at most the provider's longest lifetime. A provider of another kind is refused. */
@@ -1,6 +1,6 @@
1
1
  import { BrowserFailureError, browserFailure, cdpCall } from "@parcha/pi-browser";
2
- import { BROWSER_IMAGE, isBrowserProvider, PROVIDERS, providerFor, releaseOlder, runLabels } from "@parcha/agentrun-computer";
3
- import { KEY_TABLE, providerOptions } from "./computer-keys.js";
2
+ import { BROWSER_IMAGE, isBrowserProvider, releaseOlder, runLabels } from "@parcha/agentrun-computer";
3
+ import { providerFromEnv } from "./computer-keys.js";
4
4
  import { claimBrowser } from "./workspace/computer-for-claim.js";
5
5
  /** Custody's own refusal of a second saver, in its words: no session was started. */
6
6
  const ONE_SAVER = "one session at a time may save to this agent's saved sign-in, and another session is saving to it now. Wait for it to end, or start without saving. No session was started.";
@@ -161,7 +161,9 @@ export function claimBrowserProvider(computer, options = {}) {
161
161
  status,
162
162
  async attach(ref, signal) {
163
163
  signal?.throwIfAborted();
164
- const url = rewriteConnectUrl(await statused(computer.url(ref.id)), options.connectBaseUrl);
164
+ // The provider's connect URL as a driver dials it: one behind a gateway that fronts its sockets (hostEnv) already
165
+ // gives the gateway's.
166
+ const url = await statused(computer.url(ref.id));
165
167
  // A provider that keeps a session's downloads keeps only what the browser was told to save into its folder, and
166
168
  // that lasts as long as the socket that told it: one per session, held until its release. A failure costs the
167
169
  // files, not the session.
@@ -210,20 +212,14 @@ export function claimBrowserProvider(computer, options = {}) {
210
212
  }
211
213
  return provider;
212
214
  }
213
- /** The plane's vendor as a computer provider of the registry, made with the run's tool keys by the registry's names
214
- * (computer-keys.ts providerOptions): the same provider an agent's browser computer is, on the keys the tool plane
215
- * resolved it by. */
215
+ /** The plane's vendor as a computer provider of the registry, made with the run's tool keys and the server's own variables
216
+ * its descriptor names (computer-keys.ts providerFromEnv): the same provider an agent's browser computer is, on the keys
217
+ * the tool plane resolved it by, through the gateway the key checks and sign-ins go through. */
216
218
  export async function planeComputer(vendor, env) {
217
- const keys = Object.fromEntries((KEY_TABLE.keys[vendor] ?? []).flatMap((key) => (typeof env[key.name] === "string" && env[key.name] !== "" ? [[key.name, env[key.name]]] : [])));
218
- const options = providerOptions(vendor, keys);
219
- if (!options.ok)
220
- throw new BrowserFailureError(browserFailure("browser_unavailable", `The browser does not run here: ${options.error.message}.`));
221
- // The server's own variables the provider's descriptor says it reads (hostEnv: the gateway a server behind one reaches
222
- // the vendor through), as the claim's providers get them (workspace/computer-deps.ts): the key checks and the sign-in
223
- // creation already go through that gateway, so the browser's sessions do too.
224
- const names = PROVIDERS.find((one) => one.id === vendor)?.hostEnv;
225
- const hostEnv = names ? { env: Object.fromEntries(names.flatMap((name) => (env[name] === undefined ? [] : [[name, String(env[name])]]))) } : {};
226
- return providerFor(vendor, { ...options.options, ...hostEnv });
219
+ const made = await providerFromEnv(vendor, env);
220
+ if (!made.ok)
221
+ throw new BrowserFailureError(browserFailure("browser_unavailable", `The browser does not run here: ${made.error.message}.`));
222
+ return made.value;
227
223
  }
228
224
  /** The run's browser sessions of a lower claim epoch released, as a computer's are when a claim starts it (the janitor's
229
225
  * releaseOlder): a runner that died after the vendor made a session and before its id was kept left one this claim's
@@ -237,25 +233,6 @@ export async function releaseOlderBrowsers(provider, run, { signal, sleep = (ms)
237
233
  if (settleMs > 0 && older.value.released.length + older.value.detached.length > 0)
238
234
  await sleep(settleMs);
239
235
  }
240
- /** A Browserbase connect URL moved onto the credential proxy that fronts its sockets: only `*.browserbase.com` hosts, with
241
- * the signing query kept. */
242
- export function rewriteConnectUrl(connectUrl, connectBaseUrl) {
243
- if (!connectBaseUrl)
244
- return connectUrl;
245
- try {
246
- const target = new URL(connectBaseUrl);
247
- const url = new URL(connectUrl);
248
- if (!/(?:^|\.)browserbase\.com$/i.test(url.hostname))
249
- return connectUrl;
250
- url.protocol = target.protocol;
251
- url.host = target.host;
252
- url.pathname = target.pathname.replace(/\/$/, "") + url.pathname;
253
- return url.toString();
254
- }
255
- catch {
256
- return connectUrl;
257
- }
258
- }
259
236
  /** A run's browser over `provider`, a browser computer provider (the plane's vendor, or a test's stand-in), as the claim
260
237
  * opens an agent's browser computer: each session made under the run's labels (`run`, when the run holds a claim, so a
261
238
  * sweep finds what it left), for at most the provider's longest lifetime. A provider of another kind is refused. */