@parcha/agentrun-serve 0.1.0-beta.44 → 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 (346) hide show
  1. package/CHANGELOG.md +131 -5
  2. package/README.md +371 -300
  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 +52 -16
  28. package/dist/composio-preset.js +69 -7
  29. package/dist/composio-triggers.d.ts +14 -0
  30. package/dist/composio-triggers.js +79 -15
  31. package/dist/computer-attach.d.ts +40 -5
  32. package/dist/computer-attach.js +130 -15
  33. package/dist/computer-keys.d.ts +3 -0
  34. package/dist/computer-keys.js +7 -1
  35. package/dist/computer-live.js +3 -2
  36. package/dist/computers.d.ts +21 -10
  37. package/dist/computers.js +39 -28
  38. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  39. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/decisions.d.ts +1 -1
  42. package/dist/dial-relay.d.ts +29 -0
  43. package/dist/dial-relay.js +94 -0
  44. package/dist/email/tools.js +10 -5
  45. package/dist/env-proxy.d.ts +2 -0
  46. package/dist/env-proxy.js +35 -0
  47. package/dist/errors.d.ts +3 -1
  48. package/dist/errors.js +7 -4
  49. package/dist/faux-computers.d.ts +8 -2
  50. package/dist/faux-computers.js +83 -6
  51. package/dist/harness-archive.d.ts +67 -0
  52. package/dist/harness-archive.js +177 -0
  53. package/dist/harness-goose.d.ts +34 -0
  54. package/dist/harness-goose.js +87 -0
  55. package/dist/harness-install.d.ts +21 -0
  56. package/dist/harness-install.js +24 -11
  57. package/dist/harness-opencode/adapter.js +1 -1
  58. package/dist/harness-table.d.ts +9 -1
  59. package/dist/harness-table.js +20 -3
  60. package/dist/harness.d.ts +1 -2
  61. package/dist/harness.js +3 -4
  62. package/dist/host.js +2 -1
  63. package/dist/key-check.js +3 -0
  64. package/dist/learn/audit.d.ts +6 -6
  65. package/dist/learn/audit.js +3 -7
  66. package/dist/learn/check.d.ts +23 -89
  67. package/dist/learn/check.js +57 -335
  68. package/dist/learn/commit.d.ts +63 -90
  69. package/dist/learn/commit.js +124 -316
  70. package/dist/learn/compile.d.ts +53 -50
  71. package/dist/learn/compile.js +87 -102
  72. package/dist/learn/corrections.d.ts +13 -0
  73. package/dist/learn/corrections.js +23 -0
  74. package/dist/learn/delete.d.ts +5 -5
  75. package/dist/learn/delete.js +8 -10
  76. package/dist/learn/folder.d.ts +35 -47
  77. package/dist/learn/folder.js +118 -134
  78. package/dist/learn/index.d.ts +3 -5
  79. package/dist/learn/index.js +6 -9
  80. package/dist/learn/learning.sh +45 -15
  81. package/dist/learn/promote.d.ts +13 -1
  82. package/dist/learn/promote.js +9 -0
  83. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
  84. package/dist/learn/{skills.js → workflow-draft.js} +48 -58
  85. package/dist/learn/workflow-nodes.js +1 -1
  86. package/dist/learned-workflow.js +2 -2
  87. package/dist/learning-cost.d.ts +38 -24
  88. package/dist/learning-cost.js +41 -24
  89. package/dist/learning-routes.d.ts +91 -170
  90. package/dist/learning-routes.js +183 -421
  91. package/dist/learning-run.d.ts +19 -40
  92. package/dist/learning-run.js +23 -93
  93. package/dist/learning-setting.d.ts +4 -4
  94. package/dist/learning-setting.js +6 -6
  95. package/dist/learning-words.d.ts +28 -74
  96. package/dist/learning-words.js +64 -162
  97. package/dist/learning.d.ts +61 -392
  98. package/dist/learning.js +101 -651
  99. package/dist/live-reach.d.ts +25 -2
  100. package/dist/live-reach.js +46 -4
  101. package/dist/llms.txt +1 -1
  102. package/dist/local-models.d.ts +3 -11
  103. package/dist/local-models.js +5 -6
  104. package/dist/mcp-servers-store.d.ts +4 -4
  105. package/dist/model-form.js +6 -5
  106. package/dist/model.d.ts +4 -0
  107. package/dist/model.js +26 -9
  108. package/dist/native/binding.js +1 -1
  109. package/dist/native/connection.js +1 -1
  110. package/dist/native/discovery.js +1 -1
  111. package/dist/native/instructions.d.ts +3 -0
  112. package/dist/native/instructions.js +5 -3
  113. package/dist/native/remote-worker-bridge.js +9 -43
  114. package/dist/native/remote.d.ts +8 -15
  115. package/dist/native/remote.js +3 -3
  116. package/dist/native/schema.js +1 -1
  117. package/dist/native/types.d.ts +2 -2
  118. package/dist/openapi.js +268 -316
  119. package/dist/paid-calls.d.ts +8 -0
  120. package/dist/paid-calls.js +20 -0
  121. package/dist/particle-provider.d.ts +11 -0
  122. package/dist/particle-provider.js +135 -0
  123. package/dist/port-models.d.ts +12 -4
  124. package/dist/port-models.js +28 -11
  125. package/dist/print.d.ts +27 -0
  126. package/dist/print.js +21 -0
  127. package/dist/provider.d.ts +7 -0
  128. package/dist/provider.js +15 -1
  129. package/dist/reflect-range.js +2 -3
  130. package/dist/run-launch.d.ts +14 -28
  131. package/dist/run-launch.js +9 -12
  132. package/dist/run-learning-served.d.ts +15 -89
  133. package/dist/run-listing.d.ts +34 -0
  134. package/dist/run-listing.js +128 -0
  135. package/dist/run-model-key.js +1 -1
  136. package/dist/run-timeline-served.js +5 -3
  137. package/dist/run-trace.d.ts +97 -0
  138. package/dist/run-trace.js +253 -0
  139. package/dist/run-view.d.ts +15 -0
  140. package/dist/run-view.js +9 -0
  141. package/dist/runnable.js +2 -1
  142. package/dist/runner/adapter-loop.d.ts +8 -6
  143. package/dist/runner/adapter-loop.js +16 -12
  144. package/dist/runner/adapter-run-spec.d.ts +16 -4
  145. package/dist/runner/adapter-run-spec.js +64 -58
  146. package/dist/runner/adapters/index.js +22 -0
  147. package/dist/runner/adapters/pi.d.ts +4 -12
  148. package/dist/runner/adapters/pi.js +2 -2
  149. package/dist/runner/audit.d.ts +1 -1
  150. package/dist/runner/audit.js +16 -8
  151. package/dist/runner/beside.d.ts +6 -2
  152. package/dist/runner/beside.js +38 -9
  153. package/dist/runner/claim-secrets.d.ts +18 -2
  154. package/dist/runner/claim-secrets.js +42 -18
  155. package/dist/runner/cli-run-spec.js +55 -51
  156. package/dist/runner/conformance/harness.d.ts +6 -0
  157. package/dist/runner/conformance/harness.js +16 -5
  158. package/dist/runner/dispatch.d.ts +2 -2
  159. package/dist/runner/end-of-run.d.ts +6 -14
  160. package/dist/runner/end-of-run.js +8 -33
  161. package/dist/runner/feedback-round.d.ts +2 -2
  162. package/dist/runner/feedback-round.js +7 -7
  163. package/dist/runner/github-app.js +3 -1
  164. package/dist/runner/harness-loops.d.ts +0 -8
  165. package/dist/runner/harness-loops.js +11 -59
  166. package/dist/runner/held.d.ts +170 -0
  167. package/dist/runner/held.js +57 -0
  168. package/dist/runner/journal-kinds.d.ts +2 -3
  169. package/dist/runner/journal-kinds.js +2 -3
  170. package/dist/runner/learned-first.d.ts +40 -0
  171. package/dist/runner/learned-first.js +32 -0
  172. package/dist/runner/learning-end.d.ts +77 -69
  173. package/dist/runner/learning-end.js +250 -303
  174. package/dist/runner/learning-seed.d.ts +15 -33
  175. package/dist/runner/learning-seed.js +24 -45
  176. package/dist/runner/loop-contract.d.ts +2 -3
  177. package/dist/runner/main.d.ts +17 -9
  178. package/dist/runner/main.js +63 -20
  179. package/dist/runner/mcp-run.d.ts +11 -0
  180. package/dist/runner/mcp-run.js +67 -0
  181. package/dist/runner/memory-claim.d.ts +10 -5
  182. package/dist/runner/memory-claim.js +12 -6
  183. package/dist/runner/model-route.d.ts +7 -4
  184. package/dist/runner/model-route.js +22 -10
  185. package/dist/runner/native-loop.d.ts +0 -7
  186. package/dist/runner/native-loop.js +9 -101
  187. package/dist/runner/promotion.d.ts +8 -6
  188. package/dist/runner/promotion.js +19 -12
  189. package/dist/runner/reflect-hook.d.ts +64 -95
  190. package/dist/runner/reflect-hook.js +112 -225
  191. package/dist/runner/run-channel.d.ts +43 -0
  192. package/dist/runner/run-channel.js +467 -0
  193. package/dist/runner/run-child-host.d.ts +169 -0
  194. package/dist/runner/run-child-host.js +1222 -0
  195. package/dist/runner/run-child.d.ts +1 -0
  196. package/dist/runner/run-child.js +254 -0
  197. package/dist/runner/run-errors.d.ts +2 -0
  198. package/dist/runner/run-errors.js +20 -0
  199. package/dist/runner/runner.js +1 -5
  200. package/dist/runner/sdk-ask.d.ts +78 -0
  201. package/dist/runner/sdk-ask.js +158 -0
  202. package/dist/runner/sdk-loop.d.ts +2 -4
  203. package/dist/runner/sdk-loop.js +29 -49
  204. package/dist/runner/store-secrets.d.ts +5 -3
  205. package/dist/runner/store-secrets.js +5 -1
  206. package/dist/runner/workflow-first.d.ts +5 -0
  207. package/dist/runner/workflow-first.js +4 -0
  208. package/dist/runner/workflow-spec.js +7 -2
  209. package/dist/runs-over-store.d.ts +16 -28
  210. package/dist/runs-over-store.js +31 -38
  211. package/dist/sdk/runs.d.ts +6 -11
  212. package/dist/sdk/runs.js +20 -41
  213. package/dist/sdk/schema.js +3 -4
  214. package/dist/seal-key.d.ts +5 -0
  215. package/dist/seal-key.js +7 -0
  216. package/dist/secrets.d.ts +3 -0
  217. package/dist/secrets.js +16 -3
  218. package/dist/server.d.ts +55 -33
  219. package/dist/server.js +685 -320
  220. package/dist/sign-ins-store.d.ts +8 -0
  221. package/dist/sign-ins-store.js +36 -1
  222. package/dist/skills.js +1 -1
  223. package/dist/store/index.d.ts +2 -2
  224. package/dist/store/index.js +1 -1
  225. package/dist/store/journal/storage.js +3 -0
  226. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  227. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  228. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  229. package/dist/store/schema.d.ts +53 -4
  230. package/dist/store/schema.js +137 -6
  231. package/dist/store/sqlite/connection.d.ts +2 -0
  232. package/dist/store/sqlite/connection.js +3 -1
  233. package/dist/store/sqlite/run-patch.d.ts +0 -17
  234. package/dist/store/sqlite/run-patch.js +4 -33
  235. package/dist/store/sqlite/store.js +246 -63
  236. package/dist/store/sqlite/worker.js +25 -0
  237. package/dist/store/store.d.ts +193 -36
  238. package/dist/store/store.js +25 -3
  239. package/dist/store-reads/learning.d.ts +102 -204
  240. package/dist/store-reads/learning.js +159 -321
  241. package/dist/store-reads/loop.d.ts +0 -1
  242. package/dist/store-reads/loop.js +1 -1
  243. package/dist/store-view.d.ts +29 -1
  244. package/dist/store-view.js +97 -31
  245. package/dist/template-eval.d.ts +3 -6
  246. package/dist/template-eval.js +22 -36
  247. package/dist/templates.d.ts +2 -1
  248. package/dist/templates.js +6 -3
  249. package/dist/timeline/index.d.ts +1 -1
  250. package/dist/timeline/index.js +1 -1
  251. package/dist/timeline/timeline.d.ts +5 -1
  252. package/dist/timeline/timeline.js +16 -0
  253. package/dist/tool-gate.d.ts +0 -7
  254. package/dist/tool-gate.js +1 -15
  255. package/dist/tool-keys-store.d.ts +1 -1
  256. package/dist/tool-keys.d.ts +6 -4
  257. package/dist/tool-keys.js +12 -6
  258. package/dist/tools.d.ts +2 -2
  259. package/dist/tools.js +11 -4
  260. package/dist/triggers.d.ts +60 -5
  261. package/dist/triggers.js +123 -18
  262. package/dist/validate.js +1 -1
  263. package/dist/webhooks.d.ts +4 -1
  264. package/dist/webhooks.js +11 -4
  265. package/dist/workspace/agent-computer.d.ts +2 -0
  266. package/dist/workspace/agent-computer.js +2 -0
  267. package/dist/workspace/archil-claim.d.ts +7 -0
  268. package/dist/workspace/archil-claim.js +29 -0
  269. package/dist/workspace/archil.d.ts +9 -1
  270. package/dist/workspace/archil.js +165 -3
  271. package/dist/workspace/attach.d.ts +3 -1
  272. package/dist/workspace/attach.js +2 -0
  273. package/dist/workspace/attached-computers.d.ts +16 -5
  274. package/dist/workspace/attached-computers.js +25 -9
  275. package/dist/workspace/computer-deps.js +1 -1
  276. package/dist/workspace/computer-for-claim.d.ts +7 -3
  277. package/dist/workspace/computer-for-claim.js +119 -22
  278. package/dist/workspace/computer-hold.js +2 -1
  279. package/dist/workspace/computer-kept.d.ts +11 -1
  280. package/dist/workspace/computer-kept.js +24 -3
  281. package/dist/workspace/resolve-computer.d.ts +33 -19
  282. package/dist/workspace/resolve-computer.js +172 -64
  283. package/dist/workspace/revision-skills.d.ts +1 -2
  284. package/dist/workspace/revision-skills.js +3 -4
  285. package/dist/workspace/run-workspace.d.ts +1 -1
  286. package/dist/workspace/run-workspace.js +5 -0
  287. package/dist/workspace/synced-folder.d.ts +85 -0
  288. package/dist/workspace/synced-folder.js +230 -0
  289. package/dist/workspace/workspace.d.ts +4 -0
  290. package/launcher/agentrun-serve +1 -1
  291. package/package.json +10 -10
  292. package/templates/README.md +7 -7
  293. package/templates/inbound-lead/agent.md +3 -3
  294. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  295. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  296. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  297. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  298. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  299. package/templates/inbound-lead/lead.schema.json +6 -5
  300. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  301. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  302. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  303. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  304. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  305. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  306. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  307. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  308. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  309. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  310. package/dist/console/assets/index-BUktRvS-.css +0 -1
  311. package/dist/console/assets/index-nB9kTfIN.js +0 -711
  312. package/dist/learn/grade.d.ts +0 -138
  313. package/dist/learn/grade.js +0 -682
  314. package/dist/learn/notes.d.ts +0 -81
  315. package/dist/learn/notes.js +0 -178
  316. package/dist/learn/reflect.d.ts +0 -77
  317. package/dist/learn/reflect.js +0 -228
  318. package/dist/learn/relevance.d.ts +0 -24
  319. package/dist/learn/relevance.js +0 -91
  320. package/dist/learn/seed-check.d.ts +0 -74
  321. package/dist/learn/seed-check.js +0 -103
  322. package/dist/learning-batch.d.ts +0 -291
  323. package/dist/learning-batch.js +0 -600
  324. package/dist/learning-evals.d.ts +0 -35
  325. package/dist/learning-evals.js +0 -99
  326. package/dist/native/context.d.ts +0 -6
  327. package/dist/native/context.js +0 -22
  328. package/dist/propose.d.ts +0 -52
  329. package/dist/propose.js +0 -224
  330. package/dist/runner/learning-ask.d.ts +0 -47
  331. package/dist/runner/learning-ask.js +0 -128
  332. package/dist/runner/learning-dispatch.d.ts +0 -45
  333. package/dist/runner/learning-dispatch.js +0 -99
  334. package/dist/runner/learning-factory.d.ts +0 -16
  335. package/dist/runner/learning-factory.js +0 -50
  336. package/dist/runner/learning-loop.d.ts +0 -273
  337. package/dist/runner/learning-loop.js +0 -521
  338. package/dist/usage.d.ts +0 -11
  339. package/dist/usage.js +0 -11
  340. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  341. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  342. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  343. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  344. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  345. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  346. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -0,0 +1,467 @@
1
+ // The channel between a runner and a run's own process (run-child.ts): one inherited Unix socket, frames of a 4-byte
2
+ // length and a V8-serialized message, at most MAX_FRAME bytes each. Either side calls the other: a call names a target
3
+ // (a name the other side exposed, or a handle it was given) and a method, and is answered with a value or an error.
4
+ //
5
+ // What crosses is data, with three exceptions, each passed by reference as a handle the receiver calls back through:
6
+ // a function, an object with methods (a computer, a Workspace), and an AbortSignal (its abort is posted across). The
7
+ // sender keeps what it handed until the receiver's stand-in of it is collected (a release is then posted) or the
8
+ // channel ends, so a long run's callbacks do not pile up on either side. An
9
+ // error crosses as its name, message, code and own fields, made again on the other side as an instance of the class of
10
+ // that name when ERRORS lists it, so `instanceof Fenced` holds across the channel.
11
+ //
12
+ // The runner's side treats every frame as untrusted: the run's process runs code nodes and extensions. A frame over the
13
+ // cap, one that does not deserialize, or one that is not a message is the end of the channel (onClose), and the runner
14
+ // fails the run. A call to a target nobody exposed, or to a method a handle's object does not have, is refused. What a
15
+ // target lets a call do is the target's own business (run-child-host.ts binds each to the claim).
16
+ import { deserialize, serialize } from "node:v8";
17
+ /** The most a frame may hold, in bytes: a journal commit of a long turn fits many times over. */
18
+ export const MAX_FRAME = 32 * 1024 * 1024;
19
+ /** The channel ended: its socket closed, or a frame broke the protocol. Every call in flight fails with it. */
20
+ export class ChannelClosed extends Error {
21
+ name = "ChannelClosed";
22
+ }
23
+ /** A call the other side refused before running it: no such target or method. */
24
+ export class ChannelRefused extends Error {
25
+ name = "ChannelRefused";
26
+ }
27
+ /** The error classes made again by name on the receiving side, so instanceof holds across the channel. Each side
28
+ * registers the ones it may receive (registerErrors). */
29
+ const ERRORS = new Map();
30
+ export function registerErrors(classes) {
31
+ for (const [name, type] of Object.entries(classes))
32
+ ERRORS.set(name, type);
33
+ }
34
+ const TAG = "\u0000agentrun-rpc";
35
+ /** A post that aborts the stand-in of the sender's signal. */
36
+ const ABORT = "\u0000abort";
37
+ /** A post that tells the sender its handle's stand-in was let go of: it lets go of what it handed under it. */
38
+ const RELEASE = "\u0000release";
39
+ const isPlain = (value) => {
40
+ const proto = Object.getPrototypeOf(value);
41
+ return proto === Object.prototype || proto === null;
42
+ };
43
+ /** The names of `value`'s methods: its own and its prototypes', up to Object's, never the constructor. */
44
+ function methodsOf(value) {
45
+ const names = new Set();
46
+ for (let at = value; at && at !== Object.prototype && at !== Function.prototype; at = Object.getPrototypeOf(at)) {
47
+ for (const name of Object.getOwnPropertyNames(at)) {
48
+ if (name === "constructor")
49
+ continue;
50
+ const descriptor = Object.getOwnPropertyDescriptor(at, name);
51
+ if (descriptor && typeof descriptor.value === "function")
52
+ names.add(name);
53
+ }
54
+ }
55
+ return [...names];
56
+ }
57
+ /** Sets `key` as `target`'s own property, even "__proto__": a decoded key never reaches a setter or a prototype. */
58
+ const own = (target, key, value) => {
59
+ Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
60
+ };
61
+ /** Whether `value` holds a function anywhere (itself, or a member): it then crosses as a handle. */
62
+ const hasMethods = (value) => methodsOf(value).length > 0;
63
+ /** One side of the channel over `socket`. */
64
+ export class Channel {
65
+ #socket;
66
+ #maxFrame;
67
+ #onClose;
68
+ #context;
69
+ #within;
70
+ #next = 1;
71
+ #pending = new Map();
72
+ /** What this side handed the other by reference: functions and objects with methods, each kept until the other side
73
+ * lets go of its stand-in (RELEASE) or the channel ends. */
74
+ #handles = new Map();
75
+ /** This side's signals the other side holds a stand-in of: the listener that posts each one's abort, removed when the
76
+ * other side lets go of it. */
77
+ #handedSignals = new Map();
78
+ /** The stand-ins of the other side's signals, by its handle: each aborted here when it aborts there. Held weakly, so a
79
+ * stand-in nobody here holds any more is let go of (and the other side told). */
80
+ #signals = new Map();
81
+ /** Each stand-in signal's controller, alive as long as the signal is. */
82
+ #controllers = new WeakMap();
83
+ /** Tells the other side, once a stand-in of its handle is collected here, that it may let go of what it handed. */
84
+ #released = new FinalizationRegistry((h) => {
85
+ this.#signals.delete(h);
86
+ this.post(h, RELEASE, []);
87
+ });
88
+ #targets = new Map();
89
+ #buffer = Buffer.alloc(0);
90
+ #closed;
91
+ constructor(socket, options = {}) {
92
+ this.#socket = socket;
93
+ this.#maxFrame = options.maxFrame ?? MAX_FRAME;
94
+ this.#onClose = options.onClose;
95
+ this.#context = options.context;
96
+ this.#within = options.within;
97
+ socket.on("data", (chunk) => this.#read(chunk));
98
+ socket.on("error", (error) => this.close(new ChannelClosed(`the channel's socket failed: ${error.message}`)));
99
+ socket.on("close", () => this.close(new ChannelClosed("the channel's socket closed")));
100
+ }
101
+ get closed() {
102
+ return this.#closed !== undefined;
103
+ }
104
+ /** How many functions, objects and signals this side has handed the other and still keeps for it. */
105
+ get handed() {
106
+ return this.#handles.size + this.#handedSignals.size;
107
+ }
108
+ /** Answers calls to `name` with `dispatch`. */
109
+ expose(name, dispatch) {
110
+ this.#targets.set(name, dispatch);
111
+ }
112
+ /** Calls `method` of target `to` with `args`: its answer, or its error. */
113
+ call(to, method, args) {
114
+ if (this.#closed)
115
+ return Promise.reject(this.#closed);
116
+ const id = this.#next++;
117
+ return new Promise((resolve, reject) => {
118
+ this.#pending.set(id, { resolve, reject });
119
+ const carried = this.#context?.();
120
+ this.#send({ t: "call", id, to, m: method, a: args.map((arg) => this.#encode(arg)), ...(carried !== undefined ? { c: this.#encode(carried) } : {}) });
121
+ });
122
+ }
123
+ /** Sends `method` of target `to` with `args`, with no answer. In order with every call. */
124
+ post(to, method, args) {
125
+ if (this.#closed)
126
+ return;
127
+ this.#send({ t: "post", to, m: method, a: args.map((arg) => this.#encode(arg)) });
128
+ }
129
+ /** A stand-in for target `name`: `stub.a.b(...args)` calls method "a.b" of it. `props`: values read without a call. */
130
+ remote(name, props = {}) {
131
+ const channel = this;
132
+ const at = (path) => new Proxy(function () { }, {
133
+ get(_target, key) {
134
+ if (typeof key === "symbol")
135
+ return undefined;
136
+ const next = path ? `${path}.${key}` : key;
137
+ if (Object.hasOwn(props, next))
138
+ return props[next];
139
+ // A promise-like check (await stub) must not read a method named "then".
140
+ if (key === "then")
141
+ return undefined;
142
+ return at(next);
143
+ },
144
+ apply(_target, _this, args) {
145
+ return channel.call(name, path, args);
146
+ },
147
+ });
148
+ return at("");
149
+ }
150
+ /** Ends the channel: every call in flight fails with `why`, and the socket is destroyed. */
151
+ close(why = new ChannelClosed("the channel was closed")) {
152
+ if (this.#closed)
153
+ return;
154
+ this.#closed = why;
155
+ for (const { reject } of this.#pending.values())
156
+ reject(why);
157
+ this.#pending.clear();
158
+ for (const ref of this.#signals.values()) {
159
+ const signal = ref.deref();
160
+ if (signal)
161
+ this.#controllers.get(signal)?.abort(why);
162
+ }
163
+ this.#signals.clear();
164
+ this.#handles.clear();
165
+ for (const { signal, listener } of this.#handedSignals.values())
166
+ signal.removeEventListener("abort", listener);
167
+ this.#handedSignals.clear();
168
+ this.#socket.destroy();
169
+ this.#onClose?.(why);
170
+ }
171
+ #send(message) {
172
+ let body;
173
+ try {
174
+ body = serialize(message);
175
+ }
176
+ catch (error) {
177
+ // A value that cannot cross (a class V8 cannot clone): the call fails, never the channel.
178
+ if (message.t === "call") {
179
+ const pending = this.#pending.get(message.id);
180
+ this.#pending.delete(message.id);
181
+ pending?.reject(new TypeError(`a value of ${String(message.m)} cannot cross to the other process: ${error.message}`));
182
+ return;
183
+ }
184
+ if (message.t === "ok")
185
+ return this.#send({ t: "err", id: message.id, e: this.#encode(new TypeError(`an answer cannot cross to the other process: ${error.message}`)) });
186
+ return;
187
+ }
188
+ if (body.length > this.#maxFrame) {
189
+ if (message.t === "call") {
190
+ const pending = this.#pending.get(message.id);
191
+ this.#pending.delete(message.id);
192
+ pending?.reject(new RangeError(`a call of ${message.m} is ${body.length} bytes, past the channel's ${this.#maxFrame}`));
193
+ return;
194
+ }
195
+ if (message.t === "ok")
196
+ return this.#send({ t: "err", id: message.id, e: this.#encode(new RangeError(`an answer of ${body.length} bytes is past the channel's ${this.#maxFrame}`)) });
197
+ return;
198
+ }
199
+ const head = Buffer.alloc(4);
200
+ head.writeUInt32BE(body.length);
201
+ this.#socket.write(Buffer.concat([head, body]));
202
+ }
203
+ #read(chunk) {
204
+ if (this.#closed)
205
+ return;
206
+ this.#buffer = this.#buffer.length ? Buffer.concat([this.#buffer, chunk]) : chunk;
207
+ while (this.#buffer.length >= 4) {
208
+ const length = this.#buffer.readUInt32BE(0);
209
+ if (length > this.#maxFrame)
210
+ return this.close(new ChannelClosed(`a frame of ${length} bytes is past the channel's ${this.#maxFrame}`));
211
+ if (this.#buffer.length < 4 + length)
212
+ return;
213
+ const body = this.#buffer.subarray(4, 4 + length);
214
+ this.#buffer = this.#buffer.subarray(4 + length);
215
+ let message;
216
+ try {
217
+ message = deserialize(body);
218
+ }
219
+ catch (error) {
220
+ return this.close(new ChannelClosed(`a frame did not read: ${error.message}`));
221
+ }
222
+ if (!this.#isMessage(message))
223
+ return this.close(new ChannelClosed("a frame is not a message of the channel"));
224
+ this.#handle(message);
225
+ }
226
+ }
227
+ #isMessage(value) {
228
+ if (!value || typeof value !== "object")
229
+ return false;
230
+ const message = value;
231
+ const id = () => Number.isSafeInteger(message.id);
232
+ const target = () => (typeof message.to === "string" || Number.isSafeInteger(message.to)) && typeof message.m === "string" && Array.isArray(message.a);
233
+ if (message.t === "call")
234
+ return id() && target();
235
+ if (message.t === "post")
236
+ return target();
237
+ if (message.t === "ok" || message.t === "err")
238
+ return id();
239
+ return false;
240
+ }
241
+ #handle(message) {
242
+ if (message.t === "ok" || message.t === "err") {
243
+ const pending = this.#pending.get(message.id);
244
+ if (!pending)
245
+ return;
246
+ this.#pending.delete(message.id);
247
+ let decoded;
248
+ try {
249
+ decoded = this.#decode(message.t === "ok" ? message.v : message.e);
250
+ }
251
+ catch (error) {
252
+ return pending.reject(error);
253
+ }
254
+ if (message.t === "ok")
255
+ pending.resolve(decoded);
256
+ else
257
+ pending.reject(decoded);
258
+ return;
259
+ }
260
+ if (message.t === "post" && message.m === ABORT && typeof message.to === "number") {
261
+ const signal = this.#signals.get(message.to)?.deref();
262
+ this.#signals.delete(message.to);
263
+ if (signal)
264
+ this.#controllers.get(signal)?.abort(this.#decodeSafe(message.a[0]));
265
+ return;
266
+ }
267
+ if (message.t === "post" && message.m === RELEASE && typeof message.to === "number") {
268
+ // The other side let go of its stand-in: what this side handed under that handle goes too.
269
+ this.#handles.delete(message.to);
270
+ const handed = this.#handedSignals.get(message.to);
271
+ if (handed)
272
+ handed.signal.removeEventListener("abort", handed.listener);
273
+ this.#handedSignals.delete(message.to);
274
+ return;
275
+ }
276
+ const run = async () => {
277
+ const args = message.a.map((arg) => this.#decode(arg));
278
+ // Decoded either way, so what it handed is released once collected here.
279
+ const carried = message.t === "call" && message.c !== undefined ? this.#decode(message.c) : undefined;
280
+ if (carried === undefined || !this.#within)
281
+ return this.#dispatch(message.to, message.m, args);
282
+ return this.#within(carried, () => this.#dispatch(message.to, message.m, args));
283
+ };
284
+ const answered = run();
285
+ if (message.t === "call") {
286
+ answered.then((value) => this.#closed || this.#send({ t: "ok", id: message.id, v: this.#encode(value) }), (error) => this.#closed || this.#send({ t: "err", id: message.id, e: this.#encode(error instanceof Error ? error : new Error(String(error))) }));
287
+ }
288
+ else
289
+ answered.catch(() => { });
290
+ }
291
+ #decodeSafe(value) {
292
+ try {
293
+ return this.#decode(value);
294
+ }
295
+ catch {
296
+ return undefined;
297
+ }
298
+ }
299
+ #dispatch(to, method, args) {
300
+ if (typeof to === "string") {
301
+ const target = this.#targets.get(to);
302
+ if (!target)
303
+ throw new ChannelRefused(`no target ${JSON.stringify(to)} on this side of the channel`);
304
+ return target(method, args);
305
+ }
306
+ const handle = this.#handles.get(to);
307
+ if (handle === undefined)
308
+ throw new ChannelRefused(`no handle ${to} on this side of the channel`);
309
+ if (typeof handle === "function") {
310
+ if (method !== "")
311
+ throw new ChannelRefused(`handle ${to} is a function`);
312
+ return handle(...args);
313
+ }
314
+ const object = handle;
315
+ if (!object.methods.has(method))
316
+ throw new ChannelRefused(`handle ${to} has no method ${JSON.stringify(method)}`);
317
+ return object.value[method](...args);
318
+ }
319
+ #hand(value) {
320
+ const h = this.#next++;
321
+ this.#handles.set(h, value);
322
+ return h;
323
+ }
324
+ #encode(value, seen = new Set()) {
325
+ if (value === null || typeof value !== "object") {
326
+ if (typeof value === "function")
327
+ return { [TAG]: "fn", h: this.#hand(value) };
328
+ if (typeof value === "symbol")
329
+ return undefined;
330
+ return value;
331
+ }
332
+ if (seen.has(value))
333
+ throw new TypeError("a value with a cycle cannot cross to the other process");
334
+ seen.add(value);
335
+ try {
336
+ if (value instanceof Error) {
337
+ const fields = {};
338
+ for (const key of Object.keys(value))
339
+ if (key !== "cause")
340
+ fields[key] = this.#encodeData(value[key]);
341
+ return { [TAG]: "error", name: value.name, message: value.message, ...(value.stack ? { stack: value.stack } : {}), fields };
342
+ }
343
+ if (value instanceof AbortSignal) {
344
+ const h = this.#next++;
345
+ const signal = value;
346
+ if (!signal.aborted) {
347
+ const listener = () => {
348
+ this.#handedSignals.delete(h);
349
+ this.post(h, ABORT, [this.#encodeData(signal.reason)]);
350
+ };
351
+ signal.addEventListener("abort", listener, { once: true });
352
+ this.#handedSignals.set(h, { signal, listener });
353
+ }
354
+ return { [TAG]: "signal", h, aborted: signal.aborted, ...(signal.aborted ? { reason: this.#encodeData(signal.reason) } : {}) };
355
+ }
356
+ if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer || value instanceof Date || value instanceof RegExp)
357
+ return value;
358
+ if (Array.isArray(value))
359
+ return value.map((item) => this.#encode(item, seen));
360
+ if (value instanceof Map)
361
+ return new Map([...value].map(([k, v]) => [this.#encode(k, seen), this.#encode(v, seen)]));
362
+ if (value instanceof Set)
363
+ return new Set([...value].map((v) => this.#encode(v, seen)));
364
+ if (value instanceof Promise)
365
+ throw new TypeError("a promise cannot cross to the other process inside a value");
366
+ const data = {};
367
+ for (const key of Object.keys(value)) {
368
+ const member = value[key];
369
+ if (typeof member === "function" && !isPlain(value))
370
+ continue;
371
+ data[key] = this.#encode(member, seen);
372
+ }
373
+ if (isPlain(value) || !hasMethods(value))
374
+ return data;
375
+ const methods = methodsOf(value);
376
+ return { [TAG]: "obj", h: this.#hand({ value, methods: new Set(methods) }), data, methods };
377
+ }
378
+ finally {
379
+ seen.delete(value);
380
+ }
381
+ }
382
+ /** `value` as data alone: an error's fields and an abort's reason never carry a handle. */
383
+ #encodeData(value) {
384
+ if (value === null || typeof value !== "object")
385
+ return typeof value === "function" || typeof value === "symbol" ? undefined : value;
386
+ if (value instanceof Error)
387
+ return { [TAG]: "error", name: value.name, message: value.message, fields: {} };
388
+ try {
389
+ return deserialize(serialize(value));
390
+ }
391
+ catch {
392
+ return undefined;
393
+ }
394
+ }
395
+ #decode(value) {
396
+ if (value === null || typeof value !== "object")
397
+ return value;
398
+ if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer || value instanceof Date || value instanceof RegExp)
399
+ return value;
400
+ if (Array.isArray(value))
401
+ return value.map((item) => this.#decode(item));
402
+ if (value instanceof Map)
403
+ return new Map([...value].map(([k, v]) => [this.#decode(k), this.#decode(v)]));
404
+ if (value instanceof Set)
405
+ return new Set([...value].map((v) => this.#decode(v)));
406
+ const tagged = value;
407
+ const tag = tagged[TAG];
408
+ if (tag === undefined) {
409
+ const out = {};
410
+ for (const [key, member] of Object.entries(value))
411
+ own(out, key, this.#decode(member));
412
+ return out;
413
+ }
414
+ const h = tagged.h;
415
+ // A handed function's call that nobody awaits (a listener the other side fires and forgets) must not leave an
416
+ // unhandled rejection once the channel closed: the caller that awaits it still gets the error.
417
+ const quiet = (made) => {
418
+ made.catch(() => undefined);
419
+ return made;
420
+ };
421
+ if (tag === "fn" && Number.isSafeInteger(h)) {
422
+ const fn = (...args) => quiet(this.call(h, "", args));
423
+ // Once nothing here holds the stand-in, the other side lets go of the function.
424
+ this.#released.register(fn, h);
425
+ return fn;
426
+ }
427
+ if (tag === "obj" && Number.isSafeInteger(h)) {
428
+ const { data, methods } = tagged;
429
+ if (!data || typeof data !== "object" || !Array.isArray(methods))
430
+ throw new ChannelRefused("a handed object is not one");
431
+ const out = this.#decode(data);
432
+ // One token every method holds: the object is let go of once neither it nor any of its methods is held here.
433
+ const kept = {};
434
+ for (const name of methods)
435
+ if (typeof name === "string")
436
+ own(out, name, (...args) => (void kept, quiet(this.call(h, name, args))));
437
+ this.#released.register(kept, h);
438
+ return out;
439
+ }
440
+ if (tag === "signal" && Number.isSafeInteger(h)) {
441
+ const controller = new AbortController();
442
+ const { aborted, reason } = tagged;
443
+ if (aborted)
444
+ controller.abort(this.#decode(reason));
445
+ else {
446
+ this.#controllers.set(controller.signal, controller);
447
+ this.#signals.set(h, new WeakRef(controller.signal));
448
+ this.#released.register(controller.signal, h);
449
+ }
450
+ return controller.signal;
451
+ }
452
+ if (tag === "error") {
453
+ const { name, message, stack, fields } = tagged;
454
+ const type = typeof name === "string" ? ERRORS.get(name) : undefined;
455
+ const error = (type ? Object.create(type.prototype) : new Error());
456
+ Object.defineProperty(error, "message", { value: String(message ?? ""), writable: true, configurable: true });
457
+ Object.defineProperty(error, "name", { value: typeof name === "string" ? name : "Error", writable: true, configurable: true });
458
+ if (typeof stack === "string")
459
+ Object.defineProperty(error, "stack", { value: stack, writable: true, configurable: true });
460
+ if (fields && typeof fields === "object")
461
+ for (const [key, member] of Object.entries(fields))
462
+ own(error, key, this.#decode(member));
463
+ return error;
464
+ }
465
+ throw new ChannelRefused("a value carries a tag the channel does not know");
466
+ }
467
+ }
@@ -0,0 +1,169 @@
1
+ import { type Stats } from "node:fs";
2
+ import type { Workspace } from "../workspace/workspace.js";
3
+ import { type AdapterSpecDeps } from "./adapter-run-spec.js";
4
+ import type { Held } from "./held.js";
5
+ import { type Claim, type LoopFactory } from "./loop-contract.js";
6
+ import { type RunLaunch } from "../run-launch.js";
7
+ /** The image's helper that starts a run's process as its slot's uid (packages/serve/runas). */
8
+ export declare const RUNAS_HELPER = "/usr/local/bin/agentrun-runas";
9
+ /** `same`: every run runs as the runner's own user, the helper unused, said in the runner's log. */
10
+ export declare const RUN_USER_ENV = "AGENTRUN_RUN_USER";
11
+ /** The first of this runner's slots (0 by default): two runners on one data directory take ranges of their own. */
12
+ export declare const RUN_SLOT_FIRST_ENV = "AGENTRUN_RUN_SLOT_FIRST";
13
+ /** The helper's compiled range: slot s runs as uid and gid FIRST_RUN_ID + s. */
14
+ export declare const FIRST_RUN_ID = 1001;
15
+ export declare const RUN_SLOTS = 256;
16
+ /** How this runner's runs are kept apart: each a process of its own, and with the helper each a uid of its own. */
17
+ export type RunIsolation = {
18
+ readonly kind: "process";
19
+ readonly why: string;
20
+ } | {
21
+ readonly kind: "uid";
22
+ readonly helper: string;
23
+ readonly first: number;
24
+ readonly slots: number;
25
+ };
26
+ /** The isolation this host gives a run, as the capabilities document says it: `uid` with the helper, else `process`. */
27
+ export declare const runIsolationName: (isolation: RunIsolation) => "uid" | "process";
28
+ /** A runner that cannot keep its runs apart as the image promises: said in words that name the setting. */
29
+ export declare class RunIsolationRefused extends Error {
30
+ name: string;
31
+ }
32
+ /** This host's isolation for `loops` runs at once, by `env` and the helper: the helper's own check that it can switch
33
+ * (its effective set holds what it needs) decides `uid`; none installed (a local install), `process`; `same`, `process`
34
+ * said in the log. A helper that cannot switch is refused in words naming the setting, never a quiet fall back. `loops`
35
+ * the runner was told (--loops, AGENTRUN_MAX_RUNS) past the helper's last slot from its first is refused too; none told
36
+ * (a host's memory's count, or no bound), it holds the slots from its first. */
37
+ export declare function runIsolationOf(env: NodeJS.ProcessEnv, loops: number | undefined, log: (line: string) => void, helper?: string): Promise<RunIsolation>;
38
+ /** The runs a runner holds at once, as `uid` isolation lets it: its slots. */
39
+ export declare const isolationLoops: (isolation: RunIsolation, loops: number) => number;
40
+ /** The folder of the data directory where each slot's lock is (`<slot>.lock`, the server's user's alone). */
41
+ export declare const slotLocks: (data: string) => string;
42
+ /** The slots of a uid runner, each held by one run at a time. With `locks` (the data directory's slotLocks), each slot
43
+ * taken is locked there too, so runners on one data directory whose ranges overlap never run two runs on one slot: a
44
+ * slot another runner holds is skipped. */
45
+ export declare class Slots {
46
+ #private;
47
+ constructor(first: number, count: number, locks?: string);
48
+ /** A free slot of this runner no other runner holds; undefined when another holds every free one, or every slot not
49
+ * held is retired. */
50
+ take(): Promise<number | undefined>;
51
+ /** Never gives `slot` back: a slot whose reap did not hold (a process of its uid may still be alive) runs no run of
52
+ * this runner again, and its lock is kept, so no other runner on the data directory takes it either. */
53
+ retire(slot: number): void;
54
+ /** The slots retired (retire). */
55
+ get retired(): readonly number[];
56
+ /** Gives `slot` back, its lock ended first. */
57
+ give(slot: number): Promise<void>;
58
+ }
59
+ /** A slot's uid (and gid). */
60
+ export declare const slotId: (slot: number) => number;
61
+ /** One run's hold on its slot, bound at its spawn: a kill reaps this slot alone, and only while the run holds it. Once
62
+ * settled, no kill starts, and the settle ends only when every kill already reaping has ended, so the slot goes back
63
+ * (and its next run starts) with no reap of this run still killing the slot's uid. */
64
+ export declare class SlotHold {
65
+ #private;
66
+ readonly slot: number;
67
+ constructor(slot: number, helper: string, log: (line: string) => void);
68
+ kill(): Promise<void>;
69
+ settle(): Promise<void>;
70
+ }
71
+ /** The run's own top folders: its folder (work and recordings beneath it) and its scratch folder. */
72
+ export declare const runTops: (data: string, agentId: string, runId: string) => string[];
73
+ /** Every entry under `dir` the server's user owns, given to group `gid` as the helper's reown gives a slot's: a folder
74
+ * the group's to enter and write (2770), a file's owner bits copied to the group, none for others. The whole tree, a
75
+ * symlink never followed nor changed (an lstat's). Run while no process of the slot is alive (after its reap), so
76
+ * nothing it walks is swapped under it. */
77
+ export declare function toSlotGroup(dir: string, gid: number): Promise<void>;
78
+ /** The other slots that own an entry anywhere under `dir`, as the helper's reown walks it: the whole tree, a symlink
79
+ * never followed (an lstat's, never a directory). `statOf`: the stat it reads (a test's). */
80
+ export declare function slotsUnder(dir: string, slot: number, statOf?: (path: string) => Promise<Stats>): Promise<number[]>;
81
+ /** After the run's process ended: every process of the slot's uid killed, its files in the shared temporary folders
82
+ * removed, what it left in its folders readable and removable by the server's group, and its top folders the server's
83
+ * own again (0770), which the slot's next run cannot enter. Whether the reap held: the helper kills until no process of
84
+ * the uid is left, and says so; false when one still is, or the reap could not run (the slot is then never run on
85
+ * again by this runner). */
86
+ export declare function reapSlot(isolation: Extract<RunIsolation, {
87
+ kind: "uid";
88
+ }>, slot: number, tops: readonly string[], log: (line: string) => void): Promise<boolean>;
89
+ /** `value` as data: every function, symbol and class's method left out, so nothing the runner holds is handed by
90
+ * reference to the run's process unless a target hands it on purpose. */
91
+ export declare function dataOnly(value: unknown, seen?: Set<object>): unknown;
92
+ /** Every string inside `value` cut by `cut`: what the run's process writes, as the runner's redactor would cut it in a
93
+ * loop of its own (rule three: no secret the runner holds is written). */
94
+ export declare function cutDeep<T>(value: T, cut: (text: string) => string): T;
95
+ /** What the store target knows of the claim: its run and the run's agent and revision. */
96
+ export interface Bound {
97
+ readonly claim: Claim;
98
+ readonly agentId: string;
99
+ readonly revisionId: string;
100
+ }
101
+ /** Whether a run's process may read setting `key`. */
102
+ export declare const settingReadable: (key: unknown, bound: Bound) => boolean;
103
+ /** The store target: a call of `method` (`a.b`) with `args`, bound to the claim. */
104
+ export declare function storeCall(store: object, method: string, args: unknown[], bound: Bound, log: (line: string) => void): Promise<unknown>;
105
+ /** The claim as the runner read it, for heldFor. */
106
+ interface ClaimReads {
107
+ readonly claim: Claim;
108
+ readonly run: {
109
+ readonly agentId: string;
110
+ readonly revisionId: string;
111
+ readonly signInHanded: readonly string[] | null;
112
+ };
113
+ readonly launch: import("../run-launch.js").RunLaunch;
114
+ readonly revision: {
115
+ readonly kind: string;
116
+ readonly body: Record<string, unknown>;
117
+ };
118
+ readonly claimed: NodeJS.ProcessEnv;
119
+ }
120
+ /** Held (held.ts) for one claim, on the runner: each answer the claim's own, read with the runner's seal key from the
121
+ * runner's own reads of the claim; every argument from the run's process is checked or ignored. */
122
+ export declare function heldFor(deps: AdapterSpecDeps & {
123
+ readonly sealKey: Buffer;
124
+ }, reads: ClaimReads, cut: (text: string) => string, log: (line: string) => void): {
125
+ held: Held;
126
+ inputs(): Promise<void>;
127
+ release(): Promise<void>;
128
+ };
129
+ /** A call of the learning folder a run's process asks (Held.learning), on the runner's own Workspace of the claim's
130
+ * agent's folder: reads pass, and the learning script runs its reads, with the script's own environment (the script
131
+ * laid by the runner as the folder's own); nothing the process asks writes there. */
132
+ export declare function learningCall(folder: {
133
+ readonly workspace: Workspace;
134
+ end(): Promise<void>;
135
+ }, method: string, args: readonly unknown[]): Promise<unknown>;
136
+ /** What the runner's child loops share: its deps (its seal key), its isolation, its slots, its log. */
137
+ export interface ChildLoopsOptions {
138
+ readonly deps: AdapterSpecDeps & {
139
+ readonly sealKey: Buffer;
140
+ };
141
+ readonly isolation: RunIsolation;
142
+ readonly log: (line: string) => void;
143
+ /** The program a run's process starts with (default this Node and dist/runner/run-child.js under dist/secrets.js). */
144
+ readonly argv?: readonly string[];
145
+ }
146
+ /** The node and module a run's process starts with. */
147
+ export declare const childArgv: () => string[];
148
+ /** Whether a run stays in its runner's process rather than one of its own: one that runs no agent's code or tool here.
149
+ * A built-in learning run (its launch names harness "learning"): its grade is one ask through the runner's model route,
150
+ * and its one write is the merge into the agent's learning folder, which no run's process may write. An SDK backend
151
+ * run (launch.sdk): its agent runs in the caller's application, and its loop here reads the evidence it posts and closes
152
+ * its inbox. A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
153
+ * connectors, whose rows are the server's. */
154
+ export declare const runsInRunner: (harness: string, launch: Pick<RunLaunch, "sdk" | "native">) => boolean;
155
+ /** The words a run on Claude Code's login on this machine is refused in where each run is a user of its own. */
156
+ export declare const LOGIN_NEEDS_SERVER_USER = "A run on Claude Code's login on this machine needs runs under the server's own user, and this runner runs each run as a user of its own: set AGENTRUN_RUN_USER=same, or give the run a model_key.";
157
+ /** Whether run `runId` stays in its runner's process: runsInRunner's, and a workflow run on a server with a documents
158
+ * directory (launch.documents), whose reads and writes (a pdf_pages call's pages) are rooted in a folder the server's
159
+ * user holds and no slot's user is given; its nodes run the server's own tools alone, no agent's code. A run on Claude
160
+ * Code's login on this machine (claude-login.ts loginForRun) needs the login in the server's own folder, which its CLI
161
+ * reads and refreshes: where runs are the runner's own user (`process`) it stays in the runner; where each run is a user
162
+ * of its own (`uid`) it is refused at its claim (ClaimRefused, the run failed in words naming the setting), never run as
163
+ * the server's user. A run its caller handed a model key (model_key) runs on that key and never on the login
164
+ * (cli-run-spec.ts), so it is a process of its own like any other. */
165
+ export declare function staysInRunner(deps: Pick<AdapterSpecDeps, "store" | "data" | "env" | "sealKey">, harness: string, launch: RunLaunch, runId: string, isolation: RunIsolation): Promise<boolean>;
166
+ /** The runner's loop factory where each run is a process of its own: a ChildLoop per claim, but for a run that stays in
167
+ * the runner (staysInRunner). */
168
+ export declare function childLoops(options: ChildLoopsOptions): LoopFactory;
169
+ export {};