@iowarp/clio-coder 0.3.8 → 0.3.9

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 (333) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +7 -3
  3. package/dist/{acp-U67UHUK2.js → acp-7LOELQFP.js} +6 -6
  4. package/dist/{agents-YU6SGALZ.js → agents-FIBG2SHA.js} +27 -25
  5. package/dist/assets/codewiki.json +1 -1
  6. package/dist/{auth-5ZPJOIVG.js → auth-OI4LIH2I.js} +11 -12
  7. package/dist/{builtins-C6JMZVV6.js → builtins-AD25UL3C.js} +5 -5
  8. package/dist/{chunk-5FR74PWO.js → chunk-2JDWVJND.js} +2 -2
  9. package/dist/chunk-3DPEIQKN.js +113 -0
  10. package/dist/{chunk-4SPRNWDE.js → chunk-3DUR4WUA.js} +15 -15
  11. package/dist/{chunk-VHN4MY6O.js → chunk-3MRC2YSQ.js} +2 -2
  12. package/dist/{chunk-5DHKRSMQ.js → chunk-3UUY7R3Z.js} +11 -7
  13. package/dist/{chunk-IGWKHNIQ.js → chunk-3V5AYSEQ.js} +8 -8
  14. package/dist/{chunk-FHJEP5SW.js → chunk-465CC7FK.js} +8 -5
  15. package/dist/{chunk-5WIGXA4T.js → chunk-47CMYGET.js} +111 -4
  16. package/dist/{chunk-A3WNZD3P.js → chunk-4H6ULJ3H.js} +67 -21
  17. package/dist/{chunk-TB5666IT.js → chunk-4LJX2PUC.js} +3 -3
  18. package/dist/{chunk-XWSF374K.js → chunk-56KB5IJP.js} +2 -2
  19. package/dist/{chunk-SPULKLCF.js → chunk-5DQRIYDZ.js} +2 -2
  20. package/dist/{chunk-2HEJ2F35.js → chunk-5HFBWUMU.js} +20 -8
  21. package/dist/{chunk-WNIJTQQK.js → chunk-5PVQ4SRS.js} +78 -6
  22. package/dist/{chunk-DYIM5TJT.js → chunk-5QKCQQ3E.js} +262 -6
  23. package/dist/{chunk-TYPGUK6W.js → chunk-5T7RBWN2.js} +111 -5
  24. package/dist/{chunk-IIZWH4XA.js → chunk-774ILSRL.js} +2 -2
  25. package/dist/chunk-7C6RYZGQ.js +391 -0
  26. package/dist/{chunk-TANS5ZJS.js → chunk-AD7Y7STJ.js} +3 -3
  27. package/dist/{chunk-RWSI4YD7.js → chunk-AEYBF3TB.js} +33 -12
  28. package/dist/{chunk-DGSYXYMX.js → chunk-AMKHQW3C.js} +2 -2
  29. package/dist/{chunk-VWZOAB7K.js → chunk-B5XRQOLB.js} +7 -7
  30. package/dist/{chunk-WXY7KU3G.js → chunk-BVDVID7E.js} +2 -2
  31. package/dist/{chunk-PMDBGQSJ.js → chunk-CA42X6KT.js} +2 -2
  32. package/dist/{chunk-HLE42MG7.js → chunk-D73KXYPF.js} +3 -3
  33. package/dist/{chunk-5Q2VVUKB.js → chunk-DG4M6ZUE.js} +3 -3
  34. package/dist/{chunk-ME6CCNFO.js → chunk-EBOC7MT3.js} +6 -6
  35. package/dist/{chunk-MXKJU4JB.js → chunk-ECUO3KDP.js} +48 -7
  36. package/dist/{chunk-26LEYJZH.js → chunk-FALJGAWU.js} +2 -2
  37. package/dist/{chunk-GWS3VEIW.js → chunk-FWDFM5ZU.js} +24 -3
  38. package/dist/{chunk-7RGZWPB6.js → chunk-GAYUJ7LE.js} +67 -13
  39. package/dist/{chunk-VCBR6CU7.js → chunk-HAY4ZE2P.js} +2 -2
  40. package/dist/{chunk-FBVTI2TJ.js → chunk-HCBCAYZU.js} +11 -130
  41. package/dist/{chunk-WSB3FPX7.js → chunk-HJB5IUKP.js} +32 -136
  42. package/dist/{chunk-J3YUBZWY.js → chunk-HKO36JWF.js} +33 -5
  43. package/dist/{chunk-E77JEWSD.js → chunk-HPCTNZM2.js} +6 -36
  44. package/dist/{chunk-FJ3H4MN5.js → chunk-IHKBWSXF.js} +2 -2
  45. package/dist/{chunk-NMPKI6XL.js → chunk-JEQQR47K.js} +37 -18
  46. package/dist/{chunk-3BINW3FP.js → chunk-KV2AOLDF.js} +24 -4
  47. package/dist/{chunk-YS5VLNH5.js → chunk-LXPJXFM5.js} +7 -7
  48. package/dist/{chunk-7RFXX52T.js → chunk-MIX5N5AC.js} +271 -41
  49. package/dist/{chunk-K4XHGFR5.js → chunk-MLOK6ZOS.js} +1297 -218
  50. package/dist/{chunk-ZNLWCMVZ.js → chunk-MV2VUEJC.js} +2 -2
  51. package/dist/{chunk-MVVUPGPW.js → chunk-MXHC5QYU.js} +6 -6
  52. package/dist/{chunk-5H3GB5BO.js → chunk-N3PBVRTZ.js} +4 -382
  53. package/dist/{chunk-2HFZQUHL.js → chunk-N5XKWMDW.js} +17 -7
  54. package/dist/{chunk-5C3AQNDW.js → chunk-NNNWO6F2.js} +124 -36
  55. package/dist/{chunk-GU2UIAFZ.js → chunk-NQ6UCCOD.js} +3 -3
  56. package/dist/{chunk-N22QMJKY.js → chunk-NZU6YDNV.js} +4 -4
  57. package/dist/{chunk-ZVJ5BLO2.js → chunk-O6I4CIEU.js} +151 -13
  58. package/dist/{chunk-XN3L4EYL.js → chunk-OEDBCISO.js} +2 -2
  59. package/dist/{chunk-VAWNZU7Z.js → chunk-P3JGPQFL.js} +2 -2
  60. package/dist/{chunk-IJ7RPIYJ.js → chunk-PNY46YEY.js} +20 -3
  61. package/dist/{chunk-U6MBIEMB.js → chunk-PZ4I4JE2.js} +56 -35
  62. package/dist/{chunk-GPIEI3LY.js → chunk-QQ7EKM72.js} +2 -2
  63. package/dist/{chunk-WLFILSD5.js → chunk-R7LNVMCS.js} +66 -28
  64. package/dist/{chunk-GOXNB3AO.js → chunk-RAPCMZL4.js} +75 -4
  65. package/dist/chunk-RKKLTLYB.js +45 -0
  66. package/dist/{chunk-TT36MB5S.js → chunk-RKRLDWD3.js} +3 -1
  67. package/dist/{chunk-TTHACPOM.js → chunk-S4COXYBG.js} +456 -18
  68. package/dist/{chunk-WWCZ5F23.js → chunk-T3Z6VAAF.js} +69 -10
  69. package/dist/{chunk-GN57SG4G.js → chunk-TD7UE2L5.js} +9 -7
  70. package/dist/{chunk-TLQJPP24.js → chunk-TEO2TLVN.js} +523 -322
  71. package/dist/{chunk-FCSXB6T2.js → chunk-UOSL25KY.js} +14 -2
  72. package/dist/{chunk-KTYTFRMB.js → chunk-VKBMFOYV.js} +17 -15
  73. package/dist/{chunk-PT7HYKEM.js → chunk-VO2LKSTM.js} +2 -2
  74. package/dist/{chunk-P43ETTHK.js → chunk-VPTUJU4P.js} +2 -2
  75. package/dist/{chunk-WEH5XRJQ.js → chunk-WIE7ZOSW.js} +2 -2
  76. package/dist/{chunk-EMYUUSFG.js → chunk-WXCJ7VME.js} +5 -5
  77. package/dist/{chunk-4DGYLA73.js → chunk-XDOQXGFO.js} +22 -7
  78. package/dist/{chunk-JOZYP4GM.js → chunk-YKOFT37S.js} +5 -5
  79. package/dist/chunk-YSEHGPCT.js +127 -0
  80. package/dist/{chunk-HFSBBKSQ.js → chunk-YW7UVM5V.js} +138 -3
  81. package/dist/cli/index.js +27 -27
  82. package/dist/{clio-QVTYJ57A.js → clio-LT5V7SSZ.js} +6 -6
  83. package/dist/{code-nav-FGGFIE7L.js → code-nav-LMW275PA.js} +4 -4
  84. package/dist/{config-LW5IJFQN.js → config-RXS5T3JT.js} +71 -43
  85. package/dist/{configure-7XIZCOU4.js → configure-2WYWSCSD.js} +14 -15
  86. package/dist/{context-Y6Y7QPR6.js → context-I3BTOTCS.js} +12 -12
  87. package/dist/{context-L3WL3X7K.js → context-MVOORGMF.js} +34 -33
  88. package/dist/{context-N52ZA626.js → context-PALKKQYL.js} +20 -20
  89. package/dist/{context-clear-MBQRLSDQ.js → context-clear-N2WOYZ2K.js} +34 -33
  90. package/dist/{context-index-HVMFQHK3.js → context-index-HNG3MOME.js} +2 -2
  91. package/dist/{context-working-set-GS6DSO7F.js → context-working-set-MIEVECVZ.js} +10 -11
  92. package/dist/{dispatch-runner-22ZCNOM3.js → dispatch-runner-VVA4SRRH.js} +34 -33
  93. package/dist/doctor-TWBWFK5V.js +165 -0
  94. package/dist/{eval-BEC2WHDA.js → eval-IJ5VEZDJ.js} +2016 -142
  95. package/dist/{evidence-REJUMSKM.js → evidence-L5APPXNV.js} +29 -28
  96. package/dist/{evolve-PY5ZBA5K.js → evolve-RGNKFJ52.js} +29 -28
  97. package/dist/{extensions-HVKU65YU.js → extensions-7WYWUX5A.js} +9 -3
  98. package/dist/{fleet-7WZEWRFA.js → fleet-6CNVBZZP.js} +87 -55
  99. package/dist/{fleet-commands-UVHWM76J.js → fleet-commands-L2SXSYEI.js} +6 -6
  100. package/dist/{fleet-graph-6ULH7PES.js → fleet-graph-2J3OOIPO.js} +14 -12
  101. package/dist/{fleet-preflight-J53T6CCE.js → fleet-preflight-CZRJ4JP5.js} +3 -4
  102. package/dist/{fleet-validate-72PC4SLA.js → fleet-validate-C5RI6DP7.js} +16 -15
  103. package/dist/{init-OG3TPGQG.js → init-VBN2ACVA.js} +50 -48
  104. package/dist/{library-CNTMPLRF.js → library-JHGUMLY2.js} +13 -11
  105. package/dist/{memory-6IS7F275.js → memory-K4OQIYWG.js} +31 -30
  106. package/dist/{models-ENRJDA5W.js → models-2NCZUWDD.js} +23 -22
  107. package/dist/{monitor-XLDVO7TN.js → monitor-MMVTJABD.js} +35 -34
  108. package/dist/{orchestrator-6KSPYRHA.js → orchestrator-ZKBPCHW6.js} +1627 -294
  109. package/dist/{reset-RZ4ER727.js → reset-DD5JGOY3.js} +3 -3
  110. package/dist/{run-Y2CNK5RU.js → run-QEGNX7FL.js} +56 -55
  111. package/dist/{share-A55GYP6Z.js → share-JKD3BQMW.js} +13 -11
  112. package/dist/{skills-ALC5J6AT.js → skills-LMQIKDOZ.js} +14 -12
  113. package/dist/{skills-eval-JPBEBYQU.js → skills-eval-I7X2774U.js} +34 -32
  114. package/dist/{steer-GGWFUJUD.js → steer-CF5TDANS.js} +3 -3
  115. package/dist/{support-MIETYA5E.js → support-I7LOJLIF.js} +4 -4
  116. package/dist/{targets-VGNXIR3S.js → targets-RUSR6B5Z.js} +58 -32
  117. package/dist/{terminal-lease-WOBR64YA.js → terminal-lease-QYVORFR4.js} +6 -4
  118. package/dist/{trace-PNCASAXC.js → trace-ODOQIVIW.js} +61 -6
  119. package/dist/{upgrade-FUSUAGHR.js → upgrade-XANW3FXB.js} +17 -16
  120. package/dist/{usage-N4MKVHKD.js → usage-4H7ZRXQT.js} +88 -44
  121. package/dist/{verifiers-YAWOJ3H2.js → verifiers-UZXNBZEB.js} +6 -6
  122. package/dist/{verify-LTDHYBGY.js → verify-BVKWTNDL.js} +5 -5
  123. package/dist/{wiki-generate-6M7GHTBJ.js → wiki-generate-MY7WV2QI.js} +49 -47
  124. package/dist/worker/entry.js +29 -33
  125. package/docs/alcf-provider.md +1 -1
  126. package/docs/architecture.md +1 -1
  127. package/docs/artifact-versions.md +6 -1
  128. package/docs/built-in-agents.md +1 -1
  129. package/docs/capacity-and-scheduling.md +23 -2
  130. package/docs/commands-and-modes.md +1 -1
  131. package/docs/configuration-and-targets.md +30 -3
  132. package/docs/context-engine.md +63 -4
  133. package/docs/documentation-coverage.md +3 -3
  134. package/docs/documentation-guide.md +1 -1
  135. package/docs/environment-variables.md +2 -0
  136. package/docs/eval-runner.md +262 -11
  137. package/docs/evals-internal.md +72 -2
  138. package/docs/evidence-and-memory.md +11 -10
  139. package/docs/evolution.md +1 -1
  140. package/docs/extensions-and-sharing.md +3 -1
  141. package/docs/fleet-dispatch.md +4 -4
  142. package/docs/installation-and-lifecycle.md +1 -1
  143. package/docs/middleware-and-components.md +1 -1
  144. package/docs/model-catalog.md +1 -1
  145. package/docs/observability.md +53 -2
  146. package/docs/proactive-memory.md +127 -14
  147. package/docs/prompt-envelope-and-tools.md +19 -1
  148. package/docs/provider-adapter-cookbook.md +1 -1
  149. package/docs/release-cut-checklist.md +19 -3
  150. package/docs/safety-model.md +1 -1
  151. package/docs/scientific-validation.md +1 -1
  152. package/docs/skills-marketplace.md +1 -1
  153. package/docs/tool-usage.md +1 -1
  154. package/docs/trace-store.md +1 -1
  155. package/docs/troubleshooting.md +87 -0
  156. package/docs/tui-design.md +1 -1
  157. package/docs/worker-dispatch-mechanics.md +1 -1
  158. package/package.json +2 -1
  159. package/src/cli/agents.ts +1 -1
  160. package/src/cli/config-inspect.ts +33 -6
  161. package/src/cli/config.ts +1 -1
  162. package/src/cli/doctor-state-size.ts +82 -0
  163. package/src/cli/doctor.ts +3 -1
  164. package/src/cli/eval.ts +80 -16
  165. package/src/cli/extensions.ts +5 -1
  166. package/src/cli/fleet.ts +32 -3
  167. package/src/cli/targets.ts +44 -13
  168. package/src/cli/trace.ts +63 -4
  169. package/src/cli/usage.ts +63 -14
  170. package/src/core/bus-events.ts +29 -1
  171. package/src/core/cache-telemetry.ts +42 -0
  172. package/src/core/config.ts +18 -0
  173. package/src/core/defaults.ts +36 -6
  174. package/src/core/endpoint-key.ts +27 -0
  175. package/src/core/residency-target-key.ts +25 -0
  176. package/src/core/response-schema.ts +36 -2
  177. package/src/domains/config/classify.ts +3 -0
  178. package/src/domains/context/codewiki/coordinator.ts +12 -4
  179. package/src/domains/dispatch/admission.ts +40 -3
  180. package/src/domains/dispatch/capacity-lease.ts +98 -9
  181. package/src/domains/dispatch/contract.ts +11 -0
  182. package/src/domains/dispatch/execution-plan.ts +44 -4
  183. package/src/domains/dispatch/extension.ts +166 -42
  184. package/src/domains/dispatch/fleet-run.ts +23 -3
  185. package/src/domains/dispatch/heartbeat.ts +32 -8
  186. package/src/domains/dispatch/index.ts +3 -0
  187. package/src/domains/dispatch/orphan-recovery.ts +5 -0
  188. package/src/domains/dispatch/reservation-store.ts +116 -8
  189. package/src/domains/dispatch/state.ts +4 -0
  190. package/src/domains/dispatch/worker-spawn.ts +25 -11
  191. package/src/domains/dispatch/write-boundary-enforcer.ts +20 -3
  192. package/src/domains/dispatch/write-boundary.ts +62 -1
  193. package/src/domains/eval/artifacts/store.ts +62 -0
  194. package/src/domains/eval/compare/behavioral.ts +224 -0
  195. package/src/domains/eval/compare/compare.ts +355 -2
  196. package/src/domains/eval/compare/envelope.ts +128 -0
  197. package/src/domains/eval/compare/gates.ts +24 -6
  198. package/src/domains/eval/compare/thresholds.ts +30 -3
  199. package/src/domains/eval/execution-provenance.ts +240 -0
  200. package/src/domains/eval/metrics/aggregate.ts +136 -0
  201. package/src/domains/eval/metrics/call-ledger-stream.ts +112 -0
  202. package/src/domains/eval/metrics/tracked.ts +413 -0
  203. package/src/domains/eval/provenance.ts +117 -0
  204. package/src/domains/eval/reports/comparison.ts +128 -0
  205. package/src/domains/eval/reports/junit.ts +17 -3
  206. package/src/domains/eval/reports/markdown.ts +3 -3
  207. package/src/domains/eval/reports/text.ts +14 -0
  208. package/src/domains/eval/run-compare.ts +20 -0
  209. package/src/domains/eval/runners/clio-run.ts +127 -0
  210. package/src/domains/eval/runners/external-command.ts +28 -3
  211. package/src/domains/eval/schema/adapter.ts +111 -0
  212. package/src/domains/eval/schema/artifact.ts +20 -0
  213. package/src/domains/eval/schema/behavioral-metrics.ts +204 -0
  214. package/src/domains/eval/schema/behavioral.ts +520 -0
  215. package/src/domains/eval/schema/execution-envelope.ts +194 -0
  216. package/src/domains/eval/schema/serving.ts +74 -0
  217. package/src/domains/eval/schema/suite.ts +38 -8
  218. package/src/domains/eval/schema/validate.ts +58 -3
  219. package/src/domains/eval/schema/verdict.ts +237 -0
  220. package/src/domains/eval/suites/resolve.ts +2 -0
  221. package/src/domains/eval/suites/run.ts +264 -33
  222. package/src/domains/eval/verifiers/command.ts +2 -1
  223. package/src/domains/eval/workspaces/temp-copy.ts +145 -13
  224. package/src/domains/evidence/build.ts +2 -13
  225. package/src/domains/evidence/eval.ts +2 -12
  226. package/src/domains/evidence/findings-markdown.ts +33 -0
  227. package/src/domains/evidence/run-trust.ts +7 -113
  228. package/src/domains/evidence/trust-projection.ts +2 -2
  229. package/src/domains/extensions/compatibility.ts +285 -0
  230. package/src/domains/extensions/discovery.ts +38 -3
  231. package/src/domains/extensions/resources.ts +1 -1
  232. package/src/domains/extensions/state.ts +12 -3
  233. package/src/domains/extensions/types.ts +2 -0
  234. package/src/domains/lifecycle/doctor.ts +69 -1
  235. package/src/domains/memory/index.ts +14 -0
  236. package/src/domains/memory/task-bank-promotion.ts +64 -0
  237. package/src/domains/memory/task-memory-policy.ts +77 -8
  238. package/src/domains/memory/task-memory-spend.ts +131 -0
  239. package/src/domains/memory/task-memory-status.ts +7 -0
  240. package/src/domains/memory/task-memory-telemetry.ts +2 -0
  241. package/src/domains/middleware/index.ts +1 -0
  242. package/src/domains/middleware/memory-intervention.ts +69 -5
  243. package/src/domains/middleware/memory-step-endpoint.ts +71 -0
  244. package/src/domains/observability/background-memory-usage.ts +140 -0
  245. package/src/domains/observability/cost.ts +1 -1
  246. package/src/domains/observability/index.ts +7 -0
  247. package/src/domains/observability/out-of-turn-usage.ts +51 -2
  248. package/src/domains/observability/trace-store.ts +192 -2
  249. package/src/domains/prompts/compiler.ts +100 -13
  250. package/src/domains/providers/endpoint-capacity.ts +96 -0
  251. package/src/domains/providers/index.ts +10 -0
  252. package/src/domains/providers/models/local-models/clio-local-coding-targets.yaml +243 -1
  253. package/src/domains/providers/runtime-resolution.ts +8 -1
  254. package/src/domains/providers/runtimes/common/probe-helpers.ts +31 -9
  255. package/src/domains/providers/runtimes/local-native/llamacpp-anthropic.ts +1 -1
  256. package/src/domains/providers/runtimes/local-native/llamacpp-completion.ts +1 -1
  257. package/src/domains/providers/runtimes/local-native/llamacpp-embed.ts +1 -1
  258. package/src/domains/providers/runtimes/local-native/llamacpp-rerank.ts +1 -1
  259. package/src/domains/providers/runtimes/local-native/llamacpp.ts +4 -1
  260. package/src/domains/providers/runtimes/local-native/lmstudio.ts +4 -1
  261. package/src/domains/providers/runtimes/local-native/ollama-native.ts +6 -1
  262. package/src/domains/providers/types/capability-flags.ts +2 -0
  263. package/src/domains/providers/types/target-descriptor.ts +2 -0
  264. package/src/domains/resources/prompts/loader.ts +95 -33
  265. package/src/domains/safety/call-target.ts +52 -0
  266. package/src/domains/safety/run-effects.ts +35 -4
  267. package/src/domains/session/context-accounting.ts +52 -1
  268. package/src/domains/session/context-ledger.ts +37 -13
  269. package/src/domains/session/index.ts +6 -0
  270. package/src/domains/session/prompt-cache.ts +140 -0
  271. package/src/domains/session/prompt-manifest.ts +42 -0
  272. package/src/engine/acp/adapter.ts +18 -3
  273. package/src/engine/ai.ts +35 -0
  274. package/src/engine/apis/llamacpp-residency.ts +55 -3
  275. package/src/engine/apis/lmstudio.ts +25 -5
  276. package/src/engine/apis/ollama-native.ts +2 -1
  277. package/src/engine/apis/openai-completions.ts +80 -17
  278. package/src/engine/apis/residency-lock.ts +3 -1
  279. package/src/engine/apis/residency.ts +34 -1
  280. package/src/engine/provider-payload.ts +29 -1
  281. package/src/entry/orchestrator.ts +176 -30
  282. package/src/interactive/chat-loop-messages.ts +26 -7
  283. package/src/interactive/chat-loop.ts +318 -41
  284. package/src/interactive/chat-panel.ts +62 -8
  285. package/src/interactive/clio-editor.ts +45 -8
  286. package/src/interactive/context-activity.ts +5 -1
  287. package/src/interactive/context-meter.ts +1 -1
  288. package/src/interactive/context-overlay.ts +40 -10
  289. package/src/interactive/cost-overlay.ts +64 -6
  290. package/src/interactive/dispatch-board.ts +84 -12
  291. package/src/interactive/fleet-run-preview.ts +41 -15
  292. package/src/interactive/handoff-round.ts +41 -2
  293. package/src/interactive/interactive-application.ts +24 -1
  294. package/src/interactive/interactive-input-runtime.ts +8 -0
  295. package/src/interactive/interactive-presentation.ts +4 -0
  296. package/src/interactive/interactive-shell.ts +20 -17
  297. package/src/interactive/interactive-slash-runtime.ts +27 -4
  298. package/src/interactive/memory-overlay.ts +8 -0
  299. package/src/interactive/mutation-preview.ts +295 -0
  300. package/src/interactive/overlay-general-openers.ts +16 -0
  301. package/src/interactive/overlay-key-routing.ts +38 -0
  302. package/src/interactive/overlay-lifecycle.ts +38 -5
  303. package/src/interactive/overlay-permission-lifecycle.ts +22 -2
  304. package/src/interactive/overlay-session-lifecycle.ts +73 -9
  305. package/src/interactive/overlays/ask-user.ts +91 -19
  306. package/src/interactive/overlays/help-reference.ts +4 -0
  307. package/src/interactive/overlays/prompts.ts +11 -1
  308. package/src/interactive/overlays/settings.ts +35 -1
  309. package/src/interactive/permission-hint.ts +34 -2
  310. package/src/interactive/permission-overlay.ts +159 -9
  311. package/src/interactive/prewarm.ts +197 -0
  312. package/src/interactive/render-trace.ts +162 -15
  313. package/src/interactive/renderers/tool-execution.ts +4 -0
  314. package/src/interactive/side-question.ts +58 -1
  315. package/src/interactive/status/controller.ts +11 -0
  316. package/src/interactive/status/state-machine.ts +54 -2
  317. package/src/interactive/status/types.ts +7 -0
  318. package/src/interactive/terminal-lease.ts +2 -0
  319. package/src/interactive/turn-context.ts +299 -31
  320. package/src/interactive/turn-persistence.ts +14 -4
  321. package/src/interactive/turn-prewarm.ts +364 -0
  322. package/src/interactive/turn-queues.ts +7 -4
  323. package/src/interactive/turn-runtime.ts +8 -1
  324. package/src/interactive/turn-state.ts +23 -0
  325. package/src/interactive/view/view-overlay.ts +28 -3
  326. package/src/tools/ask-user.ts +43 -2
  327. package/src/tools/dispatch-plan.ts +17 -9
  328. package/src/tools/dispatch-scout.ts +1 -1
  329. package/src/tools/registry.ts +16 -0
  330. package/dist/chunk-AOCYTWAV.js +0 -449
  331. package/dist/chunk-HWUFFB6L.js +0 -83
  332. package/dist/chunk-R346GLFC.js +0 -31
  333. package/dist/doctor-M7YEDGAE.js +0 -91
@@ -210,6 +210,7 @@ registerEngineBuiltins();
210
210
 
211
211
  // src/engine/ai.ts
212
212
  var stream = engineStream;
213
+ var streamSimple = engineStreamSimple;
213
214
  async function completeEngineText(input) {
214
215
  const response = await completeEngineSimple(
215
216
  input.model,
@@ -231,7 +232,17 @@ async function completeEngineText(input) {
231
232
  return {
232
233
  text: response.content.filter((block) => block.type === "text").map((block) => block.text).join(""),
233
234
  inputTokens: response.usage.input,
234
- outputTokens: response.usage.output
235
+ outputTokens: response.usage.output,
236
+ usage: {
237
+ input: response.usage.input,
238
+ output: response.usage.output,
239
+ cacheRead: response.usage.cacheRead,
240
+ cacheWrite: response.usage.cacheWrite,
241
+ reasoning: response.usage.reasoning ?? 0,
242
+ totalTokens: response.usage.totalTokens,
243
+ costUsd: response.usage.cost.total
244
+ },
245
+ backend: response.backendTimings ?? null
235
246
  };
236
247
  }
237
248
  var registered = false;
@@ -325,6 +336,7 @@ export {
325
336
  activateExternalPluginApiBridge,
326
337
  StringEnum,
327
338
  stream,
339
+ streamSimple,
328
340
  completeEngineText,
329
341
  ensurePiAiRegistered,
330
342
  createEngineAi,
@@ -335,4 +347,4 @@ export {
335
347
  calculateEngineCost,
336
348
  registerFauxFromEnv
337
349
  };
338
- //# sourceMappingURL=chunk-FCSXB6T2.js.map
350
+ //# sourceMappingURL=chunk-UOSL25KY.js.map
@@ -9,23 +9,21 @@ import {
9
9
  isDispatchIntent,
10
10
  isToolProfileName,
11
11
  resolveDispatchPathScope
12
- } from "./chunk-A3WNZD3P.js";
12
+ } from "./chunk-4H6ULJ3H.js";
13
13
  import {
14
14
  ROUTE_POLICY_VERSION,
15
15
  isRouteDecisionAgentSelection,
16
16
  isRoutingIntent,
17
17
  parseRoutingIntent
18
- } from "./chunk-P43ETTHK.js";
18
+ } from "./chunk-VPTUJU4P.js";
19
19
  import {
20
20
  isExecutionRole,
21
21
  requestExecutionRole
22
22
  } from "./chunk-H7IXIC72.js";
23
23
  import {
24
+ AGENT_AUTOMATION_AUTHORITIES,
24
25
  pathBoundaryCovers
25
- } from "./chunk-TTHACPOM.js";
26
- import {
27
- AGENT_AUTOMATION_AUTHORITIES
28
- } from "./chunk-AOCYTWAV.js";
26
+ } from "./chunk-S4COXYBG.js";
29
27
  import {
30
28
  init_esm_shims
31
29
  } from "./chunk-3R73A4XB.js";
@@ -329,14 +327,18 @@ function isRecord2(value) {
329
327
  function str(value) {
330
328
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
331
329
  }
332
- function safeField(value) {
330
+ function safeField(value, bindChangedValue = true) {
333
331
  let result = "";
334
332
  for (const character of value) {
335
333
  const code = character.codePointAt(0) ?? 0;
336
334
  result += code < 32 || code >= 127 && code <= 159 ? "?" : character;
337
- if (result.length >= 256) return `${result.slice(0, 255)}\u2026`;
335
+ if (result.length >= 256) {
336
+ result = `${result.slice(0, 255)}\u2026`;
337
+ break;
338
+ }
338
339
  }
339
- return result;
340
+ if (!bindChangedValue || result === value) return result;
341
+ return `${result}{sha256=${createHash("sha256").update(value, "utf8").digest("hex")}}`;
340
342
  }
341
343
  function renderLegacyPathScope(task) {
342
344
  if (task.intent !== void 0) return [];
@@ -459,7 +461,7 @@ function renderPlanText(topology, tasks, costCeilingUsd, deadlineMs, source, max
459
461
  const routing = task.routingIntent;
460
462
  const routingText = routing === void 0 ? "" : ` posture=${routing.posture} maxCostUsd=${routing.maxCostUsd ?? "none"} deadlineMs=${routing.deadlineMs ?? "none"} minimumQuality=${routing.minimumQuality ?? "none"} locality=${routing.locality}`;
461
463
  lines.push(
462
- ` ${index + 1}.${role} agent=${safeField(task.agent)}${target}${model}${node}${failover}${routingText} task=${JSON.stringify(safeField(task.task))}`
464
+ ` ${index + 1}.${role} agent=${safeField(task.agent)}${target}${model}${node}${failover}${routingText} task_bytes=${Buffer.byteLength(task.task, "utf8")} task_sha256=${createHash("sha256").update(task.task, "utf8").digest("hex")} task_preview=${JSON.stringify(safeField(task.task, false))}`
463
465
  );
464
466
  if (task.council !== void 0) {
465
467
  lines.push(
@@ -486,22 +488,22 @@ function renderPlanText(topology, tasks, costCeilingUsd, deadlineMs, source, max
486
488
  }
487
489
  if (task.agentSelection !== null) {
488
490
  lines.push(
489
- ` agent-selection=auto baseline=${safeField(task.agentSelection.baselineAgentId)} authority=${task.agentSelection.approvedAuthorities.map(safeField).join(",")} basis=${task.agentSelection.authorityBasis}`
491
+ ` agent-selection=auto baseline=${safeField(task.agentSelection.baselineAgentId)} authority=${task.agentSelection.approvedAuthorities.map((authority) => safeField(authority)).join(",")} basis=${task.agentSelection.authorityBasis}`
490
492
  );
491
493
  }
492
494
  if (task.stepId !== null) {
493
495
  lines.push(
494
- ` step=${safeField(task.stepId)} wave=${task.wave ?? "?"} role=${task.executionRole} dependencies=${task.dependencies.map(safeField).join(",") || "none"} result=${task.expectedResultContract ?? "none"} authority=${task.authorityGrant?.requested ?? "none"} basis=${task.authorityGrant?.basis ?? "none"}`
496
+ ` step=${safeField(task.stepId)} wave=${task.wave ?? "?"} role=${task.executionRole} dependencies=${task.dependencies.map((dependency) => safeField(dependency)).join(",") || "none"} result=${task.expectedResultContract ?? "none"} authority=${task.authorityGrant?.requested ?? "none"} basis=${task.authorityGrant?.basis ?? "none"}`
495
497
  );
496
498
  const agentReasons = task.agentDecision?.agentSelection.evaluations.filter((evaluation) => evaluation.rejections.length > 0).slice(0, 8).map(
497
- (evaluation) => `${safeField(evaluation.agentId)}:${evaluation.rejections.slice(0, 4).map(safeField).join(",")}`
499
+ (evaluation) => `${safeField(evaluation.agentId)}:${evaluation.rejections.slice(0, 4).map((rejection) => safeField(rejection)).join(",")}`
498
500
  );
499
501
  if (agentReasons !== void 0 && agentReasons.length > 0)
500
502
  lines.push(` agent-exclusions=${agentReasons.join(";")}`);
501
503
  }
502
504
  if (task.briefing !== void 0) {
503
505
  lines.push(
504
- ` briefing_bytes=${Buffer.byteLength(task.briefing, "utf8")} briefing_sha256=${createHash("sha256").update(task.briefing, "utf8").digest("hex")} briefing_preview=${JSON.stringify(safeField(task.briefing))}`
506
+ ` briefing_bytes=${Buffer.byteLength(task.briefing, "utf8")} briefing_sha256=${createHash("sha256").update(task.briefing, "utf8").digest("hex")} briefing_preview=${JSON.stringify(safeField(task.briefing, false))}`
505
507
  );
506
508
  }
507
509
  if (task.intent !== void 0) {
@@ -813,4 +815,4 @@ export {
813
815
  withResolvedDispatchPlan,
814
816
  describeDispatchPlan
815
817
  };
816
- //# sourceMappingURL=chunk-KTYTFRMB.js.map
818
+ //# sourceMappingURL=chunk-VKBMFOYV.js.map
@@ -2,7 +2,7 @@ import { createRequire as __clioCreateRequire } from "node:module"; const requir
2
2
  import {
3
3
  createEngineAi,
4
4
  getEngineSupportedThinkingLevels
5
- } from "./chunk-FCSXB6T2.js";
5
+ } from "./chunk-UOSL25KY.js";
6
6
  import {
7
7
  init_esm_shims
8
8
  } from "./chunk-3R73A4XB.js";
@@ -162,4 +162,4 @@ export {
162
162
  catalogThinkingLevelsForRuntime,
163
163
  synthesizeCatalogBackedModel
164
164
  };
165
- //# sourceMappingURL=chunk-PT7HYKEM.js.map
165
+ //# sourceMappingURL=chunk-VO2LKSTM.js.map
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-H7IXIC72.js";
6
6
  import {
7
7
  isAgentCapabilityClass
8
- } from "./chunk-AOCYTWAV.js";
8
+ } from "./chunk-S4COXYBG.js";
9
9
  import {
10
10
  init_esm_shims
11
11
  } from "./chunk-3R73A4XB.js";
@@ -995,4 +995,4 @@ export {
995
995
  routingIntentRejection,
996
996
  explainRouteDecision
997
997
  };
998
- //# sourceMappingURL=chunk-P43ETTHK.js.map
998
+ //# sourceMappingURL=chunk-VPTUJU4P.js.map
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-CGKSTWHD.js";
8
8
  import {
9
9
  StringEnum
10
- } from "./chunk-FCSXB6T2.js";
10
+ } from "./chunk-UOSL25KY.js";
11
11
  import {
12
12
  init_esm_shims
13
13
  } from "./chunk-3R73A4XB.js";
@@ -29,4 +29,4 @@ var steerToolSurface = {
29
29
  export {
30
30
  steerToolSurface
31
31
  };
32
- //# sourceMappingURL=chunk-WEH5XRJQ.js.map
32
+ //# sourceMappingURL=chunk-WIE7ZOSW.js.map
@@ -4,21 +4,21 @@ import {
4
4
  READONLY_SCOPE,
5
5
  WORKSPACE_SCOPE,
6
6
  isSubset
7
- } from "./chunk-VCBR6CU7.js";
7
+ } from "./chunk-HAY4ZE2P.js";
8
8
  import {
9
9
  createLoopState,
10
10
  observe
11
11
  } from "./chunk-UOV2BYIW.js";
12
12
  import {
13
13
  createSafetyPolicyEngine
14
- } from "./chunk-5H3GB5BO.js";
14
+ } from "./chunk-N3PBVRTZ.js";
15
15
  import {
16
16
  classify
17
- } from "./chunk-AOCYTWAV.js";
17
+ } from "./chunk-S4COXYBG.js";
18
18
  import {
19
19
  BusChannels,
20
20
  isRunAbortedPayload
21
- } from "./chunk-TT36MB5S.js";
21
+ } from "./chunk-RKRLDWD3.js";
22
22
  import {
23
23
  clioStateDir,
24
24
  stateRootRemoved
@@ -608,4 +608,4 @@ var SafetyDomainModule = {
608
608
  export {
609
609
  SafetyDomainModule
610
610
  };
611
- //# sourceMappingURL=chunk-EMYUUSFG.js.map
611
+ //# sourceMappingURL=chunk-WXCJ7VME.js.map
@@ -65,11 +65,15 @@ var DEFAULT_SETTINGS = {
65
65
  everyNTools: 10,
66
66
  windowSteps: 8,
67
67
  maxTokens: 400,
68
- // A memory step runs detached from the turn that triggered it, so a
69
- // generous deadline costs no interactive latency. Measured steps on a
70
- // small local route ranged past two minutes, and a deadline shorter than
71
- // the model discards finished work as a timeout.
72
- timeoutMs: 18e4
68
+ // A memory step runs detached from the turn that triggered it, but it
69
+ // runs on a real inference endpoint that the operator's own turns and
70
+ // dispatched workers also queue against. The operator's ledger over 14
71
+ // days recorded 60 llm-tier steps spending 1,666 seconds of model time
72
+ // for 6 injections, with one step holding a local server for 102.5
73
+ // seconds to answer nothing. The deadline is what a turn boundary can
74
+ // actually wait for; a step that runs past it is recorded as timed out
75
+ // rather than spending the remaining minutes unobserved.
76
+ timeoutMs: 3e4
73
77
  }
74
78
  },
75
79
  watchdog: { enabled: false },
@@ -155,6 +159,9 @@ var DEFAULT_SETTINGS = {
155
159
  context: {
156
160
  workingSet: DEFAULT_WORKING_SET_SETTINGS
157
161
  },
162
+ prewarm: {
163
+ enabled: true
164
+ },
158
165
  retry: {
159
166
  enabled: true,
160
167
  maxRetries: 3,
@@ -237,7 +244,7 @@ memory:
237
244
  everyNTools: 10
238
245
  windowSteps: 8
239
246
  maxTokens: 400
240
- timeoutMs: 180000
247
+ timeoutMs: 30000
241
248
 
242
249
  # Opt-in turn-end watchdog. When enabled, a turn that changed the tree is
243
250
  # reviewed by one read-only verifier run briefed with the turn's coalesced diff
@@ -449,6 +456,14 @@ context:
449
456
  protectLastTurns: 6
450
457
  minEvictableTokens: 200
451
458
 
459
+ # Prompt pre-warm. At session start, after a resume rebuilds the message array,
460
+ # and after a compaction settles, Clio sends the prefix the next turn would send
461
+ # (minus your text) so a local server has already prefilled it when you press
462
+ # Enter. Local-native targets only, interactive sessions only, and never while a
463
+ # turn or a dispatch is running.
464
+ prewarm:
465
+ enabled: true
466
+
452
467
  # Transient provider/stream retry controls for interactive chat.
453
468
  # Retryable errors include overloads, rate limits, 5xx responses, network
454
469
  # resets, and timeouts. Context overflow uses compaction recovery instead.
@@ -497,4 +512,4 @@ export {
497
512
  DEFAULT_SETTINGS,
498
513
  DEFAULT_SETTINGS_YAML
499
514
  };
500
- //# sourceMappingURL=chunk-4DGYLA73.js.map
515
+ //# sourceMappingURL=chunk-XDOQXGFO.js.map
@@ -1,13 +1,13 @@
1
1
  import { createRequire as __clioCreateRequire } from "node:module"; const require = __clioCreateRequire(import.meta.url);
2
2
  import {
3
3
  assistantTextFromEvent
4
- } from "./chunk-HLE42MG7.js";
4
+ } from "./chunk-D73KXYPF.js";
5
5
  import {
6
6
  durableAssistantTextFromEvent
7
- } from "./chunk-TLQJPP24.js";
7
+ } from "./chunk-TEO2TLVN.js";
8
8
  import {
9
9
  compileExecutionPlan
10
- } from "./chunk-J3YUBZWY.js";
10
+ } from "./chunk-HKO36JWF.js";
11
11
  import {
12
12
  deriveExecutionRole
13
13
  } from "./chunk-H7IXIC72.js";
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-6XLNIQDB.js";
17
17
  import {
18
18
  BusChannels
19
- } from "./chunk-TT36MB5S.js";
19
+ } from "./chunk-RKRLDWD3.js";
20
20
  import {
21
21
  init_esm_shims
22
22
  } from "./chunk-3R73A4XB.js";
@@ -276,4 +276,4 @@ export {
276
276
  compileScoutTransition,
277
277
  createDispatchRunEventRegistry
278
278
  };
279
- //# sourceMappingURL=chunk-JOZYP4GM.js.map
279
+ //# sourceMappingURL=chunk-YKOFT37S.js.map
@@ -0,0 +1,127 @@
1
+ import { createRequire as __clioCreateRequire } from "node:module"; const require = __clioCreateRequire(import.meta.url);
2
+ import {
3
+ discoverAgentRecipes
4
+ } from "./chunk-HCBCAYZU.js";
5
+ import {
6
+ assertAgentIdNamespace
7
+ } from "./chunk-DR52UMZW.js";
8
+ import {
9
+ normalizeAgentSpec
10
+ } from "./chunk-S4COXYBG.js";
11
+ import {
12
+ init_esm_shims
13
+ } from "./chunk-3R73A4XB.js";
14
+
15
+ // src/domains/agents/index.ts
16
+ init_esm_shims();
17
+
18
+ // src/domains/agents/extension.ts
19
+ init_esm_shims();
20
+ function createAgentsBundle(_context) {
21
+ let recipes = [];
22
+ let specs = [];
23
+ let diagnostics = [];
24
+ function discover() {
25
+ const nextDiagnostics = [];
26
+ const merged = discoverAgentRecipes(process.cwd(), nextDiagnostics);
27
+ const config = _context.getContract("config");
28
+ assertAgentIdNamespace(merged, config?.get()?.delegation?.agents ?? []);
29
+ recipes = merged;
30
+ specs = recipes.map(normalizeAgentSpec);
31
+ diagnostics = nextDiagnostics;
32
+ }
33
+ const extension = {
34
+ async start() {
35
+ discover();
36
+ },
37
+ async stop() {
38
+ }
39
+ };
40
+ const contract = {
41
+ list() {
42
+ return recipes;
43
+ },
44
+ get(id) {
45
+ return recipes.find((r) => r.id === id) ?? null;
46
+ },
47
+ diagnostics() {
48
+ return diagnostics.map((diagnostic) => ({ ...diagnostic }));
49
+ },
50
+ listSpecs() {
51
+ const config = _context.getContract("config");
52
+ const delegationAgents = config?.get()?.delegation?.agents ?? [];
53
+ const delegationSpecs = delegationAgents.map((agent) => ({
54
+ version: 1,
55
+ id: agent.id,
56
+ name: agent.id,
57
+ description: `External ACP delegation agent: ${agent.command} ${(agent.args ?? []).join(" ")}`,
58
+ source: "custom",
59
+ filepath: "settings.yaml",
60
+ tools: [],
61
+ toolRequirements: { required: [], optional: [] },
62
+ category: "explore",
63
+ capabilityClass: "orchestration",
64
+ latencyClass: "deep",
65
+ projectContextTier: "none",
66
+ audience: "custom",
67
+ tags: ["delegation", "acp"],
68
+ skills: [],
69
+ resultContract: { kind: "external-delegation" },
70
+ budget: { toolCalls: 1, readReserve: 0, synthesis: false },
71
+ body: "External ACP delegation."
72
+ }));
73
+ return [...specs, ...delegationSpecs];
74
+ },
75
+ getSpec(id) {
76
+ const found = specs.find((r) => r.id === id);
77
+ if (found) return found;
78
+ const config = _context.getContract("config");
79
+ const agent = config?.get()?.delegation?.agents?.find((entry) => entry.id === id);
80
+ if (agent) {
81
+ return {
82
+ version: 1,
83
+ id: agent.id,
84
+ name: agent.id,
85
+ description: `External ACP delegation agent: ${agent.command} ${(agent.args ?? []).join(" ")}`,
86
+ source: "custom",
87
+ filepath: "settings.yaml",
88
+ tools: [],
89
+ toolRequirements: { required: [], optional: [] },
90
+ category: "explore",
91
+ capabilityClass: "orchestration",
92
+ latencyClass: "deep",
93
+ projectContextTier: "none",
94
+ audience: "custom",
95
+ tags: ["delegation", "acp"],
96
+ skills: [],
97
+ resultContract: { kind: "external-delegation" },
98
+ budget: { toolCalls: 1, readReserve: 0, synthesis: false },
99
+ body: "External ACP delegation."
100
+ };
101
+ }
102
+ return null;
103
+ },
104
+ reload() {
105
+ discover();
106
+ }
107
+ };
108
+ return { extension, contract };
109
+ }
110
+
111
+ // src/domains/agents/manifest.ts
112
+ init_esm_shims();
113
+ var AgentsManifest = {
114
+ name: "agents",
115
+ dependsOn: ["config"]
116
+ };
117
+
118
+ // src/domains/agents/index.ts
119
+ var AgentsDomainModule = {
120
+ manifest: AgentsManifest,
121
+ createExtension: createAgentsBundle
122
+ };
123
+
124
+ export {
125
+ AgentsDomainModule
126
+ };
127
+ //# sourceMappingURL=chunk-YSEHGPCT.js.map
@@ -14,7 +14,7 @@ import {
14
14
  // src/domains/observability/trace-store.ts
15
15
  init_esm_shims();
16
16
  import { createHash } from "node:crypto";
17
- import { mkdirSync } from "node:fs";
17
+ import { mkdirSync, statSync } from "node:fs";
18
18
  import { createRequire } from "node:module";
19
19
  import { hostname } from "node:os";
20
20
  import { dirname, join } from "node:path";
@@ -23,6 +23,14 @@ var TRACE_DATABASE_FILE = "trace.sqlite";
23
23
  var TRACE_EVENT_POLL_LIMIT = 500;
24
24
  var TRACE_PAYLOAD_LIMIT_BYTES = 16 * 1024;
25
25
  var TRACE_WRITE_QUEUE_LIMIT = 2048;
26
+ var TRACE_RETENTION_DAYS_ENV = "CLIO_CODER_TRACE_RETENTION_DAYS";
27
+ var TRACE_MAX_BYTES_ENV = "CLIO_CODER_TRACE_MAX_BYTES";
28
+ var DEFAULT_TRACE_RETENTION_POLICY = Object.freeze({
29
+ maxAgeDays: 30,
30
+ maxBytes: 128 * 1024 * 1024
31
+ });
32
+ var MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1e3;
33
+ var VACUUM_RECLAIMABLE_FRACTION = 0.2;
26
34
  var sqliteConstructor = null;
27
35
  function warningTracingRequested() {
28
36
  const flagged = (argument) => argument === "--trace-warnings" || argument.startsWith("--trace-warnings=");
@@ -62,6 +70,27 @@ function databaseSyncConstructor() {
62
70
  function traceDatabasePath(stateDir) {
63
71
  return join(stateDir, TRACE_DATABASE_FILE);
64
72
  }
73
+ function resolveTraceRetentionPolicy(overrides = {}, environment = process.env) {
74
+ const maxAgeDays = overrides.maxAgeDays ?? parsePositiveRetentionNumber(environment[TRACE_RETENTION_DAYS_ENV], TRACE_RETENTION_DAYS_ENV, 1);
75
+ const maxBytes = overrides.maxBytes ?? parsePositiveRetentionNumber(environment[TRACE_MAX_BYTES_ENV], TRACE_MAX_BYTES_ENV, 1024 * 1024);
76
+ return {
77
+ maxAgeDays: requirePositiveRetentionNumber(maxAgeDays, TRACE_RETENTION_DAYS_ENV, 1),
78
+ maxBytes: requirePositiveRetentionNumber(maxBytes, TRACE_MAX_BYTES_ENV, 1024 * 1024)
79
+ };
80
+ }
81
+ function parsePositiveRetentionNumber(raw, name, fallback) {
82
+ if (raw === void 0 || raw.trim().length === 0) {
83
+ return name === TRACE_RETENTION_DAYS_ENV ? DEFAULT_TRACE_RETENTION_POLICY.maxAgeDays : DEFAULT_TRACE_RETENTION_POLICY.maxBytes;
84
+ }
85
+ const value = Number(raw);
86
+ return requirePositiveRetentionNumber(value, name, fallback);
87
+ }
88
+ function requirePositiveRetentionNumber(value, name, minimum) {
89
+ if (!Number.isSafeInteger(value) || value < minimum) {
90
+ throw new Error(`${name} must be an integer of at least ${minimum}`);
91
+ }
92
+ return value;
93
+ }
65
94
  var TraceSchemaVersionError = class extends Error {
66
95
  constructor(found) {
67
96
  super(
@@ -221,8 +250,9 @@ function reconcileAbandonedRuns(db) {
221
250
  }
222
251
  }
223
252
  var TraceStore = class {
224
- constructor(path) {
253
+ constructor(path, options = {}) {
225
254
  this.path = path;
255
+ this.retention = resolveTraceRetentionPolicy(options.retention);
226
256
  mkdirSync(dirname(path), { recursive: true });
227
257
  this.db = new (databaseSyncConstructor())(path);
228
258
  applyConnectionPragmas(this.db);
@@ -236,6 +266,7 @@ var TraceStore = class {
236
266
  }
237
267
  path;
238
268
  db;
269
+ retention;
239
270
  close() {
240
271
  this.db.close();
241
272
  }
@@ -249,6 +280,72 @@ var TraceStore = class {
249
280
  throw error;
250
281
  }
251
282
  }
283
+ /**
284
+ * Remove whole terminal runs, including all of their dependent rows.
285
+ *
286
+ * Age pruning runs first. If the allocated database is still above the byte
287
+ * limit, the oldest remaining terminal runs are removed until the live page
288
+ * set fits or only queued/running runs remain. A live run is never a candidate.
289
+ */
290
+ prune(policy = this.retention, now = (/* @__PURE__ */ new Date()).toISOString()) {
291
+ const resolved = resolveTraceRetentionPolicy(policy);
292
+ const nowMs = Date.parse(now);
293
+ if (!Number.isFinite(nowMs)) throw new Error(`trace prune time is invalid: ${now}`);
294
+ const bytesBefore = traceDatabaseFootprintBytes(this.path);
295
+ let rowsRemoved = 0;
296
+ let runsRemoved = 0;
297
+ const removed = /* @__PURE__ */ new Set();
298
+ const cutoff = new Date(Math.max(0, nowMs - resolved.maxAgeDays * MILLISECONDS_PER_DAY)).toISOString();
299
+ const ageCandidates = this.db.prepare(
300
+ "SELECT run_id FROM runs WHERE status IN ('success','fail') AND ended_at IS NOT NULL AND ended_at < ? ORDER BY ended_at, started_at, run_id"
301
+ ).all(cutoff);
302
+ if (ageCandidates.length > 0) {
303
+ this.transaction(() => {
304
+ for (const candidate of ageCandidates) {
305
+ rowsRemoved += deleteTraceRun(this.db, candidate.run_id);
306
+ runsRemoved += 1;
307
+ removed.add(candidate.run_id);
308
+ }
309
+ });
310
+ }
311
+ let pages = tracePageStats(this.db);
312
+ if (pages.usedBytes > resolved.maxBytes) {
313
+ const sizeCandidates = this.db.prepare(
314
+ "SELECT run_id FROM runs WHERE status IN ('success','fail') AND ended_at IS NOT NULL ORDER BY ended_at, started_at, run_id"
315
+ ).all();
316
+ this.transaction(() => {
317
+ for (const candidate of sizeCandidates) {
318
+ if (pages.usedBytes <= resolved.maxBytes) break;
319
+ if (removed.has(candidate.run_id)) continue;
320
+ rowsRemoved += deleteTraceRun(this.db, candidate.run_id);
321
+ runsRemoved += 1;
322
+ removed.add(candidate.run_id);
323
+ pages = tracePageStats(this.db);
324
+ }
325
+ });
326
+ }
327
+ pages = tracePageStats(this.db);
328
+ const reclaimableFraction = pages.pageCount === 0 ? 0 : pages.freePages / pages.pageCount;
329
+ const sizeNeedsReclaim = pages.allocatedBytes > resolved.maxBytes && pages.freePages > 0;
330
+ const vacuumed = rowsRemoved > 0 && pages.freePages > 0 && (reclaimableFraction >= VACUUM_RECLAIMABLE_FRACTION || sizeNeedsReclaim);
331
+ if (vacuumed) {
332
+ this.db.exec("VACUUM");
333
+ this.db.prepare("PRAGMA wal_checkpoint(TRUNCATE)").get();
334
+ }
335
+ const protectedRuns = Number(
336
+ this.db.prepare("SELECT COUNT(*) AS count FROM runs WHERE status IN ('queued','running')").get().count
337
+ );
338
+ const bytesAfter = traceDatabaseFootprintBytes(this.path);
339
+ return {
340
+ runsRemoved,
341
+ rowsRemoved,
342
+ bytesBefore,
343
+ bytesAfter,
344
+ bytesRemoved: Math.max(0, bytesBefore - bytesAfter),
345
+ vacuumed,
346
+ protectedRuns
347
+ };
348
+ }
252
349
  upsertRun(input, at = (/* @__PURE__ */ new Date()).toISOString()) {
253
350
  this.transaction(() => {
254
351
  this.db.prepare(`INSERT INTO runs
@@ -533,6 +630,7 @@ var TraceStore = class {
533
630
  startedAt: at
534
631
  });
535
632
  });
633
+ this.prune(this.retention, at);
536
634
  }
537
635
  /**
538
636
  * Record one fact about a turn the operator ran in the chat loop.
@@ -634,8 +732,42 @@ var TraceStore = class {
634
732
  startedAt: input.at
635
733
  });
636
734
  });
735
+ this.prune(this.retention, input.at);
637
736
  }
638
737
  };
738
+ function tracePageStats(db) {
739
+ const pageSize = Number(db.prepare("PRAGMA page_size").get().page_size);
740
+ const pageCount = Number(db.prepare("PRAGMA page_count").get().page_count);
741
+ const freePages = Number(
742
+ db.prepare("PRAGMA freelist_count").get().freelist_count
743
+ );
744
+ return {
745
+ pageCount,
746
+ freePages,
747
+ allocatedBytes: pageCount * pageSize,
748
+ usedBytes: Math.max(0, pageCount - freePages) * pageSize
749
+ };
750
+ }
751
+ function deleteTraceRun(db, runId) {
752
+ let rows = 0;
753
+ for (const table of ["events", "envelopes", "gate_results", "agent_sessions", "processes", "phases", "runs"]) {
754
+ const result = db.prepare(`DELETE FROM ${table} WHERE run_id=?`).run(runId);
755
+ rows += Number(result.changes);
756
+ }
757
+ return rows;
758
+ }
759
+ function traceDatabaseFootprintBytes(path) {
760
+ let total = 0;
761
+ for (const candidate of [path, `${path}-wal`, `${path}-shm`]) {
762
+ try {
763
+ total += statSync(candidate).size;
764
+ } catch (error) {
765
+ const code = typeof error === "object" && error !== null && "code" in error ? String(error.code) : "";
766
+ if (code !== "ENOENT") throw error;
767
+ }
768
+ }
769
+ return total;
770
+ }
639
771
  var TraceReader = class {
640
772
  constructor(path) {
641
773
  this.path = path;
@@ -991,8 +1123,11 @@ function finiteNonNegative(value) {
991
1123
 
992
1124
  export {
993
1125
  TRACE_EVENT_POLL_LIMIT,
1126
+ DEFAULT_TRACE_RETENTION_POLICY,
994
1127
  traceDatabasePath,
1128
+ resolveTraceRetentionPolicy,
1129
+ TraceStore,
995
1130
  TraceReader,
996
1131
  createDispatchTraceMirror
997
1132
  };
998
- //# sourceMappingURL=chunk-HFSBBKSQ.js.map
1133
+ //# sourceMappingURL=chunk-YW7UVM5V.js.map