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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/README.md +393 -118
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/api-only.d.ts +2 -4
  11. package/dist/api-only.js +2 -4
  12. package/dist/attach-conformance.js +5 -4
  13. package/dist/box-paths.d.ts +7 -5
  14. package/dist/box-paths.js +12 -8
  15. package/dist/browser-computer.d.ts +3 -8
  16. package/dist/browser-computer.js +12 -35
  17. package/dist/browser-cost.js +94 -20
  18. package/dist/capacity.d.ts +1 -1
  19. package/dist/capacity.js +3 -3
  20. package/dist/chatgpt-plan.d.ts +5 -0
  21. package/dist/chatgpt-plan.js +25 -11
  22. package/dist/claude-login-token.d.ts +121 -0
  23. package/dist/claude-login-token.js +797 -0
  24. package/dist/claude-login.d.ts +119 -34
  25. package/dist/claude-login.js +551 -79
  26. package/dist/claude-sign-in.d.ts +3 -0
  27. package/dist/claude-sign-in.js +10 -1
  28. package/dist/cli.js +325 -328
  29. package/dist/composio-made.d.ts +1 -6
  30. package/dist/composio-made.js +1 -6
  31. package/dist/composio-owners.d.ts +26 -0
  32. package/dist/composio-owners.js +36 -0
  33. package/dist/composio-preset.d.ts +56 -23
  34. package/dist/composio-preset.js +173 -77
  35. package/dist/composio-triggers.d.ts +4 -4
  36. package/dist/composio-triggers.js +6 -7
  37. package/dist/compute-cost.js +11 -2
  38. package/dist/computer-attach.d.ts +40 -19
  39. package/dist/computer-attach.js +326 -62
  40. package/dist/computer-held-routes.d.ts +1 -1
  41. package/dist/computer-held-routes.js +9 -4
  42. package/dist/computer-keys.d.ts +11 -1
  43. package/dist/computer-keys.js +26 -1
  44. package/dist/computer-record.js +3 -1
  45. package/dist/computer-view.d.ts +5 -3
  46. package/dist/computer-view.js +10 -6
  47. package/dist/computer-viewer.js +36 -7
  48. package/dist/computers.d.ts +12 -11
  49. package/dist/computers.js +11 -8
  50. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  51. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  52. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  53. package/dist/console/assets/share-L84tlUDW.js +6 -0
  54. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  55. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  56. package/dist/console/index.html +4 -3
  57. package/dist/console/share.html +17 -0
  58. package/dist/decisions.d.ts +17 -7
  59. package/dist/decisions.js +41 -15
  60. package/dist/dial-relay.d.ts +25 -4
  61. package/dist/dial-relay.js +139 -5
  62. package/dist/docker-daemon.js +4 -5
  63. package/dist/docker-host-addresses.js +29 -11
  64. package/dist/email/account.d.ts +6 -0
  65. package/dist/email/account.js +6 -0
  66. package/dist/email/authentication.d.ts +21 -0
  67. package/dist/email/authentication.js +106 -0
  68. package/dist/email/email-faux.d.ts +11 -2
  69. package/dist/email/email-faux.js +21 -5
  70. package/dist/email/mail.d.ts +25 -0
  71. package/dist/email/mail.js +58 -2
  72. package/dist/email/names.js +2 -2
  73. package/dist/email/tools.d.ts +9 -4
  74. package/dist/email/tools.js +95 -13
  75. package/dist/env-switch.d.ts +13 -5
  76. package/dist/env-switch.js +24 -6
  77. package/dist/errors.d.ts +1 -0
  78. package/dist/errors.js +2 -0
  79. package/dist/fal-price.d.ts +12 -4
  80. package/dist/fal-price.js +110 -26
  81. package/dist/faux-computers.js +1 -1
  82. package/dist/filed-answer.d.ts +2 -2
  83. package/dist/filed-answer.js +2 -2
  84. package/dist/graph-served.d.ts +10 -5
  85. package/dist/graph-served.js +40 -10
  86. package/dist/handed-values.js +1 -2
  87. package/dist/harness-check.d.ts +2 -1
  88. package/dist/harness-check.js +45 -12
  89. package/dist/harness-keys.js +9 -6
  90. package/dist/harness-opencode/facts.js +2 -0
  91. package/dist/harness-recipe-entry.d.ts +9 -3
  92. package/dist/harness-recipe-entry.js +18 -9
  93. package/dist/harness-recipe.d.ts +21 -0
  94. package/dist/harness-recipe.js +25 -3
  95. package/dist/harness-table.d.ts +8 -0
  96. package/dist/harness-table.js +17 -6
  97. package/dist/helper-env.d.ts +4 -1
  98. package/dist/helper-env.js +4 -1
  99. package/dist/host-check.d.ts +2 -3
  100. package/dist/host-check.js +13 -7
  101. package/dist/hosted-search.js +1 -1
  102. package/dist/import.d.ts +11 -8
  103. package/dist/import.js +437 -186
  104. package/dist/key-refusal.d.ts +9 -2
  105. package/dist/key-refusal.js +86 -32
  106. package/dist/learn/audit.d.ts +8 -5
  107. package/dist/learn/audit.js +15 -7
  108. package/dist/learn/compile.d.ts +5 -2
  109. package/dist/learn/compile.js +45 -21
  110. package/dist/learn/field-check.d.ts +111 -0
  111. package/dist/learn/field-check.js +174 -0
  112. package/dist/learn/ledger.d.ts +173 -0
  113. package/dist/learn/ledger.js +225 -0
  114. package/dist/learn/promote.d.ts +82 -39
  115. package/dist/learn/promote.js +61 -66
  116. package/dist/learn/secrets.d.ts +4 -0
  117. package/dist/learn/secrets.js +12 -0
  118. package/dist/learned-nodes.d.ts +8 -5
  119. package/dist/learned-nodes.js +8 -5
  120. package/dist/learned-workflow.d.ts +2 -1
  121. package/dist/learned-workflow.js +13 -10
  122. package/dist/learning-cost.d.ts +40 -21
  123. package/dist/learning-cost.js +30 -21
  124. package/dist/learning-setting.d.ts +6 -0
  125. package/dist/learning-setting.js +11 -1
  126. package/dist/listen-first.d.ts +5 -4
  127. package/dist/listen-first.js +4 -5
  128. package/dist/live-reach.d.ts +9 -0
  129. package/dist/live-reach.js +9 -0
  130. package/dist/mcp-api-only-origins.d.ts +23 -3
  131. package/dist/mcp-api-only-origins.js +57 -17
  132. package/dist/mcp-gateway.d.ts +16 -2
  133. package/dist/mcp-gateway.js +41 -3
  134. package/dist/mcp-oauth.d.ts +1 -1
  135. package/dist/mcp-oauth.js +3 -2
  136. package/dist/mcp-probe.d.ts +3 -0
  137. package/dist/mcp-probe.js +3 -0
  138. package/dist/mcp-secret-writes.d.ts +24 -2
  139. package/dist/mcp-secret-writes.js +30 -2
  140. package/dist/mcp-servers-store.d.ts +52 -14
  141. package/dist/mcp-servers-store.js +165 -61
  142. package/dist/mcp-sources.d.ts +1 -2
  143. package/dist/mcp-sources.js +1 -2
  144. package/dist/mcp-store.d.ts +5 -5
  145. package/dist/mcp-store.js +3 -3
  146. package/dist/mcp.js +1 -1
  147. package/dist/micro.d.ts +2 -0
  148. package/dist/micro.js +2 -0
  149. package/dist/model-gateway.d.ts +1 -1
  150. package/dist/model-gateway.js +20 -36
  151. package/dist/model.d.ts +5 -4
  152. package/dist/model.js +7 -6
  153. package/dist/monid.d.ts +14 -1
  154. package/dist/monid.js +103 -26
  155. package/dist/ollama-provider.d.ts +23 -9
  156. package/dist/ollama-provider.js +49 -20
  157. package/dist/openapi.js +234 -61
  158. package/dist/otel/genai.d.ts +83 -7
  159. package/dist/otel/genai.js +69 -9
  160. package/dist/otel/tracer.d.ts +42 -13
  161. package/dist/otel/tracer.js +241 -56
  162. package/dist/page.d.ts +7 -1
  163. package/dist/page.js +76 -22
  164. package/dist/paid-calls.d.ts +6 -4
  165. package/dist/paid-calls.js +15 -7
  166. package/dist/place-offers.d.ts +59 -34
  167. package/dist/place-offers.js +100 -58
  168. package/dist/place.d.ts +13 -14
  169. package/dist/place.js +56 -41
  170. package/dist/print.js +1 -1
  171. package/dist/provider.d.ts +5 -4
  172. package/dist/provider.js +26 -13
  173. package/dist/redact/match.d.ts +27 -9
  174. package/dist/redact/match.js +266 -57
  175. package/dist/run-census.d.ts +1 -1
  176. package/dist/run-census.js +4 -5
  177. package/dist/run-cut.js +4 -5
  178. package/dist/run-export-store.d.ts +15 -0
  179. package/dist/run-export-store.js +30 -0
  180. package/dist/run-export.d.ts +139 -0
  181. package/dist/run-export.js +379 -0
  182. package/dist/run-file-cut.d.ts +5 -0
  183. package/dist/run-file-cut.js +13 -0
  184. package/dist/run-launch.js +16 -3
  185. package/dist/run-learning-served.d.ts +2 -2
  186. package/dist/run-model-key.d.ts +15 -6
  187. package/dist/run-model-key.js +30 -31
  188. package/dist/run-reads-over-store.js +4 -4
  189. package/dist/run-secrets.js +3 -5
  190. package/dist/run-timeline-served.js +3 -1
  191. package/dist/run-view.d.ts +1 -2
  192. package/dist/run-view.js +2 -1
  193. package/dist/runnable.js +2 -2
  194. package/dist/runner/adapter-loop.d.ts +35 -18
  195. package/dist/runner/adapter-loop.js +97 -63
  196. package/dist/runner/adapter-run-spec.d.ts +34 -14
  197. package/dist/runner/adapter-run-spec.js +120 -75
  198. package/dist/runner/adapters/pi.js +4 -2
  199. package/dist/runner/audit.d.ts +8 -5
  200. package/dist/runner/audit.js +37 -17
  201. package/dist/runner/beside.d.ts +9 -2
  202. package/dist/runner/beside.js +29 -13
  203. package/dist/runner/claim-secrets.d.ts +27 -18
  204. package/dist/runner/claim-secrets.js +61 -47
  205. package/dist/runner/cli-run-spec.d.ts +18 -0
  206. package/dist/runner/cli-run-spec.js +93 -46
  207. package/dist/runner/compare-end.d.ts +2 -1
  208. package/dist/runner/compare-end.js +25 -10
  209. package/dist/runner/conformance/harness.js +2 -3
  210. package/dist/runner/conformance/subject.d.ts +4 -1
  211. package/dist/runner/harness-loops.js +3 -3
  212. package/dist/runner/held.d.ts +19 -4
  213. package/dist/runner/journal-kinds.d.ts +4 -1
  214. package/dist/runner/journal-kinds.js +22 -4
  215. package/dist/runner/learned-first.js +20 -4
  216. package/dist/runner/learning-end.d.ts +2 -8
  217. package/dist/runner/learning-end.js +11 -19
  218. package/dist/runner/live-ticker.js +7 -5
  219. package/dist/runner/loop-contract.d.ts +0 -2
  220. package/dist/runner/loop.d.ts +7 -0
  221. package/dist/runner/loop.js +1 -0
  222. package/dist/runner/main.d.ts +11 -6
  223. package/dist/runner/main.js +24 -18
  224. package/dist/runner/mcp-claim.js +24 -7
  225. package/dist/runner/mcp-run.d.ts +3 -6
  226. package/dist/runner/mcp-run.js +3 -4
  227. package/dist/runner/meta-tools.js +3 -2
  228. package/dist/runner/metrics.d.ts +7 -0
  229. package/dist/runner/metrics.js +19 -0
  230. package/dist/runner/model-route.d.ts +10 -7
  231. package/dist/runner/model-route.js +79 -15
  232. package/dist/runner/native-loop.js +10 -8
  233. package/dist/runner/presence.d.ts +11 -4
  234. package/dist/runner/presence.js +11 -6
  235. package/dist/runner/promotion.d.ts +25 -13
  236. package/dist/runner/promotion.js +125 -50
  237. package/dist/runner/redact.d.ts +3 -1
  238. package/dist/runner/redact.js +5 -3
  239. package/dist/runner/reflect-hook.js +1 -1
  240. package/dist/runner/responses-fetch.d.ts +36 -0
  241. package/dist/runner/responses-fetch.js +511 -0
  242. package/dist/runner/run-child-host.d.ts +38 -12
  243. package/dist/runner/run-child-host.js +231 -83
  244. package/dist/runner/run-child.js +11 -4
  245. package/dist/runner/runner-check.js +5 -1
  246. package/dist/runner/runner.d.ts +5 -3
  247. package/dist/runner/runner.js +14 -10
  248. package/dist/runner/save-slots.js +2 -1
  249. package/dist/runner/sdk-loop.js +8 -8
  250. package/dist/runner/spec-holds.d.ts +8 -1
  251. package/dist/runner/spec-holds.js +9 -4
  252. package/dist/runner/subagent.d.ts +11 -0
  253. package/dist/runner/subagent.js +17 -3
  254. package/dist/runner/workflow-calls.d.ts +9 -0
  255. package/dist/runner/workflow-calls.js +150 -0
  256. package/dist/runner/workflow-first.d.ts +138 -37
  257. package/dist/runner/workflow-first.js +230 -99
  258. package/dist/runner/workflow-spec.js +2 -2
  259. package/dist/runs-over-store.js +8 -7
  260. package/dist/save-once.d.ts +14 -0
  261. package/dist/save-once.js +31 -0
  262. package/dist/scrub-command.d.ts +34 -31
  263. package/dist/scrub-command.js +116 -147
  264. package/dist/sdk/runs.d.ts +6 -0
  265. package/dist/sdk/runs.js +89 -10
  266. package/dist/seal-key.js +4 -4
  267. package/dist/secret-cut.d.ts +3 -0
  268. package/dist/secret-cut.js +7 -1
  269. package/dist/secret-rules.d.ts +8 -1
  270. package/dist/secret-rules.js +482 -53
  271. package/dist/secrets.d.ts +51 -9
  272. package/dist/secrets.js +311 -21
  273. package/dist/server-keys.d.ts +4 -3
  274. package/dist/server-keys.js +4 -3
  275. package/dist/server-secrets-store.js +2 -4
  276. package/dist/server.d.ts +33 -10
  277. package/dist/server.js +454 -136
  278. package/dist/share-context.d.ts +22 -0
  279. package/dist/share-context.js +76 -0
  280. package/dist/shell-lex.d.ts +105 -0
  281. package/dist/shell-lex.js +646 -0
  282. package/dist/sign-ins-store.d.ts +5 -7
  283. package/dist/sign-ins-store.js +12 -16
  284. package/dist/sign-ins.d.ts +7 -11
  285. package/dist/sign-ins.js +40 -41
  286. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  287. package/dist/slots.d.ts +9 -0
  288. package/dist/slots.js +45 -0
  289. package/dist/start-switches.d.ts +6 -5
  290. package/dist/start-switches.js +8 -4
  291. package/dist/stats.d.ts +5 -1
  292. package/dist/stats.js +1 -1
  293. package/dist/store/agent-body.js +2 -2
  294. package/dist/store/dialect.d.ts +4 -0
  295. package/dist/store/dialect.js +1 -0
  296. package/dist/store/index.d.ts +2 -2
  297. package/dist/store/index.js +1 -1
  298. package/dist/store/mcp-record-keys.d.ts +10 -0
  299. package/dist/store/mcp-record-keys.js +13 -0
  300. package/dist/store/postgres/dialect.js +2 -0
  301. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  302. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  303. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  304. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  305. package/dist/store/postgres/store.js +4 -0
  306. package/dist/store/schema.d.ts +44 -4
  307. package/dist/store/schema.js +111 -11
  308. package/dist/store/seal.d.ts +4 -1
  309. package/dist/store/sqlite/run-launch.d.ts +3 -10
  310. package/dist/store/sqlite/run-launch.js +12 -23
  311. package/dist/store/sqlite/run-patch.d.ts +19 -2
  312. package/dist/store/sqlite/run-patch.js +67 -2
  313. package/dist/store/sqlite/store.d.ts +3 -0
  314. package/dist/store/sqlite/store.js +177 -32
  315. package/dist/store/store-schema.js +3 -4
  316. package/dist/store/store.d.ts +74 -25
  317. package/dist/store/store.js +14 -11
  318. package/dist/store-reads/analytics.d.ts +2 -1
  319. package/dist/store-reads/analytics.js +7 -5
  320. package/dist/store-reads/learning.d.ts +102 -136
  321. package/dist/store-reads/learning.js +251 -302
  322. package/dist/store-reads/stats.d.ts +2 -2
  323. package/dist/store-reads/stats.js +13 -7
  324. package/dist/store-view.js +10 -7
  325. package/dist/suggestions.d.ts +1 -1
  326. package/dist/suggestions.js +29 -13
  327. package/dist/template-eval.d.ts +91 -9
  328. package/dist/template-eval.js +448 -105
  329. package/dist/template-import.d.ts +0 -10
  330. package/dist/template-import.js +5 -10
  331. package/dist/timeline/labels.d.ts +1 -1
  332. package/dist/timeline/labels.js +4 -3
  333. package/dist/timeline/timeline.d.ts +23 -11
  334. package/dist/timeline/timeline.js +115 -31
  335. package/dist/timeline/web-calls.d.ts +14 -14
  336. package/dist/timeline/web-calls.js +18 -30
  337. package/dist/tool-gate.d.ts +13 -1
  338. package/dist/tool-gate.js +43 -3
  339. package/dist/tool-keys-store.js +2 -4
  340. package/dist/tool-keys.d.ts +11 -0
  341. package/dist/tool-keys.js +16 -0
  342. package/dist/tool-plane.d.ts +50 -11
  343. package/dist/tool-plane.js +94 -30
  344. package/dist/tools.d.ts +5 -1
  345. package/dist/tools.js +7 -7
  346. package/dist/trigger-email.js +12 -6
  347. package/dist/triggers.d.ts +15 -34
  348. package/dist/triggers.js +119 -126
  349. package/dist/validate.d.ts +8 -1
  350. package/dist/validate.js +163 -23
  351. package/dist/web-fake.d.ts +2 -1
  352. package/dist/web-fake.js +8 -6
  353. package/dist/web-fetch.d.ts +8 -6
  354. package/dist/web-fetch.js +13 -11
  355. package/dist/web-holds.d.ts +32 -0
  356. package/dist/web-holds.js +86 -0
  357. package/dist/web-run.d.ts +32 -5
  358. package/dist/web-run.js +75 -28
  359. package/dist/web-save.d.ts +4 -9
  360. package/dist/web-save.js +27 -55
  361. package/dist/web-search.js +14 -25
  362. package/dist/wires.d.ts +4 -3
  363. package/dist/wires.js +5 -4
  364. package/dist/workspace/archil-claim.d.ts +12 -5
  365. package/dist/workspace/archil-claim.js +45 -5
  366. package/dist/workspace/attach.js +52 -19
  367. package/dist/workspace/attached-computers.d.ts +38 -11
  368. package/dist/workspace/attached-computers.js +81 -16
  369. package/dist/workspace/computer-deps.d.ts +29 -7
  370. package/dist/workspace/computer-deps.js +36 -18
  371. package/dist/workspace/computer-for-claim.d.ts +21 -4
  372. package/dist/workspace/computer-for-claim.js +166 -57
  373. package/dist/workspace/computer-intervals.d.ts +2 -0
  374. package/dist/workspace/computer-intervals.js +1 -1
  375. package/dist/workspace/computer-janitor.d.ts +48 -14
  376. package/dist/workspace/computer-janitor.js +153 -44
  377. package/dist/workspace/computer-kept.d.ts +158 -32
  378. package/dist/workspace/computer-kept.js +288 -63
  379. package/dist/workspace/computer-providers.d.ts +8 -3
  380. package/dist/workspace/computer-providers.js +12 -5
  381. package/dist/workspace/index.d.ts +1 -1
  382. package/dist/workspace/index.js +1 -1
  383. package/dist/workspace/local.js +41 -1
  384. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  385. package/dist/workspace/mount-revoke-left.js +72 -0
  386. package/dist/workspace/paired-route.d.ts +91 -0
  387. package/dist/workspace/paired-route.js +152 -0
  388. package/dist/workspace/resolve-computer.d.ts +5 -2
  389. package/dist/workspace/resolve-computer.js +9 -3
  390. package/dist/workspace/run-end-computers.d.ts +11 -5
  391. package/dist/workspace/run-end-computers.js +153 -28
  392. package/dist/workspace/run-tools.d.ts +22 -3
  393. package/dist/workspace/run-tools.js +17 -5
  394. package/dist/workspace/run-workspace.d.ts +14 -1
  395. package/dist/workspace/run-workspace.js +34 -1
  396. package/dist/workspace/workspace.d.ts +6 -0
  397. package/dist/wrapped.d.ts +8 -2
  398. package/dist/wrapped.js +21 -6
  399. package/package.json +12 -13
  400. package/skills/agentrun-serve/SKILL.md +5 -2
  401. package/templates/README.md +25 -9
  402. package/dist/console/assets/backend-DVhHzJX2.js +0 -166
  403. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  404. package/dist/console/assets/index-okP-y8PK.js +0 -747
@@ -19,21 +19,25 @@ import { registerRunErrors } from "./run-errors.js";
19
19
  import { remoteSaveSlots } from "./save-slots.js";
20
20
  import { runEnv } from "./main.js";
21
21
  import { carriedLedger } from "../paid-calls.js";
22
+ import { reportHoldsTo } from "../web-holds.js";
22
23
  import { heldHands } from "../workspace/computer-hold.js";
23
- import { flushTraces } from "../otel/tracer.js";
24
+ import { postedTracing } from "../otel/tracer.js";
24
25
  /** How often the run's process reads its loop's held state (LoopDeps.live) and posts it to its runner when it moved: the
25
26
  * runner's live ticker reads the newest it was posted. */
26
27
  const LIVE_POLL_MS = 200;
27
28
  registerRunErrors();
28
29
  const socket = new Socket({ fd: 4, readable: true, writable: true });
29
30
  const channel = new Channel(socket, {
30
- // The runner closed the channel (the loop's end answered) or is gone: nothing of the run's goes on, but its trace's last
31
- // spans are sent first (flushTraces: at most FLUSH_MS, at once when tracing is off).
32
- onClose: () => void setImmediate(() => void flushTraces().finally(() => process.exit(0))),
31
+ // The runner closed the channel (the loop's end answered) or is gone: nothing of the run's goes on. Its trace is the
32
+ // runner's to send (postedTracing): nothing here waits on a collector.
33
+ onClose: () => void setImmediate(() => process.exit(0)),
33
34
  // Each call carries the ledger of the tool call it is made in: what the runner does for it (an MCP tool's call, a
34
35
  // computer's) books on the run's one ledger, as it would in the run's own process.
35
36
  context: carriedLedger,
36
37
  });
38
+ // A keyless hold the run meets is the server's (web-holds.ts): handed to the runner, whose server keeps it. An end JSON
39
+ // cannot carry (none named) goes as null.
40
+ reportHoldsTo((hold) => channel.post("runner", "webHold", [{ ...hold, until: Number.isFinite(hold.until) ? hold.until : null }]));
37
41
  /** A journal's reads for run `runId`, each `call(read, args)` to the runner with the arguments the caller gave but its
38
42
  * context (the runner reads with its own: run-child-host.ts readOf). */
39
43
  function readerOf(runId, call) {
@@ -190,6 +194,9 @@ function childDeps(init, store, journal, held) {
190
194
  ...(init.githubMcpOrigin ? { githubMcpOrigin: init.githubMcpOrigin } : {}),
191
195
  ...(init.composioMcpOrigin ? { composioMcpOrigin: init.composioMcpOrigin } : {}),
192
196
  ...(init.mcpLoopback ? { mcpLoopback: true, mcpOwn: init.mcpOwn ?? [] } : {}),
197
+ // The run's trace, posted to the runner, which exports it: never one of this process's own (no OTLP setting reaches
198
+ // it, and nothing here flushes).
199
+ tracing: Promise.resolve(init.traced ? postedTracing((method, args) => channel.post("trace", method, args)) : undefined),
193
200
  };
194
201
  }
195
202
  let loop;
@@ -28,7 +28,7 @@ import { DOCKER_IMAGE_ENV } from "../box-image.js";
28
28
  import { RunnerLiveRefused, runnerLiveOf } from "../live-reach.js";
29
29
  import { bootSealKey } from "../seal-key.js";
30
30
  import { SECRET_NAMES } from "../secrets.js";
31
- import { SEAL_KEY_ENV } from "../tool-keys.js";
31
+ import { notASealKey, SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
32
32
  import { LAUNCH_HOOK_SECRET_ENV } from "../trigger-launch-hook.js";
33
33
  /** The store.settings key a server keeps the names of its run-facing environment under at each start: `{ v: 1, names }`. */
34
34
  export const RUN_ENV_KEY = "server.run_env";
@@ -173,6 +173,10 @@ export async function checkRunnerEnv(options) {
173
173
  rows.push({ state: given ? "bad" : "missing", name: SEAL_KEY_ENV, why: error?.message ?? String(error) });
174
174
  }
175
175
  }
176
+ else if (given && !sealKeyOf(given)) {
177
+ // A key's shape needs no store: one that is not a key is bad here as the start refuses it, by length, never its value.
178
+ rows.push({ state: "bad", name: SEAL_KEY_ENV, why: `set, but ${notASealKey(given)}` });
179
+ }
176
180
  else
177
181
  rows.push(given ? { state: "skipped", name: SEAL_KEY_ENV, why: "set, and not checked against the store, which did not open" } : { state: "missing", name: SEAL_KEY_ENV, why: "the seal key the store's secrets are sealed under: unset" });
178
182
  const names = store ? await serverRunEnv(store) : undefined;
@@ -1,3 +1,4 @@
1
+ import { type BoundTimer } from "./loop.js";
1
2
  import { type Claim, type LoopEnd, type LoopFactory } from "./loop-contract.js";
2
3
  import { type RunnerStore } from "./store-port.js";
3
4
  import { type RunPatch, type RunState } from "../store/store.js";
@@ -50,6 +51,9 @@ export interface RunnerOptions {
50
51
  * answers on the same row, under the same incarnation): used as is, never closed here. Default: one of its own,
51
52
  * removed at its close. */
52
53
  presence?: Presence;
54
+ /** The incarnation its own presence says (no `presence` given): the runner beside a server runs under the one the
55
+ * server gave it (Serve.beside), which its paired computers' routes name. Default: a new one. */
56
+ incarnation?: string;
53
57
  /** Most runs held at once. */
54
58
  loops?: number;
55
59
  /** How long a claim lasts unless renewed. */
@@ -124,10 +128,8 @@ export interface RunnerOptions {
124
128
  claimGate?: (fresh: boolean) => Promise<string | undefined>;
125
129
  /** For tests: the claim deadline's clock (the deadline a claim not renewed in time is lost at, and the time its claimed
126
130
  * until is reckoned from). Default: the real one. Nothing else in the runner reads it. */
127
- clock?: {
131
+ clock?: BoundTimer & {
128
132
  now(): number;
129
- setTimeout(fn: () => void, ms: number): unknown;
130
- clearTimeout(handle: unknown): void;
131
133
  };
132
134
  }
133
135
  /** A runner's memory budget and its runs' weights, in MiB (RunnerOptions.memory). `weigh` answers each id it is given; an
@@ -17,6 +17,7 @@ import { HELD_COMMANDS } from "../computer-held.js";
17
17
  import { HAND_BACK } from "./hand-back.js";
18
18
  import { KINDS, withdrawnAnswers } from "./journal-kinds.js";
19
19
  import { journalEntries } from "./journal-reader.js";
20
+ import { REAL_TIMER } from "./loop.js";
20
21
  import { ClaimRefused, stopEnd } from "./loop-contract.js";
21
22
  import { FrameTooLarge } from "./run-channel.js";
22
23
  import { isFenced } from "./store-port.js";
@@ -28,7 +29,7 @@ import { keptBy, readKept } from "../workspace/computer-kept.js";
28
29
  import { cutDeep, heldRedactor, processSecretRedactor } from "./redact.js";
29
30
  import { withLiveTicker } from "./live-ticker.js";
30
31
  import { keepPresence } from "./presence.js";
31
- import { flushTraces } from "../otel/tracer.js";
32
+ import { flushTraces, genAiTracing } from "../otel/tracer.js";
32
33
  /** Tries of the re-read after a claim or release commit was answered Unanswered (the commit may have landed). */
33
34
  const UNKNOWN_READS = 5;
34
35
  /** Passes of the sweep after a claim answered Unanswered: the commit may still be on its way when the first read comes back
@@ -85,10 +86,13 @@ const message = (error) => (error instanceof Error ? error.message : String(erro
85
86
  /** The run states a run patch makes final: a commit that lands one is the run's end, and its release. */
86
87
  const FINAL = new Set(["ended", "stopped", "failed"]);
87
88
  export function startRunner(options) {
88
- const { store, createLoop, name = runnerName(), loops = RUNNER_LOOPS, leaseMs = RUNNER_LEASE_MS, renewEveryMs = RUNNER_RENEW_EVERY_MS, stopMarginMs = RUNNER_STOP_MARGIN_MS, pollMs = 1_000, commandPollMs = 500, resumeTries = 3, resumeBackoffMs = 5_000, interruptBackoffMs = 1_000, unknownBackoffMs = 200, endWaitMs = 5_000, drainMs = 0, memory, census, censusMs = CENSUS_MS, endRetryBackoffMs = END_RETRY_BACKOFF_MS, endRetryCapMs = END_RETRY_CAP_MS, endRetryAtCap = END_RETRY_AT_CAP, onEvent = () => { }, runEnded, redact: given = processSecretRedactor(), now = Date.now, onBeat = () => { }, clock = { now: () => Date.now(), setTimeout: (fn, ms) => setTimeout(fn, ms), clearTimeout: (handle) => clearTimeout(handle) }, } = options;
89
+ const { store, createLoop, name = runnerName(), loops = RUNNER_LOOPS, leaseMs = RUNNER_LEASE_MS, renewEveryMs = RUNNER_RENEW_EVERY_MS, stopMarginMs = RUNNER_STOP_MARGIN_MS, pollMs = 1_000, commandPollMs = 500, resumeTries = 3, resumeBackoffMs = 5_000, interruptBackoffMs = 1_000, unknownBackoffMs = 200, endWaitMs = 5_000, drainMs = 0, memory, census, censusMs = CENSUS_MS, endRetryBackoffMs = END_RETRY_BACKOFF_MS, endRetryCapMs = END_RETRY_CAP_MS, endRetryAtCap = END_RETRY_AT_CAP, onEvent = () => { }, runEnded, redact: given = processSecretRedactor(), now = Date.now, onBeat = () => { }, clock = { now: () => Date.now(), ...REAL_TIMER }, } = options;
89
90
  // The one instance every run's loop gets (LoopDeps.redact), able to hold what each claim opens from the store
90
91
  // (redact.ts holdClaimed): a stored key is cut wherever a key of the runner's environment is.
91
92
  const redact = heldRedactor(given);
93
+ // The process's tracing, made at its runner's start rather than at its first claim: on, it says so then, and where its
94
+ // spans go (otel/tracer.ts); off (no OTLP endpoint), nothing of OpenTelemetry loads and nothing is said.
95
+ void genAiTracing().catch(() => undefined);
92
96
  /** The first try whose wait is the cap (endRefused): 7 with the defaults (5 s × 2^6 = 320 s, over the 300 s cap). */
93
97
  const endRetryCapFrom = 1 + Math.ceil(Math.log2(endRetryCapMs / endRetryBackoffMs));
94
98
  const beat = () => {
@@ -637,8 +641,7 @@ export function startRunner(options) {
637
641
  return false;
638
642
  try {
639
643
  const kept = await readKept(store.settings, claim.runId);
640
- const ours = (options.presence ?? presence)?.incarnation;
641
- return kept?.runner !== undefined && !keptBy(kept, ours ? { runner: name, incarnation: ours } : undefined);
644
+ return kept?.runner !== undefined && !keptBy(kept, incarnation ? { runner: name, incarnation } : undefined);
642
645
  }
643
646
  catch {
644
647
  return true;
@@ -811,9 +814,8 @@ export function startRunner(options) {
811
814
  let heldNow;
812
815
  // This runner's process as its word in the store names it (presence.ts), for the claim's computer: a park that keeps one
813
816
  // only this runner can reach again pins it to this runner and this incarnation (computer-kept.ts pinnedOf).
814
- const ours = (options.presence ?? presence)?.incarnation;
815
817
  const loop = loopsOf({
816
- ...(ours ? { incarnation: ours } : {}),
818
+ ...(incarnation ? { incarnation } : {}),
817
819
  journal: (forClaim) => fenced(store.journal(forClaim), fence, forClaim.runId, () => ending()),
818
820
  flush: () => store.flush(),
819
821
  signal: abort.signal,
@@ -969,8 +971,9 @@ export function startRunner(options) {
969
971
  // - a parked run stopped or cancelled whose computer its park kept pinned to another runner, or whose kept row can't
970
972
  // be read (keptElsewhere): the store gives a stop to any runner at once, never waiting on the pin, and this
971
973
  // runner can't reach that machine.
972
- // A loop would take the kept row (takeKept) and try to attach it, orphaning it on that runner's host; ending here
973
- // leaves the row that runner's, whose own timer at its time, or its janitor once the run is final, ends it.
974
+ // A loop would take the kept row (takeKept) and try to attach it, orphaning it on that runner's host. Ending here,
975
+ // the run's end marks the row ending (run-end-computers.ts endingKept) before it deletes what its provider lists,
976
+ // so no follow-up claim takes that machine back; that runner's own timer at its time, or its janitor, ends the row.
974
977
  // One read of those claims' rows, made only when the batch has a queued or a released run.
975
978
  const reread = claims.filter((claim) => claim.from === "queued" || claim.from === "running" || claim.from === "parked");
976
979
  const rows = reread.length ? await store.commandsOf(reread.map((claim) => ({ runId: claim.runId, after: 0 }))) : new Map();
@@ -1117,7 +1120,9 @@ export function startRunner(options) {
1117
1120
  };
1118
1121
  // Its word in the store that a runner that claims is here (presence.ts), for as long as it runs: a server reads a
1119
1122
  // refusal left by an earlier runner as over once this is there. One its caller keeps is its caller's to close.
1120
- const presence = options.presence ? undefined : store.runners ? keepPresence(store.runners, name, null, { warn: (line) => emit({ type: "error", step: "presence", message: line }), slots: loops }) : undefined;
1123
+ const presence = options.presence ? undefined : store.runners ? keepPresence(store.runners, name, null, { warn: (line) => emit({ type: "error", step: "presence", message: line }), slots: loops, ...(options.incarnation ? { incarnation: options.incarnation } : {}) }) : undefined;
1124
+ // Its incarnation, read once here before the first poll: each claim's computer and the stop's kept-row check use it.
1125
+ const incarnation = (options.presence ?? presence)?.incarnation;
1121
1126
  poll();
1122
1127
  commandTimer = setTimeout(deliverAll, commandPollMs);
1123
1128
  // A run queued in this process is claimed now (claimNow). A command written for a run this runner holds is handed on
@@ -1190,7 +1195,6 @@ export function startRunner(options) {
1190
1195
  for (const held of runs.values())
1191
1196
  clock.clearTimeout(held.deadline);
1192
1197
  };
1193
- const incarnation = (options.presence ?? presence)?.incarnation;
1194
1198
  return {
1195
1199
  name,
1196
1200
  ...(incarnation ? { incarnation } : {}),
@@ -69,7 +69,8 @@ export function remoteSaveSlots(channel) {
69
69
  waiting++;
70
70
  let release;
71
71
  try {
72
- release = await channel.call(TARGET, "take", [signal]);
72
+ // The channel takes a slot under a signal: with none given, one that never aborts (Slots.take waits until free).
73
+ release = await channel.call(TARGET, "take", [signal ?? new AbortController().signal]);
73
74
  }
74
75
  finally {
75
76
  waiting--;
@@ -10,7 +10,7 @@ import { refusedIn } from "../purged-workflow.js";
10
10
  import { said, STOPPED } from "../learning-words.js";
11
11
  import { cliPolicyOf, closeSdkInbox, sdkInbox } from "../sdk/runs.js";
12
12
  import { settleSdkCheck } from "../sdk/check.js";
13
- import { runPathOverStore } from "../store-reads/learning.js";
13
+ import { runPathMetricsOverStore } from "../store-reads/learning.js";
14
14
  import { capSpendOf, learningEndOfRun } from "./learning-end.js";
15
15
  import { AskOverCap, bookedAsk } from "./sdk-ask.js";
16
16
  import { reflectRequestId, reflectRoundId } from "./end-of-run.js";
@@ -18,9 +18,8 @@ import { journalEntries } from "./journal-reader.js";
18
18
  import { capNowOf, KINDS } from "./journal-kinds.js";
19
19
  import { bookedSpend } from "./metrics.js";
20
20
  import { stopEnd } from "./loop-contract.js";
21
- import { END_PATCH_MS, END_PATCH_UNKNOWN } from "./loop.js";
21
+ import { END_PATCH_MS, END_PATCH_UNKNOWN, REAL_TIMER } from "./loop.js";
22
22
  import { storeSecrets } from "./store-secrets.js";
23
- import { pathMetrics } from "./workflow-first.js";
24
23
  const ROOT = ROOT_CONVERSATION_ID;
25
24
  export function createSdkLoop(launch, host, route) {
26
25
  const execution = launch.cli_learning ?? launch.sdk;
@@ -115,9 +114,10 @@ export function createSdkLoop(launch, host, route) {
115
114
  // The end keeps cost and path together, under the same bound as the other loops. A failed or late read
116
115
  // leaves both unknown; the completed backend task is still completed. No read writes after this end.
117
116
  const patchOf = async (read) => {
117
+ const bound = host.endPatchTimer ?? REAL_TIMER;
118
118
  let timer;
119
119
  const late = new Promise((resolve) => {
120
- timer = setTimeout(() => resolve(END_PATCH_UNKNOWN), END_PATCH_MS);
120
+ timer = bound.setTimeout(() => resolve(END_PATCH_UNKNOWN), END_PATCH_MS);
121
121
  });
122
122
  try {
123
123
  endPatch = await Promise.race([read(), late]);
@@ -126,7 +126,7 @@ export function createSdkLoop(launch, host, route) {
126
126
  endPatch = END_PATCH_UNKNOWN;
127
127
  }
128
128
  finally {
129
- clearTimeout(timer);
129
+ bound.clearTimeout(timer);
130
130
  }
131
131
  // A stop during the reads owns this end too. The catch below takes its row with the patch just read;
132
132
  // claim loss or shutdown instead leaves the durable SDK completion for the next claim.
@@ -405,10 +405,10 @@ export function createSdkLoop(launch, host, route) {
405
405
  const spend = bookedSpend(entries.map(({ kind, conversationId, data }) => ({ kind, conversationId, data })), "model");
406
406
  const turns = entries.filter((entry) => entry.kind === "runner.turn").map((entry) => entry.data).filter((turn) => !turn.givenBack && !turn.unsent);
407
407
  const tokens = (key) => spend.unmetered || turns.some((turn) => typeof turn.usage?.[key] !== "number") ? null : spend.tokens[key];
408
- const classified = completeEvidence && launch.learning ? await runPathOverStore(host.store, claim.runId, launch.learning) : undefined;
408
+ const path = completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch) : {};
409
409
  return {
410
410
  costUsd: spend.usd,
411
- metrics: { ...metrics, input: tokens("input"), output: tokens("output"), cacheRead: tokens("cacheRead"), cacheWrite: tokens("cacheWrite"), ...(completeEvidence ? pathMetrics(launch, classified, entries) : {}) },
411
+ metrics: { ...metrics, input: tokens("input"), output: tokens("output"), cacheRead: tokens("cacheRead"), cacheWrite: tokens("cacheWrite"), ...path },
412
412
  };
413
413
  });
414
414
  await append([{ kind: KINDS.end, data: { state: "ended", answer: result.answer } }], {
@@ -424,7 +424,7 @@ export function createSdkLoop(launch, host, route) {
424
424
  also = droppedLearning(cancelled);
425
425
  const patch = await patchOf(async () => ({
426
426
  costUsd: usage?.cost_usd ?? null,
427
- metrics: { ...metrics, ...(completeEvidence ? pathMetrics(launch, launch.learning ? await runPathOverStore(host.store, claim.runId, launch.learning) : undefined) : {}) },
427
+ metrics: { ...metrics, ...(completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch) : {}) },
428
428
  }));
429
429
  await append([
430
430
  {
@@ -15,8 +15,14 @@ type Held = {
15
15
  park?(cause: ParkCause): Promise<boolean>;
16
16
  readonly keeps?: string;
17
17
  };
18
+ /** Whether this claim's gate turned the run's computer off for the rest of the run (RunGate.computerOff): a park lets
19
+ * it go instead of keeping it, since no later claim of the run attaches it. */
20
+ readonly computerOff?: () => boolean;
21
+ /** The claim's Archil step: its revoke at an end that keeps nothing, and where that fails, its remove left for the
22
+ * janitor (ArchilClaim.leave). */
18
23
  readonly archil?: {
19
24
  revoke(): Promise<void>;
25
+ leave?(): Promise<void>;
20
26
  } | undefined;
21
27
  readonly ws?: {
22
28
  end(): Promise<void>;
@@ -47,7 +53,8 @@ export declare class SpecHolds {
47
53
  * Workspace's end, the CLI's scratch, then the claim's keys where they are held. A second call waits for the first and
48
54
  * does nothing more. At a park (`parked`, its cause), a computer that keeps (a desktop, a phone or a sandbox) is kept
49
55
  * for the resume first: the tools' end is left out (the processes they started and their output live on it) and so is
50
- * the revoke (its mount writes on); a keep that fails lets it go as above. */
56
+ * the revoke (its mount writes on); a keep that fails lets it go as above, as does a park of a computer this claim's
57
+ * gate turned off (computerOff). */
51
58
  release(how?: {
52
59
  readonly parked?: ParkCause;
53
60
  }): Promise<void>;
@@ -19,7 +19,8 @@ export class SpecHolds {
19
19
  * Workspace's end, the CLI's scratch, then the claim's keys where they are held. A second call waits for the first and
20
20
  * does nothing more. At a park (`parked`, its cause), a computer that keeps (a desktop, a phone or a sandbox) is kept
21
21
  * for the resume first: the tools' end is left out (the processes they started and their output live on it) and so is
22
- * the revoke (its mount writes on); a keep that fails lets it go as above. */
22
+ * the revoke (its mount writes on); a keep that fails lets it go as above, as does a park of a computer this claim's
23
+ * gate turned off (computerOff). */
23
24
  release(how) {
24
25
  return (this.#released ??= this.#releaseAll(how?.parked));
25
26
  }
@@ -46,7 +47,7 @@ export class SpecHolds {
46
47
  async #releaseAll(parked) {
47
48
  const { computer, archil, ws, scratch, keys } = this.#held;
48
49
  const log = this.#log;
49
- const kept = parked !== undefined && computer?.keeps !== undefined && computer.park
50
+ const kept = parked !== undefined && computer?.keeps !== undefined && computer.park && this.#held.computerOff?.() !== true
50
51
  ? await computer.park(parked).catch((error) => {
51
52
  log(`the run's computer could not be kept: ${words(error)}`);
52
53
  return false;
@@ -58,8 +59,12 @@ export class SpecHolds {
58
59
  else
59
60
  await this.endCheckout();
60
61
  await computer?.release().catch((error) => log(`the run's computer could not be let go: ${words(error)}`));
61
- if (!kept)
62
- await archil?.revoke().catch((error) => log(`the run's Archil mount credential could not be revoked: ${words(error)}`));
62
+ if (!kept) {
63
+ await archil?.revoke().catch(async (error) => {
64
+ log(`the run's Archil mount credential could not be revoked: ${words(error)} (its remove is left for the janitor's next pass)`);
65
+ await archil.leave?.().catch((left) => log(`the run's Archil mount credential's remove could not be left for the janitor, so it lapses at its ttl: ${words(left)}`));
66
+ });
67
+ }
63
68
  await ws?.end().catch((error) => log(`the run's workspace end failed: ${words(error)}`));
64
69
  await scratch?.sweep().catch((error) => log(`the run's scratch folder could not be swept: ${words(error)}`));
65
70
  keys?.release();
@@ -4,6 +4,17 @@ export declare const SUBAGENT_TOOL = "subagent";
4
4
  * none runs its child on the agent's own model. */
5
5
  export declare const SUBAGENT_TIERS: readonly ["fast", "strong"];
6
6
  export type SubagentTier = (typeof SUBAGENT_TIERS)[number];
7
+ /** The subagent tiers a run routes a model on, with the model its revision names for each: a tier its revision's
8
+ * modelTiers names (a string), else one `env`'s tier variable names (AGENT_MODEL_FAST, AGENT_MODEL_STRONG: tierModelOf),
9
+ * and no other. The one answer for the runner that hands a run's process its tiers' saved model keys (run-child-host.ts
10
+ * heldFor), for the run that routes the tiers (adapter-run-spec.ts) and for a replay's grader on the fast tier, so a
11
+ * tier is never routed with no key handed for it, nor a key handed for a tier no route reads. */
12
+ export declare function routedSubagentTiers(body: {
13
+ readonly modelTiers?: unknown;
14
+ }, env: NodeJS.ProcessEnv): {
15
+ readonly tiers: SubagentTier[];
16
+ readonly refs: Partial<Record<SubagentTier, string>>;
17
+ };
7
18
  /** How many of a run's children work at once; a call past it waits for a slot. */
8
19
  export declare const SUBAGENT_PARALLEL = 4;
9
20
  /** A child's instructions: the call's prompt is its whole task. Nothing of the parent's prompt is carried over. */
@@ -1,7 +1,8 @@
1
1
  import { configure, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
2
2
  import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
3
+ import { tierModelOf } from "../model.js";
3
4
  import { ASK_TOOL } from "../tools.js";
4
- import { saveSlots } from "../web-save.js";
5
+ import { slots } from "../slots.js";
5
6
  import { durableWait } from "../workflow/pi-versions.js";
6
7
  import { HOST_TOOL_OUTPUT } from "./adapters/pi.js";
7
8
  import { cutAtLimit } from "./loop-contract.js";
@@ -10,6 +11,19 @@ export const SUBAGENT_TOOL = "subagent";
10
11
  /** The tiers a call may name for its child (its definition's model_tiers, else this server's tier); a call that names
11
12
  * none runs its child on the agent's own model. */
12
13
  export const SUBAGENT_TIERS = ["fast", "strong"];
14
+ /** The subagent tiers a run routes a model on, with the model its revision names for each: a tier its revision's
15
+ * modelTiers names (a string), else one `env`'s tier variable names (AGENT_MODEL_FAST, AGENT_MODEL_STRONG: tierModelOf),
16
+ * and no other. The one answer for the runner that hands a run's process its tiers' saved model keys (run-child-host.ts
17
+ * heldFor), for the run that routes the tiers (adapter-run-spec.ts) and for a replay's grader on the fast tier, so a
18
+ * tier is never routed with no key handed for it, nor a key handed for a tier no route reads. */
19
+ export function routedSubagentTiers(body, env) {
20
+ const named = (body.modelTiers ?? {});
21
+ const refs = {};
22
+ for (const tier of SUBAGENT_TIERS)
23
+ if (typeof named[tier] === "string")
24
+ refs[tier] = named[tier];
25
+ return { tiers: SUBAGENT_TIERS.filter((tier) => refs[tier] !== undefined || tierModelOf(env, tier) !== undefined), refs };
26
+ }
13
27
  /** How many of a run's children work at once; a call past it waits for a slot. */
14
28
  export const SUBAGENT_PARALLEL = 4;
15
29
  /** Tools no child is given: a subagent of its own (depth 1), and the person, whom only the run's own conversation asks. */
@@ -51,7 +65,7 @@ export function chosenTools(asked, options) {
51
65
  /** The subagent tool: one of the session's own tools (adapters/pi.ts `tools`), so it needs no extension of its own. */
52
66
  export function subagentTool(options) {
53
67
  // The run's children's slots (SUBAGENT_PARALLEL), handed out in call order.
54
- const free = saveSlots(SUBAGENT_PARALLEL);
68
+ const free = slots(SUBAGENT_PARALLEL);
55
69
  return defineTool({
56
70
  name: SUBAGENT_TOOL,
57
71
  description: `Run a subagent: a fresh conversation that starts with nothing but your prompt, on your own model (or the model tier you name: ${SUBAGENT_TIERS.join(" or ")}), with only the tools you list (a subset of your own), and get its final answer back as text. Write the prompt self-contained: the subagent sees none of your conversation. Several calls in one turn run at once, at most ${SUBAGENT_PARALLEL} at a time; more wait their turn. A subagent cannot start subagents of its own.`,
@@ -96,7 +110,7 @@ export function subagentTool(options) {
96
110
  const missing = [...names].filter((name) => !tools.some((registration) => registration.name === name));
97
111
  if (missing.length)
98
112
  return fail(`subagent: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not bound in this run, so no subagent may have ${missing.length === 1 ? "it" : "them"}. Nothing ran.`);
99
- const release = await free.take(context.abortSignal ?? new AbortController().signal);
113
+ const release = await free.take(context.abortSignal);
100
114
  try {
101
115
  const child = await api.commit(async (tx) => {
102
116
  // The ownership index remembers the child: a rerun of this call reuses it.
@@ -0,0 +1,9 @@
1
+ import { type WorkflowCall } from "../learning-cost.js";
2
+ import type { EntryLike } from "../timeline/index.js";
3
+ /** Each learned workflow call run `entries` show (every conversation's, in log order: store-reads/journal.ts runEntries),
4
+ * in the order the calls first kept a record, from the record that counts for each (a call run again after a park or a
5
+ * crash keeps one each time: learnedCallEntries): its workflow, digest and caller, how it ended, and what it booked (callUsdOf). The
6
+ * platform's call ends as the run's WORKFLOW_FIRST entry says (its answer shaped, or taken back to the agent); one a
7
+ * crash cut before its record was kept is that entry's alone, its cost unknown. A call its record says was refused
8
+ * before any node ran (`refused`) is `refused`, whoever called it. A record that names no digest or caller is left out. */
9
+ export declare function workflowCallsOf(entries: readonly EntryLike[]): WorkflowCall[];
@@ -0,0 +1,150 @@
1
+ // A run's learned workflow calls, each from its own record: the learned_workflow tool keeps one entry beside each call
2
+ // it ends (learned-nodes.ts LEARNED_NODES: the workflow, its digest, who called it, how it ended, the nodes that ran),
3
+ // whoever called it, the platform before the agent's first turn (WORKFLOW_FIRST_CALL) or the agent itself. A run's
4
+ // metrics keep the calls as `workflow_calls` (workflow-first.ts pathMetrics), which the ledger row and the money rule
5
+ // read: a run the platform served first counts on that workflow's served side alone, one only the agent called on the
6
+ // side of each workflow it ran (workflow-first.ts costLineOf), and a call refused before any node ran on none.
7
+ import { WORKFLOW_CALLERS } from "../learning-cost.js";
8
+ import { learnedCallEntries } from "../learned-nodes.js";
9
+ import { KINDS } from "./journal-kinds.js";
10
+ import { callCostOf } from "./metrics.js";
11
+ import { WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
12
+ const dataOf = (entry) => (entry.data ?? {});
13
+ const callIdOf = (entry) => {
14
+ const id = entry.data?.callId;
15
+ return typeof id === "string" ? id : undefined;
16
+ };
17
+ /** How a call's record says it ended (LearnedEnded) in WorkflowCall's words: none said is a call stopped or thrown. */
18
+ const outcomeOf = (ended) => (ended === "complete" ? "answered" : ended === "escalated" ? "handed_back" : "failed");
19
+ /** Whether call `id` is `callId` itself or a call nested in it (`callId/...`). */
20
+ const within = (id, callId) => id === callId || id.startsWith(`${callId}/`);
21
+ /** The toolCall ids a pi answer (`pi.assistant`, its message the entry's model[0]) asked for: pi keeps no call start of
22
+ * a tool the model called, only the answer that asked for it and the tool result after. */
23
+ const piCallsOf = (entry) => {
24
+ if (entry.kind !== "pi.assistant")
25
+ return [];
26
+ const content = entry.model?.[0]?.content;
27
+ return Array.isArray(content) ? content.flatMap((block) => (block?.type === "toolCall" && typeof block.id === "string" ? [block.id] : [])) : [];
28
+ };
29
+ const piResultOf = (entry) => {
30
+ const id = entry.kind === "pi.tool-result" ? entry.model?.[0]?.toolCallId : undefined;
31
+ return typeof id === "string" ? id : undefined;
32
+ };
33
+ /** On pi, the toolCalls that hold conversation `conversation`: the subagent call whose result names it
34
+ * (`details.conversationId`), and the one that holds that call's conversation, up to the root. */
35
+ function piHoldersOf(entries, conversation) {
36
+ const parents = new Map();
37
+ for (const entry of entries) {
38
+ const call = piResultOf(entry);
39
+ const child = entry.model?.[0]?.details?.conversationId;
40
+ if (call !== undefined && child !== undefined && child !== null)
41
+ parents.set(String(child), { conversation: String(entry.conversationId), call });
42
+ }
43
+ const holders = new Set();
44
+ const seen = new Set();
45
+ for (let at = String(conversation); parents.has(at) && !seen.has(at); at = parents.get(at).conversation) {
46
+ seen.add(at);
47
+ holders.add(parents.get(at).call);
48
+ }
49
+ return holders;
50
+ }
51
+ /** On pi, whether call `callId`'s window (`from`, the answer that asked for it, to `to`) is another conversation's too:
52
+ * a toolCall still open at its start that does not hold its conversation (piHoldersOf: a sibling subagent, or a tool its
53
+ * parent runs beside the subagent), or another conversation asking a tool or taking a result inside it. The host work
54
+ * of such a tool lands in the window under a host label, as the call's own nodes do, so the window can't be told apart.
55
+ * A toolCall closes at its result, or at its conversation's next answer (its turn was cut before the result came: pi
56
+ * takes every result of a turn before it answers again), so an aborted one holds no later window open. */
57
+ function piShared(entries, from, to) {
58
+ const own = String(entries[from].conversationId);
59
+ const holders = piHoldersOf(entries, own);
60
+ // Each open toolCall, by the conversation that asked for it.
61
+ const open = new Map();
62
+ for (let at = 0; at <= from; at++) {
63
+ const entry = entries[at];
64
+ if (entry.kind === "pi.assistant")
65
+ for (const [id, by] of open)
66
+ if (by === String(entry.conversationId))
67
+ open.delete(id);
68
+ if (at === from)
69
+ break;
70
+ for (const id of piCallsOf(entry))
71
+ open.set(id, String(entry.conversationId));
72
+ const done = piResultOf(entry);
73
+ if (done !== undefined)
74
+ open.delete(done);
75
+ }
76
+ if ([...open.keys()].some((id) => !holders.has(id)))
77
+ return true;
78
+ for (let at = from + 1; at <= to; at++) {
79
+ const entry = entries[at];
80
+ if (String(entry.conversationId) !== own && (piCallsOf(entry).length > 0 || piResultOf(entry) !== undefined))
81
+ return true;
82
+ }
83
+ return false;
84
+ }
85
+ /** What call `callId` booked (runner/metrics.ts callCostOf), over the window from its start (its call start entry, or on
86
+ * pi the answer that asked for it) to the later of its end (its call end, or pi's tool result) and its record
87
+ * (`recordAt`); null when the window is not its alone: no start, a pi answer that asked for another call beside it,
88
+ * another conversation's tool at work in it on pi (piShared: a sibling subagent's), or another call (none of its own)
89
+ * started within it or still open at its start (a nesting tool's, or the call it runs inside, is its own). Never a
90
+ * guess: a cost that can't be told apart is unknown. */
91
+ function callUsdOf(entries, callId, recordAt) {
92
+ const started = entries.findIndex((entry) => entry.kind === KINDS.callStart && callIdOf(entry) === callId);
93
+ const asked = started < 0 ? entries.findIndex((entry) => piCallsOf(entry).includes(callId)) : -1;
94
+ const from = started >= 0 ? started : asked;
95
+ if (from < 0 || from > recordAt)
96
+ return null;
97
+ if (asked >= 0 && piCallsOf(entries[asked]).length > 1)
98
+ return null;
99
+ const start = (started >= 0 ? entries[from].data : {});
100
+ const to = Math.max(recordAt, entries.findLastIndex((entry) => (entry.kind === KINDS.callEnd && callIdOf(entry) === callId) || piResultOf(entry) === callId));
101
+ if (asked >= 0 && piShared(entries, from, to))
102
+ return null;
103
+ // A call that holds this one (a nesting tool's: its id a prefix of this one's, or the harness's own call it runs in).
104
+ const holds = (id) => callId.startsWith(`${id}/`) || start.parent === id || start.parentCallId === id;
105
+ const open = new Set();
106
+ for (let at = 0; at < from; at++) {
107
+ const entry = entries[at];
108
+ const id = callIdOf(entry);
109
+ if (id === undefined)
110
+ continue;
111
+ if (entry.kind === KINDS.callStart)
112
+ open.add(id);
113
+ else if (entry.kind === KINDS.callEnd)
114
+ open.delete(id);
115
+ }
116
+ if ([...open].some((id) => !holds(id)))
117
+ return null;
118
+ for (let at = from + 1; at <= to; at++) {
119
+ const entry = entries[at];
120
+ const id = callIdOf(entry);
121
+ if (entry.kind === KINDS.callStart && id !== undefined && !within(id, callId))
122
+ return null;
123
+ }
124
+ return callCostOf(entries, callId, from, to);
125
+ }
126
+ /** Each learned workflow call run `entries` show (every conversation's, in log order: store-reads/journal.ts runEntries),
127
+ * in the order the calls first kept a record, from the record that counts for each (a call run again after a park or a
128
+ * crash keeps one each time: learnedCallEntries): its workflow, digest and caller, how it ended, and what it booked (callUsdOf). The
129
+ * platform's call ends as the run's WORKFLOW_FIRST entry says (its answer shaped, or taken back to the agent); one a
130
+ * crash cut before its record was kept is that entry's alone, its cost unknown. A call its record says was refused
131
+ * before any node ran (`refused`) is `refused`, whoever called it. A record that names no digest or caller is left out. */
132
+ export function workflowCallsOf(entries) {
133
+ // The record that counts for each call (learned-nodes.ts learnedCallEntries): a rerun refused before any node ran leaves
134
+ // the attempt that ran standing, as the call's timeline row does.
135
+ const newest = new Map([...learnedCallEntries(entries)].filter(([, at]) => {
136
+ const data = dataOf(entries[at]);
137
+ return typeof data.workflow === "string" && typeof data.digest === "string" && WORKFLOW_CALLERS.includes(data.caller);
138
+ }));
139
+ const served = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && ["answered", "handed_back"].includes(String(entry.data?.outcome)))?.data;
140
+ const calls = [...newest].map(([call, at]) => {
141
+ const data = dataOf(entries[at]);
142
+ // Refused before any node ran (its record's `refused`): it ran nothing, whatever the run did after.
143
+ const outcome = data.refused === true ? "refused" : call === WORKFLOW_FIRST_CALL && served ? served.outcome : outcomeOf(data.ended);
144
+ return { workflow: data.workflow, digest: data.digest, caller: data.caller, outcome, usd: callUsdOf(entries, call, at) };
145
+ });
146
+ if (served && !newest.has(WORKFLOW_FIRST_CALL) && typeof served.workflow === "string" && typeof served.digest === "string") {
147
+ calls.unshift({ workflow: served.workflow, digest: served.digest, caller: "platform", outcome: served.outcome, usd: null });
148
+ }
149
+ return calls;
150
+ }