@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45

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 (388) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +580 -320
  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 +92 -22
  28. package/dist/composio-preset.d.ts +4 -3
  29. package/dist/composio-preset.js +81 -11
  30. package/dist/composio-triggers.d.ts +34 -2
  31. package/dist/composio-triggers.js +261 -31
  32. package/dist/computer-attach.d.ts +40 -5
  33. package/dist/computer-attach.js +130 -15
  34. package/dist/computer-keys.d.ts +3 -0
  35. package/dist/computer-keys.js +7 -1
  36. package/dist/computer-live.js +3 -2
  37. package/dist/computer-lost.d.ts +11 -0
  38. package/dist/computer-lost.js +19 -0
  39. package/dist/computer-record.d.ts +10 -2
  40. package/dist/computer-record.js +50 -18
  41. package/dist/computer-setting.d.ts +1 -0
  42. package/dist/computer-setting.js +2 -2
  43. package/dist/computers.d.ts +21 -10
  44. package/dist/computers.js +39 -28
  45. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  46. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decisions.d.ts +1 -1
  49. package/dist/dial-relay.d.ts +29 -0
  50. package/dist/dial-relay.js +94 -0
  51. package/dist/email/tools.js +10 -5
  52. package/dist/env-proxy.d.ts +2 -0
  53. package/dist/env-proxy.js +35 -0
  54. package/dist/errors.d.ts +4 -1
  55. package/dist/errors.js +10 -4
  56. package/dist/faux-computers.d.ts +8 -2
  57. package/dist/faux-computers.js +83 -6
  58. package/dist/harness-archive.d.ts +67 -0
  59. package/dist/harness-archive.js +177 -0
  60. package/dist/harness-goose.d.ts +34 -0
  61. package/dist/harness-goose.js +87 -0
  62. package/dist/harness-install.d.ts +21 -0
  63. package/dist/harness-install.js +24 -11
  64. package/dist/harness-opencode/adapter.js +1 -1
  65. package/dist/harness-table.d.ts +59 -3
  66. package/dist/harness-table.js +119 -14
  67. package/dist/harness.d.ts +17 -1
  68. package/dist/harness.js +22 -11
  69. package/dist/host.d.ts +12 -10
  70. package/dist/host.js +19 -16
  71. package/dist/import-worker.d.ts +3 -0
  72. package/dist/import-worker.js +7 -5
  73. package/dist/import.d.ts +22 -1
  74. package/dist/import.js +141 -28
  75. package/dist/key-check.js +3 -0
  76. package/dist/learn/audit.d.ts +6 -6
  77. package/dist/learn/audit.js +3 -7
  78. package/dist/learn/check.d.ts +26 -89
  79. package/dist/learn/check.js +58 -336
  80. package/dist/learn/commit.d.ts +63 -90
  81. package/dist/learn/commit.js +124 -316
  82. package/dist/learn/compile.d.ts +53 -50
  83. package/dist/learn/compile.js +88 -103
  84. package/dist/learn/corrections.d.ts +13 -0
  85. package/dist/learn/corrections.js +23 -0
  86. package/dist/learn/delete.d.ts +17 -0
  87. package/dist/learn/delete.js +42 -0
  88. package/dist/learn/folder.d.ts +35 -47
  89. package/dist/learn/folder.js +118 -134
  90. package/dist/learn/index.d.ts +3 -5
  91. package/dist/learn/index.js +6 -9
  92. package/dist/learn/learning.sh +45 -15
  93. package/dist/learn/promote.d.ts +20 -2
  94. package/dist/learn/promote.js +17 -4
  95. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
  96. package/dist/learn/{skills.js → workflow-draft.js} +65 -59
  97. package/dist/learn/workflow-nodes.d.ts +22 -1
  98. package/dist/learn/workflow-nodes.js +29 -10
  99. package/dist/learned-workflow.js +2 -2
  100. package/dist/learning-cost.d.ts +127 -13
  101. package/dist/learning-cost.js +142 -10
  102. package/dist/learning-routes.d.ts +99 -170
  103. package/dist/learning-routes.js +199 -420
  104. package/dist/learning-run.d.ts +19 -40
  105. package/dist/learning-run.js +23 -93
  106. package/dist/learning-setting.d.ts +4 -4
  107. package/dist/learning-setting.js +6 -6
  108. package/dist/learning-words.d.ts +28 -74
  109. package/dist/learning-words.js +64 -162
  110. package/dist/learning.d.ts +62 -393
  111. package/dist/learning.js +101 -651
  112. package/dist/listen-first.d.ts +30 -0
  113. package/dist/listen-first.js +115 -0
  114. package/dist/live-reach.d.ts +25 -2
  115. package/dist/live-reach.js +46 -4
  116. package/dist/llms.txt +2 -1
  117. package/dist/local-models.d.ts +3 -11
  118. package/dist/local-models.js +5 -6
  119. package/dist/mcp-servers-store.d.ts +16 -16
  120. package/dist/model-form.js +6 -5
  121. package/dist/model.d.ts +12 -4
  122. package/dist/model.js +41 -16
  123. package/dist/native/binding.js +1 -1
  124. package/dist/native/connection.js +1 -1
  125. package/dist/native/discovery.js +1 -1
  126. package/dist/native/instructions.d.ts +3 -0
  127. package/dist/native/instructions.js +5 -3
  128. package/dist/native/remote-worker-bridge.js +9 -43
  129. package/dist/native/remote.d.ts +8 -15
  130. package/dist/native/remote.js +3 -3
  131. package/dist/native/schema.js +1 -1
  132. package/dist/native/types.d.ts +2 -2
  133. package/dist/openapi.js +375 -347
  134. package/dist/owner.d.ts +8 -0
  135. package/dist/owner.js +11 -0
  136. package/dist/paid-calls.d.ts +14 -0
  137. package/dist/paid-calls.js +31 -1
  138. package/dist/particle-provider.d.ts +11 -0
  139. package/dist/particle-provider.js +135 -0
  140. package/dist/place.d.ts +8 -3
  141. package/dist/place.js +13 -9
  142. package/dist/port-models.d.ts +12 -4
  143. package/dist/port-models.js +28 -11
  144. package/dist/print.d.ts +27 -0
  145. package/dist/print.js +21 -0
  146. package/dist/provider.d.ts +7 -0
  147. package/dist/provider.js +30 -2
  148. package/dist/reflect-range.js +2 -3
  149. package/dist/run-launch.d.ts +14 -28
  150. package/dist/run-launch.js +9 -12
  151. package/dist/run-learning-served.d.ts +16 -90
  152. package/dist/run-listing.d.ts +34 -0
  153. package/dist/run-listing.js +128 -0
  154. package/dist/run-model-key.d.ts +64 -0
  155. package/dist/run-model-key.js +147 -0
  156. package/dist/run-timeline-served.js +5 -3
  157. package/dist/run-trace.d.ts +97 -0
  158. package/dist/run-trace.js +253 -0
  159. package/dist/run-view.d.ts +15 -0
  160. package/dist/run-view.js +9 -0
  161. package/dist/runnable.js +2 -1
  162. package/dist/runner/adapter-loop.d.ts +14 -6
  163. package/dist/runner/adapter-loop.js +25 -14
  164. package/dist/runner/adapter-run-spec.d.ts +22 -7
  165. package/dist/runner/adapter-run-spec.js +130 -77
  166. package/dist/runner/adapters/index.d.ts +4 -2
  167. package/dist/runner/adapters/index.js +35 -4
  168. package/dist/runner/adapters/pi.d.ts +4 -12
  169. package/dist/runner/adapters/pi.js +2 -2
  170. package/dist/runner/audit.d.ts +5 -1
  171. package/dist/runner/audit.js +31 -12
  172. package/dist/runner/beside.d.ts +7 -2
  173. package/dist/runner/beside.js +41 -9
  174. package/dist/runner/claim-secrets.d.ts +66 -1
  175. package/dist/runner/claim-secrets.js +136 -3
  176. package/dist/runner/cli-run-spec.d.ts +2 -1
  177. package/dist/runner/cli-run-spec.js +82 -59
  178. package/dist/runner/commands.d.ts +3 -6
  179. package/dist/runner/conformance/harness.d.ts +6 -0
  180. package/dist/runner/conformance/harness.js +16 -5
  181. package/dist/runner/dispatch.d.ts +2 -2
  182. package/dist/runner/end-of-run.d.ts +6 -14
  183. package/dist/runner/end-of-run.js +8 -33
  184. package/dist/runner/feedback-round.d.ts +5 -4
  185. package/dist/runner/feedback-round.js +14 -10
  186. package/dist/runner/github-app.js +3 -1
  187. package/dist/runner/harness-loops.d.ts +0 -8
  188. package/dist/runner/harness-loops.js +30 -56
  189. package/dist/runner/held.d.ts +170 -0
  190. package/dist/runner/held.js +57 -0
  191. package/dist/runner/journal-kinds.d.ts +7 -3
  192. package/dist/runner/journal-kinds.js +2 -3
  193. package/dist/runner/learned-first.d.ts +40 -0
  194. package/dist/runner/learned-first.js +32 -0
  195. package/dist/runner/learning-end.d.ts +77 -66
  196. package/dist/runner/learning-end.js +250 -299
  197. package/dist/runner/learning-seed.d.ts +15 -33
  198. package/dist/runner/learning-seed.js +24 -45
  199. package/dist/runner/loop-contract.d.ts +8 -3
  200. package/dist/runner/loop-contract.js +4 -0
  201. package/dist/runner/loop.js +6 -2
  202. package/dist/runner/main.d.ts +18 -9
  203. package/dist/runner/main.js +82 -22
  204. package/dist/runner/mcp-run.d.ts +11 -0
  205. package/dist/runner/mcp-run.js +67 -0
  206. package/dist/runner/memory-claim.d.ts +14 -6
  207. package/dist/runner/memory-claim.js +18 -9
  208. package/dist/runner/model-route.d.ts +7 -4
  209. package/dist/runner/model-route.js +22 -10
  210. package/dist/runner/native-loop.d.ts +0 -7
  211. package/dist/runner/native-loop.js +9 -101
  212. package/dist/runner/promotion.d.ts +13 -6
  213. package/dist/runner/promotion.js +63 -17
  214. package/dist/runner/reflect-hook.d.ts +64 -91
  215. package/dist/runner/reflect-hook.js +112 -206
  216. package/dist/runner/run-channel.d.ts +43 -0
  217. package/dist/runner/run-channel.js +467 -0
  218. package/dist/runner/run-child-host.d.ts +169 -0
  219. package/dist/runner/run-child-host.js +1222 -0
  220. package/dist/runner/run-child.d.ts +1 -0
  221. package/dist/runner/run-child.js +254 -0
  222. package/dist/runner/run-errors.d.ts +2 -0
  223. package/dist/runner/run-errors.js +20 -0
  224. package/dist/runner/runner.js +58 -9
  225. package/dist/runner/sdk-ask.d.ts +78 -0
  226. package/dist/runner/sdk-ask.js +158 -0
  227. package/dist/runner/sdk-loop.d.ts +2 -4
  228. package/dist/runner/sdk-loop.js +29 -49
  229. package/dist/runner/store-secrets.d.ts +5 -3
  230. package/dist/runner/store-secrets.js +14 -6
  231. package/dist/runner/workflow-first.d.ts +5 -0
  232. package/dist/runner/workflow-first.js +4 -0
  233. package/dist/runner/workflow-spec.js +17 -4
  234. package/dist/runs-over-store.d.ts +21 -32
  235. package/dist/runs-over-store.js +44 -41
  236. package/dist/sdk/runs.d.ts +6 -11
  237. package/dist/sdk/runs.js +20 -41
  238. package/dist/sdk/schema.js +3 -4
  239. package/dist/sdk/workflows.d.ts +1 -1
  240. package/dist/seal-key.d.ts +5 -0
  241. package/dist/seal-key.js +7 -0
  242. package/dist/secrets.d.ts +3 -0
  243. package/dist/secrets.js +16 -3
  244. package/dist/server.d.ts +119 -83
  245. package/dist/server.js +1121 -419
  246. package/dist/sign-ins-store.d.ts +8 -0
  247. package/dist/sign-ins-store.js +36 -1
  248. package/dist/skills.js +1 -1
  249. package/dist/store/index.d.ts +3 -3
  250. package/dist/store/index.js +2 -2
  251. package/dist/store/journal/storage.js +3 -0
  252. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  253. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  254. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  255. package/dist/store/schema.d.ts +53 -4
  256. package/dist/store/schema.js +137 -6
  257. package/dist/store/seal.d.ts +20 -2
  258. package/dist/store/seal.js +24 -8
  259. package/dist/store/sqlite/connection.d.ts +2 -0
  260. package/dist/store/sqlite/connection.js +3 -1
  261. package/dist/store/sqlite/run-launch.d.ts +4 -1
  262. package/dist/store/sqlite/run-launch.js +12 -0
  263. package/dist/store/sqlite/run-patch.d.ts +0 -17
  264. package/dist/store/sqlite/run-patch.js +4 -33
  265. package/dist/store/sqlite/store.d.ts +3 -2
  266. package/dist/store/sqlite/store.js +360 -75
  267. package/dist/store/sqlite/worker.js +25 -0
  268. package/dist/store/store.d.ts +231 -39
  269. package/dist/store/store.js +25 -3
  270. package/dist/store-reads/analytics.js +11 -1
  271. package/dist/store-reads/learning.d.ts +131 -194
  272. package/dist/store-reads/learning.js +292 -301
  273. package/dist/store-reads/loop.d.ts +0 -1
  274. package/dist/store-reads/loop.js +1 -1
  275. package/dist/store-reads/stats.js +13 -3
  276. package/dist/store-view.d.ts +34 -2
  277. package/dist/store-view.js +108 -41
  278. package/dist/telemetry.d.ts +59 -0
  279. package/dist/telemetry.js +153 -0
  280. package/dist/template-eval.d.ts +3 -6
  281. package/dist/template-eval.js +22 -36
  282. package/dist/templates.d.ts +2 -1
  283. package/dist/templates.js +6 -3
  284. package/dist/timeline/index.d.ts +1 -1
  285. package/dist/timeline/index.js +1 -1
  286. package/dist/timeline/timeline.d.ts +5 -1
  287. package/dist/timeline/timeline.js +16 -0
  288. package/dist/tool-gate.d.ts +0 -7
  289. package/dist/tool-gate.js +1 -15
  290. package/dist/tool-keys-store.d.ts +1 -1
  291. package/dist/tool-keys.d.ts +6 -4
  292. package/dist/tool-keys.js +12 -6
  293. package/dist/tool-plane.d.ts +12 -12
  294. package/dist/tools.d.ts +13 -13
  295. package/dist/tools.js +29 -9
  296. package/dist/trigger-adapter.d.ts +3 -0
  297. package/dist/trigger-adapters.d.ts +4 -0
  298. package/dist/trigger-adapters.js +13 -0
  299. package/dist/trigger-composio.d.ts +58 -1
  300. package/dist/trigger-composio.js +160 -6
  301. package/dist/triggers.d.ts +64 -5
  302. package/dist/triggers.js +141 -17
  303. package/dist/validate.d.ts +11 -7
  304. package/dist/validate.js +9 -8
  305. package/dist/webhooks.d.ts +4 -1
  306. package/dist/webhooks.js +11 -4
  307. package/dist/workspace/agent-computer.d.ts +2 -0
  308. package/dist/workspace/agent-computer.js +2 -0
  309. package/dist/workspace/archil-claim.d.ts +7 -0
  310. package/dist/workspace/archil-claim.js +29 -0
  311. package/dist/workspace/archil.d.ts +9 -1
  312. package/dist/workspace/archil.js +165 -3
  313. package/dist/workspace/attach.d.ts +3 -1
  314. package/dist/workspace/attach.js +2 -0
  315. package/dist/workspace/attached-computers.d.ts +16 -5
  316. package/dist/workspace/attached-computers.js +25 -9
  317. package/dist/workspace/computer-deps.js +1 -1
  318. package/dist/workspace/computer-for-claim.d.ts +22 -8
  319. package/dist/workspace/computer-for-claim.js +339 -46
  320. package/dist/workspace/computer-hold.js +2 -1
  321. package/dist/workspace/computer-kept.d.ts +11 -1
  322. package/dist/workspace/computer-kept.js +24 -3
  323. package/dist/workspace/resolve-computer.d.ts +41 -21
  324. package/dist/workspace/resolve-computer.js +172 -64
  325. package/dist/workspace/revision-skills.d.ts +1 -2
  326. package/dist/workspace/revision-skills.js +3 -4
  327. package/dist/workspace/run-workspace.d.ts +1 -1
  328. package/dist/workspace/run-workspace.js +5 -0
  329. package/dist/workspace/synced-folder.d.ts +85 -0
  330. package/dist/workspace/synced-folder.js +230 -0
  331. package/dist/workspace/workspace.d.ts +4 -0
  332. package/launcher/agentrun-serve +1 -1
  333. package/package.json +10 -9
  334. package/templates/README.md +7 -7
  335. package/templates/inbound-lead/agent.md +3 -3
  336. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  337. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  338. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  339. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  340. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  341. package/templates/inbound-lead/lead.schema.json +6 -5
  342. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  343. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  344. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  345. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  346. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  347. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  348. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  349. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  350. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  351. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  352. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  353. package/dist/console/assets/index-Bz6IWncl.js +0 -711
  354. package/dist/learn/grade.d.ts +0 -138
  355. package/dist/learn/grade.js +0 -682
  356. package/dist/learn/notes.d.ts +0 -81
  357. package/dist/learn/notes.js +0 -178
  358. package/dist/learn/reflect.d.ts +0 -77
  359. package/dist/learn/reflect.js +0 -228
  360. package/dist/learn/relevance.d.ts +0 -24
  361. package/dist/learn/relevance.js +0 -91
  362. package/dist/learn/seed-check.d.ts +0 -74
  363. package/dist/learn/seed-check.js +0 -103
  364. package/dist/learning-batch.d.ts +0 -291
  365. package/dist/learning-batch.js +0 -600
  366. package/dist/learning-evals.d.ts +0 -33
  367. package/dist/learning-evals.js +0 -98
  368. package/dist/native/context.d.ts +0 -6
  369. package/dist/native/context.js +0 -22
  370. package/dist/propose.d.ts +0 -52
  371. package/dist/propose.js +0 -224
  372. package/dist/runner/learning-ask.d.ts +0 -47
  373. package/dist/runner/learning-ask.js +0 -128
  374. package/dist/runner/learning-dispatch.d.ts +0 -45
  375. package/dist/runner/learning-dispatch.js +0 -99
  376. package/dist/runner/learning-factory.d.ts +0 -16
  377. package/dist/runner/learning-factory.js +0 -50
  378. package/dist/runner/learning-loop.d.ts +0 -273
  379. package/dist/runner/learning-loop.js +0 -521
  380. package/dist/usage.d.ts +0 -11
  381. package/dist/usage.js +0 -11
  382. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  383. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  384. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  385. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  386. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  387. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  388. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -1,49 +1,31 @@
1
- import type { LearningFolder } from "../learn/folder.js";
2
1
  import { type LearnedWorkflow, type Seed, type Shown } from "../learning.js";
3
- import type { Workspace } from "../workspace/index.js";
2
+ import type { LearningFolder } from "../learn/folder.js";
3
+ /** What a claim reads its seed with: the commit, the agent's learning folder where the run's place keeps it (opened for
4
+ * the read and ended after it), the server's secrets as cuts (`shown`), its log, and `workflows: false` for a run that
5
+ * takes none (an SDK run with no workflow binding). */
4
6
  export interface LearningSeedLay {
5
- /** The run's Workspace: its work, where `.learning/` and `.agents/skills/` are. */
6
- readonly work: Workspace;
7
- /** The commit the run's learning start pinned (null: the folder had no main yet, an empty seed). */
8
7
  readonly seed: string | null;
9
- /** The agent's learning folder where the run's place keeps it, opened for this one read and ended after it. */
10
8
  readonly folder: () => LearningFolder;
11
- /** The revision's own skill files, by their paths under `.agents/skills/` (laid already): a learned skill named like
12
- * one of them is the revision's and is not laid. */
13
- readonly own: readonly string[];
14
- /** The server's secrets as a reader cuts them, read at the claim. */
15
9
  readonly shown: () => Promise<Shown>;
16
- /** One line of the run's log. */
17
10
  readonly log: (line: string) => void;
18
- /** False for a run of a revision that says `learning: "notes"`: its notes and skills are laid, never a learned workflow. */
19
11
  readonly workflows?: false;
20
- /** The notes its # Learned section names in no way, over the learning budget (the launch's `notesLeftOut`), by file:
21
- * said in the run's log, so a run that read only some of what its agent learned says which it did not. */
22
- readonly notesLeftOut?: readonly string[];
23
12
  }
24
- /** The most notes the log line names: past it, it says how many more. */
25
- export declare const LEFT_OUT_NAMED = 100;
26
- /** The run's log line for the notes its # Learned section leaves out, or undefined for none. */
27
- export declare const notesLeftOutLine: (files: readonly string[] | undefined) => string | undefined;
28
- /** What the claim laid of the run's seed: the seed it read, the learned skills' files it laid, by their paths under
29
- * `.agents/skills/`, for the skill list the run's harness is handed beside the revision's own, and the learned workflows
30
- * the run's learned_workflow tool runs, cut of the server's secrets as the skills are (none of either when the lay
31
- * failed part way and was taken back). */
13
+ /** What a claim read of a run's seed: the seed, and the learned workflows the run's learned_workflow tool runs. */
32
14
  export type LaidSeed = {
33
15
  readonly seed: Seed;
34
- readonly skills: readonly string[];
35
16
  readonly workflows: readonly LearnedWorkflow[];
36
17
  };
37
- /** What a claim laid of a run's learning seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
38
- * skill whose files it laid, and each learned workflow it handed the tool; none when nothing was laid. */
18
+ /** What a claim handed a run of its seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
19
+ * workflow it handed the tool; none when nothing was read. */
39
20
  export declare const laidOf: (laid: LaidSeed | undefined) => {
40
- skills: string[];
41
21
  workflows: string[];
42
22
  };
43
- /** Lays the run's learning seed (see the file's head). Undefined when the seed could not be read: nothing was laid.
44
- * Never throws. */
23
+ /** The run's seed and its learned workflows. Undefined when the seed could not be read: the run starts with none. A
24
+ * secrets read (or a choice) that fails after the seed was read answers the seed with no learned workflow. Never
25
+ * throws: a learning fault never stops a run. */
45
26
  export declare function layLearningSeed(lay: LearningSeedLay): Promise<LaidSeed | undefined>;
46
- /** The learned workflows the folder held active at `commit`, as a claim's lay hands them to the learned_workflow tool
47
- * (chooseWorkflows: within the budget, none holding a secret): what a champion serves from while a newer revision of it
48
- * is on main (runner/promotion.ts). Throws when the folder cannot answer or the commit is gone. */
49
- export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown">, commit: string): Promise<LearnedWorkflow[]>;
27
+ /** The learned workflows the folder held active at `commit`, as a claim's read hands them to the learned_workflow tool
28
+ * (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
29
+ * what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
30
+ * commit is gone. */
31
+ export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown">, commit: string | null): Promise<LearnedWorkflow[]>;
@@ -1,71 +1,50 @@
1
- import { chooseSkills, chooseWorkflows, layLearned, LEARNED_DIR, laySkills, readerOf, seedFrom, takeSkills } from "../learning.js";
2
- /** The most notes the log line names: past it, it says how many more. */
3
- export const LEFT_OUT_NAMED = 100;
4
- /** The run's log line for the notes its # Learned section leaves out, or undefined for none. */
5
- export const notesLeftOutLine = (files) => {
6
- if (!files?.length)
7
- return undefined;
8
- const named = files.slice(0, LEFT_OUT_NAMED).join(", ");
9
- const more = files.length > LEFT_OUT_NAMED ? `, and ${files.length - LEFT_OUT_NAMED} more` : "";
10
- return `starts without ${files.length} of the notes its agent learned in its # Learned section, over the learning budget (the notes that bear most on it are given whole; the rest stay in ${LEARNED_DIR}/): ${named}${more}`;
11
- };
1
+ // A claim's read of a run's learning seed: the learned workflows its learning folder held active at the commit the run
2
+ // started from, which the run's learned_workflow tool runs and workflow-first serves (learning.ts chooseWorkflows: within
3
+ // the tool's budget, none holding a host secret). Nothing is laid in the run's work: its corrections reach it in its
4
+ // instructions (learning.ts laidLearned, from the launch's learning start).
5
+ import { chooseWorkflows, seedAt } from "../learning.js";
6
+ /** What a claim handed a run of its seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
7
+ * workflow it handed the tool; none when nothing was read. */
8
+ export const laidOf = (laid) => ({ workflows: (laid?.workflows ?? []).map(({ name }) => name) });
12
9
  const message = (error) => (error instanceof Error ? error.message : String(error));
13
- /** What a claim laid of a run's learning seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
14
- * skill whose files it laid, and each learned workflow it handed the tool; none when nothing was laid. */
15
- export const laidOf = (laid) => ({
16
- skills: [...new Set((laid?.skills ?? []).map((path) => path.split("/")[0]))],
17
- workflows: (laid?.workflows ?? []).map(({ name }) => name),
18
- });
19
- /** Lays the run's learning seed (see the file's head). Undefined when the seed could not be read: nothing was laid.
20
- * Never throws. */
10
+ /** The run's seed and its learned workflows. Undefined when the seed could not be read: the run starts with none. A
11
+ * secrets read (or a choice) that fails after the seed was read answers the seed with no learned workflow. Never
12
+ * throws: a learning fault never stops a run. */
21
13
  export async function layLearningSeed(lay) {
22
14
  let seed;
23
15
  const folder = lay.folder();
24
16
  try {
25
- seed = await seedFrom(lay.seed, readerOf(folder.workspace), { warn: lay.log });
17
+ seed = await seedAt(folder.workspace, lay.seed);
26
18
  }
27
19
  catch (error) {
28
- lay.log(`the run starts with nothing learned laid in its work: ${message(error)}`);
20
+ lay.log(`the run starts with no learned workflow: ${message(error)}`);
29
21
  return undefined;
30
22
  }
31
23
  finally {
32
24
  await folder.end().catch(() => undefined);
33
25
  }
34
- const made = [];
26
+ if (lay.workflows === false)
27
+ return { seed, workflows: [] };
35
28
  try {
36
- const shown = await lay.shown();
37
- await layLearned(lay.work, seed, shown);
38
- const { taken, left } = await chooseSkills(lay.work, seed, lay.own, shown);
39
- await laySkills(lay.work, taken, made);
40
- for (const path of seed.skipped)
41
- lay.log(`its learning folder's ${path} was not read`);
42
- const leftOut = notesLeftOutLine(lay.notesLeftOut);
43
- if (leftOut)
44
- lay.log(leftOut);
29
+ const { flows, left } = chooseWorkflows(seed, await lay.shown());
45
30
  for (const name of left)
46
- lay.log(`starts without the skill ${name} its agent learned: it is over what is left of the learned skills' budget, or holds a secret`);
47
- const workflows = lay.workflows === false ? { flows: [], left: [] } : chooseWorkflows(seed, shown);
48
- for (const name of workflows.left)
49
31
  lay.log(`starts without the learned workflow ${name} its agent learned: it is over what is left of the learned workflows' budget, or holds a secret`);
50
- return { seed, skills: taken.flatMap(({ name, files = {} }) => Object.keys(files).sort().map((path) => `${name}/${path}`)), workflows: workflows.flows };
32
+ return { seed, workflows: flows };
51
33
  }
52
34
  catch (error) {
53
- // Nothing half laid: the notes' copy and every learned skill laid so far go, as pinSeed takes them back. The seed was
54
- // read all the same, and is answered with no skills and no learned workflows.
55
- await lay.work.remove(LEARNED_DIR, { recursive: true, force: true }).catch(() => undefined);
56
- await takeSkills(lay.work, made).catch(() => undefined);
57
- lay.log(`the run starts with nothing learned laid in its work: ${message(error)}`);
58
- return { seed, skills: [], workflows: [] };
35
+ lay.log(`the run starts with no learned workflow: ${message(error)}`);
36
+ return { seed, workflows: [] };
59
37
  }
60
38
  }
61
- /** The learned workflows the folder held active at `commit`, as a claim's lay hands them to the learned_workflow tool
62
- * (chooseWorkflows: within the budget, none holding a secret): what a champion serves from while a newer revision of it
63
- * is on main (runner/promotion.ts). Throws when the folder cannot answer or the commit is gone. */
39
+ /** The learned workflows the folder held active at `commit`, as a claim's read hands them to the learned_workflow tool
40
+ * (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
41
+ * what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
42
+ * commit is gone. */
64
43
  export async function workflowsAt(read, commit) {
65
44
  const folder = read.folder();
66
45
  let seed;
67
46
  try {
68
- seed = await seedFrom(commit, readerOf(folder.workspace));
47
+ seed = await seedAt(folder.workspace, commit);
69
48
  }
70
49
  finally {
71
50
  await folder.end().catch(() => undefined);
@@ -4,6 +4,12 @@ export type { AlsoRow, Claim, Command, Journal };
4
4
  /** Why a run ends failed when the answer it would end on was cut at the model's output limit (stopReason "length"): the
5
5
  * answer is unfinished, so the run never reads ended. `tokens`: what the cut answer used, when its harness says. */
6
6
  export declare const cutAtLimit: (tokens?: number) => string;
7
+ /** Why a run ends failed when the answer it would end on was cut at the output its cap limited it to (a CLI's turn_end
8
+ * capCut): the cap stopped it, not the model, so the words name the cap and the least cap that lets it finish. */
9
+ export declare const cutByCap: (cut: {
10
+ capUsd: number;
11
+ raiseToUsd: number;
12
+ }, tokens?: number) => string;
7
13
  /** What the step keeps with its end-of-run turn as the turn is first asked (EndOfRunTurn ask's `keep`): written with the
8
14
  * turn's prompt, durable before the turn's first request leaves. */
9
15
  export type EndOfRunKept = Readonly<Record<string, string | number | boolean | null>>;
@@ -24,9 +30,8 @@ export type EndOfRunAnswer = ({
24
30
  };
25
31
  /**
26
32
  * The end-of-run step (the learning lane's end-of-run turn): asked once, after the job's last turn ended and before the
27
- * loop writes the run's end. `ask` sends one more turn through the run's own session, its origin `reflect`: while it
28
- * runs the loop refuses its writes and edits under work/.learning/ (REFLECT_NOTE_ONLY), and it is aborted at
29
- * `deadlineMs`. The rows it returns are staged into the end commit, so they land in that commit's one transaction or not
33
+ * loop writes the run's end. `ask` sends one more turn through the run's own session (the compile turn's attempts),
34
+ * its origin `reflect`, aborted at `deadlineMs`. The rows it returns are staged into the end commit, so they land in that commit's one transaction or not
30
35
  * at all. A stop or a lost claim aborts `signal`: no end is written, and the next claim asks again (the turn's request
31
36
  * id is one per run, so its model is asked once).
32
37
  */
@@ -1,10 +1,14 @@
1
1
  // The contract between a runner and the loop that runs one claimed run (design: "Runners carry many loops"). The runner
2
2
  // claims, renews, delivers command rows and releases; the loop runs the harness on the run's journal. B2's loop.ts
3
3
  // implements `Loop` for pi and the CLI adapters; the runner knows nothing about harnesses.
4
+ import { money } from "@parcha/agentrun-kernel/kernel/cap";
4
5
  import { refusedText } from "../refusal-words.js";
5
6
  /** Why a run ends failed when the answer it would end on was cut at the model's output limit (stopReason "length"): the
6
7
  * answer is unfinished, so the run never reads ended. `tokens`: what the cut answer used, when its harness says. */
7
8
  export const cutAtLimit = (tokens) => `the model stopped at its output limit${tokens !== undefined && Number.isSafeInteger(tokens) && tokens > 0 ? ` (${tokens} tokens)` : ""} before finishing its answer`;
9
+ /** Why a run ends failed when the answer it would end on was cut at the output its cap limited it to (a CLI's turn_end
10
+ * capCut): the cap stopped it, not the model, so the words name the cap and the least cap that lets it finish. */
11
+ export const cutByCap = (cut, tokens) => `the run's ${money(cut.capUsd)} cap stopped the model${tokens !== undefined && Number.isSafeInteger(tokens) && tokens > 0 ? ` at ${tokens} tokens` : ""} before it finished its answer: raise the cap to at least $${cut.raiseToUsd.toFixed(2)} to let it finish`;
8
12
  /** A claim its spec builder refuses before anything of the run runs (a handed sign-in that won't read back, an MCP pin
9
13
  * that can't be made): the loop ends the run failed in these words, with nothing sent. Its message names no secret. */
10
14
  export class ClaimRefused extends Error {
@@ -1,6 +1,6 @@
1
1
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
2
2
  import { KINDS } from "./journal-kinds.js";
3
- import { cutAtLimit } from "./loop-contract.js";
3
+ import { cutAtLimit, cutByCap } from "./loop-contract.js";
4
4
  import { PI_STOP } from "./pi-stop.js";
5
5
  /** pi's own default restart limit (pi-durable 1.5.0 agent settings). */
6
6
  export const DEFAULT_RESTART_LIMIT = 5;
@@ -193,7 +193,11 @@ export function cutLast(entries) {
193
193
  const last = [...entries].reverse().find((entry) => entry.kind === "pi.assistant" || (entry.kind === KINDS.message && entry.data?.role === "model"));
194
194
  if (last?.kind === KINDS.message) {
195
195
  const said = last.data;
196
- return said.stopReason === "length" ? cutAtLimit(said.outputTokens) : undefined;
196
+ if (said.stopReason !== "length")
197
+ return undefined;
198
+ // Cut at the output the run's cap limited it to: the cap's cut, named with the cap that lets it finish.
199
+ const { capUsd, raiseToUsd } = said.capCut ?? {};
200
+ return typeof capUsd === "number" && Number.isFinite(capUsd) && typeof raiseToUsd === "number" && Number.isFinite(raiseToUsd) ? cutByCap({ capUsd, raiseToUsd }, said.outputTokens) : cutAtLimit(said.outputTokens);
197
201
  }
198
202
  const message = last?.model?.[0];
199
203
  return message?.stopReason === PI_STOP.length ? cutAtLimit(message.usage?.output) : undefined;
@@ -1,7 +1,9 @@
1
+ import { type HostedDial } from "@parcha/agentrun-computer";
1
2
  import { type Store } from "../store/index.js";
2
3
  import { type KeyEnv } from "../key-meta.js";
3
4
  import { type ComputerDeps, type ComputerDepsOptions } from "../workspace/computer-deps.js";
4
5
  import type { LoopFactory } from "./loop-contract.js";
6
+ import { type RunIsolation } from "./run-child-host.js";
5
7
  import { type Runner, type RunnerEvent, type RunnerMemory } from "./runner.js";
6
8
  export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
7
9
  export interface RunnerProcessOptions {
@@ -14,10 +16,14 @@ export interface RunnerProcessOptions {
14
16
  /** Its memory budget and its runs' weights (RunnerOptions.memory). Default: this host's memory, each run weighed by its
15
17
  * harness (memory-claim.ts runnerMemory). */
16
18
  memory?: RunnerMemory;
19
+ /** With the default memory: what each run's own process weighs beside its harness's run (memory-claim.ts
20
+ * RUN_PROCESS_MIB), for a runner whose runs are each a process of their own. Default 0. */
21
+ processMib?: number;
17
22
  /** This runner's name in the runs it claims, its lines and its heartbeat. Default runner.ts runnerName(). */
18
23
  name?: string;
19
- /** Each claimed run's loop; default the runner's dispatch over the store (runnerLoop), with the computers it composed. */
20
- createLoop?: LoopFactory | ((store: Store, sealKey: Buffer) => LoopFactory | RunnerParts);
24
+ /** Each claimed run's loop; default the runner's dispatch over the store (runnerLoop), with the computers it composed.
25
+ * A factory of the store is given the runner's dial too, where it has a relay (dial-relay.ts). */
26
+ createLoop?: LoopFactory | ((store: Store, sealKey: Buffer, dial?: HostedDial) => LoopFactory | RunnerParts);
21
27
  /** Run the computer janitor (workspace/computer-janitor.ts) over the computers createLoop composed: at the start, then
22
28
  * on its interval. Only the runner subcommand asks for it; a test that does not ask runs none. */
23
29
  janitor?: boolean;
@@ -83,7 +89,7 @@ export declare function besideRunEnv(env: NodeJS.ProcessEnv, switches: NodeJS.Pr
83
89
  * its launch (harness-loops.ts resolveRunnerLoop), with the data directory, the run environment (runEnv), the store's
84
90
  * journal, the seal key and the model route. `booted`: the seal key startRunnerProcess booted against the store (else
85
91
  * this process's, as it was handed or booted). Refused in words with no seal key. */
86
- export declare function runnerLoop(store: Store, dataDir: string, env?: NodeJS.ProcessEnv, booted?: Buffer): RunnerParts;
92
+ export declare function runnerLoop(store: Store, dataDir: string, env?: NodeJS.ProcessEnv, booted?: Buffer, isolation?: RunIsolation, dial?: HostedDial): RunnerParts;
87
93
  /** What a runner in its own process may reach on loopback, from its own environment alone, as a server takes its opt-in
88
94
  * (cli.ts mcpLoopback): with AGENTRUN_MCP_ALLOW_LOOPBACK=1, an MCP server on this machine's loopback (the machine this
89
95
  * process runs on, its container's in a container), never at `own`: the port a server listens on unless --port says
@@ -116,8 +122,8 @@ export declare function checkRunner(options: {
116
122
  };
117
123
  /** Opens the store as a runner and starts claiming runs. */
118
124
  export declare function startRunnerProcess(options: RunnerProcessOptions): Promise<RunnerProcess>;
119
- /** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens). */
120
- export declare function ofStore<Made extends LoopFactory | RunnerParts>(make: (store: Store, sealKey: Buffer) => Made): (store: Store, sealKey: Buffer) => Made;
125
+ /** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens, and its relay's dial). */
126
+ export declare function ofStore<Made extends LoopFactory | RunnerParts>(make: (store: Store, sealKey: Buffer, dial?: HostedDial) => Made): (store: Store, sealKey: Buffer, dial?: HostedDial) => Made;
121
127
  /** How long a runner process lets each busy run finish its turn on SIGTERM, unless --drain-timeout or
122
128
  * AGENTRUN_DRAIN_TIMEOUT says: the image's server drain (its CMD's --drain-timeout 6s), so a runner beside a --no-runner
123
129
  * server drains as the server's own runner would.
@@ -138,17 +144,20 @@ export declare function runnerHolds(args: {
138
144
  loops: number;
139
145
  drainMs: number;
140
146
  };
141
- /** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M]`, or `--check --data D
142
- * [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts
143
- * with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the faux model module, a
144
- * test switch, as the server's own --faux; the only way a runner loads one. */
147
+ /** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]]`, or
148
+ * `--check --data D [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data
149
+ * directory that starts with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the
150
+ * faux model module, a test switch, as the server's own --faux; the only way a runner loads one. `--faux-browser`: the
151
+ * fake browser's module, with --faux only, as the server's. */
145
152
  export declare function runnerArgs(argv: readonly string[]): {
146
153
  dataDir: string;
147
154
  loops?: number;
148
155
  drainMs?: number;
149
156
  name?: string;
150
157
  faux?: string;
158
+ fauxBrowser?: string;
151
159
  check?: true;
160
+ harnessModules?: string[];
152
161
  };
153
162
  /** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
154
163
  * says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
@@ -13,13 +13,14 @@
13
13
  import { mkdirSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
14
14
  import { join, resolve } from "node:path";
15
15
  import { PROVIDERS } from "@parcha/agentrun-computer";
16
+ import { startRunnerRelay } from "../dial-relay.js";
16
17
  import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
17
18
  import { ArchilSettingsEnvInvalid, archilSettingsFromEnv } from "../archil-settings.js";
18
19
  import { dockerPathsForRuns } from "../box-paths.js";
19
20
  import { hostCommandRefusals } from "../computers.js";
20
21
  import { hostAddressesOnce } from "../docker-host-addresses.js";
21
22
  import { claimInstallsStopped } from "../harness-install.js";
22
- import { HARNESS_TABLE_ENV } from "../harness-table.js";
23
+ import { HARNESS_MODULES_ENV, HARNESS_TABLE_ENV, harnessModulesEnv, harnessModulesOf, harnessTable } from "../harness-table.js";
23
24
  import { DEFAULT_PORT, maxRunsOf } from "../host.js";
24
25
  import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
25
26
  import { durationMs, runLine } from "../print.js";
@@ -28,6 +29,7 @@ import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
28
29
  import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget } from "../store/index.js";
29
30
  import { SCHEMA_VERSION } from "../store/schema.js";
30
31
  import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
32
+ import { FAUX_BROWSER_ENV } from "../tools.js";
31
33
  import { claimViewOpener } from "../computer-live.js";
32
34
  import { LOOPBACK as LIVE_LOOPBACK, runnerLiveOf } from "../live-reach.js";
33
35
  import { LOOPBACK } from "../mcp-oauth.js";
@@ -41,7 +43,8 @@ import { runEndComputers } from "../workspace/run-end-computers.js";
41
43
  import { createDispatchLoop } from "./dispatch.js";
42
44
  import { resolveRunnerLoop } from "./harness-loops.js";
43
45
  import { routeOf } from "./model-route.js";
44
- import { runnerMemory } from "./memory-claim.js";
46
+ import { RUN_PROCESS_MIB, runnerMemory } from "./memory-claim.js";
47
+ import { childLoops, isolationLoops, RunIsolationRefused, runIsolationOf } from "./run-child-host.js";
45
48
  import { sweepEndedScratch } from "./scratch-sweep.js";
46
49
  import { RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
47
50
  export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
@@ -111,7 +114,7 @@ computerDepsFrom({ env, store, sealKey, openComputerView: claimViewOpener(runner
111
114
  export function besideRunEnv(env, switches) {
112
115
  const out = runEnv(env);
113
116
  for (const name of Object.keys(out))
114
- if (name.startsWith(FAUX_PREFIX) || name === HARNESS_TABLE_ENV)
117
+ if (name.startsWith(FAUX_PREFIX) || name === HARNESS_TABLE_ENV || name === HARNESS_MODULES_ENV)
115
118
  delete out[name];
116
119
  return Object.assign(out, switches);
117
120
  }
@@ -119,7 +122,7 @@ export function besideRunEnv(env, switches) {
119
122
  * its launch (harness-loops.ts resolveRunnerLoop), with the data directory, the run environment (runEnv), the store's
120
123
  * journal, the seal key and the model route. `booted`: the seal key startRunnerProcess booted against the store (else
121
124
  * this process's, as it was handed or booted). Refused in words with no seal key. */
122
- export function runnerLoop(store, dataDir, env = process.env, booted) {
125
+ export function runnerLoop(store, dataDir, env = process.env, booted, isolation, dial) {
123
126
  const sealKey = booted ?? sealKeyOf(secret(SEAL_KEY_ENV) ?? env[SEAL_KEY_ENV]);
124
127
  if (!sealKey)
125
128
  throw new RunnerRefused(`A runner needs the server's seal key (${SEAL_KEY_ENV}): start it through the server's launcher, which hands it over.`);
@@ -127,8 +130,9 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
127
130
  // The run's computer at its claim, composed once (runnerComputers): none for the runner's place, a box's computer by the
128
131
  // agent's setting, its keys read from the run environment first, then the store's sealed rows; a Docker computer's
129
132
  // mounts by where this process's Docker has the data directory (box-paths.ts), read once; a desktop's or a phone's live
130
- // view opened with it.
131
- const computers = runnerComputers(store, runs, sealKey, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
133
+ // view opened with it. A machine that dials goes to this runner's own hub, through the server's relay (`dial`, its
134
+ // relay's: dial-relay.ts); with none, its provider refuses.
135
+ const computers = runnerComputers(store, runs, sealKey, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH), ...(dial ? { dial } : {}) });
132
136
  const loopback = runnerLoopback(env);
133
137
  if (loopback)
134
138
  process.stderr.write(`agentrun-serve runner: ${MCP_ALLOW_LOOPBACK_ENV}=1: this runner's runs may reach an MCP server on this machine's loopback, never at ${loopback.own.join(" or ")} nor where its server listens\n`);
@@ -143,7 +147,10 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
143
147
  // The server's own addresses, as it kept them in the store at its last start, are read at each claim beside these.
144
148
  ...(loopback ? { mcpLoopback: true, mcpOwn: loopback.own, mcpOwnOf: () => serverOwn(store) } : {}),
145
149
  };
146
- return { createLoop: createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) }), computers: computers.computerDeps, env: runs };
150
+ // `isolation`: each run a process of its own (run-child-host.ts), as the runner subcommand runs them; none, in this one
151
+ // (a test's runner).
152
+ const createLoop = isolation ? childLoops({ deps, isolation, log: deps.log }) : createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) });
153
+ return { createLoop, computers: computers.computerDeps, env: runs };
147
154
  }
148
155
  /** What a runner in its own process may reach on loopback, from its own environment alone, as a server takes its opt-in
149
156
  * (cli.ts mcpLoopback): with AGENTRUN_MCP_ALLOW_LOOPBACK=1, an MCP server on this machine's loopback (the machine this
@@ -179,7 +186,7 @@ function heartbeat(dataDir, name, now) {
179
186
  }
180
187
  catch {
181
188
  mkdirSync(dataDir, { recursive: true });
182
- writeFileSync(file, `${name}\n`);
189
+ writeFileSync(file, `${name}\n`, { mode: 0o600 });
183
190
  utimesSync(file, seconds, seconds);
184
191
  }
185
192
  };
@@ -205,10 +212,11 @@ export async function startRunnerProcess(options) {
205
212
  const warn = options.warn ?? ((message) => void process.stderr.write(`agentrun-serve runner: ${message}\n`));
206
213
  const env = options.env ?? process.env;
207
214
  const { store, kind, schema } = await openRunnerStore(options.dataDir, env, warn, options.storeUrl);
208
- const memory = options.memory ?? runnerMemory(store);
215
+ const memory = options.memory ?? runnerMemory(store, undefined, env, options.processMib ?? 0);
209
216
  let runner;
210
217
  let seal;
211
218
  let janitor;
219
+ let relay;
212
220
  try {
213
221
  // The server's seal key, booted the one way the server boots it (seal-key.ts): the one handed over, else the one in
214
222
  // this data directory, checked against what the store records. A runner on a store whose secrets another key sealed
@@ -216,9 +224,12 @@ export async function startRunnerProcess(options) {
216
224
  // or records a key.
217
225
  seal = await bootSealKey(store, options.dataDir, { given: handedSecret(SEAL_KEY_ENV) ?? env[SEAL_KEY_ENV], role: "runner" });
218
226
  const name = options.name ?? runnerName();
219
- const made = options.createLoop ?? ofStore((opened, sealKey) => runnerLoop(opened, options.dataDir, undefined, sealKey));
227
+ // Its relay (dial-relay.ts), where its environment names the server's public address: a machine that dials the
228
+ // server lands in this runner's hub, through the server. Its log lines are the runner's warnings.
229
+ relay = await startRunnerRelay({ store, sealKey: seal.key, runner: name, env, log: warn });
230
+ const made = options.createLoop ?? ofStore((opened, sealKey, dial) => runnerLoop(opened, options.dataDir, undefined, sealKey, undefined, dial));
220
231
  // A factory of the store (marked by ofStore) is given the store; a loop factory is used as is.
221
- const parts = isStoreFactory(made) ? made(store, seal.key) : made;
232
+ const parts = isStoreFactory(made) ? made(store, seal.key, relay?.dial) : made;
222
233
  const createLoop = typeof parts === "function" ? parts : parts.createLoop;
223
234
  // The janitor sweeps with the computers the loop composed, never a second composition. Its lines are the runner's
224
235
  // warnings, said where the runner says its others (warn: stderr unless a test gives its own).
@@ -242,12 +253,14 @@ export async function startRunnerProcess(options) {
242
253
  }
243
254
  catch (error) {
244
255
  await janitor?.close();
256
+ await relay?.close();
245
257
  seal?.release();
246
258
  await store.close();
247
259
  throw error;
248
260
  }
249
261
  let closing;
250
262
  const held = seal;
263
+ const relayed = relay;
251
264
  return {
252
265
  runner,
253
266
  store: { kind, schema },
@@ -255,6 +268,8 @@ export async function startRunnerProcess(options) {
255
268
  close: () => (closing ??= (async () => {
256
269
  // The janitor's sweep is cut and waited for on its own bound, beside the runner's close, never before it.
257
270
  await Promise.all([janitor?.close(), runner.close()]);
271
+ // Its relay after its runs: a run's release revokes its machine's token through it.
272
+ await relayed?.close();
258
273
  // A first-use install its claims started, stopped as they let go: its npm ends before this process can.
259
274
  await claimInstallsStopped();
260
275
  await store.close();
@@ -263,7 +278,7 @@ export async function startRunnerProcess(options) {
263
278
  };
264
279
  }
265
280
  const storeFactories = new WeakSet();
266
- /** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens). */
281
+ /** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens, and its relay's dial). */
267
282
  export function ofStore(make) {
268
283
  storeFactories.add(make);
269
284
  return make;
@@ -309,20 +324,23 @@ export function runnerHolds(args, env) {
309
324
  }
310
325
  return { loops, drainMs };
311
326
  }
312
- /** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M]`, or `--check --data D
313
- * [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts
314
- * with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the faux model module, a
315
- * test switch, as the server's own --faux; the only way a runner loads one. */
327
+ /** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]]`, or
328
+ * `--check --data D [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data
329
+ * directory that starts with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the
330
+ * faux model module, a test switch, as the server's own --faux; the only way a runner loads one. `--faux-browser`: the
331
+ * fake browser's module, with --faux only, as the server's. */
316
332
  export function runnerArgs(argv) {
317
333
  let dataDir;
318
334
  let loops;
319
335
  let drainMs;
320
336
  let name;
321
337
  let faux;
338
+ let fauxBrowser;
322
339
  let check = false;
340
+ const harnessModules = [];
323
341
  for (let i = 0; i < argv.length; i++) {
324
342
  const given = argv[i];
325
- const equals = /^(--(?:data|loops|drain-timeout|name|faux))=(.*)$/s.exec(given);
343
+ const equals = /^(--(?:data|loops|drain-timeout|name|faux|faux-browser|harness-module))=(.*)$/s.exec(given);
326
344
  const arg = equals ? equals[1] : given;
327
345
  const value = () => {
328
346
  const next = equals ? equals[2] : argv[++i];
@@ -348,14 +366,20 @@ export function runnerArgs(argv) {
348
366
  name = value();
349
367
  else if (arg === "--faux")
350
368
  faux = value();
369
+ else if (arg === "--faux-browser")
370
+ fauxBrowser = value();
371
+ else if (arg === "--harness-module")
372
+ harnessModules.push(value());
351
373
  else if (arg === "--check")
352
374
  check = true;
353
375
  else
354
- throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M], or --check --data D [--name N]`);
376
+ throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]] [--harness-module M ...], or --check --data D [--name N]`);
355
377
  }
356
378
  if (!dataDir)
357
379
  throw new RunnerRefused("a runner needs its data directory: --data D");
358
- return { dataDir, ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(check ? { check: true } : {}) };
380
+ if (fauxBrowser !== undefined && faux === undefined)
381
+ throw new RunnerRefused("--faux-browser goes with --faux");
382
+ return { dataDir, ...(harnessModules.length ? { harnessModules } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(fauxBrowser === undefined ? {} : { fauxBrowser }), ...(check ? { check: true } : {}) };
359
383
  }
360
384
  /** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
361
385
  * says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
@@ -422,8 +446,22 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
422
446
  }
423
447
  // A test switch is this start's option alone, as on the server (server.ts withoutFaux, fauxEnvOf): one the process
424
448
  // inherited (AGENTRUN_SERVE_FAUX*, the harness table, left in an operator's shell or a platform's settings) never loads
425
- // a module or decides what a run answers. --faux sets the faux model's.
426
- const env = { ...withoutFaux(given), ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}) };
449
+ // a module or decides what a run answers. --faux sets the faux model's, --faux-browser the fake browser's.
450
+ // The owner's harness modules are this start's too: --harness-module, else AGENTRUN_SERVE_HARNESS_MODULES, as the
451
+ // server reads them, so a runner apart from the server runs the harnesses its table adds. Each is loaded and checked
452
+ // here, as the server's start checks them (harness-table.ts harnessTable), before the runner opens the store or claims a
453
+ // run: a module that names a built-in, repeats an id, gives an id the API does not carry or lacks a member refuses the
454
+ // start in words naming the module and the id, never failing every run the runner would claim.
455
+ let modules;
456
+ try {
457
+ modules = harnessModulesEnv(harnessModulesOf(args.harnessModules, given), args.dataDir);
458
+ harnessTable(modules);
459
+ }
460
+ catch (error) {
461
+ console.error(`agentrun-serve runner: ${error.message}`);
462
+ return 2;
463
+ }
464
+ const env = { ...withoutFaux(given), ...modules, ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}), ...(args.fauxBrowser ? { [FAUX_BROWSER_ENV]: resolve(args.fauxBrowser) } : {}) };
427
465
  const name = args.name ?? env.AGENTRUN_RUNNER_NAME ?? undefined;
428
466
  if (args.check) {
429
467
  if (!name) {
@@ -452,6 +490,24 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
452
490
  console.error(`agentrun-serve runner: ${error.message}`);
453
491
  return 2;
454
492
  }
493
+ // Each run a process of its own, as a user of its own where the image's helper can switch: a helper that cannot is
494
+ // refused here in words that name the setting (run-child-host.ts runIsolationOf), before any run is claimed. The slots
495
+ // the helper reaches bound the runs held at once: a number it was told (--loops, AGENTRUN_MAX_RUNS) past them is
496
+ // refused, and its memory's count is cut to them, said on its log.
497
+ let isolation;
498
+ const told = args.loops !== undefined || Boolean(env.AGENTRUN_MAX_RUNS);
499
+ try {
500
+ isolation = await runIsolationOf(env, told ? holds.loops : undefined, (line) => void console.error(`agentrun-serve runner: ${line}`));
501
+ }
502
+ catch (error) {
503
+ if (!(error instanceof RunIsolationRefused))
504
+ throw error;
505
+ console.error(`agentrun-serve runner: ${error.message}`);
506
+ return 2;
507
+ }
508
+ if (isolation.kind === "uid" && holds.loops > isolation.slots)
509
+ console.error(`agentrun-serve runner: each run runs as a user of its own, and the helper reaches ${isolation.slots} slots from slot ${isolation.first}: this runner holds at most ${isolation.slots} runs at once`);
510
+ holds = { ...holds, loops: isolationLoops(isolation, holds.loops) };
455
511
  let started;
456
512
  const runnerOf = name ?? runnerName();
457
513
  // The last resort, in this process only (never the library, the server's CLI or the runner beside a server): an error
@@ -478,7 +534,11 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
478
534
  env,
479
535
  loops: holds.loops,
480
536
  drainMs: holds.drainMs,
481
- createLoop: ofStore((store, sealKey) => runnerLoop(store, args.dataDir, env, sealKey)),
537
+ // Each run a process of its own (`isolation`); its computer, with this runner's relay's dial, held here in the
538
+ // runner, which the run's process asks for it over its channel (run-child-host.ts, held.ts computer).
539
+ createLoop: ofStore((store, sealKey, dial) => runnerLoop(store, args.dataDir, env, sealKey, isolation, dial)),
540
+ // Each run's own process weighed beside its harness's run (memory-claim.ts RUN_PROCESS_MIB).
541
+ processMib: RUN_PROCESS_MIB,
482
542
  // The runner subcommand ends what a crashed runner of this server left (never under --faux).
483
543
  janitor: true,
484
544
  onEvent: (event) => {
@@ -6,6 +6,7 @@ import type { Store, TriggerSettings } from "../store/index.js";
6
6
  import { type ApprovalPrice, type ToolEffect } from "../tool-gate.js";
7
7
  import type { Claim } from "./loop-contract.js";
8
8
  import type { GithubAppAccess, GithubTimer } from "./mcp-github.js";
9
+ import { type HeldMcp } from "./held.js";
9
10
  /** The GitHub App access for a claim (runner/github-app.ts githubAppAccess, tl-triggers'): the server's App, read from
10
11
  * the store with the runner's seal key, bound to the repository the run's launch input names. */
11
12
  export type GithubAppAccessOf = (store: {
@@ -89,3 +90,13 @@ export declare function catalogSessionNames(catalog: Pick<ClaimMcp, "tools" | "c
89
90
  * claim lost while a refresh was awaited: the loop ends interrupted). A builder calls it before it takes anything it
90
91
  * would have to let go, since a throw here leaves its spec unbuilt and its release uncalled. */
91
92
  export declare function mcpForClaim(options: McpForClaimOptions): Promise<ClaimMcp | undefined>;
93
+ /** A claim's MCP as the runner hands it to the run's own process (held.ts HeldMcp): what the gate reads of each tool,
94
+ * read now, and each call made here, its answer and its error cut by `cut` (the runner's redactor) before they cross. */
95
+ export declare function heldMcpOf(mcp: ClaimMcp, cut: (text: string) => string): HeldMcp;
96
+ /** The claim's MCP in the run's own process (run-child.ts), from what its runner holds (heldMcpOf). */
97
+ export declare function claimMcpOfHeld(held: HeldMcp): ClaimMcp;
98
+ /** The claim's MCP where the run is: mcpForClaim with the runner's seal key, else its runner's (held.ts), the gateway's
99
+ * record of each call appended to the run's root through this process's own harness. */
100
+ export declare function mcpWhereHeld(options: Omit<McpForClaimOptions, "sealKey"> & {
101
+ readonly sealKey: Buffer | undefined;
102
+ }): Promise<ClaimMcp | undefined>;