@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.37

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 (522) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/README.md +417 -219
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-conformance-cli.d.ts +1 -0
  15. package/dist/attach-conformance-cli.js +18 -0
  16. package/dist/attach-conformance.d.ts +25 -0
  17. package/dist/attach-conformance.js +343 -0
  18. package/dist/attach-images.d.ts +15 -0
  19. package/dist/attach-images.js +59 -0
  20. package/dist/background.d.ts +0 -6
  21. package/dist/background.js +0 -28
  22. package/dist/box-image.d.ts +1 -97
  23. package/dist/box-image.js +4 -284
  24. package/dist/box-paths.d.ts +2 -7
  25. package/dist/box-paths.js +7 -13
  26. package/dist/box-settings.d.ts +0 -11
  27. package/dist/box-settings.js +4 -29
  28. package/dist/browser-commands.js +1 -1
  29. package/dist/browser-computer.d.ts +47 -3
  30. package/dist/browser-computer.js +286 -18
  31. package/dist/browser-cost.d.ts +1 -1
  32. package/dist/browser-live.d.ts +20 -8
  33. package/dist/browser-live.js +50 -27
  34. package/dist/browser-person.d.ts +19 -2
  35. package/dist/browser-person.js +55 -6
  36. package/dist/browser-wait-ended.d.ts +23 -0
  37. package/dist/browser-wait-ended.js +42 -0
  38. package/dist/cap.d.ts +12 -57
  39. package/dist/cap.js +20 -160
  40. package/dist/catalog.d.ts +1 -12
  41. package/dist/catalog.js +3 -33
  42. package/dist/cli.js +17 -26
  43. package/dist/composio-preset.d.ts +36 -0
  44. package/dist/composio-preset.js +179 -0
  45. package/dist/computer-attach.d.ts +125 -0
  46. package/dist/computer-attach.js +330 -0
  47. package/dist/computer-calls.d.ts +48 -0
  48. package/dist/computer-calls.js +126 -0
  49. package/dist/computer-channel.d.ts +57 -0
  50. package/dist/computer-channel.js +115 -0
  51. package/dist/computer-commands.d.ts +1 -1
  52. package/dist/computer-held-routes.d.ts +35 -0
  53. package/dist/computer-held-routes.js +106 -0
  54. package/dist/computer-held.d.ts +48 -0
  55. package/dist/computer-held.js +87 -0
  56. package/dist/computer-keys.d.ts +21 -1
  57. package/dist/computer-keys.js +53 -11
  58. package/dist/computer-live.d.ts +160 -0
  59. package/dist/computer-live.js +643 -0
  60. package/dist/computer-routes.d.ts +1 -4
  61. package/dist/computer-routes.js +3 -5
  62. package/dist/computer-setting.d.ts +2 -0
  63. package/dist/computer-setting.js +38 -1
  64. package/dist/computer-view.d.ts +24 -2
  65. package/dist/computer-view.js +51 -3
  66. package/dist/computer-viewer.d.ts +6 -0
  67. package/dist/computer-viewer.js +297 -0
  68. package/dist/computers.d.ts +79 -12
  69. package/dist/computers.js +147 -28
  70. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  71. package/dist/console/assets/index-DRN62V5v.css +1 -0
  72. package/dist/console/index.html +2 -2
  73. package/dist/docker-daemon.d.ts +2 -2
  74. package/dist/docker-daemon.js +2 -2
  75. package/dist/errors.js +5 -5
  76. package/dist/faux-computers.d.ts +9 -20
  77. package/dist/faux-computers.js +56 -24
  78. package/dist/files.d.ts +1 -9
  79. package/dist/files.js +1 -9
  80. package/dist/github-connection.d.ts +10 -2
  81. package/dist/github-connection.js +65 -2
  82. package/dist/github-faux.js +1 -1
  83. package/dist/github.d.ts +22 -2
  84. package/dist/github.js +42 -8
  85. package/dist/gpu-words.d.ts +14 -0
  86. package/dist/gpu-words.js +21 -0
  87. package/dist/graph-view.d.ts +3 -1
  88. package/dist/graph-view.js +25 -1
  89. package/dist/handed-values.d.ts +1 -1
  90. package/dist/handed-values.js +1 -1
  91. package/dist/harness-install.d.ts +60 -3
  92. package/dist/harness-install.js +322 -34
  93. package/dist/harness.d.ts +1 -0
  94. package/dist/harness.js +36 -2
  95. package/dist/host-tools.d.ts +9 -10
  96. package/dist/host-tools.js +7 -7
  97. package/dist/hosted-search.d.ts +5 -4
  98. package/dist/hosted-search.js +2 -7
  99. package/dist/import-sources.d.ts +10 -0
  100. package/dist/import-sources.js +44 -2
  101. package/dist/import.d.ts +3 -3
  102. package/dist/import.js +37 -6
  103. package/dist/index.d.ts +1 -3
  104. package/dist/index.js +1 -2
  105. package/dist/key-refusal.d.ts +1 -1
  106. package/dist/key-refusal.js +2 -2
  107. package/dist/learn/check.d.ts +11 -2
  108. package/dist/learn/check.js +124 -6
  109. package/dist/learn/commit.d.ts +43 -7
  110. package/dist/learn/commit.js +166 -22
  111. package/dist/learn/folder.d.ts +11 -0
  112. package/dist/learn/folder.js +37 -1
  113. package/dist/learn/general.d.ts +66 -0
  114. package/dist/learn/general.js +73 -0
  115. package/dist/learn/grade.d.ts +22 -1
  116. package/dist/learn/grade.js +107 -16
  117. package/dist/learn/index.d.ts +1 -1
  118. package/dist/learn/index.js +1 -1
  119. package/dist/learn/learning.sh +12 -1
  120. package/dist/learn/notes.d.ts +3 -0
  121. package/dist/learn/notes.js +3 -0
  122. package/dist/learn/reflect.d.ts +14 -2
  123. package/dist/learn/reflect.js +54 -30
  124. package/dist/learn/skills.d.ts +37 -5
  125. package/dist/learn/skills.js +60 -7
  126. package/dist/learned-nodes.d.ts +6 -2
  127. package/dist/learned-workflow.d.ts +43 -9
  128. package/dist/learned-workflow.js +128 -37
  129. package/dist/learning-batch.d.ts +283 -0
  130. package/dist/learning-batch.js +574 -0
  131. package/dist/learning-cost.d.ts +79 -0
  132. package/dist/learning-cost.js +69 -0
  133. package/dist/learning-evals.d.ts +33 -0
  134. package/dist/learning-evals.js +98 -0
  135. package/dist/learning-routes.d.ts +32 -4
  136. package/dist/learning-routes.js +48 -12
  137. package/dist/learning-words.d.ts +9 -0
  138. package/dist/learning-words.js +12 -2
  139. package/dist/learning.d.ts +39 -19
  140. package/dist/learning.js +88 -46
  141. package/dist/live/stream.js +6 -3
  142. package/dist/live/translate.d.ts +4 -3
  143. package/dist/live/translate.js +8 -4
  144. package/dist/live-reach.d.ts +37 -0
  145. package/dist/live-reach.js +62 -0
  146. package/dist/mcp-gateway.d.ts +9 -0
  147. package/dist/mcp-gateway.js +60 -11
  148. package/dist/mcp-oauth.d.ts +57 -7
  149. package/dist/mcp-oauth.js +133 -18
  150. package/dist/mcp-private-hosts.d.ts +4 -4
  151. package/dist/mcp-private-hosts.js +20 -12
  152. package/dist/mcp-probe.d.ts +27 -3
  153. package/dist/mcp-probe.js +106 -29
  154. package/dist/mcp-secret-writes.js +8 -0
  155. package/dist/mcp-servers-store.d.ts +38 -15
  156. package/dist/mcp-servers-store.js +120 -23
  157. package/dist/mcp-store.d.ts +10 -4
  158. package/dist/mcp-store.js +17 -6
  159. package/dist/model-form.d.ts +26 -0
  160. package/dist/model-form.js +80 -0
  161. package/dist/model.d.ts +5 -5
  162. package/dist/model.js +29 -16
  163. package/dist/openapi.d.ts +2 -0
  164. package/dist/openapi.js +586 -64
  165. package/dist/owner.d.ts +0 -1
  166. package/dist/owner.js +0 -2
  167. package/dist/page.d.ts +18 -0
  168. package/dist/page.js +48 -20
  169. package/dist/paid-calls.d.ts +1 -1
  170. package/dist/paid-calls.js +1 -1
  171. package/dist/place-offers.d.ts +96 -0
  172. package/dist/place-offers.js +202 -0
  173. package/dist/place.d.ts +9 -13
  174. package/dist/place.js +21 -32
  175. package/dist/port-models.d.ts +2 -1
  176. package/dist/port-models.js +5 -3
  177. package/dist/print.d.ts +16 -9
  178. package/dist/print.js +15 -17
  179. package/dist/propose.d.ts +4 -0
  180. package/dist/propose.js +34 -11
  181. package/dist/provider.js +3 -2
  182. package/dist/reflect-range.d.ts +8 -1
  183. package/dist/reflect-range.js +1 -1
  184. package/dist/run-cut.d.ts +5 -0
  185. package/dist/run-cut.js +19 -0
  186. package/dist/run-launch.d.ts +28 -3
  187. package/dist/run-launch.js +14 -4
  188. package/dist/run-learning-served.d.ts +2 -2
  189. package/dist/run-manifest.d.ts +2 -2
  190. package/dist/run-manifest.js +2 -2
  191. package/dist/run-reads-over-store.d.ts +1 -1
  192. package/dist/run-repo.d.ts +20 -0
  193. package/dist/run-repo.js +63 -0
  194. package/dist/run-secrets.js +3 -3
  195. package/dist/run-timeline-served.d.ts +1 -1
  196. package/dist/run-timeline-served.js +56 -44
  197. package/dist/run-view.d.ts +8 -5
  198. package/dist/run-view.js +18 -10
  199. package/dist/runnable.d.ts +2 -2
  200. package/dist/runnable.js +6 -2
  201. package/dist/runner/adapter-loop.d.ts +39 -8
  202. package/dist/runner/adapter-loop.js +770 -83
  203. package/dist/runner/adapter-run-spec.d.ts +36 -7
  204. package/dist/runner/adapter-run-spec.js +171 -37
  205. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  206. package/dist/runner/adapters/pi-computer.js +43 -0
  207. package/dist/runner/adapters/pi.d.ts +20 -7
  208. package/dist/runner/adapters/pi.js +111 -26
  209. package/dist/runner/beside.d.ts +7 -3
  210. package/dist/runner/beside.js +26 -12
  211. package/dist/runner/claim-secrets.d.ts +4 -0
  212. package/dist/runner/claim-secrets.js +6 -1
  213. package/dist/runner/cli-run-spec.d.ts +27 -3
  214. package/dist/runner/cli-run-spec.js +198 -74
  215. package/dist/runner/commands.d.ts +8 -2
  216. package/dist/runner/commands.js +31 -6
  217. package/dist/runner/computer-channel.d.ts +34 -0
  218. package/dist/runner/computer-channel.js +61 -0
  219. package/dist/runner/conformance/harness.d.ts +0 -1
  220. package/dist/runner/conformance/harness.js +87 -18
  221. package/dist/runner/conformance/subject.d.ts +1 -1
  222. package/dist/runner/dispatch.js +3 -0
  223. package/dist/runner/end-of-run.d.ts +22 -12
  224. package/dist/runner/end-of-run.js +38 -16
  225. package/dist/runner/github-app.d.ts +2 -1
  226. package/dist/runner/github-app.js +6 -4
  227. package/dist/runner/harness-loops.js +16 -2
  228. package/dist/runner/held-run.d.ts +65 -0
  229. package/dist/runner/held-run.js +158 -0
  230. package/dist/runner/journal-kinds.d.ts +35 -6
  231. package/dist/runner/journal-kinds.js +20 -1
  232. package/dist/runner/journal-reader.d.ts +5 -4
  233. package/dist/runner/journal-reader.js +12 -10
  234. package/dist/runner/learning-ask.d.ts +7 -1
  235. package/dist/runner/learning-ask.js +21 -6
  236. package/dist/runner/learning-dispatch.d.ts +22 -0
  237. package/dist/runner/learning-dispatch.js +77 -10
  238. package/dist/runner/learning-end.d.ts +37 -1
  239. package/dist/runner/learning-end.js +115 -14
  240. package/dist/runner/learning-factory.d.ts +1 -1
  241. package/dist/runner/learning-factory.js +15 -5
  242. package/dist/runner/learning-loop.d.ts +139 -7
  243. package/dist/runner/learning-loop.js +369 -32
  244. package/dist/runner/learning-seed.d.ts +9 -0
  245. package/dist/runner/learning-seed.js +14 -1
  246. package/dist/runner/live-ticker.js +1 -0
  247. package/dist/runner/loop-contract.d.ts +16 -1
  248. package/dist/runner/loop-contract.js +6 -0
  249. package/dist/runner/loop.d.ts +10 -2
  250. package/dist/runner/loop.js +22 -1
  251. package/dist/runner/main.d.ts +13 -1
  252. package/dist/runner/main.js +38 -6
  253. package/dist/runner/mcp-claim.d.ts +11 -4
  254. package/dist/runner/mcp-claim.js +140 -23
  255. package/dist/runner/mcp-github.d.ts +4 -2
  256. package/dist/runner/mcp-github.js +1 -8
  257. package/dist/runner/mcp-run.d.ts +6 -4
  258. package/dist/runner/mcp-run.js +16 -3
  259. package/dist/runner/metrics.d.ts +15 -2
  260. package/dist/runner/metrics.js +21 -2
  261. package/dist/runner/model-route.d.ts +3 -0
  262. package/dist/runner/model-route.js +5 -2
  263. package/dist/runner/pr-checkout.d.ts +60 -0
  264. package/dist/runner/pr-checkout.js +176 -0
  265. package/dist/runner/reflect-hook.d.ts +19 -0
  266. package/dist/runner/reflect-hook.js +20 -8
  267. package/dist/runner/runner.d.ts +26 -0
  268. package/dist/runner/runner.js +231 -27
  269. package/dist/runner/scratch-sweep.d.ts +13 -0
  270. package/dist/runner/scratch-sweep.js +62 -0
  271. package/dist/runner/sessions.d.ts +1 -1
  272. package/dist/runner/spec-holds.d.ts +8 -3
  273. package/dist/runner/spec-holds.js +12 -10
  274. package/dist/runner/store-port.d.ts +7 -2
  275. package/dist/runner/store-secrets.js +21 -4
  276. package/dist/runner/subagent.d.ts +44 -0
  277. package/dist/runner/subagent.js +190 -0
  278. package/dist/runner/workflow-host.d.ts +24 -3
  279. package/dist/runner/workflow-host.js +24 -4
  280. package/dist/runner/workflow-loop.d.ts +6 -3
  281. package/dist/runner/workflow-loop.js +9 -8
  282. package/dist/runner/workflow-spec.d.ts +39 -15
  283. package/dist/runner/workflow-spec.js +143 -40
  284. package/dist/runs-over-store.d.ts +16 -6
  285. package/dist/runs-over-store.js +145 -29
  286. package/dist/seal-key.js +3 -3
  287. package/dist/sealed-settings-store.d.ts +5 -2
  288. package/dist/sealed-settings-store.js +10 -4
  289. package/dist/sealing.js +1 -2
  290. package/dist/secret-cut.d.ts +1 -1
  291. package/dist/secret-cut.js +1 -1
  292. package/dist/secret-writes.d.ts +5 -4
  293. package/dist/secret-writes.js +5 -4
  294. package/dist/server-secrets-store.d.ts +4 -3
  295. package/dist/server-secrets-store.js +15 -9
  296. package/dist/server-secrets.js +3 -2
  297. package/dist/server.d.ts +75 -63
  298. package/dist/server.js +712 -316
  299. package/dist/settings-wake.d.ts +21 -0
  300. package/dist/settings-wake.js +59 -0
  301. package/dist/standard-webhooks.d.ts +4 -1
  302. package/dist/standard-webhooks.js +8 -4
  303. package/dist/store/agent-body.d.ts +9 -2
  304. package/dist/store/agent-body.js +16 -8
  305. package/dist/store/command-wake.d.ts +12 -0
  306. package/dist/store/command-wake.js +37 -0
  307. package/dist/store/deadline.js +9 -5
  308. package/dist/store/dialect.d.ts +6 -0
  309. package/dist/store/dialect.js +5 -0
  310. package/dist/store/index.d.ts +4 -4
  311. package/dist/store/index.js +2 -2
  312. package/dist/store/journal/storage.d.ts +3 -2
  313. package/dist/store/journal/storage.js +15 -6
  314. package/dist/store/postgres/connection.js +9 -4
  315. package/dist/store/postgres/dialect.js +4 -0
  316. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  317. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  318. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  319. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  320. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  321. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  322. package/dist/store/schema.d.ts +2 -1
  323. package/dist/store/schema.js +85 -13
  324. package/dist/store/seal.d.ts +13 -0
  325. package/dist/store/seal.js +19 -0
  326. package/dist/store/sqlite/connection.d.ts +5 -0
  327. package/dist/store/sqlite/connection.js +88 -47
  328. package/dist/store/sqlite/run-patch.d.ts +25 -7
  329. package/dist/store/sqlite/run-patch.js +58 -14
  330. package/dist/store/sqlite/store.js +331 -59
  331. package/dist/store/store.d.ts +330 -21
  332. package/dist/store/store.js +34 -2
  333. package/dist/store-reads/analytics.js +3 -2
  334. package/dist/store-reads/cap.d.ts +2 -4
  335. package/dist/store-reads/cap.js +16 -7
  336. package/dist/store-reads/decisions.d.ts +3 -3
  337. package/dist/store-reads/decisions.js +3 -6
  338. package/dist/store-reads/import-summary.d.ts +1 -1
  339. package/dist/store-reads/journal.d.ts +5 -4
  340. package/dist/store-reads/journal.js +118 -27
  341. package/dist/store-reads/learning.d.ts +34 -4
  342. package/dist/store-reads/learning.js +137 -23
  343. package/dist/store-reads/runs.d.ts +7 -5
  344. package/dist/store-reads/runs.js +17 -10
  345. package/dist/store-reads/stats.js +5 -1
  346. package/dist/store-reads/workflow.d.ts +1 -1
  347. package/dist/store-view.d.ts +5 -0
  348. package/dist/store-view.js +70 -29
  349. package/dist/template-eval.js +8 -5
  350. package/dist/template-github-permissions.d.ts +22 -8
  351. package/dist/template-github-permissions.js +35 -15
  352. package/dist/templates.d.ts +64 -0
  353. package/dist/templates.js +101 -16
  354. package/dist/timeline/timeline.d.ts +30 -1
  355. package/dist/timeline/timeline.js +29 -13
  356. package/dist/timeline/util.d.ts +4 -0
  357. package/dist/timeline/util.js +14 -0
  358. package/dist/tool-blurbs.js +1 -0
  359. package/dist/tool-budget.d.ts +27 -7
  360. package/dist/tool-budget.js +21 -9
  361. package/dist/tool-gate.d.ts +23 -10
  362. package/dist/tool-gate.js +60 -44
  363. package/dist/tool-plane.d.ts +46 -28
  364. package/dist/tool-plane.js +73 -31
  365. package/dist/tools.d.ts +31 -38
  366. package/dist/tools.js +117 -74
  367. package/dist/trigger-adapter.d.ts +4 -0
  368. package/dist/trigger-secrets-shown.d.ts +2 -2
  369. package/dist/trigger-secrets-shown.js +1 -1
  370. package/dist/trigger-signatures.d.ts +26 -6
  371. package/dist/trigger-signatures.js +44 -8
  372. package/dist/trigger-targets.d.ts +2 -0
  373. package/dist/trigger-targets.js +1 -0
  374. package/dist/trigger-webhook.js +5 -2
  375. package/dist/triggers.d.ts +10 -6
  376. package/dist/triggers.js +37 -7
  377. package/dist/turn-end.d.ts +0 -3
  378. package/dist/turn-end.js +0 -3
  379. package/dist/turns.js +16 -1
  380. package/dist/usage-lines.d.ts +1 -1
  381. package/dist/validate.d.ts +6 -0
  382. package/dist/validate.js +41 -4
  383. package/dist/web-fetch.d.ts +1 -1
  384. package/dist/web-search.d.ts +10 -5
  385. package/dist/web-search.js +7 -6
  386. package/dist/webhooks.d.ts +147 -103
  387. package/dist/webhooks.js +564 -324
  388. package/dist/workflow/decision-recovery.d.ts +23 -0
  389. package/dist/workflow/decision-recovery.js +80 -0
  390. package/dist/workflow/decisions.d.ts +134 -0
  391. package/dist/workflow/decisions.js +46 -0
  392. package/dist/workflow/host-session.d.ts +5 -0
  393. package/dist/workflow/host-session.js +85 -0
  394. package/dist/workflow/host-tools.d.ts +3 -0
  395. package/dist/workflow/host-tools.js +3 -0
  396. package/dist/workflow/node-runner.d.ts +113 -0
  397. package/dist/workflow/node-runner.js +270 -0
  398. package/dist/workflow/node.d.ts +89 -0
  399. package/dist/workflow/node.js +101 -0
  400. package/dist/workflow/operator-error.d.ts +4 -0
  401. package/dist/workflow/operator-error.js +4 -0
  402. package/dist/workflow/pi-versions.d.ts +32 -0
  403. package/dist/workflow/pi-versions.js +65 -0
  404. package/dist/workflow/record-file.d.ts +10 -0
  405. package/dist/workflow/record-file.js +56 -0
  406. package/dist/workflow/record-tool.d.ts +77 -0
  407. package/dist/workflow/record-tool.js +126 -0
  408. package/dist/workflow/record.d.ts +151 -0
  409. package/dist/workflow/record.js +401 -0
  410. package/dist/workflow/run-error.d.ts +16 -0
  411. package/dist/workflow/run-error.js +26 -0
  412. package/dist/workflow/runner.d.ts +6 -0
  413. package/dist/workflow/runner.js +240 -0
  414. package/dist/workflow/store.d.ts +23 -0
  415. package/dist/workflow/store.js +242 -0
  416. package/dist/workflow/task.d.ts +133 -0
  417. package/dist/workflow/task.js +412 -0
  418. package/dist/workflow/thinking.d.ts +3 -0
  419. package/dist/workflow/thinking.js +7 -0
  420. package/dist/workflow/tool-context.d.ts +21 -0
  421. package/dist/workflow/tool-context.js +13 -0
  422. package/dist/workflow/types.d.ts +126 -0
  423. package/dist/workflow/types.js +1 -0
  424. package/dist/workflow-run.d.ts +2 -2
  425. package/dist/workspace/agent-computer.d.ts +137 -0
  426. package/dist/workspace/agent-computer.js +292 -0
  427. package/dist/workspace/archil-claim.d.ts +11 -0
  428. package/dist/workspace/archil-claim.js +18 -10
  429. package/dist/workspace/archil-disks.d.ts +49 -0
  430. package/dist/workspace/archil-disks.js +185 -0
  431. package/dist/workspace/archil-exec.js +2 -3
  432. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  433. package/dist/workspace/archil-mount-credential.js +13 -4
  434. package/dist/workspace/attached-computers.d.ts +41 -0
  435. package/dist/workspace/attached-computers.js +114 -0
  436. package/dist/workspace/computer-deps.d.ts +32 -17
  437. package/dist/workspace/computer-deps.js +37 -14
  438. package/dist/workspace/computer-for-claim.d.ts +58 -13
  439. package/dist/workspace/computer-for-claim.js +267 -26
  440. package/dist/workspace/computer-hold.d.ts +11 -27
  441. package/dist/workspace/computer-hold.js +36 -56
  442. package/dist/workspace/computer-janitor.d.ts +3 -2
  443. package/dist/workspace/computer-janitor.js +43 -9
  444. package/dist/workspace/computer-ledger.d.ts +5 -1
  445. package/dist/workspace/computer-ledger.js +11 -0
  446. package/dist/workspace/computer-mcp.d.ts +25 -0
  447. package/dist/workspace/computer-mcp.js +41 -0
  448. package/dist/workspace/computer-ports.d.ts +4 -13
  449. package/dist/workspace/computer-ports.js +4 -107
  450. package/dist/workspace/computer-script.d.ts +37 -0
  451. package/dist/workspace/computer-script.js +138 -0
  452. package/dist/workspace/executors.d.ts +1 -1
  453. package/dist/workspace/index.d.ts +7 -4
  454. package/dist/workspace/index.js +4 -1
  455. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  456. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  457. package/dist/workspace/resolve-computer.d.ts +45 -11
  458. package/dist/workspace/resolve-computer.js +72 -14
  459. package/dist/workspace/run-disk.d.ts +34 -0
  460. package/dist/workspace/run-disk.js +91 -0
  461. package/dist/workspace/run-tools.d.ts +35 -18
  462. package/dist/workspace/run-tools.js +24 -29
  463. package/dist/workspace/server-run-workspace.d.ts +3 -2
  464. package/dist/workspace/server-run-workspace.js +17 -4
  465. package/dist/workspace.js +1 -1
  466. package/package.json +19 -21
  467. package/templates/README.md +9 -6
  468. package/templates/code-review/agent.md +27 -11
  469. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  470. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  471. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  472. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  473. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  474. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  475. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  476. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  477. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  478. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  479. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  480. package/templates/code-review/evals/re-review/prompt.md +1 -1
  481. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  482. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  483. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  484. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  485. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  486. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  487. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  488. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  489. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  490. package/templates/code-review/findings.schema.json +131 -27
  491. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  492. package/templates/code-review/skills/review/DEEP.md +130 -0
  493. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  494. package/templates/code-review/skills/review/SKILL.md +104 -154
  495. package/templates/market-monitor/agent.md +1 -1
  496. package/dist/box/record.d.ts +0 -6
  497. package/dist/box/record.js +0 -41
  498. package/dist/box/sweep.d.ts +0 -53
  499. package/dist/box/sweep.js +0 -193
  500. package/dist/box-egress-vm.d.ts +0 -118
  501. package/dist/box-egress-vm.js +0 -354
  502. package/dist/box-egress.d.ts +0 -105
  503. package/dist/box-egress.js +0 -256
  504. package/dist/box-relay-vm.d.ts +0 -84
  505. package/dist/box-relay-vm.js +0 -437
  506. package/dist/box-relay.d.ts +0 -36
  507. package/dist/box-relay.js +0 -207
  508. package/dist/boxes.d.ts +0 -109
  509. package/dist/boxes.js +0 -249
  510. package/dist/budget.d.ts +0 -71
  511. package/dist/budget.js +0 -199
  512. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  513. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  514. package/dist/daytona-api.d.ts +0 -10
  515. package/dist/daytona-api.js +0 -20
  516. package/dist/egress-proxy.d.ts +0 -45
  517. package/dist/egress-proxy.js +0 -416
  518. package/dist/egress-table.d.ts +0 -24
  519. package/dist/egress-table.js +0 -165
  520. package/dist/run-db.d.ts +0 -53
  521. package/dist/run-db.js +0 -116
  522. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -5,11 +5,15 @@ import { type Workspace } from "./workspace/index.js";
5
5
  * default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
6
6
  export declare const LEARNING_MODES: readonly ["on", "off"];
7
7
  export type LearningMode = (typeof LEARNING_MODES)[number];
8
+ /** Whether a revision's `learning` (its definition's: true, false or "notes") has its runs learn: true learns notes, skills
9
+ * and workflows; "notes" learns notes and skills alone, never given a learned workflow nor asked to draft one. */
10
+ export declare const learnsOf: (learning: unknown) => boolean;
8
11
  export declare const LEARNING_ENV = "AGENTRUN_SERVE_LEARNING";
9
12
  /** The switch: `given`, else AGENTRUN_SERVE_LEARNING, else on. Any other value is an error, and the server does not start. */
10
13
  export declare function learningOf(env: NodeJS.ProcessEnv, given?: string): LearningMode;
11
14
  /** How much of what a run learned its instructions hold under `# Learned` by default, in UTF-8 bytes (learnedParts): its
12
- * notes whole while they fit, else the index and the notes changed last, whole, while they fit. */
15
+ * notes whole while they fit, else the notes that bear most on the run whole while they fit, then a line for each of
16
+ * the next while they fit; the rest are left out, and the run's log names them. */
13
17
  export declare const LEARNING_BUDGET = 8000;
14
18
  export declare const LEARNING_BUDGET_ENV = "AGENTRUN_SERVE_LEARNING_BUDGET";
15
19
  /** The learning budget: `given` (`--learning-budget`), else AGENTRUN_SERVE_LEARNING_BUDGET, else LEARNING_BUDGET. Any
@@ -20,7 +24,11 @@ export declare function learningBudgetOf(env: NodeJS.ProcessEnv, given?: number)
20
24
  * checks and is kept (propose.ts), `merged` once it is on main (runner/learning-loop.ts), or `dropped` with a
21
25
  * reason from the closed list. A learning fault never refuses a run: it starts with nothing learned, `seed_failed`. */
22
26
  export declare const LEARNING_STATES: readonly ["seeded", "reflecting", "proposed", "merged", "dropped"];
23
- export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_timeout", "reflect_failed", "empty", "unparsed", "propose_failed", "checker", "grader", "grade_failed"];
27
+ export declare const LEARNING_REASONS: readonly ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_timeout", "reflect_failed", "empty", "unparsed", "propose_failed", "checker", "grader", "grade_failed", "use"];
28
+ /** A run's own `learning` on its start (POST /agents/{agent_id}/runs): it starts from what its agent learned, as a run that
29
+ * learns does, and keeps nothing (no end-of-run turn, no proposal, no grade, no merge, at any end), so runs of one agent
30
+ * read one learned state however many run at once. Its learning ends `dropped`, reason `use`. */
31
+ export declare const RUN_LEARNING_USE = "use";
24
32
  export type LearningState = (typeof LEARNING_STATES)[number];
25
33
  export type LearningReason = (typeof LEARNING_REASONS)[number];
26
34
  /** Tokens by the platform's names, as a run's metrics and /v2/stats count them: `input` is the input neither read from
@@ -31,7 +39,6 @@ export type Tokens = {
31
39
  cache_write: number;
32
40
  output: number;
33
41
  };
34
- export declare const NO_TOKENS: Tokens;
35
42
  /** The variable that names the grader's model, as `--grade-model` does. */
36
43
  export declare const GRADE_MODEL_ENV = "AGENTRUN_SERVE_GRADE_MODEL";
37
44
  /** The model this server grades on, by name: `given` (`--grade-model`), else GRADE_MODEL_ENV, else its strong tier
@@ -52,7 +59,7 @@ export type NoteUsed = {
52
59
  export type NoteLearned = NoteUsed & {
53
60
  supersedes: string[];
54
61
  };
55
- /** A run's learning as serve.json keeps it. Past the view's four fields: the checker's `problems` (printable), the
62
+ /** A run's learning as the store keeps it. Past the view's four fields: the checker's `problems` (printable), the
56
63
  * grader's `verdict` and the blob of each note it read superseded (`graded`, by file), both kept before the merge, the
57
64
  * merge commit, and what the grade cost (null when unknown, never 0), which is in no run's totals; the notes the run
58
65
  * started with (`given`: each note its # Learned section names, whole or as an index line, set as it is seeded) and read
@@ -126,7 +133,7 @@ export declare function secretsShown(values: readonly string[], { local }?: {
126
133
  /** The notes a run read and learned, as a view or a list shows them, each name cut of the host's secrets (`shown`):
127
134
  * `given` from its start, `read` once the run settled, `learned` and `pending` (what waits for the owner's OK) once it merged, and the skill
128
135
  * and the workflow draft it merged (`skills`, `workflows`, each `pending` while it waits), each only when it holds one.
129
- * serve.json's are read as untrusted: an entry out of shape is left out. */
136
+ * the stored ones are read as untrusted: an entry out of shape is left out. */
130
137
  export declare function notesView({ state, given, read: opened, learned, pending, skills, workflows }: Learning, shown: Shown, settled: boolean): {
131
138
  given?: NoteUsed[];
132
139
  read?: NoteUsed[];
@@ -161,8 +168,8 @@ export declare const learningView: (learning: Learning, shown: Shown, settled: b
161
168
  pending?: NoteUsed[];
162
169
  skills?: LearnedFile[];
163
170
  workflows?: LearnedFile[];
164
- state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
165
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
171
+ state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
172
+ reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
166
173
  detail: string | null;
167
174
  at: string;
168
175
  };
@@ -176,8 +183,8 @@ export declare function shortOf<T extends {
176
183
  detail: string | null;
177
184
  at: string;
178
185
  }>({ state, reason, detail, at: _, ...notes }: T): {
179
- state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
180
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
186
+ state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
187
+ reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
181
188
  detail: string | null;
182
189
  } & Omit<T, "at" | "reason" | "detail" | "state">;
183
190
  /** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
@@ -188,7 +195,8 @@ export declare const LEARNING_LABEL = "learning";
188
195
  * secrets, then shortened to its head and tail, shortMessage; absent in a proposal kept before the grader read them). */
189
196
  export declare const PROPOSAL = "learning-proposal.json";
190
197
  /** A run's proposal: its notes, skill and drafts, each draft's dry run by its workflow.json's path (learn/skills.ts
191
- * draftDryRun: passed, or not run and why), and what was said in the run. */
198
+ * draftDryRun: passed, or not run and why), the skill of each draft's name as the folder holds it at the seed
199
+ * (`drafted`, its SKILL.md: shown to the grader beside the draft, never graded or merged), and what was said in the run. */
192
200
  export type Proposal = {
193
201
  seed: string;
194
202
  notes: {
@@ -200,6 +208,10 @@ export type Proposal = {
200
208
  text: string;
201
209
  }[];
202
210
  dryRuns?: Record<string, DraftDryRun>;
211
+ drafted?: {
212
+ file: string;
213
+ text: string;
214
+ }[];
203
215
  asked?: string[];
204
216
  triggered?: Triggered[];
205
217
  };
@@ -387,6 +399,9 @@ export type NoteCandidates = {
387
399
  readonly indexBytes: number;
388
400
  readonly indexComplete: boolean;
389
401
  readonly budget: number;
402
+ /** Whether the run has the read tool, so the section past the budget names `.learning/` (READ_LINE) and its room is kept
403
+ * for that line. Absent: kept, as for a run that has it. */
404
+ readonly read?: boolean;
390
405
  };
391
406
  /** A selector's choice: the notes the run reads whole, in the order it reads them (a subset of the candidates), and
392
407
  * whether it reads the index first. Without the index, the notes are all it is given; or, with `lines`, the notes it
@@ -401,14 +416,16 @@ export type NoteSelection = {
401
416
  * index when it serves it, fit `budget`, past which only the index may go (as loadedIndex bounds it). */
402
417
  export type NoteSelector = (candidates: NoteCandidates, run: RunInput) => NoteSelection;
403
418
  /** The selector by recency: every note whole while all fit the budget and the index names no note main does not hold
404
- * whole; else the index, then the newest notes that fit what it leaves, each whole. */
419
+ * whole; notes that fit with an index that names one it lacks, the index, then the newest notes that fit what it
420
+ * leaves, each whole; past the budget, the newest notes whole while they fit, then a line for each of the next while
421
+ * they fit (withinBudget). */
405
422
  export declare const byRecency: NoteSelector;
406
423
  /** The default selector, by relevance, past the budget: while the notes fit it, recency's choice (byRecency). Else each
407
424
  * note is scored against the run's input (learn/relevance.ts: BM25 over its name, description and body, a code
408
425
  * review's changed paths' words weighed PATH_WEIGHT; no model call), and the run reads the notes that bear on it most
409
- * whole, in score order, while they fit, then one rule line for each of the rest, best first, in place of the index; the lines count toward the
410
- * budget before the whole notes, as the index did, and no more of them than a run reads of the index (loadedIndex). An
411
- * input with no word any note holds reads by recency. */
426
+ * whole, best first, while they fit the budget, then one rule line for each of the next while they fit what is left
427
+ * (withinBudget), a note that bears on it in no word a line at most; the rest are left out. An input with no word any
428
+ * note holds reads by recency. */
412
429
  export declare const byRelevance: NoteSelector;
413
430
  /** What a run of `seed` reads under `# Learned` (`section`, the same for every harness, undefined when it learned
414
431
  * nothing) and the notes that names (`given`), from one choice of the selector, so the section and the given notes never
@@ -416,11 +433,14 @@ export declare const byRelevance: NoteSelector;
416
433
  * the index, nor counted toward the budget (readSeed reads active notes alone, and servedIndex drops their lines). Its
417
434
  * active notes, newest first (`seed.recent`, else by name), each whole while all fit `budget`; past it, the selector's
418
435
  * choice (byRelevance by default). An agent with the read tool is told the rest are in `.learning/`, one without is not.
436
+ * Notes past a budget that holds none of them (0 among them) are said to be there (NONE_FIT), never "Nothing learned yet.".
419
437
  * Every text is cut of the host's secrets. A run "was given" `given`; of them, it "read" those whose file it opened
420
- * (store-reads/learning.ts notesReadOf). Whether it applied one given whole is not measured. */
438
+ * (store-reads/learning.ts notesReadOf). Whether it applied one given whole is not measured. `left`: the active notes
439
+ * the section names in no way, over the budget, which the run's log names (runner/learning-seed.ts). */
421
440
  export declare function learnedParts(seed: Seed, options: LearnedOptions): {
422
441
  section: string | undefined;
423
442
  given: LearnedNote[];
443
+ left: LearnedNote[];
424
444
  };
425
445
  /** Lays each of `skills` in the run's `.agents/skills/<name>/` through its Workspace, a folder made new for it (one
426
446
  * already there throws EXISTS); a link on the way is ESCAPE, and nothing is written through it. Each name goes in
@@ -468,10 +488,10 @@ export declare function readPin(runDir: string): Promise<Pin | undefined>;
468
488
  /** The heading of what a run learned, in its instructions. */
469
489
  export declare const LEARNED_HEADING = "# Learned";
470
490
  /** A run's instructions with its # Learned section laid in main's position: the revision's instructions, then the heading,
471
- * LEARNS, and the section text — "Nothing learned yet." when the run learns but its section is empty (no notes yet, or a
472
- * seed that could not be read). Shared so the runner (laying launch.learning.section, read with no folder) and app.ts
473
- * (withLearned) lay the same bytes. */
474
- export declare const laidLearned: (instructions: string, section: string | undefined) => string;
491
+ * LEARNS (USES for a run that only `use`s what its agent learned), and the section text — "Nothing learned yet." when the
492
+ * run learns but its section is empty (no notes yet, or a seed that could not be read). Shared so the runner (laying
493
+ * launch.learning.section, read with no folder) and app.ts (withLearned) lay the same bytes. */
494
+ export declare const laidLearned: (instructions: string, section: string | undefined, use?: boolean) => string;
475
495
  /** A run's instructions, with `# Learned` after them when its pin in `runDir` says it learns: that it learns, then what
476
496
  * the pin says it learned, or that it has learned nothing yet. A run with no pin (its agent does not learn, its seed
477
497
  * failed, a workflow's run) is never asked what to keep, so it is told nothing. And its skill files: the revision's
package/dist/learning.js CHANGED
@@ -45,6 +45,9 @@ import { isWorkspaceError, WorkspaceError, workspaceAt } from "./workspace/index
45
45
  /** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
46
46
  * default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
47
47
  export const LEARNING_MODES = ["on", "off"];
48
+ /** Whether a revision's `learning` (its definition's: true, false or "notes") has its runs learn: true learns notes, skills
49
+ * and workflows; "notes" learns notes and skills alone, never given a learned workflow nor asked to draft one. */
50
+ export const learnsOf = (learning) => learning === true || learning === "notes";
48
51
  export const LEARNING_ENV = "AGENTRUN_SERVE_LEARNING";
49
52
  /** The switch: `given`, else AGENTRUN_SERVE_LEARNING, else on. Any other value is an error, and the server does not start. */
50
53
  export function learningOf(env, given) {
@@ -54,7 +57,8 @@ export function learningOf(env, given) {
54
57
  return value;
55
58
  }
56
59
  /** How much of what a run learned its instructions hold under `# Learned` by default, in UTF-8 bytes (learnedParts): its
57
- * notes whole while they fit, else the index and the notes changed last, whole, while they fit. */
60
+ * notes whole while they fit, else the notes that bear most on the run whole while they fit, then a line for each of
61
+ * the next while they fit; the rest are left out, and the run's log names them. */
58
62
  export const LEARNING_BUDGET = 8000;
59
63
  export const LEARNING_BUDGET_ENV = "AGENTRUN_SERVE_LEARNING_BUDGET";
60
64
  /** The learning budget: `given` (`--learning-budget`), else AGENTRUN_SERVE_LEARNING_BUDGET, else LEARNING_BUDGET. Any
@@ -71,8 +75,11 @@ export function learningBudgetOf(env, given) {
71
75
  * checks and is kept (propose.ts), `merged` once it is on main (runner/learning-loop.ts), or `dropped` with a
72
76
  * reason from the closed list. A learning fault never refuses a run: it starts with nothing learned, `seed_failed`. */
73
77
  export const LEARNING_STATES = ["seeded", "reflecting", "proposed", "merged", "dropped"];
74
- export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_timeout", "reflect_failed", "empty", "unparsed", "propose_failed", "checker", "grader", "grade_failed"];
75
- export const NO_TOKENS = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
78
+ export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_timeout", "reflect_failed", "empty", "unparsed", "propose_failed", "checker", "grader", "grade_failed", "use"];
79
+ /** A run's own `learning` on its start (POST /agents/{agent_id}/runs): it starts from what its agent learned, as a run that
80
+ * learns does, and keeps nothing (no end-of-run turn, no proposal, no grade, no merge, at any end), so runs of one agent
81
+ * read one learned state however many run at once. Its learning ends `dropped`, reason `use`. */
82
+ export const RUN_LEARNING_USE = "use";
76
83
  /** The variable that names the grader's model, as `--grade-model` does. */
77
84
  export const GRADE_MODEL_ENV = "AGENTRUN_SERVE_GRADE_MODEL";
78
85
  /** The model this server grades on, by name: `given` (`--grade-model`), else GRADE_MODEL_ENV, else its strong tier
@@ -100,7 +107,7 @@ const isText = (value) => typeof value === "string";
100
107
  /** The notes a run read and learned, as a view or a list shows them, each name cut of the host's secrets (`shown`):
101
108
  * `given` from its start, `read` once the run settled, `learned` and `pending` (what waits for the owner's OK) once it merged, and the skill
102
109
  * and the workflow draft it merged (`skills`, `workflows`, each `pending` while it waits), each only when it holds one.
103
- * serve.json's are read as untrusted: an entry out of shape is left out. */
110
+ * the stored ones are read as untrusted: an entry out of shape is left out. */
104
111
  export function notesView({ state, given, read: opened, learned, pending, skills, workflows }, shown, settled) {
105
112
  const refs = (list) => (Array.isArray(list) ? list.filter((note) => isText(note?.file) && isText(note.name)).map(({ file, name }) => ({ file: shown.name(file), name: shown.text(name) })) : []);
106
113
  const started = refs(given);
@@ -405,23 +412,55 @@ export async function layLearned(work, seed, shown) {
405
412
  }
406
413
  /** All of `candidates` fit whole: every note within the budget, and an index that names no note main does not hold. */
407
414
  const allFit = ({ notes, indexComplete, budget }) => indexComplete && notes.reduce((sum, { bytes }) => sum + bytes, 0) <= budget;
415
+ /** Past the budget: the first `bearing` notes in `ranked`'s order (those that bear on the run), each whole while it fits
416
+ * what is left of the budget (one that does not is passed over for the next), then one rule line for each of the rest,
417
+ * in the same order, while it fits what the whole notes leave and no more than a run reads of the index (INDEX_LINES,
418
+ * INDEX_BYTES), the section's own lines counted. Whole notes come first: lines never take the room a whole note fits in, so past ~50 notes a run still
419
+ * reads the ones that bear on it whole (Run B, 11-12: past 8 KB of lines every run got lines alone). The rest are left
420
+ * out, and learnedParts names them. */
421
+ const withinBudget = (ranked, budget, read = true, bearing = ranked.length) => {
422
+ const whole = [];
423
+ // The section's own lines (its intro, the read-tool line when the run has the read tool, the blank lines around the
424
+ // rule lines) come first.
425
+ let room = budget - FRAME_BYTES(read);
426
+ for (const { note, bytes } of ranked.slice(0, bearing))
427
+ if (bytes <= room)
428
+ (room -= bytes), whole.push(note);
429
+ if (whole.length === ranked.length)
430
+ return { whole, index: false };
431
+ const taken = new Set(whole);
432
+ const lines = [];
433
+ let lineBytes = 0;
434
+ for (const { note, lineBytes: bytes } of ranked) {
435
+ if (taken.has(note) || lines.length >= INDEX_LINES || bytes > room || lineBytes + bytes > INDEX_BYTES)
436
+ continue;
437
+ room -= bytes;
438
+ lineBytes += bytes;
439
+ lines.push(note);
440
+ }
441
+ return { whole, index: false, lines };
442
+ };
408
443
  /** The selector by recency: every note whole while all fit the budget and the index names no note main does not hold
409
- * whole; else the index, then the newest notes that fit what it leaves, each whole. */
444
+ * whole; notes that fit with an index that names one it lacks, the index, then the newest notes that fit what it
445
+ * leaves, each whole; past the budget, the newest notes whole while they fit, then a line for each of the next while
446
+ * they fit (withinBudget). */
410
447
  export const byRecency = (candidates) => {
411
448
  const { notes, indexBytes, budget } = candidates;
412
449
  if (allFit(candidates))
413
450
  return { whole: notes.map(({ note }) => note), index: false };
451
+ if (notes.reduce((sum, { bytes }) => sum + bytes, 0) > budget)
452
+ return withinBudget(notes, budget, candidates.read);
414
453
  let left = budget - indexBytes;
415
454
  return { whole: notes.filter(({ bytes }) => bytes <= left && ((left -= bytes), true)).map(({ note }) => note), index: true };
416
455
  };
417
456
  /** The default selector, by relevance, past the budget: while the notes fit it, recency's choice (byRecency). Else each
418
457
  * note is scored against the run's input (learn/relevance.ts: BM25 over its name, description and body, a code
419
458
  * review's changed paths' words weighed PATH_WEIGHT; no model call), and the run reads the notes that bear on it most
420
- * whole, in score order, while they fit, then one rule line for each of the rest, best first, in place of the index; the lines count toward the
421
- * budget before the whole notes, as the index did, and no more of them than a run reads of the index (loadedIndex). An
422
- * input with no word any note holds reads by recency. */
459
+ * whole, best first, while they fit the budget, then one rule line for each of the next while they fit what is left
460
+ * (withinBudget), a note that bears on it in no word a line at most; the rest are left out. An input with no word any
461
+ * note holds reads by recency. */
423
462
  export const byRelevance = (candidates, run) => {
424
- // Within the budget, nothing changes: recency's choice (every note whole, or the index where it names a note main lacks).
463
+ // Within the budget, nothing changes: recency's choice (every note whole).
425
464
  if (candidates.notes.reduce((sum, { bytes }) => sum + bytes, 0) <= candidates.budget)
426
465
  return byRecency(candidates, run);
427
466
  const { notes, budget } = candidates;
@@ -430,26 +469,8 @@ export const byRelevance = (candidates, run) => {
430
469
  return byRecency(candidates, run);
431
470
  // Best first; a tie keeps recency (the candidates' order).
432
471
  const ranked = notes.map((candidate, i) => ({ ...candidate, score: scores[i], at: i })).sort((a, b) => b.score - a.score || a.at - b.at);
433
- // The lines of the rest, as the index was read (learn/notes.ts loadedIndex): the first INDEX_LINES, within INDEX_BYTES.
434
- const linesOf = (whole) => {
435
- let bytes = 0;
436
- return ranked.filter(({ note }) => !whole.has(note)).slice(0, INDEX_LINES).filter(({ lineBytes }) => (bytes += lineBytes) <= INDEX_BYTES);
437
- };
438
- const lineBytesOf = (whole) => linesOf(whole).reduce((sum, { lineBytes }) => sum + lineBytes, 0);
439
- // Promoted whole, best first, while the whole notes and the lines served of the rest fit: the room kept for lines is
440
- // only what is served of them (past INDEX_LINES or INDEX_BYTES a line is never served), never every note's.
441
- const whole = new Set();
442
- let wholeBytes = 0;
443
- for (const { note, bytes, score } of ranked) {
444
- if (score <= 0)
445
- break;
446
- whole.add(note);
447
- if (wholeBytes + bytes + lineBytesOf(whole) <= budget)
448
- wholeBytes += bytes;
449
- else
450
- whole.delete(note);
451
- }
452
- return { whole: ranked.filter(({ note }) => whole.has(note)).map(({ note }) => note), index: false, lines: linesOf(whole).map(({ note }) => note) };
472
+ // Only a note that bears on the run is read whole; one that shares no word with it is a line at most.
473
+ return withinBudget(ranked, budget, candidates.read, ranked.filter(({ score }) => score > 0).length);
453
474
  };
454
475
  /** The lines before what a run learned, under `# Learned` after LEARNS, and the one that names `.learning/` to an agent
455
476
  * that can read it. */
@@ -457,9 +478,18 @@ const KEPT = "Follow a note when it applies to what you are doing.";
457
478
  const WHOLE_INTRO = `What you learned in earlier runs: each note whole, newest first. ${KEPT}`;
458
479
  const SOME_INTRO = `What you learned in earlier runs: the index, one line per note, then the newest notes whole. ${KEPT}`;
459
480
  const INDEX_INTRO = `What you learned in earlier runs, one line per note. ${KEPT}`;
460
- const LINES_INTRO = `What you learned in earlier runs: the notes that bear most on this run whole, then one line for each of the rest. ${KEPT}`;
481
+ const LINES_INTRO = `What you learned in earlier runs: the notes that bear most on this run whole, then one line each for more of them. ${KEPT}`;
482
+ const BEST_INTRO = `What you learned in earlier runs: the notes that bear most on this run, each whole. ${KEPT}`;
483
+ const LINES_ONLY_INTRO = `What you learned in earlier runs: one line each for the notes that bear most on this run. ${KEPT}`;
461
484
  const READ_LINE = `The notes not given whole here are files in \`${LEARNED_DIR}/\` in your working directory: open one with the read tool when it applies.`;
462
485
  const oneLine = (text) => text.replace(/\s+/g, " ").trim();
486
+ /** What a run whose notes are all past a budget that holds none of them reads in place of them: that they are there, and,
487
+ * with the read tool, where. Never "Nothing learned yet." while it has notes. */
488
+ const NONE_FIT = "You learned notes in earlier runs, but none fit this run's learning budget, so none is given here.";
489
+ const NONE_FIT_READ = `You learned notes in earlier runs, but none fit this run's learning budget. They are files in \`${LEARNED_DIR}/\` in your working directory: open one with the read tool when it applies.`;
490
+ /** The most a section past the budget takes beside its notes and lines: its longest intro, the read-tool line when the run
491
+ * has the read tool (`read`), and the blank lines between its parts (withinBudget). */
492
+ const FRAME_BYTES = (read) => Math.max(...[LINES_INTRO, BEST_INTRO, LINES_ONLY_INTRO].map((intro) => Buffer.byteLength(intro))) + (read ? Buffer.byteLength(READ_LINE) + 2 : 0) + 4;
463
493
  /** A note as one rule line: its name and file, then its description, cut of the host's secrets. */
464
494
  const ruleLine = (note, shown) => `- ${shown.text(oneLine(note.name))} (${shown.name(note.file)}): ${shown.text(oneLine(note.description))}`;
465
495
  /** A note as a run reads it whole: its name and file, its description, then its body, each cut of the host's secrets. */
@@ -470,8 +500,10 @@ const wholeNote = (note, shown) => [`## ${shown.text(oneLine(note.name))} (${sho
470
500
  * the index, nor counted toward the budget (readSeed reads active notes alone, and servedIndex drops their lines). Its
471
501
  * active notes, newest first (`seed.recent`, else by name), each whole while all fit `budget`; past it, the selector's
472
502
  * choice (byRelevance by default). An agent with the read tool is told the rest are in `.learning/`, one without is not.
503
+ * Notes past a budget that holds none of them (0 among them) are said to be there (NONE_FIT), never "Nothing learned yet.".
473
504
  * Every text is cut of the host's secrets. A run "was given" `given`; of them, it "read" those whose file it opened
474
- * (store-reads/learning.ts notesReadOf). Whether it applied one given whole is not measured. */
505
+ * (store-reads/learning.ts notesReadOf). Whether it applied one given whole is not measured. `left`: the active notes
506
+ * the section names in no way, over the budget, which the run's log names (runner/learning-seed.ts). */
475
507
  export function learnedParts(seed, options) {
476
508
  const { budget, read, shown, select = byRelevance, run = {} } = options;
477
509
  const active = new Map(activeOf(seed).map((note) => [note.file, note]));
@@ -479,7 +511,7 @@ export function learnedParts(seed, options) {
479
511
  const index = servedIndex(seed);
480
512
  const lines = index === undefined ? [] : loadedIndex(index).split("\n").filter((entry) => entry.trim() !== "");
481
513
  if (!notes.length && !lines.length)
482
- return { section: undefined, given: [] };
514
+ return { section: undefined, given: [], left: [] };
483
515
  const blocks = new Map(notes.map((note) => [note, wholeNote(note, shown)]));
484
516
  // Each part's bytes, and the blank line before it.
485
517
  const size = (text) => Buffer.byteLength(text) + 2;
@@ -491,38 +523,45 @@ export function learnedParts(seed, options) {
491
523
  indexBytes: shownIndex ? size(shownIndex) : 0,
492
524
  indexComplete: lines.every((entry) => active.has(linkedFiles(entry)[0] ?? "")),
493
525
  budget,
526
+ read,
494
527
  }, run);
495
528
  const chosen = new Set(choice.whole);
496
529
  const whole = choice.whole.filter((note) => blocks.has(note)).map((note) => blocks.get(note));
497
530
  // Rule lines in place of the index: the whole notes first, then a line for each of the rest the selector names.
498
531
  if (choice.lines) {
499
532
  // The whole section fits the budget, its intro, blank lines and read-tool line counted: while it does not, the last
500
- // whole note goes to the head of the lines (what the selector ranked best of the rest), the lines capped again as the
501
- // index is read. Lines alone may pass the budget, as the index may.
533
+ // line goes, then the last whole note (whole notes are what a run reads past the budget, so they go last). The lines
534
+ // are capped as the index is read.
502
535
  const wholeNotes = choice.whole.filter((note) => blocks.has(note));
503
536
  // The lines as the index is read (learn/notes.ts loadedIndex): the first INDEX_LINES, within INDEX_BYTES, each line
504
- // and its newline counted. Applied again after every demotion, so a note demoted to a line never takes them past it.
537
+ // and its newline counted.
505
538
  const capped = (list) => {
506
539
  let bytes = 0;
507
540
  return list.slice(0, INDEX_LINES).filter((note) => (bytes += Buffer.byteLength(ruleLine(note, shown)) + 1) <= INDEX_BYTES);
508
541
  };
509
- let lined = capped(choice.lines.filter((note) => blocks.has(note) && !chosen.has(note)));
510
- const render = () => [LINES_INTRO, ...wholeNotes.map((note) => blocks.get(note)), lined.map((note) => ruleLine(note, shown)).join("\n"), ...(read && lined.length ? [READ_LINE] : [])].filter(Boolean).join("\n\n");
542
+ const lined = capped(choice.lines.filter((note) => blocks.has(note) && !chosen.has(note)));
543
+ const render = () => [!wholeNotes.length ? LINES_ONLY_INTRO : lined.length ? LINES_INTRO : BEST_INTRO, ...wholeNotes.map((note) => blocks.get(note)), lined.map((note) => ruleLine(note, shown)).join("\n"), ...(read && wholeNotes.length < notes.length ? [READ_LINE] : [])].filter(Boolean).join("\n\n");
511
544
  let section = render();
512
- while (Buffer.byteLength(section) > budget && wholeNotes.length) {
513
- lined = capped([wholeNotes.pop(), ...lined]);
545
+ while (Buffer.byteLength(section) > budget && (lined.length || wholeNotes.length)) {
546
+ if (lined.length)
547
+ lined.pop();
548
+ else
549
+ wholeNotes.pop();
514
550
  section = render();
515
551
  }
516
552
  const served = new Set([...wholeNotes, ...lined]);
517
- return { section, given: notes.filter((note) => served.has(note)) };
553
+ // Notes, none of which fit the budget (0 among them): the run is told they are there, never that it learned nothing.
554
+ if (!served.size)
555
+ return { section: notes.length ? (read ? NONE_FIT_READ : NONE_FIT) : undefined, given: [], left: notes };
556
+ return { section, given: notes.filter((note) => served.has(note)), left: notes.filter((note) => !served.has(note)) };
518
557
  }
519
558
  if (!choice.index)
520
- return { section: [WHOLE_INTRO, ...whole].join("\n\n"), given: notes.filter((note) => chosen.has(note)) };
559
+ return { section: [WHOLE_INTRO, ...whole].join("\n\n"), given: notes.filter((note) => chosen.has(note)), left: notes.filter((note) => !chosen.has(note)) };
521
560
  // Given: each note whole here, and each the index names by its file, by any of a line's links (a hand-edited line may
522
561
  // name more than one; linkedFiles, as servedIndex reads them).
523
562
  const indexed = new Set(lines.flatMap((entry) => linkedFiles(entry).filter((file) => active.has(file))));
524
563
  const given = notes.filter((note) => indexed.has(note.file) || chosen.has(note));
525
- return { section: [whole.length ? SOME_INTRO : INDEX_INTRO, shownIndex, ...(read && whole.length < notes.length ? [READ_LINE] : []), ...whole].filter(Boolean).join("\n\n"), given };
564
+ return { section: [whole.length ? SOME_INTRO : INDEX_INTRO, shownIndex, ...(read && whole.length < notes.length ? [READ_LINE] : []), ...whole].filter(Boolean).join("\n\n"), given, left: notes.filter((note) => !given.includes(note)) };
526
565
  }
527
566
  /** The run's skills folder, `.agents/skills`, as its Workspace names it. */
528
567
  const SKILLS_PATH = RUN_SKILLS.join("/");
@@ -727,16 +766,19 @@ export async function readPin(runDir) {
727
766
  }
728
767
  /** The heading of what a run learned, in its instructions. */
729
768
  export const LEARNED_HEADING = "# Learned";
769
+ /** What a run that only uses what its agent learned (RUN_LEARNING_USE) is told first under it, in place of LEARNS: it is
770
+ * never asked what to keep. */
771
+ const USES = "You learned from earlier runs, below. This run keeps nothing new: when the person asks you to remember something, tell them in one short sentence that this run can't keep it.";
730
772
  /** What every run that learns is told first under it, notes or none: a run not told it learns saves what the person
731
773
  * asks it to remember in a file, or says it cannot, and that is never kept. */
732
774
  const LEARNS = "You learn from your runs. When this run ends you are asked what to keep for later runs, anything the person asked you to remember included, and only your answer then is kept: a file you write is not. So when the person asks you to remember something, don't put it in a file or say you can't: tell them in one short sentence at the start of your reply that you will keep it for later runs. When what they asked sets how your reply starts or ends, follow it from your reply's first line to its last and leave that sentence out. A secret (a password, key or token) is never kept, so say so instead.";
733
775
  /** What a run that starts with no note is told in place of what it learned. */
734
776
  const NOTHING_YET = "Nothing learned yet.";
735
777
  /** A run's instructions with its # Learned section laid in main's position: the revision's instructions, then the heading,
736
- * LEARNS, and the section text — "Nothing learned yet." when the run learns but its section is empty (no notes yet, or a
737
- * seed that could not be read). Shared so the runner (laying launch.learning.section, read with no folder) and app.ts
738
- * (withLearned) lay the same bytes. */
739
- export const laidLearned = (instructions, section) => `${instructions.trim()}\n\n${LEARNED_HEADING}\n\n${LEARNS}\n\n${section || NOTHING_YET}`;
778
+ * LEARNS (USES for a run that only `use`s what its agent learned), and the section text — "Nothing learned yet." when the
779
+ * run learns but its section is empty (no notes yet, or a seed that could not be read). Shared so the runner (laying
780
+ * launch.learning.section, read with no folder) and app.ts (withLearned) lay the same bytes. */
781
+ export const laidLearned = (instructions, section, use = false) => `${instructions.trim()}\n\n${LEARNED_HEADING}\n\n${use ? USES : LEARNS}\n\n${section || NOTHING_YET}`;
740
782
  /** A run's instructions, with `# Learned` after them when its pin in `runDir` says it learns: that it learns, then what
741
783
  * the pin says it learned, or that it has learned nothing yet. A run with no pin (its agent does not learn, its seed
742
784
  * failed, a workflow's run) is never asked what to keep, so it is told nothing. And its skill files: the revision's
@@ -3,7 +3,7 @@
3
3
  // stored commit (live/translate.ts), in commit order, each batch naming its commit's seq so a reader that comes back
4
4
  // resumes from it; and beside them, never inside a commit's batch, what the runner holds before pi stores it (the run's
5
5
  // run_live row: a running tool, a partial answer), in the same vocabulary.
6
- import { RUN_RESUMED } from "../timeline/index.js";
6
+ import { REQUEST_ENDED, REQUEST_STARTED, RUN_RESUMED } from "../timeline/index.js";
7
7
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
8
8
  import { FINAL_STATES } from "../store/store.js";
9
9
  import { emptyState, snapshotOf, translate } from "./translate.js";
@@ -12,8 +12,11 @@ import { emptyState, snapshotOf, translate } from "./translate.js";
12
12
  * row — but it is not a live stream event: a takeover ends the door's watch, so a reader meets the note only in a
13
13
  * reconnect's snapshot, never as a commit on the open stream. The live view polls across a takeover, so without this it
14
14
  * would stream the note's entry_appended; dropping it keeps a run taken over mid-turn streaming the same events as one
15
- * that was not. The note stays in state.entries (translate pushed it before returning), so the next snapshot carries it. */
16
- const delivered = (events) => events.filter((event) => !(event.type === "entry_appended" && event.entry?.kind === RUN_RESUMED));
15
+ * that was not. The note stays in state.entries (translate pushed it before returning), so the next snapshot carries it.
16
+ * A request's start and end marks (REQUEST_STARTED, REQUEST_ENDED) are the same: bookkeeping the timeline reads for a
17
+ * request's cost, no event a watcher is shown. */
18
+ const NOT_STREAMED = new Set([RUN_RESUMED, REQUEST_STARTED, REQUEST_ENDED]);
19
+ const delivered = (events) => events.filter((event) => !(event.type === "entry_appended" && NOT_STREAMED.has(event.entry?.kind)));
17
20
  const PAGE = 500;
18
21
  /** The journals each store's watches read, by (run, epoch), with how many watches hold each. store.journal hands out one
19
22
  * journal per (run, epoch) and keeps it until it is closed: two watches of one run share it, and the last one to end
@@ -1,4 +1,4 @@
1
- import type { JsonValue } from "@earendil-works/chord";
1
+ import type { JsonValue } from "@earendil-works/chord/json";
2
2
  import { type EntryRecord, type SubmissionRecord } from "@earendil-works/pi-durable";
3
3
  import type { JournalCommit } from "../store/journal/storage.js";
4
4
  export type LiveEvent = {
@@ -36,8 +36,9 @@ export interface LiveState {
36
36
  }>;
37
37
  /** An answer streamed as a partial (held): its stored message is only its end. */
38
38
  partial: boolean;
39
- /** Where the run's end-of-run turn began (end-of-run.ts reflectFrom), once its input is placed: its messages from there
40
- * on carry the learning label, a tag the reader puts on (the run writes nothing for it). */
39
+ /** Where the run's end-of-run turn under way began (end-of-run.ts reflectRanges), once its input is placed, until the
40
+ * run's end closes it: its messages from there on carry the learning label, a tag the reader puts on (the run writes
41
+ * nothing for it). A follow-up's messages, after that end, carry none; its next end's turn begins anew. */
41
42
  reflectFrom?: number;
42
43
  }
43
44
  export declare function emptyState(): LiveState;
@@ -1,6 +1,6 @@
1
1
  import { AgentDoc, UsageDoc } from "@earendil-works/pi-durable";
2
2
  import { HOST_PHASE, RUN_RESUMED } from "../timeline/index.js";
3
- import { REFLECT_LABEL, reflectFrom } from "../runner/end-of-run.js";
3
+ import { inReflect, REFLECT_LABEL, reflectRanges } from "../runner/end-of-run.js";
4
4
  import { KINDS } from "../runner/journal-kinds.js";
5
5
  import { PI_STOP } from "../runner/pi-stop.js";
6
6
  export function emptyState() {
@@ -106,9 +106,13 @@ export function translate(state, commit) {
106
106
  const entries = commit.entries.filter(mine);
107
107
  const tasks = commit.tasks.filter(mine);
108
108
  const submissions = commit.submissions.filter(mine);
109
- // The end-of-run turn's input placed in this commit: its messages from there on are the turn's.
110
- state.reflectFrom ??= reflectFrom(submissions, entries);
111
- const tag = (entry) => (state.reflectFrom !== undefined && Number(entry.id) >= state.reflectFrom ? { agent_label: REFLECT_LABEL } : {});
109
+ // The end-of-run turn under way, and any whose input was placed in this commit: their messages, up to the run's end that
110
+ // closes each, are the turn's. One still open after this commit carries on to the next.
111
+ const endAt = (from) => entries.find((entry) => entry.kind === KINDS.end && Number(entry.id) >= from);
112
+ const carried = state.reflectFrom === undefined ? [] : [{ from: state.reflectFrom, ...(endAt(state.reflectFrom) ? { until: Number(endAt(state.reflectFrom).id) } : {}) }];
113
+ const ranges = [...carried, ...reflectRanges(submissions, entries)];
114
+ state.reflectFrom = ranges.filter((range) => range.until === undefined).at(-1)?.from;
115
+ const tag = (entry) => (inReflect(ranges, Number(entry.id)) ? { agent_label: REFLECT_LABEL } : {});
112
116
  for (const entry of entries) {
113
117
  const message = modelOf(entry);
114
118
  if (message?.role === "assistant" && Array.isArray(message.content)) {
@@ -0,0 +1,37 @@
1
+ import type { IncomingMessage } from "node:http";
2
+ /** The header the proxy's proof travels in. */
3
+ export declare const LIVE_PROOF_HEADER = "x-agentrun-live";
4
+ /** How far a proof's time may be from the endpoint's clock. */
5
+ export declare const LIVE_PROOF_MS = 60000;
6
+ /** Where every viewer answers when its runner is on the server's own machine. */
7
+ export declare const LOOPBACK = "127.0.0.1";
8
+ export declare const isLiveHost: (host: unknown) => host is string;
9
+ /** What the server needs to reach a runner's viewer: the hosts it dials (its runners'), and the proof's key. */
10
+ export type LiveReach = {
11
+ readonly hosts: ReadonlySet<string>;
12
+ readonly key: Buffer;
13
+ };
14
+ /** The server's reach, from its environment (AGENTRUN_RUNNER_HOSTS) and the seal key. A name that is not a host is left
15
+ * out. */
16
+ export declare function liveReachOf(env: {
17
+ readonly AGENTRUN_RUNNER_HOSTS?: string | undefined;
18
+ }, sealKey: Buffer): LiveReach;
19
+ /** Where the server dials `host` (a row's): loopback with none; the host when it is one of its runners'; else nowhere. */
20
+ export declare function dialHost(host: string | undefined, reach: LiveReach | undefined): string | undefined;
21
+ /** The proxy's proof for viewer `viewerId`, at `at` (ms). */
22
+ export declare const liveProof: (reach: Pick<LiveReach, "key">, viewerId: string, at?: number) => string;
23
+ /** Where a runner's viewers answer: the host the server reaches it at (put in each row), the address they listen on,
24
+ * and the proof's key. */
25
+ export type RunnerLive = {
26
+ readonly host: string;
27
+ readonly bind: string;
28
+ readonly key: Buffer;
29
+ };
30
+ /** The runner's live host, from its environment (AGENTRUN_RUNNER_LIVE_HOST, AGENTRUN_RUNNER_LIVE_BIND) and the seal key;
31
+ * undefined with none (or one that is not a host): its viewers answer on loopback, as on a server's own machine. */
32
+ export declare function runnerLiveOf(env: {
33
+ readonly AGENTRUN_RUNNER_LIVE_HOST?: string | undefined;
34
+ readonly AGENTRUN_RUNNER_LIVE_BIND?: string | undefined;
35
+ }, sealKey: Buffer): RunnerLive | undefined;
36
+ /** Whether `req` carries a good, fresh proof for viewer `viewerId` under `live`'s key. */
37
+ export declare function provenFor(req: Pick<IncomingMessage, "headers">, live: Pick<RunnerLive, "key">, viewerId: string, now?: number): boolean;
@@ -0,0 +1,62 @@
1
+ // A live viewer on a runner on another host than its server (one image, a server and its runners apart). The runner says
2
+ // where it answers (AGENTRUN_RUNNER_LIVE_HOST: a host name or IPv4 address the server reaches it at; the viewers listen
3
+ // on AGENTRUN_RUNNER_LIVE_BIND, that host by default) and puts that host in each viewer's row. The server dials a row's
4
+ // host only when it is one of its runners' (AGENTRUN_RUNNER_HOSTS, a comma list), else the row reads as no viewer: a
5
+ // store writer that is no runner can't aim the server's socket elsewhere. Each request the server makes of a runner's
6
+ // viewer (the HEAD that asks whether it answers, and the proxied WebSocket) carries the proxy's proof: an HMAC of the
7
+ // viewer's id and the time, under a key derived from the seal key the server and its runners already share. A runner's
8
+ // endpoint off loopback takes no request without a good, fresh proof for its own viewer. The proof is not the viewer's:
9
+ // the hello's token still decides who watches. The hop is plain HTTP, for a private network (the server and its
10
+ // runners' own); TLS on it is a later step.
11
+ import { createHmac, hkdfSync, timingSafeEqual } from "node:crypto";
12
+ /** The header the proxy's proof travels in. */
13
+ export const LIVE_PROOF_HEADER = "x-agentrun-live";
14
+ /** How far a proof's time may be from the endpoint's clock. */
15
+ export const LIVE_PROOF_MS = 60_000;
16
+ /** A host a row may name: a DNS name or an IPv4 address, nothing with a port, a path or a scheme. */
17
+ const HOST = /^(?=.{1,253}$)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
18
+ /** Where every viewer answers when its runner is on the server's own machine. */
19
+ export const LOOPBACK = "127.0.0.1"; // key-gate: loopback-rule where a viewer on the same machine as its server answers
20
+ /** The derived key's label: the seal key itself is never a MAC key. */
21
+ const LABEL = "agentrun live proxy v1";
22
+ export const isLiveHost = (host) => typeof host === "string" && HOST.test(host);
23
+ const proofKey = (sealKey) => Buffer.from(hkdfSync("sha256", sealKey, Buffer.alloc(0), LABEL, 32));
24
+ const mac = (key, viewerId, at) => createHmac("sha256", key).update(`${viewerId}\n${at}`).digest("hex");
25
+ /** The server's reach, from its environment (AGENTRUN_RUNNER_HOSTS) and the seal key. A name that is not a host is left
26
+ * out. */
27
+ export function liveReachOf(env, sealKey) {
28
+ const hosts = new Set((env.AGENTRUN_RUNNER_HOSTS ?? "").split(",").map((host) => host.trim().toLowerCase()).filter(isLiveHost));
29
+ return { hosts, key: proofKey(sealKey) };
30
+ }
31
+ /** Where the server dials `host` (a row's): loopback with none; the host when it is one of its runners'; else nowhere. */
32
+ export function dialHost(host, reach) {
33
+ if (host === undefined || host === LOOPBACK)
34
+ return LOOPBACK;
35
+ return reach?.hosts.has(host.toLowerCase()) ? host : undefined;
36
+ }
37
+ /** The proxy's proof for viewer `viewerId`, at `at` (ms). */
38
+ export const liveProof = (reach, viewerId, at = Date.now()) => `${at}.${mac(reach.key, viewerId, at)}`;
39
+ /** The runner's live host, from its environment (AGENTRUN_RUNNER_LIVE_HOST, AGENTRUN_RUNNER_LIVE_BIND) and the seal key;
40
+ * undefined with none (or one that is not a host): its viewers answer on loopback, as on a server's own machine. */
41
+ export function runnerLiveOf(env, sealKey) {
42
+ // Lower case, as a URL's hostname reads a DNS name and the server's runners' hosts are read (liveReachOf): one form for
43
+ // the links, the origins and the rows.
44
+ const host = env.AGENTRUN_RUNNER_LIVE_HOST?.trim().toLowerCase();
45
+ if (!isLiveHost(host) || host === LOOPBACK)
46
+ return undefined;
47
+ const bind = env.AGENTRUN_RUNNER_LIVE_BIND?.trim().toLowerCase();
48
+ return { host, bind: bind && (isLiveHost(bind) || bind === "0.0.0.0") ? bind : host, key: proofKey(sealKey) };
49
+ }
50
+ /** Whether `req` carries a good, fresh proof for viewer `viewerId` under `live`'s key. */
51
+ export function provenFor(req, live, viewerId, now = Date.now()) {
52
+ const said = req.headers[LIVE_PROOF_HEADER];
53
+ const match = typeof said === "string" ? /^(\d{1,16})\.([0-9a-f]{64})$/.exec(said) : null;
54
+ if (!match)
55
+ return false;
56
+ const at = Number(match[1]);
57
+ if (!Number.isSafeInteger(at) || Math.abs(now - at) > LIVE_PROOF_MS)
58
+ return false;
59
+ const want = Buffer.from(mac(live.key, viewerId, at), "hex");
60
+ const got = Buffer.from(match[2], "hex");
61
+ return got.length === want.length && timingSafeEqual(got, want);
62
+ }
@@ -69,6 +69,15 @@ export interface McpGatewayOptions {
69
69
  };
70
70
  /** The run's commit to its store: an unpriced call's "not metered" is written on its root. */
71
71
  commit?: () => McpCommit | undefined;
72
+ /** Where each request to a server may go, asked before anything is sent to it: the runner's MCP claim passes the
73
+ * address rule (mcp-oauth.ts mcpServerAt) with the owner's private-network hosts read now, and a fetch dialled at the
74
+ * address it checked (`send`; none, `fetch` as it is). A refusal is said to the model, nothing sent. None: every
75
+ * request goes as `fetch` sends it. */
76
+ reach?: (url: string, signal: AbortSignal) => Promise<{
77
+ refused: string;
78
+ } | {
79
+ send?: typeof fetch;
80
+ }>;
72
81
  /** The claim's per-call check of a server's credential (its custody stamp): awaited before each call is checked for
73
82
  * sending, it may drop the credential (`credentials[server].unopened`), which the call then refuses unsent; one that
74
83
  * throws (a store read failed, the call was stopped) refuses the call unsent too, in words, and the run goes on. Only