@parcha/agentrun-serve 0.1.0-beta.35 → 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 (372) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +260 -168
  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-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/box-image.d.ts +1 -97
  19. package/dist/box-image.js +4 -284
  20. package/dist/box-paths.d.ts +2 -7
  21. package/dist/box-paths.js +7 -13
  22. package/dist/box-settings.d.ts +0 -11
  23. package/dist/box-settings.js +4 -29
  24. package/dist/browser-commands.js +1 -1
  25. package/dist/browser-computer.d.ts +47 -3
  26. package/dist/browser-computer.js +286 -18
  27. package/dist/browser-person.d.ts +19 -2
  28. package/dist/browser-person.js +55 -6
  29. package/dist/browser-wait-ended.d.ts +23 -0
  30. package/dist/browser-wait-ended.js +42 -0
  31. package/dist/cap.d.ts +13 -41
  32. package/dist/cap.js +24 -73
  33. package/dist/cli.js +4 -22
  34. package/dist/computer-routes.d.ts +1 -4
  35. package/dist/computer-routes.js +3 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +38 -1
  38. package/dist/computer-view.d.ts +11 -2
  39. package/dist/computer-view.js +2 -1
  40. package/dist/computers.d.ts +48 -7
  41. package/dist/computers.js +100 -23
  42. package/dist/console/assets/index-BI4Byidu.js +550 -0
  43. package/dist/console/assets/index-C19gUF2n.css +1 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/docker-daemon.d.ts +2 -2
  46. package/dist/docker-daemon.js +2 -2
  47. package/dist/errors.js +5 -5
  48. package/dist/faux-computers.js +4 -0
  49. package/dist/files.d.ts +1 -9
  50. package/dist/files.js +1 -9
  51. package/dist/github.d.ts +22 -2
  52. package/dist/github.js +42 -8
  53. package/dist/gpu-words.d.ts +14 -0
  54. package/dist/gpu-words.js +21 -0
  55. package/dist/graph-view.d.ts +2 -0
  56. package/dist/graph-view.js +25 -1
  57. package/dist/handed-values.d.ts +1 -1
  58. package/dist/handed-values.js +1 -1
  59. package/dist/harness-install.d.ts +60 -3
  60. package/dist/harness-install.js +322 -34
  61. package/dist/harness.js +1 -1
  62. package/dist/host-tools.d.ts +8 -9
  63. package/dist/host-tools.js +7 -7
  64. package/dist/index.d.ts +1 -3
  65. package/dist/index.js +1 -2
  66. package/dist/key-refusal.d.ts +1 -1
  67. package/dist/key-refusal.js +2 -2
  68. package/dist/learn/check.d.ts +7 -1
  69. package/dist/learn/check.js +123 -5
  70. package/dist/learn/commit.d.ts +40 -6
  71. package/dist/learn/commit.js +164 -20
  72. package/dist/learn/folder.d.ts +5 -0
  73. package/dist/learn/folder.js +33 -0
  74. package/dist/learn/grade.d.ts +18 -1
  75. package/dist/learn/grade.js +86 -16
  76. package/dist/learn/index.d.ts +1 -1
  77. package/dist/learn/index.js +1 -1
  78. package/dist/learn/learning.sh +12 -1
  79. package/dist/learn/notes.d.ts +3 -0
  80. package/dist/learn/notes.js +3 -0
  81. package/dist/learn/reflect.d.ts +5 -2
  82. package/dist/learn/reflect.js +43 -29
  83. package/dist/learn/skills.d.ts +4 -0
  84. package/dist/learn/skills.js +7 -0
  85. package/dist/learned-nodes.d.ts +6 -2
  86. package/dist/learned-workflow.d.ts +19 -9
  87. package/dist/learned-workflow.js +62 -34
  88. package/dist/learning-cost.d.ts +79 -0
  89. package/dist/learning-cost.js +69 -0
  90. package/dist/learning-routes.d.ts +8 -3
  91. package/dist/learning-routes.js +9 -6
  92. package/dist/learning-words.d.ts +3 -0
  93. package/dist/learning-words.js +6 -2
  94. package/dist/learning.d.ts +13 -6
  95. package/dist/learning.js +4 -2
  96. package/dist/mcp-probe.d.ts +8 -1
  97. package/dist/mcp-probe.js +62 -20
  98. package/dist/mcp-secret-writes.js +4 -0
  99. package/dist/mcp-servers-store.js +8 -3
  100. package/dist/model.d.ts +5 -5
  101. package/dist/model.js +6 -6
  102. package/dist/openapi.d.ts +2 -0
  103. package/dist/openapi.js +204 -47
  104. package/dist/owner.d.ts +0 -1
  105. package/dist/owner.js +0 -2
  106. package/dist/paid-calls.js +1 -1
  107. package/dist/place-offers.d.ts +97 -0
  108. package/dist/place-offers.js +206 -0
  109. package/dist/place.d.ts +9 -13
  110. package/dist/place.js +22 -32
  111. package/dist/port-models.d.ts +2 -1
  112. package/dist/port-models.js +5 -3
  113. package/dist/print.d.ts +1 -8
  114. package/dist/print.js +1 -14
  115. package/dist/propose.d.ts +1 -0
  116. package/dist/propose.js +25 -10
  117. package/dist/run-cut.d.ts +5 -0
  118. package/dist/run-cut.js +19 -0
  119. package/dist/run-db.js +3 -3
  120. package/dist/run-launch.d.ts +14 -1
  121. package/dist/run-launch.js +7 -2
  122. package/dist/run-learning-served.d.ts +1 -1
  123. package/dist/run-manifest.d.ts +2 -2
  124. package/dist/run-manifest.js +2 -2
  125. package/dist/run-secrets.js +3 -3
  126. package/dist/run-timeline-served.js +56 -44
  127. package/dist/run-view.d.ts +5 -2
  128. package/dist/run-view.js +4 -3
  129. package/dist/runnable.d.ts +2 -2
  130. package/dist/runnable.js +6 -2
  131. package/dist/runner/adapter-loop.d.ts +16 -1
  132. package/dist/runner/adapter-loop.js +131 -30
  133. package/dist/runner/adapter-run-spec.d.ts +25 -4
  134. package/dist/runner/adapter-run-spec.js +103 -24
  135. package/dist/runner/adapters/pi.d.ts +11 -3
  136. package/dist/runner/adapters/pi.js +35 -12
  137. package/dist/runner/beside.js +6 -2
  138. package/dist/runner/cli-run-spec.d.ts +7 -0
  139. package/dist/runner/cli-run-spec.js +92 -38
  140. package/dist/runner/commands.d.ts +5 -1
  141. package/dist/runner/commands.js +3 -3
  142. package/dist/runner/conformance/harness.d.ts +0 -1
  143. package/dist/runner/conformance/harness.js +8 -5
  144. package/dist/runner/github-app.js +2 -2
  145. package/dist/runner/harness-loops.js +1 -1
  146. package/dist/runner/journal-kinds.d.ts +15 -5
  147. package/dist/runner/journal-kinds.js +6 -1
  148. package/dist/runner/learning-end.d.ts +15 -0
  149. package/dist/runner/learning-end.js +26 -5
  150. package/dist/runner/learning-factory.js +6 -2
  151. package/dist/runner/learning-loop.d.ts +73 -1
  152. package/dist/runner/learning-loop.js +203 -18
  153. package/dist/runner/learning-seed.d.ts +2 -0
  154. package/dist/runner/learning-seed.js +1 -1
  155. package/dist/runner/loop-contract.d.ts +8 -0
  156. package/dist/runner/loop-contract.js +6 -0
  157. package/dist/runner/loop.d.ts +5 -1
  158. package/dist/runner/loop.js +20 -0
  159. package/dist/runner/main.js +12 -2
  160. package/dist/runner/mcp-claim.d.ts +4 -0
  161. package/dist/runner/mcp-claim.js +29 -1
  162. package/dist/runner/mcp-github.d.ts +4 -2
  163. package/dist/runner/mcp-github.js +0 -7
  164. package/dist/runner/mcp-run.d.ts +2 -0
  165. package/dist/runner/mcp-run.js +1 -0
  166. package/dist/runner/metrics.d.ts +4 -0
  167. package/dist/runner/metrics.js +9 -0
  168. package/dist/runner/model-route.d.ts +3 -0
  169. package/dist/runner/model-route.js +5 -2
  170. package/dist/runner/pr-checkout.d.ts +59 -0
  171. package/dist/runner/pr-checkout.js +176 -0
  172. package/dist/runner/reflect-hook.d.ts +1 -0
  173. package/dist/runner/reflect-hook.js +3 -3
  174. package/dist/runner/runner.js +47 -12
  175. package/dist/runner/spec-holds.d.ts +8 -3
  176. package/dist/runner/spec-holds.js +12 -10
  177. package/dist/runner/store-port.d.ts +4 -1
  178. package/dist/runner/store-secrets.js +17 -1
  179. package/dist/runner/subagent.d.ts +44 -0
  180. package/dist/runner/subagent.js +188 -0
  181. package/dist/runner/workflow-host.d.ts +18 -2
  182. package/dist/runner/workflow-host.js +23 -3
  183. package/dist/runner/workflow-loop.d.ts +5 -2
  184. package/dist/runner/workflow-loop.js +9 -8
  185. package/dist/runner/workflow-spec.d.ts +26 -14
  186. package/dist/runner/workflow-spec.js +97 -30
  187. package/dist/runs-over-store.d.ts +11 -6
  188. package/dist/runs-over-store.js +111 -24
  189. package/dist/sealing.js +1 -2
  190. package/dist/secret-cut.d.ts +1 -1
  191. package/dist/secret-cut.js +1 -1
  192. package/dist/server.d.ts +32 -49
  193. package/dist/server.js +249 -199
  194. package/dist/store/agent-body.d.ts +9 -2
  195. package/dist/store/agent-body.js +16 -8
  196. package/dist/store/deadline.js +9 -5
  197. package/dist/store/index.d.ts +3 -3
  198. package/dist/store/index.js +2 -2
  199. package/dist/store/journal/storage.js +2 -1
  200. package/dist/store/postgres/connection.js +9 -4
  201. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  202. package/dist/store/schema.d.ts +2 -1
  203. package/dist/store/schema.js +11 -8
  204. package/dist/store/seal.d.ts +13 -0
  205. package/dist/store/seal.js +19 -0
  206. package/dist/store/sqlite/connection.d.ts +5 -0
  207. package/dist/store/sqlite/connection.js +88 -47
  208. package/dist/store/sqlite/run-patch.d.ts +18 -2
  209. package/dist/store/sqlite/run-patch.js +31 -2
  210. package/dist/store/sqlite/store.js +65 -11
  211. package/dist/store/store.d.ts +62 -12
  212. package/dist/store/store.js +22 -1
  213. package/dist/store-reads/analytics.js +3 -2
  214. package/dist/store-reads/cap.d.ts +1 -3
  215. package/dist/store-reads/cap.js +8 -6
  216. package/dist/store-reads/decisions.d.ts +2 -2
  217. package/dist/store-reads/decisions.js +3 -6
  218. package/dist/store-reads/journal.js +45 -12
  219. package/dist/store-reads/learning.d.ts +15 -1
  220. package/dist/store-reads/learning.js +68 -10
  221. package/dist/store-reads/runs.d.ts +6 -4
  222. package/dist/store-reads/runs.js +17 -10
  223. package/dist/store-reads/stats.js +5 -1
  224. package/dist/store-view.js +45 -19
  225. package/dist/template-eval.js +2 -1
  226. package/dist/templates.d.ts +64 -0
  227. package/dist/templates.js +101 -16
  228. package/dist/timeline/timeline.d.ts +3 -1
  229. package/dist/timeline/timeline.js +19 -4
  230. package/dist/tool-blurbs.js +1 -0
  231. package/dist/tool-budget.d.ts +8 -0
  232. package/dist/tool-budget.js +7 -1
  233. package/dist/tool-gate.d.ts +7 -1
  234. package/dist/tool-gate.js +7 -2
  235. package/dist/tool-plane.d.ts +33 -19
  236. package/dist/tool-plane.js +64 -27
  237. package/dist/tools.d.ts +18 -34
  238. package/dist/tools.js +104 -70
  239. package/dist/trigger-signatures.d.ts +1 -0
  240. package/dist/trigger-signatures.js +3 -1
  241. package/dist/triggers.d.ts +3 -3
  242. package/dist/triggers.js +2 -2
  243. package/dist/turn-end.d.ts +0 -3
  244. package/dist/turn-end.js +0 -3
  245. package/dist/usage-lines.d.ts +1 -1
  246. package/dist/validate.d.ts +6 -0
  247. package/dist/validate.js +30 -3
  248. package/dist/webhooks.d.ts +2 -1
  249. package/dist/webhooks.js +5 -2
  250. package/dist/workflow/decision-recovery.d.ts +23 -0
  251. package/dist/workflow/decision-recovery.js +80 -0
  252. package/dist/workflow/decisions.d.ts +134 -0
  253. package/dist/workflow/decisions.js +46 -0
  254. package/dist/workflow/host-session.d.ts +5 -0
  255. package/dist/workflow/host-session.js +85 -0
  256. package/dist/workflow/host-tools.d.ts +3 -0
  257. package/dist/workflow/host-tools.js +3 -0
  258. package/dist/workflow/node-runner.d.ts +112 -0
  259. package/dist/workflow/node-runner.js +270 -0
  260. package/dist/workflow/node.d.ts +88 -0
  261. package/dist/workflow/node.js +99 -0
  262. package/dist/workflow/operator-error.d.ts +4 -0
  263. package/dist/workflow/operator-error.js +4 -0
  264. package/dist/workflow/pi-versions.d.ts +9 -0
  265. package/dist/workflow/pi-versions.js +8 -0
  266. package/dist/workflow/readers.d.ts +36 -0
  267. package/dist/workflow/readers.js +145 -0
  268. package/dist/workflow/record-file.d.ts +10 -0
  269. package/dist/workflow/record-file.js +56 -0
  270. package/dist/workflow/record-tool.d.ts +76 -0
  271. package/dist/workflow/record-tool.js +126 -0
  272. package/dist/workflow/record.d.ts +151 -0
  273. package/dist/workflow/record.js +401 -0
  274. package/dist/workflow/run-error.d.ts +16 -0
  275. package/dist/workflow/run-error.js +26 -0
  276. package/dist/workflow/runner.d.ts +6 -0
  277. package/dist/workflow/runner.js +240 -0
  278. package/dist/workflow/store.d.ts +23 -0
  279. package/dist/workflow/store.js +242 -0
  280. package/dist/workflow/task.d.ts +133 -0
  281. package/dist/workflow/task.js +411 -0
  282. package/dist/workflow/thinking.d.ts +3 -0
  283. package/dist/workflow/thinking.js +7 -0
  284. package/dist/workflow/tool-context.d.ts +21 -0
  285. package/dist/workflow/tool-context.js +13 -0
  286. package/dist/workflow/types.d.ts +126 -0
  287. package/dist/workflow/types.js +1 -0
  288. package/dist/workflow/wal.d.ts +11 -0
  289. package/dist/workflow/wal.js +106 -0
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/agent-computer.d.ts +137 -0
  292. package/dist/workspace/agent-computer.js +292 -0
  293. package/dist/workspace/archil-claim.d.ts +11 -0
  294. package/dist/workspace/archil-claim.js +18 -10
  295. package/dist/workspace/archil-disks.d.ts +49 -0
  296. package/dist/workspace/archil-disks.js +185 -0
  297. package/dist/workspace/archil-exec.js +2 -3
  298. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  299. package/dist/workspace/archil-mount-credential.js +13 -4
  300. package/dist/workspace/computer-deps.d.ts +16 -8
  301. package/dist/workspace/computer-deps.js +18 -7
  302. package/dist/workspace/computer-for-claim.d.ts +42 -6
  303. package/dist/workspace/computer-for-claim.js +209 -9
  304. package/dist/workspace/computer-janitor.d.ts +3 -2
  305. package/dist/workspace/computer-janitor.js +43 -9
  306. package/dist/workspace/computer-ledger.d.ts +3 -1
  307. package/dist/workspace/computer-ledger.js +7 -0
  308. package/dist/workspace/index.d.ts +3 -2
  309. package/dist/workspace/index.js +1 -0
  310. package/dist/workspace/resolve-computer.d.ts +42 -11
  311. package/dist/workspace/resolve-computer.js +65 -13
  312. package/dist/workspace/run-disk.d.ts +34 -0
  313. package/dist/workspace/run-disk.js +91 -0
  314. package/dist/workspace/run-tools.d.ts +4 -4
  315. package/dist/workspace/run-tools.js +8 -6
  316. package/dist/workspace/server-run-workspace.d.ts +3 -2
  317. package/dist/workspace/server-run-workspace.js +17 -4
  318. package/dist/workspace.js +1 -1
  319. package/package.json +10 -15
  320. package/templates/README.md +9 -6
  321. package/templates/code-review/agent.md +27 -11
  322. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  323. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  324. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  325. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  326. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  327. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  328. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  329. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  330. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  331. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  332. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  333. package/templates/code-review/evals/re-review/prompt.md +1 -1
  334. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  335. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  336. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  337. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  338. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  339. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  340. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  341. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  342. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  343. package/templates/code-review/findings.schema.json +131 -27
  344. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  345. package/templates/code-review/skills/review/DEEP.md +130 -0
  346. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  347. package/templates/code-review/skills/review/SKILL.md +104 -154
  348. package/dist/box/record.d.ts +0 -6
  349. package/dist/box/record.js +0 -41
  350. package/dist/box/sweep.d.ts +0 -53
  351. package/dist/box/sweep.js +0 -193
  352. package/dist/box-egress-vm.d.ts +0 -118
  353. package/dist/box-egress-vm.js +0 -354
  354. package/dist/box-egress.d.ts +0 -105
  355. package/dist/box-egress.js +0 -256
  356. package/dist/box-relay-vm.d.ts +0 -84
  357. package/dist/box-relay-vm.js +0 -437
  358. package/dist/box-relay.d.ts +0 -36
  359. package/dist/box-relay.js +0 -207
  360. package/dist/boxes.d.ts +0 -109
  361. package/dist/boxes.js +0 -249
  362. package/dist/budget.d.ts +0 -71
  363. package/dist/budget.js +0 -199
  364. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  365. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  366. package/dist/daytona-api.d.ts +0 -10
  367. package/dist/daytona-api.js +0 -20
  368. package/dist/egress-proxy.d.ts +0 -45
  369. package/dist/egress-proxy.js +0 -416
  370. package/dist/egress-table.d.ts +0 -24
  371. package/dist/egress-table.js +0 -165
  372. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -6,8 +6,8 @@
6
6
  // unavailable, a model node that names any tool, a code node or a shell or executor call is refused before any node
7
7
  // runs, never after earlier ones spent), then runs it with the workflow DSL's runWorkflow:
8
8
  // - a model node (agent, decide, extract, report) on the run's model of its tier, else the run's own model (the one
9
- // model the run was made with and handed the key of: app.ts), in a fresh session of its own (agentrun-pi's host
10
- // runner), with no tool of its own;
9
+ // model the run was made with and handed the key of: app.ts), in a fresh session of its own (the host
10
+ // runner, workflow/host-session.ts), with no tool of its own;
11
11
  // - a call node `via: "tool"` on the tool table's effect, as a workflow revision's (app.ts), for a tool the agent has,
12
12
  // its paid requests booked under the tool's call (paid-calls.ts), each node's under a call of its own; web_search
13
13
  // where it resolves native on the provider's hosted search through the run's models (hosted-search.ts), on a harness
@@ -25,6 +25,7 @@ import { LEARNED_NODES, LEARNED_NODES_MAX } from "./learned-nodes.js";
25
25
  import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
26
26
  import { workflowLine } from "./learning.js";
27
27
  import { ledgerOf } from "./paid-calls.js";
28
+ import { PORT_PROVIDER } from "./port-models.js";
28
29
  import { forModel } from "./result.js";
29
30
  import { ARGS_PREVIEW_BYTES, deniedText } from "./tool-gate.js";
30
31
  import { allows, CALL_TOOLS, learnedDraftTools, toolOf, workflowTools } from "./tools.js";
@@ -80,40 +81,45 @@ export const LEARNED_WORKFLOW_TOOL = "learned_workflow";
80
81
  /** The most of a learned workflow's output its result line shows, and the longest value it shows as written. */
81
82
  const LINE_MAX = 120;
82
83
  const VALUE_MAX = 60;
83
- /** One line of a learned workflow's output for its row: an object's fields as `name value`, each value whole or, when
84
- * longer than VALUE_MAX, only as its size, and whole fields only until LINE_MAX. Nothing is ever cut inside a value:
85
- * the timeline redacts the line as it says it (its summary's words), and its redactor matches a held value only whole,
86
- * so a cut value could leave a prefix it would not find. Newlines are flattened, so the one line it keeps holds every
87
- * field. An output already cut for the model (learnedText) says so. */
84
+ /** One line of a learned workflow's output for its row: an object's fields as `name value`, and a text output (learnedOutput
85
+ * hands one back as it is, #2412) its lines, each value or line whole or, when longer than VALUE_MAX, only as its size,
86
+ * and whole ones only until LINE_MAX. Nothing is ever cut inside a value or a line: the timeline redacts the line as it
87
+ * says it (its summary's words), and its redactor matches a held value only whole, so a cut one could leave a prefix it
88
+ * would not find. Newlines are flattened, so the one line it keeps holds every part. An output already cut for the
89
+ * model (learnedText) says so. */
88
90
  export function outputLine(text) {
89
91
  const clipped = /\n\[the workflow's output is cut at (\d+) of (\d+) characters\]$/.exec(text);
90
92
  if (clipped)
91
93
  return `its output is long, cut at ${clipped[1]} of ${clipped[2]} characters`;
94
+ const said = (value) => {
95
+ const flat = (typeof value === "string" ? value : JSON.stringify(value) ?? String(value)).replace(/\s+/g, " ").trim();
96
+ return flat.length > VALUE_MAX ? `(${flat.length} characters)` : flat;
97
+ };
98
+ /** `parts` whole, joined by `by`, until LINE_MAX: then an ellipsis. */
99
+ const joined = (parts, by) => {
100
+ const kept = [];
101
+ let length = 0;
102
+ for (const part of parts) {
103
+ if (kept.length && length + by.length + part.length > LINE_MAX) {
104
+ kept.push("…");
105
+ break;
106
+ }
107
+ kept.push(part);
108
+ length += (kept.length > 1 ? by.length : 0) + part.length;
109
+ }
110
+ return kept.length ? kept.join(by) : undefined;
111
+ };
92
112
  let output;
93
113
  try {
94
114
  output = JSON.parse(text);
95
115
  }
96
116
  catch {
97
- return undefined;
117
+ // Text, as it is: its lines that hold words.
118
+ return joined(text.split("\n").filter((line) => line.trim()).map(said), " / ");
98
119
  }
99
- const said = (value) => {
100
- const flat = (typeof value === "string" ? value : JSON.stringify(value) ?? String(value)).replace(/\s+/g, " ").trim();
101
- return flat.length > VALUE_MAX ? `(${flat.length} characters)` : flat;
102
- };
103
120
  if (!output || typeof output !== "object" || Array.isArray(output))
104
121
  return said(output);
105
- const fields = [];
106
- let length = 0;
107
- for (const [key, value] of Object.entries(output)) {
108
- const field = `${key} ${said(value)}`;
109
- if (fields.length && length + 2 + field.length > LINE_MAX) {
110
- fields.push("…");
111
- break;
112
- }
113
- fields.push(field);
114
- length += (fields.length > 1 ? 2 : 0) + field.length;
115
- }
116
- return fields.length ? fields.join(", ") : undefined;
122
+ return joined(Object.entries(output).map(([key, value]) => `${key} ${said(value)}`), ", ");
117
123
  }
118
124
  // The timeline's words for a learned workflow's call: the workflow it ran (its name), and, once it returns, its output.
119
125
  registerLabel(LEARNED_WORKFLOW_TOOL, (a) => (typeof a.name === "string" && a.name ? `Ran the learned workflow ${a.name}` : "Ran a learned workflow"), undefined, { name: "Run a learned workflow" });
@@ -124,7 +130,7 @@ registerOutcome(LEARNED_WORKFLOW_TOOL, (result) => {
124
130
  /** The most characters of a learned workflow's output its answer holds, monid's bound (monid.ts CLIP): within the
125
131
  * host's result bound, which each CLI is told to pass whole (host-bounds.test). */
126
132
  export const LEARNED_CLIP = 60_000;
127
- /** `text`, a learned workflow's output as JSON, cut at LEARNED_CLIP characters (never inside a surrogate pair), saying
133
+ /** `text`, a learned workflow's output as its tool hands it back (learnedOutput), cut at LEARNED_CLIP characters (never inside a surrogate pair), saying
128
134
  * so. */
129
135
  export function learnedText(text) {
130
136
  if (text.length <= LEARNED_CLIP)
@@ -137,12 +143,26 @@ export function learnedText(text) {
137
143
  export const NODE_TOOLS_REFUSED = "a learned workflow's model node runs without tools here";
138
144
  /** The tool's description, sent with every model request of the run, so it holds what a model needs to call it right and
139
145
  * no more: one line of what the tool does (one call, by name, a JSON input with the listed fields, `*` marking a required
140
- * one; what it answers), then each workflow on a line of its own (workflowLine): its name, its input's fields and the
141
- * line its README says what it does with. */
146
+ * one; what it answers: a text output as it is, to reply with unchanged, since a model handed it otherwise writes its own
147
+ * reply around it and a format the workflow's last node wrote is lost, #2412), then each workflow on a line of its own
148
+ * (workflowLine): its name, its input's fields and the line its README says what it does with. */
142
149
  export const learnedWorkflowDescription = (workflows) => [
143
- "Runs one of this agent's learned workflows in one call, by name, on a JSON input with the fields below (* required). Answers its output as JSON, or why it did not run.",
150
+ "Runs a learned workflow in one call, by name, on a JSON input: fields below (* required). Text output: reply with it unchanged. Else JSON, or why it did not run.",
144
151
  ...workflows.map(workflowLine),
145
152
  ].join("\n");
153
+ /** A learned workflow's output as its tool hands it back: its text when it is text, a string or an object of one string
154
+ * field (a node's record of one field, as a last node that writes the answer gives it), so the lines its last node wrote
155
+ * reach the model as lines; else JSON. */
156
+ export function learnedOutput(output) {
157
+ if (typeof output === "string")
158
+ return output;
159
+ if (output && typeof output === "object" && !Array.isArray(output)) {
160
+ const values = Object.values(output);
161
+ if (values.length === 1 && typeof values[0] === "string")
162
+ return values[0];
163
+ }
164
+ return JSON.stringify(output ?? null);
165
+ }
146
166
  /** One model request as a pi-ai event stream, sent through `models.completeSimple` as the run's own request, under its
147
167
  * cap: on pi marked and costed on the run's timeline under `learned_workflow` (sideRequests), on another harness booked
148
168
  * by the session's proxy, labelled by the side key it goes under. */
@@ -209,7 +229,7 @@ export function learnedWorkflowTool(run) {
209
229
  },
210
230
  });
211
231
  }
212
- /** `flow` run on `input` for `run`: its output as JSON, or why it did not run, and each of its nodes that ran (at most
232
+ /** `flow` run on `input` for `run`: its output as its tool hands it back (learnedOutput), or why it did not run, and each of its nodes that ran (at most
213
233
  * LEARNED_NODES_MAX), none for one refused before any node ran. Never throws, but on an abort. `ledger`: the tool call's,
214
234
  * which each call node's paid requests are booked under, as a call of its own within it. `nodes`: where each node is
215
235
  * added as it ends, the caller's to keep when the call is aborted (and so throws) part way. */
@@ -243,9 +263,8 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
243
263
  if (problems.length)
244
264
  return refuse(problems.map(({ detail }) => detail).join("; "));
245
265
  const doc = JSON.parse(flow.workflow);
246
- // agentrun-pi's root loads its host runner and @earendil-works/pi-coding-agent, an optional peer of agentrun-pi: serve
247
- // depends on it (package.json) so an installed server has it, not only this repository.
248
- const { createPiHostRunner } = await import("@parcha/agentrun-pi");
266
+ // The host runner loads @earendil-works/pi-coding-agent and pi-agent-core, serve's own dependencies (package.json).
267
+ const { createPiHostRunner } = await import("./workflow/host-session.js");
249
268
  const runners = new Map();
250
269
  const runnerFor = async (tier) => {
251
270
  const known = runners.get(tier ?? "default");
@@ -262,9 +281,17 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
262
281
  runners.set(tier ?? "default", runner);
263
282
  return runner;
264
283
  };
284
+ // Each model node's model and tier by its execution path, as it runs: its node.end (the same path) puts them on its
285
+ // trace. Never by its label, which a workflow may repeat. Only a model node runs here: a call node never has one.
286
+ const ranOn = new Map();
265
287
  const runNode = async (request) => {
266
288
  if (request.tools?.length)
267
289
  throw new Error(`${NODE_TOOLS_REFUSED}: its node "${request.label}" names ${request.tools.join(", ")}`);
290
+ const tier = typeof request.tier === "string" ? request.tier : undefined;
291
+ const ref = run.modelOf(tier);
292
+ const model = !ref ? undefined : ref.provider === PORT_PROVIDER ? (run.modelName?.(tier) ?? undefined) : ref.modelId;
293
+ if (model && typeof request.executionPath === "string")
294
+ ranOn.set(request.executionPath, { model, ...(tier ? { tier } : {}) });
268
295
  // Its own signal, which the DSL ties to the call's (a sibling's failure, a deadline, the call's stop).
269
296
  return (await runnerFor(request.tier))(request);
270
297
  };
@@ -317,13 +344,14 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
317
344
  if (event.type !== "node.end" || nodes.length >= LEARNED_NODES_MAX)
318
345
  return;
319
346
  const detail = (event.detail ?? {});
320
- nodes.push({ label: String(event.label), kind: String(detail.kind ?? ""), status: String(detail.status ?? ""), duration_ms: typeof detail.duration_ms === "number" ? detail.duration_ms : 0 });
347
+ const ran = typeof event.executionPath === "string" ? ranOn.get(event.executionPath) : undefined;
348
+ nodes.push({ label: String(event.label), kind: String(detail.kind ?? ""), status: String(detail.status ?? ""), duration_ms: typeof detail.duration_ms === "number" ? detail.duration_ms : 0, ...ran });
321
349
  };
322
350
  try {
323
351
  const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, onEvent, ...(signal ? { signal } : {}) });
324
352
  if (result.status !== "complete")
325
353
  return refuse(`it ended ${result.status}`);
326
- return { text: learnedText(JSON.stringify(result.output ?? null)), isError: false, nodes };
354
+ return { text: learnedText(learnedOutput(result.output)), isError: false, nodes };
327
355
  }
328
356
  catch (error) {
329
357
  if (signal?.aborted)
@@ -0,0 +1,79 @@
1
+ /** The path a run took: `workflow`, a learned workflow finished it alone (its job's only tool calls were learned_workflow
2
+ * calls, each answering, and nothing was said after its first message: the runner's own rule for a run with nothing new
3
+ * to look back on, runner/learning-end.ts onlyLearnedWorkflows); `handed_back`, a learned workflow ran and the agent
4
+ * went on (it failed, escalated, or the agent did more work after it); `agent`, no learned workflow ran. */
5
+ export declare const RUN_PATHS: readonly ["agent", "handed_back", "workflow"];
6
+ export type RunPath = (typeof RUN_PATHS)[number];
7
+ /** What a run that looked back kept of its costs as it answered (runner/reflect-hook.ts: store-reads/learning.ts
8
+ * answeredOf): when the job answered, what it had cost by then and what looking back cost after it. */
9
+ export type CostLooked = {
10
+ answered_at?: string;
11
+ job_cost_usd?: number | null;
12
+ look_back_usd?: number | null;
13
+ };
14
+ /** A run's own cost and what learning added for it, from its row's cost (`rowUsd`: the job, its look-back and any turn a
15
+ * person asked of it after), what it kept as it answered (`looked`, none for a run that did not look back) and what its
16
+ * grade spent (`gradeUsd`: its learning run's cost once that run ended, stopped or failed, 0 while it runs or when there
17
+ * is none, null when unknown):
18
+ * - `cost_usd`: the job's own $: its row's cost less its look-back, never under what it had cost when it answered (a
19
+ * later turn's spend is the job's too); its row's cost for a run that did not look back;
20
+ * - `learning_usd`: what learning cost for it: its look-back and its grade, 0 for a run that does not learn; null when
21
+ * either is unknown (a grade that failed or was stopped mid-ask spent what no one knows);
22
+ * - `total_usd`: their sum, the run's all-in $; null when either is. */
23
+ export declare function runCostOf(rowUsd: number | null, looked: CostLooked | null, gradeUsd?: number | null): {
24
+ cost_usd: number | null;
25
+ learning_usd: number | null;
26
+ total_usd: number | null;
27
+ };
28
+ /** One run of the series, in the order the agent's runs started: `n` its number among them (1 the first). */
29
+ export type CostRun = {
30
+ n: number;
31
+ run_id: string;
32
+ started_at: string;
33
+ path: RunPath;
34
+ /** The learned workflow its job called last, by name; null when it called none. */
35
+ workflow: string | null;
36
+ /** The commit of the agent's learning folder the run started from (its learning start's seed): the learned revision
37
+ * that served it. Null for a run that does not learn. */
38
+ learned_revision: string | null;
39
+ cost_usd: number | null;
40
+ learning_usd: number | null;
41
+ total_usd: number | null;
42
+ };
43
+ /** The fewest runs after the takeover a "times cheaper" figure needs: fewer say too little. */
44
+ export declare const CHEAPER_AFTER_RUNS = 20;
45
+ /** The latest runs the route answers by default, and at most. */
46
+ export declare const COST_RUNS_DEFAULT = 1000;
47
+ export declare const COST_RUNS_MAX = 10000;
48
+ /** What the series shows: `takeover`, its first `workflow` run, null before one; `before`, the mean of the job's own $
49
+ * (learning left out) over its `agent` runs before the takeover (every one when there is none yet), whose cost is known;
50
+ * `after`, the mean all-in $ (learning included) of every run from the takeover on whose total is known; and
51
+ * `times_cheaper`, before over after to a tenth, once `after` counts CHEAPER_AFTER_RUNS runs or more, else null. The
52
+ * before side leaves learning out and the after side keeps it in, so the figure never flatters learning. */
53
+ export type CostSummary = {
54
+ takeover: {
55
+ n: number;
56
+ run_id: string;
57
+ } | null;
58
+ before: {
59
+ runs: number;
60
+ mean_usd: number;
61
+ } | null;
62
+ after: {
63
+ runs: number;
64
+ mean_usd: number;
65
+ } | null;
66
+ times_cheaper: number | null;
67
+ };
68
+ export declare function costSummary(runs: readonly CostRun[]): CostSummary;
69
+ /** The series as CSV (RFC 4180, a header line, `\r\n` line ends): one row a run, an unknown figure empty. A text cell that
70
+ * a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
71
+ * it opens as the text it is. */
72
+ export declare const COST_CSV_COLUMNS: readonly ["n", "run_id", "started_at", "path", "workflow", "learned_revision", "cost_usd", "learning_usd", "total_usd"];
73
+ export declare function costCsv(runs: readonly CostRun[]): string;
74
+ /** GET /agents/{id}/learning/cost's query: `limit`, an integer from 1 to COST_RUNS_MAX (COST_RUNS_DEFAULT when absent),
75
+ * and `format`, `json` (the default) or `csv`. Anything else is 400. */
76
+ export declare function learningCostQuery(url: URL): {
77
+ limit: number;
78
+ csv: boolean;
79
+ };
@@ -0,0 +1,69 @@
1
+ // An agent's cost per run, run after run (GET /agents/{id}/learning/cost): what each run of its cost, what learning added
2
+ // for it, and the path it took, so a person sees the cost fall once a learned workflow does the job, and by how much.
3
+ // Aggregates only: no run's input, answer or tool text. The store's reader (store-reads/learning.ts agentCostOverStore)
4
+ // gives each run's figures and its path (runner/learning-end.ts runPathOf); this module sums its learning and says what the
5
+ // series shows (costSummary), the rule the console, the CLI and the CSV all read. It imports only the errors, so the API
6
+ // document reads its words.
7
+ import { ApiError } from "./errors.js";
8
+ /** The path a run took: `workflow`, a learned workflow finished it alone (its job's only tool calls were learned_workflow
9
+ * calls, each answering, and nothing was said after its first message: the runner's own rule for a run with nothing new
10
+ * to look back on, runner/learning-end.ts onlyLearnedWorkflows); `handed_back`, a learned workflow ran and the agent
11
+ * went on (it failed, escalated, or the agent did more work after it); `agent`, no learned workflow ran. */
12
+ export const RUN_PATHS = ["agent", "handed_back", "workflow"];
13
+ const usd = (value) => Math.round(value * 1e6) / 1e6;
14
+ /** A run's own cost and what learning added for it, from its row's cost (`rowUsd`: the job, its look-back and any turn a
15
+ * person asked of it after), what it kept as it answered (`looked`, none for a run that did not look back) and what its
16
+ * grade spent (`gradeUsd`: its learning run's cost once that run ended, stopped or failed, 0 while it runs or when there
17
+ * is none, null when unknown):
18
+ * - `cost_usd`: the job's own $: its row's cost less its look-back, never under what it had cost when it answered (a
19
+ * later turn's spend is the job's too); its row's cost for a run that did not look back;
20
+ * - `learning_usd`: what learning cost for it: its look-back and its grade, 0 for a run that does not learn; null when
21
+ * either is unknown (a grade that failed or was stopped mid-ask spent what no one knows);
22
+ * - `total_usd`: their sum, the run's all-in $; null when either is. */
23
+ export function runCostOf(rowUsd, looked, gradeUsd = 0) {
24
+ const answered = looked?.answered_at !== undefined;
25
+ const asAnswered = answered ? (looked.job_cost_usd ?? null) : rowUsd;
26
+ const back = answered ? (looked.look_back_usd ?? null) : 0;
27
+ // What the row holds past the answer and its look-back is a later turn's spend, unknown once the row's cost is; with the
28
+ // look-back's cost unknown the two can't be told apart, and the job is what it had cost when it answered.
29
+ const job = !answered || asAnswered === null || back === null ? asAnswered : rowUsd === null ? null : Math.max(asAnswered, rowUsd - back);
30
+ const spent = back === null || gradeUsd === null ? null : back + gradeUsd;
31
+ return { cost_usd: job === null ? null : usd(job), learning_usd: spent === null ? null : usd(spent), total_usd: job === null || spent === null ? null : usd(job + spent) };
32
+ }
33
+ /** The fewest runs after the takeover a "times cheaper" figure needs: fewer say too little. */
34
+ export const CHEAPER_AFTER_RUNS = 20;
35
+ /** The latest runs the route answers by default, and at most. */
36
+ export const COST_RUNS_DEFAULT = 1000;
37
+ export const COST_RUNS_MAX = 10_000;
38
+ export function costSummary(runs) {
39
+ const first = runs.findIndex((run) => run.path === "workflow");
40
+ const mean = (values) => (values.length ? { runs: values.length, mean_usd: usd(values.reduce((a, b) => a + b, 0) / values.length) } : null);
41
+ const before = mean((first < 0 ? runs : runs.slice(0, first)).flatMap((run) => (run.path === "agent" && run.cost_usd !== null ? [run.cost_usd] : [])));
42
+ const after = first < 0 ? null : mean(runs.slice(first).flatMap((run) => (run.total_usd === null ? [] : [run.total_usd])));
43
+ const times = before && after && after.runs >= CHEAPER_AFTER_RUNS && after.mean_usd > 0 ? Math.round((before.mean_usd / after.mean_usd) * 10) / 10 : null;
44
+ return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, times_cheaper: times };
45
+ }
46
+ /** The series as CSV (RFC 4180, a header line, `\r\n` line ends): one row a run, an unknown figure empty. A text cell that
47
+ * a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
48
+ * it opens as the text it is. */
49
+ export const COST_CSV_COLUMNS = ["n", "run_id", "started_at", "path", "workflow", "learned_revision", "cost_usd", "learning_usd", "total_usd"];
50
+ export function costCsv(runs) {
51
+ const cell = (value) => {
52
+ const raw = value === null || value === undefined ? "" : String(value);
53
+ const text = typeof value === "string" && /^[=+\-@\t\r]/.test(raw) ? `'${raw}` : raw;
54
+ return /[",\r\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
55
+ };
56
+ return [COST_CSV_COLUMNS.join(","), ...runs.map((run) => COST_CSV_COLUMNS.map((column) => cell(run[column])).join(","))].map((line) => `${line}\r\n`).join("");
57
+ }
58
+ /** GET /agents/{id}/learning/cost's query: `limit`, an integer from 1 to COST_RUNS_MAX (COST_RUNS_DEFAULT when absent),
59
+ * and `format`, `json` (the default) or `csv`. Anything else is 400. */
60
+ export function learningCostQuery(url) {
61
+ const limitText = url.searchParams.get("limit");
62
+ const limit = limitText === null ? COST_RUNS_DEFAULT : /^[1-9]\d*$/.test(limitText) ? Number(limitText) : NaN;
63
+ if (!(limit >= 1 && limit <= COST_RUNS_MAX))
64
+ throw new ApiError("bad_request", `limit is a whole number from 1 to ${COST_RUNS_MAX}`);
65
+ const format = url.searchParams.get("format") ?? "json";
66
+ if (format !== "json" && format !== "csv")
67
+ throw new ApiError("bad_request", "format is json or csv");
68
+ return { limit, csv: format === "csv" };
69
+ }
@@ -27,10 +27,15 @@ type NoteView = {
27
27
  };
28
28
  };
29
29
  /** When a retired note, skill or draft was retired, and by whom: a person (its retire's commit), else a run. */
30
+ /** Who retired a retired item, and when, and `from`, the status its restore gives back; or, for a skill or draft that
31
+ * reads retired only because its file can't be read (its front matter reads no way: unclearFront, read from its file as
32
+ * the view is made), that no one did: the host could not read it (`why`), with no `from`, since its restore waits for
33
+ * the file to be fixed. One closed shape. */
30
34
  type Retired = {
31
35
  at: string;
32
- by: "person" | "run";
33
- from: "active" | "pending";
36
+ by: "person" | "run" | "host";
37
+ from?: "active" | "pending";
38
+ why?: "unreadable";
34
39
  };
35
40
  /** The newest change to a note, skill or draft (its file: the note, a SKILL.md, a draft's README.md): what it was, by
36
41
  * whom and when. A person's is named by its commit (`learning: <kind> by a person: <file>`); a run's merge is `learned`. */
@@ -234,7 +239,7 @@ export declare function runLearningBody(input: {
234
239
  workflows?: import("./learning.js").LearnedFile[];
235
240
  run: string;
236
241
  state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
237
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
242
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
238
243
  detail: string | null;
239
244
  at: string;
240
245
  };
@@ -1,4 +1,4 @@
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, restorable, restore, restoredLearned } from "./learn/index.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
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";
@@ -72,8 +72,8 @@ async function reading(data, agentId, read, none) {
72
72
  /** A retired item's `retired`: its newest retire by a person; else, one a person made retired another way (an edit to
73
73
  * status: retired, or created so), their newest change; else (retired by none of theirs) its newest change's time. */
74
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). */
76
- const retiredOf = (history, from) => ({ ...(history.retire ? { at: history.retire.at, by: "person" } : history.person ? { at: history.person.at, by: "person" } : { at: history.at, by: "run" }), from: from ?? "pending" });
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" });
77
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
78
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
79
79
  * change, and when and by whom it was retired on a retired one. */
@@ -82,13 +82,13 @@ const noteView = (note, text, shown, runs) => ({
82
82
  ...(note.history.last ? { last_change: note.history.last } : {}),
83
83
  ...(note.status === "retired" ? { retired: retiredOf(note.history, note.retired_from) } : {}),
84
84
  });
85
- function learnedView(item, kind, shown) {
85
+ function learnedView(item, kind, shown, unread = false) {
86
86
  const file = kind === "skill" ? item.file : `${WORKFLOWS_DIR}/${item.name}/workflow.json`;
87
87
  const bytes = item.files.find(({ path }) => path === file)?.bytes ?? item.bytes;
88
88
  return {
89
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),
90
90
  ...(item.history.last ? { last_change: item.history.last } : {}),
91
- ...(item.status === "retired" ? { retired: retiredOf(item.history, item.retired_from) } : {}),
91
+ ...(item.status === "retired" ? { retired: retiredOf(item.history, item.retired_from, unread) } : {}),
92
92
  };
93
93
  }
94
94
  /** A change on main as the log shows it, cut of the host's secrets. */
@@ -171,7 +171,10 @@ export async function agentLearning(data, agentId, shown, counts, impact, runs =
171
171
  return reading(data, agentId, async ({ snapshot, body }) => {
172
172
  const index = snapshot.index.bytes ? await body(INDEX_FILE, snapshot.index.oid) : "";
173
173
  const notes = await notesPage(snapshot.notes, snapshot.main, 0, NOTES_PAGE, body, shown, runs);
174
- 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 };
175
178
  }, () => ({ agent: agentId, main: null, index: "", notes: EMPTY, skills: [], workflows: [], log: EMPTY, counts, impact }));
176
179
  }
177
180
  /** GET /agents/{id}/learning/notes?cursor=&limit=&status=: a page of the notes, ordered as the view's. A page at an
@@ -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,7 +164,7 @@ 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
  };
@@ -177,7 +179,7 @@ export declare function shortOf<T extends {
177
179
  at: string;
178
180
  }>({ state, reason, detail, at: _, ...notes }: T): {
179
181
  state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
180
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
182
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
181
183
  detail: string | null;
182
184
  } & Omit<T, "at" | "reason" | "detail" | "state">;
183
185
  /** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
@@ -188,7 +190,8 @@ export declare const LEARNING_LABEL = "learning";
188
190
  * secrets, then shortened to its head and tail, shortMessage; absent in a proposal kept before the grader read them). */
189
191
  export declare const PROPOSAL = "learning-proposal.json";
190
192
  /** A run's proposal: its notes, skill and drafts, each draft's dry run by its workflow.json's path (learn/skills.ts
191
- * draftDryRun: passed, or not run and why), and what was said in the run. */
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. */
192
195
  export type Proposal = {
193
196
  seed: string;
194
197
  notes: {
@@ -200,6 +203,10 @@ export type Proposal = {
200
203
  text: string;
201
204
  }[];
202
205
  dryRuns?: Record<string, DraftDryRun>;
206
+ drafted?: {
207
+ file: string;
208
+ text: string;
209
+ }[];
203
210
  asked?: string[];
204
211
  triggered?: Triggered[];
205
212
  };
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);
@@ -1,6 +1,7 @@
1
1
  import { ApiError, type InputIssue } from "./errors.js";
2
2
  export declare const MCP_SERVER_NAME: RegExp;
3
- export declare const MCP_AUTH_TYPES: readonly ["none", "bearer", "headers", "oauth", "github_app"];
3
+ /** `per_run`: the server keeps no credential; each run's caller hands one with the run (mcp_auth), held for that run alone. */
4
+ export declare const MCP_AUTH_TYPES: readonly ["none", "bearer", "headers", "oauth", "github_app", "per_run"];
4
5
  /** Why a saved credential can't be used for a run's calls, each with its own remedy and no other, as the model reads it
5
6
  * after "The MCP server <name>'s credential can't be used right now: " (mcp-gateway.ts). The one place they are said. */
6
7
  export declare const UNUSABLE: {
@@ -12,6 +13,8 @@ export declare const UNUSABLE: {
12
13
  readonly silent: "the sign-in server didn't answer; try again";
13
14
  /** An access token past its expiry whose refresh the address check refused unsent (mcp-oauth.ts), followed by its words. */
14
15
  readonly blocked: "its sign-in server's address is refused here";
16
+ /** A per_run server's run that was handed no credential for it (mcp_auth), or whose credential was erased at its end. */
17
+ readonly perRunMissing: "this server takes its credential from each run, and this run was handed none: its caller sends one as mcp_auth when it starts the run or sends it a message";
15
18
  };
16
19
  export declare const REFRESH_MARGIN_MS: number;
17
20
  /** How long an access token given with no expiry is taken to last: it is refreshed within the margin of then. */
@@ -82,6 +85,10 @@ export declare function pricesOf(value: unknown, issues: InputIssue[]): McpPrice
82
85
  export declare function urlOf(value: unknown, issues: InputIssue[]): URL | undefined;
83
86
  /** The body's auth: its type and, when it sends one, its credential as the headers it becomes. */
84
87
  export declare function authOf(value: unknown, issues: InputIssue[]): Auth | undefined;
88
+ /** A run's `mcp_auth` (POST /runs, POST /agents/{id}/runs, POST /runs/{id}/messages): the headers each named per_run
89
+ * server is called with for this run, `{"<server>": {"headers": {...}}}`. Checked for shape here; that each name is a
90
+ * saved per_run server is the caller's check. Undefined when absent or wrong (with its issues). */
91
+ export declare function mcpAuthOf(value: unknown, issues: InputIssue[]): Record<string, HeaderMap> | undefined;
85
92
  /** The OAuth scope list a sign-in body may send: 1 to 32 OAuth scopes. */
86
93
  export declare const scopesValid: (scopes: unknown) => boolean;
87
94
  /** The longest an OAuth client id or secret a sign-in body may send. */