@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
package/dist/import.d.ts CHANGED
@@ -39,6 +39,11 @@ export declare const IMPORT_ASKED = ".import-at-setup";
39
39
  export declare const LIVE_MS: number;
40
40
  /** The most of one session file read. */
41
41
  export declare const MAX_SESSION_BYTES: number;
42
+ /** The most of one run read together: its session's files and its subagents'. A run is held in memory whole while its
43
+ * keys are found and it is written, so one over this is left out whole (never cut short), whatever the history's size. */
44
+ export declare const MAX_RUN_BYTES: number;
45
+ /** The most projects a count names for the owner to choose from: the latest active. */
46
+ export declare const MAX_CANDIDATES = 500;
42
47
  /** The most of one instructions or skill file read, and of one agent's skill files together. */
43
48
  export declare const MAX_FILE_BYTES: number;
44
49
  export declare const MAX_SKILL_BYTES: number;
@@ -72,6 +77,19 @@ export type ImportOptions = {
72
77
  keys?: boolean;
73
78
  /** Read each session's turns while planning, and measure it (`Plan.found`): what a dry run's summary counts. */
74
79
  measure?: boolean;
80
+ /** The owner's choice: only the projects of these agent ids (`agentIdOf`, as a count's candidates name them) are
81
+ * planned, so only they are read for keys and written. Absent: every project. */
82
+ only?: readonly string[];
83
+ };
84
+ /** A project a count found, for the owner to choose: the agent it would become (`id`), its folder, how many sessions
85
+ * an import would take from it, by which tools, and when the latest of them ended. */
86
+ export type ImportCandidate = {
87
+ id: string;
88
+ name: string;
89
+ path: string;
90
+ sessions: number;
91
+ sources: Source[];
92
+ last_active: string | null;
75
93
  };
76
94
  /** Why a session file or a project's file is left out, by kind, as the left-out counts group them (leftOutLines). */
77
95
  export type LeftOut = "gone" | "temp" | "live" | "large" | "unread" | "no-project" | "no-words" | "copies" | "vanished" | "file";
@@ -122,11 +140,14 @@ export type ImportReport = {
122
140
  * known format secretlint found. */
123
141
  secretsRemoved?: number;
124
142
  };
143
+ /** The projects of `plan` for the owner to choose from, the latest active first (then by folder), at most MAX_CANDIDATES.
144
+ * With `env`, the values of its keys are cut from a name and a folder as the import cuts them. */
145
+ export declare function candidatesOf(plan: Pick<Plan, "projects">, env?: NodeJS.ProcessEnv): ImportCandidate[];
125
146
  export declare const agentIdOf: (cwd: string) => string;
126
147
  /** What an import would take: the sessions under `home`, by project, with what it leaves out and why. Keeps no turns
127
148
  * (with `measure`, only until each session is measured), and reads no file `store`'s imports already read whole and
128
149
  * that has not changed since. */
129
- export declare function planImport({ home, sources, all, deleted, now, temp: tempDir, measure, env, stored, own, signal, keys: scan, onKeys }: ImportOptions, store?: ImportStore): Promise<Plan>;
150
+ export declare function planImport({ home, sources, all, deleted, now, temp: tempDir, measure, env, stored, own, signal, keys: scan, onKeys, only }: ImportOptions, store?: ImportStore): Promise<Plan>;
130
151
  /** The subagents tied to no session: each one's tokens and tool calls, for a summary's totals, each response once. */
131
152
  export declare function untiedFound(plan: Plan): Promise<Found[]>;
132
153
  /** The sessions `files` write, as the import takes them: one per source and session id, however many files write it
package/dist/import.js CHANGED
@@ -170,6 +170,12 @@ async function remoteHistoryMetadata(file, source) {
170
170
  cwd ??= str(row.cwd);
171
171
  child ||= row.isSidechain === true;
172
172
  }
173
+ else if (source === 'pi') {
174
+ if (row.type === 'session') {
175
+ id = str(row.id) ?? id;
176
+ cwd = str(row.cwd) ?? cwd;
177
+ }
178
+ }
173
179
  else if (row.type === 'session_meta') {
174
180
  const payload = row.payload;
175
181
  if (!payload || typeof payload !== 'object' || Array.isArray(payload))
@@ -221,6 +227,11 @@ export const IMPORT_ASKED = ".import-at-setup";
221
227
  export const LIVE_MS = 10 * 60_000;
222
228
  /** The most of one session file read. */
223
229
  export const MAX_SESSION_BYTES = 256 * 1024 * 1024;
230
+ /** The most of one run read together: its session's files and its subagents'. A run is held in memory whole while its
231
+ * keys are found and it is written, so one over this is left out whole (never cut short), whatever the history's size. */
232
+ export const MAX_RUN_BYTES = MAX_SESSION_BYTES;
233
+ /** The most projects a count names for the owner to choose from: the latest active. */
234
+ export const MAX_CANDIDATES = 500;
224
235
  /** The most of one instructions or skill file read, and of one agent's skill files together. */
225
236
  export const MAX_FILE_BYTES = 256 * 1024;
226
237
  export const MAX_SKILL_BYTES = 1024 * 1024;
@@ -232,6 +243,24 @@ const INSTRUCTIONS = {
232
243
  pi: ["AGENTS.md", "CLAUDE.md"],
233
244
  };
234
245
  const hash = (text) => createHash("sha256").update(text).digest("hex");
246
+ /** A run's files and its subagents' are over MAX_RUN_BYTES together: the run is left out. */
247
+ class RunTooLarge extends Error {
248
+ }
249
+ const budgetOf = () => ({ left: MAX_RUN_BYTES });
250
+ const fits = (budget, bytes) => (budget.left -= bytes) >= 0;
251
+ const tooLarge = (listed) => ({ what: listed.file, why: `its files and its subagents' are over ${MAX_RUN_BYTES} bytes together`, kind: "large", session: `${listed.source}:${listed.id}` });
252
+ /** The projects of `plan` for the owner to choose from, the latest active first (then by folder), at most MAX_CANDIDATES.
253
+ * With `env`, the values of its keys are cut from a name and a folder as the import cuts them. */
254
+ export function candidatesOf(plan, env) {
255
+ const text = env ? secretCut(env, SECRET_NAMES).text : (value) => value;
256
+ return plan.projects
257
+ .map((project) => {
258
+ const last = project.sessions.reduce((latest, s) => ((s.endedAt ?? s.startedAt ?? "") > (latest ?? "") ? (s.endedAt ?? s.startedAt) : latest), undefined);
259
+ return { id: project.agentId, name: keptName(project, text), path: text(project.cwd), sessions: sessionsOf(project.sessions).length, sources: [...new Set(project.sessions.map((s) => s.source))].sort(), last_active: last ?? null };
260
+ })
261
+ .sort((a, b) => (b.last_active ?? "").localeCompare(a.last_active ?? "") || a.path.localeCompare(b.path))
262
+ .slice(0, MAX_CANDIDATES);
263
+ }
235
264
  /** A session's id as an import keeps it: as it is, unless it holds one of the keys the import cuts, the environment's or
236
265
  * one saved on the server (a session named after its file can), then `redacted-` and a hash of it, the same each time
237
266
  * and different for each id, so two such sessions stay two runs and a later import finds each one's. The plan and the
@@ -281,6 +310,8 @@ async function keysInSessions(sessions) {
281
310
  async function findKeys(plan, add, cut, held, signal) {
282
311
  const stamps = new Map();
283
312
  const texts = new Map();
313
+ // The runs over MAX_RUN_BYTES (`source:id`): read no further here, and left out by the write.
314
+ const large = new Set();
284
315
  for (const project of plan.projects) {
285
316
  if (signal?.aborted)
286
317
  break;
@@ -298,19 +329,35 @@ async function findKeys(plan, add, cut, held, signal) {
298
329
  // Its own count of records seen: the import's, shared across its files, is the write's to keep.
299
330
  const seen = new Set();
300
331
  const parts = [];
332
+ const budget = budgetOf();
333
+ let over = false;
301
334
  for (const { file } of files) {
302
335
  const stats = await stat(file).catch(() => null);
336
+ if (stats && !fits(budget, stats.size)) {
337
+ over = true;
338
+ break;
339
+ }
303
340
  const part = stats ? await readSession(file, listed.source, { seen }).catch(() => undefined) : undefined;
304
341
  if (!part || !stats)
305
342
  continue;
306
343
  stamps.set(file, stampOf(stats));
307
344
  parts.push(part);
308
345
  }
346
+ if (over) {
347
+ large.add(`${listed.source}:${listed.id}`);
348
+ continue;
349
+ }
309
350
  if (!parts.length)
310
351
  continue;
311
352
  add(await keysInSessions(parts));
312
353
  const session = merged(parts);
313
- const subagents = await readChildren(plan, { ...session, id: cut(session.id) === session.id ? session.id : redactedId(session.id) }, parts, seen);
354
+ const subagents = await readChildren(plan, { ...session, id: cut(session.id) === session.id ? session.id : redactedId(session.id) }, parts, seen, budget).catch((error) => {
355
+ if (!(error instanceof RunTooLarge))
356
+ throw error;
357
+ large.add(`${listed.source}:${listed.id}`);
358
+ });
359
+ if (!subagents)
360
+ continue;
314
361
  for (const child of subagents) {
315
362
  const stats = await stat(child.file).catch(() => null);
316
363
  if (stats)
@@ -319,7 +366,7 @@ async function findKeys(plan, add, cut, held, signal) {
319
366
  add(await keysInSessions(subagents));
320
367
  }
321
368
  }
322
- return { stamps, texts };
369
+ return { stamps, texts, large };
323
370
  }
324
371
  /** A project's own text for secretlint: its path, its instructions, and its skills' paths and text. */
325
372
  const projectText = (cwd, files) => [cwd, ...Object.values(files.instructions), ...Object.entries(files.skills).flat()].join("\n");
@@ -343,11 +390,14 @@ const clip = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…`
343
390
  /** What an import would take: the sessions under `home`, by project, with what it leaves out and why. Keeps no turns
344
391
  * (with `measure`, only until each session is measured), and reads no file `store`'s imports already read whole and
345
392
  * that has not changed since. */
346
- export async function planImport({ home, sources = SOURCES, all = false, deleted = false, now = Date.now(), temp: tempDir = tmpdir(), measure = false, env, stored, own = [], signal, keys: scan = true, onKeys }, store) {
393
+ export async function planImport({ home, sources = SOURCES, all = false, deleted = false, now = Date.now(), temp: tempDir = tmpdir(), measure = false, env, stored, own = [], signal, keys: scan = true, onKeys, only }, store) {
347
394
  // A session's id that holds a key (one named after its file can) is kept as a hash of it: every lookup of an earlier
348
395
  // import's run then goes by the id as kept.
349
396
  const idOf = keptId([env, stored ?? {}], own);
350
397
  const skipped = [];
398
+ // Each file left out here, with the project folder its read gave, if it was read that far: what `only` goes by.
399
+ const leftFrom = new Map();
400
+ const leave = (entry, source, cwd) => void (skipped.push(entry), leftFrom.set(entry, { source, cwd }));
351
401
  const seen = store ? await filesIn(store) : new Map();
352
402
  let already = 0;
353
403
  const held = [];
@@ -370,19 +420,15 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
370
420
  continue;
371
421
  }
372
422
  if (now - stats.mtimeMs < LIVE_MS) {
373
- skipped.push({
374
- what: file,
375
- why: "written in the last 10 minutes: it may still be running",
376
- kind: "live",
377
- });
423
+ leave({ what: file, why: "written in the last 10 minutes: it may still be running", kind: "live" }, source);
378
424
  continue;
379
425
  }
380
426
  if (stats.size > MAX_SESSION_BYTES) {
381
- skipped.push({ what: file, why: `over ${MAX_SESSION_BYTES} bytes`, kind: "large" });
427
+ leave({ what: file, why: `over ${MAX_SESSION_BYTES} bytes`, kind: "large" }, source);
382
428
  continue;
383
429
  }
384
430
  // One file this user cannot read, or one gone since its stat, is named and passed over: the rest still import.
385
- const session = await readSession(file, source, { turns: false }).catch((error) => void skipped.push(unread(file, error)));
431
+ const session = await readSession(file, source, { turns: false }).catch((error) => leave(unread(file, error), source));
386
432
  if (!session)
387
433
  continue;
388
434
  session.id = await idOf(session.id, scan);
@@ -395,28 +441,23 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
395
441
  continue;
396
442
  }
397
443
  if (!session.cwd) {
398
- skipped.push({ what: file, why: "no project directory in it", kind: "no-project" });
444
+ leave({ what: file, why: "no project directory in it", kind: "no-project" }, source);
399
445
  continue;
400
446
  }
401
447
  if (!all && session.users === 0 && !session.child) {
402
- skipped.push({ what: file, why: "no message of the person's", kind: "no-words", session: `${source}:${session.id}` });
448
+ leave({ what: file, why: "no message of the person's", kind: "no-words", session: `${source}:${session.id}` }, source, session.cwd);
403
449
  continue;
404
450
  }
405
451
  const cwd = session.cwd;
406
452
  if (!all) {
407
453
  // A temp folder first, gone or not: only --all brings it in, as the left-out line says.
408
454
  if (temps.some((temp) => cwd === temp || cwd.startsWith(temp + sep))) {
409
- skipped.push({
410
- what: file,
411
- why: `its project ${cwd} is a temp directory`,
412
- kind: "temp",
413
- session: `${source}:${session.id}`,
414
- });
455
+ leave({ what: file, why: `its project ${cwd} is a temp directory`, kind: "temp", session: `${source}:${session.id}` }, source, cwd);
415
456
  continue;
416
457
  }
417
458
  const there = await lstat(cwd).catch(() => null);
418
459
  if (!there?.isDirectory() && !deleted) {
419
- skipped.push({ what: file, why: `its project ${cwd} is gone`, kind: "gone", session: `${source}:${session.id}` });
460
+ leave({ what: file, why: `its project ${cwd} is gone`, kind: "gone", session: `${source}:${session.id}` }, source, cwd);
420
461
  continue;
421
462
  }
422
463
  }
@@ -440,7 +481,24 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
440
481
  child(of, file);
441
482
  }
442
483
  ownRuns(projects, rank);
443
- const plan = { projects: [...projects.values()].sort((a, b) => a.cwd.localeCompare(b.cwd)), skipped, already, held, children, untied };
484
+ // The owner's choice, once each session has its one project: a project not chosen is no part of the plan.
485
+ const chosen = only === undefined ? undefined : new Set(only);
486
+ // What is left out is said of the projects chosen alone, each file by the folder it names: as its read gave it, or,
487
+ // for a file left out unread (still written, over the cap, unreadable), as its first records say. A file that names
488
+ // no folder is no chosen project's.
489
+ if (chosen) {
490
+ const ofChosen = [];
491
+ for (const entry of skipped) {
492
+ // A stop ends these reads as it ends the listing's: the plan is the stopped one's, and is not used.
493
+ if (signal?.aborted)
494
+ break;
495
+ const { source, cwd = (await remoteHistoryMetadata(entry.what, source).catch(() => undefined))?.cwd } = leftFrom.get(entry);
496
+ if (cwd !== undefined && chosen.has(agentIdOf(cwd)))
497
+ ofChosen.push(entry);
498
+ }
499
+ skipped.splice(0, skipped.length, ...ofChosen);
500
+ }
501
+ const plan = { projects: [...projects.values()].filter((project) => !chosen || chosen.has(project.agentId)).sort((a, b) => a.cwd.localeCompare(b.cwd)), skipped, already, held, children, untied };
444
502
  if (!measure)
445
503
  return plan;
446
504
  const counting = secretCut(env, SECRET_NAMES);
@@ -449,7 +507,7 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
449
507
  const foundKeys = (keys) => (counting.add(keys), onKeys?.(keys));
450
508
  // This server's own secrets first, as the import takes them.
451
509
  foundKeys(own);
452
- await findKeys(plan, foundKeys, counting.text, (listed) => heldBy?.get(`${listed.source}:${listed.id}`) !== undefined, signal);
510
+ const { large } = await findKeys(plan, foundKeys, counting.text, (listed) => heldBy?.get(`${listed.source}:${listed.id}`) !== undefined, signal);
453
511
  // Measured in the import's own order, a record or response counted once across files, each session with its
454
512
  // subagents; a session the store holds already from its run, as the import counts it, not from its file now.
455
513
  for (const project of plan.projects) {
@@ -460,14 +518,31 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
460
518
  held.push(run);
461
519
  continue;
462
520
  }
521
+ // A run over MAX_RUN_BYTES is left out by the import, so by its dry run: said, and read no further.
522
+ if (large.has(`${files[0].source}:${files[0].id}`)) {
523
+ skipped.push(tooLarge(files[0]));
524
+ continue;
525
+ }
463
526
  // Each of its files read; those holding only copies add no records to it, but their subagents' folders are its
464
527
  // too, read through the same count (readChildren).
465
528
  const read = [];
529
+ const budget = budgetOf();
530
+ let over = false;
466
531
  for (const listed of files) {
532
+ const stats = await stat(listed.file).catch(() => null);
533
+ // Grown over the cap since the scan above: left out here as the import leaves it out, and read no further.
534
+ if (stats && !fits(budget, stats.size)) {
535
+ over = true;
536
+ break;
537
+ }
467
538
  const part = await readSession(listed.file, listed.source, { seen: seen(listed.source) }).catch(() => undefined);
468
539
  if (part)
469
540
  read.push(part);
470
541
  }
542
+ if (over) {
543
+ skipped.push(tooLarge(files[0]));
544
+ continue;
545
+ }
471
546
  const parts = read.filter((part) => !ownless(part));
472
547
  if (!parts.length)
473
548
  continue;
@@ -476,7 +551,13 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
476
551
  counting.json(session.turns);
477
552
  if (session.firstPrompt)
478
553
  counting.text(session.firstPrompt);
479
- const subagents = await readChildren(plan, session, read, seen(session.source));
554
+ const subagents = await readChildren(plan, session, read, seen(session.source), budget).catch((error) => {
555
+ if (!(error instanceof RunTooLarge))
556
+ throw error;
557
+ skipped.push(tooLarge(files[0]));
558
+ });
559
+ if (!subagents)
560
+ continue;
480
561
  found.push({ source: session.source, agent: project.agentId, ...measured(session, subagents) });
481
562
  }
482
563
  }
@@ -513,7 +594,13 @@ export async function untiedFound(plan) {
513
594
  const found = [];
514
595
  for (const parts of threads.values()) {
515
596
  const session = merged(parts);
516
- found.push({ source: session.source, agent: "", untied: true, metrics: metricsOf(session, await readChildren(plan, session, parts, counted(session.source))) });
597
+ // One whose own subagents are over the cap together counts for itself alone: the totals never hold more than a run.
598
+ const children = await readChildren(plan, session, parts, counted(session.source), budgetOf()).catch((error) => {
599
+ if (!(error instanceof RunTooLarge))
600
+ throw error;
601
+ return [];
602
+ });
603
+ found.push({ source: session.source, agent: "", untied: true, metrics: metricsOf(session, children) });
517
604
  }
518
605
  return found;
519
606
  }
@@ -635,9 +722,10 @@ async function seenIn(store, agentId) {
635
722
  return seen;
636
723
  }
637
724
  /** A run's subagents, theirs, and so on down, each file once, read with the import's `seen`: those beside each of its
638
- * files (Claude Code's), and those naming its thread (Codex's, whichever of its files they ran under). Each within the cap
639
- * and readable; another is passed over. */
640
- async function readChildren(plan, session, parts, seen) {
725
+ * files (Claude Code's), and those naming its thread (Codex's, whichever of its files they ran under). One gone or
726
+ * unreadable is passed over. All of them are held at once, so their sizes are taken from `budget` (what the run's own
727
+ * files left of MAX_RUN_BYTES) before each is read: RunTooLarge once it is spent, as one file over the cap alone spends it. */
728
+ async function readChildren(plan, session, parts, seen, budget) {
641
729
  const out = [];
642
730
  const visited = new Set();
643
731
  const under = async (owner) => {
@@ -646,8 +734,12 @@ async function readChildren(plan, session, parts, seen) {
646
734
  continue;
647
735
  visited.add(file);
648
736
  const stats = await stat(file).catch(() => null);
649
- if (!stats || stats.size > MAX_SESSION_BYTES)
737
+ if (!stats)
650
738
  continue;
739
+ // Every subagent read is held with the run: one more than the run's cap holds ends the read, and the run is left out.
740
+ // No subagent is passed over for its size: the run would be kept without its usage.
741
+ if (!fits(budget, stats.size))
742
+ throw new RunTooLarge();
651
743
  const child = await readSession(file, session.source, { seen }).catch(() => undefined);
652
744
  if (!child)
653
745
  continue;
@@ -1068,6 +1160,13 @@ export async function runImport(store, plan, options) {
1068
1160
  line.already += 1;
1069
1161
  continue;
1070
1162
  }
1163
+ // A run over MAX_RUN_BYTES (found so by the scan above, or grown so since) is left out whole, and said.
1164
+ if (known.large.has(`${listed.source}:${listed.id}`)) {
1165
+ report.skipped.push(tooLarge(listed));
1166
+ continue;
1167
+ }
1168
+ const budget = budgetOf();
1169
+ let over = false;
1071
1170
  // Each of its files, in order. The first's size and time before its read: a file that changes during it is read
1072
1171
  // again next time.
1073
1172
  const parts = [];
@@ -1080,6 +1179,10 @@ export async function runImport(store, plan, options) {
1080
1179
  let changed = false;
1081
1180
  for (const { file } of files) {
1082
1181
  const stats = await stat(file).catch(() => null);
1182
+ if (stats && !fits(budget, stats.size)) {
1183
+ over = true;
1184
+ break;
1185
+ }
1083
1186
  const part = stats ? await readSession(file, listed.source, { seen: seen(listed.source) }).catch((error) => void report.skipped.push(unread(file, error))) : void report.skipped.push({ what: file, why: "gone since it was listed", kind: "vanished" });
1084
1187
  if (!part || !stats)
1085
1188
  continue;
@@ -1096,6 +1199,10 @@ export async function runImport(store, plan, options) {
1096
1199
  if (scannedAs.get(file) !== stampOf(stats))
1097
1200
  changed = true;
1098
1201
  }
1202
+ if (over) {
1203
+ report.skipped.push(tooLarge(listed));
1204
+ continue;
1205
+ }
1099
1206
  if (!read)
1100
1207
  continue;
1101
1208
  const session = merged(parts);
@@ -1109,7 +1216,13 @@ export async function runImport(store, plan, options) {
1109
1216
  // holding a key counts among the keys removed.
1110
1217
  const keptAs = text(session.id) === session.id ? session.id : redactedId(session.id);
1111
1218
  session.id = keptAs;
1112
- const subagents = await readChildren(plan, session, searched, seen(listed.source));
1219
+ const subagents = await readChildren(plan, session, searched, seen(listed.source), budget).catch((error) => {
1220
+ if (!(error instanceof RunTooLarge))
1221
+ throw error;
1222
+ report.skipped.push(tooLarge(listed));
1223
+ });
1224
+ if (!subagents)
1225
+ continue;
1113
1226
  const moved = await Promise.all(subagents.map(async (child) => scannedAs.get(child.file) !== stampOf((await stat(child.file).catch(() => null)) ?? { size: -1, mtimeMs: -1 })));
1114
1227
  if (moved.some(Boolean))
1115
1228
  add(await keysInSessions(subagents));
package/dist/key-check.js CHANGED
@@ -39,6 +39,9 @@ export const KEY_CHECKS = {
39
39
  // in NOT_CHECKED.
40
40
  anthropic: (key, env) => ({ url: `${base(env.ANTHROPIC_BASE_URL, "https://api.anthropic.com")}/v1/models?limit=1`, headers: { "x-api-key": key, "anthropic-version": "2023-06-01" } }),
41
41
  openrouter: (key) => ({ url: "https://openrouter.ai/api/v1/key", headers: { authorization: `Bearer ${key}` } }),
42
+ // Particle bills inference tokens; its authenticated model listing performs no generation
43
+ // (https://docs.particle.ai/models, https://docs.particle.ai/pricing).
44
+ particle: (key) => ({ url: "https://api.particle.ai/v1/models", headers: { authorization: `Bearer ${key}` } }),
42
45
  };
43
46
  /** A key not checked, by key id, and why: OpenAI answers 401 (missing_scope) to a restricted key that works but may not
44
47
  * list models, which the 401 rule would refuse. */
@@ -2,7 +2,7 @@ import type { Workspace } from "../workspace/index.js";
2
2
  import type { AuditLoop } from "../learning-setting.js";
3
3
  import type { RunLaunch } from "../run-launch.js";
4
4
  import { AUDITS_FILE, type FolderChange, type FolderRead } from "./folder.js";
5
- import { type PromotionRecord } from "./promote.js";
5
+ import { type CostStop, type PromotionRecord, type ServingState } from "./promote.js";
6
6
  export { AUDITS_FILE };
7
7
  /** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX), and a file well under the
8
8
  * folder's file cap (a line is a few hundred bytes); with them, the started lines of theirs, and every open one. */
@@ -107,11 +107,11 @@ export type AuditLine = {
107
107
  };
108
108
  export declare function auditLineOf(rows: readonly AuditRow[], workflow: string, digest: string, promotedAt: string | null, loop: Pick<AuditLoop, "hold_window" | "hold_disagree">): AuditLine;
109
109
  /** What the promotions read says of each learned workflow beside what serves (learn/promote.ts servingOf, in its order):
110
- * `state` (`checking`, its newest record is a check at work; `serving`, a revision serves; `stopped`, its newest record
111
- * is a hold that stops it; `held`, else), its newest decided check's numbers, and its audit line over the rows of the
112
- * serving (else the newest) revision's newest promotion (the ones the hold rule counts). */
110
+ * `state` (learn/promote.ts servingStateOf with the money rule's decision, `costStop`: the word the learning view's
111
+ * `status` says too), its newest decided check's numbers, and its audit line over the rows of the serving (else the
112
+ * newest) revision's newest promotion (the ones the hold rule counts). */
113
113
  export type ServingLine = {
114
- readonly state: "serving" | "checking" | "held" | "stopped";
114
+ readonly state: ServingState;
115
115
  readonly check: {
116
116
  readonly n: number;
117
117
  readonly agreed: number;
@@ -120,4 +120,4 @@ export type ServingLine = {
120
120
  } | null;
121
121
  readonly audit: AuditLine | null;
122
122
  };
123
- export declare function servingLinesOf(records: readonly PromotionRecord[], rows: readonly AuditRow[], loop: Pick<AuditLoop, "hold_window" | "hold_disagree">): ServingLine[];
123
+ export declare function servingLinesOf(records: readonly PromotionRecord[], rows: readonly AuditRow[], loop: Pick<AuditLoop, "hold_window" | "hold_disagree">, costStop: CostStop): ServingLine[];
@@ -11,7 +11,7 @@ import { createHash } from "node:crypto";
11
11
  import { COMPUTER_TOOLS } from "@parcha/agentrun-kernel/kernel";
12
12
  import { pinAnnotations, toolClassOf, toolWord } from "./replay-calls.js";
13
13
  import { AUDITS_FILE, readLearning } from "./folder.js";
14
- import { promotionStartOf, servingOf } from "./promote.js";
14
+ import { promotionStartOf, servingOf, servingStateOf } from "./promote.js";
15
15
  export { AUDITS_FILE };
16
16
  /** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX), and a file well under the
17
17
  * folder's file cap (a line is a few hundred bytes); with them, the started lines of theirs, and every open one. */
@@ -140,18 +140,14 @@ export function auditLineOf(rows, workflow, digest, promotedAt, loop) {
140
140
  const counted = windowOf(rows, workflow, digest, promotedAt, loop);
141
141
  return { window: loop.hold_window, disagree: loop.hold_disagree, rows: counted.length, disagreed: counted.filter((row) => row.agreed === false).length };
142
142
  }
143
- export function servingLinesOf(records, rows, loop) {
143
+ export function servingLinesOf(records, rows, loop, costStop) {
144
144
  return servingOf(records).map(({ workflow, digest }) => {
145
145
  const own = records.filter((one) => one.workflow === workflow);
146
146
  const newest = own.at(-1);
147
- const state = newest?.decided === "replaying" ? "checking"
148
- : digest !== null ? "serving"
149
- : newest?.decided === "hold" && (newest.check?.stopped || newest.audit?.stopped) ? "stopped"
150
- : "held";
151
147
  const checked = own.findLast((one) => one.check?.n !== undefined)?.check;
152
148
  const at = digest ?? newest?.digest;
153
149
  return {
154
- state,
150
+ state: servingStateOf(records, workflow, costStop),
155
151
  check: checked ? { n: checked.n, agreed: checked.agreed ?? 0, alone: checked.alone ?? 0, attempt: checked.attempt } : null,
156
152
  audit: at === undefined ? null : auditLineOf(rows, workflow, at, promotionStartOf(records, workflow, at)?.at ?? null, loop),
157
153
  };
@@ -1,44 +1,21 @@
1
- import { type LearnedNote } from "./notes.js";
2
- import { type DraftDecisions, type DraftDryRun, type DraftReader } from "./skills.js";
3
- /** A note's bytes as the note cap counts them: all of `text` but the `compiled_into` line the host adds when a learned
4
- * workflow is compiled from it (notes.ts compiledLineBytes). A note at the cap stays one once marked: it retires,
5
- * restores, and a later note supersedes it through the grader, each checked against `note`. A run never sets the line
6
- * (checkProposal refuses it), so a run's note is counted whole. */
7
- export declare const noteBytes: (text: string) => number;
8
- /** Byte caps (UTF-8) and counts. Over a cap is refused, never cut. */
1
+ import { type DraftDecisions, type DraftDryRun, type DraftReader } from "./workflow-draft.js";
2
+ /** Byte caps (UTF-8). Over a cap is refused, never cut. */
9
3
  export declare const CAPS: Readonly<{
10
- /** One note's file, as noteBytes counts it: the host's `compiled_into` line on top. */
11
- note: 4096;
12
- /** One note a run proposes: the note cap less HOST_LINES, so a run's note stays within `note` once the host merges
13
- * it, and a person can still retire it and a later run supersede it, each read and checked against `note`. */
14
- runNote: number;
15
- /** New notes in one run. */
16
- newNotes: 8;
17
- /** Notes one run's new notes supersede, together. */
18
- supersedes: 8;
19
- /** Changed paths in one run; over it nothing else is read. */
20
- changes: 64;
21
- /** One skill's SKILL.md, or one workflow draft's workflow.json: one grader reads each whole beside the notes, so the
22
- * most a run proposes stays within its prompt (grade.ts GRADE_CAPS.prompt). */
4
+ /** One draft's workflow.json. */
23
5
  file: 16384;
24
6
  /** One draft's README.md, which the host writes from the one-line description its block gives. */
25
7
  readme: 1024;
26
- /** Skills one run adds or changes. */
27
- skills: 1;
28
- /** Workflow drafts one run adds or changes. */
29
- workflows: 1;
30
8
  }>;
31
9
  /** The rule a problem breaks. SPEC.md lists each. */
32
- export type Rule = "too_many_files" | "outside" | "file_name" | "file_mode" | "encoding" | "edited" | "deleted" | "exists" | "too_large" | "too_many_notes" | "invisible_unicode" | "secret_shape" | "secret_value" | "note" | "status" | "supersedes" | "index_full" | "skill" | "skill_outcome" | "too_many_skills" | "workflow" | "too_many_workflows" | "no_tool_list" | "executable_node" | "skill_front_matter" | "skill_status" | "duplicate";
33
- /** One problem with what a run proposed, printable as it is. */
10
+ export type Rule = "outside" | "file_name" | "file_mode" | "encoding" | "deleted" | "too_large" | "invisible_unicode" | "secret_shape" | "secret_value" | "workflow" | "no_tool_list" | "executable_node" | "front_matter" | "kept";
11
+ /** One problem with a draft, printable as it is. */
34
12
  export type Problem = {
35
13
  readonly rule: Rule;
36
14
  readonly path?: string;
37
15
  readonly detail: string;
38
16
  };
39
- /** One file of the run's copy that differs from the commit it started from. `mode` is git's (`100644` a regular file,
40
- * `120000` a link, `040000` a folder; anything else is not a regular file). A change that is not a deletion carries its
41
- * bytes, or only its `size` when that is over the note cap. */
17
+ /** One file a draft adds or changes. `mode` is git's (`100644` a regular file, `120000` a link, `040000` a folder;
18
+ * anything else is not a regular file). A change that is not a deletion carries its bytes. */
42
19
  export type Change = {
43
20
  readonly path: string;
44
21
  readonly status: "added" | "modified" | "deleted";
@@ -46,61 +23,38 @@ export type Change = {
46
23
  readonly size?: number;
47
24
  readonly bytes?: Uint8Array;
48
25
  };
49
- /** The folder a proposal is checked against (the run's seed, or main at merge time): every path it holds, and its active
50
- * notes. */
51
- /** What a proposal is checked against: every path at the seed's top, its active notes, and `rules`, when the caller read
52
- * the active notes' texts, each one's rule (notes.ts ruleOf) to its file: a new note of the same rule is a duplicate. */
53
- export type Base = {
54
- readonly files: Iterable<string>;
55
- readonly active: readonly LearnedNote[];
56
- readonly rules?: ReadonlyMap<string, string>;
57
- };
58
- /** A new note that passed, with its whole text. */
59
- export type ProposedNote = LearnedNote & {
60
- readonly text: string;
61
- };
62
- export type CheckInput = {
63
- readonly base: Base;
26
+ export type DraftCheckInput = {
64
27
  readonly changes: readonly Change[];
65
28
  /** Values the host holds as secrets: a file, or a file's name, that holds one is refused. */
66
29
  readonly refuseValues?: readonly string[];
67
- /** How the run's job ended, its status (`completed`, `failed`, ...). Only a completed run adds or changes a skill:
68
- * without it, none does. */
69
- readonly outcome?: string;
70
30
  /** The tools a workflow draft may name: the agent's granted tools a workflow's call node runs here (tools.ts
71
31
  * learnedWorkflowTools). Without it, a draft that names a tool is refused. */
72
32
  readonly tools?: readonly string[];
73
33
  /** The agent's granted tools the gate does not allow, with what each is set to (tools.ts learnedDraftTools): a draft
74
- * whose call node calls one is refused, in the words a workflow revision's is (learn/skills.ts gatedNodes). */
34
+ * whose call node calls one is refused (workflow-draft.ts gatedNodes). */
75
35
  readonly gated?: Readonly<Record<string, string>>;
76
36
  /** Where each of `gated`'s denies was set (this agent's settings or this server's), for the refusal's words. */
77
37
  readonly deniedBy?: Readonly<Record<string, "agent" | "server" | "default">>;
78
- /** False for a run of a revision that says `learning: "notes"`: a workflow draft it gives is left out (rule `workflow`,
79
- * NOTES_ONLY), and its notes and skill go on. */
80
- readonly workflows?: false;
81
38
  /** Explicit host adapter capabilities; absent keeps the managed runner defaults. */
82
39
  readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
83
- /** The workflow DSL a draft is read with; a proposal that holds a draft is checked with it, never without. */
84
- readonly dsl?: DraftReader;
85
- /** The decision providers a draft's decision nodes may ask, and the gate's setting of each (learn/skills.ts
40
+ /** The workflow DSL a draft is read with. */
41
+ readonly dsl: DraftReader;
42
+ /** The decision providers a draft's decision nodes may ask, and the gate's setting of each (workflow-draft.ts
86
43
  * DraftDecisions, LS-07). Without them, a draft with a decision node is refused. */
87
44
  readonly decisions?: DraftDecisions;
88
- /** Each draft's dry run (skills.ts draftDryRun), by its workflow.json's path: one that failed is refused, rule
45
+ /** Each draft's dry run (workflow-draft.ts draftDryRun), by its workflow.json's path: one that failed is refused, rule
89
46
  * `workflow`, when the draft has no other problem. A draft with none given is checked without one. */
90
47
  readonly dryRuns?: Readonly<Record<string, DraftDryRun>>;
91
- /** The skills' and drafts' files whose text in the run's seed has a status (a person retired it, or it waits for its
92
- * owner's OK): a run never changes those. A draft's is its README.md. */
48
+ /** The drafts' files whose text on main has a status (a person retired it, or it waits for its owner's OK): a run
49
+ * never changes those. A draft's is its README.md. */
93
50
  readonly kept?: readonly string[];
94
51
  };
95
- /** `ok` when `problems` is empty; then `notes` are the new notes, each in shape. */
96
- export type ProposalCheck = {
97
- readonly ok: boolean;
98
- readonly problems: Problem[];
99
- readonly notes: ProposedNote[];
100
- };
101
52
  /** `problem` as it may be printed: its path and detail cut of `values` and of every shape learning refuses, a bank's
102
53
  * numbers too (redactLearned: a name refused for one never prints it), whole when over PRINT_MAX. */
103
54
  export declare const printable: (problem: Problem, values: readonly string[]) => Problem;
55
+ /** The model node kinds a tier routes (model.ts MODEL_NODES); a decision node (judge, pick, sift) goes to its decision
56
+ * provider, never a tier. */
57
+ export declare const TIERED_KINDS: ReadonlySet<string>;
104
58
  /** Why a draft's answer is not written on the agent's own model: each model node that writes the state key its
105
59
  * output.path reads (its answering step) and names tier "fast", one line each, in words the compile retry acts on. A
106
60
  * composed workflow node that writes it answers with its own workflow's answering step, held to the same; a map that
@@ -132,30 +86,13 @@ export declare function compactStateProblems(doc: unknown): string[];
132
86
  * H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
133
87
  * quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
134
88
  export declare function quoteCheckProblems(doc: unknown): string[];
135
- /** The checks one note's file passes by itself (SPEC.md), as a person writes it through the host: its name, the note cap,
136
- * UTF-8, hidden characters, secret shapes and the host's values in its name and text, and its front matter. A person
137
- * may set `status` and `superseded_by`; what a run may not do (edit, delete, set status) is checkProposal's. Every
138
- * problem is printable. */
139
- export declare function checkNote(path: string, bytes: Uint8Array, refuseValues?: readonly string[]): {
140
- problems: Problem[];
141
- note?: ProposedNote;
142
- };
143
- /** Checks what a run proposes against SPEC.md: its notes, and a skill or workflow drafts beside them (learnedChecked).
144
- * `MEMORY.md` is the host's: a change to it is ignored, never refused. */
145
89
  /** What must never be stored, in every change's name and text, whatever the checks would refuse it for first: the
146
- * name and text scans (nameScanned, textOf) of each change, its text read whole (an edit, a file over its cap, one not
147
- * a regular file included), printable as checkProposal's are. A text that is not UTF-8 is `encoding`: unread, so
148
- * never trusted. Empty when nothing in them must be refused. Ahead of keeping some items of a proposal the checks
149
- * refuse (propose.ts): an item refused before its text was read hides nothing. */
90
+ * name and text scans (nameScanned, textOf) of each change, its text read whole (a file over its cap, one not a regular
91
+ * file included), printable as checkDraft's are. A text that is not UTF-8 is `encoding`: unread, so never trusted.
92
+ * Empty when nothing in them must be refused. */
150
93
  export declare function unstorable(changes: readonly Change[], refuseValues?: readonly string[]): Problem[];
151
- export declare function checkProposal(input: CheckInput): ProposalCheck;
152
- /** The notes the active ones of `notes` supersede, each by the note that supersedes it. A note that waits for its
153
- * owner's OK (`status: pending`) supersedes nothing until it is approved: what it names stays active. The one rule the
154
- * merge writes by (runner/learning-loop.ts mergeChangeOf) and its index is counted by (mergeProblems). */
155
- export declare function supersededBy(notes: readonly LearnedNote[]): Map<string, string>;
156
- /** What stops `notes` from joining `base` as they are: a name `base` holds (`exists`), a `supersedes` that names no
157
- * active note of `base` or one another new note supersedes too, or more than CAPS.supersedes notes superseded, and an
158
- * index past INDEX_LINES, counted as the merge makes it (supersededBy: a pending note adds no line and replaces none).
159
- * The checker asks it of the run's seed, where every new note is active; the host asks it again of main at merge time,
160
- * with each note as it merges it, since other runs may have merged meanwhile. */
161
- export declare function mergeProblems(base: Base, notes: readonly LearnedNote[], refuseValues?: readonly string[]): Problem[];
94
+ /** Checks one workflow draft (its workflow.json and README.md, given together by draftFiles) against SPEC.md: each file
95
+ * under workflows/<name>/ (learnedChecked), nothing else, and the two together (a workflow whose files are otherwise in
96
+ * shape with one of them missing names it: restore reads the README). Never throws: a draft it could not read (no
97
+ * workflow DSL, a check that threw) is a problem in words. Every problem printable; none when it passes. */
98
+ export declare function checkDraft(input: DraftCheckInput): Problem[];