@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
@@ -1,8 +1,9 @@
1
1
  import { type TimelineEvent } from "../timeline/index.js";
2
2
  import { type LearningFolder } from "../learn/folder.js";
3
+ import type { RunPath } from "../learning-cost.js";
3
4
  import { type RunLaunch } from "../run-launch.js";
4
5
  import { type SignInReader } from "../run-view.js";
5
- import type { Store } from "../store/store.js";
6
+ import { type Store } from "../store/store.js";
6
7
  import type { EndOfRunTurn } from "./loop-contract.js";
7
8
  /** What the step reads: the run's store, the data directory (the server's tool settings a draft's tools are read with),
8
9
  * the agent's learning folder (where the run's place keeps it), the runner's environment (the host's secrets a
@@ -24,15 +25,50 @@ export interface LearningEndDeps {
24
25
  /** Every secret the server keeps sealed, read once at the run's end (store-secrets.ts storeSecrets over the store, the
25
26
  * seal key and the data directory), never learned. A throw is a list that can't be read: the run learns nothing. */
26
27
  readonly stored?: () => Promise<readonly string[]>;
28
+ /** The decision providers a draft's decision nodes may ask (LS-07): built on the host's keys (claim-secrets.ts
29
+ * hostDecisionKeys), host-side, never handed to the run. Read once per check; none: a draft with a decision node is
30
+ * refused. */
31
+ readonly decisionProviders?: () => Promise<{
32
+ readonly providers: Readonly<Record<string, unknown>>;
33
+ readonly default: string;
34
+ } | undefined>;
27
35
  }
28
36
  /** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
29
37
  * does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
30
38
  export declare function learningEndOfRun(launch: RunLaunch, deps: LearningEndDeps): EndOfRunTurn | undefined;
39
+ /** What every cap gate of run `runId` reads as spent beside it on its behalf (adapter-loop.ts RunCapConfig.beside): its
40
+ * learning runs' grades (Store.learning.spentBeside, the one figure), for a capped run that learns, the only run whose
41
+ * ends queue them; none for any other, whose gates read only its own sessions. */
42
+ export declare function spentBesideOf(launch: RunLaunch, store: Pick<Store, "learning">, runId: string): (() => Promise<number | null>) | undefined;
43
+ /** The cap the grade of round `round` of run `runId` runs under (its learning run's max_cost_usd), so the run's grades
44
+ * never take it past its cap: the cap the run is held to now (capNowOf: its newest raise's, else `launchCapUsd`), less
45
+ * what the run spent (its job, its follow-ups and every look-back, its timeline's cost) and what was spent beside it on its
46
+ * behalf by its earlier rounds (Learning.spentBeside, the figure the run's own gates read: each earlier grade at its cost
47
+ * once it ended, at its own cap while it has not). $0, no room, when any of those is unknown (a cost null, or a read that
48
+ * fails): a grade whose room can't be read is skipped, never run past the cap. */
49
+ export declare function gradeCapOf(store: Store, runId: string, round: number, launchCapUsd: number): Promise<number>;
50
+ /** The learning run of round `round` of run `runId`'s learning: `<runId>-learning` for its first, `<runId>-learning-<n>`
51
+ * for each later one. */
52
+ export declare const learningRunIdOf: (runId: string, round?: number) => string;
53
+ /** learned_workflow by every name a harness calls it: its own, and claude-agent's host-tool alias (`mcp__hands__<name>`).
54
+ * A harness that names it another way reads as another tool, so its run is asked as before. */
55
+ export declare const LEARNED_NAMES: ReadonlySet<string>;
31
56
  /** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
32
57
  * nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
33
58
  * its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
34
59
  * came in. Anything else is asked its end-of-run turn. */
35
60
  export declare function onlyLearnedWorkflows(rows: readonly TimelineEvent[]): boolean;
61
+ /** The path a run took (learning-cost.ts RunPath), by its timeline `rows` as runTimeline labels them (its end-of-run
62
+ * turn's rows, LEARNING_LABEL, are the learning's and left out): `workflow` when its job did only what
63
+ * onlyLearnedWorkflows asks of a run with nothing new to look back on, `handed_back` when it called a learned workflow
64
+ * otherwise, `agent` when it called none. */
65
+ export declare function runPathOf(rows: readonly TimelineEvent[]): RunPath;
66
+ /** The learned workflow a run's job called last by its call's `name` (callArgsOf's arguments, in the job's order: `calls`),
67
+ * or null when it called none by a name. */
68
+ export declare function workflowNameOf(calls: readonly {
69
+ tool: string;
70
+ args: Record<string, unknown>;
71
+ }[]): string | null;
36
72
  /** How many of an agent's latest runs draftForOf reads at most: a skill offered to fewer than DRAFT_AFTER_RUNS of them is
37
73
  * no repeated job. */
38
74
  export declare const DRAFT_SCAN_RUNS = 200;
@@ -28,6 +28,7 @@ import { Hearing } from "../heard.js";
28
28
  import { readSnapshot } from "../learn/folder.js";
29
29
  import { DRAFT_AFTER_RUNS } from "../learn/reflect.js";
30
30
  import { SKILL_NAME } from "../learn/skills.js";
31
+ import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
31
32
  import { handedValuesOf } from "../handed-values.js";
32
33
  import { MIN_SECRET } from "../learn/secrets.js";
33
34
  import { LEARNED_WORKFLOW_TOOL } from "../learned-workflow.js";
@@ -46,28 +47,37 @@ import { runnerSecrets } from "./redact.js";
46
47
  * does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
47
48
  export function learningEndOfRun(launch, deps) {
48
49
  const start = learningStartOf(launch);
49
- if (!start)
50
+ // A run that only uses what its agent learned (`learning: "use"`) is asked nothing and keeps nothing, at every end.
51
+ if (!start || start.use)
50
52
  return undefined;
51
53
  const env = deps.env ?? process.env;
52
54
  // The grade model the server named at the run's start (its learning start's), none: the agent's own grades it.
53
55
  const gradeModel = start.gradeModel;
54
- const hookFor = (runId) => createReflectHook({
56
+ const hookFor = (runId, round, before) => createReflectHook({
57
+ round,
58
+ ...(before ? { before } : {}),
55
59
  // reflectSkip's facts: a run its cap stopped has no room left, and one whose spend is unknown under a cap cannot be
56
60
  // kept within it. The cap is the run's now (capNowOf: its newest raise's, else its launch's), the one its requests
57
61
  // were admitted under, never the launch's alone. A person's stop comes to the hook as its `cut`.
62
+ // What its earlier rounds' grades took beside it counts toward that cap as its own spend does (Learning.spentBeside, the
63
+ // figure its gates read): unknown, no room.
58
64
  facts: async (runId) => {
59
65
  const costUsd = costOf(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false }));
60
66
  const capUsd = launch.maxCostUsd === undefined ? undefined : capNowOf(launch.maxCostUsd, await runEntries(deps.store, runId, BACKGROUND_CONTEXT));
61
- return { learns: true, costUsd, ...(capUsd !== undefined ? { capUsd, capReached: costUsd !== null && costUsd >= capUsd } : {}) };
67
+ if (capUsd === undefined)
68
+ return { learns: true, costUsd };
69
+ const beside = await deps.store.learning.spentBeside(runId);
70
+ return { learns: true, costUsd, capUsd, capReached: costUsd !== null && (beside === null || costUsd + beside >= capUsd) };
62
71
  },
63
72
  nothingNew: async (runId) => onlyLearnedWorkflows(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false })),
64
73
  // A draft asked for or not never stops the turn: a count that can't be read asks for none.
65
74
  promptFacts: async (runId, agentId) => {
66
- const { tools } = await draftTools(deps, runId);
67
- const draftFor = await draftForOf(deps, agentId, runId, start.skills ?? []).catch(() => []);
75
+ const { tools, decisions } = await draftTools(deps, runId);
76
+ // A notes run (`learning: "notes"`) is asked for no workflow draft, and its prompt describes none.
77
+ const draftFor = start.notesOnly ? [] : await draftForOf(deps, agentId, runId, start.skills ?? []).catch(() => []);
68
78
  // With a draft asked for, what each tool its call nodes may run takes and gives, in the server's own words.
69
79
  const described = draftFor.length ? await describedOf(tools, deps.store) : [];
70
- return { active: start.seedNotes ?? start.given.length, tools, draftFor, described };
80
+ return { active: start.seedNotes ?? start.given.length, tools, draftFor, described, ...(decisions ? { decisions } : {}), ...(start.notesOnly ? { workflows: false } : {}) };
71
81
  },
72
82
  asked: async (runId) => {
73
83
  const [entries, reflect] = await Promise.all([runEntries(deps.store, runId, BACKGROUND_CONTEXT), runReflect(deps.store, runId, BACKGROUND_CONTEXT)]);
@@ -97,10 +107,17 @@ export function learningEndOfRun(launch, deps) {
97
107
  check: async ({ runId, agentId, turn, outcome, refuse }) => {
98
108
  if (start.seed === null)
99
109
  throw new Error("the run's learning start names no commit of main to propose against");
100
- return checkedOf(deps, { runId, agentId, seed: start.seed, turn, outcome, refuse });
110
+ // A later round checks against the main the earlier rounds merged into, not the seed the run started from: a note
111
+ // round 1 added and a reviewer corrected is a supersedes target round 2 may name.
112
+ // The skills and workflows keep the seed the run was laid from as their conflict base (the merge refuses a file main
113
+ // changed since), so only the notes are checked against that main.
114
+ const notesSeed = round > 1 ? await mainOf(deps, agentId) : undefined;
115
+ return checkedOf(deps, { runId, agentId, seed: start.seed, ...(notesSeed ? { notesSeed } : {}), turn, outcome, refuse, ...(start.notesOnly ? { workflows: false } : {}) });
101
116
  },
102
- // The learning run's id, one per run: a replayed end queues the same one (the store adds it once).
103
- newRunId: () => `${runId}-learning`,
117
+ // The learning run's id, one per round of the run: a replayed end queues the same one (the store adds it once).
118
+ newRunId: () => learningRunIdOf(runId, round),
119
+ // The cap its grade runs under (none for an uncapped run): what the run's cap leaves now.
120
+ ...(launch.maxCostUsd !== undefined ? { gradeCap: (runId) => gradeCapOf(deps.store, runId, round, launch.maxCostUsd) } : {}),
104
121
  ...(gradeModel ? { gradeModel } : {}),
105
122
  });
106
123
  return async (input) => {
@@ -110,14 +127,53 @@ export function learningEndOfRun(launch, deps) {
110
127
  if (seedFailed(start)) {
111
128
  const failed = start.seedFailed;
112
129
  const why = failed === "unreadable" ? STOPPED.unreadable : failed === "not_copied" ? STOPPED.notCopied : STOPPED.noSeed;
130
+ // Every end of it: the first's drop stands for a later one (the store keeps one a round, so it adds nothing new).
113
131
  return { also: [{ table: "learning_proposals", row: { turn: null, proposal: { state: "dropped", reason: "seed_failed", detail: said.stopped(why) } } }] };
114
132
  }
115
- return hookFor(input.runId)(input);
133
+ // Which end of the run this is: the round after the newest it kept (a follow-up opened the run again after it), else
134
+ // its first. A replayed end reads the same round: its rows are written only with the end that closes it.
135
+ const prior = await deps.store.learning.proposal(input.runId);
136
+ const round = prior ? prior.round + 1 : 1;
137
+ const kept = prior?.proposal;
138
+ const spent = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
139
+ const before = prior ? { job_cost_usd: spent(kept?.job_cost_usd), look_back_usd: spent(kept?.look_back_usd), looked: prior.turn !== null } : undefined;
140
+ return hookFor(input.runId, round, before)(input);
116
141
  };
117
142
  }
143
+ /** What every cap gate of run `runId` reads as spent beside it on its behalf (adapter-loop.ts RunCapConfig.beside): its
144
+ * learning runs' grades (Store.learning.spentBeside, the one figure), for a capped run that learns, the only run whose
145
+ * ends queue them; none for any other, whose gates read only its own sessions. */
146
+ export function spentBesideOf(launch, store, runId) {
147
+ const start = learningStartOf(launch);
148
+ if (launch.maxCostUsd === undefined || !start || start.use)
149
+ return undefined;
150
+ return () => store.learning.spentBeside(runId);
151
+ }
152
+ /** The cap the grade of round `round` of run `runId` runs under (its learning run's max_cost_usd), so the run's grades
153
+ * never take it past its cap: the cap the run is held to now (capNowOf: its newest raise's, else `launchCapUsd`), less
154
+ * what the run spent (its job, its follow-ups and every look-back, its timeline's cost) and what was spent beside it on its
155
+ * behalf by its earlier rounds (Learning.spentBeside, the figure the run's own gates read: each earlier grade at its cost
156
+ * once it ended, at its own cap while it has not). $0, no room, when any of those is unknown (a cost null, or a read that
157
+ * fails): a grade whose room can't be read is skipped, never run past the cap. */
158
+ export async function gradeCapOf(store, runId, round, launchCapUsd) {
159
+ try {
160
+ const capUsd = capNowOf(launchCapUsd, await runEntries(store, runId, BACKGROUND_CONTEXT));
161
+ const spent = costOf(await runTimeline(store, runId, BACKGROUND_CONTEXT, { settled: false }));
162
+ const beside = await store.learning.spentBeside(runId, { beforeRound: round });
163
+ if (capUsd === undefined || spent === null || !Number.isFinite(spent) || beside === null)
164
+ return 0;
165
+ return Math.max(0, capUsd - spent - beside);
166
+ }
167
+ catch {
168
+ return 0;
169
+ }
170
+ }
171
+ /** The learning run of round `round` of run `runId`'s learning: `<runId>-learning` for its first, `<runId>-learning-<n>`
172
+ * for each later one. */
173
+ export const learningRunIdOf = (runId, round = 1) => (round > 1 ? `${runId}-learning-${round}` : `${runId}-learning`);
118
174
  /** learned_workflow by every name a harness calls it: its own, and claude-agent's host-tool alias (`mcp__hands__<name>`).
119
175
  * A harness that names it another way reads as another tool, so its run is asked as before. */
120
- const LEARNED_NAMES = new Set([LEARNED_WORKFLOW_TOOL, `mcp__hands__${LEARNED_WORKFLOW_TOOL}`]);
176
+ export const LEARNED_NAMES = new Set([LEARNED_WORKFLOW_TOOL, `mcp__hands__${LEARNED_WORKFLOW_TOOL}`]);
121
177
  /** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
122
178
  * nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
123
179
  * its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
@@ -137,6 +193,26 @@ export function onlyLearnedWorkflows(rows) {
137
193
  const answered = new Set(results.filter((row) => !row.parent_tool_use_id).map((row) => row.tool_use_id));
138
194
  return calls.every((row) => answered.has(row.tool_use_id));
139
195
  }
196
+ /** The path a run took (learning-cost.ts RunPath), by its timeline `rows` as runTimeline labels them (its end-of-run
197
+ * turn's rows, LEARNING_LABEL, are the learning's and left out): `workflow` when its job did only what
198
+ * onlyLearnedWorkflows asks of a run with nothing new to look back on, `handed_back` when it called a learned workflow
199
+ * otherwise, `agent` when it called none. */
200
+ export function runPathOf(rows) {
201
+ const ran = rows.some((row) => row.agent_label !== LEARNING_LABEL && row.kind === "tool_use" && !row.parent_tool_use_id && LEARNED_NAMES.has(row.tool_name ?? ""));
202
+ if (!ran)
203
+ return "agent";
204
+ return onlyLearnedWorkflows(rows) ? "workflow" : "handed_back";
205
+ }
206
+ /** The learned workflow a run's job called last by its call's `name` (callArgsOf's arguments, in the job's order: `calls`),
207
+ * or null when it called none by a name. */
208
+ export function workflowNameOf(calls) {
209
+ for (let i = calls.length - 1; i >= 0; i--) {
210
+ const call = calls[i];
211
+ if (LEARNED_NAMES.has(call.tool) && typeof call.args.name === "string")
212
+ return call.args.name;
213
+ }
214
+ return null;
215
+ }
140
216
  /** Why each draft of `proposal` waits for its owner's OK whatever the grade: its steps calling an MCP tool with no
141
217
  * declared price (skills.ts unpricedCalls), by its workflow.json's path, from the prices each server's row keeps
142
218
  * (mcp-probe.ts McpPrices). A server the store can't read gives no price: held. */
@@ -277,21 +353,46 @@ async function draftTools(deps, runId) {
277
353
  // `deniedBy`: where each deny was set (the agent's tool settings, the server's, a default), which a left-out draft's
278
354
  // words name.
279
355
  const { tools, gated, deniedBy, asked } = learnedDraftTools(granted, (name) => permissionFrom(name, server, agent, approvals).permission, undefined, (name) => permissionFrom(name, server, agent, approvals).from, { mcp: true, approvers: await readApprovers(deps.store.settings) });
280
- return { tools, gated, deniedBy, asked };
356
+ // A draft's decision nodes (LS-07): the host's decision providers, each held to the gate by its bare id as the run's
357
+ // gate holds it (tool-plane.ts DECISION_PROVIDER_KEYS); deny alone refuses one.
358
+ const providers = await deps.decisionProviders?.();
359
+ if (!providers)
360
+ return { tools, gated, deniedBy, asked };
361
+ const decided = {};
362
+ const decisionDeniedBy = {};
363
+ for (const id of DECISION_PROVIDER_KEYS) {
364
+ const { permission, from } = permissionFrom(id, server, agent, approvals);
365
+ if (permission === "allow")
366
+ continue;
367
+ decided[id] = permission;
368
+ if (permission === "deny")
369
+ decisionDeniedBy[id] = from;
370
+ }
371
+ return { tools, gated, deniedBy, asked, decisions: { providers: providers.providers, default: providers.default, gated: decided, deniedBy: decisionDeniedBy } };
372
+ }
373
+ /** The commit main of the agent's learning folder is at now; none for a folder with no main yet. */
374
+ async function mainOf(deps, agentId) {
375
+ const folder = deps.learningFolder(agentId);
376
+ try {
377
+ return (await readSnapshot(folder.workspace))?.main ?? undefined;
378
+ }
379
+ finally {
380
+ await folder.end();
381
+ }
281
382
  }
282
383
  /** proposeRun's checks over the turn, against seed `seed`, in a directory of the step's own: the proposal it keeps there
283
384
  * is read back for the hook to store with the run's end, and the directory is removed. */
284
385
  async function checkedOf(deps, input) {
285
386
  const runDir = await mkdtemp(join(tmpdir(), "agentrun-learning-end-"));
286
387
  try {
287
- const { tools, gated, deniedBy, asked } = await draftTools(deps, input.runId);
388
+ const { tools, gated, deniedBy, asked, decisions } = await draftTools(deps, input.runId);
288
389
  // #2424's card rule (learnedAskFits): a draft whose ask-set MCP tools would not all show on its approval card is refused.
289
390
  const { learnedAskFits } = await import("../learned-workflow.js");
290
391
  const turn = { answer: input.turn.answer, asked: [...input.turn.asked], ...(input.turn.triggered?.length ? { triggered: input.turn.triggered.map((one) => ({ ...one })) } : {}) };
291
392
  const folder = deps.learningFolder(input.agentId);
292
393
  let proposed;
293
394
  try {
294
- proposed = await proposeRun({ folder: folder.workspace, runDir, seed: input.seed, turn, refuse: input.refuse, outcome: input.outcome, tools, ...(Object.keys(gated).length ? { gated } : {}), ...(Object.keys(deniedBy).length ? { deniedBy } : {}), ask: { asked, fits: learnedAskFits } });
395
+ proposed = await proposeRun({ folder: folder.workspace, runDir, seed: input.seed, ...(input.notesSeed ? { notesSeed: input.notesSeed } : {}), turn, refuse: input.refuse, outcome: input.outcome, tools, ...(Object.keys(gated).length ? { gated } : {}), ...(Object.keys(deniedBy).length ? { deniedBy } : {}), ask: { asked, fits: learnedAskFits }, ...(decisions ? { decisions } : {}), ...(input.workflows === false ? { workflows: false } : {}) });
295
396
  }
296
397
  finally {
297
398
  await folder.end();
@@ -3,7 +3,7 @@ import { type LearningLoopDeps } from "./learning-loop.js";
3
3
  import type { LoopFactory } from "./loop-contract.js";
4
4
  /** The harness a learning run's launch names (store/sqlite/run-patch.ts learningLaunchOf). */
5
5
  export declare const LEARNING_HARNESS = "learning";
6
- export interface LearningFactoryDeps extends Pick<LearningLoopDeps, "ask" | "now"> {
6
+ export interface LearningFactoryDeps extends Pick<LearningLoopDeps, "ask" | "now" | "general" | "generalThreshold"> {
7
7
  readonly store: Pick<Store, "runs" | "agents" | "learning">;
8
8
  /** The server's data directory: where each agent's learning folder is. */
9
9
  readonly data: string;
@@ -6,8 +6,11 @@
6
6
  // (passed in by the runner's wiring);
7
7
  // folder the agent's learning folder in the server's data (learn/folder.ts learningWorkspace), ended after each run;
8
8
  // readMain main as the grader reads it, from the folder's snapshot (learn/commit.ts readMain);
9
- // commit the folder's one write (learn/commit.ts learningCommit).
10
- import { learningCommit, readMain } from "../learn/commit.js";
9
+ // commit the folder's one write (learn/commit.ts learningCommit);
10
+ // merged the run's merge when it is on main already, with the texts its own commit holds (learn/commit.ts mergedAt),
11
+ // for a resume after its commit;
12
+ // general the generality pre-check (learn/general.ts), on this host's Jev, when it has one (passed in by the wiring).
13
+ import { learningCommit, mainTexts, mergedAt, readMain } from "../learn/commit.js";
11
14
  import { learningWorkspace } from "../learn/folder.js";
12
15
  import { createLearningLoop } from "./learning-loop.js";
13
16
  /** The harness a learning run's launch names (store/sqlite/run-patch.ts learningLaunchOf). */
@@ -18,20 +21,27 @@ export function learningLoopFactory(deps) {
18
21
  return createLearningLoop({
19
22
  sourceOf: async (learningRunId) => {
20
23
  const launch = await store.runs.launch(learningRunId);
21
- const runId = objectOf(objectOf(launch.body).input).runId;
24
+ const input = objectOf(objectOf(launch.body).input);
25
+ const runId = input.runId;
22
26
  if (typeof runId !== "string")
23
27
  return undefined;
24
28
  const source = await store.runs.get(runId);
25
29
  if (!source)
26
30
  return undefined;
27
31
  const instructions = objectOf((await store.agents.revision(source.revisionId))?.body).instructions;
28
- return { runId, agentId: source.agentId, ...(typeof instructions === "string" ? { instructions } : {}) };
32
+ const round = Number.isSafeInteger(input.round) && input.round > 1 ? { round: input.round } : {};
33
+ return { runId, ...round, agentId: source.agentId, ...(typeof instructions === "string" ? { instructions } : {}) };
29
34
  },
30
- proposal: (runId) => store.learning.proposal(runId),
35
+ proposal: (runId, round) => store.learning.proposal(runId, round),
31
36
  ask: deps.ask,
32
37
  folder: (agentId) => learningWorkspace({ mode: "local", agentId, data: deps.data, ...(deps.log ? { log: deps.log } : {}) }),
33
38
  readMain: async (ws, proposal) => (await readMain(ws, { notes: proposal.notes })),
34
39
  commit: async (ws, change) => (await learningCommit(ws, change)),
40
+ mainTexts: (ws, paths) => mainTexts(ws, paths),
41
+ merged: (ws, runId, paths, round) => mergedAt(ws, runId, paths, round),
35
42
  ...(deps.now ? { now: deps.now } : {}),
43
+ ...(deps.general ? { general: deps.general } : {}),
44
+ ...(deps.generalThreshold !== undefined ? { generalThreshold: deps.generalThreshold } : {}),
45
+ ...(deps.log ? { log: deps.log } : {}),
36
46
  });
37
47
  }
@@ -1,4 +1,5 @@
1
1
  import type { LearningProposal } from "../store/store.js";
2
+ import { type GeneralScores, type GeneralSource } from "../learn/general.js";
2
3
  import { type IndexEntry, type NoteText, type Verdict } from "../learn/grade.js";
3
4
  import type { LearnedFile, NoteLearned, Tokens } from "../learning.js";
4
5
  import type { Journal, Loop, LoopDeps } from "./loop-contract.js";
@@ -17,6 +18,8 @@ export interface KeptProposal {
17
18
  readonly status: string;
18
19
  readonly detail?: string;
19
20
  }>>;
21
+ /** The skill of each draft's name as the folder held it at the seed, which the grader is shown beside the draft. */
22
+ readonly drafted?: readonly NoteText[];
20
23
  readonly asked?: readonly string[];
21
24
  /** Why each draft waits for its owner's OK whatever the grade (the learning end's: skills.ts unpricedCalls). */
22
25
  readonly held?: Readonly<Record<string, readonly string[]>>;
@@ -33,16 +36,49 @@ export interface GradeMain {
33
36
  readonly active: readonly IndexEntry[];
34
37
  readonly superseded: readonly NoteText[];
35
38
  readonly graded: Readonly<Record<string, string>>;
39
+ /** The proposal's notes named like a note main holds, left out of the grade and settled alone (learn/commit.ts
40
+ * readMain): `same` when main's note says its rule, else `taken`. */
41
+ readonly taken?: readonly {
42
+ readonly path: string;
43
+ readonly reason: "same" | "taken";
44
+ }[];
36
45
  }
37
46
  export type Problem = {
38
47
  readonly rule: string;
39
48
  readonly path?: string;
40
49
  readonly detail: string;
41
50
  };
51
+ /** A grader call its learning run's cap refused before it was sent (learning-ask.ts bookedAsk: the run's cap left, its
52
+ * launch's max_cost_usd): nothing of it was spent, and the grade is skipped, said so (said.noRoomToGrade), never run past
53
+ * the cap, never a failure. `forGood`: no room could ever send it (its spend or price unknown), not only none now. */
54
+ export declare class GradeOverCap extends Error {
55
+ readonly forGood: boolean;
56
+ readonly booked?: GradeBooked | undefined;
57
+ /** `booked`: the grade's records when it was refused (GradeBooked), what it spent before it. */
58
+ constructor(message: string, forGood: boolean, booked?: GradeBooked | undefined);
59
+ }
60
+ /** A generality check its learning run's cap refused before any of its requests left (learning-dispatch.ts general: its
61
+ * worst case over the cap left): nothing of it was sent or spent, and it is skipped as `unchecked` "no_budget"
62
+ * (GENERAL_NO_BUDGET), said so, the grader then judged against the cap on its own. `forGood`: no room could ever send it
63
+ * (its provider's price unknown here), not only none now. */
64
+ export declare class GeneralOverCap extends Error {
65
+ readonly forGood: boolean;
66
+ constructor(message: string, forGood: boolean);
67
+ }
68
+ /** The grade's own records after an ask (learning-ask.ts bookedAsk: its session's booking): what every grade request of
69
+ * the learning run spent, an earlier attempt's included (null: unknown, as a cut one's), and how many left. What the
70
+ * grade ends with is read from these, never summed in memory alone: a runner that restarted before the grade was saved
71
+ * holds no sum of what its earlier attempt spent. */
72
+ export type GradeBooked = {
73
+ readonly usd: number | null;
74
+ readonly turns: number;
75
+ };
42
76
  /** The folder's one write (learn/commit.ts learningCommit), a merge. */
43
77
  export interface MergeChange {
44
78
  readonly kind: "merge";
45
79
  readonly runId: string;
80
+ /** The round of the run's looks back it merges, past the first (learn/folder.ts runDiffKey). */
81
+ readonly round?: number;
46
82
  readonly reason: string;
47
83
  readonly files: readonly {
48
84
  readonly path: string;
@@ -52,12 +88,24 @@ export interface MergeChange {
52
88
  readonly graded: Readonly<Record<string, string>>;
53
89
  /** The run's seed: a skill's or a draft's file not on main as it was on it is a conflict, never written over. */
54
90
  readonly seed?: string;
91
+ /** New notes written over main's note of the same name, each superseding it by name (takenOnMain). */
92
+ readonly replace?: readonly string[];
93
+ /** Each skill re-filed as a note, retired on main in the same write (its SKILL.md, and the note that replaces it). */
94
+ readonly retire?: readonly {
95
+ readonly skill: string;
96
+ readonly note: string;
97
+ }[];
55
98
  }
56
99
  export type LearningCommitResult = {
57
100
  readonly ok: true;
58
101
  readonly main: string;
59
102
  readonly commit: string;
60
103
  readonly files: readonly string[];
104
+ readonly left?: readonly {
105
+ readonly path: string;
106
+ readonly reason: "same" | "taken";
107
+ }[];
108
+ readonly already?: true;
61
109
  } | {
62
110
  readonly ok: false;
63
111
  readonly reason: "conflict" | "refused";
@@ -75,14 +123,16 @@ export interface GraderRun {
75
123
  flush(): Promise<void>;
76
124
  }
77
125
  export interface LearningLoopDeps {
78
- /** The run that learned, from the learning run's launch row (its input's runId). */
126
+ /** The run that learned, from the learning run's launch row (its input's runId), and the round of its looks back the
127
+ * learning run grades (its input's round; absent, the first). */
79
128
  sourceOf(learningRunId: string): Promise<{
80
129
  readonly runId: string;
130
+ readonly round?: number;
81
131
  readonly agentId: string;
82
132
  readonly instructions?: string;
83
133
  } | undefined>;
84
- /** Its kept proposal (store.learning.proposal). */
85
- proposal(runId: string): Promise<LearningProposal | undefined>;
134
+ /** Its kept proposal of that round (store.learning.proposal). */
135
+ proposal(runId: string, round: number): Promise<LearningProposal | undefined>;
86
136
  /** The agent's learning folder (learn/folder.ts learningWorkspace): its Workspace, and its end, called once the run is
87
137
  * done with it, whichever way it goes out. */
88
138
  folder(agentId: string): {
@@ -93,29 +143,56 @@ export interface LearningLoopDeps {
93
143
  readMain(ws: unknown, proposal: KeptProposal): Promise<GradeMain | {
94
144
  readonly problems: readonly Problem[];
95
145
  }>;
96
- /** One grader call, through the kernel's model proxy and the cap, booked to the agent's learning meter. */
146
+ /** One grader call, through the kernel's model proxy and the cap, booked to the agent's learning meter. `beside`: what
147
+ * the grade spent outside its records, at most (the generality check's dollars, else its worst case), which the cap's
148
+ * room for the call leaves out. */
97
149
  ask(request: {
98
150
  readonly prompt: string;
99
151
  readonly maxTokens: number;
152
+ readonly beside?: number;
100
153
  }, signal: AbortSignal, run: GraderRun): Promise<{
101
154
  readonly text: unknown;
102
155
  readonly usd: number | null;
103
156
  readonly tokens?: Tokens | null;
157
+ readonly booked?: GradeBooked;
104
158
  }>;
105
159
  /** The folder's one write. */
106
160
  commit(ws: unknown, change: MergeChange): Promise<LearningCommitResult>;
161
+ /** The texts main holds at these note paths (learn/commit.ts mainTexts): a note the merge keeps whose name main
162
+ * already holds is settled alone (takenOnMain). */
163
+ mainTexts(ws: unknown, paths: readonly string[]): Promise<Readonly<Record<string, string>>>;
164
+ /** Run `runId`'s merge, when it is on main already (learn/folder.ts readRunDiff: its diff file, named by the run as its
165
+ * commit's Run-Id trailer names it; a resume after its commit, before its end was recorded): the texts its own commit
166
+ * holds at these note paths, as that merge saved them, whatever main says of them since. Undefined when it is not. */
167
+ merged(ws: unknown, runId: string, paths: readonly string[], round?: number): Promise<{
168
+ readonly texts: Readonly<Record<string, string>>;
169
+ } | undefined>;
107
170
  /** The clock (epoch ms), for a parked run's wake. */
108
171
  now?(): number;
172
+ /** The generality pre-check (learn/general.ts): each proposed note's Jev probability that it holds for inputs other
173
+ * than the one it came from, by file, and what it cost. Undefined, or one that answers undefined (no Jev key on this
174
+ * host), skips it: every note goes to the grader. One that throws (Jev down) skips it too: what it spent is unknown, and
175
+ * the skip is kept on the grade's entry (`unchecked`) and said in the log. `sending` is called once, before its first
176
+ * paid request leaves, with their worst case under a cap (`held`): the loop marks the check sent there, durably
177
+ * (journal-kinds.ts learningGeneralSent). Under a cap, `before` is what an earlier attempt's cut check may have spent
178
+ * (its worst case), which the room for this one leaves out; one that doesn't fit throws GeneralOverCap, sending nothing. */
179
+ general?(notes: readonly NoteText[], source: GeneralSource, signal: AbortSignal, run: string, sending?: (held?: number) => Promise<void>, before?: number): Promise<GeneralScores | undefined>;
180
+ /** The bar a note's score must reach to go on to the grader (default GENERAL_THRESHOLD). */
181
+ generalThreshold?: number;
182
+ /** One line of the runner's log. */
183
+ log?(line: string): void;
109
184
  }
110
185
  /** The journal's learning entries' data (journal-kinds.ts learningGraded, learningDropped, learningMerged), as the reader
111
186
  * of a run's learning end reads them (store-reads/learning.ts). What a grade spent: its dollars and tokens, each null when
112
- * any ask's are unknown. */
187
+ * any ask's are unknown. `unchecked`: why the generality pre-check could not run (its provider's error), so the grader read
188
+ * every note; the run's learning end says the check was skipped. */
113
189
  export type GradedData = {
114
190
  readonly source: string;
115
191
  readonly verdict: Verdict;
116
192
  readonly usd: number | null;
117
193
  readonly tokens?: Tokens | null;
118
194
  readonly graded: Readonly<Record<string, string>>;
195
+ readonly unchecked?: string;
119
196
  };
120
197
  export type DroppedData = {
121
198
  readonly source: string;
@@ -124,21 +201,52 @@ export type DroppedData = {
124
201
  readonly problems?: readonly Problem[];
125
202
  readonly usd?: number | null;
126
203
  readonly tokens?: Tokens | null;
204
+ readonly unchecked?: string;
127
205
  };
206
+ /** `verdict`: each item's final decision once the merge settled it (takenOnMain's and the commit's left-out notes dropped,
207
+ * with their words), which the run's learning end reads in place of the grade's (store-reads/learning.ts). */
128
208
  export type MergedData = {
129
209
  readonly source: string;
130
210
  readonly main: string;
131
211
  readonly commit: string;
132
212
  readonly files: readonly string[];
133
213
  readonly detail: string;
214
+ readonly verdict: Verdict;
215
+ };
216
+ /** The generality check's end (journal-kinds.ts learningGeneral): its scores, or why it could not run (GENERAL_NO_BUDGET:
217
+ * no room under the cap), and what it spent (null once unknown: a request that failed, or one an earlier attempt sent and
218
+ * a restart cut). `held`: under a cap, the most every attempt's requests may have spent (each sent mark's worst case), the
219
+ * bound the grader's room leaves out when `usd` is unknown. */
220
+ export type GeneralData = {
221
+ readonly source: string;
222
+ readonly scores?: Readonly<Record<string, number>>;
223
+ readonly unchecked?: string;
224
+ readonly usd: number | null;
225
+ readonly held?: number;
226
+ };
227
+ /** The why of a note whose name main already holds with other text, which it does not supersede: never written over,
228
+ * and the rest of what the run learned merges. */
229
+ export declare const NOTE_NAME_TAKEN: (name: string) => string;
230
+ /** The why of a skill re-filed as a note whose file this run's own kept note (or another re-filed skill) takes: the run's
231
+ * own stands, and the skill is not written over it. */
232
+ export declare const NOTE_NAME_IN_RUN: (name: string) => string;
233
+ export declare function takenOnMain(proposal: Pick<KeptProposal, "notes">, verdict: Verdict, onMain: Readonly<Record<string, string>>): {
234
+ verdict: Verdict;
235
+ replace: string[];
236
+ graded: Record<string, string>;
134
237
  };
135
- /** `proposal` with only what `verdict` keeps (a verdict per item): a note or file its item keeps or holds. */
238
+ /** `verdict` with one item per file a kept note is written as, within the run: the files the run's own kept notes are,
239
+ * then each re-filed skill's as it is kept; a re-filed skill whose note file one of those takes is left out, saying so
240
+ * (NOTE_NAME_IN_RUN). The merge (takenOnMain) and its resume (resumedOf, from the saved grade) settle it the one way. */
241
+ export declare function oneItemAFile(proposal: Pick<KeptProposal, "notes">, verdict: Verdict): Verdict;
242
+ /** `proposal` with only what `verdict` keeps (a verdict per item): a note or file its item keeps or holds; a skill its
243
+ * item re-filed (`note`: a standing rule for every reply) is kept as that note instead, never as a skill. */
136
244
  export declare function keptOf(proposal: KeptProposal, verdict: Verdict): KeptProposal;
137
245
  /** The merge of `merging` (what the verdict kept), the one rule learningCommit's merge is made by: each note with
138
246
  * the origin its item gives (`you` for the user's own words, else the run's) and held for its owner's OK when its item
139
247
  * is pending; a skill's SKILL.md or a draft's README.md held when its item is (a draft's workflow.json is held by its
140
248
  * README); and the seed the source run started from, so a skill's or draft's file changed on main since is a conflict. */
141
- export declare function mergeChangeOf(runId: string, merging: KeptProposal, verdict: Verdict, graded: Readonly<Record<string, string>>): MergeChange;
249
+ export declare function mergeChangeOf(runId: string, merging: KeptProposal, verdict: Verdict, graded: Readonly<Record<string, string>>, round?: number): MergeChange;
142
250
  /** What a merge of `merging` learned, as the server's grade named it on the run (learning-run.ts grade): the notes it
143
251
  * added that runs read, with what each supersedes; the ones waiting for their owner's OK; its skills and workflow
144
252
  * drafts, each pending when it waits. The merge's words and the reader of a run's learning end (store-reads/learning.ts)
@@ -152,6 +260,30 @@ export declare function learnedOf(merging: KeptProposal, verdict: Verdict): {
152
260
  skills: LearnedFile[];
153
261
  workflows: LearnedFile[];
154
262
  };
263
+ /** `merging` and `verdict` once the merge left out `left` (learn/commit.ts LeftNote): each note it left out is no longer
264
+ * merged, and its item is dropped, unsaid when its rule is held already (SAME_NOTE), else saying its name is taken. */
265
+ export declare function leftOf(merging: KeptProposal, verdict: Verdict, left: readonly {
266
+ readonly path: string;
267
+ readonly reason: "same" | "taken";
268
+ }[]): {
269
+ merging: KeptProposal;
270
+ verdict: Verdict;
271
+ };
272
+ /** What a merge already on main settled (learn/commit.ts: its files, and `left`, the new notes it did not write): each
273
+ * note the grade kept is kept when the merge wrote it, its path changed and main holding its rule there now (`onMain`,
274
+ * the texts main holds at the kept notes' paths), else left out, saying why as takenOnMain said it (`taken`, its
275
+ * verdict after main was read), or by main's text there (the same rule, or a name it holds with another), else as the
276
+ * commit does. Skills and drafts as the grade kept them. */
277
+ export declare function resumedOf(proposal: KeptProposal, graded: Verdict, taken: Verdict, result: {
278
+ readonly files: readonly string[];
279
+ readonly left?: readonly {
280
+ readonly path: string;
281
+ readonly reason: "same" | "taken";
282
+ }[];
283
+ }, onMain: Readonly<Record<string, string>>): {
284
+ merging: KeptProposal;
285
+ verdict: Verdict;
286
+ };
155
287
  /** The skills and drafts a proposal names, by their item's file: what a merge the grader refused loses (notKept). */
156
288
  export declare const lostOf: (proposal: KeptProposal) => LearnedFile[];
157
289
  export declare function createLearningLoop(learning: LearningLoopDeps): (deps: LoopDeps) => Loop;