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

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 (450) hide show
  1. package/CHANGELOG.md +263 -0
  2. package/README.md +339 -179
  3. package/dist/adapters.d.ts +15 -2
  4. package/dist/adapters.js +34 -2
  5. package/dist/agent-rows.d.ts +3 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +25 -5
  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 +90 -8
  13. package/dist/archil-settings.js +150 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/bash-read-only.d.ts +13 -0
  19. package/dist/bash-read-only.js +77 -0
  20. package/dist/box-image.d.ts +1 -97
  21. package/dist/box-image.js +4 -284
  22. package/dist/box-paths.d.ts +2 -7
  23. package/dist/box-paths.js +7 -13
  24. package/dist/box-settings.d.ts +0 -11
  25. package/dist/box-settings.js +4 -29
  26. package/dist/browser-commands.js +1 -1
  27. package/dist/browser-computer.d.ts +47 -3
  28. package/dist/browser-computer.js +286 -18
  29. package/dist/browser-cost.d.ts +2 -2
  30. package/dist/browser-cost.js +6 -4
  31. package/dist/browser-person.d.ts +19 -2
  32. package/dist/browser-person.js +55 -6
  33. package/dist/browser-wait-ended.d.ts +23 -0
  34. package/dist/browser-wait-ended.js +42 -0
  35. package/dist/cap.d.ts +19 -44
  36. package/dist/cap.js +31 -77
  37. package/dist/cli.js +36 -27
  38. package/dist/computer-keys.d.ts +20 -10
  39. package/dist/computer-keys.js +36 -57
  40. package/dist/computer-routes.d.ts +1 -4
  41. package/dist/computer-routes.js +3 -5
  42. package/dist/computer-setting.d.ts +8 -5
  43. package/dist/computer-setting.js +91 -26
  44. package/dist/computer-view.d.ts +11 -2
  45. package/dist/computer-view.js +2 -1
  46. package/dist/computers.d.ts +54 -8
  47. package/dist/computers.js +101 -22
  48. package/dist/console/assets/index-BI4Byidu.js +550 -0
  49. package/dist/console/assets/index-C19gUF2n.css +1 -0
  50. package/dist/console/index.html +2 -2
  51. package/dist/content-filter.d.ts +7 -0
  52. package/dist/content-filter.js +23 -0
  53. package/dist/decision-cap.d.ts +7 -29
  54. package/dist/decision-cap.js +3 -94
  55. package/dist/docker-daemon.d.ts +2 -2
  56. package/dist/docker-daemon.js +2 -2
  57. package/dist/errors.d.ts +1 -0
  58. package/dist/errors.js +8 -5
  59. package/dist/explain.js +3 -1
  60. package/dist/faux-computers.js +4 -0
  61. package/dist/files.d.ts +1 -9
  62. package/dist/files.js +1 -9
  63. package/dist/github-connection.js +25 -7
  64. package/dist/github-faux.d.ts +26 -0
  65. package/dist/github-faux.js +76 -0
  66. package/dist/github.d.ts +28 -4
  67. package/dist/github.js +46 -10
  68. package/dist/gpu-words.d.ts +14 -0
  69. package/dist/gpu-words.js +21 -0
  70. package/dist/graph-served.d.ts +5 -3
  71. package/dist/graph-served.js +14 -6
  72. package/dist/graph-view.d.ts +2 -0
  73. package/dist/graph-view.js +29 -2
  74. package/dist/handed-values.d.ts +1 -1
  75. package/dist/handed-values.js +1 -1
  76. package/dist/harness-install.d.ts +60 -3
  77. package/dist/harness-install.js +322 -34
  78. package/dist/harness-opencode/harness.js +0 -1
  79. package/dist/harness-opencode/host/policy.js +2 -2
  80. package/dist/harness.js +1 -1
  81. package/dist/host-tools.d.ts +8 -9
  82. package/dist/host-tools.js +7 -7
  83. package/dist/index.d.ts +2 -3
  84. package/dist/index.js +2 -2
  85. package/dist/key-refusal.d.ts +1 -1
  86. package/dist/key-refusal.js +2 -2
  87. package/dist/learn/check.d.ts +10 -2
  88. package/dist/learn/check.js +126 -8
  89. package/dist/learn/commit.d.ts +40 -6
  90. package/dist/learn/commit.js +164 -20
  91. package/dist/learn/folder.d.ts +11 -3
  92. package/dist/learn/folder.js +40 -16
  93. package/dist/learn/grade.d.ts +22 -2
  94. package/dist/learn/grade.js +127 -19
  95. package/dist/learn/index.d.ts +2 -2
  96. package/dist/learn/index.js +2 -2
  97. package/dist/learn/learning.sh +11 -13
  98. package/dist/learn/notes.d.ts +17 -3
  99. package/dist/learn/notes.js +19 -6
  100. package/dist/learn/reflect.d.ts +5 -2
  101. package/dist/learn/reflect.js +48 -32
  102. package/dist/learn/skills.d.ts +52 -5
  103. package/dist/learn/skills.js +104 -21
  104. package/dist/learned-nodes.d.ts +18 -0
  105. package/dist/learned-nodes.js +8 -0
  106. package/dist/learned-workflow.d.ts +27 -13
  107. package/dist/learned-workflow.js +110 -38
  108. package/dist/learning-cost.d.ts +79 -0
  109. package/dist/learning-cost.js +69 -0
  110. package/dist/learning-routes.d.ts +48 -2
  111. package/dist/learning-routes.js +99 -28
  112. package/dist/learning-run.d.ts +7 -5
  113. package/dist/learning-run.js +9 -6
  114. package/dist/learning-words.d.ts +3 -0
  115. package/dist/learning-words.js +6 -2
  116. package/dist/learning.d.ts +13 -28
  117. package/dist/learning.js +4 -18
  118. package/dist/llm.d.ts +4 -1
  119. package/dist/llm.js +4 -2
  120. package/dist/mcp-gateway.d.ts +6 -0
  121. package/dist/mcp-gateway.js +11 -1
  122. package/dist/mcp-probe.d.ts +8 -1
  123. package/dist/mcp-probe.js +62 -20
  124. package/dist/mcp-secret-writes.js +4 -0
  125. package/dist/mcp-servers-store.d.ts +12 -12
  126. package/dist/mcp-servers-store.js +8 -3
  127. package/dist/model.d.ts +8 -5
  128. package/dist/model.js +14 -6
  129. package/dist/openapi.d.ts +2 -0
  130. package/dist/openapi.js +236 -55
  131. package/dist/owner.d.ts +0 -1
  132. package/dist/owner.js +0 -2
  133. package/dist/pause.d.ts +2 -19
  134. package/dist/pause.js +5 -74
  135. package/dist/place-offers.d.ts +97 -0
  136. package/dist/place-offers.js +206 -0
  137. package/dist/place.d.ts +9 -13
  138. package/dist/place.js +22 -32
  139. package/dist/port-models.d.ts +12 -4
  140. package/dist/port-models.js +31 -9
  141. package/dist/print.d.ts +1 -8
  142. package/dist/print.js +1 -14
  143. package/dist/propose.d.ts +3 -0
  144. package/dist/propose.js +25 -19
  145. package/dist/run-cut.d.ts +5 -0
  146. package/dist/run-cut.js +19 -0
  147. package/dist/run-db.js +3 -3
  148. package/dist/run-launch.d.ts +18 -3
  149. package/dist/run-launch.js +11 -5
  150. package/dist/run-learning-served.d.ts +12 -1
  151. package/dist/run-manifest.d.ts +2 -2
  152. package/dist/run-manifest.js +2 -2
  153. package/dist/run-reads-over-store.d.ts +4 -2
  154. package/dist/run-reads-over-store.js +10 -8
  155. package/dist/run-secrets.js +3 -3
  156. package/dist/run-timeline-served.js +60 -38
  157. package/dist/run-view.d.ts +35 -16
  158. package/dist/run-view.js +64 -35
  159. package/dist/runnable.d.ts +6 -3
  160. package/dist/runnable.js +20 -4
  161. package/dist/runner/adapter-loop.d.ts +46 -5
  162. package/dist/runner/adapter-loop.js +381 -56
  163. package/dist/runner/adapter-run-spec.d.ts +46 -4
  164. package/dist/runner/adapter-run-spec.js +200 -45
  165. package/dist/runner/adapters/pi.d.ts +39 -3
  166. package/dist/runner/adapters/pi.js +124 -29
  167. package/dist/runner/beside.d.ts +8 -0
  168. package/dist/runner/beside.js +24 -2
  169. package/dist/runner/claim-secrets.d.ts +6 -0
  170. package/dist/runner/claim-secrets.js +15 -1
  171. package/dist/runner/cli-run-spec.d.ts +10 -0
  172. package/dist/runner/cli-run-spec.js +207 -64
  173. package/dist/runner/commands.d.ts +5 -1
  174. package/dist/runner/commands.js +3 -3
  175. package/dist/runner/conformance/harness.d.ts +1 -1
  176. package/dist/runner/conformance/harness.js +13 -10
  177. package/dist/runner/github-app.d.ts +7 -2
  178. package/dist/runner/github-app.js +46 -15
  179. package/dist/runner/harness-loops.d.ts +6 -1
  180. package/dist/runner/harness-loops.js +24 -1
  181. package/dist/runner/journal-kinds.d.ts +53 -7
  182. package/dist/runner/journal-kinds.js +29 -1
  183. package/dist/runner/learning-end.d.ts +15 -0
  184. package/dist/runner/learning-end.js +113 -20
  185. package/dist/runner/learning-factory.js +6 -2
  186. package/dist/runner/learning-loop.d.ts +75 -1
  187. package/dist/runner/learning-loop.js +215 -22
  188. package/dist/runner/learning-seed.d.ts +8 -0
  189. package/dist/runner/learning-seed.js +7 -1
  190. package/dist/runner/loop-contract.d.ts +12 -0
  191. package/dist/runner/loop-contract.js +6 -0
  192. package/dist/runner/loop.d.ts +5 -1
  193. package/dist/runner/loop.js +20 -0
  194. package/dist/runner/main.d.ts +9 -4
  195. package/dist/runner/main.js +38 -13
  196. package/dist/runner/mcp-claim.d.ts +7 -0
  197. package/dist/runner/mcp-claim.js +35 -2
  198. package/dist/runner/mcp-github.d.ts +15 -4
  199. package/dist/runner/mcp-github.js +55 -11
  200. package/dist/runner/mcp-run.d.ts +2 -0
  201. package/dist/runner/mcp-run.js +2 -0
  202. package/dist/runner/metrics.d.ts +18 -1
  203. package/dist/runner/metrics.js +81 -1
  204. package/dist/runner/model-route.d.ts +6 -0
  205. package/dist/runner/model-route.js +5 -2
  206. package/dist/runner/pr-checkout.d.ts +59 -0
  207. package/dist/runner/pr-checkout.js +176 -0
  208. package/dist/runner/reflect-hook.d.ts +1 -0
  209. package/dist/runner/reflect-hook.js +3 -3
  210. package/dist/runner/runner.js +136 -19
  211. package/dist/runner/spec-holds.d.ts +13 -3
  212. package/dist/runner/spec-holds.js +13 -10
  213. package/dist/runner/store-port.d.ts +4 -1
  214. package/dist/runner/store-secrets.js +17 -1
  215. package/dist/runner/subagent.d.ts +44 -0
  216. package/dist/runner/subagent.js +188 -0
  217. package/dist/runner/workflow-host.d.ts +25 -4
  218. package/dist/runner/workflow-host.js +26 -4
  219. package/dist/runner/workflow-loop.d.ts +9 -3
  220. package/dist/runner/workflow-loop.js +17 -10
  221. package/dist/runner/workflow-spec.d.ts +28 -13
  222. package/dist/runner/workflow-spec.js +247 -102
  223. package/dist/runs-over-store.d.ts +18 -7
  224. package/dist/runs-over-store.js +149 -31
  225. package/dist/seal-key.d.ts +0 -2
  226. package/dist/seal-key.js +0 -2
  227. package/dist/sealing.js +1 -2
  228. package/dist/secret-cut.d.ts +1 -1
  229. package/dist/secret-cut.js +1 -1
  230. package/dist/server-lock.js +4 -5
  231. package/dist/server.d.ts +49 -63
  232. package/dist/server.js +429 -230
  233. package/dist/stop-signals.d.ts +4 -2
  234. package/dist/stop-signals.js +5 -3
  235. package/dist/store/agent-body.d.ts +14 -3
  236. package/dist/store/agent-body.js +22 -8
  237. package/dist/store/deadline.d.ts +18 -0
  238. package/dist/store/deadline.js +49 -0
  239. package/dist/store/index.d.ts +3 -3
  240. package/dist/store/index.js +2 -2
  241. package/dist/store/journal/storage.js +2 -1
  242. package/dist/store/postgres/connection.d.ts +4 -0
  243. package/dist/store/postgres/connection.js +64 -13
  244. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  245. package/dist/store/schema.d.ts +2 -1
  246. package/dist/store/schema.js +11 -8
  247. package/dist/store/seal.d.ts +13 -0
  248. package/dist/store/seal.js +19 -0
  249. package/dist/store/sqlite/connection.d.ts +5 -0
  250. package/dist/store/sqlite/connection.js +88 -82
  251. package/dist/store/sqlite/run-patch.d.ts +18 -2
  252. package/dist/store/sqlite/run-patch.js +31 -2
  253. package/dist/store/sqlite/store.js +65 -11
  254. package/dist/store/store.d.ts +62 -12
  255. package/dist/store/store.js +22 -1
  256. package/dist/store-reads/analytics.js +3 -2
  257. package/dist/store-reads/cap.d.ts +1 -3
  258. package/dist/store-reads/cap.js +8 -6
  259. package/dist/store-reads/decisions.d.ts +2 -2
  260. package/dist/store-reads/decisions.js +3 -6
  261. package/dist/store-reads/journal.js +83 -15
  262. package/dist/store-reads/learning.d.ts +73 -3
  263. package/dist/store-reads/learning.js +232 -9
  264. package/dist/store-reads/runs.d.ts +6 -4
  265. package/dist/store-reads/runs.js +17 -10
  266. package/dist/store-reads/stats.js +5 -1
  267. package/dist/store-view.d.ts +15 -1
  268. package/dist/store-view.js +88 -29
  269. package/dist/template-eval.js +2 -1
  270. package/dist/templates.d.ts +73 -4
  271. package/dist/templates.js +113 -23
  272. package/dist/timeline/timeline.d.ts +11 -1
  273. package/dist/timeline/timeline.js +19 -4
  274. package/dist/tool-blurbs.js +1 -0
  275. package/dist/tool-budget.d.ts +26 -0
  276. package/dist/tool-budget.js +56 -0
  277. package/dist/tool-gate.d.ts +13 -3
  278. package/dist/tool-gate.js +15 -7
  279. package/dist/tool-plane.d.ts +42 -29
  280. package/dist/tool-plane.js +64 -27
  281. package/dist/tools.d.ts +53 -39
  282. package/dist/tools.js +174 -79
  283. package/dist/trigger-signatures.d.ts +1 -0
  284. package/dist/trigger-signatures.js +3 -1
  285. package/dist/triggers.d.ts +3 -3
  286. package/dist/triggers.js +2 -2
  287. package/dist/turn-end.d.ts +0 -3
  288. package/dist/turn-end.js +0 -3
  289. package/dist/uploads.d.ts +28 -5
  290. package/dist/uploads.js +82 -9
  291. package/dist/usage-lines.d.ts +1 -1
  292. package/dist/usage.d.ts +1 -47
  293. package/dist/usage.js +3 -82
  294. package/dist/validate.d.ts +8 -0
  295. package/dist/validate.js +40 -3
  296. package/dist/webhooks.d.ts +2 -1
  297. package/dist/webhooks.js +5 -2
  298. package/dist/workflow/decision-recovery.d.ts +23 -0
  299. package/dist/workflow/decision-recovery.js +80 -0
  300. package/dist/workflow/decisions.d.ts +134 -0
  301. package/dist/workflow/decisions.js +46 -0
  302. package/dist/workflow/host-session.d.ts +5 -0
  303. package/dist/workflow/host-session.js +85 -0
  304. package/dist/workflow/host-tools.d.ts +3 -0
  305. package/dist/workflow/host-tools.js +3 -0
  306. package/dist/workflow/node-runner.d.ts +112 -0
  307. package/dist/workflow/node-runner.js +270 -0
  308. package/dist/workflow/node.d.ts +88 -0
  309. package/dist/workflow/node.js +99 -0
  310. package/dist/workflow/operator-error.d.ts +4 -0
  311. package/dist/workflow/operator-error.js +4 -0
  312. package/dist/workflow/pi-versions.d.ts +9 -0
  313. package/dist/workflow/pi-versions.js +8 -0
  314. package/dist/workflow/readers.d.ts +36 -0
  315. package/dist/workflow/readers.js +145 -0
  316. package/dist/workflow/record-file.d.ts +10 -0
  317. package/dist/workflow/record-file.js +56 -0
  318. package/dist/workflow/record-tool.d.ts +76 -0
  319. package/dist/workflow/record-tool.js +126 -0
  320. package/dist/workflow/record.d.ts +151 -0
  321. package/dist/workflow/record.js +401 -0
  322. package/dist/workflow/run-error.d.ts +16 -0
  323. package/dist/workflow/run-error.js +26 -0
  324. package/dist/workflow/runner.d.ts +6 -0
  325. package/dist/workflow/runner.js +240 -0
  326. package/dist/workflow/store.d.ts +23 -0
  327. package/dist/workflow/store.js +242 -0
  328. package/dist/workflow/task.d.ts +133 -0
  329. package/dist/workflow/task.js +411 -0
  330. package/dist/workflow/thinking.d.ts +3 -0
  331. package/dist/workflow/thinking.js +7 -0
  332. package/dist/workflow/tool-context.d.ts +21 -0
  333. package/dist/workflow/tool-context.js +13 -0
  334. package/dist/workflow/types.d.ts +126 -0
  335. package/dist/workflow/types.js +1 -0
  336. package/dist/workflow/wal.d.ts +11 -0
  337. package/dist/workflow/wal.js +106 -0
  338. package/dist/workflow-run.d.ts +1 -1
  339. package/dist/workspace/agent-computer.d.ts +137 -0
  340. package/dist/workspace/agent-computer.js +292 -0
  341. package/dist/workspace/archil-claim.d.ts +13 -2
  342. package/dist/workspace/archil-claim.js +22 -13
  343. package/dist/workspace/archil-disk.d.ts +10 -1
  344. package/dist/workspace/archil-disk.js +4 -0
  345. package/dist/workspace/archil-disks.d.ts +49 -0
  346. package/dist/workspace/archil-disks.js +185 -0
  347. package/dist/workspace/archil-exec.d.ts +12 -2
  348. package/dist/workspace/archil-exec.js +18 -3
  349. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  350. package/dist/workspace/archil-mount-credential.js +13 -4
  351. package/dist/workspace/archil.d.ts +2 -2
  352. package/dist/workspace/archil.js +25 -5
  353. package/dist/workspace/attach.js +2 -0
  354. package/dist/workspace/computer-deps.d.ts +18 -11
  355. package/dist/workspace/computer-deps.js +64 -40
  356. package/dist/workspace/computer-for-claim.d.ts +47 -9
  357. package/dist/workspace/computer-for-claim.js +236 -24
  358. package/dist/workspace/computer-janitor.d.ts +3 -2
  359. package/dist/workspace/computer-janitor.js +43 -9
  360. package/dist/workspace/computer-ledger.d.ts +3 -8
  361. package/dist/workspace/computer-ledger.js +7 -3
  362. package/dist/workspace/computer-providers.d.ts +5 -3
  363. package/dist/workspace/computer-providers.js +11 -9
  364. package/dist/workspace/hands.d.ts +5 -2
  365. package/dist/workspace/hands.js +4 -3
  366. package/dist/workspace/index.d.ts +5 -4
  367. package/dist/workspace/index.js +2 -1
  368. package/dist/workspace/local.d.ts +3 -0
  369. package/dist/workspace/local.js +9 -0
  370. package/dist/workspace/paths.js +3 -2
  371. package/dist/workspace/pi-env.d.ts +4 -0
  372. package/dist/workspace/pi-env.js +3 -2
  373. package/dist/workspace/resolve-computer.d.ts +48 -12
  374. package/dist/workspace/resolve-computer.js +88 -19
  375. package/dist/workspace/run-disk.d.ts +34 -0
  376. package/dist/workspace/run-disk.js +91 -0
  377. package/dist/workspace/run-tools.d.ts +6 -4
  378. package/dist/workspace/run-tools.js +17 -9
  379. package/dist/workspace/server-run-workspace.d.ts +3 -2
  380. package/dist/workspace/server-run-workspace.js +17 -4
  381. package/dist/workspace/workspace.d.ts +5 -0
  382. package/dist/workspace.d.ts +0 -3
  383. package/dist/workspace.js +2 -15
  384. package/package.json +11 -16
  385. package/skills/agentrun-serve/SKILL.md +1 -1
  386. package/templates/README.md +11 -8
  387. package/templates/code-review/agent.md +27 -11
  388. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  389. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  390. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  391. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  392. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  393. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  394. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  395. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  396. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  397. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  398. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  399. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  400. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  401. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  402. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  404. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  405. package/templates/code-review/evals/re-review/prompt.md +1 -1
  406. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  407. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  408. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  409. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  410. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  411. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  412. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  413. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  414. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  415. package/templates/code-review/findings.schema.json +131 -27
  416. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  417. package/templates/code-review/skills/review/DEEP.md +130 -0
  418. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  419. package/templates/code-review/skills/review/SKILL.md +104 -154
  420. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  421. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  422. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  423. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  424. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  425. package/templates/release-notes/agent.md +11 -0
  426. package/dist/box/record.d.ts +0 -6
  427. package/dist/box/record.js +0 -41
  428. package/dist/box/sweep.d.ts +0 -53
  429. package/dist/box/sweep.js +0 -193
  430. package/dist/box-egress-vm.d.ts +0 -118
  431. package/dist/box-egress-vm.js +0 -354
  432. package/dist/box-egress.d.ts +0 -105
  433. package/dist/box-egress.js +0 -256
  434. package/dist/box-relay-vm.d.ts +0 -84
  435. package/dist/box-relay-vm.js +0 -437
  436. package/dist/box-relay.d.ts +0 -36
  437. package/dist/box-relay.js +0 -207
  438. package/dist/boxes.d.ts +0 -109
  439. package/dist/boxes.js +0 -249
  440. package/dist/budget.d.ts +0 -76
  441. package/dist/budget.js +0 -204
  442. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  443. package/dist/console/assets/index-opTN5Naq.css +0 -1
  444. package/dist/daytona-api.d.ts +0 -10
  445. package/dist/daytona-api.js +0 -20
  446. package/dist/egress-proxy.d.ts +0 -45
  447. package/dist/egress-proxy.js +0 -416
  448. package/dist/egress-table.d.ts +0 -24
  449. package/dist/egress-table.js +0 -165
  450. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -1,5 +1,5 @@
1
- import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, frontMatter, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, statusOnOneLine, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, UNCLEAR_FRONT, unstorable, WORKFLOWS_DIR } from "./learn/index.js";
2
- import { beforeRetire, blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, heldOnMain, isBodyMismatch, readLearning, PATCH_CAP, readRunDiff, readSnapshot, snapshotNotes, writeLearning } from "./learn/folder.js";
1
+ import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, UNCLEAR_FRONT, unstorable, WORKFLOWS_DIR, unclearFront, restorable, restore, restoredLearned } from "./learn/index.js";
2
+ import { blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, heldOnMain, isBodyMismatch, readLearning, PATCH_CAP, readRunDiff, readSnapshot, snapshotNotes, writeLearning } from "./learn/folder.js";
3
3
  import { ApiError, invalid } from "./errors.js";
4
4
  import { detailShown, learningFolderOf, notesView, reasonShown, secretsShown, withAgentRepo } from "./learning.js";
5
5
  import { isObject } from "./validate.js";
@@ -11,7 +11,8 @@ const NOTES_PAGE = 50;
11
11
  const LOG_PAGE = 20;
12
12
  const PAGE_MAX = 200;
13
13
  /** What a retire adds to a note, on top of the note cap a retired note may fill (learn/notes.ts retire). */
14
- const RETIRED_LINE = Buffer.byteLength("status: retired\n");
14
+ /** What a retire adds to a note: its status line and the status it took it from (the longer of the two). */
15
+ const RETIRED_LINE = Buffer.byteLength("status: retired\nretired_from: pending\n");
15
16
  export { secretsShown } from "./learning.js";
16
17
  /** The few values last kept, by key, oldest dropped first: at most `entries` of them. */
17
18
  class Recent {
@@ -70,22 +71,24 @@ async function reading(data, agentId, read, none) {
70
71
  }
71
72
  /** A retired item's `retired`: its newest retire by a person; else, one a person made retired another way (an edit to
72
73
  * status: retired, or created so), their newest change; else (retired by none of theirs) its newest change's time. */
73
- const retiredOf = (history) => (history.retire ? { at: history.retire.at, by: "person" } : history.person ? { at: history.person.at, by: "person" } : { at: history.at, by: "run" });
74
+ /** `from`: the status its restore gives back (its retire recorded it, retired_from; none recorded reads pending, as its
75
+ * restore gives it: only an approval makes an item active). `unread`: the host could not read its file. */
76
+ const retiredOf = (history, from, unread = false) => (unread ? { at: history.at, by: "host", why: "unreadable" } : { ...(history.retire ? { at: history.retire.at, by: "person" } : history.person ? { at: history.person.at, by: "person" } : { at: history.at, by: "run" }), from: from ?? "pending" });
74
77
  /** A note as the view shows it, cut of the host's secrets: its name and the one that superseded it whole; with its
75
78
  * ETag, the one its file's GET answers, so an edit or a retire from the card names the version it shows; its last
76
79
  * change, and when and by whom it was retired on a retired one. */
77
80
  const noteView = (note, text, shown, runs) => ({
78
81
  file: shown.name(note.file), name: shown.text(note.name), description: shown.text(note.description), type: note.type, status: note.status, origin: note.origin, superseded_by: note.superseded_by === null ? null : shown.name(note.superseded_by), text: shown.text(text), etag: etagOf(note.oid), runs: { ...(runs.get(note.file) ?? { given: 0, read: 0 }) },
79
82
  ...(note.history.last ? { last_change: note.history.last } : {}),
80
- ...(note.status === "retired" ? { retired: retiredOf(note.history) } : {}),
83
+ ...(note.status === "retired" ? { retired: retiredOf(note.history, note.retired_from) } : {}),
81
84
  });
82
- function learnedView(item, kind, shown) {
85
+ function learnedView(item, kind, shown, unread = false) {
83
86
  const file = kind === "skill" ? item.file : `${WORKFLOWS_DIR}/${item.name}/workflow.json`;
84
87
  const bytes = item.files.find(({ path }) => path === file)?.bytes ?? item.bytes;
85
88
  return {
86
89
  name: shown.name(item.name), file: shown.name(file), ...(kind === "workflow" ? { readme: shown.name(item.file) } : {}), description: shown.text(item.description), status: item.status, run: item.run, bytes, etag: etagOf(item.oid),
87
90
  ...(item.history.last ? { last_change: item.history.last } : {}),
88
- ...(item.status === "retired" ? { retired: retiredOf(item.history) } : {}),
91
+ ...(item.status === "retired" ? { retired: retiredOf(item.history, item.retired_from, unread) } : {}),
89
92
  };
90
93
  }
91
94
  /** A change on main as the log shows it, cut of the host's secrets. */
@@ -168,7 +171,10 @@ export async function agentLearning(data, agentId, shown, counts, impact, runs =
168
171
  return reading(data, agentId, async ({ snapshot, body }) => {
169
172
  const index = snapshot.index.bytes ? await body(INDEX_FILE, snapshot.index.oid) : "";
170
173
  const notes = await notesPage(snapshot.notes, snapshot.main, 0, NOTES_PAGE, body, shown, runs);
171
- return { agent: agentId, main: snapshot.main, index: shown.text(index), notes, skills: snapshot.skills.map((item) => learnedView(item, "skill", shown)), workflows: snapshot.workflows.map((item) => learnedView(item, "workflow", shown)), log: logPage(snapshot, 0, LOG_PAGE, shown), counts, impact };
174
+ // A retired skill or draft whose key file can't be read is said so (unclearFront), read from its file now, as the
175
+ // snapshot's status was: a few retired items, one read each.
176
+ const unread = async (item) => item.status === "retired" && unclearFront(await body(item.file, item.oid));
177
+ return { agent: agentId, main: snapshot.main, index: shown.text(index), notes, skills: await Promise.all(snapshot.skills.map(async (item) => learnedView(item, "skill", shown, await unread(item)))), workflows: await Promise.all(snapshot.workflows.map(async (item) => learnedView(item, "workflow", shown, await unread(item)))), log: logPage(snapshot, 0, LOG_PAGE, shown), counts, impact };
172
178
  }, () => ({ agent: agentId, main: null, index: "", notes: EMPTY, skills: [], workflows: [], log: EMPTY, counts, impact }));
173
179
  }
174
180
  /** GET /agents/{id}/learning/notes?cursor=&limit=&status=: a page of the notes, ordered as the view's. A page at an
@@ -363,12 +369,20 @@ export async function writeNote(data, agentId, raw, input) {
363
369
  }
364
370
  let text = given;
365
371
  // A note that waits for its owner's OK is made active by an approval alone: an edit keeps it waiting, so one that
366
- // drops or changes its status is refused, whoever sends it.
372
+ // drops or changes its status is refused, whoever sends it. A retired note comes back by its restore alone, to the
373
+ // status its retire recorded: an edit keeps it retired and keeps that record (retired_from) as it is.
367
374
  if (given !== undefined && current) {
368
375
  const was = parseNoteFile(file, current.text);
369
376
  const now = parseNoteFile(file, given);
370
377
  if (!Array.isArray(was) && was.status === "pending" && !Array.isArray(now) && now.status !== "pending")
371
378
  throw refused([printable({ rule: "status", path: file, detail: "it waits for its owner's OK: an edit keeps status: pending, only an approval makes it active, and a retire takes it out" }, input.refuse)]);
379
+ if (!Array.isArray(was) && was.status === "retired" && !Array.isArray(now)) {
380
+ const kept = was.retired_from ?? "pending";
381
+ if (now.status !== "retired" || (now.keys.includes("retired_from") && now.retired_from !== kept))
382
+ throw refused([printable({ rule: "status", path: file, detail: `it is retired: an edit keeps status: retired and retired_from: ${kept}, and only its restore brings it back, as it was before its retire` }, input.refuse)]);
383
+ // What its retire recorded is the host's: the edit carries it, written or not.
384
+ text = retire(given, kept);
385
+ }
372
386
  }
373
387
  // Beside the note itself: what an approve marks of the notes the approved one supersedes.
374
388
  const also = new Map();
@@ -379,24 +393,24 @@ export async function writeNote(data, agentId, raw, input) {
379
393
  if (notes.get(old)?.status === "active")
380
394
  also.set(old, supersede(await body(old, noteOid(old)), file));
381
395
  };
382
- let heldBefore = false;
383
396
  if (input.restore) {
384
- // Restored, a retired note, skill or draft is active again: given to every later run. It is checked again as a
385
- // new one is (secrets' shapes, the host's values, hidden characters, its format, every file of a skill's or a
386
- // draft's folder): a retire takes a leaking one out of every run unchecked, and a restore never brings it back.
387
- // One that waited for its owner's OK before its retire is recorded as their approval too (Approved-Via).
388
- const before = await beforeRetire(ws, main, file);
389
- heldBefore = before !== undefined && (learned ? learnedStatus(before) === "pending" : ((note) => !Array.isArray(note) && note.status === "pending")(parseNoteFile(file, before)));
397
+ // Restored, a retired note, skill or draft goes back to the status its retire recorded (retired_from): active, so
398
+ // given to every later run, or waiting for its owner's OK again, so a retire and a restore never skip that OK
399
+ // (a retire that recorded none restores it waiting). It is checked again as a new one is (secrets' shapes, the
400
+ // host's values, hidden characters, its format, every file of a skill's or a draft's folder): a retire takes a
401
+ // leaking one out of every run unchecked, and a restore never brings it back. A restore is never an approval.
390
402
  if (learned) {
391
403
  const status = learnedStatus(current.text);
392
404
  const kind = learned.kind === "skill" ? "skill" : "workflow";
393
405
  if (status !== "retired")
394
406
  throw new ApiError("bad_request", `The ${kind} is not retired: it is ${status}.`);
395
- // Read as retired since its front matter reads no way, or its status is set on more than one line, which no
396
- // writer edits (learnedStatus): refused until it is written so it does.
397
- if (!frontMatter(current.text) || !statusOnOneLine(current.text))
407
+ // Read as retired since its front matter reads no way, or its status (or the retired_from its retire recorded) is
408
+ // set on more than one line, which no writer edits (learnedStatus, restorable): refused until it is written so.
409
+ if (!restorable(current.text))
398
410
  throw refused([printable({ rule: kind, path: file, detail: UNCLEAR_FRONT }, input.refuse)]);
399
- text = released(current.text);
411
+ // Back to the status its retire recorded (restoredLearned: retired_from, read by the one reader), never active
412
+ // unless it was active: a held skill or draft waits for its owner's OK again.
413
+ text = restoredLearned(current.text);
400
414
  const problems = skillProblems(text, learned.name).map((detail) => printable({ rule: kind, path: file, detail }, input.refuse));
401
415
  const extra = (frontKeys(text) ?? []).filter((key) => !LEARNED_KEYS.includes(key) && key !== "status");
402
416
  if (extra.length)
@@ -409,9 +423,9 @@ export async function writeNote(data, agentId, raw, input) {
409
423
  // a restore never brings back a draft no run could run.
410
424
  const draft = changes.find(({ path }) => path === `${folder}workflow.json`);
411
425
  if (learned.kind !== "skill" && draft && input.draftTools) {
412
- const { tools, gated } = await input.draftTools();
426
+ const { tools, gated, deniedBy, ask } = await input.draftTools();
413
427
  const dsl = await import("@parcha/agentrun-dsl");
414
- for (const { rule, detail } of draftProblems(dsl, draft.bytes.toString("utf8"), tools, gated))
428
+ for (const { rule, detail } of draftProblems(dsl, draft.bytes.toString("utf8"), tools, gated, deniedBy ?? {}, ask))
415
429
  problems.push(printable({ rule, path: draft.path, detail }, input.refuse));
416
430
  }
417
431
  if (problems.length)
@@ -423,12 +437,14 @@ export async function writeNote(data, agentId, raw, input) {
423
437
  throw refused(note.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
424
438
  if (note.status !== "retired")
425
439
  throw new ApiError("bad_request", `The note is not retired: it is ${note.status}.`);
426
- text = approve(current.text);
440
+ text = restore(current.text, note);
427
441
  const { problems } = checkNote(file, Buffer.from(text, "utf8"), input.refuse);
428
442
  if (problems.length)
429
443
  throw refused(problems);
430
- // What it supersedes, and is active still, is superseded now, as an approval marks it.
431
- await mark(note.supersedes);
444
+ // Back active, what it supersedes, and is active still, is superseded now, as an approval marks it; back
445
+ // waiting, it supersedes nothing until it is approved.
446
+ if (note.retired_from === "active")
447
+ await mark(note.supersedes);
432
448
  }
433
449
  }
434
450
  else if (text === undefined && learned && !input.approve) {
@@ -465,13 +481,13 @@ export async function writeNote(data, agentId, raw, input) {
465
481
  // A retire is how a person takes a note out of every later run's prompt, a leaking one above all, so it always
466
482
  // can: only the note's format is checked as retired (its front matter parses, and it fits the note cap with the
467
483
  // status line added), never a secret in its name or text. Every answer cuts those as any read does.
468
- text = retire(current.text);
484
+ text = retire(current.text, note.status === "pending" ? "pending" : "active");
469
485
  const retired = parseNoteFile(file, text);
470
486
  if (Array.isArray(retired))
471
487
  throw refused(retired.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
472
488
  const size = Buffer.byteLength(text);
473
489
  if (size > CAPS.note + RETIRED_LINE)
474
- throw refused([printable({ rule: "too_large", path: file, detail: `${size} bytes as retired; the cap is ${CAPS.note}, and the status line a retire adds` }, input.refuse)]);
490
+ throw refused([printable({ rule: "too_large", path: file, detail: `${size} bytes as retired; the cap is ${CAPS.note}, and the status lines a retire adds` }, input.refuse)]);
475
491
  }
476
492
  if (current && text === current.text)
477
493
  return { result: { status: 200, file, text, etag: etagOf(current.oid) } };
@@ -482,7 +498,7 @@ export async function writeNote(data, agentId, raw, input) {
482
498
  const kind = input.approve ? "approved" : input.restore ? "restored" : given === undefined ? "retired" : current ? "edited" : "created";
483
499
  const change = {
484
500
  // Who approved, and how, in the trailers; the commit's own date is when. Never the note's text.
485
- by: { person: kind, file, approved: Boolean(input.approve || heldBefore) },
501
+ by: { person: kind, file, approved: Boolean(input.approve) },
486
502
  writes: [{ path: file, text: text }, { path: INDEX_FILE, text: buildIndex(after) }, ...[...also].map(([path, marked]) => ({ path, text: marked }))],
487
503
  // A create takes a name main holds nothing by, as git holds it: a file the notes leave out included.
488
504
  ...(current ? {} : { absent: [file] }),
@@ -503,6 +519,55 @@ export async function writeNote(data, agentId, raw, input) {
503
519
  }
504
520
  });
505
521
  }
522
+ /** POST /agents/{id}/learning/workflows/{name}/promote's read of the learned workflow `raw` (percent-encoded) on agent
523
+ * `agentId`'s main: an active one alone, as every later run is given it. One that waits for its owner's OK, or that a
524
+ * person retired, is 409 learned_not_active: a promotion never runs what the owner has not let every run use. Each of
525
+ * its files is checked again as a restore checks it (unstorable: a secret's shape, the host's values as they are now,
526
+ * a hidden character), and its workflow.json as the learning checker checks a run's draft against the agent's tools and
527
+ * its gate (draftProblems: the DSL's validation with no code run, no code node, no shell or executor call, no call node
528
+ * on a tool the agent does not have or the gate holds to ask or deny). Any of those is 400 with `problems`, printable.
529
+ * Reads only: the folder is never written. */
530
+ export async function promotable(data, agentId, raw, input) {
531
+ let name;
532
+ try {
533
+ name = decodeURIComponent(raw);
534
+ }
535
+ catch {
536
+ throw new ApiError("bad_request", "the workflow's name is not percent-encoded right");
537
+ }
538
+ if (!learnedName("workflow", name))
539
+ throw new ApiError("bad_request", "A learned workflow's folder is named with lowercase letters, digits, dashes and underscores.");
540
+ const found = await reading(data, agentId, async ({ snapshot, body }) => {
541
+ const item = snapshot.workflows.find((one) => one.name === name);
542
+ if (!item)
543
+ return undefined;
544
+ if (item.status !== "active")
545
+ return { item, files: [] };
546
+ return { item, files: await Promise.all(item.files.map(async ({ path, oid }) => ({ path, text: await body(path, oid) }))) };
547
+ }, () => undefined);
548
+ if (!found)
549
+ throw new ApiError("not_found", "the agent's learning folder has no such workflow on main");
550
+ const { item, files } = found;
551
+ if (item.status === "pending")
552
+ throw new ApiError("learned_not_active", "This workflow waits for your OK: approve it first. Making it an agent never skips your OK.");
553
+ if (item.status !== "active")
554
+ throw new ApiError("learned_not_active", "This workflow is retired: restore it first to make it an agent.");
555
+ const file = `${WORKFLOWS_DIR}/${name}/workflow.json`;
556
+ const json = files.find(({ path }) => path === file);
557
+ const problems = unstorable(files.map(({ path, text }) => ({ path, status: "modified", bytes: Buffer.from(text, "utf8") })), input.refuse);
558
+ if (!json)
559
+ problems.push(printable({ rule: "workflow", path: file, detail: "the workflow's folder holds no workflow.json" }, input.refuse));
560
+ const dsl = await import("@parcha/agentrun-dsl");
561
+ if (json && !problems.length) {
562
+ const { tools, gated, deniedBy } = await input.draftTools();
563
+ for (const { rule, detail } of draftProblems(dsl, json.text, tools, gated, deniedBy ?? {}))
564
+ problems.push(printable({ rule, path: file, detail }, input.refuse));
565
+ }
566
+ if (problems.length)
567
+ throw new ApiError("bad_request", `The workflow does not pass the checks: ${[...new Set(problems.map((problem) => problem.rule))].join(", ")}.`, { problems });
568
+ const workflow = JSON.parse(json.text);
569
+ return { name, description: item.description, workflow, calls: dsl.inspectWorkflow(workflow).requires.tools };
570
+ }
506
571
  /** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
507
572
  * settled: the one shape, read from the one store (store-reads/learning.ts
508
573
  * runLearningOverStore). */
@@ -525,6 +590,12 @@ export function runLearningBody(input, shown, secrets) {
525
590
  // The grade's alone: the end-of-run turn's cost is in the run's own totals.
526
591
  cost_usd: { grade: cost_usd?.grade ?? null },
527
592
  tokens: { grade: tokens?.grade ?? null },
593
+ // What the job did with the learned skills and workflows it was offered (store-reads/learning.ts learnedUseOf), apart
594
+ // from the skills and workflows it learned (notesView's), each name cut of the host's secrets as a note's is.
595
+ used: {
596
+ skills: (input.used?.skills ?? []).map(({ name, read }) => ({ name: shown.name(name), read })),
597
+ workflows: (input.used?.workflows ?? []).map(({ name, calls, failed }) => ({ name: shown.name(name), calls, failed })),
598
+ },
528
599
  };
529
600
  }
530
601
  /** `text`, an added file, as git's unified diff writes it, hunks only. */
@@ -43,8 +43,7 @@ export type Impact = {
43
43
  after: ImpactSide;
44
44
  } | null;
45
45
  /** Each note's count of runs that were given it and that read it, by its file, over runs' note files (usage.ts
46
- * notesOf, lineNotesOf): a held run's from its learning, an ended one's from its ledger line. A run counts a note
47
- * once each way. */
46
+ * notesOf). A run counts a note once each way. */
48
47
  export declare function noteRuns(runs: readonly (NoteFiles | null | undefined)[]): NoteRuns;
49
48
  /** What a run's learning tells its impact (learning-run.ts ofAgent), from memory or from its ledger line: how it
50
49
  * ended and when, how many notes it started from, when its answer was final and its costs; `grade_usd` once it ended
@@ -54,15 +53,18 @@ export type ImpactLearning = {
54
53
  reason: string | null;
55
54
  at: string;
56
55
  seed_notes?: number;
56
+ seed_skills?: number;
57
+ seed_workflows?: number;
57
58
  answered_at?: string;
58
59
  job_cost_usd?: number | null;
59
60
  look_back_usd?: number | null;
60
61
  grade_usd?: number | null;
61
62
  };
62
63
  /** What learning changed for an agent, from its run rows (`rows`) and what its runs' learning says (`learningOf`),
63
- * never a run's files. `after`: its completed agentic runs that started from at least one active note. `before`: its
64
- * completed agentic runs that started before its first note, the earlier of its first merge's end and the start of its
65
- * first run that started from a note (a person's note comes first that way); none of them could have. Each side's
64
+ * never a run's files. `after`: its completed agentic runs that started from at least one learned item: an active note,
65
+ * a learned skill it was offered or a learned workflow its learned_workflow tool could run (seededItems). `before`: its
66
+ * completed agentic runs that started before its first item, the earlier of its first merge's end and the start of its
67
+ * first run that started from one (a person's note comes first that way); none of them could have. Each side's
66
68
  * figures (sideOf, figuresOf): its time to the answer in seconds to a tenth, its job's own cost, what learning cost.
67
69
  * An imported or archived run is on neither side, nor is a later one with learning off or seeded with no note (every
68
70
  * note retired), nor one whose learning predates these figures. Null unless both sides hold 2 runs or more. */
@@ -71,8 +71,7 @@ export function learningStats(rows, filter, learningOf) {
71
71
  return out;
72
72
  }
73
73
  /** Each note's count of runs that were given it and that read it, by its file, over runs' note files (usage.ts
74
- * notesOf, lineNotesOf): a held run's from its learning, an ended one's from its ledger line. A run counts a note
75
- * once each way. */
74
+ * notesOf). A run counts a note once each way. */
76
75
  export function noteRuns(runs) {
77
76
  const out = new Map();
78
77
  for (const files of runs) {
@@ -88,6 +87,9 @@ export function noteRuns(runs) {
88
87
  }
89
88
  return out;
90
89
  }
90
+ /** How many learned items a run started from: its notes, the learned skills it was offered and the learned workflows its
91
+ * learned_workflow tool could run. */
92
+ const seededItems = (learning) => (learning?.seed_notes ?? 0) + (learning?.seed_skills ?? 0) + (learning?.seed_workflows ?? 0);
91
93
  /** The middle of `values` (the mean of the two middle ones when there is an even count); undefined for none. */
92
94
  const median = (values) => {
93
95
  if (!values.length)
@@ -123,15 +125,16 @@ function figuresOf(row, learning) {
123
125
  return { seconds: (answered - Date.parse(row.startedAt)) / 1000, cost, learning: typeof back === "number" && typeof grade === "number" ? back + grade : null };
124
126
  }
125
127
  /** What learning changed for an agent, from its run rows (`rows`) and what its runs' learning says (`learningOf`),
126
- * never a run's files. `after`: its completed agentic runs that started from at least one active note. `before`: its
127
- * completed agentic runs that started before its first note, the earlier of its first merge's end and the start of its
128
- * first run that started from a note (a person's note comes first that way); none of them could have. Each side's
128
+ * never a run's files. `after`: its completed agentic runs that started from at least one learned item: an active note,
129
+ * a learned skill it was offered or a learned workflow its learned_workflow tool could run (seededItems). `before`: its
130
+ * completed agentic runs that started before its first item, the earlier of its first merge's end and the start of its
131
+ * first run that started from one (a person's note comes first that way); none of them could have. Each side's
129
132
  * figures (sideOf, figuresOf): its time to the answer in seconds to a tenth, its job's own cost, what learning cost.
130
133
  * An imported or archived run is on neither side, nor is a later one with learning off or seeded with no note (every
131
134
  * note retired), nor one whose learning predates these figures. Null unless both sides hold 2 runs or more. */
132
135
  export function learningImpact(rows, learningOf) {
133
136
  const done = rows.filter((row) => row.kind === "agentic" && !row.importedFrom && !row.archivedAt && row.state === "completed" && row.endedAt);
134
- const after = done.filter((row) => (learningOf(row)?.seed_notes ?? 0) > 0);
137
+ const after = done.filter((row) => seededItems(learningOf(row)) > 0);
135
138
  const merges = rows.flatMap((row) => {
136
139
  const learning = learningOf(row);
137
140
  return learning?.state === "merged" ? [Date.parse(learning.at)] : [];
@@ -77,6 +77,9 @@ export declare const said: {
77
77
  * skill X: …"), any other as lost with it ("Not kept, with the skill X: …"). The caller cuts the line of the host's
78
78
  * secrets: a name is the run's to choose. */
79
79
  export declare function notKept(verdict: Pick<Verdict, "reason" | "items">, lost?: readonly Pick<LearnedFile, "file">[]): string;
80
+ /** The why of a note main already holds the same (a run's new note, or a skill re-filed as one: runner/learning-loop.ts
81
+ * takenOnMain): no change, so no words of a run's learning say it, the merge's own or a read's rebuilt from its verdict. */
82
+ export declare const SAME_NOTE = "The same rule is already one of the agent's notes.";
80
83
  /** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, or why the
81
84
  * grader kept nothing, said again from its parts (`learned`, `pending`, `verdict`) each cut by `cut` first (the host's
82
85
  * secrets as they are now), and the whole line cut again, as notKept's is: a skill's or a workflow's file names it in
@@ -44,6 +44,7 @@ const RULE_WORDS = {
44
44
  edited: "a change to a note it had (a new note replaces an old one instead)",
45
45
  deleted: "a deleted note",
46
46
  exists: "a note under a name already taken",
47
+ duplicate: "a note that says what another one says",
47
48
  too_large: `a note over ${CAPS.note / 1024} KB`,
48
49
  too_many_notes: `more than ${CAPS.newNotes} new notes`,
49
50
  note: "a note whose header is not in shape",
@@ -175,6 +176,9 @@ export function notKept(verdict, lost = []) {
175
176
  const named = [subject, others.length ? `with ${listed(others)}` : ""].filter(Boolean).join(" ");
176
177
  return said_.replace(/^Not kept: /, `Not kept, ${named}: `);
177
178
  }
179
+ /** The why of a note main already holds the same (a run's new note, or a skill re-filed as one: runner/learning-loop.ts
180
+ * takenOnMain): no change, so no words of a run's learning say it, the merge's own or a read's rebuilt from its verdict. */
181
+ export const SAME_NOTE = "The same rule is already one of the agent's notes.";
178
182
  /** A run's learning in words as a read says them, whole: what it learned and what waits for the owner's OK, or why the
179
183
  * grader kept nothing, said again from its parts (`learned`, `pending`, `verdict`) each cut by `cut` first (the host's
180
184
  * secrets as they are now), and the whole line cut again, as notKept's is: a skill's or a workflow's file names it in
@@ -187,10 +191,10 @@ export function wordsOf(learning, cut) {
187
191
  const waiting = Array.isArray(pending) ? pending.filter((note) => typeof note?.name === "string") : [];
188
192
  const files = [...(Array.isArray(learning.skills) ? learning.skills : []), ...(Array.isArray(learning.workflows) ? learning.workflows : [])].filter((file) => typeof file?.file === "string" && typeof file.name === "string");
189
193
  if (kept.length || waiting.length || files.length)
190
- return cut(said.merged(kept.map((note) => ({ name: cut(note.name), supersedes: note.supersedes })), waiting.map((note) => ({ name: cut(note.name) })), files.map((file) => ({ file: file.file, name: cut(file.name), ...(file.pending ? { pending: true } : {}) })), (verdict?.items ?? []).filter((item) => !item.keep && typeof item.why === "string").map((item) => ({ why: cut(item.why) })), Array.isArray(learning.problems) ? learning.problems : []));
194
+ return cut(said.merged(kept.map((note) => ({ name: cut(note.name), supersedes: note.supersedes })), waiting.map((note) => ({ name: cut(note.name) })), files.map((file) => ({ file: file.file, name: cut(file.name), ...(file.pending ? { pending: true } : {}) })), (verdict?.items ?? []).filter((item) => !item.keep && typeof item.why === "string" && item.why !== SAME_NOTE).map((item) => ({ why: cut(item.why) })), Array.isArray(learning.problems) ? learning.problems : []));
191
195
  }
192
196
  if (learning.state === "dropped" && learning.reason === "grader" && verdict) {
193
- // serve.json's `lost` is read as untrusted: an entry out of shape is left out. The whole line is cut again, the names
197
+ // the stored `lost` is read as untrusted: an entry out of shape is left out. The whole line is cut again, the names
194
198
  // in it included.
195
199
  const lost = Array.isArray(learning.lost) ? learning.lost.filter((file) => typeof file?.file === "string") : [];
196
200
  return cut(notKept({ reason: cut(verdict.reason), items: (verdict.items ?? []).map((item) => ({ ...item, why: cut(item.why) })) }, lost));
@@ -5,6 +5,9 @@ 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;
@@ -31,7 +34,6 @@ export type Tokens = {
31
34
  cache_write: number;
32
35
  output: number;
33
36
  };
34
- export declare const NO_TOKENS: Tokens;
35
37
  /** The variable that names the grader's model, as `--grade-model` does. */
36
38
  export declare const GRADE_MODEL_ENV = "AGENTRUN_SERVE_GRADE_MODEL";
37
39
  /** The model this server grades on, by name: `given` (`--grade-model`), else GRADE_MODEL_ENV, else its strong tier
@@ -52,7 +54,7 @@ export type NoteUsed = {
52
54
  export type NoteLearned = NoteUsed & {
53
55
  supersedes: string[];
54
56
  };
55
- /** A run's learning as serve.json keeps it. Past the view's four fields: the checker's `problems` (printable), the
57
+ /** A run's learning as the store keeps it. Past the view's four fields: the checker's `problems` (printable), the
56
58
  * grader's `verdict` and the blob of each note it read superseded (`graded`, by file), both kept before the merge, the
57
59
  * merge commit, and what the grade cost (null when unknown, never 0), which is in no run's totals; the notes the run
58
60
  * started with (`given`: each note its # Learned section names, whole or as an index line, set as it is seeded) and read
@@ -126,7 +128,7 @@ export declare function secretsShown(values: readonly string[], { local }?: {
126
128
  /** 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
129
  * `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
130
  * 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. */
131
+ * the stored ones are read as untrusted: an entry out of shape is left out. */
130
132
  export declare function notesView({ state, given, read: opened, learned, pending, skills, workflows }: Learning, shown: Shown, settled: boolean): {
131
133
  given?: NoteUsed[];
132
134
  read?: NoteUsed[];
@@ -162,32 +164,13 @@ export declare const learningView: (learning: Learning, shown: Shown, settled: b
162
164
  skills?: LearnedFile[];
163
165
  workflows?: LearnedFile[];
164
166
  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;
167
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
166
168
  detail: string | null;
167
169
  at: string;
168
170
  };
169
171
  /** A learning's `reason` as it is served: one of its words as the server writes them, read back from a kept row, which is
170
172
  * untrusted, so cut of the host's secrets as every text is. */
171
173
  export declare const reasonShown: (reason: Learning["reason"] | undefined, shown: Shown) => Learning["reason"];
172
- /** A run's learning as a list shows it: its state and reason, its detail cut of the host's secrets and then short (at
173
- * most LIST_DETAIL characters, so a secret is never cut in half and shown), and the notes it read and learned
174
- * (notesView); never its time. */
175
- export declare const shortLearning: (learning: Learning | null, shown: Shown, settled: boolean) => ({
176
- state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
177
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
178
- detail: string | null;
179
- } & Omit<{
180
- given?: NoteUsed[];
181
- read?: NoteUsed[];
182
- learned?: NoteLearned[];
183
- pending?: NoteUsed[];
184
- skills?: LearnedFile[];
185
- workflows?: LearnedFile[];
186
- state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
187
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
188
- detail: string | null;
189
- at: string;
190
- }, "at" | "reason" | "detail" | "state">) | null;
191
174
  /** A run's learning as its view shows it, in short for a list: all of it but its time, its detail cut short. */
192
175
  export declare function shortOf<T extends {
193
176
  state: LearningState;
@@ -196,7 +179,7 @@ export declare function shortOf<T extends {
196
179
  at: string;
197
180
  }>({ state, reason, detail, at: _, ...notes }: T): {
198
181
  state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
199
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
182
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
200
183
  detail: string | null;
201
184
  } & Omit<T, "at" | "reason" | "detail" | "state">;
202
185
  /** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
@@ -207,7 +190,8 @@ export declare const LEARNING_LABEL = "learning";
207
190
  * secrets, then shortened to its head and tail, shortMessage; absent in a proposal kept before the grader read them). */
208
191
  export declare const PROPOSAL = "learning-proposal.json";
209
192
  /** A run's proposal: its notes, skill and drafts, each draft's dry run by its workflow.json's path (learn/skills.ts
210
- * draftDryRun: passed, or not run and why), and what was said in the run. */
193
+ * draftDryRun: passed, or not run and why), the skill of each draft's name as the folder holds it at the seed
194
+ * (`drafted`, its SKILL.md: shown to the grader beside the draft, never graded or merged), and what was said in the run. */
211
195
  export type Proposal = {
212
196
  seed: string;
213
197
  notes: {
@@ -219,6 +203,10 @@ export type Proposal = {
219
203
  text: string;
220
204
  }[];
221
205
  dryRuns?: Record<string, DraftDryRun>;
206
+ drafted?: {
207
+ file: string;
208
+ text: string;
209
+ }[];
222
210
  asked?: string[];
223
211
  triggered?: Triggered[];
224
212
  };
@@ -502,6 +490,3 @@ export declare function withLearned(runDir: string, given: Workspace | string, i
502
490
  instructions: string;
503
491
  skills: string[];
504
492
  }>;
505
- /** The learned workflows a run's pin names, as its directory keeps them (LEARNED_WORKFLOWS_FILE): none when the pin
506
- * names none. A file that is not the list the pin names throws. */
507
- export declare function pinnedWorkflows(runDir: string, pin: Pin | undefined): Promise<LearnedWorkflow[]>;
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) {
@@ -72,7 +75,6 @@ export function learningBudgetOf(env, given) {
72
75
  * reason from the closed list. A learning fault never refuses a run: it starts with nothing learned, `seed_failed`. */
73
76
  export const LEARNING_STATES = ["seeded", "reflecting", "proposed", "merged", "dropped"];
74
77
  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 };
76
78
  /** The variable that names the grader's model, as `--grade-model` does. */
77
79
  export const GRADE_MODEL_ENV = "AGENTRUN_SERVE_GRADE_MODEL";
78
80
  /** The model this server grades on, by name: `given` (`--grade-model`), else GRADE_MODEL_ENV, else its strong tier
@@ -100,7 +102,7 @@ const isText = (value) => typeof value === "string";
100
102
  /** 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
103
  * `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
104
  * 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. */
105
+ * the stored ones are read as untrusted: an entry out of shape is left out. */
104
106
  export function notesView({ state, given, read: opened, learned, pending, skills, workflows }, shown, settled) {
105
107
  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
108
  const started = refs(given);
@@ -148,10 +150,6 @@ export const learningView = (learning, shown, settled) => {
148
150
  /** A learning's `reason` as it is served: one of its words as the server writes them, read back from a kept row, which is
149
151
  * untrusted, so cut of the host's secrets as every text is. */
150
152
  export const reasonShown = (reason, shown) => (typeof reason === "string" ? shown.text(reason) : (reason ?? null));
151
- /** A run's learning as a list shows it: its state and reason, its detail cut of the host's secrets and then short (at
152
- * most LIST_DETAIL characters, so a secret is never cut in half and shown), and the notes it read and learned
153
- * (notesView); never its time. */
154
- export const shortLearning = (learning, shown, settled) => (learning ? shortOf(learningView(learning, shown, settled)) : null);
155
153
  /** A run's learning as its view shows it, in short for a list: all of it but its time, its detail cut short. */
156
154
  export function shortOf({ state, reason, detail, at: _, ...notes }) {
157
155
  return { state, reason, detail: detail === null ? null : short(detail, LIST_DETAIL), ...notes };
@@ -768,15 +766,3 @@ export async function withLearned(runDir, given, instructions, own = []) {
768
766
  skills: [...own, ...learned.filter((path) => whole.has(path.split("/")[0]))],
769
767
  };
770
768
  }
771
- /** The learned workflows a run's pin names, as its directory keeps them (LEARNED_WORKFLOWS_FILE): none when the pin
772
- * names none. A file that is not the list the pin names throws. */
773
- export async function pinnedWorkflows(runDir, pin) {
774
- const names = pin?.workflows ?? [];
775
- if (!names.length)
776
- return [];
777
- const kept = JSON.parse(await readFile(join(runDir, LEARNED_WORKFLOWS_FILE), "utf8"));
778
- const ok = (entry) => isObject(entry) && typeof entry.name === "string" && typeof entry.description === "string" && typeof entry.workflow === "string";
779
- if (!Array.isArray(kept) || !kept.every(ok) || kept.map(({ name }) => name).join("\n") !== names.join("\n"))
780
- throw new Error(`the run's ${LEARNED_WORKFLOWS_FILE} is not the workflows its pin names`);
781
- return kept;
782
- }
package/dist/llm.d.ts CHANGED
@@ -32,9 +32,12 @@ type Models = {
32
32
  errorMessage?: string;
33
33
  }>;
34
34
  };
35
- /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. */
35
+ /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. An answer names the model as `named`
36
+ * (the run's own name for it) when the pick reaches it through another provider (a runner's session proxy), else as
37
+ * `<provider>/<model id>`. */
36
38
  export declare function completer(models: Models, pick: (tier: string | undefined) => {
37
39
  provider: string;
38
40
  modelId: string;
41
+ named?: string;
39
42
  } | undefined, thinking: ModelThinkingLevel): Complete;
40
43
  export {};
package/dist/llm.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { sideRequests } from "./cap.js";
2
2
  export const LLM_TOOL = "llm";
3
3
  const MAX_PROMPT = 400_000;
4
- /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. */
4
+ /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. An answer names the model as `named`
5
+ * (the run's own name for it) when the pick reaches it through another provider (a runner's session proxy), else as
6
+ * `<provider>/<model id>`. */
5
7
  export function completer(models, pick, thinking) {
6
8
  return async (args, signal) => {
7
9
  const { prompt, system, maxTokens, tier } = args;
@@ -35,6 +37,6 @@ export function completer(models, pick, thinking) {
35
37
  const cached = (message.usage?.cacheRead ?? 0) + (message.usage?.cacheWrite ?? 0);
36
38
  const usage = message.usage ? { input_tokens: message.usage.input + cached, output_tokens: message.usage.output, cached_input_tokens: cached } : null;
37
39
  const cost = priced && typeof message.usage?.cost?.total === "number" ? message.usage.cost.total : null;
38
- return { text, model: `${ref.provider}/${ref.modelId}`, usage, cost_usd: cost };
40
+ return { text, model: ref.named ?? `${ref.provider}/${ref.modelId}`, usage, cost_usd: cost };
39
41
  };
40
42
  }
@@ -69,6 +69,12 @@ 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
+ /** The claim's per-call check of a server's credential (its custody stamp): awaited before each call is checked for
73
+ * sending, it may drop the credential (`credentials[server].unopened`), which the call then refuses unsent; one that
74
+ * throws (a store read failed, the call was stopped) refuses the call unsent too, in words, and the run goes on. Only
75
+ * the runner's MCP claim step passes it: a github_app token whose App was disconnected or replaced. A CLI harness's
76
+ * session proxy ends in the same call. */
77
+ beforeCall?: (server: string, signal: AbortSignal) => Promise<void>;
72
78
  }
73
79
  /** A run's journal commit. */
74
80
  export type McpCommit = <T>(change: (tx: unknown) => Promise<T>) => Promise<T>;
@@ -185,7 +185,7 @@ export function mcpGateway(options) {
185
185
  const statuses = new Map();
186
186
  const send = options.fetch ?? fetch;
187
187
  /** The credential values each call in flight took or its server's requests sent while it was out, one set per call, by
188
- * server: with liveCredentials a refresh can swap a token between a call taking its headers and a request leaving, so
188
+ * server: a refresh can swap a token between a call taking its headers and a request leaving, so
189
189
  * what its answer or error is scrubbed of is every one of them, never only the headers it took. A call's set goes when
190
190
  * the call ends, so nothing held outlives the calls that sent it. */
191
191
  const inFlight = new Map();
@@ -359,6 +359,16 @@ export function mcpGateway(options) {
359
359
  };
360
360
  /** A call the gate let go: a priced one under the run's cap and booked, an unpriced one marked not metered. */
361
361
  const sent = async (server, tool, args, callId, signal) => {
362
+ // The credential's custody checked first: one the claim drops now is refused below, unsent. A check that could not
363
+ // be made (a store read failed, the call was stopped) refuses this call unsent too, in words: never sent unchecked.
364
+ if (options.beforeCall) {
365
+ try {
366
+ await options.beforeCall(server, signal);
367
+ }
368
+ catch {
369
+ return said(`The MCP server ${server}'s credential can't be used right now: it could not be checked just now. Nothing was sent.`, true);
370
+ }
371
+ }
362
372
  const why = unsendable(server, tool);
363
373
  if (why)
364
374
  return said(why, true);