@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45

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 (388) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +580 -320
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +92 -22
  28. package/dist/composio-preset.d.ts +4 -3
  29. package/dist/composio-preset.js +81 -11
  30. package/dist/composio-triggers.d.ts +34 -2
  31. package/dist/composio-triggers.js +261 -31
  32. package/dist/computer-attach.d.ts +40 -5
  33. package/dist/computer-attach.js +130 -15
  34. package/dist/computer-keys.d.ts +3 -0
  35. package/dist/computer-keys.js +7 -1
  36. package/dist/computer-live.js +3 -2
  37. package/dist/computer-lost.d.ts +11 -0
  38. package/dist/computer-lost.js +19 -0
  39. package/dist/computer-record.d.ts +10 -2
  40. package/dist/computer-record.js +50 -18
  41. package/dist/computer-setting.d.ts +1 -0
  42. package/dist/computer-setting.js +2 -2
  43. package/dist/computers.d.ts +21 -10
  44. package/dist/computers.js +39 -28
  45. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  46. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decisions.d.ts +1 -1
  49. package/dist/dial-relay.d.ts +29 -0
  50. package/dist/dial-relay.js +94 -0
  51. package/dist/email/tools.js +10 -5
  52. package/dist/env-proxy.d.ts +2 -0
  53. package/dist/env-proxy.js +35 -0
  54. package/dist/errors.d.ts +4 -1
  55. package/dist/errors.js +10 -4
  56. package/dist/faux-computers.d.ts +8 -2
  57. package/dist/faux-computers.js +83 -6
  58. package/dist/harness-archive.d.ts +67 -0
  59. package/dist/harness-archive.js +177 -0
  60. package/dist/harness-goose.d.ts +34 -0
  61. package/dist/harness-goose.js +87 -0
  62. package/dist/harness-install.d.ts +21 -0
  63. package/dist/harness-install.js +24 -11
  64. package/dist/harness-opencode/adapter.js +1 -1
  65. package/dist/harness-table.d.ts +59 -3
  66. package/dist/harness-table.js +119 -14
  67. package/dist/harness.d.ts +17 -1
  68. package/dist/harness.js +22 -11
  69. package/dist/host.d.ts +12 -10
  70. package/dist/host.js +19 -16
  71. package/dist/import-worker.d.ts +3 -0
  72. package/dist/import-worker.js +7 -5
  73. package/dist/import.d.ts +22 -1
  74. package/dist/import.js +141 -28
  75. package/dist/key-check.js +3 -0
  76. package/dist/learn/audit.d.ts +6 -6
  77. package/dist/learn/audit.js +3 -7
  78. package/dist/learn/check.d.ts +26 -89
  79. package/dist/learn/check.js +58 -336
  80. package/dist/learn/commit.d.ts +63 -90
  81. package/dist/learn/commit.js +124 -316
  82. package/dist/learn/compile.d.ts +53 -50
  83. package/dist/learn/compile.js +88 -103
  84. package/dist/learn/corrections.d.ts +13 -0
  85. package/dist/learn/corrections.js +23 -0
  86. package/dist/learn/delete.d.ts +17 -0
  87. package/dist/learn/delete.js +42 -0
  88. package/dist/learn/folder.d.ts +35 -47
  89. package/dist/learn/folder.js +118 -134
  90. package/dist/learn/index.d.ts +3 -5
  91. package/dist/learn/index.js +6 -9
  92. package/dist/learn/learning.sh +45 -15
  93. package/dist/learn/promote.d.ts +20 -2
  94. package/dist/learn/promote.js +17 -4
  95. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
  96. package/dist/learn/{skills.js → workflow-draft.js} +65 -59
  97. package/dist/learn/workflow-nodes.d.ts +22 -1
  98. package/dist/learn/workflow-nodes.js +29 -10
  99. package/dist/learned-workflow.js +2 -2
  100. package/dist/learning-cost.d.ts +127 -13
  101. package/dist/learning-cost.js +142 -10
  102. package/dist/learning-routes.d.ts +99 -170
  103. package/dist/learning-routes.js +199 -420
  104. package/dist/learning-run.d.ts +19 -40
  105. package/dist/learning-run.js +23 -93
  106. package/dist/learning-setting.d.ts +4 -4
  107. package/dist/learning-setting.js +6 -6
  108. package/dist/learning-words.d.ts +28 -74
  109. package/dist/learning-words.js +64 -162
  110. package/dist/learning.d.ts +62 -393
  111. package/dist/learning.js +101 -651
  112. package/dist/listen-first.d.ts +30 -0
  113. package/dist/listen-first.js +115 -0
  114. package/dist/live-reach.d.ts +25 -2
  115. package/dist/live-reach.js +46 -4
  116. package/dist/llms.txt +2 -1
  117. package/dist/local-models.d.ts +3 -11
  118. package/dist/local-models.js +5 -6
  119. package/dist/mcp-servers-store.d.ts +16 -16
  120. package/dist/model-form.js +6 -5
  121. package/dist/model.d.ts +12 -4
  122. package/dist/model.js +41 -16
  123. package/dist/native/binding.js +1 -1
  124. package/dist/native/connection.js +1 -1
  125. package/dist/native/discovery.js +1 -1
  126. package/dist/native/instructions.d.ts +3 -0
  127. package/dist/native/instructions.js +5 -3
  128. package/dist/native/remote-worker-bridge.js +9 -43
  129. package/dist/native/remote.d.ts +8 -15
  130. package/dist/native/remote.js +3 -3
  131. package/dist/native/schema.js +1 -1
  132. package/dist/native/types.d.ts +2 -2
  133. package/dist/openapi.js +375 -347
  134. package/dist/owner.d.ts +8 -0
  135. package/dist/owner.js +11 -0
  136. package/dist/paid-calls.d.ts +14 -0
  137. package/dist/paid-calls.js +31 -1
  138. package/dist/particle-provider.d.ts +11 -0
  139. package/dist/particle-provider.js +135 -0
  140. package/dist/place.d.ts +8 -3
  141. package/dist/place.js +13 -9
  142. package/dist/port-models.d.ts +12 -4
  143. package/dist/port-models.js +28 -11
  144. package/dist/print.d.ts +27 -0
  145. package/dist/print.js +21 -0
  146. package/dist/provider.d.ts +7 -0
  147. package/dist/provider.js +30 -2
  148. package/dist/reflect-range.js +2 -3
  149. package/dist/run-launch.d.ts +14 -28
  150. package/dist/run-launch.js +9 -12
  151. package/dist/run-learning-served.d.ts +16 -90
  152. package/dist/run-listing.d.ts +34 -0
  153. package/dist/run-listing.js +128 -0
  154. package/dist/run-model-key.d.ts +64 -0
  155. package/dist/run-model-key.js +147 -0
  156. package/dist/run-timeline-served.js +5 -3
  157. package/dist/run-trace.d.ts +97 -0
  158. package/dist/run-trace.js +253 -0
  159. package/dist/run-view.d.ts +15 -0
  160. package/dist/run-view.js +9 -0
  161. package/dist/runnable.js +2 -1
  162. package/dist/runner/adapter-loop.d.ts +14 -6
  163. package/dist/runner/adapter-loop.js +25 -14
  164. package/dist/runner/adapter-run-spec.d.ts +22 -7
  165. package/dist/runner/adapter-run-spec.js +130 -77
  166. package/dist/runner/adapters/index.d.ts +4 -2
  167. package/dist/runner/adapters/index.js +35 -4
  168. package/dist/runner/adapters/pi.d.ts +4 -12
  169. package/dist/runner/adapters/pi.js +2 -2
  170. package/dist/runner/audit.d.ts +5 -1
  171. package/dist/runner/audit.js +31 -12
  172. package/dist/runner/beside.d.ts +7 -2
  173. package/dist/runner/beside.js +41 -9
  174. package/dist/runner/claim-secrets.d.ts +66 -1
  175. package/dist/runner/claim-secrets.js +136 -3
  176. package/dist/runner/cli-run-spec.d.ts +2 -1
  177. package/dist/runner/cli-run-spec.js +82 -59
  178. package/dist/runner/commands.d.ts +3 -6
  179. package/dist/runner/conformance/harness.d.ts +6 -0
  180. package/dist/runner/conformance/harness.js +16 -5
  181. package/dist/runner/dispatch.d.ts +2 -2
  182. package/dist/runner/end-of-run.d.ts +6 -14
  183. package/dist/runner/end-of-run.js +8 -33
  184. package/dist/runner/feedback-round.d.ts +5 -4
  185. package/dist/runner/feedback-round.js +14 -10
  186. package/dist/runner/github-app.js +3 -1
  187. package/dist/runner/harness-loops.d.ts +0 -8
  188. package/dist/runner/harness-loops.js +30 -56
  189. package/dist/runner/held.d.ts +170 -0
  190. package/dist/runner/held.js +57 -0
  191. package/dist/runner/journal-kinds.d.ts +7 -3
  192. package/dist/runner/journal-kinds.js +2 -3
  193. package/dist/runner/learned-first.d.ts +40 -0
  194. package/dist/runner/learned-first.js +32 -0
  195. package/dist/runner/learning-end.d.ts +77 -66
  196. package/dist/runner/learning-end.js +250 -299
  197. package/dist/runner/learning-seed.d.ts +15 -33
  198. package/dist/runner/learning-seed.js +24 -45
  199. package/dist/runner/loop-contract.d.ts +8 -3
  200. package/dist/runner/loop-contract.js +4 -0
  201. package/dist/runner/loop.js +6 -2
  202. package/dist/runner/main.d.ts +18 -9
  203. package/dist/runner/main.js +82 -22
  204. package/dist/runner/mcp-run.d.ts +11 -0
  205. package/dist/runner/mcp-run.js +67 -0
  206. package/dist/runner/memory-claim.d.ts +14 -6
  207. package/dist/runner/memory-claim.js +18 -9
  208. package/dist/runner/model-route.d.ts +7 -4
  209. package/dist/runner/model-route.js +22 -10
  210. package/dist/runner/native-loop.d.ts +0 -7
  211. package/dist/runner/native-loop.js +9 -101
  212. package/dist/runner/promotion.d.ts +13 -6
  213. package/dist/runner/promotion.js +63 -17
  214. package/dist/runner/reflect-hook.d.ts +64 -91
  215. package/dist/runner/reflect-hook.js +112 -206
  216. package/dist/runner/run-channel.d.ts +43 -0
  217. package/dist/runner/run-channel.js +467 -0
  218. package/dist/runner/run-child-host.d.ts +169 -0
  219. package/dist/runner/run-child-host.js +1222 -0
  220. package/dist/runner/run-child.d.ts +1 -0
  221. package/dist/runner/run-child.js +254 -0
  222. package/dist/runner/run-errors.d.ts +2 -0
  223. package/dist/runner/run-errors.js +20 -0
  224. package/dist/runner/runner.js +58 -9
  225. package/dist/runner/sdk-ask.d.ts +78 -0
  226. package/dist/runner/sdk-ask.js +158 -0
  227. package/dist/runner/sdk-loop.d.ts +2 -4
  228. package/dist/runner/sdk-loop.js +29 -49
  229. package/dist/runner/store-secrets.d.ts +5 -3
  230. package/dist/runner/store-secrets.js +14 -6
  231. package/dist/runner/workflow-first.d.ts +5 -0
  232. package/dist/runner/workflow-first.js +4 -0
  233. package/dist/runner/workflow-spec.js +17 -4
  234. package/dist/runs-over-store.d.ts +21 -32
  235. package/dist/runs-over-store.js +44 -41
  236. package/dist/sdk/runs.d.ts +6 -11
  237. package/dist/sdk/runs.js +20 -41
  238. package/dist/sdk/schema.js +3 -4
  239. package/dist/sdk/workflows.d.ts +1 -1
  240. package/dist/seal-key.d.ts +5 -0
  241. package/dist/seal-key.js +7 -0
  242. package/dist/secrets.d.ts +3 -0
  243. package/dist/secrets.js +16 -3
  244. package/dist/server.d.ts +119 -83
  245. package/dist/server.js +1121 -419
  246. package/dist/sign-ins-store.d.ts +8 -0
  247. package/dist/sign-ins-store.js +36 -1
  248. package/dist/skills.js +1 -1
  249. package/dist/store/index.d.ts +3 -3
  250. package/dist/store/index.js +2 -2
  251. package/dist/store/journal/storage.js +3 -0
  252. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  253. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  254. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  255. package/dist/store/schema.d.ts +53 -4
  256. package/dist/store/schema.js +137 -6
  257. package/dist/store/seal.d.ts +20 -2
  258. package/dist/store/seal.js +24 -8
  259. package/dist/store/sqlite/connection.d.ts +2 -0
  260. package/dist/store/sqlite/connection.js +3 -1
  261. package/dist/store/sqlite/run-launch.d.ts +4 -1
  262. package/dist/store/sqlite/run-launch.js +12 -0
  263. package/dist/store/sqlite/run-patch.d.ts +0 -17
  264. package/dist/store/sqlite/run-patch.js +4 -33
  265. package/dist/store/sqlite/store.d.ts +3 -2
  266. package/dist/store/sqlite/store.js +360 -75
  267. package/dist/store/sqlite/worker.js +25 -0
  268. package/dist/store/store.d.ts +231 -39
  269. package/dist/store/store.js +25 -3
  270. package/dist/store-reads/analytics.js +11 -1
  271. package/dist/store-reads/learning.d.ts +131 -194
  272. package/dist/store-reads/learning.js +292 -301
  273. package/dist/store-reads/loop.d.ts +0 -1
  274. package/dist/store-reads/loop.js +1 -1
  275. package/dist/store-reads/stats.js +13 -3
  276. package/dist/store-view.d.ts +34 -2
  277. package/dist/store-view.js +108 -41
  278. package/dist/telemetry.d.ts +59 -0
  279. package/dist/telemetry.js +153 -0
  280. package/dist/template-eval.d.ts +3 -6
  281. package/dist/template-eval.js +22 -36
  282. package/dist/templates.d.ts +2 -1
  283. package/dist/templates.js +6 -3
  284. package/dist/timeline/index.d.ts +1 -1
  285. package/dist/timeline/index.js +1 -1
  286. package/dist/timeline/timeline.d.ts +5 -1
  287. package/dist/timeline/timeline.js +16 -0
  288. package/dist/tool-gate.d.ts +0 -7
  289. package/dist/tool-gate.js +1 -15
  290. package/dist/tool-keys-store.d.ts +1 -1
  291. package/dist/tool-keys.d.ts +6 -4
  292. package/dist/tool-keys.js +12 -6
  293. package/dist/tool-plane.d.ts +12 -12
  294. package/dist/tools.d.ts +13 -13
  295. package/dist/tools.js +29 -9
  296. package/dist/trigger-adapter.d.ts +3 -0
  297. package/dist/trigger-adapters.d.ts +4 -0
  298. package/dist/trigger-adapters.js +13 -0
  299. package/dist/trigger-composio.d.ts +58 -1
  300. package/dist/trigger-composio.js +160 -6
  301. package/dist/triggers.d.ts +64 -5
  302. package/dist/triggers.js +141 -17
  303. package/dist/validate.d.ts +11 -7
  304. package/dist/validate.js +9 -8
  305. package/dist/webhooks.d.ts +4 -1
  306. package/dist/webhooks.js +11 -4
  307. package/dist/workspace/agent-computer.d.ts +2 -0
  308. package/dist/workspace/agent-computer.js +2 -0
  309. package/dist/workspace/archil-claim.d.ts +7 -0
  310. package/dist/workspace/archil-claim.js +29 -0
  311. package/dist/workspace/archil.d.ts +9 -1
  312. package/dist/workspace/archil.js +165 -3
  313. package/dist/workspace/attach.d.ts +3 -1
  314. package/dist/workspace/attach.js +2 -0
  315. package/dist/workspace/attached-computers.d.ts +16 -5
  316. package/dist/workspace/attached-computers.js +25 -9
  317. package/dist/workspace/computer-deps.js +1 -1
  318. package/dist/workspace/computer-for-claim.d.ts +22 -8
  319. package/dist/workspace/computer-for-claim.js +339 -46
  320. package/dist/workspace/computer-hold.js +2 -1
  321. package/dist/workspace/computer-kept.d.ts +11 -1
  322. package/dist/workspace/computer-kept.js +24 -3
  323. package/dist/workspace/resolve-computer.d.ts +41 -21
  324. package/dist/workspace/resolve-computer.js +172 -64
  325. package/dist/workspace/revision-skills.d.ts +1 -2
  326. package/dist/workspace/revision-skills.js +3 -4
  327. package/dist/workspace/run-workspace.d.ts +1 -1
  328. package/dist/workspace/run-workspace.js +5 -0
  329. package/dist/workspace/synced-folder.d.ts +85 -0
  330. package/dist/workspace/synced-folder.js +230 -0
  331. package/dist/workspace/workspace.d.ts +4 -0
  332. package/launcher/agentrun-serve +1 -1
  333. package/package.json +10 -9
  334. package/templates/README.md +7 -7
  335. package/templates/inbound-lead/agent.md +3 -3
  336. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  337. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  338. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  339. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  340. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  341. package/templates/inbound-lead/lead.schema.json +6 -5
  342. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  343. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  344. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  345. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  346. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  347. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  348. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  349. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  350. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  351. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  352. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  353. package/dist/console/assets/index-Bz6IWncl.js +0 -711
  354. package/dist/learn/grade.d.ts +0 -138
  355. package/dist/learn/grade.js +0 -682
  356. package/dist/learn/notes.d.ts +0 -81
  357. package/dist/learn/notes.js +0 -178
  358. package/dist/learn/reflect.d.ts +0 -77
  359. package/dist/learn/reflect.js +0 -228
  360. package/dist/learn/relevance.d.ts +0 -24
  361. package/dist/learn/relevance.js +0 -91
  362. package/dist/learn/seed-check.d.ts +0 -74
  363. package/dist/learn/seed-check.js +0 -103
  364. package/dist/learning-batch.d.ts +0 -291
  365. package/dist/learning-batch.js +0 -600
  366. package/dist/learning-evals.d.ts +0 -33
  367. package/dist/learning-evals.js +0 -98
  368. package/dist/native/context.d.ts +0 -6
  369. package/dist/native/context.js +0 -22
  370. package/dist/propose.d.ts +0 -52
  371. package/dist/propose.js +0 -224
  372. package/dist/runner/learning-ask.d.ts +0 -47
  373. package/dist/runner/learning-ask.js +0 -128
  374. package/dist/runner/learning-dispatch.d.ts +0 -45
  375. package/dist/runner/learning-dispatch.js +0 -99
  376. package/dist/runner/learning-factory.d.ts +0 -16
  377. package/dist/runner/learning-factory.js +0 -50
  378. package/dist/runner/learning-loop.d.ts +0 -273
  379. package/dist/runner/learning-loop.js +0 -521
  380. package/dist/usage.d.ts +0 -11
  381. package/dist/usage.js +0 -11
  382. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  383. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  384. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  385. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  386. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  387. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  388. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -1,6 +1,5 @@
1
1
  import { LEARNING_LABEL } from "./learning.js";
2
2
  import { said } from "./learning-words.js";
3
- import { askedForDryRun } from "./learn/reflect.js";
4
3
  import { askedForCompile } from "./learn/compile.js";
5
4
  /** The run asked its end-of-run turn and has not ended since. */
6
5
  export const reflecting = (run) => run.meta.reflect !== undefined && run.meta.reflect.until === undefined;
@@ -25,7 +24,7 @@ export function labelled(reflect, rows) {
25
24
  return rows.map((row) => (!reflects(reflect, row.id) ? row : {
26
25
  ...row, agent_label: LEARNING_LABEL,
27
26
  ...(row.kind === "final_answer" ? { kind: "text_block" } : {}),
28
- // The turn asked again for a draft whose dry run failed says so; every other message of the turn is its ask.
29
- ...(row.kind === "user_message" ? ((words) => ({ summary: words, text: words }))(askedForDryRun(row.text) ? said.askedDryRun : askedForCompile(row.text) === "again" ? said.askedCompileAgain : askedForCompile(row.text) ? said.askedCompile : said.asked) : {}),
27
+ // The compile turn's ask, or its ask again once the checks sent a draft back; any other message of the turn, its own.
28
+ ...(row.kind === "user_message" ? ((words) => ({ summary: words, text: words }))(askedForCompile(row.text) === "again" ? said.askedCompileAgain : askedForCompile(row.text) ? said.askedCompile : said.asked) : {}),
30
29
  }));
31
30
  }
@@ -7,9 +7,9 @@ import { type Json } from "./validate.js";
7
7
  import type { Place } from "./workspace/place.js";
8
8
  /** What a run is launched with: everything its runner needs to build the run's spec at its claim, nothing derived later.
9
9
  * The server writes it once at start; the runner reads it at each claim (its claim rebuilds the run from the store, this
10
- * body included). `harness` picks the loop's adapter (a built-in learning run names "learning"; absent, the revision's
11
- * harness is used); `input` is the start request's body for a person's or a trigger's run, or an object a built-in run
12
- * names (a learning run's `{ runId }`). `model`, `plane`, `approvers`, `documents` and `boxAllow` are the per-run choices
10
+ * body included). `harness` picks the loop's adapter (absent, the revision's harness is used); `input` is the start
11
+ * request's body for a person's or a trigger's run, or an object a built-in run names. `model`, `plane`, `approvers`,
12
+ * `documents` and `boxAllow` are the per-run choices
13
13
  * the old path recomputed; here they are pinned at start, and optional (a built-in run may name none). */
14
14
  export interface RunLaunch {
15
15
  readonly sdk?: {
@@ -27,7 +27,7 @@ export interface RunLaunch {
27
27
  * repository (run-repo.ts); a github trigger's run has none here, its event names it. */
28
28
  readonly repo?: string;
29
29
  readonly place: Place;
30
- /** The loop's adapter, when not the revision's: a built-in learning run names "learning". */
30
+ /** The loop's adapter, when not the revision's (an SDK run names "sdk"). */
31
31
  readonly harness?: string;
32
32
  /** The run's model, pinned at start. */
33
33
  readonly model?: {
@@ -51,33 +51,19 @@ export interface RunLaunch {
51
51
  * runner copies them into the run's work/inputs/ at its claim, as the old start copied them before the process ran. */
52
52
  readonly files?: readonly string[];
53
53
  /** The run's learning start, when its agent learns and the server's learning is on, decided once here so the runner reads
54
- * no learning folder or git: `given`, the notes its # Learned section names (each `{file, name}`, as /runs/{id}/learning
55
- * shows them); `seed`, the learning commit's sha (or null when the seed could not be read); and `section`, the exact
56
- * # Learned text to lay into the prompt for those notes (what the old layLearned laid), within the learning budget; and
57
- * `seedNotes`, the count of all notes in the seed before the budget picked `given` (present with a read seed; absent when
58
- * the seed could not be read); `notesLeftOut`, the files of the active notes the section names in no way, over the
59
- * learning budget, which its claim says in the run's log, absent when none; `skills`, the names of the learned skills the seed offers the run (each active one that
60
- * fits a run's skill budget at all; its claim lays them), absent when none; `workflows`, the names of the learned
61
- * workflows the seed offers its learned_workflow tool (chooseWorkflows), absent when none; `notesOnly`, a run of a
62
- * revision that says `learning: "notes"`: given its notes and skills but never a learned workflow, and asked for no
63
- * workflow draft at its end; `gradeModel`, the model the
64
- * server names to grade what the run proposes (learning.ts gradeModelOf: --grade-model, else AGENTRUN_SERVE_GRADE_MODEL,
65
- * else AGENT_MODEL_STRONG), absent when it names none and the agent's own grades it; and `seedFailed`, why it starts with
66
- * nothing learned when it does (SeedFailed); `use`, a run started with `learning: "use"` (learning.ts RUN_LEARNING_USE):
67
- * it starts from all of the above and keeps nothing, never asked its end-of-run turn. Absent when the run does not learn. */
54
+ * no learning folder or git: `seed`, the learning commit's sha (or null when the seed could not be read); `section`,
55
+ * the exact # Learned text to lay into the prompt (its owner's corrections, learning.ts learnedSection); `workflows`,
56
+ * the names of the learned workflows the seed offers the run (chooseWorkflows), absent when none; `noWorkflows`, a run
57
+ * never answered by a learned workflow and asked for no workflow draft at its end (a native run, an SDK run with no
58
+ * workflow binding); `model`, the model an SDK run's compile turn is asked on (its agent's own); `seedFailed`, why it
59
+ * starts with nothing learned when it does (SeedFailed); `use`, a run started with `learning: "use"` (learning.ts
60
+ * RUN_LEARNING_USE): it starts from all of the above and keeps nothing. Absent when the run does not learn. */
68
61
  readonly learning?: {
69
- readonly given: readonly {
70
- readonly file: string;
71
- readonly name: string;
72
- }[];
73
62
  readonly seed: string | null;
74
63
  readonly section: string;
75
- readonly seedNotes?: number;
76
- readonly notesLeftOut?: readonly string[];
77
- readonly skills?: readonly string[];
78
64
  readonly workflows?: readonly string[];
79
- readonly notesOnly?: true;
80
- readonly gradeModel?: string;
65
+ readonly noWorkflows?: true;
66
+ readonly model?: string;
81
67
  readonly seedFailed?: SeedFailed;
82
68
  readonly use?: true;
83
69
  };
@@ -129,7 +115,7 @@ export declare function launchBody(launch: RunLaunch): Json;
129
115
  /** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
130
116
  * undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
131
117
  export declare function readLaunchBody(stored: unknown): RunLaunch | undefined;
132
- /** The run's learning start (its given notes, its seed sha and its # Learned section), read from one place by learning's
118
+ /** The run's learning start (its seed sha, its # Learned section and its learned workflows), read from one place by learning's
133
119
  * routes and the runner; undefined when the run does not learn. */
134
120
  export declare const learningStartOf: (launch: RunLaunch) => RunLaunch["learning"];
135
121
  /** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
@@ -67,7 +67,7 @@ export function launchBody(launch) {
67
67
  ...(launch.boxAllow !== undefined ? { box_allow: launch.boxAllow } : {}),
68
68
  ...(launch.boxAllowSet ? { box_allow_set: true } : {}),
69
69
  ...(launch.files?.length ? { files: launch.files } : {}),
70
- ...(launch.learning ? { learning: { given: launch.learning.given.map((note) => ({ file: note.file, name: note.name })), seed: launch.learning.seed, section: launch.learning.section, ...(launch.learning.seedNotes !== undefined ? { seedNotes: launch.learning.seedNotes } : {}), ...(launch.learning.notesLeftOut?.length ? { notesLeftOut: [...launch.learning.notesLeftOut] } : {}), ...(launch.learning.skills?.length ? { skills: [...launch.learning.skills] } : {}), ...(launch.learning.notesOnly ? { notesOnly: true } : {}), ...(launch.learning.workflows?.length ? { workflows: [...launch.learning.workflows] } : {}), ...(launch.learning.gradeModel ? { gradeModel: launch.learning.gradeModel } : {}), ...(launch.learning.seedFailed ? { seedFailed: launch.learning.seedFailed } : {}), ...(launch.learning.use ? { use: true } : {}) } } : {}),
70
+ ...(launch.learning ? { learning: { seed: launch.learning.seed, section: launch.learning.section, ...(launch.learning.workflows?.length ? { workflows: [...launch.learning.workflows] } : {}), ...(launch.learning.noWorkflows ? { noWorkflows: true } : {}), ...(launch.learning.model ? { model: launch.learning.model } : {}), ...(launch.learning.seedFailed ? { seedFailed: launch.learning.seedFailed } : {}), ...(launch.learning.use ? { use: true } : {}) } } : {}),
71
71
  ...(launch.workflowFirst === false ? { workflow_first: false } : {}),
72
72
  ...(launch.replay ? { replay: { of: launch.replay.of, workflow: launch.replay.workflow, digest: launch.replay.digest } } : {}),
73
73
  ...(launch.audit ? { audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest } } : {}),
@@ -78,19 +78,16 @@ export function launchBody(launch) {
78
78
  ...(launch.hold ? { hold: { minutes: launch.hold.minutes } } : {}),
79
79
  };
80
80
  }
81
- /** The learning start a launch body names, as read back: its given notes (each {file, name}), its seed sha, its # Learned
82
- * section text, the learned skills and workflows it was offered, its grade model, why its seed failed and whether it only
83
- * uses them (`use`), or undefined
84
- * when the body names none (a run that does not learn). */
81
+ /** The learning start a launch body names, as read back: its seed sha, its # Learned section text, the learned workflows
82
+ * it was offered, its compile model, why its seed failed and whether it only uses them (`use`), or undefined when the
83
+ * body names none (a run that does not learn). */
85
84
  function readLearning(value) {
86
85
  if (!isObject(value))
87
86
  return undefined;
88
- const given = Array.isArray(value.given) ? value.given.flatMap((note) => (isObject(note) && typeof note.file === "string" && typeof note.name === "string" ? [{ file: note.file, name: note.name }] : [])) : [];
89
87
  const seed = typeof value.seed === "string" ? value.seed : null;
90
88
  const section = typeof value.section === "string" ? value.section : "";
91
- const names = (list) => (Array.isArray(list) ? list.filter((name) => typeof name === "string") : []);
92
- const [skills, workflows, notesLeftOut] = [names(value.skills), names(value.workflows), names(value.notesLeftOut)];
93
- return { given, seed, section, ...(typeof value.seedNotes === "number" ? { seedNotes: value.seedNotes } : {}), ...(notesLeftOut.length ? { notesLeftOut } : {}), ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}), ...(value.notesOnly === true ? { notesOnly: true } : {}), ...(typeof value.gradeModel === "string" && value.gradeModel !== "" ? { gradeModel: value.gradeModel } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}), ...(value.use === true ? { use: true } : {}) };
89
+ const workflows = Array.isArray(value.workflows) ? value.workflows.filter((name) => typeof name === "string") : [];
90
+ return { seed, section, ...(workflows.length ? { workflows } : {}), ...(value.noWorkflows === true ? { noWorkflows: true } : {}), ...(typeof value.model === "string" && value.model !== "" ? { model: value.model } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}), ...(value.use === true ? { use: true } : {}) };
94
91
  }
95
92
  /** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
96
93
  * undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
@@ -122,7 +119,7 @@ export function readLaunchBody(stored) {
122
119
  ...(boxAllow !== undefined ? { boxAllow } : {}),
123
120
  ...(stored.box_allow_set === true ? { boxAllowSet: true } : {}),
124
121
  ...(Array.isArray(stored.files) && stored.files.every((id) => typeof id === "string") ? { files: stored.files } : {}),
125
- ...(stored.learning !== undefined ? { learning: readLearning(stored.learning) ?? { given: [], seed: null, section: "" } } : {}),
122
+ ...(stored.learning !== undefined ? { learning: readLearning(stored.learning) ?? { seed: null, section: "" } } : {}),
126
123
  ...(stored.workflow_first === false ? { workflowFirst: false } : {}),
127
124
  ...(readReplay(stored.replay) ? { replay: readReplay(stored.replay) } : {}),
128
125
  ...(readReplay(stored.audit) ? { audit: readReplay(stored.audit) } : {}),
@@ -133,11 +130,11 @@ export function readLaunchBody(stored) {
133
130
  ...(isObject(stored.hold) && typeof stored.hold.minutes === "number" ? { hold: { minutes: stored.hold.minutes } } : {}),
134
131
  };
135
132
  }
136
- /** The run's learning start (its given notes, its seed sha and its # Learned section), read from one place by learning's
133
+ /** The run's learning start (its seed sha, its # Learned section and its learned workflows), read from one place by learning's
137
134
  * routes and the runner; undefined when the run does not learn. */
138
135
  export const learningStartOf = (launch) => launch.learning;
139
136
  /** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
140
- export const learningStartOfStored = (stored) => (stored === undefined ? undefined : readLearning(stored) ?? { given: [], seed: null, section: "" });
137
+ export const learningStartOfStored = (stored) => (stored === undefined ? undefined : readLearning(stored) ?? { seed: null, section: "" });
141
138
  const SEED_FAILURES = ["unreadable", "not_copied"];
142
139
  /** A learning start with no seed (no commit of main, runs-over-store.ts learningStartFor): the run learns nothing, is
143
140
  * never asked what to keep, and so is never told it learns. Why is its `seedFailed`, when its start records one. */
@@ -7,24 +7,15 @@ export declare function servedRunLearning(deps: {
7
7
  signIns?: SignInReader;
8
8
  statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
9
9
  }, store: Store, runId: string): Promise<{
10
+ run: string;
11
+ state: "dropped" | "merged" | "seeded" | "reflecting";
12
+ reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
13
+ detail: string | null;
14
+ at: string;
15
+ workflows: import("./learning.js").LearnedFile[];
16
+ corrections: number;
10
17
  seed: string | null;
11
18
  merged: string | null;
12
- pending: {
13
- file: string;
14
- name: string;
15
- }[];
16
- verdict: {
17
- merge: boolean;
18
- reason: string;
19
- items: {
20
- why: string;
21
- question?: string | undefined;
22
- origin?: "run" | "you" | undefined;
23
- pending?: boolean | undefined;
24
- file: string;
25
- keep: boolean;
26
- }[];
27
- } | null;
28
19
  problems: {
29
20
  detail: string;
30
21
  path?: string | undefined;
@@ -32,7 +23,6 @@ export declare function servedRunLearning(deps: {
32
23
  }[];
33
24
  compiled: {
34
25
  workflow: string;
35
- from_notes: string[];
36
26
  attempts: {
37
27
  ok: boolean;
38
28
  errors: string[];
@@ -41,63 +31,34 @@ export declare function servedRunLearning(deps: {
41
31
  promoted: boolean | null;
42
32
  } | null;
43
33
  draft_errors: string[];
44
- cost_usd: {
45
- grade: number | null;
46
- };
47
- tokens: {
48
- grade: import("./learning.js").Tokens | null;
49
- };
50
34
  used: {
51
- skills: {
52
- name: string;
53
- read: boolean;
54
- }[];
55
35
  workflows: {
56
36
  name: string;
57
37
  calls: number;
58
38
  failed: number;
59
39
  }[];
60
40
  };
61
- given?: import("./learning.js").NoteUsed[];
62
- read?: import("./learning.js").NoteUsed[];
63
- learned?: import("./learning.js").NoteLearned[];
64
- skills?: import("./learning.js").LearnedFile[];
65
- workflows?: import("./learning.js").LearnedFile[];
66
- run: string;
67
- state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
68
- reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
69
- detail: string | null;
70
- at: string;
71
41
  } | {
72
42
  graded: {
73
43
  workflow: string | null;
74
44
  feedback_status: "running" | "ended" | "not_run" | null;
75
45
  source: "feedback" | "eval";
76
46
  graded_at: string;
77
- path: "agent" | "workflow" | "handed_back" | "replay" | "audit";
47
+ path: "agent" | "workflow" | "replay" | "handed_back" | "audit";
78
48
  workflow_digest: string | null;
79
- feedback: "look_back" | null;
49
+ feedback: "correction" | null;
80
50
  run_id: string;
81
51
  correct: boolean;
82
52
  };
53
+ run: string;
54
+ state: "dropped" | "merged" | "seeded" | "reflecting";
55
+ reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
56
+ detail: string | null;
57
+ at: string;
58
+ workflows: import("./learning.js").LearnedFile[];
59
+ corrections: number;
83
60
  seed: string | null;
84
61
  merged: string | null;
85
- pending: {
86
- file: string;
87
- name: string;
88
- }[];
89
- verdict: {
90
- merge: boolean;
91
- reason: string;
92
- items: {
93
- why: string;
94
- question?: string | undefined;
95
- origin?: "run" | "you" | undefined;
96
- pending?: boolean | undefined;
97
- file: string;
98
- keep: boolean;
99
- }[];
100
- } | null;
101
62
  problems: {
102
63
  detail: string;
103
64
  path?: string | undefined;
@@ -105,7 +66,6 @@ export declare function servedRunLearning(deps: {
105
66
  }[];
106
67
  compiled: {
107
68
  workflow: string;
108
- from_notes: string[];
109
69
  attempts: {
110
70
  ok: boolean;
111
71
  errors: string[];
@@ -114,33 +74,13 @@ export declare function servedRunLearning(deps: {
114
74
  promoted: boolean | null;
115
75
  } | null;
116
76
  draft_errors: string[];
117
- cost_usd: {
118
- grade: number | null;
119
- };
120
- tokens: {
121
- grade: import("./learning.js").Tokens | null;
122
- };
123
77
  used: {
124
- skills: {
125
- name: string;
126
- read: boolean;
127
- }[];
128
78
  workflows: {
129
79
  name: string;
130
80
  calls: number;
131
81
  failed: number;
132
82
  }[];
133
83
  };
134
- given?: import("./learning.js").NoteUsed[];
135
- read?: import("./learning.js").NoteUsed[];
136
- learned?: import("./learning.js").NoteLearned[];
137
- skills?: import("./learning.js").LearnedFile[];
138
- workflows?: import("./learning.js").LearnedFile[];
139
- run: string;
140
- state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
141
- reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
142
- detail: string | null;
143
- at: string;
144
84
  } | null>;
145
85
  /** Run `runId`'s learning diff as GET /runs/{id}/learning/diff serves it (learning-routes.ts runDiffOverStore), cut as its
146
86
  * learning is, or ApiError forbidden for a withheld run. */
@@ -161,20 +101,6 @@ export declare function servedRunDiff(deps: {
161
101
  patch: string;
162
102
  withheld?: undefined;
163
103
  })[];
164
- } | {
165
- base: string;
166
- head: null;
167
- files: ({
168
- path: string;
169
- status: string;
170
- withheld: string;
171
- patch?: undefined;
172
- } | {
173
- path: string;
174
- status: string;
175
- patch: string;
176
- withheld?: undefined;
177
- })[];
178
104
  } | {
179
105
  base: string | null;
180
106
  head: null;
@@ -0,0 +1,34 @@
1
+ import type { RunListing, Store } from "./store/store.js";
2
+ import { type ViewDeps } from "./store-view.js";
3
+ /** How often an idle lister looks again (ms). */
4
+ export declare const LISTER_IDLE_MS = 400;
5
+ export interface Lister {
6
+ /** Starts its own passes: the first at once, then one each idle time (none with an idle time of Infinity). */
7
+ start(): void;
8
+ /** Builds run `runId`'s listing over `deps` and writes it at `mark`, the mark read before the build (Runs.putListing:
9
+ * not written when a write moved it since). A listing that read a workflow held for its owner's OK puts its agent's
10
+ * folder among those each pass reads, with the statuses this build read: an approval that lands after that read is
11
+ * then seen by the next pass, whoever built the listing (a pass, or a list). Undefined for an unknown run. */
12
+ build(runId: string, mark: number, deps: ViewDeps): Promise<{
13
+ listing: RunListing | undefined;
14
+ written: boolean;
15
+ }>;
16
+ /** Resolves once a pass finds nothing it may build now: every run's listing is current, but for a held run built within
17
+ * its rebuild time. For tests and benchmarks; the server never waits on it. */
18
+ settled(): Promise<void>;
19
+ /** The server's keys or settings changed: every failed run's listing (its error words) is marked behind before this
20
+ * resolves, so the next list builds it again. */
21
+ keysChanged(): Promise<void>;
22
+ /** A person changed agent `agentId`'s learning folder (a workflow approved, retired or restored): each of its runs
23
+ * whose listing read a workflow held for the owner's OK is marked behind before this resolves, so the next list says what
24
+ * the folder says now. A change made outside the server is read by the next pass. */
25
+ learningChanged(agentId: string): Promise<void>;
26
+ /** Stops after the pass under way. */
27
+ stop(): Promise<void>;
28
+ }
29
+ /** The lister over `store`, its passes not started (Lister.start): a list may build through it before they are. */
30
+ export declare function createLister(store: Store, depsOf: () => ViewDeps, options?: {
31
+ readonly log?: (line: string, error: Error) => void;
32
+ readonly now?: () => number;
33
+ readonly idleMs?: number;
34
+ }): Lister;
@@ -0,0 +1,128 @@
1
+ import { LISTING_HELD, LISTING_KEYED } from "./store/schema.js";
2
+ import { LISTING_RETRY_MS, listingOverStore } from "./store-view.js";
3
+ /** Most rows one read of a pass reads. */
4
+ const PASS_ROWS = 32;
5
+ /** How often an idle lister looks again (ms). */
6
+ export const LISTER_IDLE_MS = 400;
7
+ /** The least time between two builds of one run a runner holds (ms). */
8
+ const HELD_REBUILD_MS = 1_000;
9
+ /** The lister over `store`, its passes not started (Lister.start): a list may build through it before they are. */
10
+ export function createLister(store, depsOf, options = {}) {
11
+ const now = options.now ?? Date.now;
12
+ /** Infinity: no pass of its own, only those settled() asks for. */
13
+ const idleMs = options.idleMs ?? LISTER_IDLE_MS;
14
+ let closing = false;
15
+ let timer;
16
+ let pass = Promise.resolve(0);
17
+ /** A held run's last build: when, and how long it took. */
18
+ const built = new Map();
19
+ /** The agents with a run whose learning holds items for the owner's OK, with their folder's statuses as last read (for an
20
+ * agent first met in a build, as that build read them). */
21
+ const folders = new Map();
22
+ /** When each run whose view failed to build last failed. */
23
+ const failed = new Map();
24
+ /** The first pass marks behind every listing that read outside its run: the keys or folders may have moved while no
25
+ * server ran. */
26
+ let relistKeys = true;
27
+ const say = (what, error) => options.log?.(what, error instanceof Error ? error : new Error(String(error)));
28
+ /** Lister.build: the one build of a listing, a pass's or a list's. */
29
+ async function build(id, mark, deps) {
30
+ // The folder statuses this build read, by agent: the baseline a later pass compares against, never a read made after
31
+ // it, which a person's approval landing before this listing's write would already hold.
32
+ const read = new Map();
33
+ const statuses = deps.statuses;
34
+ const buildDeps = statuses ? { ...deps, statuses: async (agentId) => { const seen = await statuses(agentId); if (!read.has(agentId))
35
+ read.set(agentId, seen); return seen; } } : deps;
36
+ const listing = await listingOverStore(store, id, buildDeps);
37
+ const written = listing ? await store.runs.putListing(id, mark, listing) : false;
38
+ const agentId = listing ? String(listing.item.agent_id) : "";
39
+ if (listing && listing.flags & LISTING_HELD && !folders.has(agentId))
40
+ folders.set(agentId, read.get(agentId));
41
+ return { listing, written };
42
+ }
43
+ /** One pass: what moved outside the runs' writes, then each behind row this pass may build. The rows it built. */
44
+ async function once() {
45
+ const deps = depsOf();
46
+ if (relistKeys) {
47
+ relistKeys = false;
48
+ await store.runs.relist({ flags: LISTING_HELD | LISTING_KEYED });
49
+ }
50
+ for (const [agentId, seen] of folders) {
51
+ const statuses = await deps.statuses?.(agentId);
52
+ if (statuses === seen)
53
+ continue;
54
+ folders.set(agentId, statuses);
55
+ await store.runs.relist({ flags: LISTING_HELD, agentId });
56
+ }
57
+ // PASS_ROWS rows at a time, until a read builds one or none is left. A row passed over (a held run built within its
58
+ // rebuild time, a run whose view failed to build and waits for its retry, one written meanwhile) stays behind, so
59
+ // the next read starts after every row passed over so far: such rows never hold up the rows after them.
60
+ let count = 0;
61
+ let passed = 0;
62
+ for (;;) {
63
+ const rows = await store.runs.behind({ limit: PASS_ROWS, offset: passed });
64
+ for (const { id, mark, held } of rows) {
65
+ if (closing)
66
+ break;
67
+ const last = built.get(id);
68
+ if ((held && last && now() - last.at < Math.max(HELD_REBUILD_MS, 4 * last.ms)) || (failed.get(id) ?? -Infinity) > now() - LISTING_RETRY_MS) {
69
+ passed++;
70
+ continue;
71
+ }
72
+ const start = now();
73
+ let listing;
74
+ let written;
75
+ try {
76
+ ({ listing, written } = await build(id, mark, deps));
77
+ failed.delete(id);
78
+ }
79
+ catch (error) {
80
+ failed.set(id, now());
81
+ say("run_listing_unbuilt", error);
82
+ passed++;
83
+ continue;
84
+ }
85
+ if (!written)
86
+ passed++;
87
+ if (!listing)
88
+ continue;
89
+ count++;
90
+ if (held)
91
+ built.set(id, { at: now(), ms: now() - start });
92
+ else
93
+ built.delete(id);
94
+ }
95
+ if (closing || count > 0 || rows.length < PASS_ROWS)
96
+ return count;
97
+ }
98
+ }
99
+ /** A pass after the one under way: one at a time, whoever asks. */
100
+ const turn = () => (pass = pass.then(() => (closing ? 0 : once())).catch((error) => (say("run_listing_unbuilt", error), 0)));
101
+ function next(delay) {
102
+ if (closing || !Number.isFinite(idleMs))
103
+ return;
104
+ timer = setTimeout(() => void turn().then((count) => next(count > 0 ? 0 : idleMs)), delay);
105
+ timer.unref();
106
+ }
107
+ return {
108
+ start() {
109
+ next(0);
110
+ },
111
+ build,
112
+ async settled() {
113
+ while ((await turn()) > 0)
114
+ ;
115
+ },
116
+ async keysChanged() {
117
+ await store.runs.relist({ flags: LISTING_KEYED });
118
+ },
119
+ async learningChanged(agentId) {
120
+ await store.runs.relist({ flags: LISTING_HELD, agentId });
121
+ },
122
+ async stop() {
123
+ closing = true;
124
+ clearTimeout(timer);
125
+ await pass;
126
+ },
127
+ };
128
+ }
@@ -0,0 +1,64 @@
1
+ import { ApiError, type InputIssue } from "./errors.js";
2
+ /** The longest model key a run takes: a header value, never a document. */
3
+ export declare const MAX_MODEL_KEY_CHARS = 4096;
4
+ /** The origin of the model gateway a run's model key goes to (AGENT_MODEL_BASE_URL's, by the one base rule), or undefined
5
+ * when the server names none or one a key may not go to. */
6
+ export declare function runModelOrigin(env: NodeJS.ProcessEnv): string | undefined;
7
+ /** The variables a run's model key fills in a model route's env, for a gateway at `origin`: the gateway's key, and
8
+ * ANTHROPIC_API_KEY where ANTHROPIC_BASE_URL is that same gateway. */
9
+ export declare function runKeyNames(env: NodeJS.ProcessEnv, origin: string): string[];
10
+ /** A model key `body` hands, checked: text of 1 to MAX_MODEL_KEY_CHARS characters with no whitespace or control character
11
+ * (it goes in a header). Issues are pushed at `model_key`. */
12
+ export declare function modelKeyOf(value: unknown, issues: InputIssue[]): string | undefined;
13
+ /** 422 model_key_required: a run start, or a message that would start a turn, with no model key to spend: none handed,
14
+ * none the run holds, and none the server holds for its route. */
15
+ export declare const modelKeyRequired: (message: boolean) => ApiError;
16
+ /** What of a run says where its model requests go: its kind and its launch's pinned model. */
17
+ export type ModelKeyTarget = {
18
+ readonly kind: "agentic" | "workflow" | string;
19
+ readonly model?: {
20
+ readonly provider: string;
21
+ readonly modelId: string;
22
+ } | undefined;
23
+ readonly native?: boolean;
24
+ };
25
+ /** The variables a run's model route reads its key from when that route goes to the model gateway (a workflow's model
26
+ * nodes, pi's and codex's models, a CLI harness on Anthropic's wire where ANTHROPIC_BASE_URL is the gateway's origin);
27
+ * undefined for a route that goes elsewhere (a provider's own, the ChatGPT plan, the faux model) or a native run. */
28
+ export declare function gatewayKeyNames(env: NodeJS.ProcessEnv, run: ModelKeyTarget): string[] | undefined;
29
+ /** Whether a run of `run` with no key of its own has none to spend: its route goes to the gateway, and `env` (the
30
+ * server's, with the keys saved in Settings) holds no key it reads. */
31
+ export declare function serverKeyMissing(env: NodeJS.ProcessEnv, run: ModelKeyTarget): boolean;
32
+ /** Words for model spend tied to no run's key (`what`, a noun phrase) on a server that holds no gateway key (`env`, its
33
+ * keys saved in Settings among them): skipped or refused, never sent with no key. Undefined where the server holds one. */
34
+ export declare function noServerKeyFor(env: NodeJS.ProcessEnv, what: string): string | undefined;
35
+ /** The words of noServerKeyFor for `what`. */
36
+ export declare const noServerKeyWords: (what: string) => string;
37
+ /** Words for spend after the turn of a run that held its own model key (`what`): skipped, since that key is erased with
38
+ * the turn's end and revoked by its caller, and the server's key never pays for a run that brought its own. */
39
+ export declare const runKeyEndedFor: (what: string) => string;
40
+ /** Why a run's model key would never be used, so it is refused rather than kept unused; undefined where it applies: a
41
+ * workflow run (its model nodes go to the gateway), or an agentic run whose model goes to the gateway (pi's and codex's,
42
+ * MODEL_PROVIDER) or to Anthropic's endpoint on the gateway's origin (a CLI harness on Anthropic's wire). */
43
+ export declare function modelKeyMisfit(env: NodeJS.ProcessEnv, run: ModelKeyTarget): string | undefined;
44
+ /** A run's model key as a claim holds it: the gateway origin it was handed for, and the key now (a message's replaces it
45
+ * at the next command; none before the run's first key, and none once its launch no longer holds one). */
46
+ export interface HeldModelKey {
47
+ readonly origin: string;
48
+ key(): string | undefined;
49
+ }
50
+ /**
51
+ * `env` for a run's model routes when the run holds its own key: every property of `env` but each model key (the runner's
52
+ * own and any saved one never go), with the run's key read at each request (`held.key()`) in each variable it fills
53
+ * (runKeyNames). Those are getters, never enumerable: a spread of the result, a spawn given it or a tool's env made from
54
+ * it carries none of them. No ChatGPT sign-in either (a symbol, not copied): every model call tied to the run carries
55
+ * the run's key.
56
+ */
57
+ export declare function withRunModelKey(env: NodeJS.ProcessEnv, held: HeldModelKey): NodeJS.ProcessEnv;
58
+ /**
59
+ * `env` (a claim's model env on the server's keys, withModelKeys) for a run that holds no key of its own yet: each
60
+ * variable a run's key fills (runKeyNames) reads the run's key once a message hands one, and the server's value until
61
+ * then, at each request; every other variable as it is. So a run that started on the server's key spends a message's
62
+ * key from the request after that message on. Getters, never enumerable, as withRunModelKey's.
63
+ */
64
+ export declare function withRunModelKeyLater(env: NodeJS.ProcessEnv, held: HeldModelKey): NodeJS.ProcessEnv;