@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
@@ -4,7 +4,7 @@ import type { HostTool, Wire } from "@parcha/agentrun-kernel";
4
4
  import type { Approvals } from "../approvals.js";
5
5
  import type { installSettled } from "../harness-install.js";
6
6
  import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
7
- import type { PinnedModel, Tier } from "../model.js";
7
+ import { type PinnedModel, type Tier } from "../model.js";
8
8
  import { type RunLaunch } from "../run-launch.js";
9
9
  import type { Store } from "../store/store.js";
10
10
  import { type Permission, type RunFiles, type SettingFrom } from "../tool-gate.js";
@@ -13,12 +13,14 @@ import { type ToolHost } from "../tools.js";
13
13
  import { type HostToolCtx } from "../host-tools.js";
14
14
  import { type LearnedWorkflow } from "../learning.js";
15
15
  import { type ToolResults } from "../workspace/run-tools.js";
16
+ import { type ClaimMcp } from "./mcp-run.js";
16
17
  import { type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
17
18
  import { type Claim, type Journal } from "./loop-contract.js";
18
19
  import type { ModelRoute } from "./model-route.js";
19
20
  import { type ArchilClaimOptions } from "../workspace/archil-claim.js";
20
21
  import { type claimComputer, type ComputerDeps } from "../workspace/computer-deps.js";
21
22
  import type { RunComputer } from "../workspace/run-tools.js";
23
+ import type { ShellPlace } from "../workspace/resolve-computer.js";
22
24
  import type { Workspace } from "../workspace/workspace.js";
23
25
  import { type HeldRedact } from "./redact.js";
24
26
  /** What a claim gives the shared computerForClaim: the run, its epoch, its revision, its place and any computer choice. */
@@ -52,10 +54,10 @@ export declare const PI_WIRES: readonly Wire[];
52
54
  /** Whether the runner offers the browser at all: on pi's native route (PiAdapterOptions.extensions), where pi-browser's
53
55
  * durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations). */
54
56
  export declare const BROWSER_ON_RUNNER = true;
55
- /** Whether the runner installs the browser for a run whose revision grants `granted`, fail closed: only on the native route
56
- * (BROWSER_ON_RUNNER), and only with the run's ledger booking on its ToolHost (host.ledger.paid), so no browser call is
57
- * held on this process's own spend. */
58
- export declare const browserListed: (host: Pick<ToolHost, "ledger">, granted: readonly string[]) => boolean;
57
+ /** Whether the runner installs the browser for a run whose revision grants `granted`, or whose computer is a browser
58
+ * (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
59
+ * booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
60
+ export declare const browserListed: (host: Pick<ToolHost, "ledger" | "browserComputer">, granted: readonly string[]) => boolean;
59
61
  /** What the runner hands the spec builder, beside the claim and the loop's own Harness (the AdapterRun): the store (its
60
62
  * agent and run reads, and the live-viewer seam the browser tool writes through), the data directory a Mode 1 run folder
61
63
  * sits in, the model route, and the key the live-viewer tokens are sealed under. One per runner, not per claim. */
@@ -75,6 +77,8 @@ export interface AdapterSpecDeps {
75
77
  readonly routeOf: (model: string | PinnedModel | undefined, env: NodeJS.ProcessEnv, tier?: Tier, wires?: readonly Wire[], upstream?: typeof fetch, redact?: (text: string) => string) => Promise<ModelRoute>;
76
78
  /** The run's log line (what its Workspace and computer have to say that is not a run failure). */
77
79
  readonly log?: (message: string) => void;
80
+ /** For tests: a learning run's grade bound, as a signal (learning-dispatch.ts gradeBound). Default: GRADE_TIMEOUT_MS. */
81
+ readonly gradeBound?: () => AbortSignal;
78
82
  /** The one shared claim-time computer (computer-for-claim.ts), for both the pi and the CLI spec: none for a runner place.
79
83
  * The runner gives it; a test gives its own. */
80
84
  readonly computerForClaim: ComputerForClaim;
@@ -122,8 +126,8 @@ export declare function modelAskOf(pinned: {
122
126
  * The run's gate before a call's intent, as the adapter loop asks it: the revision's tool settings and approvals over the
123
127
  * server's, from the one store (loadToolSettings), through RunGate (decide: deny with its words, a pin, allow, ask). The
124
128
  * adapter loop handles the ask/park/answer on the journal itself, so only the answer is read here, never RunGate's own
125
- * file-based approval flow. `root`: the run's files, the run's Workspace (Mode 2: its folder on the run's disk; the turn's
126
- * origin is read through it, never a folder of this machine) or the local folder's path.
129
+ * file-based approval flow. `root`: the run's folder, the run's Workspace (Mode 2: its folder on the run's disk, never a
130
+ * folder of this machine) or the local folder's path, for the gate's path checks; nothing in it is read.
127
131
  *
128
132
  * The server's settings are read again at each call, from the store (a row of the local store: no cache, no signal from
129
133
  * the server, which may be another process), so a permission set while the run goes reaches its next call ("applies at the
@@ -139,6 +143,11 @@ export type RunPermissions = {
139
143
  readonly policy: (tool: string) => Permission;
140
144
  readonly denyFrom: (tool: string) => SettingFrom;
141
145
  readonly refresh: () => Promise<void>;
146
+ /** The gate's whole decision of one call with its arguments (RunGate.decide: its deny, its argument pins, its ask or a
147
+ * refusal where no one can approve), as the run's own call of the tool gets it: a learned workflow's MCP node's. */
148
+ readonly decide: (tool: string, args: unknown) => Promise<"allow" | "ask" | {
149
+ deny: string;
150
+ }>;
142
151
  };
143
152
  export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pick<Claim, "runId">, revision: {
144
153
  kind: string;
@@ -147,8 +156,9 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
147
156
  harness?: string;
148
157
  approvals?: Approvals;
149
158
  };
150
- }, root: RunFiles): Promise<NonNullable<AdapterRunSpec["gate"]> & {
159
+ }, root: RunFiles, shell?: ShellPlace): Promise<NonNullable<AdapterRunSpec["gate"]> & {
151
160
  readonly permissions: RunPermissions;
161
+ readonly learn: (flows: readonly LearnedWorkflow[]) => void;
152
162
  }>;
153
163
  /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
154
164
  * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
@@ -183,6 +193,9 @@ export declare function learnedWorkflowHostTool(opts: {
183
193
  /** The run's gate's permissions (adapterRunGate): each call node's tool is held to them, as main holds it. */
184
194
  readonly permissions: RunPermissions;
185
195
  readonly ctx: HostToolCtx;
196
+ /** The claim's MCP (mcp-run.ts mcpForClaim), when its revision grants an MCP tool: its call nodes may name its tools by
197
+ * catalog name, each run through the run's own MCP as the loop wraps it. */
198
+ readonly mcp?: Pick<ClaimMcp, "tools" | "catalogOf">;
186
199
  }): Promise<HostTool | undefined>;
187
200
  /** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
188
201
  * hostToolOf): web_fetch, web_search and monid, each by its catalog name under the adapter loop's one gate (`spec.gate`;
@@ -2,10 +2,11 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
2
  import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
3
3
  import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
4
4
  import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
5
+ import { thinkingLevel } from "../model.js";
5
6
  import { firstMessage } from "../run-manifest.js";
6
- import { learningStartOf } from "../run-launch.js";
7
+ import { learningStartOf, seedFailed } from "../run-launch.js";
7
8
  import { isObject } from "../validate.js";
8
- import { runGate } from "../tool-gate.js";
9
+ import { deniedText, noApproverText, runGate } from "../tool-gate.js";
9
10
  import { loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
10
11
  import { readApprovers } from "../server-approvers.js";
11
12
  import { ASK_TOOL, askPerson, toolOf } from "../tools.js";
@@ -18,7 +19,7 @@ import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
18
19
  import { layLearningSeed } from "./learning-seed.js";
19
20
  import { learningWorkspace } from "../learn/folder.js";
20
21
  import { learningEndOfRun } from "./learning-end.js";
21
- import { LEARNED_WORKFLOW_TOOL, learnedWorkflowTool } from "../learned-workflow.js";
22
+ import { learnedAskFits, learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpTools, learnedWorkflowTool } from "../learned-workflow.js";
22
23
  import { PORT_PROVIDER } from "../port-models.js";
23
24
  import { promptOf, readsFiles } from "../skills.js";
24
25
  import { openRunWorkspace } from "../workspace/run-workspace.js";
@@ -28,7 +29,7 @@ import { runTools, withKindTools } from "../workspace/run-tools.js";
28
29
  import { INPUTS_DIR, UPLOADS_DIR, Uploads } from "../uploads.js";
29
30
  import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
30
31
  import { UNREADABLE_SIGN_IN } from "../run-view.js";
31
- import { claimSecrets, withModelKeys } from "./claim-secrets.js";
32
+ import { claimSecrets, learnedDecisionKeys, withModelKeys } from "./claim-secrets.js";
32
33
  import { mcpForClaim } from "./mcp-run.js";
33
34
  import { join } from "node:path";
34
35
  import { hostLifecycle } from "./adapter-loop.js";
@@ -50,10 +51,10 @@ const BROWSER_TOOL = "browser";
50
51
  /** Whether the runner offers the browser at all: on pi's native route (PiAdapterOptions.extensions), where pi-browser's
51
52
  * durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations). */
52
53
  export const BROWSER_ON_RUNNER = true;
53
- /** Whether the runner installs the browser for a run whose revision grants `granted`, fail closed: only on the native route
54
- * (BROWSER_ON_RUNNER), and only with the run's ledger booking on its ToolHost (host.ledger.paid), so no browser call is
55
- * held on this process's own spend. */
56
- export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger?.paid !== undefined && granted.includes(BROWSER_TOOL);
54
+ /** Whether the runner installs the browser for a run whose revision grants `granted`, or whose computer is a browser
55
+ * (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
56
+ * booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
57
+ export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger?.paid !== undefined && (granted.includes(BROWSER_TOOL) || host.browserComputer !== undefined);
57
58
  /** A model as the cap prices it, from the route's catalog cost: its price WITH TIERS (the money rule — a request past a
58
59
  * model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
59
60
  * overhead its provider adds; the output ceiling is the route's when it carries one, else none. */
@@ -78,20 +79,59 @@ export function capModelOf(route) {
78
79
  export function modelAskOf(pinned, ref) {
79
80
  return pinned ? { pinned, ...(ref ? { ref } : {}) } : ref;
80
81
  }
81
- export async function adapterRunGate(store, claim, revision, root) {
82
+ export async function adapterRunGate(store, claim, revision, root, shell) {
82
83
  let current = await storeSettings(store);
83
84
  const approvers = await readApprovers(store.settings);
84
85
  // A Workspace's paths are in the run's folder: its folder named as a computer names it, for the gate's path checks.
85
86
  const folder = typeof root === "string" ? root : COMPUTER_ROOT;
86
- const gate = runGate({ root: folder, work: folder }, claim.runId, revision, () => current, root, approvers);
87
+ // Where the run's shell is (run-tools.ts shell): with no computer, a tool no setting names takes the kernel's ruled
88
+ // default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused.
89
+ const gate = runGate({ root: folder, work: folder, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
90
+ // The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
91
+ let learned = [];
87
92
  const decide = async (call) => {
88
93
  current = await storeSettings(store);
89
- return gate.decide(call.tool, call.args);
94
+ const decision = await gate.decide(call.tool, call.args);
95
+ // A learned workflow's MCP nodes are the run's own MCP calls, held to the same settings, decided for the whole call
96
+ // before any node runs, never mid-run: one set to deny refuses the call in the gate's words, nothing sent; one set to
97
+ // ask asks for the call, up front, on the run's one card (a running workflow can't park mid-call: it is never run
98
+ // again after a crash), and the person's allow lets that call's MCP nodes run, and only that call's.
99
+ // Checked whether the learned_workflow call is itself allowed or asked: a workflow that can't run is never put to a
100
+ // person.
101
+ if (call.tool !== LEARNED_WORKFLOW_TOOL || typeof decision === "object")
102
+ return decision;
103
+ const tools = await mcpOf(call.args);
104
+ const refused = (why) => ({ deny: `The learned workflow ${String(call.args.name)} was not run: ${why}` });
105
+ const denied = tools.find((tool) => gate.policy(tool) === "deny");
106
+ if (denied)
107
+ return refused(deniedText(denied, undefined, gate.denyFrom(denied)));
108
+ const asks = tools.filter((tool) => gate.policy(tool) === "ask");
109
+ // An ask no one can answer (the server's accounts off) is refused at once in the gate's words, never parked.
110
+ if (asks.length && !approvers)
111
+ return refused(noApproverText(asks[0], "no"));
112
+ // A card that could not name every MCP tool the person would approve (past its preview's bound) is never shown: the
113
+ // call is refused, so no allow covers a tool its approver did not see.
114
+ if (asks.length && !learnedAskFits(asks))
115
+ return refused(`its approval card can't name all ${asks.length} MCP tools it would call that are set to ask: set some of them to allow or deny for this agent.`);
116
+ return asks.length ? "ask" : decision;
117
+ };
118
+ /** The MCP tools the learned workflow a learned_workflow call names can call; none for another call or workflow. */
119
+ const mcpOf = async (args) => {
120
+ const flow = learned.find((one) => one.name === args?.name);
121
+ return flow ? learnedMcpTools(flow.workflow) : [];
90
122
  };
91
123
  // An ask is named as main's pending approval is (RunGate.askedAs: its settings key), beside the decision, which is
92
124
  // unchanged. The permissions are the learned workflow's (main's toolGate.policy and denyFrom), over the same settings.
93
- const permissions = { policy: (tool) => gate.policy(tool), denyFrom: (tool) => gate.denyFrom(tool), refresh: async () => { current = await storeSettings(store); } };
94
- return Object.assign(decide, { askedAs: (tool) => gate.askedAs(tool), permissions });
125
+ const permissions = { policy: (tool) => gate.policy(tool), denyFrom: (tool) => gate.denyFrom(tool), refresh: async () => { current = await storeSettings(store); }, decide: (tool, args) => gate.decide(tool, args) };
126
+ // What a learned_workflow call's card shows beside its own input: every MCP tool set to ask that the workflow can call,
127
+ // and that their arguments are decided while it runs, so the person sees what they approve.
128
+ const askedFor = async (tool, args) => {
129
+ if (tool !== LEARNED_WORKFLOW_TOOL)
130
+ return undefined;
131
+ const asks = (await mcpOf(args)).filter((one) => gate.policy(one) === "ask");
132
+ return asks.length ? learnedAskShown(asks) : undefined;
133
+ };
134
+ return Object.assign(decide, { askedAs: (tool) => gate.askedAs(tool), askedFor, permissions, learn: (flows) => void (learned = flows) });
95
135
  }
96
136
  /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
97
137
  * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
@@ -221,9 +261,9 @@ async function adapterSpec(launch, run, deps, claim, holds) {
221
261
  // ask it leaves into an allow). The adapter loop asks `gate` and handles the ask/park/answer on the journal itself, so
222
262
  // only the permission is read here, never runGate's own file-based approval flow.
223
263
  const root = runFolder(deps.data, runRow.agentId, claim.runId);
224
- // The gate reads the run's own files (the turn's origin) through the run's Workspace: in Mode 2, its folder on the run's
225
- // disk, never this machine's folder at the same path.
226
- const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace);
264
+ // The gate names the run's folder by its Workspace (Mode 2: its folder on the run's disk, never this machine's folder at
265
+ // the same path), for its path checks; it reads nothing in it.
266
+ const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell);
227
267
  // The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
228
268
  // uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
229
269
  // launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
@@ -263,47 +303,66 @@ async function adapterSpec(launch, run, deps, claim, holds) {
263
303
  // A learning run's seed, read once from its learning folder where the run's place keeps it: its notes in .learning/
264
304
  // and its learned skills beside the revision's own (runner/learning-seed.ts), cut of the server's secrets, the learned
265
305
  // skills then in the skill list the prompt names, its learned workflows the ones its learned_workflow tool runs. Laid
266
- // before the run's tools are bound. A learning fault lays nothing and the run goes on.
267
- const seedLaid = start
306
+ // before the run's tools are bound. A learning fault, or a seed that failed (seedFailed), lays nothing.
307
+ const seedLaid = start && !seedFailed(start)
268
308
  ? await layLearningSeed({
269
309
  work: ws.workspace,
270
310
  seed: start.seed,
271
311
  folder: () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil })),
272
312
  own: Object.keys(revisionRow.skills ?? {}),
273
- shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data))),
313
+ shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
274
314
  log,
275
315
  })
276
316
  : undefined;
317
+ // The decision keys its learned workflows' typed questions need (claim-secrets.ts learnedDecisionKeys), read once the lay
318
+ // chose them, scoped as the revision's own: each provider the run's gate does not deny, held by the run's one redactor,
319
+ // onto the tools' environment alone. The model's route was built on the revision's keys above, so a decision key never
320
+ // becomes its model's.
321
+ const workflows = seedLaid?.workflows ?? [];
322
+ if (learnsWorkflows(revision.kind, workflows)) {
323
+ const learnedKeys = await learnedDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, workflows, (provider) => gate.permissions.policy(provider) !== "deny");
324
+ holdClaimed(cut, learnedKeys);
325
+ Object.assign(toolEnv, learnedKeys);
326
+ }
277
327
  // The tool host's install lifecycle: what a binding registers to run in each conversation's creating commit, once the
278
328
  // Harness is open before the session, and at the run's end (the browser tool's reconcile and release hang off these). The
279
329
  // adapter loop runs them from the spec's `lifecycle` (adapter-loop.ts hostLifecycle).
280
330
  const life = hostLifecycle();
281
331
  // The ToolHost the non-hand tools (browser, web, MCP, decisions, monid) bind through (buildToolHost, the one the CLI
282
332
  // spec builds too), on the claim's keys and the run's one ledger and redactor.
283
- const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut });
333
+ // An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
334
+ const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
335
+ const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
284
336
  // The run's tools. The hands (read/write/edit/bash and the background tools) are the kernel registry's over the run's
285
337
  // Workspace and computer (runTools.hostTools); the gate is the adapter loop's own (spec.gate), so they run as asked.
286
338
  const results = new Map();
287
- const handTools = tools.hostTools(withKindTools(granted, tools), undefined, results);
339
+ const handTools = tools.hostTools(withKindTools(granted, tools), results);
288
340
  // The non-hand tools run on the claim's keys (host.env), so a vendor's error may echo one: each answer, and a throw's
289
341
  // words, pass the run's one redactor before the harness, the model or the record has them.
290
- const nonHandTools = (await bindNonHandTools(host, revision.kind, granted, run, context, results, root, launch.plane, seedLaid?.workflows ?? [], native, gate.permissions)).map((tool) => answersCut(tool, cut));
342
+ // The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate).
343
+ gate.learn(workflows);
344
+ const nonHandTools = (await bindNonHandTools(host, revision.kind, granted, run, context, results, root, launch.plane, workflows, native, gate.permissions, mcp)).map((tool) => answersCut(tool, cut));
291
345
  const sessionTools = [...handTools, ...nonHandTools];
292
346
  // The run's system prompt, as main's per-run process builds it (app.ts): the environment line first (environment.ts, as
293
347
  // pi installs it before every other section), then the revision's instructions with what the agent learned laid in
294
348
  // (learning.ts laidLearned, from the launch's learning start — the # Learned section decided once at launch, so the runner
295
- // reads no learning folder for it), its own skills through skills.ts promptOf, then the effort guidance (the launch's
296
- // effort, never this process's environment). The one path for every harness.
297
- const laid = start ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
349
+ // reads no learning folder), its own skills through skills.ts promptOf, then the effort guidance (the launch's effort,
350
+ // never this process's environment). The one path for every harness.
351
+ // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
352
+ const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
298
353
  const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, { onDemand: readsFiles(granted) });
299
354
  const guidance = effortGuidance(launch.effort);
300
355
  const system = [environmentLine(), instructions, guidance].filter((line) => Boolean(line));
356
+ // The level pi thinks at: the launch's effort (the run's own, else its revision's, else the host's), every level pi's
357
+ // agent takes; none, pi's default.
358
+ const thinking = thinkingLevel(launch.effort);
301
359
  const session = {
302
360
  key: `run:${claim.runId}`,
303
361
  label: runRow.agentId,
304
362
  system,
305
363
  tools: sessionTools,
306
364
  context: "fresh",
365
+ ...(thinking ? { thinking: thinking } : {}),
307
366
  };
308
367
  // The person's first message: the start body's content, with the run's file manifest beside it (run-manifest.ts), read
309
368
  // through the run's Workspace (Mode 2: its inputs/ on the disk, never a folder of this machine).
@@ -401,7 +460,8 @@ export async function learnedWorkflowHostTool(opts) {
401
460
  return undefined;
402
461
  const flows = opts.workflows;
403
462
  const models = await opts.run.ledger.models(LEARNED_WORKFLOW_TOOL);
404
- const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: models, modelOf: () => ({ provider: PORT_PROVIDER, modelId: "session" }), policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh });
463
+ const mcpTools = (opts.mcp?.tools ?? []).map((one) => opts.mcp.catalogOf(one.name)).filter((name) => typeof name === "string");
464
+ const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: models, modelOf: () => ({ provider: PORT_PROVIDER, modelId: "session" }), policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh, decide: opts.permissions.decide, mcpTools });
405
465
  return hostToolOf(LEARNED_WORKFLOW_TOOL, tool, opts.ctx) ?? undefined;
406
466
  }
407
467
  /** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
@@ -451,11 +511,10 @@ export function answersCut(tool, cut) {
451
511
  export function buildToolHost(opts) {
452
512
  const { root, claim, run, life } = opts;
453
513
  return {
454
- // The run's directory and its per-claim environment. `coding` is the runner's: the hands come from runTools, not from
455
- // a coding source, so the non-hand tools that read it get the run's environment only.
514
+ // The run's directory and its per-claim environment: the hands come from runTools, so the non-hand tools get the run's
515
+ // environment only.
456
516
  where: { root, work: root, ref: { id: claim.runId } },
457
517
  env: opts.env,
458
- coding: { tools: [], extension: { name: "coding", tools: [] } },
459
518
  install: (extension) => run.registry.install(extension),
460
519
  onConversation: life.register.onConversation,
461
520
  beforeResume: life.register.beforeResume,
@@ -463,7 +522,6 @@ export function buildToolHost(opts) {
463
522
  personWait: life.register.personWait,
464
523
  // The run row's summary staged on a commit of the run's (a hand-over's wait, its claim held: run.needs_input).
465
524
  ...(run.rowSummaryOn ? { rowSummaryOn: run.rowSummaryOn } : {}),
466
- handoverInJournal: true,
467
525
  store: opts.store,
468
526
  claim,
469
527
  sealKey: opts.sealKey,
@@ -500,7 +558,7 @@ export async function webHostTools(host, granted, ctx) {
500
558
  }
501
559
  return tools;
502
560
  }
503
- async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions) {
561
+ async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions, mcp) {
504
562
  // Fail closed (browserListed): the browser binds only on the native route (BROWSER_ON_RUNNER) and with the claim's
505
563
  // one-ledger booking on its ToolHost (host.ledger.paid); otherwise its extension is not installed. learned_workflow
506
564
  // binds below with no web tool, so a learned run with no web tool still lists it.
@@ -513,7 +571,7 @@ async function bindNonHandTools(host, kind, granted, run, context, results, root
513
571
  // the session's tools the harness is told of: its model nodes run on the session's proxied models (run.ledger.models),
514
572
  // each a request on the run's one route labelled learned_workflow. The agent's scoped keys (host.env) are its call
515
573
  // nodes'.
516
- const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx });
574
+ const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx, ...(mcp ? { mcp } : {}) });
517
575
  if (learned)
518
576
  tools.push(learned);
519
577
  // The browser (tl-browser), on pi's native route: tools.ts's own binding on this run's ToolHost (its store, claim and seal
@@ -19,6 +19,10 @@ export const RUNNER_HARNESSES = {
19
19
  record: "loop",
20
20
  adapter: async (launch, extra = {}) => {
21
21
  const claude = (await import(CLAUDE_PACKAGE));
22
+ // The CLI the adapter checks, checked first off the event loop: a pass is kept, and the adapter's own check answers
23
+ // from it; a failure is the adapter's to report (warm).
24
+ if (!extra.standIn)
25
+ await claude.verifyClaudeAgentCliAsync(extra.cliPath ?? claude.claudeAgentExecutable());
22
26
  return claude.claudeAgentAdapter({
23
27
  model: launch.model,
24
28
  provider: { origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}) },
@@ -33,6 +37,9 @@ export const RUNNER_HARNESSES = {
33
37
  record: "loop",
34
38
  adapter: async (launch, extra = {}) => {
35
39
  const codex = (await import(CODEX_PACKAGE));
40
+ // Its binary checked first off the event loop, as claude-agent's CLI is (warm): a failure is the adapter's to report.
41
+ if (!extra.standIn)
42
+ await codex.verifyCodexAsync(extra.binary).catch(() => undefined);
36
43
  // Codex's provider is its origin and credential, as serve gives it today (adapters.ts, codexOf): no headers.
37
44
  return codex.codexAdapter({
38
45
  model: launch.model,
@@ -48,7 +55,10 @@ export const RUNNER_HARNESSES = {
48
55
  record: "loop",
49
56
  adapter: async (launch, extra = {}) => {
50
57
  // OpenCode's adapter is serve's own (its pinned binary is checked when the adapter is made); loaded when first asked.
51
- const { openCodeAdapter } = await import("../../harness-opencode/index.js");
58
+ const { openCodeAdapter, verifyOpenCodeAsync } = await import("../../harness-opencode/index.js");
59
+ // Its binary checked first off the event loop, as codex's is (warm): a failure is the adapter's to report.
60
+ if (!extra.standIn)
61
+ await verifyOpenCodeAsync().catch(() => undefined);
52
62
  return openCodeAdapter({
53
63
  model: launch.model,
54
64
  provider: { origin: launch.provider.origin, credential: launch.provider.credential },
@@ -1,9 +1,9 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
2
  import type { Models } from "@earendil-works/pi-ai";
3
3
  import { type Extension, type Harness, type Registry } from "@earendil-works/pi-durable";
4
- import type { AgentAdapter, SessionIO, Wire } from "@parcha/agentrun-kernel";
4
+ import { type AgentAdapter, type SessionIO, type Wire } from "@parcha/agentrun-kernel";
5
5
  import { type ProviderPolicy } from "@parcha/agentrun-kernel/host";
6
- import { CALL_REFUSED } from "@parcha/pi-durable-agent/timeline";
6
+ import { CALL_REFUSED } from "../../timeline/index.js";
7
7
  /** What the adapter loop lends pi for one claim: the run's Harness, its registry, and where pi's models go. */
8
8
  export interface PiRun {
9
9
  readonly harness: Harness;
@@ -101,3 +101,13 @@ export declare function refusalWords(): {
101
101
  } | undefined;
102
102
  readonly held: number;
103
103
  };
104
+ /** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
105
+ * characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
106
+ * default (50 KB or 2,000 lines, its head kept) would cut the end off a host tool's answer, where the answer says how to
107
+ * go on: an MCP answer's "[cut at ...; the whole answer is in the run's files at <path>]", a read's "Use offset=<n> to
108
+ * continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
109
+ * Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
110
+ export declare const HOST_TOOL_OUTPUT: Readonly<{
111
+ maxLines: number;
112
+ maxBytes: number;
113
+ }>;
@@ -2,12 +2,13 @@ import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/conte
2
2
  import { createModels } from "@earendil-works/pi-ai/models";
3
3
  import { defineExtension, defineTool, GenerationTask, hook, ToolTask } from "@earendil-works/pi-durable";
4
4
  import { anthropicPolicy } from "@parcha/agentrun-harness-claude";
5
+ import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
5
6
  import { startModelProxy } from "@parcha/agentrun-kernel/host";
6
7
  import { randomBytes } from "node:crypto";
7
8
  import { DEFAULT_HARNESS } from "../../harness.js";
8
9
  import { sessionProvider } from "../../port-models.js";
9
10
  import { KINDS } from "../journal-kinds.js";
10
- import { CALL_REFUSED } from "@parcha/pi-durable-agent/timeline";
11
+ import { CALL_REFUSED } from "../../timeline/index.js";
11
12
  const PROVIDER = "agentrun-session";
12
13
  const INPUT_REQUEST = "agentrun:input";
13
14
  /** pi as an AgentAdapter for one claim's run. */
@@ -138,7 +139,8 @@ async function sessionOn(proxy, options, spec, io, context) {
138
139
  // session's tools and the run's native extensions, on every open. A conversation a native tool opens takes this agent's
139
140
  // model (pi copies its owner's), so its requests go through this session's proxy.
140
141
  const instructions = spec.system.join("\n\n");
141
- const agent = { model: { provider: PROVIDER, modelId: model }, extensions: [extension, ...native], ...(instructions ? { instructions } : {}) };
142
+ // Its thinking level, the session's (the run's effort), on every open; none leaves pi's default.
143
+ const agent = { model: { provider: PROVIDER, modelId: model }, extensions: [extension, ...native], ...(instructions ? { instructions } : {}), ...(spec.thinking ? { thinkingLevel: spec.thinking } : {}) };
142
144
  const root = await run.harness.root(context, { agent });
143
145
  await root.configure(agent, context);
144
146
  // The run's input submission, if one was placed: its state says where the session is. Answered: idle. Open, or settled
@@ -237,15 +239,24 @@ export function refusalWords() {
237
239
  },
238
240
  };
239
241
  }
240
- /** A host tool as a pi tool: replay-safe or at most once, its answer the host's text and any images it shows. Each call
241
- * gets what pi's own tool task gives a tool: the calling agent's model, resolved in the session's models (its input and
242
- * input limits, which a file read sizes an image by), and pi's output stream (the running tool's live slot). */
242
+ /** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
243
+ * characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
244
+ * default (50 KB or 2,000 lines, its head kept) would cut the end off a host tool's answer, where the answer says how to
245
+ * go on: an MCP answer's "[cut at ...; the whole answer is in the run's files at <path>]", a read's "Use offset=<n> to
246
+ * continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
247
+ * Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
248
+ export const HOST_TOOL_OUTPUT = Object.freeze({ maxLines: HOST_RESULT_MAX_CHARS + 1, maxBytes: HOST_RESULT_MAX_CHARS * 3 });
249
+ /** A host tool as a pi tool: replay-safe or at most once, its answer the host's text and any images it shows, passed
250
+ * whole within the host's bound (HOST_TOOL_OUTPUT). Each call gets what pi's own tool task gives a tool: the calling
251
+ * agent's model, resolved in the session's models (its input and input limits, which a file read sizes an image by),
252
+ * and pi's output stream (the running tool's live slot). */
243
253
  function piTool(tool, io) {
244
254
  return defineTool({
245
255
  name: tool.name,
246
256
  description: tool.description,
247
257
  parameters: tool.inputSchema,
248
258
  replay: tool.replay === "safe" ? "safe" : "unsafe",
259
+ outputLimits: HOST_TOOL_OUTPUT,
249
260
  execute: async (args, api, toolContext) => {
250
261
  io.onEvent({ type: "tool_start", callId: api.callId, name: tool.name, args });
251
262
  const ref = (await api.agent(toolContext)).model;
@@ -1,11 +1,38 @@
1
+ /** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
2
+ export declare const DRAIN_TIMEOUT = "30s";
3
+ /** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
4
+ * number maxRunsOf gives the capabilities' max_concurrent_runs: AGENTRUN_MAX_RUNS, else as many pi runs as this host's
5
+ * memory holds), and on its close lets each held run finish its turn for up to --drain-timeout (default DRAIN_TIMEOUT)
6
+ * before it stops the rest to resume. The server has checked both by the time this reads them (startServe). */
7
+ export declare function besideRunnerOptions(serve: {
8
+ maxRuns?: number;
9
+ drainTimeout?: string;
10
+ }, env: NodeJS.ProcessEnv): {
11
+ loops: number;
12
+ drainMs: number;
13
+ };
14
+ /** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
15
+ * and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
16
+ * the stop of the loops left: runnerCloseBoundMs), so the stop's deadline never cuts a run's end and release short. */
17
+ export declare function besideStopping(server: {
18
+ runs: number;
19
+ boundMs: number;
20
+ }, held: number, drainMs: number): {
21
+ runs: number;
22
+ boundMs: number;
23
+ };
1
24
  /** A runner beside the server on the same data directory (the CLI start's server-and-runner, and the `runner` subcommand):
2
25
  * its own store handle (role runner), and the runner's dispatch (dispatch.ts) for each claimed run — pi on the kernel's
3
26
  * adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
4
- * caller hands its own: the template eval's in-process server, its faux's). Returns the runner and a close() that
5
- * stops it and closes its store. */
6
- export declare function runnerBeside(dataDir: string, { loops, env }?: {
27
+ * caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
28
+ * (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
29
+ * too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
30
+ * closes its store. */
31
+ export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor }?: {
7
32
  loops?: number;
33
+ drainMs?: number;
8
34
  env?: NodeJS.ProcessEnv;
35
+ janitor?: boolean;
9
36
  }): Promise<{
10
37
  runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
11
38
  close: () => Promise<void>;
@@ -1,11 +1,35 @@
1
1
  // A runner beside a server on the same data directory: the CLI start's server-and-runner, the `runner` subcommand and
2
2
  // the template eval's in-process server (template-eval.ts), which would otherwise leave every run it starts queued.
3
+ import { maxRunsOf } from "../host.js";
4
+ import { durationMs } from "../print.js";
5
+ import { runnerCloseBoundMs } from "./runner.js";
6
+ /** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
7
+ export const DRAIN_TIMEOUT = "30s";
8
+ /** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
9
+ * number maxRunsOf gives the capabilities' max_concurrent_runs: AGENTRUN_MAX_RUNS, else as many pi runs as this host's
10
+ * memory holds), and on its close lets each held run finish its turn for up to --drain-timeout (default DRAIN_TIMEOUT)
11
+ * before it stops the rest to resume. The server has checked both by the time this reads them (startServe). */
12
+ export function besideRunnerOptions(serve, env) {
13
+ const drainTimeout = serve.drainTimeout ?? DRAIN_TIMEOUT;
14
+ const drainMs = durationMs(drainTimeout);
15
+ if (drainMs === undefined)
16
+ throw new Error(`the drain timeout ${drainTimeout} is not a duration such as 8s`);
17
+ return { loops: maxRunsOf(env, serve.maxRuns), drainMs };
18
+ }
19
+ /** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
20
+ * and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
21
+ * the stop of the loops left: runnerCloseBoundMs), so the stop's deadline never cuts a run's end and release short. */
22
+ export function besideStopping(server, held, drainMs) {
23
+ return { runs: server.runs + held, boundMs: Math.max(server.boundMs, runnerCloseBoundMs(drainMs)) };
24
+ }
3
25
  /** A runner beside the server on the same data directory (the CLI start's server-and-runner, and the `runner` subcommand):
4
26
  * its own store handle (role runner), and the runner's dispatch (dispatch.ts) for each claimed run — pi on the kernel's
5
27
  * adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
6
- * caller hands its own: the template eval's in-process server, its faux's). Returns the runner and a close() that
7
- * stops it and closes its store. */
8
- export async function runnerBeside(dataDir, { loops, env } = {}) {
28
+ * caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
29
+ * (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
30
+ * too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
31
+ * closes its store. */
32
+ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor } = {}) {
9
33
  const { startRunner } = await import("./runner.js");
10
34
  const { dispatchRunner } = await import("./harness-loops.js");
11
35
  const { routeOf } = await import("./model-route.js");
@@ -36,6 +60,13 @@ export async function runnerBeside(dataDir, { loops, env } = {}) {
36
60
  const { hostAddressesOnce } = await import("../docker-host-addresses.js");
37
61
  const computers = computerDepsFrom({ env: runs, store, sealKey: seal.key, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs) });
38
62
  const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps });
39
- const runner = startRunner({ store, createLoop, ...(loops !== undefined ? { loops } : {}) });
40
- return { runner, close: async () => { await runner.close(); await store.close(); seal.release(); } };
63
+ // It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room.
64
+ const { runnerMemory } = await import("./memory-claim.js");
65
+ const runner = startRunner({ store, createLoop, memory: runnerMemory(store), ...(loops !== undefined ? { loops } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
66
+ // The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
67
+ // runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
68
+ const { startJanitor } = await import("../workspace/computer-janitor.js");
69
+ const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`) }) : undefined;
70
+ // The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
71
+ return { runner, close: async () => { await Promise.all([swept?.close(), runner.close()]); await store.close(); seal.release(); } };
41
72
  }
@@ -1,6 +1,7 @@
1
+ import type { LearnedWorkflow } from "../learning.js";
1
2
  import type { RunLaunch } from "../run-launch.js";
2
3
  import type { SealedKeys } from "../store/store.js";
3
- import type { Revision } from "@parcha/pi-durable-agent";
4
+ import type { Revision } from "../agent-rows.js";
4
5
  /** What claimSecrets reads the keys from: the one store (its sealed keys) and the runner's seal key, and the runner's base
5
6
  * environment (its own, with no server secret in it: those are the store's). */
6
7
  export interface ClaimSecretsDeps {
@@ -15,6 +16,14 @@ export interface ClaimSecretsDeps {
15
16
  * revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
16
17
  * decision provider keys. A fresh object per claim, so no run's keys reach another's. */
17
18
  export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">): Promise<NodeJS.ProcessEnv>;
19
+ /** The decision keys a run's learned workflows need, beside those claimSecrets scoped to its revision (whose own nodes
20
+ * are all needsOf reads, so an agentic run gets none there): the keys of the providers the chosen workflows' typed
21
+ * questions name (decisions.ts providersNamed, Jev for a node that names none), but any provider `allowed` refuses (the
22
+ * run's gate), read as claimSecrets reads its keys and scoped by decisionKeysFor. `workflows`: those the claim's seed
23
+ * lay chose for the run's learned_workflow tool (runner/learning-seed.ts), so this read comes after the lay. A
24
+ * workflow that does not parse or inspect names no provider: the tool refuses it before any node runs. No workflow, or
25
+ * no provider left, reads nothing. A fresh object per call, so no run's keys reach another's. */
26
+ export declare function learnedDecisionKeys(deps: ClaimSecretsDeps, workflows: readonly Pick<LearnedWorkflow, "workflow">[], allowed: (provider: string) => boolean): Promise<Record<string, string>>;
18
27
  /** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
19
28
  export declare const MODEL_KEY_NAMES: readonly string[];
20
29
  /** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept