@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.34

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 (381) hide show
  1. package/CHANGELOG.md +233 -0
  2. package/README.md +266 -201
  3. package/dist/adapters.d.ts +0 -4
  4. package/dist/adapters.js +11 -15
  5. package/dist/agent-rows.d.ts +98 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +60 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/bash-read-only.d.ts +22 -0
  16. package/dist/bash-read-only.js +701 -0
  17. package/dist/box-settings.d.ts +3 -23
  18. package/dist/box-settings.js +7 -51
  19. package/dist/boxes.d.ts +17 -0
  20. package/dist/boxes.js +27 -20
  21. package/dist/browser-commands.d.ts +5 -2
  22. package/dist/browser-commands.js +4 -4
  23. package/dist/browser-computer.d.ts +5 -0
  24. package/dist/browser-computer.js +21 -0
  25. package/dist/browser-cost.d.ts +9 -6
  26. package/dist/browser-cost.js +92 -50
  27. package/dist/browser-live.d.ts +7 -20
  28. package/dist/browser-live.js +15 -93
  29. package/dist/browser-person.d.ts +18 -51
  30. package/dist/browser-person.js +94 -277
  31. package/dist/cap.d.ts +8 -5
  32. package/dist/cap.js +12 -5
  33. package/dist/cli.js +39 -13
  34. package/dist/closed-pipes.d.ts +2 -0
  35. package/dist/closed-pipes.js +13 -0
  36. package/dist/computer-commands.d.ts +2 -0
  37. package/dist/computer-commands.js +2 -0
  38. package/dist/computer-keys.js +5 -2
  39. package/dist/computer-setting.d.ts +20 -4
  40. package/dist/computer-setting.js +25 -5
  41. package/dist/computers.d.ts +30 -2
  42. package/dist/computers.js +70 -11
  43. package/dist/confine.d.ts +120 -0
  44. package/dist/confine.js +436 -0
  45. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  46. package/dist/console/assets/index-opTN5Naq.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decision-rows.d.ts +1 -1
  49. package/dist/decision-rows.js +1 -1
  50. package/dist/docker-daemon.d.ts +31 -0
  51. package/dist/docker-daemon.js +56 -0
  52. package/dist/effort-guidance.js +4 -3
  53. package/dist/environment.d.ts +0 -3
  54. package/dist/environment.js +3 -5
  55. package/dist/errors.d.ts +0 -2
  56. package/dist/errors.js +6 -9
  57. package/dist/filed-answer.d.ts +32 -0
  58. package/dist/filed-answer.js +160 -0
  59. package/dist/files.d.ts +1 -3
  60. package/dist/files.js +2 -4
  61. package/dist/github-connection.d.ts +1 -1
  62. package/dist/graph-view.d.ts +3 -5
  63. package/dist/graph-view.js +4 -14
  64. package/dist/handed-values.d.ts +9 -0
  65. package/dist/handed-values.js +26 -0
  66. package/dist/harness-install.d.ts +1 -7
  67. package/dist/harness-install.js +1 -18
  68. package/dist/harness-opencode/adapter.d.ts +7 -0
  69. package/dist/harness-opencode/adapter.js +23 -6
  70. package/dist/harness-opencode/index.d.ts +1 -1
  71. package/dist/harness-opencode/index.js +1 -1
  72. package/dist/harness-opencode/verify.d.ts +17 -0
  73. package/dist/harness-opencode/verify.js +30 -10
  74. package/dist/harness-table.js +6 -1
  75. package/dist/heard.js +1 -1
  76. package/dist/held-fd.d.ts +5 -0
  77. package/dist/held-fd.js +14 -0
  78. package/dist/host-calls.d.ts +20 -0
  79. package/dist/host-calls.js +12 -0
  80. package/dist/host-tools.d.ts +4 -21
  81. package/dist/host-tools.js +4 -61
  82. package/dist/host.d.ts +2 -4
  83. package/dist/host.js +2 -7
  84. package/dist/import-summary.d.ts +1 -5
  85. package/dist/import-summary.js +0 -21
  86. package/dist/import.d.ts +6 -6
  87. package/dist/import.js +14 -15
  88. package/dist/key-refusal.d.ts +5 -1
  89. package/dist/key-refusal.js +19 -4
  90. package/dist/learn/check.d.ts +6 -2
  91. package/dist/learn/check.js +83 -29
  92. package/dist/learn/folder.d.ts +5 -1
  93. package/dist/learn/folder.js +10 -3
  94. package/dist/learn/grade.d.ts +14 -0
  95. package/dist/learn/grade.js +68 -12
  96. package/dist/learn/index.d.ts +4 -4
  97. package/dist/learn/index.js +4 -4
  98. package/dist/learn/reflect.d.ts +31 -2
  99. package/dist/learn/reflect.js +79 -4
  100. package/dist/learn/relevance.d.ts +24 -0
  101. package/dist/learn/relevance.js +91 -0
  102. package/dist/learn/secrets.d.ts +7 -1
  103. package/dist/learn/secrets.js +86 -19
  104. package/dist/learn/skills.d.ts +112 -14
  105. package/dist/learn/skills.js +556 -52
  106. package/dist/learned-workflow.d.ts +32 -1
  107. package/dist/learned-workflow.js +100 -9
  108. package/dist/learning-routes.d.ts +8 -4
  109. package/dist/learning-routes.js +23 -9
  110. package/dist/learning-run.d.ts +9 -26
  111. package/dist/learning-run.js +22 -32
  112. package/dist/learning-words.d.ts +12 -5
  113. package/dist/learning-words.js +18 -9
  114. package/dist/learning.d.ts +93 -77
  115. package/dist/learning.js +176 -304
  116. package/dist/live/stream.js +1 -1
  117. package/dist/live/translate.js +12 -2
  118. package/dist/local-models.d.ts +11 -5
  119. package/dist/local-models.js +13 -8
  120. package/dist/mcp-gateway.d.ts +11 -49
  121. package/dist/mcp-gateway.js +44 -135
  122. package/dist/mcp-oauth.d.ts +10 -14
  123. package/dist/mcp-oauth.js +14 -32
  124. package/dist/mcp-probe.d.ts +0 -7
  125. package/dist/mcp-probe.js +4 -10
  126. package/dist/mcp-servers-store.d.ts +6 -6
  127. package/dist/mcp-servers-store.js +12 -14
  128. package/dist/mcp-store.js +3 -4
  129. package/dist/mcp.js +4 -3
  130. package/dist/model.d.ts +6 -7
  131. package/dist/model.js +43 -27
  132. package/dist/monid.d.ts +0 -2
  133. package/dist/monid.js +3 -6
  134. package/dist/openapi.d.ts +8 -1
  135. package/dist/openapi.js +121 -47
  136. package/dist/page.d.ts +1 -3
  137. package/dist/page.js +6 -18
  138. package/dist/paid-calls.d.ts +21 -27
  139. package/dist/paid-calls.js +25 -60
  140. package/dist/propose.js +83 -39
  141. package/dist/push-handler.d.ts +1 -1
  142. package/dist/reflect-range.d.ts +25 -0
  143. package/dist/reflect-range.js +30 -0
  144. package/dist/refusal-words.d.ts +5 -1
  145. package/dist/refusal-words.js +5 -1
  146. package/dist/rows.d.ts +1 -1
  147. package/dist/run-cut.d.ts +0 -6
  148. package/dist/run-cut.js +0 -6
  149. package/dist/run-db.d.ts +2 -11
  150. package/dist/run-db.js +2 -37
  151. package/dist/run-launch.d.ts +19 -2
  152. package/dist/run-launch.js +13 -5
  153. package/dist/run-learning-served.d.ts +10 -4
  154. package/dist/run-learning-served.js +23 -13
  155. package/dist/run-reads-over-store.d.ts +1 -1
  156. package/dist/run-reads-over-store.js +15 -6
  157. package/dist/run-secrets.d.ts +1 -1
  158. package/dist/run-timeline-served.d.ts +5 -1
  159. package/dist/run-timeline-served.js +15 -4
  160. package/dist/run-view.d.ts +7 -8
  161. package/dist/run-view.js +26 -7
  162. package/dist/runnable.d.ts +18 -10
  163. package/dist/runnable.js +21 -10
  164. package/dist/runner/adapter-loop.d.ts +6 -1
  165. package/dist/runner/adapter-loop.js +423 -53
  166. package/dist/runner/adapter-run-spec.d.ts +21 -8
  167. package/dist/runner/adapter-run-spec.js +90 -32
  168. package/dist/runner/adapters/index.js +11 -1
  169. package/dist/runner/adapters/pi.d.ts +12 -2
  170. package/dist/runner/adapters/pi.js +16 -5
  171. package/dist/runner/beside.d.ts +30 -3
  172. package/dist/runner/beside.js +36 -5
  173. package/dist/runner/claim-secrets.d.ts +10 -1
  174. package/dist/runner/claim-secrets.js +48 -14
  175. package/dist/runner/cli-run-spec.d.ts +2 -0
  176. package/dist/runner/cli-run-spec.js +45 -16
  177. package/dist/runner/commands.js +1 -1
  178. package/dist/runner/computer-journal.d.ts +15 -2
  179. package/dist/runner/computer-journal.js +41 -5
  180. package/dist/runner/conformance/harness.js +118 -8
  181. package/dist/runner/conformance/subject.d.ts +4 -1
  182. package/dist/runner/dispatch.d.ts +8 -1
  183. package/dist/runner/dispatch.js +81 -7
  184. package/dist/runner/end-of-run.d.ts +8 -2
  185. package/dist/runner/end-of-run.js +10 -4
  186. package/dist/runner/github-app.js +1 -1
  187. package/dist/runner/harness-loops.d.ts +9 -1
  188. package/dist/runner/harness-loops.js +15 -2
  189. package/dist/runner/journal-kinds.d.ts +24 -6
  190. package/dist/runner/journal-kinds.js +20 -5
  191. package/dist/runner/journal-reader.d.ts +1 -1
  192. package/dist/runner/journal-reader.js +2 -2
  193. package/dist/runner/learning-ask.d.ts +4 -0
  194. package/dist/runner/learning-ask.js +15 -1
  195. package/dist/runner/learning-end.d.ts +18 -3
  196. package/dist/runner/learning-end.js +113 -11
  197. package/dist/runner/learning-loop.d.ts +5 -0
  198. package/dist/runner/learning-loop.js +26 -6
  199. package/dist/runner/main.d.ts +56 -9
  200. package/dist/runner/main.js +127 -18
  201. package/dist/runner/mcp-claim.js +1 -2
  202. package/dist/runner/mcp-run.d.ts +2 -0
  203. package/dist/runner/mcp-run.js +15 -5
  204. package/dist/runner/memory-claim.d.ts +9 -0
  205. package/dist/runner/memory-claim.js +25 -0
  206. package/dist/runner/metrics.d.ts +33 -1
  207. package/dist/runner/metrics.js +85 -1
  208. package/dist/runner/model-route.d.ts +13 -0
  209. package/dist/runner/model-route.js +133 -9
  210. package/dist/runner/reflect-hook.d.ts +12 -1
  211. package/dist/runner/reflect-hook.js +33 -3
  212. package/dist/runner/runner.d.ts +20 -0
  213. package/dist/runner/runner.js +56 -10
  214. package/dist/runner/store-port.d.ts +1 -1
  215. package/dist/runner/store-secrets.d.ts +3 -3
  216. package/dist/runner/store-secrets.js +8 -12
  217. package/dist/runner/text-tools.d.ts +44 -0
  218. package/dist/runner/text-tools.js +237 -0
  219. package/dist/runner/workflow-loop.d.ts +6 -0
  220. package/dist/runner/workflow-loop.js +6 -4
  221. package/dist/runner/workflow-spec.d.ts +18 -0
  222. package/dist/runner/workflow-spec.js +63 -17
  223. package/dist/runs-over-store.d.ts +7 -2
  224. package/dist/runs-over-store.js +60 -14
  225. package/dist/seal-key.js +5 -43
  226. package/dist/sealed-settings-store.d.ts +19 -4
  227. package/dist/sealed-settings-store.js +9 -9
  228. package/dist/sealing.d.ts +4 -0
  229. package/dist/sealing.js +20 -0
  230. package/dist/secret-cut.d.ts +1 -1
  231. package/dist/secret-cut.js +1 -1
  232. package/dist/secret-name.d.ts +9 -0
  233. package/dist/secret-name.js +15 -0
  234. package/dist/secret-writes.d.ts +0 -1
  235. package/dist/secret-writes.js +0 -1
  236. package/dist/server-fs.d.ts +4 -0
  237. package/dist/server-fs.js +8 -2
  238. package/dist/server-lock.d.ts +0 -24
  239. package/dist/server-lock.js +1 -80
  240. package/dist/server-secrets-store.d.ts +4 -4
  241. package/dist/server-secrets-store.js +9 -31
  242. package/dist/server-secrets.d.ts +4 -9
  243. package/dist/server-secrets.js +12 -36
  244. package/dist/server.d.ts +16 -38
  245. package/dist/server.js +145 -106
  246. package/dist/sign-ins-store.d.ts +34 -36
  247. package/dist/sign-ins-store.js +27 -38
  248. package/dist/sign-ins.d.ts +2 -119
  249. package/dist/sign-ins.js +5 -311
  250. package/dist/standard-webhooks.d.ts +1 -1
  251. package/dist/standard-webhooks.js +1 -1
  252. package/dist/stats.d.ts +3 -2
  253. package/dist/stats.js +1 -1
  254. package/dist/store/agent-body.d.ts +8 -2
  255. package/dist/store/agent-body.js +16 -4
  256. package/dist/store/index.d.ts +2 -2
  257. package/dist/store/index.js +2 -2
  258. package/dist/store/open.d.ts +6 -3
  259. package/dist/store/open.js +2 -2
  260. package/dist/store/postgres/connection.d.ts +18 -2
  261. package/dist/store/postgres/connection.js +156 -32
  262. package/dist/store/postgres/migrate.d.ts +4 -0
  263. package/dist/store/postgres/migrate.js +9 -2
  264. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  265. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  266. package/dist/store/postgres/store.d.ts +9 -2
  267. package/dist/store/postgres/store.js +9 -0
  268. package/dist/store/schema.js +1 -1
  269. package/dist/store/seal.js +2 -2
  270. package/dist/store/sqlite/connection.js +49 -5
  271. package/dist/store/sqlite/run-patch.d.ts +3 -0
  272. package/dist/store/sqlite/run-patch.js +3 -0
  273. package/dist/store/sqlite/store.js +41 -12
  274. package/dist/store/store.d.ts +35 -6
  275. package/dist/store/store.js +12 -2
  276. package/dist/store-reads/cap.d.ts +1 -1
  277. package/dist/store-reads/cap.js +22 -4
  278. package/dist/store-reads/journal.d.ts +9 -6
  279. package/dist/store-reads/journal.js +93 -17
  280. package/dist/store-reads/learning.d.ts +26 -8
  281. package/dist/store-reads/learning.js +12 -4
  282. package/dist/store-reads/workflow.d.ts +1 -1
  283. package/dist/store-reads/workflow.js +1 -1
  284. package/dist/store-view.d.ts +5 -1
  285. package/dist/store-view.js +53 -18
  286. package/dist/template-eval.d.ts +60 -4
  287. package/dist/template-eval.js +120 -54
  288. package/dist/templates.d.ts +24 -10
  289. package/dist/templates.js +69 -38
  290. package/dist/timeline/group.d.ts +33 -0
  291. package/dist/timeline/group.js +77 -0
  292. package/dist/timeline/index.d.ts +7 -0
  293. package/dist/timeline/index.js +7 -0
  294. package/dist/timeline/labels.d.ts +79 -0
  295. package/dist/timeline/labels.js +150 -0
  296. package/dist/timeline/origin.d.ts +56 -0
  297. package/dist/timeline/origin.js +92 -0
  298. package/dist/timeline/render-text.d.ts +11 -0
  299. package/dist/timeline/render-text.js +62 -0
  300. package/dist/timeline/timeline.d.ts +274 -0
  301. package/dist/timeline/timeline.js +1308 -0
  302. package/dist/timeline/util.d.ts +17 -0
  303. package/dist/timeline/util.js +49 -0
  304. package/dist/tool-gate.d.ts +41 -216
  305. package/dist/tool-gate.js +79 -540
  306. package/dist/tool-keys-store.d.ts +11 -12
  307. package/dist/tool-keys-store.js +24 -31
  308. package/dist/tool-keys.d.ts +5 -101
  309. package/dist/tool-keys.js +8 -267
  310. package/dist/tool-plane.d.ts +14 -42
  311. package/dist/tool-plane.js +23 -81
  312. package/dist/tool-settings-store.d.ts +1 -2
  313. package/dist/tool-settings-store.js +5 -8
  314. package/dist/tools.d.ts +30 -18
  315. package/dist/tools.js +97 -107
  316. package/dist/trigger-adapter.d.ts +2 -2
  317. package/dist/trigger-targets.d.ts +13 -1
  318. package/dist/trigger-targets.js +31 -1
  319. package/dist/triggers.d.ts +2 -2
  320. package/dist/triggers.js +3 -3
  321. package/dist/turn-end.d.ts +1 -1
  322. package/dist/turn-end.js +1 -1
  323. package/dist/turns.d.ts +0 -6
  324. package/dist/turns.js +0 -19
  325. package/dist/uploads.js +1 -1
  326. package/dist/usage.d.ts +0 -2
  327. package/dist/usage.js +0 -2
  328. package/dist/validate.d.ts +2 -0
  329. package/dist/validate.js +23 -14
  330. package/dist/webhooks.d.ts +102 -76
  331. package/dist/webhooks.js +266 -233
  332. package/dist/workflow-run.d.ts +114 -0
  333. package/dist/workflow-run.js +144 -0
  334. package/dist/workspace/beneath.d.ts +19 -0
  335. package/dist/workspace/beneath.js +106 -0
  336. package/dist/workspace/computer-deps.d.ts +24 -6
  337. package/dist/workspace/computer-deps.js +108 -20
  338. package/dist/workspace/computer-for-claim.d.ts +12 -11
  339. package/dist/workspace/computer-for-claim.js +76 -15
  340. package/dist/workspace/computer-hold.d.ts +6 -1
  341. package/dist/workspace/computer-hold.js +6 -1
  342. package/dist/workspace/computer-janitor.d.ts +47 -0
  343. package/dist/workspace/computer-janitor.js +182 -0
  344. package/dist/workspace/grep-worker.d.ts +5 -0
  345. package/dist/workspace/grep-worker.js +9 -6
  346. package/dist/workspace/index.d.ts +3 -2
  347. package/dist/workspace/index.js +3 -3
  348. package/dist/workspace/local.d.ts +11 -2
  349. package/dist/workspace/local.js +161 -43
  350. package/dist/workspace/resolve-computer.d.ts +50 -10
  351. package/dist/workspace/resolve-computer.js +46 -11
  352. package/dist/workspace/run-tools.d.ts +13 -31
  353. package/dist/workspace/run-tools.js +10 -27
  354. package/dist/workspace-paths.d.ts +0 -17
  355. package/dist/workspace-paths.js +1 -41
  356. package/dist/workspace.d.ts +0 -14
  357. package/dist/workspace.js +3 -96
  358. package/package.json +13 -13
  359. package/templates/README.md +9 -3
  360. package/templates/market-monitor/agent.md +2 -2
  361. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  362. package/dist/bound-files.d.ts +0 -4
  363. package/dist/bound-files.js +0 -164
  364. package/dist/coding-tools.d.ts +0 -47
  365. package/dist/coding-tools.js +0 -189
  366. package/dist/computer-adb.d.ts +0 -12
  367. package/dist/computer-adb.js +0 -14
  368. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  369. package/dist/console/assets/index-DvW6Aled.css +0 -1
  370. package/dist/grade.d.ts +0 -63
  371. package/dist/grade.js +0 -150
  372. package/dist/mcp-servers.d.ts +0 -269
  373. package/dist/mcp-servers.js +0 -456
  374. package/dist/packs.d.ts +0 -71
  375. package/dist/packs.js +0 -180
  376. package/dist/sealed-settings.d.ts +0 -60
  377. package/dist/sealed-settings.js +0 -171
  378. package/dist/sessions.d.ts +0 -6
  379. package/dist/sessions.js +0 -109
  380. package/dist/workspace/computer-serves.d.ts +0 -12
  381. package/dist/workspace/computer-serves.js +0 -15
@@ -1,3 +1,5 @@
1
+ import { checkGpu } from "@parcha/agentrun-computer";
2
+ import { noDockerWords } from "../docker-daemon.js";
1
3
  /** A provider's keys as the claim reads them: each key its registry entry declares, by `keyOf` (the server's reader:
2
4
  * key-meta.ts keyReader, the environment's value, else the saved one); a key with no value is left out. */
3
5
  export const providerKeys = (registry, keyOf) => async (provider) => {
@@ -9,15 +11,28 @@ export const providerKeys = (registry, keyOf) => async (provider) => {
9
11
  }
10
12
  return keys;
11
13
  };
14
+ /** Whether a provider's computers run only on the vendor's own network: the network forms it declares (its module's
15
+ * NETWORK, its capabilities().network) are "open" alone, as a cloud phone's and a hosted browser's are. */
16
+ export const vendorNetworkOnly = (network) => network !== undefined && network.length > 0 && network.every((one) => one === "open");
17
+ /** Whether a provider's computers can't have no network: it declares its network forms and "none" isn't one (a cloud
18
+ * phone, a hosted browser, Local Chrome). */
19
+ export const needsNetwork = (network) => network !== undefined && network.length > 0 && !network.includes("none");
20
+ /** Why a computer that needs a network is refused where this server's AGENTRUN_BOX_ALLOW is none, in words that name the
21
+ * fix: the operator said no network at all, and the computer can't run without one. */
22
+ export const noNetworkRefusal = (label, kind) => `This agent's computer is a ${label} ${kind}, which needs a network (the vendor's own, or public addresses from this machine), and this server's AGENTRUN_BOX_ALLOW is none (no network): pick a computer that runs with no network in ${SETTINGS}, or set AGENTRUN_BOX_ALLOW to a host list.`;
12
23
  /** Whether an agent's computer `setting` can be had in `mode` now, by the answers the claim gives (resolveComputer: the
13
24
  * kind, the provider and what it serves, the mode's mount, the provider's keys by `keyOf`): ok, or its refusal in words
14
25
  * that name the fix. Nothing starts. A run's start asks it before the run is made (runnable.ts).
15
26
  *
16
- * `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not, in words
17
- * that say how to fix it (the server's start-time probe of it). A Mode 1 sandbox on such a provider is refused in those
18
- * words here, at the start, where the claim would only fail to launch it. Asked here, not in resolveComputer: the claim
19
- * has no such answer and launches it. Absent: not asked. */
20
- export async function computerReadiness(setting, mode, registry, keyOf, answers) {
27
+ * `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not (the server's
28
+ * daemon check, docker-daemon.ts). Any computer on such a provider, a sandbox or a desktop in either mode, is refused
29
+ * here, at the start, where the claim would only fail to launch it: no daemon at all in the one wording Settings →
30
+ * Computers and the claim say (noDockerWords), another reason in its own words. Asked here, not in resolveComputer: the
31
+ * claim launches it, and asks only once its launch fails (ClaimSide.daemon). Absent: not asked.
32
+ *
33
+ * `boxAllow`: this server's allow setting (box-settings.ts boxAllowOf). Under "none", a computer whose provider makes no
34
+ * "none" is refused (noNetworkRefusal), as the claim refuses it. Absent: not asked. */
35
+ export async function computerReadiness(setting, mode, registry, keyOf, answers, boxAllow) {
21
36
  const resolved = await resolveComputer(setting, mode, registry, {
22
37
  keysOf: providerKeys(registry, keyOf),
23
38
  // A setting is given, so the Mode 1 default (the only asker) is never read; and nothing is launched.
@@ -27,10 +42,16 @@ export async function computerReadiness(setting, mode, registry, keyOf, answers)
27
42
  if ("refused" in resolved)
28
43
  return { refused: resolved.refused };
29
44
  const entry = registry.PROVIDERS.find((one) => one.id === resolved.provider);
30
- const why = mode === 1 && resolved.mounts && entry?.mounts.includes("bind") && answers ? answers(entry.id) : true;
31
- // It names the box whose probe said no (a refusal's details.box), as the box check did.
32
- if (why !== true)
33
- return { refused: `This agent's computer is a ${entry.label} ${resolved.kind}, and this server cannot run it: ${why.replace(/[.!?]+$/, "")}.`, box: entry.id };
45
+ if (entry && entry.mounts.includes("bind") && answers) {
46
+ const said = await answers(entry.id);
47
+ // It names the box whose probe said no (a refusal's details.box), as the box check did.
48
+ if (!said.up && said.absent)
49
+ return { refused: noDockerWords(resolved.kind, registry.PROVIDERS, mode), box: entry.id };
50
+ if (!said.up)
51
+ return { refused: `This agent's computer is a ${entry.label} ${resolved.kind}, and this server cannot run it: ${said.reason.replace(/[.!?]+$/, "")}.`, box: entry.id };
52
+ }
53
+ if (boxAllow === "none" && entry && needsNetwork(entry.network))
54
+ return { refused: noNetworkRefusal(entry.label, resolved.kind) };
34
55
  return { ok: true };
35
56
  }
36
57
  const SETTINGS = "Settings → Computers";
@@ -134,6 +155,15 @@ export async function resolveComputer(given, mode, registry, side) {
134
155
  return { refused: `Mode 2 keeps workspaces on Archil; a local Docker computer can't mount them. Pick a remote sandbox for this agent's computer in ${SETTINGS}, or no computer.` };
135
156
  return { refused: `A ${entry.label} sandbox can't mount the run's folder from Archil: pick another sandbox for this agent's computer in ${SETTINGS}.` };
136
157
  }
158
+ // Its GPUs, a sandbox's alone: in checkGpu's words, against what the configuration that serves it declares, with the
159
+ // mode's folder as the mount it takes (a sandbox here always mounts it).
160
+ const gpu = kind === "sandbox" && setting.gpu ? setting.gpu : undefined;
161
+ if (gpu) {
162
+ const offered = serving.find((one) => one.gpu !== undefined) ?? serving[0];
163
+ const [refusal] = checkGpu(gpu, offered, { kind: mode === 1 ? "bind" : "archil" });
164
+ if (refusal)
165
+ return { refused: `A ${entry.label} sandbox can't have this agent's GPUs: ${refusal.message}. Change the GPUs or the provider for this agent's computer in ${SETTINGS}.` };
166
+ }
137
167
  // Its keys: every required one saved, before anything starts; only declared names go to the provider.
138
168
  const saved = await side.keysOf(entry.id);
139
169
  const has = (name) => typeof saved[name] === "string" && saved[name] !== "";
@@ -154,9 +184,13 @@ export async function resolveComputer(given, mode, registry, side) {
154
184
  const mount = mounts ? await workspace.mountSpec() : undefined;
155
185
  let launched;
156
186
  try {
157
- launched = await side.launch(entry, { kind, keys, ...(mount ? { mount } : {}), ...(signal ? { signal } : {}) });
187
+ launched = await side.launch(entry, { kind, keys, ...(mount ? { mount } : {}), ...(gpu ? { gpu: { type: gpu.type, count: gpu.count } } : {}), ...(signal ? { signal } : {}) });
158
188
  }
159
189
  catch (error) {
190
+ // A provider that binds a folder of this machine (Docker) whose daemon does not answer: the one wording.
191
+ const said = entry.mounts.includes("bind") && side.daemon ? await side.daemon(entry.id).catch(() => undefined) : undefined;
192
+ if (said && !said.up && said.absent)
193
+ throw unavailable(noDockerWords(kind, registry.PROVIDERS, mode));
160
194
  throw unavailable(`${entry.label} could not start a ${kind} computer: ${error instanceof Error ? error.message : String(error)}`);
161
195
  }
162
196
  const computer = runComputerOf(kind, launched, mounts ? check : undefined);
@@ -171,8 +205,9 @@ export async function resolveComputer(given, mode, registry, side) {
171
205
  /** The started computer as runTools takes it, or what it lacks, in words. */
172
206
  function runComputerOf(kind, launched, check) {
173
207
  const groups = launched.groups;
208
+ // The run's browser tool opens a browser's sessions through its provider.
174
209
  if (kind === "browser")
175
- return launched.connect ? { kind, connect: () => launched.connect() } : "it gave no CDP connection";
210
+ return launched.browser ? { kind, browser: launched.browser } : "it gave no CDP connection";
176
211
  const { client } = launched;
177
212
  if (!client)
178
213
  return "it gave no computer protocol client";
@@ -1,12 +1,11 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
2
  import type { HostTool } from "@parcha/agentrun-kernel";
3
- import { type CapabilityKind, type CdpSession, type Executor, type Registry } from "@parcha/agentrun-kernel/kernel";
3
+ import { type CapabilityKind, type Registry } from "@parcha/agentrun-kernel/kernel";
4
4
  import type { ComputerClient, Group } from "@parcha/agentrun-computer";
5
- import type { Park, RunGate } from "../tool-gate.js";
6
5
  import type { AttachableComputer, MountCheck } from "./attach.js";
7
6
  import { type PiAnswer, type PiExecutor } from "./executors.js";
8
7
  import { type Hands } from "./hands.js";
9
- import { type ShellPlace } from "./resolve-computer.js";
8
+ import { type ClaimBrowser, type ShellPlace } from "./resolve-computer.js";
10
9
  import type { Workspace } from "./workspace.js";
11
10
  /**
12
11
  * The run's computer, as runTools takes it, by its kind:
@@ -15,7 +14,8 @@ import type { Workspace } from "./workspace.js";
15
14
  * - desktop: a screen and input; the folder is attached only when its provider mounts it (`check` given) and it offers
16
15
  * files and exec;
17
16
  * - phone: a screen, touch and apps; never attached;
18
- * - browser: its CDP connect; never attached.
17
+ * - browser: what the run's browser tool drives it by (its CDP URL through its provider); no tools of the registry's,
18
+ * never attached.
19
19
  * `groups`: what the computer offers (its hello's groups), which fill its kind's ports.
20
20
  */
21
21
  export type RunComputer = {
@@ -35,7 +35,7 @@ export type RunComputer = {
35
35
  readonly groups: readonly Group[];
36
36
  } | {
37
37
  readonly kind: "browser";
38
- readonly connect: () => Promise<CdpSession>;
38
+ readonly browser: ClaimBrowser;
39
39
  };
40
40
  /** A desktop's or a phone's ports as a person's hold on the computer gives them back: each call made while the person
41
41
  * holds it waits for hand-back; a read then runs, an action then is refused (the take-over's own words). With them, the
@@ -105,17 +105,12 @@ export type ToolResults = Map<string, {
105
105
  }>;
106
106
  /**
107
107
  * `registry`'s tools that `names` names, in that order, bound to `run`: each as the kernel's HostTool, which an adapter's
108
- * session takes. A call passes the run's gate first (`gated`: the gate and the park it takes; none for the gate's own
109
- * run of an approved call): a refused one runs nothing, a parked one says it waits. Then the registry runs it on the
108
+ * session takes. The run's gate decided the call before its intent (the adapter loop's). The registry runs it on the
110
109
  * run's hands, and its answer is the text a model reads (executors.ts answerText): the output, the failure's words, the
111
110
  * diagnostics; in a failure, a write's or an edit's answer a path in the run's folder is named relative to it. A
112
111
  * failure the registry throws is the answer's text. `results` keeps each answer by its call id.
113
112
  */
114
113
  export declare function bindTools(run: RunHands, registry: RunRegistry, names: readonly string[], options?: {
115
- readonly gated?: {
116
- readonly gate: RunGate;
117
- readonly park: Park;
118
- };
119
114
  readonly results?: ToolResults;
120
115
  }): HostTool[];
121
116
  /** A run's tools: what E2's harness start calls runTools for. */
@@ -125,46 +120,33 @@ export type RunTools = {
125
120
  /** The run's registry: the kernel's definitions, words and limits, over this run's hands and executors. */
126
121
  readonly registry: Registry;
127
122
  readonly hands: Hands;
123
+ /** Where the run's shell is (runHands' shell): its gate reads its defaults by it (tool-gate.ts defaultPermission). */
124
+ readonly shell: ShellPlace;
128
125
  /** The tools the claimed computer brings by its kind, as its groups offer them: a desktop's (desktop_screen,
129
126
  * desktop_input, computer_request_handoff) or a phone's, by the kernel registry's own list. None with no computer, for
130
127
  * a sandbox, or for a browser (its own binding lists its tools). An agent names its computer, never these tools
131
128
  * (definition.tools refuses them), so a run binds them beside what it was granted (withKindTools). */
132
129
  readonly kindTools: readonly string[];
133
130
  /** The registry's tools `names` names, as the kernel's HostTool an adapter's session takes, each call through the
134
- * run's gate (`gated`; none for the gate's own run of an approved call), each answer kept in `results` (bindTools). */
135
- hostTools(names: readonly string[], gated?: {
136
- readonly gate: RunGate;
137
- readonly park: Park;
138
- }, results?: ToolResults): HostTool[];
131
+ * run's gate decided before its intent, each answer kept in `results` (bindTools). */
132
+ hostTools(names: readonly string[], results?: ToolResults): HostTool[];
139
133
  /** The run's end, before the computer is let go: its background processes ended (TERM, then KILL 3 s later; none with
140
134
  * no computer), then bash's full outputs and TMPDIR swept. */
141
135
  end(): Promise<void>;
142
136
  };
143
- /** A browser computer's tools as the run's start gives them: pi-browser's runs by tool name (over hands.browser), and
144
- * what the browser offers, which lists browser_downloads, browser_upload and browser_request_handoff (pi-browser's
145
- * listedFor). */
146
- export type RunBrowser = {
147
- readonly executors: Readonly<Record<string, Executor>>;
148
- readonly offers: {
149
- readonly downloads: boolean;
150
- readonly upload: boolean;
151
- readonly handoff: boolean;
152
- };
153
- };
154
137
  /**
155
138
  * A run's tools on `workspace`, attached to `computer` when its kind has files and exec and its provider mounts the
156
139
  * folder (RunComputer). `computer.check` is the mount check attach runs (attach.ts MountCheck: `{ readBackOf, epoch }`),
157
140
  * which the caller builds with the claim's epoch, so a read-back under another epoch is refused. `options.mode`: 1, or 2
158
141
  * (the run's folder on Archil); `options.aliases`: other absolute names of the run's folder a tool call may give (the
159
- * harness's scratch folder); `options.browser`: a browser computer's runs and offers. The tools' definitions, words and
160
- * limits come only from the kernel's registry, and a browser's from pi-browser's BROWSER_TOOLS; this binds their
161
- * executors to the run.
142
+ * harness's scratch folder). The tools' definitions, words and limits come only from the kernel's registry; this binds
143
+ * their executors to the run. A browser computer brings none of the registry's: the run's browser tool (tools.ts,
144
+ * pi-browser's durable extension) drives it.
162
145
  */
163
146
  export declare function runTools(workspace: Workspace, computer: RunComputer | undefined, options: {
164
147
  readonly mode: 1 | 2;
165
148
  readonly context: Context;
166
149
  readonly aliases?: readonly string[];
167
- readonly browser?: RunBrowser;
168
150
  readonly hold?: RunHold;
169
151
  }): Promise<RunTools>;
170
152
  /** The names a run binds as host tools: what it was granted, then the tools its claimed computer brings by its kind
@@ -15,7 +15,7 @@ function mountedIn(computer) {
15
15
  return undefined;
16
16
  }
17
17
  /** The kind's ports, as the computer's groups offer them, the kinds whose tools the run gets (a desktop's with a screen
18
- * and input, a phone's with a screen and touch, a browser's always), and the kind's tools its groups do not offer: a
18
+ * and input, a phone's with a screen and touch; a browser's none), and the kind's tools its groups do not offer: a
19
19
  * phone's tree without apps.ui_tree, its keys without input.keys (an iPhone's today). */
20
20
  function portsOf(computer) {
21
21
  if (computer?.kind === "desktop") {
@@ -31,8 +31,6 @@ function portsOf(computer) {
31
31
  const keys = computer.groups.includes("input.keys");
32
32
  return { ports: { phone: phoneOf(computer.computer.client, { tree, keys }) }, kinds: ["phone"], without: [...(tree ? [] : ["phone_tree"]), ...(keys ? [] : ["phone_key"])] };
33
33
  }
34
- if (computer?.kind === "browser")
35
- return { ports: { browser: { connect: computer.connect } }, kinds: ["browser"], without: [] };
36
34
  return { ports: {}, kinds: [], without: [] };
37
35
  }
38
36
  /** The run's scratch in its own folder: bash's TMPDIR. */
@@ -86,8 +84,7 @@ export async function runHands(workspace, computer, options) {
86
84
  const SAYS_PATH = new Set(["write", "edit"]);
87
85
  /**
88
86
  * `registry`'s tools that `names` names, in that order, bound to `run`: each as the kernel's HostTool, which an adapter's
89
- * session takes. A call passes the run's gate first (`gated`: the gate and the park it takes; none for the gate's own
90
- * run of an approved call): a refused one runs nothing, a parked one says it waits. Then the registry runs it on the
87
+ * session takes. The run's gate decided the call before its intent (the adapter loop's). The registry runs it on the
91
88
  * run's hands, and its answer is the text a model reads (executors.ts answerText): the output, the failure's words, the
92
89
  * diagnostics; in a failure, a write's or an edit's answer a path in the run's folder is named relative to it. A
93
90
  * failure the registry throws is the answer's text. `results` keeps each answer by its call id.
@@ -104,14 +101,7 @@ export function bindTools(run, registry, names, options = {}) {
104
101
  description: def.description,
105
102
  inputSchema: def.parameters,
106
103
  replay: def.replaySafe ? "safe" : "never",
107
- async call(args, { callId, signal, attempt, model, output }) {
108
- // A replay (the kernel's attempt above 0) may follow an attempt that was sent: the gate's refusal then says so.
109
- const refused = await options.gated?.gate.enter(name, args, callId, options.gated.park, (attempt ?? 0) > 0 ? { replayed: true } : {});
110
- if (refused) {
111
- const answer = { text: refused.text, isError: refused.isError === true };
112
- options.results?.set(callId, answer);
113
- return refused.parked ? { ...answer, parked: true } : answer;
114
- }
104
+ async call(args, { callId, signal, model, output }) {
115
105
  let given;
116
106
  try {
117
107
  // The calling model and the call's output stream, as the session gave them: pi's read sizes an image by the
@@ -136,28 +126,21 @@ export function bindTools(run, registry, names, options = {}) {
136
126
  * folder (RunComputer). `computer.check` is the mount check attach runs (attach.ts MountCheck: `{ readBackOf, epoch }`),
137
127
  * which the caller builds with the claim's epoch, so a read-back under another epoch is refused. `options.mode`: 1, or 2
138
128
  * (the run's folder on Archil); `options.aliases`: other absolute names of the run's folder a tool call may give (the
139
- * harness's scratch folder); `options.browser`: a browser computer's runs and offers. The tools' definitions, words and
140
- * limits come only from the kernel's registry, and a browser's from pi-browser's BROWSER_TOOLS; this binds their
141
- * executors to the run.
129
+ * harness's scratch folder). The tools' definitions, words and limits come only from the kernel's registry; this binds
130
+ * their executors to the run. A browser computer brings none of the registry's: the run's browser tool (tools.ts,
131
+ * pi-browser's durable extension) drives it.
142
132
  */
143
133
  export async function runTools(workspace, computer, options) {
144
134
  const run = await runHands(workspace, computer, options);
145
- // pi-browser's contracts, listed for what this browser offers; with no browser, all of them, so a browser tool called
146
- // in another run is refused in words that name the setting.
147
- const { BROWSER_TOOLS, listedFor } = await import("@parcha/pi-browser");
148
- const offers = options.browser?.offers;
149
- const browserTools = run.kinds.includes("browser") ? BROWSER_TOOLS.filter((contract) => listedFor(contract, offers ?? { downloads: false, upload: false, handoff: false })) : BROWSER_TOOLS;
150
- const registry = createRegistry({
151
- maxExecS: run.maxExecS, shell: run.shell, kinds: run.kinds, browserTools, without: run.without,
152
- executors: { ...run.executors, ...(options.browser ? { browser: options.browser.executors } : {}) },
153
- });
154
- const brought = new Set(run.kinds.filter((kind) => kind !== "browser").flatMap((kind) => capabilityToolDefs(kind).map((def) => def.name)));
135
+ const registry = createRegistry({ maxExecS: run.maxExecS, shell: run.shell, kinds: run.kinds, without: run.without, executors: run.executors });
136
+ const brought = new Set(run.kinds.flatMap((kind) => capabilityToolDefs(kind).map((def) => def.name)));
155
137
  return {
156
138
  workspace: run.workspace,
157
139
  registry,
158
140
  hands: run.hands,
141
+ shell: run.shell,
159
142
  kindTools: registry.list().map((def) => def.name).filter((name) => brought.has(name)),
160
- hostTools: (names, gated, results) => bindTools(run, registry, names, { ...(gated ? { gated } : {}), ...(results ? { results } : {}) }),
143
+ hostTools: (names, results) => bindTools(run, registry, names, results ? { results } : {}),
161
144
  async end() {
162
145
  await endBackground(run.hands);
163
146
  await run.sweep();
@@ -1,21 +1,4 @@
1
- import type { ToolRegistration } from "@earendil-works/pi-durable";
2
1
  export { realOf, workspaceRelative } from "./workspace/paths.js";
3
- /**
4
- * Refuses `given`, a path a call gave that leaves the workspace, in the one words every refusal uses:
5
- * `<given>: outside the workspace`, and no other path (not the workspace, a box's work dir, or where it resolves). It is
6
- * the confinement's typed refusal (`PathOutsideWorkError`, `outside_work`), so its type tells it from any other error.
7
- * For a tool that checks a path itself (a box's file tools); pi's own tools refuse through the confinement, named by
8
- * `asGivenRefusals`.
9
- */
10
- export declare function refuseOutsideWorkspace(given: string): never;
11
- /**
12
- * pi's file `tools`, each with its confinement's refusal named by the path the call gave, as it gave it:
13
- * `../../.token: outside the workspace`. The confinement names no path itself: pi's tools resolve a path against the
14
- * workspace before they ask for it, so every path it sees is the host's own (`<data>/runs/.token`), and the call's
15
- * `path` is the only one the model gave. A refusal is told by its type (`PathOutsideWorkError`), never by its text; one
16
- * already named (`refuseOutsideWorkspace`), every other error, and every result are the tool's own.
17
- */
18
- export declare function asGivenRefusals(tools: readonly ToolRegistration[]): ToolRegistration[];
19
2
  /** How a run's rows name a file path, a whole path (never a text): one in the run's directory relative to its workspace
20
3
  * (`<run>/work`: `hello.md`, `.`, `../work 2024/a.md`, `..`), and any other path, or one that is not absolute, exactly
21
4
  * as given. Checked against the workspace as serve names it and as the kernel resolves it (a harness's CLI sends the
@@ -1,50 +1,10 @@
1
1
  // How serve names a path in the run's workspace to a person or a model: relative to the workspace, never by the server's
2
2
  // data directory. The rule is one for every place that shows a path: a host tool's error or write result
3
- // (host-tools.ts), and a timeline row's file (runs.ts, through the projector's `path` option). A refusal of a path
4
- // outside the workspace names the path the call gave, as it gave it, and no other (`asGivenRefusals`), wherever the
5
- // coding tools come from (coding-tools.ts: pi's own runs and the other harnesses' host tools, on the runner and in a box).
3
+ // (host-tools.ts), and a row's file path (rowPaths).
6
4
  import { dirname, isAbsolute, join, relative, sep } from "node:path";
7
- import { PathOutsideWorkError } from "@parcha/pi-durable-disk";
8
5
  import { realOf } from "./workspace/paths.js";
9
6
  // How a text names the run's folder, and a path as the kernel resolves it, are the Workspace's (workspace/paths.ts).
10
7
  export { realOf, workspaceRelative } from "./workspace/paths.js";
11
- /** A refusal already named by the path the call gave: `asGivenRefusals` passes it on as it is. */
12
- class GivenPathRefusal extends PathOutsideWorkError {
13
- }
14
- /**
15
- * Refuses `given`, a path a call gave that leaves the workspace, in the one words every refusal uses:
16
- * `<given>: outside the workspace`, and no other path (not the workspace, a box's work dir, or where it resolves). It is
17
- * the confinement's typed refusal (`PathOutsideWorkError`, `outside_work`), so its type tells it from any other error.
18
- * For a tool that checks a path itself (a box's file tools); pi's own tools refuse through the confinement, named by
19
- * `asGivenRefusals`.
20
- */
21
- export function refuseOutsideWorkspace(given) {
22
- throw new GivenPathRefusal(given, "outside_work", `${given}: outside the workspace`);
23
- }
24
- /**
25
- * pi's file `tools`, each with its confinement's refusal named by the path the call gave, as it gave it:
26
- * `../../.token: outside the workspace`. The confinement names no path itself: pi's tools resolve a path against the
27
- * workspace before they ask for it, so every path it sees is the host's own (`<data>/runs/.token`), and the call's
28
- * `path` is the only one the model gave. A refusal is told by its type (`PathOutsideWorkError`), never by its text; one
29
- * already named (`refuseOutsideWorkspace`), every other error, and every result are the tool's own.
30
- */
31
- export function asGivenRefusals(tools) {
32
- return tools.map((tool) => ({
33
- ...tool,
34
- async execute(args, api, context) {
35
- try {
36
- return await tool.execute(args, api, context);
37
- }
38
- catch (error) {
39
- const reason = error instanceof PathOutsideWorkError ? error.reason : undefined;
40
- const given = args?.path;
41
- if (reason === undefined || error instanceof GivenPathRefusal || typeof given !== "string" || given === "")
42
- throw error;
43
- throw new GivenPathRefusal(given, reason, `${given}: ${error.message}`);
44
- }
45
- },
46
- }));
47
- }
48
8
  /** How a run's rows name a file path, a whole path (never a text): one in the run's directory relative to its workspace
49
9
  * (`<run>/work`: `hello.md`, `.`, `../work 2024/a.md`, `..`), and any other path, or one that is not absolute, exactly
50
10
  * as given. Checked against the workspace as serve names it and as the kernel resolves it (a harness's CLI sends the
@@ -34,8 +34,6 @@ export declare function openWorkFile(work: string, rel: string): Promise<{
34
34
  handle: FileHandle;
35
35
  stats: Stats;
36
36
  }>;
37
- /** `rel` under `work` as text, read as `openWorkFile` reads it. */
38
- export declare function readWorkText(work: string, rel: string): Promise<string>;
39
37
  /** `rel` under `work`, its bytes, read as `openWorkFile` reads it; refused ("over_cap") when larger than `maxBytes`. */
40
38
  export declare function readWorkBytes(work: string, rel: string, { maxBytes }: {
41
39
  maxBytes: number;
@@ -54,18 +52,6 @@ export declare function walkWork(work: string, visit: (path: string, stats: Stat
54
52
  depth?: number;
55
53
  refused?: (path: string, reason: RefusedReason) => void;
56
54
  }): Promise<void>;
57
- /**
58
- * Writes `bytes` to `rel` under `work` whole and durably (files.ts writeDurable), as a file of `mode`: through a temporary
59
- * file in the same directory, a dot-name of the server's own, renamed over the file. The directories on the way are made
60
- * when missing, and each is synced into its parent before this resolves. A link on the way or at the file, or a directory
61
- * there, is refused: never followed and never replaced. Answers the stats of the file this call wrote. `asTool`, a run's
62
- * file tool writing a bound box's work/ (bound-files.ts): a file with another hard link is refused, a file already there
63
- * keeps its mode, and a new one gets `mode` as given, whatever this process's umask.
64
- */
65
- export declare function writeWorkFile(work: string, rel: string, bytes: Uint8Array, mode?: number, asTool?: boolean): Promise<Stats>;
66
- /** Removes the regular file `rel` under `work`, reached through no link: refused when it is missing, a link, or not a
67
- * regular file. A directory it leaves empty stays. */
68
- export declare function removeWorkFile(work: string, rel: string): Promise<void>;
69
55
  /** Throws unless the kernel refuses a hard link to a file the linker cannot write (fs.protected_hardlinks = 1): with a
70
56
  * run's commands under a uid of their own, it keeps them from linking this server's files into their workspace. */
71
57
  export declare function assertHardlinkProtection(read?: () => string): void;
package/dist/workspace.js CHANGED
@@ -4,12 +4,10 @@
4
4
  // check and the open is refused, not followed. On top of it: the path must be the root joined with its own names (a link
5
5
  // anywhere on the way, even one pointing inside the root, is refused), only regular files and directories are read, and a
6
6
  // file with a second hard link is refused, since it could be one of this server's own files linked in.
7
- import { randomBytes } from "node:crypto";
8
7
  import { closeSync, constants, openSync, readFileSync, realpathSync, statSync } from "node:fs";
9
- import { access, lstat, readdir, unlink } from "node:fs/promises";
10
- import { dirname, join } from "node:path";
11
- import { Confinement } from "@parcha/pi-durable-disk/internals";
12
- import { syncDir, writeDurable } from "./files.js";
8
+ import { access, lstat, readdir } from "node:fs/promises";
9
+ import { join } from "node:path";
10
+ import { Confinement } from "./confine.js";
13
11
  /** A path under work/ this server does not read, and why. */
14
12
  export class WorkRefused extends Error {
15
13
  path;
@@ -90,16 +88,6 @@ export async function openWorkFile(work, rel) {
90
88
  await pin.close();
91
89
  }
92
90
  }
93
- /** `rel` under `work` as text, read as `openWorkFile` reads it. */
94
- export async function readWorkText(work, rel) {
95
- const { handle } = await openWorkFile(work, rel);
96
- try {
97
- return await handle.readFile("utf8");
98
- }
99
- finally {
100
- await handle.close();
101
- }
102
- }
103
91
  /** `rel` under `work`, its bytes, read as `openWorkFile` reads it; refused ("over_cap") when larger than `maxBytes`. */
104
92
  export async function readWorkBytes(work, rel, { maxBytes }) {
105
93
  const { handle, stats } = await openWorkFile(work, rel);
@@ -202,87 +190,6 @@ export async function walkWork(work, visit, { skip = () => false, depth = WALK_D
202
190
  };
203
191
  await into("", 0);
204
192
  }
205
- /** A write's or a removal's failure that is a refusal: a link on the way (the confinement's refusal), a directory that
206
- * is missing or this server may not enter, or a file where a directory is on the way (a directory where the file is).
207
- * Any other failure, a full disk say, is thrown as it is. */
208
- const REFUSALS = { permission_denied: "link", ELOOP: "link", ENOENT: "missing", EACCES: "unreadable", ENOTDIR: "not_regular", EISDIR: "not_regular" };
209
- const refusing = (rel) => (error) => {
210
- const reason = error instanceof WorkRefused ? error.reason : REFUSALS[error?.code ?? ""];
211
- throw reason ? new WorkRefused(rel, reason) : error;
212
- };
213
- /** Pins the directory holding `rel` under `work` for writing, every directory on the way reached through no link (and,
214
- * with `parents`, made when missing). Close the pin. */
215
- async function pinForWrite(work, rel, parents) {
216
- if (!writesHeld())
217
- throw new WorkRefused(rel, "unheld");
218
- const { real, confinement } = confinementOf(work);
219
- const abs = join(real, rel);
220
- const refuse = refusing(rel);
221
- // Checked before the walk makes any directory, so none is made through a link.
222
- const { canonical } = await confinement.locate(abs, rel, "write", false).catch(refuse);
223
- if (canonical !== abs)
224
- throw new WorkRefused(rel, "link");
225
- // Whether the walk is to make a directory (the file's own is missing).
226
- const making = parents && !(await lstat(dirname(abs)).catch(() => null));
227
- const pin = await confinement.pinEntry(abs, rel, { access: "write", follow: false, parents }).catch(refuse);
228
- if (pin.canonical !== abs) {
229
- await pin.close();
230
- throw new WorkRefused(rel, "link");
231
- }
232
- return { pin, refuse, real, making };
233
- }
234
- /** What is at the pinned entry, by lstat: nothing (undefined), else a regular file, or refused. */
235
- async function entryOf(pin, refuse, rel) {
236
- const stats = await lstat(pin.entry).catch((error) => (error?.code === "ENOENT" ? undefined : refuse(error)));
237
- if (stats && !stats.isFile())
238
- throw new WorkRefused(rel, stats.isSymbolicLink() ? "link" : "not_regular");
239
- return stats;
240
- }
241
- /**
242
- * Writes `bytes` to `rel` under `work` whole and durably (files.ts writeDurable), as a file of `mode`: through a temporary
243
- * file in the same directory, a dot-name of the server's own, renamed over the file. The directories on the way are made
244
- * when missing, and each is synced into its parent before this resolves. A link on the way or at the file, or a directory
245
- * there, is refused: never followed and never replaced. Answers the stats of the file this call wrote. `asTool`, a run's
246
- * file tool writing a bound box's work/ (bound-files.ts): a file with another hard link is refused, a file already there
247
- * keeps its mode, and a new one gets `mode` as given, whatever this process's umask.
248
- */
249
- export async function writeWorkFile(work, rel, bytes, mode = 0o600, asTool = false) {
250
- const { pin, refuse, real, making } = await pinForWrite(work, rel, true);
251
- try {
252
- const before = await entryOf(pin, refuse, rel);
253
- if (asTool && before && before.nlink !== 1)
254
- throw new WorkRefused(rel, "hard_link");
255
- const kept = asTool && before ? before.mode & 0o777 : mode;
256
- // A link swapped in after that check is replaced by the rename, never written through.
257
- const stats = await writeDurable(pin.entry, bytes, kept, `${pin.dir}/.agentrun-${process.pid}-${randomBytes(6).toString("hex")}.tmp`, asTool).catch(refuse);
258
- // writeDurable synced the file's own directory; a directory made above it survives a crash once its parent is synced.
259
- if (making) {
260
- let at = real;
261
- for (const name of dirname(rel).split("/")) {
262
- await syncDir(at);
263
- at = join(at, name);
264
- }
265
- }
266
- return stats;
267
- }
268
- finally {
269
- await pin.close();
270
- }
271
- }
272
- /** Removes the regular file `rel` under `work`, reached through no link: refused when it is missing, a link, or not a
273
- * regular file. A directory it leaves empty stays. */
274
- export async function removeWorkFile(work, rel) {
275
- const { pin, refuse } = await pinForWrite(work, rel, false);
276
- try {
277
- if (!(await entryOf(pin, refuse, rel)))
278
- throw new WorkRefused(rel, "missing");
279
- // unlink never follows the name it removes: a link swapped in after the check is removed, not its target.
280
- await unlink(pin.entry).catch(refuse);
281
- }
282
- finally {
283
- await pin.close();
284
- }
285
- }
286
193
  /** Throws unless the kernel refuses a hard link to a file the linker cannot write (fs.protected_hardlinks = 1): with a
287
194
  * run's commands under a uid of their own, it keeps them from linking this server's files into their workspace. */
288
195
  export function assertHardlinkProtection(read = () => readFileSync("/proc/sys/fs/protected_hardlinks", "utf8")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-serve",
3
- "version": "0.1.0-beta.33",
3
+ "version": "0.1.0-beta.34",
4
4
  "description": "The AgentRun server: the /v2 API and console over one store, with runners that run your agents; the deployable process of the AgentRun platform.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -54,18 +54,18 @@
54
54
  "@earendil-works/pi-coding-agent": "1.5.0",
55
55
  "@modelcontextprotocol/client": "2.4.0",
56
56
  "@modelcontextprotocol/server": "2.4.0",
57
- "@parcha/agentrun-computer": "0.1.0-beta.33",
58
- "@parcha/agentrun-decisions": "0.1.0-beta.33",
59
- "@parcha/agentrun-dsl": "0.1.0-beta.33",
60
- "@parcha/agentrun-harness-claude": "0.1.0-beta.33",
61
- "@parcha/agentrun-harness-codex": "0.1.0-beta.33",
62
- "@parcha/agentrun-jev": "0.1.0-beta.33",
63
- "@parcha/agentrun-kernel": "0.1.0-beta.33",
64
- "@parcha/agentrun-pi": "0.1.0-beta.33",
65
- "@parcha/pi-browser": "0.1.0-beta.33",
66
- "@parcha/pi-durable-agent": "0.1.0-beta.33",
67
- "@parcha/pi-durable-disk": "0.1.0-beta.33",
68
- "@parcha/pi-transport": "0.1.0-beta.33",
57
+ "@parcha/agentrun-computer": "0.1.0-beta.34",
58
+ "@parcha/agentrun-decisions": "0.1.0-beta.34",
59
+ "@parcha/agentrun-dsl": "0.1.0-beta.34",
60
+ "@parcha/agentrun-harness-claude": "0.1.0-beta.34",
61
+ "@parcha/agentrun-harness-codex": "0.1.0-beta.34",
62
+ "@parcha/agentrun-jev": "0.1.0-beta.34",
63
+ "@parcha/agentrun-kernel": "0.1.0-beta.34",
64
+ "@parcha/agentrun-pi": "0.1.0-beta.34",
65
+ "@parcha/pi-browser": "0.1.0-beta.34",
66
+ "@parcha/pi-durable-agent": "0.1.0-beta.34",
67
+ "@parcha/pi-durable-disk": "0.1.0-beta.34",
68
+ "@parcha/pi-transport": "0.1.0-beta.34",
69
69
  "@secretlint/core": "13.1.0",
70
70
  "@secretlint/profiler": "13.1.0",
71
71
  "@secretlint/secretlint-rule-preset-recommend": "13.1.0",
@@ -77,8 +77,13 @@ Each `evals/<case>/` is one test of the package's agent. No eval runs on the ser
77
77
  "answers": [ { "when": { "path": "README.md" }, "result": { "content": [ { "type": "text", "text": "..." } ] } } ],
78
78
  "default": { "content": [ { "type": "text", "text": "not found" } ], "isError": true } } } }
79
79
  ```
80
- An answer is taken when every argument its `when` lists equals the call's, the first that does; else `default`. Each
81
- `result` is an MCP tool result.
80
+ An answer is taken when every argument its `when` lists equals the call's, the first that does; else `default`. A
81
+ `when` may be a list of such mappings, taken when any one matches (one answer for each spelling of a call: a file by
82
+ `sha` or by `ref`). Each `result` is an MCP tool result. A tool may also hold `search`, `{query, files: [{path,
83
+ text}], limit?, note?}`: a call no answer matches is answered by searching its `query` argument over those files
84
+ (GitHub code search's syntax, read loosely: terms every one of which a file holds, `NOT` before a term or a
85
+ qualifier, and `path:`, `filename:`, `extension:`, `language:`; a `/.../` term is read as literal text, never as a
86
+ regular expression, so no query can stall the eval), as `path:line: text` lines, at most `limit` (100).
82
87
  - `fixtures/`: what the case's fakes and notes read.
83
88
  - `graders/*.md`, each one check of every run, by its front matter's `type`:
84
89
  - `llm`: the body is the rubric a blind grader applies to the answer (or to `target`, one field of the answer's JSON), with the run's tool calls (each with its preview) and the fake MCP servers' calls beside it, so a rubric can check what the run did, not only what it said.
@@ -170,6 +175,7 @@ The report gives each run's cost and each `llm` grade's, as their run records sa
170
175
  | `effort` | The thinking level: `low`, `medium`, `high`, `xhigh` or `max`. |
171
176
  | `tools` | The tools the agent is granted, never an MCP tool (`mcp` grants those). Absent: those the server gives a new agent (its box's shell, where it has a box). |
172
177
  | `mcp` | `[{server, tools, required?, allow?, pin?}]`: MCP servers by the name a server saves them under (Settings → MCP servers), the tools of each the agent uses (each one tool by its name, `A-Z a-z 0-9 _ . -`; never `*`), and `allow`, those of its tools the package asks the owner to allow (`GET /v2/templates` shows each tool with `asks: allow` or `ask`, for a consent screen). Where the server has one saved, apply grants `mcp:<server>/<tool>` for each, beside the other tools, at the owner's own setting: a package never sets a permission. Only the apply's `grants`, the owner's answer, are set to `allow`. Where it has none, apply skips it with a warning (`mcp.<server>`), or, when `required` is true, refuses with `409 agent_not_runnable` and makes nothing. `pin`, optional: `{<tool>: {<argument>: <value>}}`, for tools of the entry, 1 to 8 top-level arguments each, every value a scalar (text, which may be or hold `${parameters.<name>}`, a number, `true`/`false`, or `null` for an argument that must be left out) or a list of 1 to 16 of them, the argument one of the list (`event: [null, COMMENT]`), kept with each value once, null first, then by its JSON text. Apply writes it, filled, as the tool's `pin` in the agent's `tool_settings` (text that is one placeholder alone takes the parameter's value and type), whatever the tool's permission, and the gate refuses any call not as pinned; a pin the server's own settings (Settings → Tools) set for the tool holds too. A pin whose parameter apply is not given sets the tool to `deny` instead, granted or not, with a `pins.mcp:<server>/<tool>` warning. `GET /v2/templates` shows each tool's `pin`, unfilled. |
178
+ | `tool_policy` | `{bash: read-only}`: a policy on the agent's bash, the one tool that takes one. Apply writes it as `policy` on bash in the agent's `tool_settings` (`definition.tool_settings.bash.policy`), whatever bash's permission, and the tool gate reads each shell call's command before it runs or anyone is asked. Under `read-only` it refuses, in words the model reads, any command that could write, run code or read outside the run's folder: a program outside the read list (git's read subcommands `diff`, `show`, `log`, `blame`, `grep`, `ls-files`, `ls-tree`, `rev-parse`, `cat-file`, `merge-base`, `status`, `shortlog`, `rev-list`, `diff-tree`, `name-rev`, `describe`; `grep`, `egrep`, `fgrep`, `rg`, `sed -n 'N,Mp'`, `cat`, `head`, `tail`, `wc`, `nl`, `ls`, `find` without `-exec` or `-delete`, `sort`, `uniq`, `cut`, `tr`, `diff`, `basename`, `dirname`, `echo`, `true`), a redirection other than `2>/dev/null` and `2>&1`, `$` and backticks, a subshell, `\|\|` or a lone `&`, a pipe into anything but a filter (`head`, `tail`, `sed -n`, `grep`, `wc`, `sort`, `uniq`, `cut`, `tr`, `nl`), an unquoted glob (a glob is quoted, and only in a grep pattern, an `--include=` value or a `find -name` value), a path outside the run's folder, or one on the never-open list (`.env*`, `.ssh/`, `id_rsa*`, `*.pem`, `*.key`, `.npmrc`, `.netrc`, `.git-credentials`, `credentials`), which refuses a command that names such a file but is no fence around the folder: a recursive search reads all it holds, the run's own files and never a key of the server's. `git -C <dir>` is allowed to a directory inside the folder. A line with a `cd` joins its commands with `&&` only. `bash_background` and `bash_input` are refused under it. The check reads the command, never the folder, so a symbolic link in the folder reaches what the computer lets it; and it holds bash alone, so a read-only agent's tools are `read` and `bash` (one that may write can change what git obeys). Approvals `never` lifts none of it. A package with `tools` grants `bash` among them. |
173
179
  | `computer` | `default` only, for now: the agent runs where this server puts a new one. |
174
180
  | `parameters` | By name: `{type: string \| number \| integer \| boolean, required?, pattern? (strings), enum?, default?, description}`. `enum` lists a closed set of values, which a form shows as a choice; give it instead of a pattern. The `description` is what a person reads beside the field, never the pattern, so say the format in it ("a Slack channel ID like C0123ABCD"). Apply takes them in `parameters`, and one left out takes its `default`. `display_name`, the body, a trigger's `target.input`, a schedule's `cron` and `timezone` and an `mcp` entry's `pin` values name them as `${parameters.<name>}`, nowhere else. A parameter a schedule uses has a default, and the package's own schedule is checked with it; apply checks every trigger with the parameters given before it makes anything, so a bad cron or zone is a `422` under `triggers.<i>`. |
175
181
  | `secrets` | Variable names (never values) the server must hold: a model or tool key Settings saves (`OPENROUTER_API_KEY`, `PARALLEL_API_KEY`, ...), set where it starts or saved there. Any other name is refused: the server could neither save it nor hand it to a run. Apply refuses with `409 agent_not_runnable`, making nothing, when one is missing. |
@@ -197,7 +203,7 @@ apply. A trigger's date is checked for its form only: one that has passed is ref
197
203
  described as the package, its MCP tools granted where their server is saved, each at the owner's setting (a
198
204
  third-party tool asks by default) and those in `grants` set to `allow`, never one the owner denies on this server
199
205
  (it stays denied, with a `grants.<tool>` warning), each pinned tool with its pin filled (or set to `deny`, with a
200
- `pins.<tool>` warning, when its parameter was not given), its body held to `POST /v2/agents`' 1 MiB limit (`413`), its instructions
206
+ `pins.<tool>` warning, when its parameter was not given), bash's policy from `tool_policy`, its body held to `POST /v2/agents`' 1 MiB limit (`413`), its instructions
201
207
  the body with the parameters filled in, its skills and rules as its skill files, its harness and model chosen as
202
208
  above, `thinking` from `effort`, `max_cost_usd` from `budget`.
203
209
  3. Each trigger is made on the agent through `POST /v2/triggers`' own function. One that still fails (the store, say)
@@ -26,8 +26,8 @@ parameters:
26
26
  topics: { type: string, pattern: "^[^\\n]{0,500}$", description: "optional market keywords, comma-separated (\"payments orchestration, KYB\"): market news on them is in scope too" }
27
27
  channel: { type: string, pattern: "^([CG][A-Z0-9]{8,12}|[^@\\s]+@[^@\\s]+\\.[^@\\s]+)$", description: "where the digest goes, the one destination it is ever posted to: a Slack channel's id (C0123ABCD: in Slack, the channel's details, at the bottom) or an email address. Not a #name. Leave it out to have the digest returned only" }
28
28
  lookback_days: { type: integer, description: "how many days back a run looks; leave it out for 7, the weekly schedule's gap. Set it to your schedule's gap when you change cron (1 for daily), or runs repeat each other's items" }
29
- cron: { type: string, default: "0 8 * * 1", description: "when the digest runs, as a cron line (minute hour day-of-month month day-of-week): Monday 08:00 unless you set it; set lookback_days to its gap" }
30
- timezone: { type: string, default: UTC, description: "the IANA time zone the cron line is read in (Europe/Madrid, America/New_York): UTC unless you set it" }
29
+ cron: { type: string, format: cron, default: "0 8 * * 1", description: "when the digest runs, as a cron line (minute hour day-of-month month day-of-week): Monday 08:00 unless you set it; set lookback_days to its gap" }
30
+ timezone: { type: string, format: timezone, default: UTC, description: "the IANA time zone the cron line is read in (Europe/Madrid, America/New_York): UTC unless you set it" }
31
31
  budget: { per_run_usd: 5.00 }
32
32
  learning: true
33
33
  # Runs unattended (its job runs on triggers): no tool asks; deny and the pins above still hold.