@wrongstack/core 0.296.4 → 0.298.0

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 (820) hide show
  1. package/dist/chronicle/index.js +126 -22
  2. package/dist/chronicle/project-server-client.d.ts +12 -0
  3. package/dist/chronicle/project-server-protocol.d.ts +22 -0
  4. package/dist/chronicle/project-server.js +1076 -283
  5. package/dist/coordination/agents/index.js +136 -1
  6. package/dist/coordination/agents/role-skills.d.ts +3 -2
  7. package/dist/coordination/brain-cache.d.ts +14 -0
  8. package/dist/coordination/brain-trace.d.ts +2 -1
  9. package/dist/coordination/director/director-task-registry.d.ts +12 -0
  10. package/dist/coordination/fleet-supervisor.d.ts +21 -0
  11. package/dist/coordination/index.d.ts +23 -21
  12. package/dist/coordination/index.js +16514 -15945
  13. package/dist/coordination/mail-tools.d.ts +3 -3
  14. package/dist/coordination/mailbox-credential-store.d.ts +22 -2
  15. package/dist/coordination/mailbox-credential-throttle.d.ts +63 -0
  16. package/dist/coordination/mailbox-http-router.d.ts +6 -0
  17. package/dist/coordination/mailbox-project-server-client.d.ts +16 -0
  18. package/dist/coordination/mailbox-project-server-protocol.d.ts +43 -5
  19. package/dist/coordination/mailbox-project-server.js +1270 -289
  20. package/dist/coordination/provider-status-tracker.d.ts +2 -0
  21. package/dist/coordination/remote-mailbox-credential-store.d.ts +5 -5
  22. package/dist/coordination/remote-mailbox.d.ts +30 -4
  23. package/dist/coordination/sqlite-mailbox-credentials.d.ts +11 -0
  24. package/dist/core/context.d.ts +5 -5
  25. package/dist/core/fallback-profile-manager.d.ts +14 -0
  26. package/dist/core/index.js +624 -168
  27. package/dist/core/instruction-bundle.d.ts +12 -0
  28. package/dist/core/system-prompt-builder.d.ts +14 -0
  29. package/dist/core/system-prompt-skill-bodies.d.ts +1 -1
  30. package/dist/core/system-prompt-skill-text.d.ts +1 -2
  31. package/dist/defaults/index.js +2393 -1302
  32. package/dist/design/index.js +47 -8
  33. package/dist/execution/design-materialize.d.ts +22 -0
  34. package/dist/execution/index.js +582 -285
  35. package/dist/execution/skill-loader.d.ts +10 -1
  36. package/dist/execution/tool-error-taxonomy.d.ts +31 -0
  37. package/dist/execution/tool-executor.d.ts +1 -0
  38. package/dist/goal/index.js +71 -17
  39. package/dist/goal/phase-store.d.ts +7 -0
  40. package/dist/hooks/index.js +5 -0
  41. package/dist/hq/auth-audit.d.ts +6 -0
  42. package/dist/hq/auth-store.d.ts +59 -3
  43. package/dist/hq/index.js +680 -163
  44. package/dist/hq/kanban-store.d.ts +3 -0
  45. package/dist/hq/persistence/event-log.d.ts +25 -0
  46. package/dist/hq/persistence.d.ts +1 -1
  47. package/dist/hq/protocol/browser.d.ts +2 -1
  48. package/dist/hq/protocol/client.d.ts +18 -1
  49. package/dist/hq/protocol/core.d.ts +5 -16
  50. package/dist/hq/protocol/envelope.d.ts +29 -0
  51. package/dist/hq/protocol/governance.d.ts +34 -0
  52. package/dist/hq/protocol/peer.d.ts +55 -0
  53. package/dist/hq/protocol/project.d.ts +3 -0
  54. package/dist/hq/protocol/resume.d.ts +56 -0
  55. package/dist/hq/protocol.d.ts +11 -8
  56. package/dist/hq/protocol.js +675 -0
  57. package/dist/hq/publisher.d.ts +31 -2
  58. package/dist/hq/session-bridge.d.ts +8 -0
  59. package/dist/index.js +7197 -4006
  60. package/dist/infrastructure/index.js +198 -101
  61. package/dist/kernel/events/session-events.d.ts +3 -0
  62. package/dist/kernel/events/tool-events.d.ts +3 -1
  63. package/dist/models/index.js +1 -1
  64. package/dist/observability/index.d.ts +1 -1
  65. package/dist/observability/index.js +103 -5
  66. package/dist/observability/metrics.d.ts +37 -0
  67. package/dist/observability/prometheus.d.ts +11 -0
  68. package/dist/plugin/index.d.ts +5 -1
  69. package/dist/plugin/index.js +965 -511
  70. package/dist/plugins/auto-review-plugin.d.ts +6 -0
  71. package/dist/plugins/review-store-maintenance.d.ts +26 -0
  72. package/dist/plugins/review-types.d.ts +6 -0
  73. package/dist/security/capabilities.d.ts +45 -1
  74. package/dist/security/error-sanitize.d.ts +49 -0
  75. package/dist/security/file-permissions.d.ts +41 -0
  76. package/dist/security/index.d.ts +9 -6
  77. package/dist/security/index.js +3007 -2032
  78. package/dist/security/permission-policy.d.ts +55 -3
  79. package/dist/security/secret-vault.d.ts +17 -0
  80. package/dist/security/totp.d.ts +86 -0
  81. package/dist/skills/frontmatter.d.ts +12 -1
  82. package/dist/skills/github-fetcher.d.ts +48 -0
  83. package/dist/skills/index.js +137 -26
  84. package/dist/skills/limits.d.ts +19 -0
  85. package/dist/skills/skill-installer.d.ts +13 -0
  86. package/dist/storage/file-session-writer.d.ts +23 -0
  87. package/dist/storage/index.js +1140 -905
  88. package/dist/storage/provider-config-watcher.d.ts +1 -0
  89. package/dist/storage/session-helpers.d.ts +1 -0
  90. package/dist/storage/session-reader.d.ts +0 -7
  91. package/dist/storage/session-store/types.d.ts +12 -1
  92. package/dist/storage/session-store.d.ts +11 -2
  93. package/dist/storage/session-workspace-checkpoints.d.ts +5 -0
  94. package/dist/tools/fallback-manage-tools.d.ts +6 -0
  95. package/dist/tools/index.js +305 -133
  96. package/dist/tools/mcp-use.d.ts +1 -1
  97. package/dist/types/blocks.d.ts +7 -0
  98. package/dist/types/config/autonomy.d.ts +12 -3
  99. package/dist/types/config/mcp-features.d.ts +15 -1
  100. package/dist/types/config/root.d.ts +10 -4
  101. package/dist/types/context-window.d.ts +15 -0
  102. package/dist/types/index.d.ts +1 -1
  103. package/dist/types/observability.d.ts +13 -0
  104. package/dist/types/secret-vault.d.ts +8 -0
  105. package/dist/types/session.d.ts +42 -0
  106. package/dist/types/skill.d.ts +56 -0
  107. package/dist/types/tool-executor.d.ts +2 -0
  108. package/dist/utils/continuous-memory-profiler.d.ts +35 -0
  109. package/dist/utils/env-typed.d.ts +64 -0
  110. package/dist/utils/glob-match.d.ts +21 -1
  111. package/dist/utils/heap-watchdog-types.d.ts +62 -0
  112. package/dist/utils/heap-watchdog.d.ts +15 -34
  113. package/dist/utils/heap-watchdog.js +592 -18
  114. package/dist/utils/incoming-images.d.ts +19 -0
  115. package/dist/utils/index.d.ts +15 -11
  116. package/dist/utils/index.js +1425 -545
  117. package/dist/utils/memory-flight-recorder.d.ts +47 -0
  118. package/dist/utils/path-segment.d.ts +29 -0
  119. package/dist/utils/tool-name.d.ts +34 -0
  120. package/dist/utils/win32-cmd.d.ts +25 -0
  121. package/dist/worktree/index.js +5 -0
  122. package/package.json +11 -3
  123. package/skills/chimera/SKILL.md +16 -4
  124. package/skills/data-governance/SKILL.md +92 -0
  125. package/skills/wrongstack-kanban/SKILL.md +129 -0
  126. package/skills/wrongstack-kanban/agents/openai.yaml +4 -0
  127. package/skills/wrongstack-mailbox-mcp/SKILL.md +72 -0
  128. package/skills/wrongstack-mailbox-mcp/agents/openai.yaml +4 -0
  129. package/dist/agent-status-helpers.d.ts.map +0 -1
  130. package/dist/agent-status-tracker.d.ts.map +0 -1
  131. package/dist/boot.d.ts.map +0 -1
  132. package/dist/chronicle/context.d.ts.map +0 -1
  133. package/dist/chronicle/decision-adapter.d.ts.map +0 -1
  134. package/dist/chronicle/domain-adapter.d.ts.map +0 -1
  135. package/dist/chronicle/event-hash.d.ts.map +0 -1
  136. package/dist/chronicle/file-observer.d.ts.map +0 -1
  137. package/dist/chronicle/health-monitor.d.ts.map +0 -1
  138. package/dist/chronicle/identity.d.ts.map +0 -1
  139. package/dist/chronicle/index.d.ts.map +0 -1
  140. package/dist/chronicle/index.js.map +0 -7
  141. package/dist/chronicle/journal.d.ts.map +0 -1
  142. package/dist/chronicle/legacy-journal-import.d.ts.map +0 -1
  143. package/dist/chronicle/metrics-store.d.ts.map +0 -1
  144. package/dist/chronicle/partition-filename.d.ts.map +0 -1
  145. package/dist/chronicle/partition-range-cache.d.ts.map +0 -1
  146. package/dist/chronicle/process-adapter.d.ts.map +0 -1
  147. package/dist/chronicle/project-access.d.ts.map +0 -1
  148. package/dist/chronicle/project-server-client.d.ts.map +0 -1
  149. package/dist/chronicle/project-server-endpoint.d.ts.map +0 -1
  150. package/dist/chronicle/project-server-protocol.d.ts.map +0 -1
  151. package/dist/chronicle/project-server.d.ts.map +0 -1
  152. package/dist/chronicle/project-server.js.map +0 -7
  153. package/dist/chronicle/prompt-manifest.d.ts.map +0 -1
  154. package/dist/chronicle/provider-adapter.d.ts.map +0 -1
  155. package/dist/chronicle/query.d.ts.map +0 -1
  156. package/dist/chronicle/review-adapter.d.ts.map +0 -1
  157. package/dist/chronicle/rollup-adapter.d.ts.map +0 -1
  158. package/dist/chronicle/sink.d.ts.map +0 -1
  159. package/dist/chronicle/sqlite-journal.d.ts.map +0 -1
  160. package/dist/chronicle/sqlite-query.d.ts.map +0 -1
  161. package/dist/chronicle/stream-adapter.d.ts.map +0 -1
  162. package/dist/chronicle/tool-adapter.d.ts.map +0 -1
  163. package/dist/chronicle/types.d.ts.map +0 -1
  164. package/dist/coordination/adaptive-concurrency.d.ts.map +0 -1
  165. package/dist/coordination/agent-bridge.d.ts.map +0 -1
  166. package/dist/coordination/agent-monitor.d.ts.map +0 -1
  167. package/dist/coordination/agent-subagent-runner.d.ts.map +0 -1
  168. package/dist/coordination/agents/agent-prompts.d.ts.map +0 -1
  169. package/dist/coordination/agents/index.d.ts.map +0 -1
  170. package/dist/coordination/agents/index.js.map +0 -7
  171. package/dist/coordination/agents/phase1-discovery.d.ts.map +0 -1
  172. package/dist/coordination/agents/phase2-planning.d.ts.map +0 -1
  173. package/dist/coordination/agents/phase3-build.d.ts.map +0 -1
  174. package/dist/coordination/agents/phase3-techstack.d.ts.map +0 -1
  175. package/dist/coordination/agents/phase3-wave1-platform.d.ts.map +0 -1
  176. package/dist/coordination/agents/phase3-wave2-meta.d.ts.map +0 -1
  177. package/dist/coordination/agents/phase4-verify.d.ts.map +0 -1
  178. package/dist/coordination/agents/phase5-review.d.ts.map +0 -1
  179. package/dist/coordination/agents/phase6-domain.d.ts.map +0 -1
  180. package/dist/coordination/agents/phase7-knowledge.d.ts.map +0 -1
  181. package/dist/coordination/agents/phase8-delivery.d.ts.map +0 -1
  182. package/dist/coordination/agents/phase8-wave3-products.d.ts.map +0 -1
  183. package/dist/coordination/agents/phase9-meta.d.ts.map +0 -1
  184. package/dist/coordination/agents/phase9-wave4-platform-meta.d.ts.map +0 -1
  185. package/dist/coordination/agents/project-agent-config-validation.d.ts.map +0 -1
  186. package/dist/coordination/agents/project-agent-consolidation.d.ts.map +0 -1
  187. package/dist/coordination/agents/project-agent-files.d.ts.map +0 -1
  188. package/dist/coordination/agents/project-agent-identity-types.d.ts.map +0 -1
  189. package/dist/coordination/agents/project-agent-identity.d.ts.map +0 -1
  190. package/dist/coordination/agents/project-agent-knowledge-manifests.d.ts.map +0 -1
  191. package/dist/coordination/agents/project-agent-learning-entries.d.ts.map +0 -1
  192. package/dist/coordination/agents/project-agent-learning-normalize.d.ts.map +0 -1
  193. package/dist/coordination/agents/project-agent-learning-policy.d.ts.map +0 -1
  194. package/dist/coordination/agents/project-agent-learning-structured.d.ts.map +0 -1
  195. package/dist/coordination/agents/project-agent-paths.d.ts.map +0 -1
  196. package/dist/coordination/agents/project-agent-profile.d.ts.map +0 -1
  197. package/dist/coordination/agents/role-skills.d.ts.map +0 -1
  198. package/dist/coordination/agents/types.d.ts.map +0 -1
  199. package/dist/coordination/agents.d.ts.map +0 -1
  200. package/dist/coordination/auto-extend.d.ts.map +0 -1
  201. package/dist/coordination/autonomous-brain.d.ts.map +0 -1
  202. package/dist/coordination/autonomous-coordinator.d.ts.map +0 -1
  203. package/dist/coordination/brain-cache.d.ts.map +0 -1
  204. package/dist/coordination/brain-heuristics.d.ts.map +0 -1
  205. package/dist/coordination/brain-ledger.d.ts.map +0 -1
  206. package/dist/coordination/brain-monitor.d.ts.map +0 -1
  207. package/dist/coordination/brain-rules.d.ts.map +0 -1
  208. package/dist/coordination/brain-telemetry.d.ts.map +0 -1
  209. package/dist/coordination/brain-trace.d.ts.map +0 -1
  210. package/dist/coordination/brain.d.ts.map +0 -1
  211. package/dist/coordination/change-manager.d.ts.map +0 -1
  212. package/dist/coordination/checkpoint-wiring.d.ts.map +0 -1
  213. package/dist/coordination/collab-bus.d.ts.map +0 -1
  214. package/dist/coordination/collab-debug-types.d.ts.map +0 -1
  215. package/dist/coordination/collab-debug.d.ts.map +0 -1
  216. package/dist/coordination/collab-director-host.d.ts.map +0 -1
  217. package/dist/coordination/commit-safety.d.ts.map +0 -1
  218. package/dist/coordination/consensus-protocol.d.ts.map +0 -1
  219. package/dist/coordination/coordinator/error-classifier.d.ts.map +0 -1
  220. package/dist/coordination/delegate-tool.d.ts.map +0 -1
  221. package/dist/coordination/dep-watcher-bridge.d.ts.map +0 -1
  222. package/dist/coordination/dep-watcher.d.ts.map +0 -1
  223. package/dist/coordination/director/director-btw-notes.d.ts.map +0 -1
  224. package/dist/coordination/director/director-budget-policy.d.ts.map +0 -1
  225. package/dist/coordination/director/director-collab.d.ts.map +0 -1
  226. package/dist/coordination/director/director-errors.d.ts.map +0 -1
  227. package/dist/coordination/director/director-task-registry.d.ts.map +0 -1
  228. package/dist/coordination/director/director-toolset.d.ts.map +0 -1
  229. package/dist/coordination/director-basic-tools.d.ts.map +0 -1
  230. package/dist/coordination/director-collab-tools.d.ts.map +0 -1
  231. package/dist/coordination/director-host-contracts.d.ts.map +0 -1
  232. package/dist/coordination/director-input-helpers.d.ts.map +0 -1
  233. package/dist/coordination/director-kanban-queue-helpers.d.ts.map +0 -1
  234. package/dist/coordination/director-options.d.ts.map +0 -1
  235. package/dist/coordination/director-prompts.d.ts.map +0 -1
  236. package/dist/coordination/director-quality-gate-tool.d.ts.map +0 -1
  237. package/dist/coordination/director-session.d.ts.map +0 -1
  238. package/dist/coordination/director-spawn-model.d.ts.map +0 -1
  239. package/dist/coordination/director-tools.d.ts.map +0 -1
  240. package/dist/coordination/director.d.ts.map +0 -1
  241. package/dist/coordination/dispatcher.d.ts.map +0 -1
  242. package/dist/coordination/file-author-tracker.d.ts.map +0 -1
  243. package/dist/coordination/fleet-bus.d.ts.map +0 -1
  244. package/dist/coordination/fleet-event-validation.d.ts.map +0 -1
  245. package/dist/coordination/fleet-manager.d.ts.map +0 -1
  246. package/dist/coordination/fleet-spawn.d.ts.map +0 -1
  247. package/dist/coordination/fleet-status-tool.d.ts.map +0 -1
  248. package/dist/coordination/fleet-supervisor.d.ts.map +0 -1
  249. package/dist/coordination/fleet.d.ts.map +0 -1
  250. package/dist/coordination/global-mailbox-completion.d.ts.map +0 -1
  251. package/dist/coordination/global-mailbox-paths.d.ts.map +0 -1
  252. package/dist/coordination/icoordinator.d.ts.map +0 -1
  253. package/dist/coordination/ifleet-manager.d.ts.map +0 -1
  254. package/dist/coordination/in-memory-transport.d.ts.map +0 -1
  255. package/dist/coordination/index.d.ts.map +0 -1
  256. package/dist/coordination/index.js.map +0 -7
  257. package/dist/coordination/knowledge-graph.d.ts.map +0 -1
  258. package/dist/coordination/large-answer-store.d.ts.map +0 -1
  259. package/dist/coordination/mail-tools.d.ts.map +0 -1
  260. package/dist/coordination/mailbox-actions.d.ts.map +0 -1
  261. package/dist/coordination/mailbox-auth-types.d.ts.map +0 -1
  262. package/dist/coordination/mailbox-codecs.d.ts.map +0 -1
  263. package/dist/coordination/mailbox-constants.d.ts.map +0 -1
  264. package/dist/coordination/mailbox-credential-store.d.ts.map +0 -1
  265. package/dist/coordination/mailbox-events.d.ts.map +0 -1
  266. package/dist/coordination/mailbox-health.d.ts.map +0 -1
  267. package/dist/coordination/mailbox-hooks.d.ts.map +0 -1
  268. package/dist/coordination/mailbox-http-auth.d.ts.map +0 -1
  269. package/dist/coordination/mailbox-http-rate-limit.d.ts.map +0 -1
  270. package/dist/coordination/mailbox-http-router.d.ts.map +0 -1
  271. package/dist/coordination/mailbox-http-validation.d.ts.map +0 -1
  272. package/dist/coordination/mailbox-message-codec.d.ts.map +0 -1
  273. package/dist/coordination/mailbox-parse-state.d.ts.map +0 -1
  274. package/dist/coordination/mailbox-project-server-client.d.ts.map +0 -1
  275. package/dist/coordination/mailbox-project-server-endpoint.d.ts.map +0 -1
  276. package/dist/coordination/mailbox-project-server-protocol.d.ts.map +0 -1
  277. package/dist/coordination/mailbox-project-server.d.ts.map +0 -1
  278. package/dist/coordination/mailbox-project-server.js.map +0 -7
  279. package/dist/coordination/mailbox-receipt-folding.d.ts.map +0 -1
  280. package/dist/coordination/mailbox-registry-codec.d.ts.map +0 -1
  281. package/dist/coordination/mailbox-retention-state.d.ts.map +0 -1
  282. package/dist/coordination/mailbox-status-mappers.d.ts.map +0 -1
  283. package/dist/coordination/mailbox-tool.d.ts.map +0 -1
  284. package/dist/coordination/mailbox-type-properties.d.ts.map +0 -1
  285. package/dist/coordination/mailbox-types.d.ts.map +0 -1
  286. package/dist/coordination/model-matrix.d.ts.map +0 -1
  287. package/dist/coordination/multi-agent-coordinator.d.ts.map +0 -1
  288. package/dist/coordination/multi-agent-timeout.d.ts.map +0 -1
  289. package/dist/coordination/null-fleet-bus.d.ts.map +0 -1
  290. package/dist/coordination/package-author-tracker.d.ts.map +0 -1
  291. package/dist/coordination/package-outdated-watcher.d.ts.map +0 -1
  292. package/dist/coordination/provider-status-tracker.d.ts.map +0 -1
  293. package/dist/coordination/remote-mailbox-credential-store.d.ts.map +0 -1
  294. package/dist/coordination/remote-mailbox.d.ts.map +0 -1
  295. package/dist/coordination/single-instance-mailbox.d.ts.map +0 -1
  296. package/dist/coordination/spawn-budget.d.ts.map +0 -1
  297. package/dist/coordination/sqlite-mailbox-compaction.d.ts.map +0 -1
  298. package/dist/coordination/sqlite-mailbox-credentials.d.ts.map +0 -1
  299. package/dist/coordination/sqlite-mailbox-rows.d.ts.map +0 -1
  300. package/dist/coordination/sqlite-mailbox-schema.d.ts.map +0 -1
  301. package/dist/coordination/sqlite-mailbox.d.ts.map +0 -1
  302. package/dist/coordination/subagent-budget.d.ts.map +0 -1
  303. package/dist/coordination/subagent-nicknames.d.ts.map +0 -1
  304. package/dist/coordination/subagent-result-tool.d.ts.map +0 -1
  305. package/dist/coordination/task-auctioneer.d.ts.map +0 -1
  306. package/dist/coordination/task-dag.d.ts.map +0 -1
  307. package/dist/coordination/techstack-mailbox-consumer.d.ts.map +0 -1
  308. package/dist/coordination/transport.d.ts.map +0 -1
  309. package/dist/coordination/worktree-task-runner.d.ts.map +0 -1
  310. package/dist/core/agent-internals.d.ts.map +0 -1
  311. package/dist/core/agent-loop.d.ts.map +0 -1
  312. package/dist/core/agent-response.d.ts.map +0 -1
  313. package/dist/core/agent-tools.d.ts.map +0 -1
  314. package/dist/core/agent-types.d.ts.map +0 -1
  315. package/dist/core/agent.d.ts.map +0 -1
  316. package/dist/core/btw.d.ts.map +0 -1
  317. package/dist/core/context.d.ts.map +0 -1
  318. package/dist/core/continue-intent.d.ts.map +0 -1
  319. package/dist/core/continue-to-next-iteration.d.ts.map +0 -1
  320. package/dist/core/conversation-state.d.ts.map +0 -1
  321. package/dist/core/fallback-model.d.ts.map +0 -1
  322. package/dist/core/fallback-profile-manager.d.ts.map +0 -1
  323. package/dist/core/fleet-pulse.d.ts.map +0 -1
  324. package/dist/core/index.d.ts.map +0 -1
  325. package/dist/core/index.js.map +0 -7
  326. package/dist/core/input-builder.d.ts.map +0 -1
  327. package/dist/core/instruction-bundle.d.ts.map +0 -1
  328. package/dist/core/iteration-limit.d.ts.map +0 -1
  329. package/dist/core/mailbox-loop.d.ts.map +0 -1
  330. package/dist/core/model-availability-calendar.d.ts.map +0 -1
  331. package/dist/core/model-ref.d.ts.map +0 -1
  332. package/dist/core/model-ref.js.map +0 -7
  333. package/dist/core/modes/brief.d.ts.map +0 -1
  334. package/dist/core/modes/default.d.ts.map +0 -1
  335. package/dist/core/modes/teach.d.ts.map +0 -1
  336. package/dist/core/provider-runner.d.ts.map +0 -1
  337. package/dist/core/queued-messages.d.ts.map +0 -1
  338. package/dist/core/request-provider-binding.d.ts.map +0 -1
  339. package/dist/core/run-env.d.ts.map +0 -1
  340. package/dist/core/streaming-response-builder.d.ts.map +0 -1
  341. package/dist/core/system-prompt-blocks.d.ts.map +0 -1
  342. package/dist/core/system-prompt-builder.d.ts.map +0 -1
  343. package/dist/core/system-prompt-environment-probes.d.ts.map +0 -1
  344. package/dist/core/system-prompt-environment.d.ts.map +0 -1
  345. package/dist/core/system-prompt-memory-skills.d.ts.map +0 -1
  346. package/dist/core/system-prompt-plan.d.ts.map +0 -1
  347. package/dist/core/system-prompt-shell.d.ts.map +0 -1
  348. package/dist/core/system-prompt-skill-bodies.d.ts.map +0 -1
  349. package/dist/core/system-prompt-skill-text.d.ts.map +0 -1
  350. package/dist/defaults/index.d.ts.map +0 -1
  351. package/dist/defaults/index.js.map +0 -7
  352. package/dist/design/index.d.ts.map +0 -1
  353. package/dist/design/index.js.map +0 -7
  354. package/dist/execution/auto-compaction-middleware.d.ts.map +0 -1
  355. package/dist/execution/autonomous-runner.d.ts.map +0 -1
  356. package/dist/execution/autonomy-brain.d.ts.map +0 -1
  357. package/dist/execution/autonomy-prompt-contributor.d.ts.map +0 -1
  358. package/dist/execution/brain-chain.d.ts.map +0 -1
  359. package/dist/execution/brain-circuit.d.ts.map +0 -1
  360. package/dist/execution/brain-evaluation.d.ts.map +0 -1
  361. package/dist/execution/brain-runtime-constants.d.ts.map +0 -1
  362. package/dist/execution/brain-runtime.d.ts.map +0 -1
  363. package/dist/execution/compaction-core.d.ts.map +0 -1
  364. package/dist/execution/compaction-scoring.d.ts.map +0 -1
  365. package/dist/execution/compaction-summary-cache.d.ts.map +0 -1
  366. package/dist/execution/compactor.d.ts.map +0 -1
  367. package/dist/execution/council-brain.d.ts.map +0 -1
  368. package/dist/execution/council-orchestrator.d.ts.map +0 -1
  369. package/dist/execution/council-personas.d.ts.map +0 -1
  370. package/dist/execution/council-profiles.d.ts.map +0 -1
  371. package/dist/execution/council-prompts.d.ts.map +0 -1
  372. package/dist/execution/council-resolution.d.ts.map +0 -1
  373. package/dist/execution/design-color.d.ts.map +0 -1
  374. package/dist/execution/design-detect.d.ts.map +0 -1
  375. package/dist/execution/design-kit-loader.d.ts.map +0 -1
  376. package/dist/execution/design-materialize.d.ts.map +0 -1
  377. package/dist/execution/design-project-store.d.ts.map +0 -1
  378. package/dist/execution/design-tune.d.ts.map +0 -1
  379. package/dist/execution/design-verify.d.ts.map +0 -1
  380. package/dist/execution/enhance-recovery.d.ts.map +0 -1
  381. package/dist/execution/error-handler.d.ts.map +0 -1
  382. package/dist/execution/eternal-autonomy-types.d.ts.map +0 -1
  383. package/dist/execution/eternal-autonomy.d.ts.map +0 -1
  384. package/dist/execution/goal-preamble.d.ts.map +0 -1
  385. package/dist/execution/index.d.ts.map +0 -1
  386. package/dist/execution/index.js.map +0 -7
  387. package/dist/execution/intelligent-compactor.d.ts.map +0 -1
  388. package/dist/execution/model-runtime.d.ts.map +0 -1
  389. package/dist/execution/one-shot-llm.d.ts.map +0 -1
  390. package/dist/execution/parallel-eternal-engine.d.ts.map +0 -1
  391. package/dist/execution/prompt-enhancer.d.ts.map +0 -1
  392. package/dist/execution/prompt-enhancer.js.map +0 -7
  393. package/dist/execution/prompt-loader.d.ts.map +0 -1
  394. package/dist/execution/provider-runner-impl.d.ts.map +0 -1
  395. package/dist/execution/regex-patterns.d.ts.map +0 -1
  396. package/dist/execution/retry-policy.d.ts.map +0 -1
  397. package/dist/execution/selective-compactor.d.ts.map +0 -1
  398. package/dist/execution/skill-loader.d.ts.map +0 -1
  399. package/dist/execution/strategy-compactor.d.ts.map +0 -1
  400. package/dist/execution/subagent-compaction.d.ts.map +0 -1
  401. package/dist/execution/tool-executor-logging.d.ts.map +0 -1
  402. package/dist/execution/tool-executor-results.d.ts.map +0 -1
  403. package/dist/execution/tool-executor-stream.d.ts.map +0 -1
  404. package/dist/execution/tool-executor-support.d.ts.map +0 -1
  405. package/dist/execution/tool-executor.d.ts.map +0 -1
  406. package/dist/extension/extension-points.d.ts.map +0 -1
  407. package/dist/extension/index.d.ts.map +0 -1
  408. package/dist/extension/index.js.map +0 -7
  409. package/dist/extension/registry.d.ts.map +0 -1
  410. package/dist/fleet-notifier.d.ts.map +0 -1
  411. package/dist/goal/checkpoint.d.ts.map +0 -1
  412. package/dist/goal/goal-assessor.d.ts.map +0 -1
  413. package/dist/goal/goal-planner.d.ts.map +0 -1
  414. package/dist/goal/goal-runner.d.ts.map +0 -1
  415. package/dist/goal/index.d.ts.map +0 -1
  416. package/dist/goal/index.js.map +0 -7
  417. package/dist/goal/phase-board-mutations.d.ts.map +0 -1
  418. package/dist/goal/phase-graph-builder.d.ts.map +0 -1
  419. package/dist/goal/phase-orchestrator-integration.d.ts.map +0 -1
  420. package/dist/goal/phase-orchestrator-queries.d.ts.map +0 -1
  421. package/dist/goal/phase-orchestrator-runtime.d.ts.map +0 -1
  422. package/dist/goal/phase-orchestrator-types.d.ts.map +0 -1
  423. package/dist/goal/phase-orchestrator.d.ts.map +0 -1
  424. package/dist/goal/phase-store.d.ts.map +0 -1
  425. package/dist/goal/types.d.ts.map +0 -1
  426. package/dist/hooks/http-executor.d.ts.map +0 -1
  427. package/dist/hooks/index.d.ts.map +0 -1
  428. package/dist/hooks/index.js.map +0 -7
  429. package/dist/hooks/registry.d.ts.map +0 -1
  430. package/dist/hooks/runner.d.ts.map +0 -1
  431. package/dist/hooks/shell-executor.d.ts.map +0 -1
  432. package/dist/hooks/shell-hooks-equal.d.ts.map +0 -1
  433. package/dist/hq/alerts.d.ts.map +0 -1
  434. package/dist/hq/auth-audit.d.ts.map +0 -1
  435. package/dist/hq/auth-store.d.ts.map +0 -1
  436. package/dist/hq/bootstrap-store.d.ts.map +0 -1
  437. package/dist/hq/brain-bridge.d.ts.map +0 -1
  438. package/dist/hq/bridge-context.d.ts.map +0 -1
  439. package/dist/hq/commands.d.ts.map +0 -1
  440. package/dist/hq/cost-bridge.d.ts.map +0 -1
  441. package/dist/hq/exposure.d.ts.map +0 -1
  442. package/dist/hq/factory.d.ts.map +0 -1
  443. package/dist/hq/fleet-bridge.d.ts.map +0 -1
  444. package/dist/hq/index.d.ts.map +0 -1
  445. package/dist/hq/index.js.map +0 -7
  446. package/dist/hq/kanban-store.d.ts.map +0 -1
  447. package/dist/hq/mailbox-mapper.d.ts.map +0 -1
  448. package/dist/hq/persistence/event-log.d.ts.map +0 -1
  449. package/dist/hq/persistence/jsonl-io.d.ts.map +0 -1
  450. package/dist/hq/persistence/simple-log.d.ts.map +0 -1
  451. package/dist/hq/persistence/snapshot-store.d.ts.map +0 -1
  452. package/dist/hq/persistence/timeseries-store.d.ts.map +0 -1
  453. package/dist/hq/persistence.d.ts.map +0 -1
  454. package/dist/hq/protocol/brain.d.ts.map +0 -1
  455. package/dist/hq/protocol/browser.d.ts.map +0 -1
  456. package/dist/hq/protocol/client.d.ts.map +0 -1
  457. package/dist/hq/protocol/core.d.ts.map +0 -1
  458. package/dist/hq/protocol/fleet.d.ts.map +0 -1
  459. package/dist/hq/protocol/kanban.d.ts.map +0 -1
  460. package/dist/hq/protocol/mailbox.d.ts.map +0 -1
  461. package/dist/hq/protocol/mcp.d.ts.map +0 -1
  462. package/dist/hq/protocol/project.d.ts.map +0 -1
  463. package/dist/hq/protocol/session.d.ts.map +0 -1
  464. package/dist/hq/protocol/tool.d.ts.map +0 -1
  465. package/dist/hq/protocol.d.ts.map +0 -1
  466. package/dist/hq/publisher.d.ts.map +0 -1
  467. package/dist/hq/redaction.d.ts.map +0 -1
  468. package/dist/hq/session-bridge.d.ts.map +0 -1
  469. package/dist/hq/tool-bridge.d.ts.map +0 -1
  470. package/dist/hq/transcript-mapper.d.ts.map +0 -1
  471. package/dist/hq/worktree-bridge.d.ts.map +0 -1
  472. package/dist/hq/write-queues.d.ts.map +0 -1
  473. package/dist/index.d.ts.map +0 -1
  474. package/dist/index.js.map +0 -7
  475. package/dist/infrastructure/context-manager.d.ts.map +0 -1
  476. package/dist/infrastructure/index.d.ts.map +0 -1
  477. package/dist/infrastructure/index.js.map +0 -7
  478. package/dist/infrastructure/logger.d.ts.map +0 -1
  479. package/dist/infrastructure/mcp-servers.d.ts.map +0 -1
  480. package/dist/infrastructure/path-resolver.d.ts.map +0 -1
  481. package/dist/infrastructure/provider-cache-ledger.d.ts.map +0 -1
  482. package/dist/infrastructure/token-counter.d.ts.map +0 -1
  483. package/dist/kernel/container.d.ts.map +0 -1
  484. package/dist/kernel/events/agent-events.d.ts.map +0 -1
  485. package/dist/kernel/events/brain-events.d.ts.map +0 -1
  486. package/dist/kernel/events/file-events.d.ts.map +0 -1
  487. package/dist/kernel/events/fleet-events.d.ts.map +0 -1
  488. package/dist/kernel/events/memory-events.d.ts.map +0 -1
  489. package/dist/kernel/events/network-events.d.ts.map +0 -1
  490. package/dist/kernel/events/process-events.d.ts.map +0 -1
  491. package/dist/kernel/events/provider-events.d.ts.map +0 -1
  492. package/dist/kernel/events/sdd-events.d.ts.map +0 -1
  493. package/dist/kernel/events/session-events.d.ts.map +0 -1
  494. package/dist/kernel/events/tool-events.d.ts.map +0 -1
  495. package/dist/kernel/events/worktree-events.d.ts.map +0 -1
  496. package/dist/kernel/events.d.ts.map +0 -1
  497. package/dist/kernel/index.d.ts.map +0 -1
  498. package/dist/kernel/index.js.map +0 -7
  499. package/dist/kernel/pipeline.d.ts.map +0 -1
  500. package/dist/kernel/run-controller.d.ts.map +0 -1
  501. package/dist/kernel/tokens.d.ts.map +0 -1
  502. package/dist/mailbox-attach.d.ts.map +0 -1
  503. package/dist/middleware/collab-pause.d.ts.map +0 -1
  504. package/dist/models/alibaba-token-plan-catalog.d.ts.map +0 -1
  505. package/dist/models/codex-catalog.d.ts.map +0 -1
  506. package/dist/models/index.d.ts.map +0 -1
  507. package/dist/models/index.js.map +0 -7
  508. package/dist/models/llm-selector.d.ts.map +0 -1
  509. package/dist/models/mode-store.d.ts.map +0 -1
  510. package/dist/models/model-intelligence.d.ts.map +0 -1
  511. package/dist/models/model-router.d.ts.map +0 -1
  512. package/dist/models/models-registry.d.ts.map +0 -1
  513. package/dist/models/provider-model-resolve.d.ts.map +0 -1
  514. package/dist/notifications/index.d.ts.map +0 -1
  515. package/dist/notifications/index.js.map +0 -7
  516. package/dist/notifications/notifier-impl.d.ts.map +0 -1
  517. package/dist/notifications/notifier.d.ts.map +0 -1
  518. package/dist/notifications/types.d.ts.map +0 -1
  519. package/dist/observability/event-bridge.d.ts.map +0 -1
  520. package/dist/observability/health.d.ts.map +0 -1
  521. package/dist/observability/index.d.ts.map +0 -1
  522. package/dist/observability/index.js.map +0 -7
  523. package/dist/observability/metrics.d.ts.map +0 -1
  524. package/dist/observability/network-telemetry.d.ts.map +0 -1
  525. package/dist/observability/otel-tracer.d.ts.map +0 -1
  526. package/dist/observability/otlp-metrics.d.ts.map +0 -1
  527. package/dist/observability/otlp-traces.d.ts.map +0 -1
  528. package/dist/observability/process-telemetry.d.ts.map +0 -1
  529. package/dist/observability/prometheus.d.ts.map +0 -1
  530. package/dist/observability/redact-command.d.ts.map +0 -1
  531. package/dist/observability/tracer.d.ts.map +0 -1
  532. package/dist/plugin/api.d.ts.map +0 -1
  533. package/dist/plugin/config.d.ts.map +0 -1
  534. package/dist/plugin/index.d.ts.map +0 -1
  535. package/dist/plugin/index.js.map +0 -7
  536. package/dist/plugin/loader.d.ts.map +0 -1
  537. package/dist/plugins/auto-review-plugin.d.ts.map +0 -1
  538. package/dist/plugins/chimera-plugin.d.ts.map +0 -1
  539. package/dist/plugins/prompts-plugin.d.ts.map +0 -1
  540. package/dist/plugins/review-claim-registry.d.ts.map +0 -1
  541. package/dist/plugins/review-context-builder.d.ts.map +0 -1
  542. package/dist/plugins/review-finding-commands.d.ts.map +0 -1
  543. package/dist/plugins/review-finding-integration.d.ts.map +0 -1
  544. package/dist/plugins/review-finding-parser.d.ts.map +0 -1
  545. package/dist/plugins/review-finding-store.d.ts.map +0 -1
  546. package/dist/plugins/review-finding-types.d.ts.map +0 -1
  547. package/dist/plugins/review-report-integration.d.ts.map +0 -1
  548. package/dist/plugins/review-report-store.d.ts.map +0 -1
  549. package/dist/plugins/review-report-types.d.ts.map +0 -1
  550. package/dist/plugins/review-types.d.ts.map +0 -1
  551. package/dist/plugins/skills-plugin.d.ts.map +0 -1
  552. package/dist/plugins/sync-plugin.d.ts.map +0 -1
  553. package/dist/prompts/index.d.ts.map +0 -1
  554. package/dist/prompts/prompt-installer.d.ts.map +0 -1
  555. package/dist/prompts/prompt-manifest-store.d.ts.map +0 -1
  556. package/dist/registry/index.d.ts.map +0 -1
  557. package/dist/registry/index.js.map +0 -7
  558. package/dist/registry/provider-registry.d.ts.map +0 -1
  559. package/dist/registry/slash-command-registry.d.ts.map +0 -1
  560. package/dist/registry/tool-registry.d.ts.map +0 -1
  561. package/dist/replay/hash.d.ts.map +0 -1
  562. package/dist/replay/index.d.ts.map +0 -1
  563. package/dist/replay/index.js.map +0 -7
  564. package/dist/replay/replay-provider-runner.d.ts.map +0 -1
  565. package/dist/security/capabilities.d.ts.map +0 -1
  566. package/dist/security/config-secrets.d.ts.map +0 -1
  567. package/dist/security/directory-permission-policy.d.ts.map +0 -1
  568. package/dist/security/directory-policy-schema.d.ts.map +0 -1
  569. package/dist/security/index.d.ts.map +0 -1
  570. package/dist/security/index.js.map +0 -7
  571. package/dist/security/kanban-boundary.d.ts.map +0 -1
  572. package/dist/security/permission-policy-schema.d.ts.map +0 -1
  573. package/dist/security/permission-policy.d.ts.map +0 -1
  574. package/dist/security/readonly-permission-policy.d.ts.map +0 -1
  575. package/dist/security/secret-scrubber.d.ts.map +0 -1
  576. package/dist/security/secret-vault.d.ts.map +0 -1
  577. package/dist/security/trust-boundary.d.ts.map +0 -1
  578. package/dist/security/yolo-risk.d.ts.map +0 -1
  579. package/dist/session-registry-atomic-file.d.ts.map +0 -1
  580. package/dist/session-registry-types.d.ts.map +0 -1
  581. package/dist/session-registry.d.ts.map +0 -1
  582. package/dist/skills/foreign-sources.d.ts.map +0 -1
  583. package/dist/skills/frontmatter.d.ts.map +0 -1
  584. package/dist/skills/github-fetcher.d.ts.map +0 -1
  585. package/dist/skills/index.d.ts.map +0 -1
  586. package/dist/skills/index.js.map +0 -7
  587. package/dist/skills/limits.d.ts.map +0 -1
  588. package/dist/skills/manifest-store.d.ts.map +0 -1
  589. package/dist/skills/registry/github-direct-adapter.d.ts.map +0 -1
  590. package/dist/skills/registry/registry-adapter.d.ts.map +0 -1
  591. package/dist/skills/registry/skills-sh-adapter.d.ts.map +0 -1
  592. package/dist/skills/skill-generator.d.ts.map +0 -1
  593. package/dist/skills/skill-installer.d.ts.map +0 -1
  594. package/dist/storage/annotations-store.d.ts.map +0 -1
  595. package/dist/storage/attachment-store.d.ts.map +0 -1
  596. package/dist/storage/cloud-sync.d.ts.map +0 -1
  597. package/dist/storage/completed-work-checkpoint.d.ts.map +0 -1
  598. package/dist/storage/config-loader/bootstrap.d.ts.map +0 -1
  599. package/dist/storage/config-loader/default-repair.d.ts.map +0 -1
  600. package/dist/storage/config-loader/defaults.d.ts.map +0 -1
  601. package/dist/storage/config-loader/diagnostics.d.ts.map +0 -1
  602. package/dist/storage/config-loader/env-overrides.d.ts.map +0 -1
  603. package/dist/storage/config-loader/in-project-policy.d.ts.map +0 -1
  604. package/dist/storage/config-loader/inline-provider-models.d.ts.map +0 -1
  605. package/dist/storage/config-loader/legacy-sage-migration.d.ts.map +0 -1
  606. package/dist/storage/config-loader/path-identity.d.ts.map +0 -1
  607. package/dist/storage/config-loader/types.d.ts.map +0 -1
  608. package/dist/storage/config-loader/validation.d.ts.map +0 -1
  609. package/dist/storage/config-loader.d.ts.map +0 -1
  610. package/dist/storage/config-migration.d.ts.map +0 -1
  611. package/dist/storage/config-store.d.ts.map +0 -1
  612. package/dist/storage/director-state.d.ts.map +0 -1
  613. package/dist/storage/file-session-writer.d.ts.map +0 -1
  614. package/dist/storage/goal-coordination.d.ts.map +0 -1
  615. package/dist/storage/goal-kanban.d.ts.map +0 -1
  616. package/dist/storage/goal-store.d.ts.map +0 -1
  617. package/dist/storage/index.d.ts.map +0 -1
  618. package/dist/storage/index.js.map +0 -7
  619. package/dist/storage/input-history-store.d.ts.map +0 -1
  620. package/dist/storage/memory-backend.d.ts.map +0 -1
  621. package/dist/storage/memory-consolidator.d.ts.map +0 -1
  622. package/dist/storage/memory-graph-backend.d.ts.map +0 -1
  623. package/dist/storage/plan-store.d.ts.map +0 -1
  624. package/dist/storage/plan-templates.d.ts.map +0 -1
  625. package/dist/storage/prompt-store.d.ts.map +0 -1
  626. package/dist/storage/prompt-usage-store.d.ts.map +0 -1
  627. package/dist/storage/provider-config-watcher.d.ts.map +0 -1
  628. package/dist/storage/queue-store.d.ts.map +0 -1
  629. package/dist/storage/recovery-lock.d.ts.map +0 -1
  630. package/dist/storage/replay-log-store.d.ts.map +0 -1
  631. package/dist/storage/session-analyzer.d.ts.map +0 -1
  632. package/dist/storage/session-checkpoint-cas.d.ts.map +0 -1
  633. package/dist/storage/session-event-bridge.d.ts.map +0 -1
  634. package/dist/storage/session-helpers.d.ts.map +0 -1
  635. package/dist/storage/session-id-resolver.d.ts.map +0 -1
  636. package/dist/storage/session-id.d.ts.map +0 -1
  637. package/dist/storage/session-read-scrubber.d.ts.map +0 -1
  638. package/dist/storage/session-reader.d.ts.map +0 -1
  639. package/dist/storage/session-recovery.d.ts.map +0 -1
  640. package/dist/storage/session-resume-validation.d.ts.map +0 -1
  641. package/dist/storage/session-rewind-apply.d.ts.map +0 -1
  642. package/dist/storage/session-rewinder.d.ts.map +0 -1
  643. package/dist/storage/session-store/delete-session-artifacts.d.ts.map +0 -1
  644. package/dist/storage/session-store/delete-session-guards.d.ts.map +0 -1
  645. package/dist/storage/session-store/directory-scan.d.ts.map +0 -1
  646. package/dist/storage/session-store/directory-session-files.d.ts.map +0 -1
  647. package/dist/storage/session-store/events.d.ts.map +0 -1
  648. package/dist/storage/session-store/fork-session.d.ts.map +0 -1
  649. package/dist/storage/session-store/index-reader.d.ts.map +0 -1
  650. package/dist/storage/session-store/load-cache.d.ts.map +0 -1
  651. package/dist/storage/session-store/load-session-data.d.ts.map +0 -1
  652. package/dist/storage/session-store/paths.d.ts.map +0 -1
  653. package/dist/storage/session-store/prune-helpers.d.ts.map +0 -1
  654. package/dist/storage/session-store/replay.d.ts.map +0 -1
  655. package/dist/storage/session-store/search-events.d.ts.map +0 -1
  656. package/dist/storage/session-store/shard-manifest.d.ts.map +0 -1
  657. package/dist/storage/session-store/summary-builder.d.ts.map +0 -1
  658. package/dist/storage/session-store/summary-header.d.ts.map +0 -1
  659. package/dist/storage/session-store/types.d.ts.map +0 -1
  660. package/dist/storage/session-store.d.ts.map +0 -1
  661. package/dist/storage/session-summary.d.ts.map +0 -1
  662. package/dist/storage/session-tool-call-ends.d.ts.map +0 -1
  663. package/dist/storage/session-writer-scrubber.d.ts.map +0 -1
  664. package/dist/storage/session-writer-truncate.d.ts.map +0 -1
  665. package/dist/storage/storage-concurrency.d.ts.map +0 -1
  666. package/dist/storage/task-store.d.ts.map +0 -1
  667. package/dist/storage/todos-checkpoint.d.ts.map +0 -1
  668. package/dist/storage/tool-audit-log.d.ts.map +0 -1
  669. package/dist/tasking/index.d.ts.map +0 -1
  670. package/dist/tasking/index.js.map +0 -7
  671. package/dist/tasking/task-store.d.ts.map +0 -1
  672. package/dist/tasking/task-tracker.d.ts.map +0 -1
  673. package/dist/tools/council-tool.d.ts.map +0 -1
  674. package/dist/tools/fallback-chain-manage-tool.d.ts.map +0 -1
  675. package/dist/tools/fallback-favorite-manage-tool.d.ts.map +0 -1
  676. package/dist/tools/fallback-manage-helpers.d.ts.map +0 -1
  677. package/dist/tools/fallback-manage-tool-options.d.ts.map +0 -1
  678. package/dist/tools/fallback-manage-tools.d.ts.map +0 -1
  679. package/dist/tools/fallback-model-ref-parse.d.ts.map +0 -1
  680. package/dist/tools/fallback-provider-key-store.d.ts.map +0 -1
  681. package/dist/tools/fallback-system-config-view-tool.d.ts.map +0 -1
  682. package/dist/tools/index.d.ts.map +0 -1
  683. package/dist/tools/index.js.map +0 -7
  684. package/dist/tools/mcp-control.d.ts.map +0 -1
  685. package/dist/tools/mcp-use.d.ts.map +0 -1
  686. package/dist/tools/one-shot-llm-tool.d.ts.map +0 -1
  687. package/dist/tools/plugin-manager.d.ts.map +0 -1
  688. package/dist/types/agent-bridge.d.ts.map +0 -1
  689. package/dist/types/attachment.d.ts.map +0 -1
  690. package/dist/types/autonomy.d.ts.map +0 -1
  691. package/dist/types/blocks.d.ts.map +0 -1
  692. package/dist/types/compactor.d.ts.map +0 -1
  693. package/dist/types/config/autonomy.d.ts.map +0 -1
  694. package/dist/types/config/context.d.ts.map +0 -1
  695. package/dist/types/config/fleet-chat.d.ts.map +0 -1
  696. package/dist/types/config/mcp-features.d.ts.map +0 -1
  697. package/dist/types/config/providers.d.ts.map +0 -1
  698. package/dist/types/config/root.d.ts.map +0 -1
  699. package/dist/types/config/runtime.d.ts.map +0 -1
  700. package/dist/types/config/skills-fleet-brain.d.ts.map +0 -1
  701. package/dist/types/config/tools.d.ts.map +0 -1
  702. package/dist/types/config.d.ts.map +0 -1
  703. package/dist/types/context-evidence.d.ts.map +0 -1
  704. package/dist/types/context-window.d.ts.map +0 -1
  705. package/dist/types/council.d.ts.map +0 -1
  706. package/dist/types/default-config.d.ts.map +0 -1
  707. package/dist/types/design-kit.d.ts.map +0 -1
  708. package/dist/types/error-handler.d.ts.map +0 -1
  709. package/dist/types/errors.d.ts.map +0 -1
  710. package/dist/types/file-event-record.d.ts.map +0 -1
  711. package/dist/types/hooks.d.ts.map +0 -1
  712. package/dist/types/index.d.ts.map +0 -1
  713. package/dist/types/index.js.map +0 -7
  714. package/dist/types/input-reader.d.ts.map +0 -1
  715. package/dist/types/logger.d.ts.map +0 -1
  716. package/dist/types/memory.d.ts.map +0 -1
  717. package/dist/types/messages.d.ts.map +0 -1
  718. package/dist/types/mode-prompts.d.ts.map +0 -1
  719. package/dist/types/mode.d.ts.map +0 -1
  720. package/dist/types/models-registry.d.ts.map +0 -1
  721. package/dist/types/multi-agent.d.ts.map +0 -1
  722. package/dist/types/observability.d.ts.map +0 -1
  723. package/dist/types/one-shot-llm.d.ts.map +0 -1
  724. package/dist/types/path-resolver.d.ts.map +0 -1
  725. package/dist/types/permission.d.ts.map +0 -1
  726. package/dist/types/plugin.d.ts.map +0 -1
  727. package/dist/types/prompt-registry.d.ts.map +0 -1
  728. package/dist/types/prompt.d.ts.map +0 -1
  729. package/dist/types/provider-runner.d.ts.map +0 -1
  730. package/dist/types/provider.d.ts.map +0 -1
  731. package/dist/types/quota-regex.d.ts.map +0 -1
  732. package/dist/types/renderer.d.ts.map +0 -1
  733. package/dist/types/retry-policy.d.ts.map +0 -1
  734. package/dist/types/secret-scrubber.d.ts.map +0 -1
  735. package/dist/types/secret-vault.d.ts.map +0 -1
  736. package/dist/types/selector.d.ts.map +0 -1
  737. package/dist/types/session-markers.d.ts.map +0 -1
  738. package/dist/types/session-markers.js.map +0 -7
  739. package/dist/types/session-reader.d.ts.map +0 -1
  740. package/dist/types/session-rewinder.d.ts.map +0 -1
  741. package/dist/types/session.d.ts.map +0 -1
  742. package/dist/types/side-effect.d.ts.map +0 -1
  743. package/dist/types/skill.d.ts.map +0 -1
  744. package/dist/types/slash-command.d.ts.map +0 -1
  745. package/dist/types/spec.d.ts.map +0 -1
  746. package/dist/types/system-prompt-contributor.d.ts.map +0 -1
  747. package/dist/types/system-prompt.d.ts.map +0 -1
  748. package/dist/types/task-graph.d.ts.map +0 -1
  749. package/dist/types/token-counter.d.ts.map +0 -1
  750. package/dist/types/tool-executor.d.ts.map +0 -1
  751. package/dist/types/tool-markers.d.ts.map +0 -1
  752. package/dist/types/tool.d.ts.map +0 -1
  753. package/dist/types/utility-types.d.ts.map +0 -1
  754. package/dist/utils/assert-never.d.ts.map +0 -1
  755. package/dist/utils/atomic-write.d.ts.map +0 -1
  756. package/dist/utils/cache-key.d.ts.map +0 -1
  757. package/dist/utils/child-env.d.ts.map +0 -1
  758. package/dist/utils/color.d.ts.map +0 -1
  759. package/dist/utils/compaction-preview.d.ts.map +0 -1
  760. package/dist/utils/config-backup.d.ts.map +0 -1
  761. package/dist/utils/config-json.d.ts.map +0 -1
  762. package/dist/utils/connectivity.d.ts.map +0 -1
  763. package/dist/utils/context-breakdown.d.ts.map +0 -1
  764. package/dist/utils/context-evidence.d.ts.map +0 -1
  765. package/dist/utils/crash-shield.d.ts.map +0 -1
  766. package/dist/utils/deep-merge.d.ts.map +0 -1
  767. package/dist/utils/diff.d.ts.map +0 -1
  768. package/dist/utils/error.d.ts.map +0 -1
  769. package/dist/utils/error.js.map +0 -7
  770. package/dist/utils/expect-defined.d.ts.map +0 -1
  771. package/dist/utils/expect-defined.js.map +0 -7
  772. package/dist/utils/glob-expand.d.ts.map +0 -1
  773. package/dist/utils/glob-match.d.ts.map +0 -1
  774. package/dist/utils/heap-watchdog.d.ts.map +0 -1
  775. package/dist/utils/heap-watchdog.js.map +0 -7
  776. package/dist/utils/incoming-images.d.ts.map +0 -1
  777. package/dist/utils/index.d.ts.map +0 -1
  778. package/dist/utils/index.js.map +0 -7
  779. package/dist/utils/instruction-file.d.ts.map +0 -1
  780. package/dist/utils/ip-guard.d.ts.map +0 -1
  781. package/dist/utils/json-repair.d.ts.map +0 -1
  782. package/dist/utils/json-schema-validate.d.ts.map +0 -1
  783. package/dist/utils/lru-cache.d.ts.map +0 -1
  784. package/dist/utils/merge-custom-models.d.ts.map +0 -1
  785. package/dist/utils/merge-models-payload.d.ts.map +0 -1
  786. package/dist/utils/message-invariants.d.ts.map +0 -1
  787. package/dist/utils/newline-normalize.d.ts.map +0 -1
  788. package/dist/utils/perf-profile.d.ts.map +0 -1
  789. package/dist/utils/pid.d.ts.map +0 -1
  790. package/dist/utils/project-identity.d.ts.map +0 -1
  791. package/dist/utils/project-watch.d.ts.map +0 -1
  792. package/dist/utils/regex-guard.d.ts.map +0 -1
  793. package/dist/utils/safe-json.d.ts.map +0 -1
  794. package/dist/utils/sage-output-block.d.ts.map +0 -1
  795. package/dist/utils/session-scoped-path.d.ts.map +0 -1
  796. package/dist/utils/sleep.d.ts.map +0 -1
  797. package/dist/utils/slug.d.ts.map +0 -1
  798. package/dist/utils/socket-path.d.ts.map +0 -1
  799. package/dist/utils/sqlite-warning.d.ts.map +0 -1
  800. package/dist/utils/string.d.ts.map +0 -1
  801. package/dist/utils/task-format.d.ts.map +0 -1
  802. package/dist/utils/term.d.ts.map +0 -1
  803. package/dist/utils/todos-format.d.ts.map +0 -1
  804. package/dist/utils/token-estimate.d.ts.map +0 -1
  805. package/dist/utils/tool-description-mode.d.ts.map +0 -1
  806. package/dist/utils/tool-output-serializer.d.ts.map +0 -1
  807. package/dist/utils/tool-result-render-mode.d.ts.map +0 -1
  808. package/dist/utils/tool-subject.d.ts.map +0 -1
  809. package/dist/utils/tool-wire-compact.d.ts.map +0 -1
  810. package/dist/utils/tree-kill.d.ts.map +0 -1
  811. package/dist/utils/tree-kill.js.map +0 -7
  812. package/dist/utils/ulid.d.ts.map +0 -1
  813. package/dist/utils/walk-ignore.d.ts.map +0 -1
  814. package/dist/utils/wstack-paths.d.ts.map +0 -1
  815. package/dist/worktree/index.d.ts.map +0 -1
  816. package/dist/worktree/index.js.map +0 -7
  817. package/dist/worktree/worktree-git.d.ts.map +0 -1
  818. package/dist/worktree/worktree-managed-ops.d.ts.map +0 -1
  819. package/dist/worktree/worktree-manager.d.ts.map +0 -1
  820. package/dist/worktree/worktree-types.d.ts.map +0 -1
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/chronicle/project-server.ts", "../../src/utils/perf-profile.ts", "../../src/chronicle/context.ts", "../../src/chronicle/file-observer.ts", "../../src/storage/storage-concurrency.ts", "../../src/utils/project-watch.ts", "../../src/utils/walk-ignore.ts", "../../src/chronicle/identity.ts", "../../src/chronicle/journal.ts", "../../src/utils/atomic-write.ts", "../../src/types/errors.ts", "../../src/chronicle/event-hash.ts", "../../src/chronicle/partition-filename.ts", "../../src/chronicle/types.ts", "../../src/chronicle/legacy-journal-import.ts", "../../src/chronicle/metrics-store.ts", "../../src/utils/sqlite-warning.ts", "../../src/chronicle/query.ts", "../../src/chronicle/partition-range-cache.ts", "../../src/chronicle/project-server-endpoint.ts", "../../src/utils/socket-path.ts", "../../src/chronicle/project-server-protocol.ts", "../../src/chronicle/sqlite-journal.ts", "../../src/chronicle/sqlite-query.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\n/**\n * One detached Chronicle owner per local project.\n *\n * Event mapping and secret scrubbing remain in the originating process. This\n * server owns ordering/hash chaining, partition rotation, retention, the\n * project file watcher, derived metrics, and journal queries.\n */\n\nimport * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport * as net from 'node:net';\nimport * as path from 'node:path';\nimport { useDaemonPerfDefaults } from '../utils/perf-profile.js';\nimport { type ChronicleContext, createChronicleContext } from './context.js';\nimport { type ChronicleFileObserver, startChronicleFileObserver } from './file-observer.js';\nimport { resolveChronicleRuntimeLocation } from './identity.js';\nimport { ChronicleJournal, type ChronicleJournalStats } from './journal.js';\nimport { importLegacyChronicleJournal } from './legacy-journal-import.js';\nimport { ChronicleMetricsStore } from './metrics-store.js';\nimport { ChroniclePartitionRangeCache } from './partition-range-cache.js';\nimport {\n chronicleProjectServerEndpoint,\n chronicleProjectServerMetadataPath,\n ensureChronicleProjectServerSocketDirectory,\n} from './project-server-endpoint.js';\nimport {\n CHRONICLE_PROJECT_SERVER_MAX_FRAME_CHARS,\n CHRONICLE_PROJECT_SERVER_PROTOCOL_VERSION,\n type ChronicleProjectServerClientMessage,\n type ChronicleProjectServerHealth,\n type ChronicleProjectServerInfo,\n type ChronicleProjectServerMessage,\n type ChronicleServerOperationName,\n type ChronicleServerOperations,\n encodeChronicleProjectServerMessage,\n} from './project-server-protocol.js';\nimport { type ChronicleQuery, ChronicleQueryEngine } from './query.js';\nimport type { ChronicleEventSink } from './sink.js';\nimport { type ChronicleQuarantinedFamily, ChronicleSqliteJournal } from './sqlite-journal.js';\nimport type { ChronicleSqliteQueryEngine } from './sqlite-query.js';\nimport type { ChronicleEvent, ChronicleEventInput } from './types.js';\n\nconst DEFAULT_IDLE_MS = 5 * 60_000;\nconst MAX_APPEND_BATCH = 10_000;\n/** Outbound bytes queued for one client before it is dropped as unresponsive. */\nconst MAX_CLIENT_WRITE_BUFFER_BYTES = 8 * 1024 * 1024;\n\ninterface ParsedArgs {\n projectRoot: string;\n globalRoot: string;\n projectId: string;\n projectDir: string;\n workspaceId: string;\n retentionDays: number;\n}\n\ninterface ClientState {\n socket: net.Socket;\n buffer: string;\n}\n\nfunction parseArgs(argv: string[]): ParsedArgs {\n const values = new Map<string, string>();\n for (let index = 0; index < argv.length; index++) {\n const key = argv[index];\n if (key?.startsWith('--') && argv[index + 1] !== undefined) {\n values.set(key, argv[++index]!);\n }\n }\n const required = [\n '--project-root',\n '--global-root',\n '--project-id',\n '--project-dir',\n '--workspace-id',\n ] as const;\n for (const key of required) {\n if (!values.get(key)) throw new Error(`Chronicle project server requires ${key}`);\n }\n const retentionInput = Number(values.get('--retention-days'));\n return {\n projectRoot: path.resolve(values.get('--project-root')!),\n globalRoot: path.resolve(values.get('--global-root')!),\n projectId: values.get('--project-id')!,\n projectDir: path.resolve(values.get('--project-dir')!),\n workspaceId: values.get('--workspace-id')!,\n retentionDays: Number.isFinite(retentionInput) && retentionInput >= 0 ? retentionInput : 30,\n };\n}\n\n// Long-lived daemon: lean SQLite residency unless the operator says\n// otherwise. Must run before any store opens.\nuseDaemonPerfDefaults();\n\nconst parsed = parseArgs(process.argv.slice(2));\nconst chronicleDirectory = path.join(parsed.projectDir, 'chronicle');\nconst endpoint = chronicleProjectServerEndpoint(parsed.projectDir);\nconst metadataPath = chronicleProjectServerMetadataPath(parsed.projectDir);\nconst idleInput = Number(process.env['WRONGSTACK_CHRONICLE_SERVER_IDLE_MS']);\nconst idleMs = Number.isFinite(idleInput) && idleInput >= 100 ? idleInput : DEFAULT_IDLE_MS;\nconst startedAt = new Date().toISOString();\nconst serverInfo: ChronicleProjectServerInfo = {\n protocolVersion: CHRONICLE_PROJECT_SERVER_PROTOCOL_VERSION,\n pid: process.pid,\n projectRoot: parsed.projectRoot,\n projectDir: parsed.projectDir,\n chronicleDirectory,\n endpoint,\n startedAt,\n};\n\nprocess.title = `wrongstack-chronicle:${path.basename(parsed.projectRoot)}`;\n\nconst clients = new Set<ClientState>();\nconst journals = new Map<string, ChronicleJournal>();\nlet activeRequests = 0;\nlet idleTimer: ReturnType<typeof setTimeout> | undefined;\nlet stopping = false;\nlet watcher: ChronicleFileObserver | undefined;\nlet watcherLastError: string | undefined;\nlet queryGeneration = 0;\nlet cachedQuery: { generation: number; engine: ChronicleQueryEngine } | undefined;\nlet metricsStore: ChronicleMetricsStore | undefined;\nlet partitionRangeCache: ChroniclePartitionRangeCache | undefined;\nlet metricsRefresh:\n | Promise<ChronicleServerOperations['metrics']['result']['refreshed']>\n | undefined;\nconst pendingMutationHints: Parameters<ChronicleFileObserver['noteToolMutation']>[0][] = [];\n\n/**\n * Days of journal to keep open. Yesterday stays available because events can\n * still arrive for it right after midnight; anything older can only accumulate.\n */\nconst MAX_OPEN_JOURNAL_DAYS = 2;\n\n/**\n * Drop journals for days we will not write to again.\n *\n * `journals` was only ever `get`/`set`/iterated \u2014 there was no `delete` and no\n * cap \u2014 so a daemon that lived across midnight kept one open `ChronicleJournal`\n * (with its write buffer and file handle) per day, forever. These daemons\n * routinely stay up for many hours.\n */\nfunction pruneJournals(currentDay: string): void {\n if (journals.size <= MAX_OPEN_JOURNAL_DAYS) return;\n const keep = new Set([...journals.keys()].sort().reverse().slice(0, MAX_OPEN_JOURNAL_DAYS));\n keep.add(currentDay);\n for (const [day, journal] of journals) {\n if (keep.has(day)) continue;\n journals.delete(day);\n // Flush what is still buffered before letting it go. Detached, so a slow\n // disk cannot stall an append \u2014 but never unhandled.\n void journal.flush().catch(() => {\n /* best-effort: the daemon is dropping this day either way */\n });\n }\n}\n\n/** Compose the legacy partition path a `ChronicleJournal` writes to. */\nfunction legacyPartitionPath(location: { chronicleDirectory: string; day: string }): string {\n return path.join(location.chronicleDirectory, `${location.day}.events.jsonl`);\n}\n\n/**\n * SQLite is the daemon's store; `WRONGSTACK_CHRONICLE_STORE=jsonl` restores the\n * partition writer. This is the production write path \u2014 the inline one only\n * runs in explicit recovery mode \u2014 so the cut-over lives here.\n */\nfunction useSqliteStore(): boolean {\n return process.env['WRONGSTACK_CHRONICLE_STORE'] !== 'jsonl';\n}\n\nlet sqliteStore: Promise<ChronicleSqliteJournal> | undefined;\n\n/** Day families the legacy import refused; surfaced by `ping` so health degrades. */\nlet quarantinedFamilies: ChronicleQuarantinedFamily[] = [];\n\n/**\n * Open the store, importing the legacy partitions the first time.\n *\n * The import is folded into opening so no request can observe a half-migrated\n * journal: everything queues behind this one promise.\n */\nfunction store(): Promise<ChronicleSqliteJournal> {\n sqliteStore ??= (async () => {\n await fsp.mkdir(chronicleDirectory, { recursive: true });\n const journal = new ChronicleSqliteJournal({ directory: chronicleDirectory });\n try {\n const result = await importLegacyChronicleJournal(journal, chronicleDirectory);\n quarantinedFamilies = result.quarantined;\n } catch (error) {\n // Caching a rejected promise poisons the daemon for its whole lifetime:\n // every later request awaits the same rejection, and the handle above\n // keeps the database \u2014 and its write-ahead log \u2014 open the entire time.\n // Drop both so the next request gets a real retry.\n sqliteStore = undefined;\n journal.close();\n throw error;\n }\n return journal;\n })();\n return sqliteStore;\n}\n\nfunction journalForToday(): ChronicleJournal {\n const now = new Date();\n const day = now.toISOString().slice(0, 10);\n let journal = journals.get(day);\n if (!journal) {\n const location = resolveChronicleRuntimeLocation({\n globalRoot: parsed.globalRoot,\n projectId: parsed.projectId,\n projectDir: parsed.projectDir,\n now,\n });\n journal = new ChronicleJournal({\n filePath: legacyPartitionPath(location),\n retentionDays: parsed.retentionDays,\n });\n journals.set(day, journal);\n pruneJournals(day);\n }\n return journal;\n}\n\nconst runtimeLocation = resolveChronicleRuntimeLocation({\n globalRoot: parsed.globalRoot,\n projectId: parsed.projectId,\n projectDir: parsed.projectDir,\n});\nconst serverContext: ChronicleContext = createChronicleContext({\n installationId: runtimeLocation.installationId,\n machineId: runtimeLocation.machineId,\n projectId: parsed.projectId,\n workspaceId: parsed.workspaceId,\n});\n\nfunction noteMutation(input: ChronicleEventInput): void {\n if (\n input.eventType !== 'file.mutation.observed' ||\n input.resource?.kind !== 'file' ||\n !input.resource.path ||\n !input.correlation.toolCallId\n ) {\n return;\n }\n const toolName = input.attributes?.['toolName'];\n if (typeof toolName !== 'string' || !toolName) return;\n const at = input.occurredAt ? Date.parse(input.occurredAt) : Number.NaN;\n const hint = {\n path: input.resource.path,\n toolUseId: input.correlation.toolCallId,\n toolName,\n agentId: input.scope.agentId,\n sessionId: input.scope.sessionId,\n ...(Number.isFinite(at) ? { at } : {}),\n };\n if (watcher) watcher.noteToolMutation(hint);\n else {\n if (pendingMutationHints.length >= 1_000) pendingMutationHints.shift();\n pendingMutationHints.push(hint);\n }\n}\n\nasync function appendInputs(inputs: ChronicleEventInput[]): Promise<ChronicleEvent[]> {\n if (!Array.isArray(inputs) || inputs.length === 0 || inputs.length > MAX_APPEND_BATCH) {\n throw new TypeError(`Chronicle append requires 1..${MAX_APPEND_BATCH} inputs`);\n }\n for (const input of inputs) {\n if (!input || typeof input !== 'object' || typeof input.eventType !== 'string') {\n throw new TypeError('Chronicle append received an invalid event input');\n }\n noteMutation(input);\n }\n const events = useSqliteStore()\n ? await (await store()).appendBatch(inputs)\n : await Promise.all(inputs.map((input) => journalForToday().append(input)));\n queryGeneration += events.length;\n return events;\n}\n\nconst watcherSink: ChronicleEventSink = {\n append: async (input) => (await appendInputs([input]))[0]!,\n flush: async () => flushJournals(),\n stats: () => journalForToday().stats(),\n};\n\nasync function flushJournals(): Promise<void> {\n if (useSqliteStore()) {\n // Transactional writes leave nothing buffered; this only waits for an\n // in-flight open (and its legacy import).\n if (sqliteStore) await sqliteStore;\n return;\n }\n await Promise.all([...journals.values()].map((journal) => journal.flush()));\n}\n\nfunction rangeCache(): ChroniclePartitionRangeCache {\n partitionRangeCache ??= new ChroniclePartitionRangeCache(chronicleDirectory);\n return partitionRangeCache;\n}\n\nasync function queryEngine(): Promise<ChronicleQueryEngine | ChronicleSqliteQueryEngine> {\n // The SQLite engine reads through the journal's own connection, so it always\n // sees the latest commit \u2014 the generation cache exists only to avoid\n // re-scanning partition files and is meaningless here.\n if (useSqliteStore()) return (await store()).queryEngine();\n if (cachedQuery?.generation === queryGeneration) return cachedQuery.engine;\n const engine = await ChronicleQueryEngine.fromDirectory(chronicleDirectory, {\n rangeCache: rangeCache(),\n });\n cachedQuery = { generation: queryGeneration, engine };\n return engine;\n}\n\nfunction metrics(): ChronicleMetricsStore {\n metricsStore ??= ChronicleMetricsStore.open(chronicleDirectory);\n return metricsStore;\n}\n\nasync function refreshMetrics(): Promise<\n ChronicleServerOperations['metrics']['result']['refreshed']\n> {\n if (metricsRefresh) return metricsRefresh;\n const run = metrics().refresh();\n metricsRefresh = run;\n try {\n return await run;\n } finally {\n metricsRefresh = undefined;\n }\n}\n\nasync function serverHealth(): Promise<ChronicleProjectServerHealth> {\n const memory = process.memoryUsage();\n await flushJournals();\n // `ping` is the one call a health probe makes, so it has to open the store:\n // a daemon that answers \"healthy\" without ever touching its own journal is\n // exactly what let a broken import go unnoticed while nothing was recorded.\n if (useSqliteStore()) {\n quarantinedFamilies = (await store()).quarantinedFamilies();\n }\n const journalStats: ChronicleJournalStats = journalForToday().stats();\n return {\n ...serverInfo,\n checkedAt: Date.now(),\n uptimeMs: Math.round(process.uptime() * 1_000),\n clients: clients.size,\n activeRequests,\n journal: journalStats,\n ...(quarantinedFamilies.length > 0 ? { quarantinedFamilies } : {}),\n watcher: {\n active: watcher !== undefined,\n watchedFiles: watcher?.watchedFiles ?? 0,\n ...(watcherLastError ? { lastError: watcherLastError } : {}),\n },\n memory: {\n rss: memory.rss,\n heapUsed: memory.heapUsed,\n heapTotal: memory.heapTotal,\n external: memory.external,\n },\n };\n}\n\n/** True when the only narrowing is a time window/page \u2014 no genuinely ad hoc\n * filter (text/path/provider/model/session/etc.) that fixed-dimension\n * aggregation in ChronicleMetricsStore can't answer. */\nfunction isDefaultView(query: ChronicleQuery): boolean {\n const { from, to, limit, order, cursor, ...rest } = query;\n return Object.values(rest).every((value) => value === undefined);\n}\n\nasync function dispatch<O extends ChronicleServerOperationName>(\n op: O,\n rawArgs: unknown,\n): Promise<ChronicleServerOperations[O]['result']> {\n switch (op) {\n case 'ping':\n return (await serverHealth()) as ChronicleServerOperations[O]['result'];\n case 'append': {\n const args = rawArgs as ChronicleServerOperations['append']['args'];\n return (await appendInputs(args.inputs)) as ChronicleServerOperations[O]['result'];\n }\n case 'flush':\n await flushJournals();\n return undefined as ChronicleServerOperations[O]['result'];\n case 'purge': {\n const args = rawArgs as ChronicleServerOperations['purge']['args'];\n return useSqliteStore()\n ? ((await (await store()).purge(args)) as ChronicleServerOperations[O]['result'])\n : ((await journalForToday().purge(args)) as ChronicleServerOperations[O]['result']);\n }\n case 'query': {\n const args = rawArgs as ChronicleServerOperations['query']['args'];\n const result = await (await queryEngine()).query(args.query);\n // The default/unfiltered view (only from/to/limit/order/cursor set) is\n // servable from the incrementally-refreshed metrics store instead of\n // the summary the query engine just computed by scanning matched\n // events \u2014 any other filter (text/path/provider/model/session/etc.)\n // keeps the raw-scan summary, since fixed-dimension aggregation can't\n // answer genuinely ad hoc filters.\n if (isDefaultView(args.query)) {\n await refreshMetrics();\n result.summary = metrics().defaultSummary({\n ...(args.query.from ? { from: args.query.from } : {}),\n ...(args.query.to ? { to: args.query.to } : {}),\n });\n }\n return result as ChronicleServerOperations[O]['result'];\n }\n case 'facet': {\n const args = rawArgs as ChronicleServerOperations['facet']['args'];\n const engine = await queryEngine();\n return {\n values: await engine.facet(args.field, args.query, args.limit),\n diagnostics: engine.diagnostics,\n } as ChronicleServerOperations[O]['result'];\n }\n case 'facets': {\n const args = rawArgs as ChronicleServerOperations['facets']['args'];\n const engine = await queryEngine();\n return {\n values: await engine.facets(args.fields, args.query, args.limit),\n diagnostics: engine.diagnostics,\n } as ChronicleServerOperations[O]['result'];\n }\n case 'graph': {\n const args = rawArgs as ChronicleServerOperations['graph']['args'];\n return (await (\n await queryEngine()\n ).graph(args.seed, args.hops, args.maxNodes)) as ChronicleServerOperations[O]['result'];\n }\n case 'metrics': {\n const args = rawArgs as ChronicleServerOperations['metrics']['args'];\n const refreshed =\n args.refresh === false\n ? { ingestedEvents: 0, ingestedBytes: 0, sourceFiles: 0, invalidLines: 0 }\n : await refreshMetrics();\n if (args.refresh === false) {\n // Keep the projection converging without putting historical indexing\n // latency on the caller's critical path.\n void refreshMetrics().catch(() => {});\n }\n const store = metrics();\n const data =\n args.view === 'providers'\n ? store.providerDaily(args.providers)\n : args.view === 'tasks'\n ? store.taskOutcomes(args.tasks)\n : args.view === 'files'\n ? store.fileLineage(args.files)\n : store.summary();\n return { refreshed, data } as ChronicleServerOperations[O]['result'];\n }\n }\n}\n\nfunction send(state: ClientState, message: ChronicleProjectServerMessage): void {\n if (state.socket.destroyed) return;\n const encoded = encodeChronicleProjectServerMessage(message);\n if (encoded.length > CHRONICLE_PROJECT_SERVER_MAX_FRAME_CHARS) {\n state.socket.destroy(new Error('Chronicle project server response exceeded frame limit'));\n return;\n }\n // The frame cap above bounds one message; this bounds the queue. Ignoring\n // `socket.write()`'s `false` return lets a client that stopped reading grow\n // the owner's heap without limit \u2014 see the identical guard in the mailbox,\n // kanban, SAGE and index owners.\n if (state.socket.writableLength > MAX_CLIENT_WRITE_BUFFER_BYTES) {\n state.socket.destroy(new Error('Chronicle client fell too far behind on reads'));\n return;\n }\n state.socket.write(encoded);\n}\n\nasync function handleMessage(\n state: ClientState,\n message: ChronicleProjectServerClientMessage,\n): Promise<void> {\n if (message.type === 'shutdown') {\n send(state, { type: 'response', id: message.id, ok: true, result: { stopped: true } });\n await stop(message.reason ?? 'client request');\n return;\n }\n activeRequests++;\n try {\n const result = await dispatch(message.op, message.args);\n send(state, { type: 'response', id: message.id, ok: true, result });\n } catch (error) {\n send(state, {\n type: 'response',\n id: message.id,\n ok: false,\n error: error instanceof Error ? error.message : String(error),\n errorName: error instanceof Error ? error.name : undefined,\n });\n } finally {\n activeRequests--;\n // The client may have hung up while this ran \u2014 the socket 'close' handler\n // already tried to arm the idle stop and was refused because work was in\n // flight. Re-arm here or the daemon would linger with nobody attached.\n scheduleIdleStop();\n }\n}\n\nfunction onData(state: ClientState, chunk: string): void {\n state.buffer += chunk;\n if (state.buffer.length > CHRONICLE_PROJECT_SERVER_MAX_FRAME_CHARS) {\n state.socket.destroy(new Error('Chronicle project server request exceeded frame limit'));\n return;\n }\n while (true) {\n const newline = state.buffer.indexOf('\\n');\n if (newline < 0) return;\n const line = state.buffer.slice(0, newline);\n state.buffer = state.buffer.slice(newline + 1);\n if (!line) continue;\n let message: ChronicleProjectServerClientMessage;\n try {\n message = JSON.parse(line) as ChronicleProjectServerClientMessage;\n } catch {\n state.socket.destroy(new Error('Invalid Chronicle project server request'));\n return;\n }\n void handleMessage(state, message);\n }\n}\n\n/**\n * Arm the idle stop, but never while a request is still running.\n *\n * \"Idle\" has to mean no clients *and* no work \u2014 a long operation outlives the\n * connection that asked for it. The legacy import is the extreme case: it runs\n * for minutes inside the first `ping`, so a client that disconnects meanwhile\n * left the daemon counting down and exiting mid-import. Each restart then\n * redid the scan from the top, and because the completion marker is only\n * written at the end, it could never finish. `activeRequests` is decremented\n * in a `finally` that re-arms this, so a hung-up client still gets collected.\n */\nfunction scheduleIdleStop(): void {\n if (stopping || clients.size > 0 || activeRequests > 0 || idleTimer) return;\n idleTimer = setTimeout(() => {\n idleTimer = undefined;\n void stop('idle timeout');\n }, idleMs);\n idleTimer.unref?.();\n}\n\nasync function writeMetadata(): Promise<void> {\n await fsp.mkdir(path.dirname(metadataPath), { recursive: true });\n const temporary = `${metadataPath}.${process.pid}.tmp`;\n await fsp.writeFile(temporary, `${JSON.stringify(serverInfo, null, 2)}\\n`, {\n encoding: 'utf8',\n mode: 0o600,\n });\n try {\n await fsp.rename(temporary, metadataPath);\n } catch {\n await fsp.rm(metadataPath, { force: true });\n await fsp.rename(temporary, metadataPath);\n }\n}\n\nasync function removeOwnedMetadata(): Promise<void> {\n try {\n const current = JSON.parse(await fsp.readFile(metadataPath, 'utf8')) as { pid?: number };\n if (current.pid === process.pid) await fsp.rm(metadataPath, { force: true });\n } catch {\n // Missing or replaced metadata is not ours to remove.\n }\n}\n\nasync function stop(_reason: string): Promise<void> {\n if (stopping) return;\n stopping = true;\n if (idleTimer) clearTimeout(idleTimer);\n idleTimer = undefined;\n await new Promise<void>((resolve) => server.close(() => resolve()));\n for (const state of clients) state.socket.destroy();\n clients.clear();\n await watcher?.close().catch(() => {});\n watcher = undefined;\n await flushJournals().catch(() => {});\n metricsStore?.close();\n metricsStore = undefined;\n await removeOwnedMetadata();\n if (process.platform !== 'win32') await fsp.rm(endpoint, { force: true }).catch(() => {});\n}\n\nensureChronicleProjectServerSocketDirectory(endpoint);\nconst server = net.createServer((socket) => {\n if (stopping) {\n socket.destroy();\n return;\n }\n if (idleTimer) clearTimeout(idleTimer);\n idleTimer = undefined;\n socket.setEncoding('utf8');\n const state: ClientState = { socket, buffer: '' };\n clients.add(state);\n send(state, { type: 'hello', ...serverInfo });\n socket.on('data', (chunk: string) => onData(state, chunk));\n socket.on('close', () => {\n clients.delete(state);\n scheduleIdleStop();\n });\n});\n\nlet probingExistingEndpoint = false;\n\nfunction listenForOwnership(): void {\n server.listen(endpoint);\n}\n\nserver.on('error', (error: NodeJS.ErrnoException) => {\n if (error.code === 'EADDRINUSE' && process.platform === 'win32') {\n process.exitCode = 0;\n return;\n }\n if (error.code === 'EADDRINUSE' && !probingExistingEndpoint) {\n probingExistingEndpoint = true;\n const probe = net.createConnection(endpoint);\n probe.once('connect', () => {\n probe.destroy();\n process.exitCode = 0;\n });\n probe.once('error', () => {\n probe.destroy();\n try {\n fs.rmSync(endpoint, { force: true });\n } catch {\n // A competing candidate may already have repaired the endpoint.\n }\n probingExistingEndpoint = false;\n listenForOwnership();\n });\n return;\n }\n process.exitCode = 1;\n});\n\nserver.on('listening', () => {\n if (process.platform !== 'win32') {\n try {\n fs.chmodSync(endpoint, 0o600);\n } catch {\n // The containing 0700 directory still limits access to this user.\n }\n }\n void writeMetadata();\n void startChronicleFileObserver({\n projectRoot: parsed.projectRoot,\n journal: watcherSink,\n context: serverContext,\n excludedPaths: [chronicleDirectory],\n onError: (error) => {\n watcherLastError = error instanceof Error ? error.message : String(error);\n },\n })\n .then((value) => {\n watcher = value;\n for (const hint of pendingMutationHints.splice(0)) value.noteToolMutation(hint);\n watcherLastError = undefined;\n })\n .catch((error) => {\n watcherLastError = error instanceof Error ? error.message : String(error);\n });\n scheduleIdleStop();\n});\n\nprocess.once('SIGINT', () => void stop('SIGINT'));\nprocess.once('SIGTERM', () => void stop('SIGTERM'));\nlistenForOwnership();\n", "/**\n * Process-wide performance profile.\n *\n * `WRONGSTACK_PERF_PROFILE` (alias `WSTACK_PERF_PROFILE`):\n * - `balanced` (default) \u2014 current throughput-oriented defaults\n * - `frugal` / `cimri` \u2014 lower CPU concurrency, leaner SQLite caches,\n * coarser UI stream paint. Correctness and APIs unchanged.\n */\n\nexport type PerfProfile = 'balanced' | 'frugal';\n\n/**\n * Long-lived IPC daemons default to `frugal`.\n *\n * The SQLite pragmas below are per *connection*, and a daemon holds its\n * connections for its whole lifetime \u2014 the codebase-index daemon measured\n * 336MB RSS, essentially all of it the 128MiB page cache plus 512MiB mmap\n * reservation, while sitting idle. A foreground host pays that cost briefly;\n * a daemon pays it for hours. An explicit `WRONGSTACK_PERF_PROFILE` from the\n * operator still wins in both directions.\n */\nlet daemonDefaults = false;\n\n/** Call once from a daemon entry point, before opening any store. */\nexport function useDaemonPerfDefaults(): void {\n daemonDefaults = true;\n}\n\n/** Resolve the active profile from the environment (evaluated each call). */\nexport function getPerfProfile(): PerfProfile {\n const explicit = process.env.WRONGSTACK_PERF_PROFILE ?? process.env.WSTACK_PERF_PROFILE;\n if (explicit === undefined || explicit.trim() === '') {\n return daemonDefaults ? 'frugal' : 'balanced';\n }\n const raw = explicit.trim().toLowerCase();\n if (raw === 'frugal' || raw === 'cimri' || raw === 'low' || raw === 'eco') {\n return 'frugal';\n }\n return 'balanced';\n}\n\nexport function isFrugalPerf(): boolean {\n return getPerfProfile() === 'frugal';\n}\n\n/** Parallel file-parse batch size for the codebase indexer. */\nexport function indexParallelBatchSize(availableCores: number): number {\n const cores = Math.max(1, Math.floor(availableCores) || 1);\n if (isFrugalPerf()) {\n // Serial-ish: at most 4 files concurrent, never more than core count.\n return Math.min(4, cores);\n }\n // Historical default: cores\u00D74, hard-capped at 40.\n return Math.min(cores * 4, 40);\n}\n\n/**\n * SQLite page-cache / mmap sizes in KiB (negative PRAGMA = KiB units for cache).\n * Frugal keeps correctness; just spends less RSS.\n */\nexport function sqliteCachePragmas(): { cacheSizeKiB: number; mmapBytes: number } {\n if (isFrugalPerf()) {\n return { cacheSizeKiB: 16_384, mmapBytes: 64 * 1024 * 1024 }; // 16 MiB / 64 MiB\n }\n return { cacheSizeKiB: 131_072, mmapBytes: 512 * 1024 * 1024 }; // 128 MiB / 512 MiB\n}\n\n/** sage store defaults (slightly smaller than index). */\nexport function SageCachePragmas(): { cacheSizeKiB: number; mmapBytes: number } {\n if (isFrugalPerf()) {\n return { cacheSizeKiB: 8_192, mmapBytes: 32 * 1024 * 1024 }; // 8 MiB / 32 MiB\n }\n return { cacheSizeKiB: 65_536, mmapBytes: 256 * 1024 * 1024 }; // 64 MiB / 256 MiB\n}\n\n/**\n * TUI stream paint interval. Higher = fewer React dispatches (less CPU/heap\n * churn). Balanced keeps the historical ~10fps; frugal ~6\u20137fps.\n */\nexport function tuiStreamFlushMs(): number {\n return isFrugalPerf() ? 150 : 100;\n}\n", "import { randomUUID } from 'node:crypto';\nimport type { ChronicleCorrelation, ChronicleScope } from './types.js';\n\nexport interface ChronicleContext {\n scope: ChronicleScope;\n correlation: ChronicleCorrelation;\n}\n\n/** Create a root correlation context for a session, run, or background worker. */\nexport function createChronicleContext(\n scope: ChronicleScope,\n traceId: string = randomUUID(),\n): ChronicleContext {\n return {\n scope: { ...scope },\n correlation: { traceId, spanId: randomUUID() },\n };\n}\n\n/** Derive a child span without losing project/session/task attribution. */\nexport function childChronicleContext(\n parent: ChronicleContext,\n overrides: {\n scope?: Partial<ChronicleScope> | undefined;\n correlation?: Partial<Omit<ChronicleCorrelation, 'traceId'>> | undefined;\n } = {},\n): ChronicleContext {\n return {\n scope: { ...parent.scope, ...overrides.scope },\n correlation: {\n ...parent.correlation,\n ...overrides.correlation,\n traceId: parent.correlation.traceId,\n parentSpanId: parent.correlation.spanId,\n spanId: overrides.correlation?.spanId ?? randomUUID(),\n },\n };\n}\n", "import { createHash } from 'node:crypto';\nimport * as fsp from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type { EventBus } from '../kernel/events.js';\nimport { mapWithConcurrency } from '../storage/storage-concurrency.js';\nimport { type ProjectWatchSubscription, watchProjectTree } from '../utils/project-watch.js';\nimport { DEFAULT_WALK_IGNORE_DIRS } from '../utils/walk-ignore.js';\nimport type { ChronicleContext } from './context.js';\nimport type { ChronicleEventSink } from './sink.js';\nimport type { ChronicleEventInput } from './types.js';\n\ninterface FileFingerprint {\n size: number;\n mtimeMs: number;\n hash?: string | undefined;\n}\n\ninterface RecentToolMutation {\n at: number;\n toolUseId: string;\n toolName: string;\n agentId?: string | undefined;\n sessionId?: string | undefined;\n}\n\nexport interface ChronicleToolMutationHint {\n path: string;\n toolUseId: string;\n toolName: string;\n agentId?: string | undefined;\n sessionId?: string | undefined;\n at?: number | undefined;\n}\n\nexport interface ChronicleFileObserverOptions {\n projectRoot: string;\n journal: ChronicleEventSink;\n context: ChronicleContext | (() => ChronicleContext);\n events?: EventBus | undefined;\n debounceMs?: number | undefined;\n maxHashBytes?: number | undefined;\n excludedDirectories?: readonly string[] | undefined;\n /** Absolute or project-relative path prefixes that must never be observed. */\n excludedPaths?: readonly string[] | undefined;\n /** Min gap between full-project rescans triggered by null-filename events. */\n minFullRescanIntervalMs?: number | undefined;\n onError?: ((error: unknown) => void) | undefined;\n}\n\nexport interface ChronicleFileObserver {\n close(): Promise<void>;\n readonly watchedFiles: number;\n noteToolMutation(hint: ChronicleToolMutationHint): void;\n}\n\n/**\n * Directories this observer must never descend into.\n *\n * `.claude` earns its place the same way `.wrongstack` did: it is the tool's own\n * workspace, not the user's project, so nothing inside it is an \"external\n * mutation\" worth an audit event. It matters far more than it looks \u2014 git\n * worktrees live under `.claude/worktrees`, and a worktree is a full copy of the\n * repository. Creating one made the watcher report every tracked file as\n * `file.external.created`, and removing it reported every file again as\n * `deleted`. Measured on this repo: 85,619 of 85,813 file events in a single\n * day came from `.claude/worktrees`, ~95 MB of a 106 MB journal \u2014 90% of the\n * day's telemetry describing the tool watching itself.\n */\nconst DEFAULT_EXCLUDED = [\n ...DEFAULT_WALK_IGNORE_DIRS,\n '.wrongstack',\n '.claude',\n '.temp_files',\n];\nconst SCAN_HASH_CONCURRENCY = 32;\n// Platforms that omit the filename (common on Windows recursive watch) can\n// emit null-filename events in bursts. Each one used to trigger a full\n// project walk \u2014 bound rescans to this floor; a queued rescan is deferred,\n// never dropped, so no external mutation is lost.\nconst DEFAULT_FULL_RESCAN_MIN_INTERVAL_MS = 30_000;\n/** Max entries in recentToolMutations before oldest are evicted. */\nconst MAX_RECENT_TOOL_MUTATIONS = 500;\n\n/** Observe editor/user/external process mutations that bypass WrongStack tools. */\nexport async function startChronicleFileObserver(\n options: ChronicleFileObserverOptions,\n): Promise<ChronicleFileObserver> {\n const root = path.resolve(options.projectRoot);\n const excluded = new Set(options.excludedDirectories ?? DEFAULT_EXCLUDED);\n const excludedPaths = normalizeExcludedPaths(root, options.excludedPaths ?? []);\n const debounceMs = options.debounceMs ?? 120;\n const maxHashBytes = options.maxHashBytes ?? 8 * 1024 * 1024;\n const known = (await scanProject(root, excluded, excludedPaths, maxHashBytes, options.onError))\n .files;\n const recentToolMutations = new Map<string, RecentToolMutation>();\n const noteToolMutation = (hint: ChronicleToolMutationHint): void => {\n const absolute = path.isAbsolute(hint.path)\n ? path.normalize(hint.path)\n : path.resolve(root, hint.path);\n const relative = normalizeRelative(path.relative(root, absolute));\n if (relative.startsWith('../') || isExcluded(relative, excluded, excludedPaths)) return;\n recentToolMutations.set(relative, {\n at: hint.at ?? Date.now(),\n toolUseId: hint.toolUseId,\n toolName: hint.toolName,\n agentId: hint.agentId,\n sessionId: hint.sessionId,\n });\n // Evict oldest entries past the cap to prevent unbounded growth when\n // tool mutations accumulate faster than reconciliation drains them.\n if (recentToolMutations.size > MAX_RECENT_TOOL_MUTATIONS) {\n const overflow = recentToolMutations.size - MAX_RECENT_TOOL_MUTATIONS;\n const keys = [...recentToolMutations.keys()];\n for (let i = 0; i < overflow && i < keys.length; i++) {\n recentToolMutations.delete(keys[i]!);\n }\n }\n };\n const offToolProgress = options.events?.on('tool.progress', (event) => {\n if (event.event.type !== 'file_changed' || !event.event.path) return;\n noteToolMutation({\n path: event.event.path,\n toolUseId: event.id,\n toolName: event.name,\n agentId: event.agentId,\n sessionId: event.sessionId,\n });\n });\n const pending = new Set<string>();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let closed = false;\n let flushTail: Promise<void> | null = null;\n const minFullRescanIntervalMs =\n options.minFullRescanIntervalMs ?? DEFAULT_FULL_RESCAN_MIN_INTERVAL_MS;\n // The startup scan just ran \u2014 the first watcher-triggered full rescan also\n // waits out the interval instead of immediately repeating that work.\n let lastFullScanAt = Date.now();\n let fullRescanTimer: ReturnType<typeof setTimeout> | undefined;\n\n const bumpDebounce = (): void => {\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => {\n timer = undefined;\n drainPending();\n }, debounceMs);\n };\n\n // Some platforms omit the filename. A bounded full rescan recovers the\n // facts instead of silently losing an external mutation \u2014 but rescans walk\n // (and stat) the whole tree, so they are rate-limited: within the interval\n // the request is queued for the earliest allowed time, not dropped.\n const requestFullRescan = (): void => {\n if (closed) return;\n const since = Date.now() - lastFullScanAt;\n if (since >= minFullRescanIntervalMs) {\n pending.add('*');\n bumpDebounce();\n return;\n }\n if (fullRescanTimer) return;\n fullRescanTimer = setTimeout(() => {\n fullRescanTimer = undefined;\n if (closed) return;\n pending.add('*');\n bumpDebounce();\n }, minFullRescanIntervalMs - since);\n if (typeof fullRescanTimer.unref === 'function') fullRescanTimer.unref();\n };\n\n const schedule = (filename: string | Buffer | null): void => {\n if (closed) return;\n if (filename === null) {\n requestFullRescan();\n return;\n }\n const relative = normalizeRelative(String(filename));\n if (!relative || isExcluded(relative, excluded, excludedPaths)) return;\n pending.add(relative);\n bumpDebounce();\n };\n\n const reconcile = async (changedPaths: string[]): Promise<void> => {\n const wantsFullScan = changedPaths.includes('*');\n if (wantsFullScan) lastFullScanAt = Date.now();\n const fullScan = wantsFullScan\n ? await scanProject(root, excluded, excludedPaths, maxHashBytes, options.onError, known)\n : undefined;\n // Re-apply the exclusion boundary at reconciliation time. OS watchers can\n // report paths using a different recursive-root shape than the scheduling\n // callback (notably on Windows), and pending paths may outlive a directory\n // rename. Excluded tool workspaces must never become Chronicle events even\n // if an upstream watcher notification slips through the first filter.\n const candidates = (fullScan ? unionKeys(known, fullScan.files) : changedPaths).filter(\n (relative) => !isExcluded(relative, excluded, excludedPaths),\n );\n const changes: Array<{\n relative: string;\n before?: FileFingerprint | undefined;\n after?: FileFingerprint | undefined;\n }> = [];\n for (const relative of candidates) {\n const before = known.get(relative);\n // A successful full scan already paid the stat/read/hash cost. Reuse\n // those fingerprints instead of reading every file a second time.\n // When the scan is incomplete (a directory read or individual hash\n // threw), reuse whatever was hashed successfully and only re-probe\n // the files the scan did not reach \u2014 never treat a scan gap as a\n // deletion.\n const cached = fullScan?.files.get(relative);\n const after =\n cached ??\n (fullScan?.complete\n ? undefined\n : await fingerprint(path.join(root, relative), maxHashBytes));\n if (sameFingerprint(before, after)) continue;\n changes.push({ relative, before, after });\n }\n\n // Atomic saves and renames commonly arrive as delete+create. Matching the\n // last-known content hash preserves resource lineage when the OS provides\n // only generic \"rename\" notifications.\n const deleted = changes.filter((change) => change.before && !change.after);\n const created = changes.filter((change) => !change.before && change.after);\n const consumed = new Set<string>();\n const journalWrites: Promise<void>[] = [];\n for (const from of deleted) {\n const match = created.find(\n (to) =>\n !consumed.has(to.relative) &&\n from.before?.hash !== undefined &&\n from.before.hash === to.after?.hash,\n );\n if (!match) continue;\n consumed.add(from.relative);\n consumed.add(match.relative);\n known.delete(from.relative);\n known.set(match.relative, match.after!);\n journalWrites.push(\n recordMutation(\n options,\n 'file.external.renamed',\n match.relative,\n match.after,\n {\n operation: 'rename',\n previousPath: from.relative,\n previousResourceId: resourceId(from.relative),\n actor: 'external',\n },\n mutationAttribution(match.relative, recentToolMutations),\n ),\n );\n }\n\n for (const change of changes) {\n if (consumed.has(change.relative)) continue;\n if (!change.after) {\n known.delete(change.relative);\n journalWrites.push(\n recordMutation(\n options,\n 'file.external.deleted',\n change.relative,\n change.before,\n {\n operation: 'delete',\n actor: 'external',\n previousHash: change.before?.hash,\n previousSize: change.before?.size,\n },\n mutationAttribution(change.relative, recentToolMutations),\n ),\n );\n } else if (!change.before) {\n known.set(change.relative, change.after);\n journalWrites.push(\n recordMutation(\n options,\n 'file.external.created',\n change.relative,\n change.after,\n {\n operation: 'write',\n actor: 'external',\n },\n mutationAttribution(change.relative, recentToolMutations),\n ),\n );\n } else {\n known.set(change.relative, change.after);\n journalWrites.push(\n recordMutation(\n options,\n 'file.external.modified',\n change.relative,\n change.after,\n {\n operation: 'edit',\n actor: 'external',\n previousHash: change.before.hash,\n previousSize: change.before.size,\n },\n mutationAttribution(change.relative, recentToolMutations),\n ),\n );\n }\n }\n await Promise.all(journalWrites);\n };\n\n const drainPending = (): Promise<void> => {\n if (flushTail) return flushTail;\n const drain = (async () => {\n while (pending.size > 0) {\n const paths = [...pending];\n pending.clear();\n await reconcile(paths).catch((error) => options.onError?.(error));\n }\n })().finally(() => {\n if (flushTail === drain) flushTail = null;\n if (!closed && pending.size > 0) drainPending();\n });\n flushTail = drain;\n return drain;\n };\n\n let watcher: ProjectWatchSubscription;\n try {\n watcher = watchProjectTree(root, (event) => schedule(event.filename), {\n onError: (error) => options.onError?.(error),\n });\n } catch (error) {\n options.onError?.(error);\n throw error;\n }\n\n return {\n get watchedFiles() {\n return known.size;\n },\n noteToolMutation,\n async close() {\n if (closed) return;\n closed = true;\n offToolProgress?.();\n watcher.close();\n if (timer) {\n clearTimeout(timer);\n timer = undefined;\n }\n if (fullRescanTimer) {\n clearTimeout(fullRescanTimer);\n fullRescanTimer = undefined;\n }\n if (pending.size > 0) drainPending();\n await flushTail;\n recentToolMutations.clear();\n },\n };\n}\n\nasync function recordMutation(\n options: ChronicleFileObserverOptions,\n eventType: string,\n relativePath: string,\n state: FileFingerprint | undefined,\n attributes: Record<string, unknown>,\n attribution?: RecentToolMutation | undefined,\n): Promise<void> {\n const context = typeof options.context === 'function' ? options.context() : options.context;\n const operation = attributes['operation'] as 'write' | 'edit' | 'delete' | 'rename';\n options.events?.emit('file.activity', {\n filePath: path.join(options.projectRoot, relativePath),\n operation,\n phase: 'changed',\n source: attribution ? 'tool' : 'external',\n at: Date.now(),\n sessionId: context.scope.sessionId,\n traceId: context.correlation.traceId,\n agentId: attribution?.agentId ?? context.scope.agentId,\n ...(attribution ? { toolUseId: attribution.toolUseId, toolName: attribution.toolName } : {}),\n });\n const input: ChronicleEventInput = {\n eventType: attribution ? eventType.replace('.external.', '.tool.') : eventType,\n scope: {\n ...context.scope,\n ...(attribution?.sessionId ? { sessionId: attribution.sessionId } : {}),\n ...(attribution?.agentId ? { agentId: attribution.agentId } : {}),\n },\n correlation: {\n ...context.correlation,\n ...(attribution ? { toolCallId: attribution.toolUseId } : {}),\n },\n outcome: 'success',\n resource: {\n kind: 'file',\n id: resourceId(relativePath),\n path: normalizeRelative(relativePath),\n ...(state?.hash ? { contentHashAfter: state.hash } : {}),\n },\n attributes: {\n ...attributes,\n actor: attribution ? 'agent' : attributes['actor'],\n source: attribution ? 'tool' : 'external',\n toolName: attribution?.toolName,\n size: state?.size,\n mtimeMs: state?.mtimeMs,\n observedBy: 'fs.watch',\n },\n };\n await options.journal.append(input);\n}\n\nfunction mutationAttribution(\n relativePath: string,\n recent: Map<string, RecentToolMutation>,\n): RecentToolMutation | undefined {\n const value = recent.get(relativePath);\n if (!value) return undefined;\n recent.delete(relativePath);\n return Date.now() - value.at <= 2_000 ? value : undefined;\n}\n\nasync function scanProject(\n root: string,\n excluded: ReadonlySet<string>,\n excludedPaths: ReadonlySet<string>,\n maxHashBytes: number,\n onError?: ((error: unknown) => void) | undefined,\n previous?: ReadonlyMap<string, FileFingerprint> | undefined,\n): Promise<{ files: Map<string, FileFingerprint>; complete: boolean }> {\n const result = new Map<string, FileFingerprint>();\n const dirs = [''];\n let complete = true;\n while (dirs.length > 0) {\n const relativeDir = dirs.pop()!;\n try {\n const entries = await fsp.readdir(path.join(root, relativeDir), { withFileTypes: true });\n const filePaths: string[] = [];\n for (const entry of entries) {\n const relative = normalizeRelative(path.join(relativeDir, entry.name));\n if (isExcluded(relative, excluded, excludedPaths)) continue;\n if (entry.isDirectory()) {\n dirs.push(relative);\n } else if (entry.isFile()) {\n filePaths.push(relative);\n }\n }\n const fingerprints = await mapWithConcurrency(\n filePaths,\n SCAN_HASH_CONCURRENCY,\n async (relative): Promise<[string, FileFingerprint] | null> => {\n try {\n const value = await fingerprint(\n path.join(root, relative),\n maxHashBytes,\n previous?.get(relative),\n );\n return value ? [relative, value] : null;\n } catch (error) {\n complete = false;\n onError?.(error);\n return null;\n }\n },\n );\n for (const entry of fingerprints) {\n if (entry) result.set(entry[0], entry[1]);\n }\n } catch (error) {\n complete = false;\n onError?.(error);\n }\n }\n return { files: result, complete };\n}\n\nasync function fingerprint(\n filePath: string,\n maxHashBytes: number,\n previous?: FileFingerprint | undefined,\n): Promise<FileFingerprint | undefined> {\n try {\n const stat = await fsp.stat(filePath);\n if (!stat.isFile()) return undefined;\n const base: FileFingerprint = { size: stat.size, mtimeMs: stat.mtimeMs };\n // Unchanged size+mtime \u2192 reuse the known content hash instead of\n // re-reading the file. Full rescans over a quiet tree become stat-only.\n if (\n previous?.hash !== undefined &&\n previous.size === stat.size &&\n previous.mtimeMs === stat.mtimeMs\n ) {\n base.hash = previous.hash;\n return base;\n }\n if (stat.size <= maxHashBytes) {\n base.hash = createHash('sha256')\n .update(await fsp.readFile(filePath))\n .digest('hex');\n }\n return base;\n } catch (error) {\n if (typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT')\n return undefined;\n throw error;\n }\n}\n\nfunction sameFingerprint(a: FileFingerprint | undefined, b: FileFingerprint | undefined): boolean {\n if (!a || !b) return a === b;\n if (a.hash !== undefined && b.hash !== undefined) return a.hash === b.hash;\n return a.size === b.size && a.mtimeMs === b.mtimeMs;\n}\n\nfunction isExcluded(\n relative: string,\n excluded: ReadonlySet<string>,\n excludedPaths: ReadonlySet<string>,\n): boolean {\n const normalized = normalizeRelative(relative);\n if (normalized.split('/').some((segment) => excluded.has(segment))) return true;\n for (const prefix of excludedPaths) {\n if (normalized === prefix || normalized.startsWith(`${prefix}/`)) return true;\n }\n return false;\n}\n\nfunction normalizeExcludedPaths(root: string, values: readonly string[]): Set<string> {\n const result = new Set<string>();\n for (const value of values) {\n const relative = path.isAbsolute(value) ? path.relative(root, path.resolve(value)) : value;\n const normalized = normalizeRelative(relative).replace(/\\/+$/u, '');\n if (!normalized || normalized === '.' || normalized.startsWith('../')) continue;\n result.add(normalized);\n }\n return result;\n}\n\nfunction normalizeRelative(value: string): string {\n return value.replaceAll('\\\\', '/').replace(/^\\.\\//, '');\n}\n\nfunction resourceId(relativePath: string): string {\n return `file_${createHash('sha256').update(normalizeRelative(relativePath)).digest('hex').slice(0, 24)}`;\n}\n\nfunction unionKeys(a: ReadonlyMap<string, unknown>, b: ReadonlyMap<string, unknown>): string[] {\n return [...new Set([...a.keys(), ...b.keys()])];\n}\n", "export async function mapWithConcurrency<T, R>(\n items: readonly T[],\n concurrency: number,\n mapper: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n if (items.length === 0) return [];\n const limit = Math.max(1, Math.floor(concurrency));\n const results = new Array<R>(items.length);\n let next = 0;\n\n async function worker(): Promise<void> {\n while (true) {\n const index = next;\n next++;\n if (index >= items.length) return;\n results[index] = await mapper(items[index] as T, index);\n }\n }\n\n const workers = Array.from({ length: Math.min(limit, items.length) }, () => worker());\n await Promise.all(workers);\n return results;\n}\n", "/**\n * Shared recursive project-tree watcher.\n *\n * Several subsystems each used to open their own `fs.watch(projectRoot,\n * {recursive:true})` \u2014 the codebase indexer, the chronicle file observer, and\n * the WebUI indexing mirror. Every recursive watch makes the OS track the\n * whole tree independently, so a single runtime paid that cost 2\u20133\u00D7. This\n * registry keeps ONE watcher per resolved root per process and fans events\n * out to all subscribers; the watcher closes when the last subscriber leaves.\n *\n * The registry lives behind a `Symbol.for` global so it stays a singleton\n * even if core is loaded twice (Windows path-casing double-load).\n *\n * @module utils/project-watch\n */\n\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nexport interface ProjectWatchEvent {\n eventType: 'rename' | 'change';\n /** Path relative to the watched root as delivered by the OS, or null when omitted. */\n filename: string | null;\n}\n\nexport interface ProjectWatchSubscription {\n close(): void;\n}\n\ninterface Subscriber {\n listener: (event: ProjectWatchEvent) => void;\n onError?: ((error: unknown) => void) | undefined;\n}\n\ninterface WatchEntry {\n watcher: fs.FSWatcher;\n subscribers: Set<Subscriber>;\n /** Set once the underlying watcher errored or closed \u2014 dead entries are never reused. */\n dead: boolean;\n}\n\nconst REGISTRY_KEY = Symbol.for('wrongstack.projectWatchRegistry');\nconst globalScope = globalThis as { [REGISTRY_KEY]?: Map<string, WatchEntry> };\nif (!globalScope[REGISTRY_KEY]) globalScope[REGISTRY_KEY] = new Map();\nconst registry: Map<string, WatchEntry> = globalScope[REGISTRY_KEY];\n\nfunction registryKey(root: string): string {\n const resolved = path.resolve(root);\n return process.platform === 'win32' ? resolved.toLowerCase() : resolved;\n}\n\n/**\n * Subscribe to recursive change events under `root`, sharing one OS watcher\n * per root per process. Throws when the platform cannot create the watcher\n * (no recursive support, permission) and no live shared watcher exists \u2014\n * callers that can degrade should try/catch exactly as they would `fs.watch`.\n *\n * The watcher is non-persistent: it never keeps the process alive.\n */\nexport function watchProjectTree(\n root: string,\n listener: (event: ProjectWatchEvent) => void,\n opts?: { onError?: ((error: unknown) => void) | undefined },\n): ProjectWatchSubscription {\n const key = registryKey(root);\n let entry = registry.get(key);\n if (!entry || entry.dead) {\n const subscribers = new Set<Subscriber>();\n const watcher = fs.watch(\n path.resolve(root),\n { recursive: true, persistent: false },\n (eventType, filename) => {\n const event: ProjectWatchEvent = {\n eventType: eventType === 'rename' ? 'rename' : 'change',\n filename: filename === null ? null : String(filename),\n };\n for (const sub of subscribers) {\n try {\n sub.listener(event);\n } catch (error) {\n sub.onError?.(error);\n }\n }\n },\n );\n const created: WatchEntry = { watcher, subscribers, dead: false };\n const retire = (): void => {\n created.dead = true;\n if (registry.get(key) === created) registry.delete(key);\n };\n watcher.on('error', (error) => {\n // A watcher that errored is closed by Node \u2014 mark the entry dead so the\n // next acquire creates a fresh one instead of reusing a corpse.\n retire();\n for (const sub of subscribers) sub.onError?.(error);\n });\n // Watchers can also close without first emitting `error` (for example when\n // the watched tree disappears). Never leave that closed handle reusable.\n watcher.on('close', retire);\n registry.set(key, created);\n entry = created;\n }\n\n const active = entry;\n const subscriber: Subscriber = { listener, onError: opts?.onError };\n active.subscribers.add(subscriber);\n\n let closed = false;\n return {\n close() {\n if (closed) return;\n closed = true;\n active.subscribers.delete(subscriber);\n if (active.subscribers.size === 0 && !active.dead) {\n active.dead = true;\n if (registry.get(key) === active) registry.delete(key);\n try {\n active.watcher.close();\n } catch {\n /* already closed */\n }\n }\n },\n };\n}\n", "/**\n * Canonical directory-name ignore list for recursive tree walkers.\n *\n * Every walker that enumerates the project tree (glob, grep's native\n * fallback, tree, the codebase indexer, the chronicle file observer, the\n * semantic-search indexer, project fingerprinting, security scans) should\n * start from this list instead of hand-rolling its own \u2014 the hand-rolled\n * copies drifted, and a walker missing `.turbo` or `__pycache__` pays for\n * it by walking thousands of artifact files.\n *\n * The list is intentionally conservative: only dependency stores, VCS\n * internals, and build/cache artifacts that are never the subject of a\n * search. Directories a user may legitimately target (`.wrongstack`,\n * `vendor`, `out`) are NOT here \u2014 walkers with stricter needs append their\n * own entries.\n *\n * @module utils/walk-ignore\n */\n\n/** Directory basenames every recursive walker skips (matched per path segment). */\nexport const DEFAULT_WALK_IGNORE_DIRS: readonly string[] = Object.freeze([\n 'node_modules',\n '.git',\n 'dist',\n 'build',\n '.next',\n '.nuxt',\n '.turbo',\n 'coverage',\n '.nyc_output',\n '__snapshots__',\n '__pycache__',\n '.venv',\n 'venv',\n 'target',\n '.cache',\n '.parcel-cache',\n '.pnpm-store',\n '.gradle',\n]);\n\n/** Set form of {@link DEFAULT_WALK_IGNORE_DIRS} for per-segment membership checks. */\nexport const DEFAULT_WALK_IGNORE_SET: ReadonlySet<string> = new Set(DEFAULT_WALK_IGNORE_DIRS);\n", "import { createHash } from 'node:crypto';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\n\nexport interface ChronicleRuntimeIdentityInput {\n globalRoot: string;\n projectId: string;\n projectDir: string;\n now?: Date | undefined;\n}\n\nexport interface ChronicleRuntimeLocation {\n installationId: string;\n machineId: string;\n projectId: string;\n /** Directory holding this project's Chronicle storage, whatever its format. */\n chronicleDirectory: string;\n /**\n * Day this location was resolved for, `YYYY-MM-DD` UTC.\n *\n * It is also the chain scope: the legacy writer used it to name a partition\n * file, and SQLite uses it as the `day` column. Exposing the day rather than\n * a `.jsonl` path keeps identity resolution independent of storage format.\n */\n day: string;\n}\n\n/**\n * Resolve privacy-preserving stable IDs and the UTC day that scopes a chain.\n * Raw host names and global paths never enter the journal envelope.\n */\nexport function resolveChronicleRuntimeLocation(\n input: ChronicleRuntimeIdentityInput,\n): ChronicleRuntimeLocation {\n const day = (input.now ?? new Date()).toISOString().slice(0, 10);\n return {\n installationId: stableId('installation', path.resolve(input.globalRoot)),\n machineId: stableId('machine', `${os.hostname()}\\0${os.platform()}\\0${os.arch()}`),\n projectId: input.projectId,\n chronicleDirectory: path.join(input.projectDir, 'chronicle'),\n day,\n };\n}\n\nfunction stableId(prefix: string, value: string): string {\n return `${prefix}_${createHash('sha256').update(value).digest('hex').slice(0, 24)}`;\n}\n", "import { randomUUID } from 'node:crypto';\nimport { createReadStream } from 'node:fs';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { createInterface } from 'node:readline';\nimport { atomicWrite, withFileLock } from '../utils/atomic-write.js';\nimport { GENESIS_HASH, hashValue } from './event-hash.js';\nimport { comparePartitionPaths } from './partition-filename.js';\nimport {\n CHRONICLE_SCHEMA_VERSION,\n type ChronicleEvent,\n type ChronicleEventInput,\n type ChronicleVerifyResult,\n} from './types.js';\n\nconst DEFAULT_MAX_PARTITION_BYTES = 100 * 1024 * 1024;\nconst DEFAULT_ROTATION_WINDOW_MS = 60 * 60 * 1000;\nconst RETENTION_CHECKPOINT_VERSION = 1;\n\nexport interface ChronicleRetentionCheckpoint {\n version: typeof RETENTION_CHECKPOINT_VERSION;\n sequence: number;\n hash: string;\n}\n\nexport interface ChronicleJournalOptions {\n filePath: string;\n now?: (() => Date) | undefined;\n monotonicNow?: (() => bigint) | undefined;\n idFactory?: (() => string) | undefined;\n maxPending?: number | undefined;\n batchWindowMs?: number | undefined;\n maxPartitionSizeBytes?: number | undefined;\n rotationWindowMs?: number | undefined;\n retentionDays?: number | undefined;\n autoPurgeIntervalMs?: number | undefined;\n}\nexport interface ChronicleJournalStats {\n acceptedEvents: number; persistedEvents: number; rejectedEvents: number; failedEvents: number;\n batches: number; pendingEvents: number; maxObservedPending: number; largestBatch: number;\n lastBatchDurationMs?: number | undefined;\n partitionRolls: number;\n}\nexport interface ChroniclePurgeOptions {\n retentionDays: number;\n dryRun?: boolean | undefined;\n files?: string[] | undefined;\n}\nexport interface ChroniclePurgeResult {\n deletedCount: number;\n deletedBytes: number;\n skippedCount: number;\n errors: Array<{ file: string; reason: string }>;\n candidates?: string[] | undefined;\n}\n\nexport class ChronicleJournal {\n private readonly basePath: string;\n private readonly now: () => Date;\n private readonly monotonicNow: () => bigint;\n private readonly idFactory: () => string;\n private readonly maxPending: number;\n private readonly batchWindowMs: number;\n private readonly maxPartitionSizeBytes: number;\n private readonly rotationWindowMs: number;\n private readonly retentionDays: number;\n private readonly autoPurgeIntervalMs: number;\n private pending: Array<{ input: ChronicleEventInput; resolve: (event: ChronicleEvent) => void; reject: (error: unknown) => void; }> = [];\n private drainPromise: Promise<void> | undefined;\n private drainScheduled = false;\n private drainTimer: ReturnType<typeof setTimeout> | undefined;\n private readonly counters = { acceptedEvents: 0, persistedEvents: 0, rejectedEvents: 0, failedEvents: 0, batches: 0, maxObservedPending: 0, largestBatch: 0, partitionRolls: 0 };\n private lastBatchDurationMs: number | undefined;\n private partitionIndex = 0;\n private partitionStartedAt: number;\n private partitionSizeBytes = 0;\n private stateInitialized = false;\n private lastSequence = 0;\n private lastHash: string = GENESIS_HASH;\n private lastAutoPurgeAt = 0;\n\n constructor(options: ChronicleJournalOptions) {\n this.basePath = path.resolve(options.filePath);\n this.now = options.now ?? (() => new Date());\n this.monotonicNow = options.monotonicNow ?? (() => process.hrtime.bigint());\n this.idFactory = options.idFactory ?? randomUUID;\n this.maxPending = Math.max(1, options.maxPending ?? 100_000);\n this.batchWindowMs = Math.max(0, options.batchWindowMs ?? 5);\n this.maxPartitionSizeBytes = options.maxPartitionSizeBytes ?? DEFAULT_MAX_PARTITION_BYTES;\n this.rotationWindowMs = options.rotationWindowMs ?? DEFAULT_ROTATION_WINDOW_MS;\n this.retentionDays = options.retentionDays && Number.isFinite(options.retentionDays) && options.retentionDays > 0 ? options.retentionDays : 0;\n this.autoPurgeIntervalMs = Math.max(0, options.autoPurgeIntervalMs ?? 3_600_000);\n this.partitionStartedAt = Date.now();\n }\n\n get path(): string { return this.partitionIndex === 0 ? this.basePath : rotatedPath(this.basePath, this.partitionIndex); }\n\n stats(): ChronicleJournalStats {\n return { ...this.counters, pendingEvents: this.pending.length, ...(this.lastBatchDurationMs !== undefined ? { lastBatchDurationMs: this.lastBatchDurationMs } : {}) };\n }\n\n append(input: ChronicleEventInput): Promise<ChronicleEvent> {\n if (this.pending.length >= this.maxPending) { this.counters.rejectedEvents++; return Promise.reject(new Error(`Chronicle backpressure limit reached (${this.maxPending} pending events)`)); }\n const promise = new Promise<ChronicleEvent>((resolve, reject) => { this.pending.push({ input, resolve, reject }); });\n this.counters.acceptedEvents++;\n this.counters.maxObservedPending = Math.max(this.counters.maxObservedPending, this.pending.length);\n this.scheduleDrain();\n return promise;\n }\n\n async readAll(): Promise<ChronicleEvent[]> {\n await this.flush();\n const files = await collectPartitions(this.basePath);\n const entries: ChronicleEvent[] = [];\n for (const file of files) entries.push(...(await readEntriesStrict(file)));\n return entries;\n }\n\n async flush(): Promise<void> {\n if (this.drainTimer) { clearTimeout(this.drainTimer); this.drainTimer = undefined; this.drainScheduled = false; }\n while (this.pending.length > 0 || this.drainPromise) {\n if (this.pending.length > 0 && !this.drainPromise) this.startDrain();\n await this.drainPromise;\n }\n }\n\n async verify(): Promise<ChronicleVerifyResult> {\n await this.flush();\n const files = await collectPartitions(this.basePath);\n const checkpointResult = await readRetentionCheckpoint(this.basePath);\n if (checkpointResult.error) return { ok: false, entries: 0, brokenAt: 0, reason: checkpointResult.error };\n return verifyPartitionFiles(files, checkpointResult.checkpoint);\n }\n\n async purge(options: ChroniclePurgeOptions): Promise<ChroniclePurgeResult> {\n await this.flush();\n if (!Number.isFinite(options.retentionDays) || options.retentionDays <= 0) {\n throw new TypeError('Chronicle retentionDays must be a positive finite number');\n }\n await this.refreshStateFromDisk();\n const cutoff = Date.now() - options.retentionDays * 86400000;\n const activePath = path.resolve(this.path);\n const errors: ChroniclePurgeResult['errors'] = [];\n let dc = 0, db = 0, sc = 0;\n const suppliedFiles = options.files === undefined\n ? await collectJournalPartitions(this.basePath)\n : [...options.files];\n const eligible = new Set<string>();\n for (const suppliedPath of new Set(suppliedFiles)) {\n const file = path.resolve(suppliedPath);\n if (!isJournalPartition(file, path.dirname(this.basePath), this.basePath)) {\n errors.push({ file: suppliedPath, reason: 'not a Chronicle journal partition in this journal directory' });\n sc++;\n continue;\n }\n if (file === activePath) { sc++; continue; }\n let mtimeMs: number;\n try {\n const fileStat = await fs.lstat(file);\n if (!fileStat.isFile()) { sc++; continue; }\n mtimeMs = fileStat.mtimeMs;\n } catch (error) { if (isNotFound(error)) continue; errors.push({ file, reason: errorMessage(error) }); sc++; continue; }\n if (mtimeMs > cutoff) { sc++; continue; }\n eligible.add(file);\n }\n\n const candidates: string[] = [];\n const allPartitions = await collectJournalPartitions(this.basePath);\n for (const family of groupPartitionsByFamily(allPartitions).values()) {\n for (const file of family) {\n if (file === activePath || !eligible.has(file)) break;\n candidates.push(file);\n eligible.delete(file);\n }\n }\n sc += eligible.size;\n\n if (!options.dryRun) {\n for (const file of candidates) {\n try {\n const familyBase = partitionFamilyBase(file);\n let deletedBytes: number | undefined;\n await withFileLock(familyBase, async () => {\n const fileStat = await fs.lstat(file);\n if (!fileStat.isFile() || fileStat.mtimeMs > cutoff) return;\n const checkpointResult = await readRetentionCheckpoint(familyBase);\n if (checkpointResult.error) throw new Error(checkpointResult.error);\n const checkpoint = checkpointResult.checkpoint;\n const nextCheckpoint = await verifyRetainedPrefix(streamEntriesStrict(file), checkpoint);\n if (!nextCheckpoint) throw new Error('partition does not extend the trusted Chronicle chain');\n if (nextCheckpoint.sequence > (checkpoint?.sequence ?? 0)) {\n await writeRetentionCheckpoint(familyBase, nextCheckpoint);\n }\n deletedBytes = fileStat.size;\n await fs.unlink(file);\n });\n if (deletedBytes === undefined) { sc++; break; }\n db += deletedBytes;\n dc++;\n } catch (error) {\n errors.push({ file, reason: errorMessage(error) });\n sc++;\n // Candidates form an oldest-first prefix. Do not advance the\n // checkpoint beyond a partition that could not be removed: if its\n // checkpoint-covered bytes remain on disk, verify() must still be\n // able to anchor and validate them against that checkpoint.\n break;\n }\n }\n }\n return { deletedCount: dc, deletedBytes: db, skippedCount: sc, errors, ...(options.dryRun ? { candidates } : {}) };\n }\n\n private async maybeAutoPurge(): Promise<void> {\n if (this.retentionDays <= 0) return;\n const n = Date.now();\n if (n - this.lastAutoPurgeAt < this.autoPurgeIntervalMs) return;\n this.lastAutoPurgeAt = n;\n try { await this.purge({ retentionDays: this.retentionDays }); } catch { /* best-effort */ }\n }\n\n private scheduleDrain(): void {\n if (this.drainScheduled || this.drainPromise) return;\n this.drainScheduled = true;\n if (this.batchWindowMs === 0) {\n queueMicrotask(() => {\n this.drainScheduled = false;\n this.startDrain();\n });\n return;\n }\n this.drainTimer = setTimeout(() => { this.drainTimer = undefined; this.drainScheduled = false; this.startDrain(); }, this.batchWindowMs);\n }\n\n private startDrain(): void {\n if (this.drainPromise || this.pending.length === 0) return;\n const batch = this.pending.splice(0);\n const drain = this.persistBatch(batch);\n this.drainPromise = drain.finally(() => { this.drainPromise = undefined; if (this.pending.length > 0) this.scheduleDrain(); });\n }\n\n private async refreshStateFromDisk(): Promise<void> {\n const files = await collectPartitions(this.basePath);\n const latest = files[files.length - 1] ?? this.basePath;\n this.partitionIndex = partitionIndex(latest, this.basePath);\n const state = await readLastEntryState(latest);\n const entry = state.entry;\n // A non-empty active partition already carries the latest sequence and\n // hash-chain anchor. The retention checkpoint is only needed when no\n // retained event exists, so avoid opening (or probing for) the sidecar on\n // every normal append batch.\n const checkpointResult = entry ? {} : await readRetentionCheckpoint(this.basePath);\n if (checkpointResult.error) throw new Error(checkpointResult.error);\n const checkpoint = checkpointResult.checkpoint;\n this.lastSequence = entry?.sequence ?? checkpoint?.sequence ?? 0;\n this.lastHash = entry?.hash ?? checkpoint?.hash ?? GENESIS_HASH;\n this.partitionSizeBytes = state.size;\n this.partitionStartedAt = state.birthtimeMs ?? Date.now();\n this.stateInitialized = true;\n }\n\n private async canReuseDiskState(): Promise<boolean> {\n if (!this.stateInitialized) return false;\n const nextPartition = rotatedPath(this.basePath, this.partitionIndex + 1);\n const [currentStat, nextExists] = await Promise.all([\n fs.stat(this.path).catch((error: unknown) => {\n if (isNotFound(error)) return undefined;\n throw error;\n }),\n fs.access(nextPartition).then(\n () => true,\n (error: unknown) => {\n if (isNotFound(error)) return false;\n throw error;\n },\n ),\n ]);\n // Appends change the active partition size; rotations create the next\n // numbered partition. If neither happened since our last successful\n // batch, the cached sequence/hash anchor is still current and there is no\n // need to rescan the directory or read the JSONL tail again.\n return currentStat?.isFile() === true && currentStat.size === this.partitionSizeBytes && !nextExists;\n }\n\n private async checkRotation(): Promise<void> {\n if (this.partitionIndex === 0 && this.lastSequence === 0) return;\n if (Number.isFinite(this.rotationWindowMs) && Date.now() - this.partitionStartedAt >= this.rotationWindowMs) { this.rotate(); return; }\n if (Number.isFinite(this.maxPartitionSizeBytes) && this.partitionSizeBytes >= this.maxPartitionSizeBytes) this.rotate();\n }\n\n private rotate(): void { this.partitionIndex++; this.partitionStartedAt = Date.now(); this.partitionSizeBytes = 0; this.counters.partitionRolls++; }\n\n private async persistBatch(batch: typeof this.pending): Promise<void> {\n const started = performance.now();\n this.counters.batches++;\n this.counters.largestBatch = Math.max(this.counters.largestBatch, batch.length);\n try {\n let recorded: ChronicleEvent[] = [];\n await withFileLock(this.basePath, async () => {\n if (!(await this.canReuseDiskState())) await this.refreshStateFromDisk();\n await this.checkRotation();\n const cp = this.path;\n let prev: { sequence: number; hash: string } | undefined = this.lastSequence > 0 ? { sequence: this.lastSequence, hash: this.lastHash } : undefined;\n recorded = batch.map(({ input }) => {\n const instant = this.now().toISOString();\n const uh = { ...input, occurredAt: input.occurredAt ?? instant, monotonicNs: input.monotonicNs ?? this.monotonicNow().toString(), schemaVersion: CHRONICLE_SCHEMA_VERSION, eventId: this.idFactory(), observedAt: instant, persistedAt: instant, sequence: (prev?.sequence ?? 0) + 1, previousHash: prev?.hash ?? GENESIS_HASH };\n const event: ChronicleEvent = { ...uh, hash: hashValue(uh) };\n prev = event;\n return event;\n });\n const serialized = recorded.map((e) => JSON.stringify(e)).join('\\n') + '\\n';\n await fs.appendFile(cp, serialized, 'utf8');\n this.partitionSizeBytes += Buffer.byteLength(serialized);\n });\n const last = recorded[recorded.length - 1]!;\n this.lastSequence = last.sequence;\n this.lastHash = last.hash;\n batch.forEach((item, i) => { item.resolve(recorded[i]!); });\n this.counters.persistedEvents += batch.length;\n void this.maybeAutoPurge();\n } catch (error) {\n // appendFile can fail after a partial write. Force the next batch to\n // rebuild its chain anchor from disk instead of trusting local counters.\n this.stateInitialized = false;\n this.counters.failedEvents += batch.length;\n batch.forEach((item) => { item.reject(error); });\n } finally { this.lastBatchDurationMs = performance.now() - started; }\n }\n}\n\nfunction rotatedPath(basePath: string, index: number): string {\n const dir = path.dirname(basePath);\n const ext = path.extname(basePath);\n const base = path.basename(basePath, ext);\n return path.join(dir, `${base}.${String(index).padStart(5, '0')}${ext}`);\n}\n\n/**\n * Exported for the SQLite migration only (`legacy-journal-import.ts`).\n *\n * The importer has to walk partitions in exactly the order the writer produced\n * them and parse them with exactly the same strictness, so it reuses these\n * rather than growing a second implementation that could disagree about\n * rotation order or malformed lines. All three go away with the legacy reader\n * in phase 4 of `chronicle-sqlite-journal-v1`.\n */\nexport async function collectPartitions(basePath: string): Promise<string[]> {\n const dir = path.dirname(basePath);\n const ext = path.extname(basePath);\n const base = path.basename(basePath, ext);\n const pattern = new RegExp(`^${escapeRegex(base)}(?:\\\\.\\\\d{5})?${escapeRegex(ext)}$`);\n const result: string[] = [];\n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n for (const entry of entries) if (entry.isFile() && pattern.test(entry.name)) result.push(path.join(dir, entry.name));\n } catch { /* ok */ }\n const baseFile = path.join(dir, base + ext);\n const rotated = result.filter((file) => file !== baseFile).sort((left, right) => parseIndex(left, base, ext) - parseIndex(right, base, ext));\n return [baseFile, ...rotated];\n}\n\nasync function collectJournalPartitions(basePath: string): Promise<string[]> {\n const directory = path.dirname(basePath);\n const result: string[] = [];\n try {\n const entries = await fs.readdir(directory, { withFileTypes: true });\n for (const entry of entries) {\n const file = path.join(directory, entry.name);\n if (entry.isFile() && isJournalPartition(file, directory, basePath)) result.push(file);\n }\n } catch { /* ok */ }\n return result.sort(comparePartitionPaths);\n}\n\nfunction isJournalPartition(filePath: string, directory: string, basePath?: string): boolean {\n if (path.dirname(path.resolve(filePath)) !== path.resolve(directory)) return false;\n const fileName = path.basename(filePath);\n if (!basePath) return false;\n const baseName = path.basename(basePath);\n const dailyFamily = /^\\d{4}-\\d{2}-\\d{2}\\.events(?:\\.\\d{5})?\\.jsonl$/;\n if (/^\\d{4}-\\d{2}-\\d{2}\\.events\\.jsonl$/.test(baseName)) return dailyFamily.test(fileName);\n return partitionFamilyBase(path.resolve(filePath)) === partitionFamilyBase(path.resolve(basePath));\n}\n\nfunction groupPartitionsByFamily(files: string[]): Map<string, string[]> {\n const groups = new Map<string, string[]>();\n for (const file of files) {\n const family = partitionFamilyBase(file);\n const group = groups.get(family) ?? [];\n group.push(file);\n groups.set(family, group);\n }\n return groups;\n}\n\nfunction partitionFamilyBase(filePath: string): string {\n return filePath.replace(/\\.\\d{5}(?=\\.jsonl$)/, '');\n}\n\nfunction retentionCheckpointPath(basePath: string): string {\n return `${partitionFamilyBase(basePath)}.retention.json`;\n}\n\nasync function verifyRetainedPrefix(\n entries: AsyncIterable<ChronicleEvent>,\n checkpoint: ChronicleRetentionCheckpoint | undefined,\n): Promise<ChronicleRetentionCheckpoint | undefined> {\n let sequence = checkpoint?.sequence ?? 0;\n let hash = checkpoint?.hash ?? GENESIS_HASH;\n let advanced = false;\n let sawEntry = false;\n for await (const entry of entries) {\n sawEntry = true;\n if (entry.sequence <= sequence) continue;\n if (entry.sequence !== sequence + 1 || entry.previousHash !== hash) return undefined;\n const { hash: recordedHash, ...content } = entry;\n if (hashValue(content) !== recordedHash) return undefined;\n sequence = entry.sequence;\n hash = recordedHash;\n advanced = true;\n }\n if (!sawEntry) return undefined;\n if (!advanced) return checkpoint;\n return { version: RETENTION_CHECKPOINT_VERSION, sequence, hash };\n}\n\nasync function verifyPartitionFiles(\n files: string[],\n checkpoint: ChronicleRetentionCheckpoint | undefined,\n): Promise<ChronicleVerifyResult> {\n const checkpointSequence = checkpoint?.sequence ?? 0;\n let previousHash = checkpoint?.hash ?? GENESIS_HASH;\n let entries = 0;\n let lastSequence = checkpointSequence;\n let coveredPrevious: ChronicleEvent | undefined;\n for (const file of files) {\n try {\n for await (const entry of streamEntriesStrict(file)) {\n const { hash: recordedHash, ...content } = entry;\n if (entry.sequence <= checkpointSequence) {\n // A checkpoint can be durably renamed just before its source\n // partition fails to unlink. Such retained bytes are still evidence:\n // validate them rather than treating every covered sequence as absent.\n if (hashValue(content) !== recordedHash) return { ok: false, entries, brokenAt: entries, reason: 'entry hash mismatch' };\n if (coveredPrevious && entry.sequence !== coveredPrevious.sequence + 1) {\n return { ok: false, entries, brokenAt: entries, reason: `sequence ${entry.sequence} is not ${coveredPrevious.sequence + 1}` };\n }\n if (coveredPrevious && entry.previousHash !== coveredPrevious.hash) {\n return { ok: false, entries, brokenAt: entries, reason: 'previous hash mismatch' };\n }\n if (entry.sequence === checkpointSequence && recordedHash !== checkpoint?.hash) {\n return { ok: false, entries, brokenAt: entries, reason: 'retention checkpoint hash mismatch' };\n }\n coveredPrevious = entry;\n continue;\n }\n const index = entries++;\n if (entry.sequence !== lastSequence + 1) return { ok: false, entries, brokenAt: index, reason: `sequence ${entry.sequence} is not ${lastSequence + 1}` };\n if (entry.previousHash !== previousHash) return { ok: false, entries, brokenAt: index, reason: 'previous hash mismatch' };\n if (hashValue(content) !== recordedHash) return { ok: false, entries, brokenAt: index, reason: 'entry hash mismatch' };\n previousHash = recordedHash;\n lastSequence = entry.sequence;\n }\n } catch (error) { return { ok: false, entries, brokenAt: entries, reason: errorMessage(error) }; }\n }\n if (\n coveredPrevious &&\n (coveredPrevious.sequence !== checkpointSequence || coveredPrevious.hash !== checkpoint?.hash)\n ) {\n return { ok: false, entries, brokenAt: entries, reason: 'retention checkpoint hash mismatch' };\n }\n return { ok: true, entries, lastSequence, lastHash: previousHash };\n}\n\nexport async function readRetentionCheckpoint(basePath: string): Promise<{\n checkpoint?: ChronicleRetentionCheckpoint | undefined;\n error?: string | undefined;\n}> {\n const checkpointPath = retentionCheckpointPath(basePath);\n let raw: string;\n try { raw = await fs.readFile(checkpointPath, 'utf8'); } catch (error) {\n return isNotFound(error) ? {} : { error: `cannot read retention checkpoint: ${errorMessage(error)}` };\n }\n try {\n const parsed = JSON.parse(raw) as Partial<ChronicleRetentionCheckpoint>;\n if (parsed.version !== RETENTION_CHECKPOINT_VERSION || !Number.isSafeInteger(parsed.sequence) || (parsed.sequence ?? -1) < 0 || !isHash(parsed.hash)) {\n return { error: 'invalid Chronicle retention checkpoint' };\n }\n return { checkpoint: parsed as ChronicleRetentionCheckpoint };\n } catch { return { error: 'invalid Chronicle retention checkpoint JSON' }; }\n}\n\nasync function writeRetentionCheckpoint(basePath: string, checkpoint: ChronicleRetentionCheckpoint): Promise<void> {\n await atomicWrite(retentionCheckpointPath(basePath), `${JSON.stringify(checkpoint)}\\n`, { mode: 0o600 });\n}\n\nfunction isHash(value: unknown): value is string {\n return typeof value === 'string' && /^[a-f0-9]{64}$/.test(value);\n}\n\nfunction parseIndex(filePath: string, base: string, ext: string): number {\n const suffix = path.basename(filePath).slice(base.length + 1, -ext.length);\n return suffix ? parseInt(suffix, 10) : 0;\n}\n\nfunction partitionIndex(filePath: string, basePath: string): number {\n const ext = path.extname(basePath);\n return parseIndex(filePath, path.basename(basePath, ext), ext);\n}\n\nfunction escapeRegex(text: string): string { return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'); }\n\nasync function readLastEntryState(filePath: string): Promise<{\n entry?: ChronicleEvent | undefined;\n size: number;\n birthtimeMs?: number | undefined;\n}> {\n let handle: fs.FileHandle;\n try { handle = await fs.open(filePath, 'r'); } catch (error) { if (isNotFound(error)) return { size: 0 }; throw error; }\n try {\n const stat = await handle.stat();\n const size = stat.size;\n let position = size, suffix = '';\n while (position > 0) {\n const length = Math.min(65536, position);\n position -= length;\n const buf = Buffer.allocUnsafe(length);\n await handle.read(buf, 0, length, position);\n suffix = buf.toString('utf8') + suffix;\n const lines = suffix.split('\\n');\n const start = position === 0 ? 0 : 1;\n for (let i = lines.length - 1; i >= start; i--) {\n const trimmed = lines[i]!.trim();\n if (!trimmed) continue;\n try { return { entry: JSON.parse(trimmed) as ChronicleEvent, size, birthtimeMs: stat.birthtimeMs }; } catch { /* scan earlier */ }\n }\n suffix = lines[0] ?? '';\n }\n return { size, birthtimeMs: stat.birthtimeMs };\n } finally { await handle.close(); }\n}\n\n/** Stream entries line by line. Reading a whole partition into one string\n * breaks past V8's max string length (~512MB) \u2014 purge and verify must work\n * on partitions of any size, so only individual lines are materialized. */\nexport async function* streamEntriesStrict(filePath: string): AsyncGenerator<ChronicleEvent> {\n let lineNumber = 0;\n try {\n const input = createReadStream(filePath, { encoding: 'utf8', highWaterMark: 256 * 1024 });\n const lines = createInterface({ input, crlfDelay: Infinity });\n for await (const line of lines) {\n lineNumber++;\n const trimmed = line.trim();\n if (!trimmed) continue;\n let entry: ChronicleEvent;\n try { entry = JSON.parse(trimmed) as ChronicleEvent; } catch { throw new Error(`invalid JSON at line ${lineNumber} in ${path.basename(filePath)}`); }\n yield entry;\n }\n } catch (error) {\n if (isNotFound(error)) return;\n throw error;\n }\n}\n\nasync function readEntriesStrict(filePath: string): Promise<ChronicleEvent[]> {\n const entries: ChronicleEvent[] = [];\n for await (const entry of streamEntriesStrict(filePath)) entries.push(entry);\n return entries;\n}\n\nfunction isNotFound(error: unknown): boolean { return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT'; }\nfunction errorMessage(error: unknown): string { return error instanceof Error ? error.message : String(error); }\n\nexport { GENESIS_HASH };\n", "import type { FileHandle } from 'node:fs/promises';\nimport {\n type AtomicWriteOptions,\n createPersistencePrimitives,\n type FileLockOptions,\n} from '@wrongstack/persistence';\nimport { FsError } from '../types/errors.js';\n\nexport type { AtomicWriteOptions, FileLockOptions } from '@wrongstack/persistence';\n\nconst primitives = createPersistencePrimitives({\n createLockTimeoutError: ({ targetPath, timeoutMs }) =>\n new FsError({\n message: `Timed out waiting for file lock: ${targetPath}`,\n code: 'FS_ATOMIC_WRITE_FAILED',\n path: targetPath,\n context: { timeoutMs },\n }),\n});\n\nexport const atomicWrite: (\n targetPath: string,\n content: string | Uint8Array,\n opts?: AtomicWriteOptions,\n) => Promise<void> = primitives.atomicWrite;\n/**\n * Atomic replace that streams its new contents instead of taking them as one\n * buffer. Use when the replacement is large enough that materializing it would\n * itself be the memory problem (log rotation, tail compaction).\n */\nexport const atomicReplaceWithWriter: <T>(\n targetPath: string,\n write: (handle: FileHandle) => Promise<T>,\n opts?: AtomicWriteOptions,\n) => Promise<T> = primitives.atomicReplaceWithWriter;\nexport const ensureDir: (dir: string) => Promise<void> = primitives.ensureDir;\nexport const withFileLock: <T>(\n targetPath: string,\n fn: () => Promise<T>,\n opts?: FileLockOptions,\n) => Promise<T> = primitives.withFileLock;\n", "import { toErrorMessage } from '../utils/error.js';\n\n/**\n * WrongStack error hierarchy.\n *\n * Every error thrown by the framework is a `WrongStackError` with a\n * machine-readable `code`, a `subsystem` tag, and a `severity` level.\n * This lets consumers (CLI, TUI, plugins, tests) branch on structured\n * data instead of parsing error messages.\n */\n\n// \u2500\u2500 Error codes \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * Machine-readable error codes as frozen constants.\n *\n * Use `ERROR_CODES.X` instead of raw string literals for:\n * - IDE autocomplete and compile-time validation\n * - Safe refactoring (rename updates all usages)\n * - Plugin extensibility (extend the object to add custom codes)\n *\n * The `ErrorCode` type is derived from this object, so adding a new\n * code here automatically updates the type without extra changes.\n */\nexport const ERROR_CODES = {\n // Provider\n PROVIDER_RATE_LIMITED: 'PROVIDER_RATE_LIMITED',\n PROVIDER_AUTH_FAILED: 'PROVIDER_AUTH_FAILED',\n PROVIDER_OVERLOADED: 'PROVIDER_OVERLOADED',\n PROVIDER_INVALID_REQUEST: 'PROVIDER_INVALID_REQUEST',\n PROVIDER_SERVER_ERROR: 'PROVIDER_SERVER_ERROR',\n PROVIDER_NETWORK_ERROR: 'PROVIDER_NETWORK_ERROR',\n PROVIDER_CONTEXT_OVERFLOW: 'PROVIDER_CONTEXT_OVERFLOW',\n // Tool\n TOOL_NOT_FOUND: 'TOOL_NOT_FOUND',\n TOOL_PERMISSION_DENIED: 'TOOL_PERMISSION_DENIED',\n TOOL_EXECUTION_FAILED: 'TOOL_EXECUTION_FAILED',\n TOOL_TIMEOUT: 'TOOL_TIMEOUT',\n TOOL_INPUT_INVALID: 'TOOL_INPUT_INVALID',\n // Config\n CONFIG_INVALID: 'CONFIG_INVALID',\n CONFIG_NOT_FOUND: 'CONFIG_NOT_FOUND',\n CONFIG_PARSE_FAILED: 'CONFIG_PARSE_FAILED',\n CONFIG_MIGRATION_NEEDED: 'CONFIG_MIGRATION_NEEDED',\n // Plugin\n PLUGIN_LOAD_FAILED: 'PLUGIN_LOAD_FAILED',\n PLUGIN_API_MISMATCH: 'PLUGIN_API_MISMATCH',\n PLUGIN_MISSING_DEPENDENCY: 'PLUGIN_MISSING_DEPENDENCY',\n // Agent\n AGENT_ITERATION_LIMIT: 'AGENT_ITERATION_LIMIT',\n AGENT_CONTEXT_OVERFLOW: 'AGENT_CONTEXT_OVERFLOW',\n AGENT_ABORTED: 'AGENT_ABORTED',\n AGENT_RUN_FAILED: 'AGENT_RUN_FAILED',\n // Session\n SESSION_NOT_FOUND: 'SESSION_NOT_FOUND',\n SESSION_CORRUPTED: 'SESSION_CORRUPTED',\n SESSION_WRITE_FAILED: 'SESSION_WRITE_FAILED',\n // Container / Registry\n CONTAINER_TOKEN_ALREADY_BOUND: 'CONTAINER_TOKEN_ALREADY_BOUND',\n CONTAINER_TOKEN_NOT_BOUND: 'CONTAINER_TOKEN_NOT_BOUND',\n CONTAINER_CIRCULAR_DEPENDENCY: 'CONTAINER_CIRCULAR_DEPENDENCY',\n REGISTRY_DUPLICATE: 'REGISTRY_DUPLICATE',\n REGISTRY_NOT_FOUND: 'REGISTRY_NOT_FOUND',\n REGISTRY_INVALID: 'REGISTRY_INVALID',\n // File system\n FS_READ_FAILED: 'FS_READ_FAILED',\n FS_WRITE_FAILED: 'FS_WRITE_FAILED',\n FS_MKDIR_FAILED: 'FS_MKDIR_FAILED',\n FS_DELETE_FAILED: 'FS_DELETE_FAILED',\n FS_ATOMIC_WRITE_FAILED: 'FS_ATOMIC_WRITE_FAILED',\n // SDD (Spec-Driven Development)\n SDD_VALIDATION_FAILED: 'SDD_VALIDATION_FAILED',\n SDD_PARSE_FAILED: 'SDD_PARSE_FAILED',\n SDD_INVALID_STATE: 'SDD_INVALID_STATE',\n SDD_NOT_READY: 'SDD_NOT_READY',\n // General\n VALIDATION_ERROR: 'VALIDATION_ERROR',\n PARSE_FAILED: 'PARSE_FAILED',\n UNKNOWN: 'UNKNOWN',\n} as const;\n\n/**\n * Union type derived from `ERROR_CODES`. Using `typeof ERROR_CODES[keyof typeof ERROR_CODES]`\n * instead of a string literal union means TypeScript auto-updates the type whenever\n * a new code is added to `ERROR_CODES` \u2014 no need to keep two lists in sync.\n */\nexport type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];\n\nexport type ErrorSubsystem =\n | 'provider'\n | 'tool'\n | 'config'\n | 'plugin'\n | 'agent'\n | 'session'\n | 'sdd'\n | 'container'\n | 'fs'\n | 'general';\nexport type ErrorSeverity = 'fatal' | 'error' | 'warning';\n\n// \u2500\u2500 Base error class \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport class WrongStackError extends Error {\n readonly code: ErrorCode;\n readonly subsystem: ErrorSubsystem;\n readonly severity: ErrorSeverity;\n readonly recoverable: boolean;\n readonly context?: Record<string, unknown> | undefined;\n\n constructor(opts: {\n message: string;\n code: ErrorCode;\n subsystem: ErrorSubsystem;\n severity?: ErrorSeverity | undefined;\n recoverable?: boolean | undefined;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super(opts.message, { cause: opts.cause });\n this.name = 'WrongStackError';\n this.code = opts.code;\n this.subsystem = opts.subsystem;\n this.severity = opts.severity ?? 'error';\n this.recoverable = opts.recoverable ?? false;\n this.context = opts.context;\n }\n\n /**\n * Render a one-line user-facing description.\n * Subclasses should override for domain-specific formatting.\n */\n describe(): string {\n const ctx = this.context ? ` ${formatContext(this.context)}` : '';\n return `${this.code}: ${this.message}${ctx}`;\n }\n}\n\nfunction formatContext(ctx: Record<string, unknown>): string {\n const parts = Object.entries(ctx)\n .filter(([, v]) => v !== undefined)\n .slice(0, 3)\n .map(([k, v]) => `${k}=${String(v)}`);\n return parts.length > 0 ? `[${parts.join(' ')}]` : '';\n}\n\n// \u2500\u2500 Specific error classes \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * Tool execution errors \u2014 thrown by ToolExecutor and individual tools.\n */\nexport class ToolError extends WrongStackError {\n readonly toolName: string;\n\n constructor(opts: {\n message: string;\n code: Extract<\n ErrorCode,\n | 'TOOL_NOT_FOUND'\n | 'TOOL_PERMISSION_DENIED'\n | 'TOOL_EXECUTION_FAILED'\n | 'TOOL_TIMEOUT'\n | 'TOOL_INPUT_INVALID'\n >;\n toolName: string;\n recoverable?: boolean | undefined;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: opts.code,\n subsystem: 'tool',\n recoverable: opts.recoverable,\n context: { tool: opts.toolName, ...opts.context },\n cause: opts.cause,\n });\n this.name = 'ToolError';\n this.toolName = opts.toolName;\n }\n}\n\n/**\n * Config loading / validation errors.\n */\nexport class ConfigError extends WrongStackError {\n constructor(opts: {\n message: string;\n code: Extract<\n ErrorCode,\n 'CONFIG_INVALID' | 'CONFIG_NOT_FOUND' | 'CONFIG_PARSE_FAILED' | 'CONFIG_MIGRATION_NEEDED'\n >;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: opts.code,\n subsystem: 'config',\n severity: 'fatal',\n recoverable: false,\n context: opts.context,\n cause: opts.cause,\n });\n this.name = 'ConfigError';\n }\n}\n\n/**\n * Plugin loading / lifecycle errors.\n */\nexport class PluginError extends WrongStackError {\n readonly pluginName: string;\n\n constructor(opts: {\n message: string;\n code: Extract<\n ErrorCode,\n 'PLUGIN_LOAD_FAILED' | 'PLUGIN_API_MISMATCH' | 'PLUGIN_MISSING_DEPENDENCY'\n >;\n pluginName: string;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: opts.code,\n subsystem: 'plugin',\n severity: 'error',\n recoverable: opts.code === ERROR_CODES.PLUGIN_MISSING_DEPENDENCY,\n context: { plugin: opts.pluginName, ...opts.context },\n cause: opts.cause,\n });\n this.name = 'PluginError';\n this.pluginName = opts.pluginName;\n }\n}\n\n/**\n * Agent runtime errors \u2014 thrown by Agent.run when a non-WrongStackError\n * escapes the inner loop, so callers always see a structured error.\n */\nexport class AgentError extends WrongStackError {\n constructor(opts: {\n message: string;\n code: Extract<\n ErrorCode,\n 'AGENT_ITERATION_LIMIT' | 'AGENT_CONTEXT_OVERFLOW' | 'AGENT_ABORTED' | 'AGENT_RUN_FAILED'\n >;\n recoverable?: boolean | undefined;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: opts.code,\n subsystem: 'agent',\n severity: opts.code === ERROR_CODES.AGENT_ABORTED ? 'warning' : 'error',\n recoverable: opts.recoverable ?? opts.code === ERROR_CODES.AGENT_ITERATION_LIMIT,\n context: opts.context,\n cause: opts.cause,\n });\n this.name = 'AgentError';\n }\n}\n\n/**\n * Wrap an arbitrary thrown value into a `WrongStackError` so the caller\n * always gets a structured error. Pass-throughs WrongStackError instances\n * unchanged; raw `Error`s and primitives get an `AGENT_RUN_FAILED` wrapper\n * with the original preserved as `cause`.\n */\nexport function toWrongStackError(\n err: unknown,\n code: Extract<ErrorCode, 'AGENT_RUN_FAILED' | 'AGENT_ABORTED' | 'UNKNOWN'> = ERROR_CODES.AGENT_RUN_FAILED,\n): WrongStackError {\n if (err instanceof WrongStackError) return err;\n const message = toErrorMessage(err);\n return new AgentError({\n message,\n code: code === 'UNKNOWN' ? ERROR_CODES.AGENT_RUN_FAILED : code,\n cause: err,\n });\n}\n\n/**\n * Session storage errors.\n */\nexport class SessionError extends WrongStackError {\n readonly sessionId?: string | undefined;\n\n constructor(opts: {\n message: string;\n code: Extract<ErrorCode, 'SESSION_NOT_FOUND' | 'SESSION_CORRUPTED' | 'SESSION_WRITE_FAILED'>;\n sessionId?: string | undefined;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: opts.code,\n subsystem: 'session',\n severity: opts.code === ERROR_CODES.SESSION_WRITE_FAILED ? 'error' : 'warning',\n recoverable: opts.code !== ERROR_CODES.SESSION_CORRUPTED,\n context: { sessionId: opts.sessionId, ...opts.context },\n cause: opts.cause,\n });\n this.name = 'SessionError';\n this.sessionId = opts.sessionId;\n }\n}\n\n/**\n * SDD (Spec-Driven Development) errors \u2014 spec validation, parsing, and\n * state machine violations in the AISpecBuilder, TaskFlow, and TaskTracker.\n */\nexport class SddError extends WrongStackError {\n constructor(opts: {\n message: string;\n code: Extract<\n ErrorCode,\n 'SDD_VALIDATION_FAILED' | 'SDD_PARSE_FAILED' | 'SDD_INVALID_STATE' | 'SDD_NOT_READY'\n >;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: opts.code,\n subsystem: 'sdd',\n severity: opts.code === ERROR_CODES.SDD_PARSE_FAILED ? 'warning' : 'error',\n recoverable: opts.code === ERROR_CODES.SDD_NOT_READY,\n context: opts.context,\n cause: opts.cause,\n });\n this.name = 'SddError';\n }\n}\n\n/**\n * File system operation errors.\n */\nexport class FsError extends WrongStackError {\n readonly path?: string | undefined;\n\n constructor(opts: {\n message: string;\n code: Extract<\n ErrorCode,\n 'FS_READ_FAILED' | 'FS_WRITE_FAILED' | 'FS_MKDIR_FAILED' | 'FS_DELETE_FAILED' | 'FS_ATOMIC_WRITE_FAILED'\n >;\n path?: string | undefined;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: opts.code,\n subsystem: 'fs',\n severity: 'error',\n recoverable: opts.code !== ERROR_CODES.FS_READ_FAILED,\n context: { path: opts.path, ...opts.context },\n cause: opts.cause,\n });\n this.name = 'FsError';\n this.path = opts.path;\n }\n}\n\n/**\n * HTTP fetch error \u2014 thrown when a network request returns a non-OK status.\n * Carries the response status so {@link classifyToolError} can branch on it\n * (429 \u2192 transient, 404 \u2192 not_found, 401 \u2192 permission) without duck-typing\n * the error via `'response' in err`.\n *\n * P3 #18 (before-release.md): the previous `'response' in err` check caught\n * any Error with a `response` property, including custom errors, proxy\n * objects, or mocked errors in tests. `instanceof FetchError` is reliable.\n *\n * Tools and providers that make HTTP requests and need the executor to\n * classify their failures should throw `new FetchError({ status, message })`\n * instead of a bare `Error` with an ad-hoc `response` field.\n */\nexport class FetchError extends WrongStackError {\n readonly status: number;\n\n constructor(opts: {\n message: string;\n status: number;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: ERROR_CODES.VALIDATION_ERROR,\n subsystem: 'general',\n severity: 'error',\n recoverable: opts.status === 429 || opts.status >= 500,\n context: { status: opts.status, ...opts.context },\n cause: opts.cause,\n });\n this.name = 'FetchError';\n this.status = opts.status;\n }\n}\n\n/**\n * Tool input validation error \u2014 thrown when a tool's input fails a validation\n * check that the JSON Schema cannot express (e.g. `old_string === new_string`\n * in edit, or a cross-field invariant). Use this instead of a bare\n * `throw new Error('...validation...')` so {@link classifyToolError} can\n * match on `instanceof` rather than a locale-dependent message substring.\n *\n * P2 #6 (before-release.md): the previous `err.message.includes('validation')`\n * check misclassified any error whose message happened to contain \"validation\"\n * (e.g. a third-party \"input validation timeout\") as a VALIDATION error.\n *\n * Named `ToolValidationError` (not `ValidationError`) to avoid colliding with\n * the existing `ValidationError` interface exported by json-schema-validate.ts\n * (a validation-result shape, not an Error subclass).\n */\nexport class ToolValidationError extends WrongStackError {\n constructor(opts: {\n message: string;\n /** Field path or tool name that failed validation, for diagnostics. */\n field?: string | undefined;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: ERROR_CODES.VALIDATION_ERROR,\n subsystem: 'general',\n severity: 'error',\n recoverable: false,\n context: { field: opts.field, ...opts.context },\n cause: opts.cause,\n });\n this.name = 'ToolValidationError';\n }\n}\n\n/**\n * Response / payload parse error \u2014 thrown when an upstream HTTP response,\n * file, or data structure is well-formed at the transport layer (HTTP 200,\n * valid JSON) but is missing required fields or has an unexpected shape.\n *\n * Distinct from `ConfigError(CONFIG_PARSE_FAILED)` (which is specifically\n * for config-file parsing) and `FetchError` (which covers HTTP non-OK\n * responses). `ParseError` fills the gap: the request succeeded but the\n * response body couldn't be interpreted.\n *\n * Common sites: OAuth token responses missing `access_token`, device-code\n * responses missing `device_code`, registry responses with unexpected\n * schemas.\n */\nexport class ParseError extends WrongStackError {\n readonly source?: string | undefined;\n\n constructor(opts: {\n message: string;\n /**\n * What was being parsed \u2014 e.g. `'oauth-token-response'`,\n * `'device-code-response'`. Lets consumers distinguish parse failures\n * from different upstream APIs without parsing the message.\n */\n source?: string | undefined;\n context?: Record<string, unknown> | undefined;\n cause?: unknown | undefined;\n }) {\n super({\n message: opts.message,\n code: ERROR_CODES.PARSE_FAILED,\n subsystem: 'general',\n severity: 'error',\n recoverable: false,\n context: { source: opts.source, ...opts.context },\n cause: opts.cause,\n });\n this.name = 'ParseError';\n this.source = opts.source;\n }\n}\n\n// \u2500\u2500 Type guards \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport function isWrongStackError(err: unknown): err is WrongStackError {\n return err instanceof WrongStackError;\n}\n\nexport function isToolError(err: unknown): err is ToolError {\n return err instanceof ToolError;\n}\n\nexport function isConfigError(err: unknown): err is ConfigError {\n return err instanceof ConfigError;\n}\n\nexport function isPluginError(err: unknown): err is PluginError {\n return err instanceof PluginError;\n}\n\nexport function isSessionError(err: unknown): err is SessionError {\n return err instanceof SessionError;\n}\n\nexport function isAgentError(err: unknown): err is AgentError {\n return err instanceof AgentError;\n}\n\nexport function isFsError(err: unknown): err is FsError {\n return err instanceof FsError;\n}\n\nexport function isToolValidationError(err: unknown): err is ToolValidationError {\n return err instanceof ToolValidationError;\n}\n\nexport function isFetchError(err: unknown): err is FetchError {\n return err instanceof FetchError;\n}\n\nexport function isParseError(err: unknown): err is ParseError {\n return err instanceof ParseError;\n}\n\nexport function isSddError(err: unknown): err is SddError {\n return err instanceof SddError;\n}\n", "/**\n * The one implementation of Chronicle's tamper-evident hash.\n *\n * Chronicle events form a chain: each carries the `hash` of its predecessor in\n * `previousHash`, anchored at {@link GENESIS_HASH}. Verification recomputes\n * every `hash` from the stored event, so the canonicalization below is part of\n * the durable format \u2014 two subtly different implementations would produce two\n * incompatible chains, and the divergence would only surface later as a\n * \"corrupt journal\" report on data that was never actually tampered with.\n *\n * It therefore lives here rather than beside any one store, and both the JSONL\n * journal and the SQLite journal import it.\n */\nimport { createHash } from 'node:crypto';\nimport type { ChronicleEvent } from './types.js';\n\n/** `previousHash` of the first event in a chain. */\nexport const GENESIS_HASH = '0'.repeat(64);\n\n/**\n * Deterministic JSON encoding: object keys sorted, `undefined` members dropped,\n * `undefined` array elements encoded as `null`.\n *\n * Note this is NOT what gets written to disk \u2014 the JSONL journal stores\n * `JSON.stringify(event)` in V8 property order. The stored bytes are a record;\n * the preimage is always re-derived from the parsed event.\n */\nexport function stableStringify(value: unknown): string {\n if (value === null || typeof value !== 'object') return JSON.stringify(value);\n if (Array.isArray(value)) {\n return `[${value.map((item) => (item === undefined ? 'null' : stableStringify(item))).join(',')}]`;\n }\n const obj = value as Record<string, unknown>;\n return `{${Object.keys(obj)\n .sort()\n .filter((key) => obj[key] !== undefined)\n .map((key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`)\n .join(',')}}`;\n}\n\nexport function hashValue(value: unknown): string {\n return createHash('sha256').update(stableStringify(value), 'utf8').digest('hex');\n}\n\n/**\n * Recompute the hash a stored event should carry.\n *\n * The `hash` field is excluded from its own preimage, so verification of an\n * event read back from any store is `chronicleEventHash(event) === event.hash`.\n */\nexport function chronicleEventHash(event: ChronicleEvent): string {\n const { hash: _hash, ...unhashed } = event;\n return hashValue(unhashed);\n}\n", "import * as path from 'node:path';\n\n/** Matches both rotated (`*.events.NNNNN.jsonl`) and unrotated (`*.events.jsonl`) partition files. */\nexport const PARTITION_FILE_PATTERN = /^(.*\\.events)(?:\\.(\\d{5}))?\\.jsonl$/;\n\nfunction partitionFamily(filePath: string): string {\n const match = PARTITION_FILE_PATTERN.exec(path.basename(filePath));\n return path.join(path.dirname(filePath), match?.[1] ?? path.basename(filePath));\n}\n\nfunction partitionSequence(filePath: string): number {\n const match = PARTITION_FILE_PATTERN.exec(path.basename(filePath));\n return Number(match?.[2] ?? 0);\n}\n\n/** Orders partitions by family, then by rotation sequence \u2014 the unrotated file (no sequence) sorts first. */\nexport function comparePartitionPaths(left: string, right: string): number {\n const familyOrder = partitionFamily(left).localeCompare(partitionFamily(right));\n return familyOrder || partitionSequence(left) - partitionSequence(right);\n}\n", "/** Schema version for the first durable WrongStack Chronicle event envelope. */\nexport const CHRONICLE_SCHEMA_VERSION = 1 as const;\n\nexport type ChronicleOutcome =\n | 'started'\n | 'success'\n | 'failure'\n | 'cancelled'\n | 'denied'\n | 'abandoned'\n | 'unknown';\n\n/** Stable identities used to project one event into global and project views. */\nexport interface ChronicleScope {\n installationId: string;\n machineId: string;\n projectId?: string | undefined;\n repositoryId?: string | undefined;\n workspaceId?: string | undefined;\n worktreeId?: string | undefined;\n sessionId?: string | undefined;\n turnId?: string | undefined;\n iterationId?: string | undefined;\n agentId?: string | undefined;\n goalId?: string | undefined;\n planId?: string | undefined;\n taskId?: string | undefined;\n kanbanBoardId?: string | undefined;\n}\n\nexport interface ChronicleCorrelation {\n traceId: string;\n spanId: string;\n parentSpanId?: string | undefined;\n logicalRequestId?: string | undefined;\n attemptId?: string | undefined;\n toolCallId?: string | undefined;\n}\n\nexport interface ChronicleRuntimeIdentity {\n providerId?: string | undefined;\n modelId?: string | undefined;\n modelRevision?: string | undefined;\n processId?: number | undefined;\n parentProcessId?: number | undefined;\n}\n\nexport interface ChronicleResourceRef {\n kind: 'file' | 'symbol' | 'memory' | 'task' | 'kanban' | 'process' | 'network' | 'artifact' | 'other';\n id: string;\n path?: string | undefined;\n lineStart?: number | undefined;\n lineEnd?: number | undefined;\n contentHashBefore?: string | undefined;\n contentHashAfter?: string | undefined;\n}\n\nexport interface ChronicleEventInput {\n eventType: string;\n scope: ChronicleScope;\n correlation: ChronicleCorrelation;\n runtime?: ChronicleRuntimeIdentity | undefined;\n resource?: ChronicleResourceRef | undefined;\n outcome?: ChronicleOutcome | undefined;\n durationNs?: string | undefined;\n occurredAt?: string | undefined;\n monotonicNs?: string | undefined;\n attributes?: Record<string, unknown> | undefined;\n tags?: Record<string, string> | undefined;\n}\n\n/**\n * Lossless durable envelope. All wall-clock timestamps are UTC ISO-8601;\n * monotonicNs is used for elapsed-time ordering inside one process.\n */\nexport interface ChronicleEvent extends ChronicleEventInput {\n schemaVersion: typeof CHRONICLE_SCHEMA_VERSION;\n eventId: string;\n observedAt: string;\n persistedAt: string;\n sequence: number;\n previousHash: string;\n hash: string;\n}\n\nexport type ChronicleVerifyResult =\n | { ok: true; entries: number; lastSequence: number; lastHash: string }\n | { ok: false; entries: number; brokenAt: number; reason: string };\n", "/**\n * One-shot import of the legacy JSONL journal into SQLite\n * (phase 2 of `chronicle-sqlite-journal-v1`).\n *\n * The events being moved are an audit record, so this is deliberately strict:\n * every event is verified against the running chain *before* it is inserted,\n * and a single break aborts that day inside a rolled-back transaction.\n * Repairing a broken chain silently would defeat the purpose of having one \u2014\n * the operator is told exactly where it broke and decides.\n *\n * Chains are scoped to a day family (`<day>.events.jsonl` plus its `.NNNNN`\n * rotations), not to the journal as a whole: `sequence` restarts at 1 each day.\n * Each family is therefore imported as its own chain and its own transaction,\n * seeded from that family's `*.retention.json` checkpoint when its prefix was\n * already purged.\n *\n * A family that fails verification is quarantined \u2014 never imported, never\n * repaired, recorded by day so health can report it \u2014 and the remaining days\n * still move. Scoping the abort to the journal instead made every future day\n * hostage to the worst day on disk: one multi-writer partition from before the\n * single-daemon invariant, and the store could never finish opening, so\n * Chronicle recorded nothing at all from then on.\n */\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { chronicleEventHash, GENESIS_HASH } from './event-hash.js';\nimport { collectPartitions, readRetentionCheckpoint, streamEntriesStrict } from './journal.js';\nimport { PARTITION_FILE_PATTERN } from './partition-filename.js';\nimport type {\n ChronicleQuarantinedFamily,\n ChronicleSqliteJournal,\n} from './sqlite-journal.js';\n\nexport interface ChronicleLegacyImportResult {\n /** True when the marker was already set and nothing was read. */\n alreadyImported: boolean;\n /** Day families imported. */\n families: number;\n /** Events imported across all families. */\n events: number;\n /** Day families refused for a broken chain; none of their events landed. */\n quarantined: ChronicleQuarantinedFamily[];\n}\n\n/** A chain break found while importing; carries enough context to act on. */\nexport class ChronicleImportError extends Error {\n constructor(\n message: string,\n readonly day: string,\n readonly sequence: number,\n ) {\n super(message);\n this.name = 'ChronicleImportError';\n }\n}\n\n/**\n * Discover the day families in a chronicle directory.\n *\n * `PARTITION_FILE_PATTERN` captures the family base (`<day>.events`) separately\n * from the rotation index, so rotations collapse onto the family they belong\n * to instead of being mistaken for separate days.\n */\nasync function discoverFamilies(directory: string): Promise<string[]> {\n let entries: string[];\n try {\n entries = await fs.readdir(directory);\n } catch {\n return [];\n }\n const bases = new Set<string>();\n for (const entry of entries) {\n const match = PARTITION_FILE_PATTERN.exec(entry);\n if (match?.[1]) bases.add(match[1]);\n }\n return [...bases].sort();\n}\n\n/** `2026-07-28.events` \u2192 `2026-07-28`. */\nfunction dayOfFamily(familyBase: string): string {\n return familyBase.replace(/\\.events$/u, '');\n}\n\nexport async function importLegacyChronicleJournal(\n journal: ChronicleSqliteJournal,\n directory: string,\n): Promise<ChronicleLegacyImportResult> {\n if (journal.hasImportedLegacyJournal()) {\n return {\n alreadyImported: true,\n families: 0,\n events: 0,\n quarantined: journal.quarantinedFamilies(),\n };\n }\n\n const families = await discoverFamilies(directory);\n const quarantined: ChronicleQuarantinedFamily[] = [];\n let importedEvents = 0;\n let importedFamilies = 0;\n\n for (const familyBase of families) {\n const day = dayOfFamily(familyBase);\n const basePath = path.join(directory, `${familyBase}.jsonl`);\n let familyEvents = 0;\n\n // Resume rather than restart. Families commit one at a time, so a run cut\n // short \u2014 the daemon restarted, the machine rebooted \u2014 leaves whole days\n // already stored. Re-reading them would abort on the `(day, sequence)`\n // primary key and put the import back to square one every time.\n if (journal.hasImportedDay(day)) continue;\n\n try {\n // One transaction per family: a break below rolls back this day only,\n // leaving the days already committed \u2014 and every future day \u2014 intact.\n await journal.runFamilyImport(async (sink) => {\n familyEvents = 0;\n\n const checkpointResult = await readRetentionCheckpoint(basePath);\n if (checkpointResult.error) {\n throw new ChronicleImportError(checkpointResult.error, day, 0);\n }\n const checkpoint = checkpointResult.checkpoint;\n if (checkpoint) sink.checkpoint(day, checkpoint.sequence, checkpoint.hash);\n\n let expectedSequence = (checkpoint?.sequence ?? 0) + 1;\n let previousHash = checkpoint?.hash ?? GENESIS_HASH;\n\n for (const partition of await collectPartitions(basePath)) {\n for await (const event of streamEntriesStrict(partition)) {\n if (event.sequence !== expectedSequence) {\n throw new ChronicleImportError(\n `sequence gap in ${day}: expected ${expectedSequence}, found ${event.sequence}`,\n day,\n event.sequence,\n );\n }\n if (event.previousHash !== previousHash) {\n throw new ChronicleImportError(\n `previous hash mismatch in ${day} at sequence ${event.sequence}`,\n day,\n event.sequence,\n );\n }\n if (chronicleEventHash(event) !== event.hash) {\n throw new ChronicleImportError(\n `entry hash mismatch in ${day} at sequence ${event.sequence}`,\n day,\n event.sequence,\n );\n }\n sink.insert(day, event);\n familyEvents += 1;\n expectedSequence = event.sequence + 1;\n previousHash = event.hash;\n }\n }\n });\n } catch (error) {\n // A broken chain is data the operator has to decide about, so it is\n // quarantined and reported. Anything else \u2014 an unreadable file, a full\n // disk, SQLite refusing to write \u2014 is an infrastructure failure that\n // would corrupt the import if treated as \"just skip that day\".\n if (!(error instanceof ChronicleImportError)) throw error;\n quarantined.push({ day, sequence: error.sequence, reason: error.message });\n continue;\n }\n\n if (familyEvents > 0) importedFamilies += 1;\n importedEvents += familyEvents;\n }\n\n journal.recordQuarantinedFamilies(quarantined);\n journal.markLegacyJournalImported();\n\n return {\n alreadyImported: false,\n families: importedFamilies,\n events: importedEvents,\n quarantined,\n };\n}\n", "/**\n * ChronicleMetricsStore \u2014 derived, queryable aggregates over the raw\n * Chronicle journal (\"process, don't hoard\").\n *\n * The journal is the durable evidence log; this store is a disposable\n * projection kept in `<chronicleDir>/metrics.db` (node:sqlite, WAL). Each\n * `refresh()` incrementally consumes only the journal bytes appended since\n * the previous run (per-partition byte offsets in `ingest_state`), so the\n * raw JSONL partitions can be purged by retention without losing metrics:\n *\n * - `provider_daily` \u2014 provider\u00D7model\u00D7day attempt/success/failure/retry/\n * fallback counts, token totals, duration stats.\n * - `task_outcomes` \u2014 one row per task (kanban/SDD/subagent) with status,\n * timing, retry counts, and board/run/session lineage.\n * - `file_lineage` \u2014 one row per observed file mutation with full\n * session/agent/task/board/tool/model attribution.\n * - `token_cost` \u2014 latest cumulative token.accounted cost snapshot per\n * scope (same latest-wins semantics as the query\n * engine's summary).\n * - `daily_counters`, `family_daily`, `agent_daily`, `logical_request_daily`,\n * `file_seen_daily` \u2014 per-day scalar counters and dedup sets backing\n * `defaultSummary()`, a `ChronicleSummary` for the common unfiltered/\n * time-bounded dashboard view. Any genuinely ad hoc filter (free text,\n * path, session, provider, model) falls back to the raw-scan summary in\n * query.ts \u2014 fixed-dimension aggregation fundamentally can't answer those.\n *\n * The schema is a cache: on version mismatch it is dropped and re-ingested\n * from whatever journal partitions still exist.\n */\n\nimport * as fs from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport * as path from 'node:path';\nimport type { DatabaseSync } from 'node:sqlite';\nimport { withFileLock } from '../utils/atomic-write.js';\nimport { withSqliteExperimentalWarningSuppressed } from '../utils/sqlite-warning.js';\nimport { findChroniclePartitions, isTerminalFailure, signalFamily } from './query.js';\nimport type { ChronicleEvent } from './types.js';\nimport type { ChronicleSignalFamily, ChronicleSummary } from './query.js';\n\nconst SCHEMA_VERSION = 3;\nconst READ_CHUNK_BYTES = 1024 * 1024;\nconst EMPTY_FAMILIES: Record<ChronicleSignalFamily, number> = {\n llm: 0, agent: 0, tool: 0, file: 0, memory: 0, task: 0, decision: 0, runtime: 0, finding: 0,\n};\n\nexport interface ChronicleMetricsRefreshResult {\n ingestedEvents: number;\n ingestedBytes: number;\n sourceFiles: number;\n invalidLines: number;\n}\n\nexport interface ChronicleProviderDailyRow {\n day: string;\n providerId: string;\n modelId: string;\n attempts: number;\n completed: number;\n failed: number;\n retries: number;\n fallbacks: number;\n inputTokens: number;\n outputTokens: number;\n cacheReadTokens: number;\n cacheWriteTokens: number;\n avgDurationMs: number;\n maxDurationMs: number;\n}\n\nexport interface ChronicleTaskOutcomeRow {\n taskId: string;\n runId: string;\n boardId: string;\n sessionId: string;\n agentId: string;\n status: string;\n startedAt: string | null;\n endedAt: string | null;\n durationMs: number | null;\n retries: number;\n verificationFailures: number;\n filesTouched: number;\n}\n\nexport interface ChronicleFileLineageRow {\n path: string;\n operation: string;\n occurredAt: string;\n sessionId: string;\n agentId: string;\n taskId: string;\n boardId: string;\n runId: string;\n toolName: string;\n providerId: string;\n modelId: string;\n source: string;\n}\n\nexport interface ChronicleMetricsSummary {\n providers: { attempts: number; completed: number; failed: number; successRate: number };\n tasks: Record<string, number>;\n files: { mutations: number; uniquePaths: number };\n estimatedCostUsd: number;\n}\n\n// \u2500\u2500\u2500 node:sqlite lazy loader (mirrors SAGE's pattern, compacted) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nlet Ctor: typeof DatabaseSync | null | undefined;\n\nfunction loadDatabaseSync(): typeof DatabaseSync {\n if (Ctor) return Ctor;\n if (Ctor === null) throw new Error('node:sqlite is unavailable in this runtime');\n try {\n Ctor = withSqliteExperimentalWarningSuppressed(\n () => (createRequire(import.meta.url)('node:sqlite') as typeof import('node:sqlite')).DatabaseSync,\n );\n return Ctor;\n } catch (error) {\n Ctor = null;\n throw new Error(\n \"Chronicle metrics need Node's built-in SQLite (node:sqlite, Node >= 22.5): \" +\n (error instanceof Error ? error.message : String(error)),\n );\n }\n}\n\n/** Non-throwing availability probe for callers that degrade gracefully. */\nexport function isChronicleMetricsAvailable(): boolean {\n try {\n loadDatabaseSync();\n return true;\n } catch {\n return false;\n }\n}\n\n// \u2500\u2500\u2500 Store \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport class ChronicleMetricsStore {\n private readonly db: DatabaseSync;\n private readonly directory: string;\n private readonly dbPath: string;\n\n private constructor(directory: string) {\n this.directory = path.resolve(directory);\n this.dbPath = path.join(this.directory, 'metrics.db');\n const Database = loadDatabaseSync();\n this.db = new Database(this.dbPath);\n this.db.exec('PRAGMA journal_mode = WAL');\n this.ensureSchema();\n }\n\n static open(chronicleDirectory: string): ChronicleMetricsStore {\n return new ChronicleMetricsStore(chronicleDirectory);\n }\n\n close(): void {\n this.db.close();\n }\n\n /** Incrementally ingest journal bytes appended since the last refresh.\n * Safe across processes: guarded by a file lock on the database path. */\n async refresh(): Promise<ChronicleMetricsRefreshResult> {\n const result: ChronicleMetricsRefreshResult = {\n ingestedEvents: 0,\n ingestedBytes: 0,\n sourceFiles: 0,\n invalidLines: 0,\n };\n await withFileLock(this.dbPath, async () => {\n const files = await findChroniclePartitions(this.directory);\n const offsets = this.loadOffsets();\n for (const file of files) {\n const key = normalizeKey(path.relative(this.directory, file));\n const consumed = offsets.get(key) ?? 0;\n const ingested = await this.ingestFile(file, key, consumed, result);\n if (ingested) result.sourceFiles++;\n }\n this.pruneOffsets(files);\n });\n return result;\n }\n\n providerDaily(options: { from?: string; to?: string } = {}): ChronicleProviderDailyRow[] {\n const clauses: string[] = [];\n const params: string[] = [];\n if (options.from) {\n clauses.push('day >= ?');\n params.push(options.from.slice(0, 10));\n }\n if (options.to) {\n clauses.push('day <= ?');\n params.push(options.to.slice(0, 10));\n }\n const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';\n const rows = this.db\n .prepare(\n `SELECT day, provider_id, model_id, attempts, completed, failed, retries, fallbacks,\n input_tokens, output_tokens, cache_read_tokens, cache_write_tokens,\n duration_ms_total, duration_ms_max, duration_count\n FROM provider_daily${where} ORDER BY day DESC, provider_id, model_id`,\n )\n .all(...params) as Array<Record<string, string | number>>;\n return rows.map((row) => ({\n day: String(row.day),\n providerId: String(row.provider_id),\n modelId: String(row.model_id),\n attempts: Number(row.attempts),\n completed: Number(row.completed),\n failed: Number(row.failed),\n retries: Number(row.retries),\n fallbacks: Number(row.fallbacks),\n inputTokens: Number(row.input_tokens),\n outputTokens: Number(row.output_tokens),\n cacheReadTokens: Number(row.cache_read_tokens),\n cacheWriteTokens: Number(row.cache_write_tokens),\n avgDurationMs:\n Number(row.duration_count) > 0\n ? Number(row.duration_ms_total) / Number(row.duration_count)\n : 0,\n maxDurationMs: Number(row.duration_ms_max),\n }));\n }\n\n taskOutcomes(\n options: {\n runId?: string;\n boardId?: string;\n sessionId?: string;\n status?: string;\n limit?: number;\n } = {},\n ): ChronicleTaskOutcomeRow[] {\n const clauses: string[] = [];\n const params: Array<string | number> = [];\n if (options.runId) {\n clauses.push('t.run_id = ?');\n params.push(options.runId);\n }\n if (options.boardId) {\n clauses.push('t.board_id = ?');\n params.push(options.boardId);\n }\n if (options.sessionId) {\n clauses.push('t.session_id = ?');\n params.push(options.sessionId);\n }\n if (options.status) {\n clauses.push('t.status = ?');\n params.push(options.status);\n }\n const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';\n params.push(clampLimit(options.limit, 100));\n const rows = this.db\n .prepare(\n `SELECT t.*, (SELECT COUNT(*) FROM file_lineage f WHERE f.task_id = t.task_id) AS files_touched\n FROM task_outcomes t${where}\n ORDER BY COALESCE(t.started_at, '') DESC LIMIT ?`,\n )\n .all(...params) as Array<Record<string, string | number | null>>;\n return rows.map((row) => ({\n taskId: String(row.task_id),\n runId: String(row.run_id),\n boardId: String(row.board_id),\n sessionId: String(row.session_id),\n agentId: String(row.agent_id),\n status: String(row.status),\n startedAt: row.started_at === null ? null : String(row.started_at),\n endedAt: row.ended_at === null ? null : String(row.ended_at),\n durationMs: row.duration_ms === null ? null : Number(row.duration_ms),\n retries: Number(row.retries),\n verificationFailures: Number(row.verification_failures),\n filesTouched: Number(row.files_touched),\n }));\n }\n\n fileLineage(\n options: {\n path?: string;\n paths?: string[];\n latestPerPath?: boolean;\n taskId?: string;\n boardId?: string;\n sessionId?: string;\n limit?: number;\n } = {},\n ): ChronicleFileLineageRow[] {\n const clauses: string[] = [];\n const params: Array<string | number> = [];\n if (options.path) {\n clauses.push('path_key = ?');\n params.push(normalizePathKey(options.path));\n }\n if (options.paths) {\n const pathKeys = [...new Set(options.paths.map(normalizePathKey))];\n if (pathKeys.length === 0) return [];\n clauses.push(`path_key IN (${pathKeys.map(() => '?').join(',')})`);\n params.push(...pathKeys);\n }\n if (options.taskId) {\n clauses.push('task_id = ?');\n params.push(options.taskId);\n }\n if (options.boardId) {\n clauses.push('board_id = ?');\n params.push(options.boardId);\n }\n if (options.sessionId) {\n clauses.push('session_id = ?');\n params.push(options.sessionId);\n }\n const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';\n params.push(clampLimit(options.limit, 200));\n const projection =\n `path, operation, occurred_at, session_id, agent_id, task_id, board_id, run_id,\n tool_name, provider_id, model_id, source`;\n const sql = options.latestPerPath\n ? `SELECT ${projection} FROM (\n SELECT ${projection}, ROW_NUMBER() OVER (\n PARTITION BY path_key ORDER BY occurred_at DESC, event_id DESC\n ) AS path_rank\n FROM file_lineage${where}\n ) WHERE path_rank = 1 ORDER BY occurred_at DESC LIMIT ?`\n : `SELECT ${projection}\n FROM file_lineage${where} ORDER BY occurred_at DESC LIMIT ?`;\n const rows = this.db\n .prepare(sql)\n .all(...params) as Array<Record<string, string>>;\n return rows.map((row) => ({\n path: row.path!,\n operation: row.operation!,\n occurredAt: row.occurred_at!,\n sessionId: row.session_id!,\n agentId: row.agent_id!,\n taskId: row.task_id!,\n boardId: row.board_id!,\n runId: row.run_id!,\n toolName: row.tool_name!,\n providerId: row.provider_id!,\n modelId: row.model_id!,\n source: row.source!,\n }));\n }\n\n summary(): ChronicleMetricsSummary {\n const provider = this.db\n .prepare(\n 'SELECT COALESCE(SUM(attempts),0) a, COALESCE(SUM(completed),0) c, COALESCE(SUM(failed),0) f FROM provider_daily',\n )\n .get() as { a: number; c: number; f: number };\n const tasks: Record<string, number> = {};\n for (const row of this.db\n .prepare('SELECT status, COUNT(*) n FROM task_outcomes GROUP BY status')\n .all() as Array<{ status: string; n: number }>) {\n tasks[row.status] = Number(row.n);\n }\n const files = this.db\n .prepare('SELECT COUNT(*) n, COUNT(DISTINCT path) p FROM file_lineage')\n .get() as { n: number; p: number };\n const cost = this.db.prepare('SELECT COALESCE(SUM(cost),0) c FROM token_cost').get() as {\n c: number;\n };\n const terminal = Number(provider.c) + Number(provider.f);\n return {\n providers: {\n attempts: Number(provider.a),\n completed: Number(provider.c),\n failed: Number(provider.f),\n successRate: terminal > 0 ? Number(provider.c) / terminal : 0,\n },\n tasks,\n files: { mutations: Number(files.n), uniquePaths: Number(files.p) },\n estimatedCostUsd: Number(cost.c),\n };\n }\n\n /**\n * A `ChronicleSummary` for the default/unfiltered dashboard view \u2014 only\n * `from`/`to` (day-precision) narrow it. Any other ad hoc filter (text,\n * path, provider, model, session) can't be answered from these\n * fixed-dimension aggregates; callers must fall back to query.ts's\n * raw-scan summary for those.\n */\n defaultSummary(options: { from?: string; to?: string } = {}): ChronicleSummary {\n const fromDay = options.from?.slice(0, 10);\n const toDay = options.to?.slice(0, 10);\n const dayFilter = (column: string): { where: string; params: string[] } => {\n const clauses: string[] = [];\n const params: string[] = [];\n if (fromDay) { clauses.push(`${column} >= ?`); params.push(fromDay); }\n if (toDay) { clauses.push(`${column} <= ?`); params.push(toDay); }\n return { where: clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '', params };\n };\n\n const providerRange = dayFilter('day');\n const provider = this.db\n .prepare(\n `SELECT COALESCE(SUM(attempts),0) attempts, COALESCE(SUM(completed),0) completed, COALESCE(SUM(failed),0) failed,\n COALESCE(SUM(retries),0) retries, COALESCE(SUM(fallbacks),0) fallbacks,\n COUNT(DISTINCT provider_id) providers, COUNT(DISTINCT model_id) models,\n COALESCE(SUM(input_tokens),0) inputTokens, COALESCE(SUM(output_tokens),0) outputTokens,\n COALESCE(SUM(cache_read_tokens),0) cacheReadTokens, COALESCE(SUM(cache_write_tokens),0) cacheWriteTokens,\n COALESCE(SUM(duration_ms_total),0) durationTotal, COALESCE(MAX(duration_ms_max),0) durationMax,\n COALESCE(SUM(duration_count),0) durationCount\n FROM provider_daily${providerRange.where}`,\n )\n .get(...providerRange.params) as Record<string, number>;\n\n const counterRange = dayFilter('day');\n const counters = this.db\n .prepare(\n `SELECT COALESCE(SUM(tool_calls),0) toolCalls, COALESCE(SUM(completed_tools),0) completedTools,\n COALESCE(SUM(failed_tools),0) failedTools, COALESCE(SUM(tool_duration_ms_total),0) toolDurationTotal,\n COALESCE(SUM(tool_duration_count),0) toolDurationCount, COALESCE(SUM(processes),0) processes,\n COALESCE(SUM(failed_processes),0) failedProcesses, COALESCE(SUM(file_events_all),0) fileEvents,\n COALESCE(SUM(decisions),0) decisions, COALESCE(SUM(escalations),0) escalations,\n COALESCE(SUM(agent_events),0) agentEvents, COALESCE(SUM(failures),0) failures,\n COALESCE(SUM(cancellations),0) cancellations\n FROM daily_counters${counterRange.where}`,\n )\n .get(...counterRange.params) as Record<string, number>;\n\n const familyRange = dayFilter('day');\n const familyRows = this.db\n .prepare(`SELECT family, count, failure_count FROM family_daily${familyRange.where}`)\n .all(...familyRange.params) as Array<{ family: string; count: number; failure_count: number }>;\n const families = { ...EMPTY_FAMILIES };\n const failuresByFamily = { ...EMPTY_FAMILIES };\n for (const row of familyRows) {\n const family = row.family as ChronicleSignalFamily;\n families[family] = Number(row.count);\n failuresByFamily[family] = Number(row.failure_count);\n }\n\n const agentRange = dayFilter('day');\n const uniqueAgents = (\n this.db.prepare(`SELECT COUNT(DISTINCT agent_id) n FROM agent_daily${agentRange.where}`).get(...agentRange.params) as { n: number }\n ).n;\n const requestRange = dayFilter('day');\n const logicalRequests = (\n this.db.prepare(`SELECT COUNT(DISTINCT logical_request_id) n FROM logical_request_daily${requestRange.where}`).get(...requestRange.params) as { n: number }\n ).n;\n const fileRange = dayFilter('day');\n const uniqueFiles = (\n this.db.prepare(`SELECT COUNT(DISTINCT path_key) n FROM file_seen_daily${fileRange.where}`).get(...fileRange.params) as { n: number }\n ).n;\n const costRange = dayFilter('day');\n const cost = (\n this.db.prepare(`SELECT COALESCE(SUM(cost),0) c FROM token_cost${costRange.where}`).get(...costRange.params) as { c: number }\n ).c;\n\n return {\n logicalRequests: Number(logicalRequests),\n modelAttempts: Number(provider.attempts),\n completedAttempts: Number(provider.completed),\n failedAttempts: Number(provider.failed),\n scheduledRetries: Number(provider.retries),\n fallbacks: Number(provider.fallbacks),\n providers: Number(provider.providers),\n models: Number(provider.models),\n inputTokens: Number(provider.inputTokens),\n outputTokens: Number(provider.outputTokens),\n cacheReadTokens: Number(provider.cacheReadTokens),\n cacheWriteTokens: Number(provider.cacheWriteTokens),\n estimatedCostUsd: Number(cost),\n providerAvgDurationMs: Number(provider.durationCount) > 0 ? Number(provider.durationTotal) / Number(provider.durationCount) : 0,\n // True p95 needs a retained distribution; this per-day aggregate only\n // keeps sum/max/count, so approximate with the observed max rather\n // than adding a per-attempt histogram write (would add the same kind\n // of per-event overhead this whole effort is trying to remove).\n providerP95DurationMs: Number(provider.durationMax),\n toolCalls: Number(counters.toolCalls),\n completedTools: Number(counters.completedTools),\n failedTools: Number(counters.failedTools),\n toolAvgDurationMs: Number(counters.toolDurationCount) > 0 ? Number(counters.toolDurationTotal) / Number(counters.toolDurationCount) : 0,\n processes: Number(counters.processes),\n failedProcesses: Number(counters.failedProcesses),\n fileEvents: Number(counters.fileEvents),\n uniqueFiles: Number(uniqueFiles),\n agentEvents: Number(counters.agentEvents),\n uniqueAgents: Number(uniqueAgents),\n decisions: Number(counters.decisions),\n escalations: Number(counters.escalations),\n failures: Number(counters.failures),\n cancellations: Number(counters.cancellations),\n families,\n failuresByFamily,\n };\n }\n\n // \u2500\u2500\u2500 Ingest internals \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n private ensureSchema(): void {\n const version = (this.db.prepare('PRAGMA user_version').get() as { user_version: number })\n .user_version;\n if (version !== 0 && version !== SCHEMA_VERSION) {\n // Derived cache \u2014 drop and re-ingest from whatever journal remains.\n this.db.exec(\n 'DROP TABLE IF EXISTS ingest_state; DROP TABLE IF EXISTS provider_daily;' +\n 'DROP TABLE IF EXISTS task_outcomes; DROP TABLE IF EXISTS file_lineage;' +\n 'DROP TABLE IF EXISTS token_cost; DROP TABLE IF EXISTS daily_counters;' +\n 'DROP TABLE IF EXISTS family_daily; DROP TABLE IF EXISTS agent_daily;' +\n 'DROP TABLE IF EXISTS logical_request_daily; DROP TABLE IF EXISTS file_seen_daily;',\n );\n }\n this.db.exec(`\n CREATE TABLE IF NOT EXISTS ingest_state (\n file TEXT PRIMARY KEY,\n bytes INTEGER NOT NULL\n );\n CREATE TABLE IF NOT EXISTS provider_daily (\n day TEXT NOT NULL,\n provider_id TEXT NOT NULL,\n model_id TEXT NOT NULL,\n attempts INTEGER NOT NULL DEFAULT 0,\n completed INTEGER NOT NULL DEFAULT 0,\n failed INTEGER NOT NULL DEFAULT 0,\n retries INTEGER NOT NULL DEFAULT 0,\n fallbacks INTEGER NOT NULL DEFAULT 0,\n input_tokens INTEGER NOT NULL DEFAULT 0,\n output_tokens INTEGER NOT NULL DEFAULT 0,\n cache_read_tokens INTEGER NOT NULL DEFAULT 0,\n cache_write_tokens INTEGER NOT NULL DEFAULT 0,\n duration_ms_total REAL NOT NULL DEFAULT 0,\n duration_ms_max REAL NOT NULL DEFAULT 0,\n duration_count INTEGER NOT NULL DEFAULT 0,\n PRIMARY KEY (day, provider_id, model_id)\n );\n CREATE TABLE IF NOT EXISTS task_outcomes (\n task_id TEXT PRIMARY KEY,\n run_id TEXT NOT NULL DEFAULT '',\n board_id TEXT NOT NULL DEFAULT '',\n session_id TEXT NOT NULL DEFAULT '',\n agent_id TEXT NOT NULL DEFAULT '',\n status TEXT NOT NULL DEFAULT 'started',\n started_at TEXT,\n ended_at TEXT,\n duration_ms REAL,\n retries INTEGER NOT NULL DEFAULT 0,\n verification_failures INTEGER NOT NULL DEFAULT 0\n );\n CREATE TABLE IF NOT EXISTS file_lineage (\n event_id TEXT PRIMARY KEY,\n path TEXT NOT NULL,\n path_key TEXT NOT NULL,\n operation TEXT NOT NULL,\n occurred_at TEXT NOT NULL,\n session_id TEXT NOT NULL DEFAULT '',\n agent_id TEXT NOT NULL DEFAULT '',\n task_id TEXT NOT NULL DEFAULT '',\n board_id TEXT NOT NULL DEFAULT '',\n run_id TEXT NOT NULL DEFAULT '',\n tool_name TEXT NOT NULL DEFAULT '',\n provider_id TEXT NOT NULL DEFAULT '',\n model_id TEXT NOT NULL DEFAULT '',\n source TEXT NOT NULL DEFAULT ''\n );\n -- Lookups filter on the case-normalized path_key (matching the query\n -- engine); the path column retains original casing for display.\n CREATE INDEX IF NOT EXISTS idx_file_lineage_path ON file_lineage(path_key, occurred_at);\n CREATE INDEX IF NOT EXISTS idx_file_lineage_task ON file_lineage(task_id);\n CREATE TABLE IF NOT EXISTS token_cost (\n scope_key TEXT PRIMARY KEY,\n day TEXT NOT NULL,\n occurred_at TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n cost REAL NOT NULL\n );\n -- Backing store for defaultSummary(): per-day scalar counters plus\n -- dedup sets, populated for every ingested event (not just the\n -- provider/task/file families above).\n CREATE TABLE IF NOT EXISTS daily_counters (\n day TEXT PRIMARY KEY,\n tool_calls INTEGER NOT NULL DEFAULT 0,\n completed_tools INTEGER NOT NULL DEFAULT 0,\n failed_tools INTEGER NOT NULL DEFAULT 0,\n tool_duration_ms_total REAL NOT NULL DEFAULT 0,\n tool_duration_ms_max REAL NOT NULL DEFAULT 0,\n tool_duration_count INTEGER NOT NULL DEFAULT 0,\n processes INTEGER NOT NULL DEFAULT 0,\n failed_processes INTEGER NOT NULL DEFAULT 0,\n file_events_all INTEGER NOT NULL DEFAULT 0,\n decisions INTEGER NOT NULL DEFAULT 0,\n escalations INTEGER NOT NULL DEFAULT 0,\n agent_events INTEGER NOT NULL DEFAULT 0,\n failures INTEGER NOT NULL DEFAULT 0,\n cancellations INTEGER NOT NULL DEFAULT 0\n );\n CREATE TABLE IF NOT EXISTS family_daily (\n day TEXT NOT NULL,\n family TEXT NOT NULL,\n count INTEGER NOT NULL DEFAULT 0,\n failure_count INTEGER NOT NULL DEFAULT 0,\n PRIMARY KEY (day, family)\n );\n CREATE TABLE IF NOT EXISTS agent_daily (day TEXT NOT NULL, agent_id TEXT NOT NULL, PRIMARY KEY (day, agent_id));\n CREATE TABLE IF NOT EXISTS logical_request_daily (day TEXT NOT NULL, logical_request_id TEXT NOT NULL, PRIMARY KEY (day, logical_request_id));\n CREATE TABLE IF NOT EXISTS file_seen_daily (day TEXT NOT NULL, path_key TEXT NOT NULL, PRIMARY KEY (day, path_key));\n PRAGMA user_version = ${SCHEMA_VERSION};\n `);\n }\n\n private loadOffsets(): Map<string, number> {\n const rows = this.db.prepare('SELECT file, bytes FROM ingest_state').all() as Array<{\n file: string;\n bytes: number;\n }>;\n return new Map(rows.map((row) => [row.file, Number(row.bytes)]));\n }\n\n private pruneOffsets(existingFiles: string[]): void {\n const keep = new Set(\n existingFiles.map((file) => normalizeKey(path.relative(this.directory, file))),\n );\n for (const row of this.db.prepare('SELECT file FROM ingest_state').all() as Array<{\n file: string;\n }>) {\n if (!keep.has(row.file))\n this.db.prepare('DELETE FROM ingest_state WHERE file = ?').run(row.file);\n }\n }\n\n /** Read complete lines appended after `consumed` bytes. The trailing\n * partial line of an actively-written partition is left for the next\n * refresh \u2014 `ingest_state.bytes` only ever advances past full lines. */\n private async ingestFile(\n file: string,\n key: string,\n consumed: number,\n result: ChronicleMetricsRefreshResult,\n ): Promise<boolean> {\n let handle: fs.FileHandle;\n try {\n handle = await fs.open(file, 'r');\n } catch {\n return false;\n }\n try {\n const size = (await handle.stat()).size;\n if (size <= consumed) return false;\n let position = consumed;\n let remainder = Buffer.alloc(0);\n let advanced = consumed;\n this.db.exec('BEGIN');\n try {\n while (position < size) {\n const length = Math.min(READ_CHUNK_BYTES, size - position);\n const buffer = Buffer.allocUnsafe(length);\n const { bytesRead } = await handle.read(buffer, 0, length, position);\n if (bytesRead <= 0) break;\n position += bytesRead;\n const data =\n remainder.length > 0\n ? Buffer.concat([remainder, buffer.subarray(0, bytesRead)])\n : buffer.subarray(0, bytesRead);\n const lastNewline = data.lastIndexOf(0x0a);\n if (lastNewline < 0) {\n remainder = Buffer.from(data);\n continue;\n }\n // '\\n' is a single byte in UTF-8, so complete-line slices always\n // fall on character boundaries.\n for (const line of data.subarray(0, lastNewline).toString('utf8').split('\\n')) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n try {\n this.ingestEvent(JSON.parse(trimmed) as ChronicleEvent);\n result.ingestedEvents++;\n } catch {\n result.invalidLines++;\n }\n }\n // `data` always begins at absolute offset `advanced` (remainder is\n // exactly the unconsumed bytes), so the newline index maps directly.\n advanced += lastNewline + 1;\n remainder = Buffer.from(data.subarray(lastNewline + 1));\n }\n this.db\n .prepare(\n 'INSERT INTO ingest_state (file, bytes) VALUES (?, ?) ' +\n 'ON CONFLICT(file) DO UPDATE SET bytes = excluded.bytes',\n )\n .run(key, advanced);\n this.db.exec('COMMIT');\n } catch (error) {\n this.db.exec('ROLLBACK');\n throw error;\n }\n result.ingestedBytes += advanced - consumed;\n return advanced > consumed;\n } finally {\n await handle.close();\n }\n }\n\n private ingestEvent(event: ChronicleEvent): void {\n if (typeof event?.eventType !== 'string' || !event.scope) return;\n this.ingestDailyCounters(event);\n const type = event.eventType;\n if (type.startsWith('provider.attempt.') || type === 'provider.fallback') {\n this.ingestProvider(event);\n } else if (type === 'token.accounted') {\n this.ingestTokenCost(event);\n } else if (/^(?:sdd|subagent|kanban)\\.task[._]/.test(type)) {\n this.ingestTask(event);\n } else if (type === 'file.event' || /^file\\.(?:tool|external)\\./.test(type)) {\n this.ingestFileEvent(event);\n }\n }\n\n /** Runs for every ingested event (not just the type-specific branches\n * below) \u2014 mirrors query.ts's updateSummary() closely enough that\n * defaultSummary() matches what a raw scan of the same window would say. */\n private ingestDailyCounters(event: ChronicleEvent): void {\n const day = eventDay(event);\n this.db.prepare('INSERT OR IGNORE INTO daily_counters (day) VALUES (?)').run(day);\n const bump = (sql: string, ...params: Array<string | number>) =>\n this.db.prepare(`UPDATE daily_counters SET ${sql} WHERE day = ?`).run(...params, day);\n\n const family = signalFamily(event);\n const failed = isTerminalFailure(event) ? 1 : 0;\n this.db\n .prepare(\n `INSERT INTO family_daily (day, family, count, failure_count) VALUES (?, ?, 1, ?)\n ON CONFLICT(day, family) DO UPDATE SET count = count + 1, failure_count = failure_count + excluded.failure_count`,\n )\n .run(day, family, failed);\n if (failed) bump('failures = failures + 1');\n if (event.outcome === 'cancelled' || event.outcome === 'abandoned') bump('cancellations = cancellations + 1');\n if (family === 'agent') bump('agent_events = agent_events + 1');\n\n if (event.correlation.logicalRequestId) {\n this.db\n .prepare('INSERT OR IGNORE INTO logical_request_daily (day, logical_request_id) VALUES (?, ?)')\n .run(day, event.correlation.logicalRequestId);\n }\n if (event.scope.agentId) {\n this.db.prepare('INSERT OR IGNORE INTO agent_daily (day, agent_id) VALUES (?, ?)').run(day, event.scope.agentId);\n }\n\n const type = event.eventType;\n if (type === 'decision.requested') bump('decisions = decisions + 1');\n else if (type === 'decision.escalated') bump('escalations = escalations + 1');\n else if (type === 'tool.started') bump('tool_calls = tool_calls + 1');\n else if (type === 'tool.executed' || type === 'tool.failed') {\n const dur = durationMs(event);\n const durationCount = dur > 0 ? 1 : 0;\n bump(\n `${type === 'tool.executed' ? 'completed_tools' : 'failed_tools'} = ${type === 'tool.executed' ? 'completed_tools' : 'failed_tools'} + 1,\n tool_duration_ms_total = tool_duration_ms_total + ?, tool_duration_ms_max = MAX(tool_duration_ms_max, ?), tool_duration_count = tool_duration_count + ?`,\n dur, dur, durationCount,\n );\n } else if (type === 'process.started') bump('processes = processes + 1');\n else if (type === 'process.completed' && event.outcome === 'failure') bump('failed_processes = failed_processes + 1');\n\n if (event.resource?.kind === 'file' || type.startsWith('file.')) {\n bump('file_events_all = file_events_all + 1');\n if (event.resource?.path) {\n this.db\n .prepare('INSERT OR IGNORE INTO file_seen_daily (day, path_key) VALUES (?, ?)')\n .run(day, normalizePathKey(event.resource.path));\n }\n }\n }\n\n private ingestProvider(event: ChronicleEvent): void {\n const day = eventDay(event);\n // provider.fallback carries no top-level runtime identity \u2014 it belongs to\n // the provider being fallen back FROM, held in attributes.from. Attribute\n // it there rather than letting it manufacture a phantom ('', '') row.\n const providerId =\n event.runtime?.providerId ?? asString(readPath(event.attributes ?? {}, 'from.providerId')) ?? '';\n const modelId =\n event.runtime?.modelId ?? asString(readPath(event.attributes ?? {}, 'from.model')) ?? '';\n // No identity at all \u2192 not attributable to any provider row; skip.\n if (!providerId && !modelId) return;\n this.db\n .prepare('INSERT OR IGNORE INTO provider_daily (day, provider_id, model_id) VALUES (?, ?, ?)')\n .run(day, providerId, modelId);\n const update = (sql: string, ...params: Array<string | number>) =>\n this.db\n .prepare(\n `UPDATE provider_daily SET ${sql} WHERE day = ? AND provider_id = ? AND model_id = ?`,\n )\n .run(...params, day, providerId, modelId);\n const duration = durationMs(event);\n switch (event.eventType) {\n case 'provider.attempt.started':\n update('attempts = attempts + 1');\n break;\n case 'provider.attempt.completed':\n update(\n 'completed = completed + 1, input_tokens = input_tokens + ?, output_tokens = output_tokens + ?, ' +\n 'cache_read_tokens = cache_read_tokens + ?, cache_write_tokens = cache_write_tokens + ?, ' +\n 'duration_ms_total = duration_ms_total + ?, duration_ms_max = MAX(duration_ms_max, ?), ' +\n 'duration_count = duration_count + ?',\n numberAt(event, 'usage.input'),\n numberAt(event, 'usage.output'),\n numberAt(event, 'usage.cacheRead'),\n numberAt(event, 'usage.cacheWrite'),\n duration,\n duration,\n duration > 0 ? 1 : 0,\n );\n break;\n case 'provider.attempt.failed':\n update(\n 'failed = failed + 1, retries = retries + ?, duration_ms_total = duration_ms_total + ?, ' +\n 'duration_ms_max = MAX(duration_ms_max, ?), duration_count = duration_count + ?',\n event.attributes?.retryScheduled === true ? 1 : 0,\n duration,\n duration,\n duration > 0 ? 1 : 0,\n );\n break;\n case 'provider.fallback':\n update('fallbacks = fallbacks + 1');\n break;\n default:\n break;\n }\n }\n\n private ingestTokenCost(event: ChronicleEvent): void {\n const cost = readPath(event.attributes ?? {}, 'cost.total');\n if (typeof cost !== 'number' || !Number.isFinite(cost)) return;\n const scopeKey = `${event.scope.projectId ?? ''}\\0${event.scope.sessionId ?? ''}\\0${event.scope.agentId ?? ''}`;\n const occurredAt = event.occurredAt ?? event.observedAt;\n // Latest-wins per scope: token.accounted carries a cumulative snapshot.\n this.db\n .prepare(\n `INSERT INTO token_cost (scope_key, day, occurred_at, sequence, cost) VALUES (?, ?, ?, ?, ?)\n ON CONFLICT(scope_key) DO UPDATE SET\n day = excluded.day, occurred_at = excluded.occurred_at,\n sequence = excluded.sequence, cost = excluded.cost\n WHERE excluded.occurred_at > token_cost.occurred_at\n OR (excluded.occurred_at = token_cost.occurred_at AND excluded.sequence > token_cost.sequence)`,\n )\n .run(scopeKey, eventDay(event), occurredAt, event.sequence, cost);\n }\n\n private ingestTask(event: ChronicleEvent): void {\n const attributes = event.attributes ?? {};\n const taskId = event.scope.taskId ?? stringAt(attributes, 'taskId');\n if (!taskId) return;\n const occurredAt = event.occurredAt ?? event.observedAt;\n this.db.prepare('INSERT OR IGNORE INTO task_outcomes (task_id) VALUES (?)').run(taskId);\n const set = (sql: string, ...params: Array<string | number>) =>\n this.db.prepare(`UPDATE task_outcomes SET ${sql} WHERE task_id = ?`).run(...params, taskId);\n // Lineage columns: last non-empty observation wins.\n const lineage: Array<[string, string | undefined]> = [\n ['run_id', stringAt(attributes, 'runId')],\n ['board_id', event.scope.kanbanBoardId ?? stringAt(attributes, 'boardId')],\n ['session_id', event.scope.sessionId],\n ['agent_id', event.scope.agentId ?? stringAt(attributes, 'subagentId')],\n ];\n for (const [column, value] of lineage) {\n if (value) set(`${column} = ?`, value);\n }\n const base = event.eventType.replace(/^(?:sdd|subagent|kanban)\\.task[._]/, '');\n switch (base) {\n case 'started':\n set(\"status = 'started', started_at = COALESCE(started_at, ?)\", occurredAt);\n break;\n case 'completed':\n set(\n \"status = 'completed', ended_at = ?, duration_ms = ?\",\n occurredAt,\n numberOrDuration(event, attributes),\n );\n break;\n case 'failed':\n set(\"status = 'failed', ended_at = ?\", occurredAt);\n break;\n case 'retrying':\n set('retries = retries + 1');\n break;\n case 'verification_failed':\n set('verification_failures = verification_failures + 1');\n break;\n case 'merged':\n set(\"status = 'merged'\");\n break;\n case 'conflict':\n set(\"status = 'conflict'\");\n break;\n default:\n break;\n }\n }\n\n private ingestFileEvent(event: ChronicleEvent): void {\n const attributes = event.attributes ?? {};\n const operation = stringAt(attributes, 'operation') ?? '';\n if (!operation || operation === 'read') return;\n const filePath = event.resource?.path ?? stringAt(attributes, 'filePath');\n if (!filePath) return;\n this.db\n .prepare(\n `INSERT OR IGNORE INTO file_lineage\n (event_id, path, path_key, operation, occurred_at, session_id, agent_id, task_id, board_id, run_id,\n tool_name, provider_id, model_id, source)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n )\n .run(\n event.eventId,\n normalizeKey(filePath),\n normalizePathKey(filePath),\n operation,\n event.occurredAt ?? event.observedAt,\n event.scope.sessionId ?? '',\n event.scope.agentId ?? '',\n event.scope.taskId ?? stringAt(attributes, 'taskId') ?? '',\n event.scope.kanbanBoardId ?? stringAt(attributes, 'boardId') ?? '',\n stringAt(attributes, 'runId') ?? '',\n stringAt(attributes, 'toolName') ?? '',\n event.runtime?.providerId ?? stringAt(attributes, 'provider') ?? '',\n event.runtime?.modelId ?? stringAt(attributes, 'model') ?? '',\n stringAt(attributes, 'source') ?? (event.eventType === 'file.event' ? 'tool' : 'external'),\n );\n }\n}\n\n// \u2500\u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction eventDay(event: ChronicleEvent): string {\n return (event.occurredAt ?? event.observedAt).slice(0, 10);\n}\n\nfunction durationMs(event: ChronicleEvent): number {\n const value = Number(event.durationNs ?? 0) / 1_000_000;\n return Number.isFinite(value) && value > 0 ? value : 0;\n}\n\nfunction numberOrDuration(event: ChronicleEvent, attributes: Record<string, unknown>): number {\n const explicit = attributes.durationMs;\n if (typeof explicit === 'number' && Number.isFinite(explicit)) return explicit;\n return durationMs(event);\n}\n\nfunction numberAt(event: ChronicleEvent, dotPath: string): number {\n const value = readPath(event.attributes ?? {}, dotPath);\n return typeof value === 'number' && Number.isFinite(value) ? value : 0;\n}\n\nfunction readPath(value: Record<string, unknown>, key: string): unknown {\n return key\n .split('.')\n .reduce<unknown>(\n (current, part) =>\n current && typeof current === 'object'\n ? (current as Record<string, unknown>)[part]\n : undefined,\n value,\n );\n}\n\nfunction stringAt(record: Record<string, unknown>, key: string): string | undefined {\n const value = record[key];\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction asString(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction clampLimit(limit: number | undefined, fallback: number): number {\n if (typeof limit !== 'number' || !Number.isFinite(limit) || limit <= 0) return fallback;\n return Math.min(Math.floor(limit), 10_000);\n}\n\nfunction normalizeKey(value: string): string {\n return value.replaceAll('\\\\', '/');\n}\n\n/** Case-normalized path key for lineage lookups. Mirrors the query engine's\n * path comparison (lowercase + forward-slash) and additionally strips a\n * leading `./` so a repo-relative path matches however the tool reported it \u2014\n * case differences on Windows are the common mismatch. */\nfunction normalizePathKey(value: string): string {\n return value.replaceAll('\\\\', '/').replace(/^\\.\\//, '').toLowerCase();\n}\n", "const SQLITE_EXPERIMENTAL_WARNING_RE = /sqlite is an experimental feature/i;\n\nfunction isSqliteExperimentalWarning(warning: unknown, rest: readonly unknown[]): boolean {\n const message = typeof warning === 'string' ? warning : warning instanceof Error ? warning.message : '';\n const typeOrOptions = rest[0];\n const warningType =\n typeof warning === 'string'\n ? typeof typeOrOptions === 'string'\n ? typeOrOptions\n : typeof typeOrOptions === 'object' &&\n typeOrOptions !== null &&\n 'type' in typeOrOptions &&\n typeof typeOrOptions.type === 'string'\n ? typeOrOptions.type\n : ''\n : warning instanceof Error\n ? warning.name\n : '';\n const warningCode =\n typeof warning === 'string'\n ? typeof typeOrOptions === 'object' &&\n typeOrOptions !== null &&\n 'code' in typeOrOptions &&\n typeof typeOrOptions.code === 'string'\n ? typeOrOptions.code\n : typeof rest[1] === 'string'\n ? rest[1]\n : ''\n : warning instanceof Error && 'code' in warning && typeof warning.code === 'string'\n ? warning.code\n : '';\n\n return (\n SQLITE_EXPERIMENTAL_WARNING_RE.test(message) &&\n (warningType === 'ExperimentalWarning' || warningCode === 'ExperimentalWarning')\n );\n}\n\n/**\n * Run a synchronous `node:sqlite` load while filtering only Node's built-in\n * SQLite ExperimentalWarning. All other warnings still go through the original\n * process warning path, and the patch is removed before returning.\n */\nexport function withSqliteExperimentalWarningSuppressed<T>(run: () => T): T {\n const originalEmitWarning = process.emitWarning;\n const forwardWarning = originalEmitWarning.bind(process) as (\n warning: unknown,\n ...rest: unknown[]\n ) => void;\n\n process.emitWarning = ((warning: unknown, ...rest: unknown[]): void => {\n if (isSqliteExperimentalWarning(warning, rest)) return;\n forwardWarning(warning, ...rest);\n }) as typeof process.emitWarning;\n\n try {\n return run();\n } finally {\n process.emitWarning = originalEmitWarning;\n }\n}\n", "import { createHash } from 'node:crypto';\nimport { createReadStream } from 'node:fs';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { createInterface } from 'node:readline';\nimport { comparePartitionPaths, PARTITION_FILE_PATTERN } from './partition-filename.js';\nimport { type ChroniclePartitionRange, ChroniclePartitionRangeCache } from './partition-range-cache.js';\nimport type { ChronicleEvent, ChronicleOutcome, ChronicleResourceRef } from './types.js';\n\nexport interface ChronicleQuery {\n eventId?: string;\n eventTypes?: string[]; outcomes?: ChronicleOutcome[]; from?: string; to?: string;\n projectId?: string; sessionId?: string; agentId?: string; taskId?: string;\n providerId?: string; modelId?: string; traceId?: string; logicalRequestId?: string;\n attemptId?: string; toolCallId?: string; resourceKind?: ChronicleResourceRef['kind'];\n resourceId?: string; path?: string; line?: number; tags?: Record<string, string>;\n attributes?: Record<string, unknown>; text?: string; order?: 'asc' | 'desc';\n limit?: number; cursor?: string;\n}\n\nexport interface ChronicleQueryResult {\n events: ChronicleEvent[]; total: number; nextCursor?: string;\n scannedEvents: number; sourceFiles: number; invalidLines: number;\n summary: ChronicleSummary;\n}\n\n/** Derived once from all matching events; never from the paginated UI sample. */\nexport interface ChronicleSummary {\n logicalRequests: number; modelAttempts: number; completedAttempts: number; failedAttempts: number;\n scheduledRetries: number; fallbacks: number; providers: number; models: number;\n inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheWriteTokens: number;\n estimatedCostUsd: number;\n providerAvgDurationMs: number; providerP95DurationMs: number;\n toolCalls: number; completedTools: number; failedTools: number; toolAvgDurationMs: number;\n processes: number; failedProcesses: number; fileEvents: number; uniqueFiles: number;\n agentEvents: number; uniqueAgents: number; decisions: number; escalations: number;\n failures: number; cancellations: number;\n families: Record<ChronicleSignalFamily, number>;\n failuresByFamily: Record<ChronicleSignalFamily, number>;\n}\nexport type ChronicleSignalFamily = 'llm'|'agent'|'tool'|'file'|'memory'|'task'|'decision'|'runtime'|'finding';\n\nexport type ChronicleFacet = 'eventType' | 'outcome' | 'projectId' | 'sessionId' |\n 'agentId' | 'taskId' | 'providerId' | 'modelId' | 'resourceKind' | 'resourcePath' | 'toolCallId';\nexport interface ChronicleFacetValue { value: string; count: number }\nexport type ChronicleFacetResults = Partial<Record<ChronicleFacet, ChronicleFacetValue[]>>;\n\n/**\n * The complete set of valid {@link ChronicleFacet} values. Shared by both\n * the CLI-embedded and standalone WebUI message routers so they can validate\n * `chronicle.facet` / `chronicle.facets` payloads against a single source of\n * truth \u2014 if `ChronicleFacet` grows a member, this set is the only place\n * that needs updating.\n */\nexport const CHRONICLE_FACET_FIELDS: ReadonlySet<ChronicleFacet> = new Set<ChronicleFacet>([\n 'eventType',\n 'outcome',\n 'projectId',\n 'sessionId',\n 'agentId',\n 'taskId',\n 'providerId',\n 'modelId',\n 'resourceKind',\n 'resourcePath',\n 'toolCallId',\n]);\nexport type ChronicleRelationKind = 'parent_span' | 'trace' | 'tool_call' | 'logical_request' |\n 'attempt' | 'decision' | 'network_request' | 'prompt_manifest' | 'resource_lineage';\nexport interface ChronicleGraphEdge { from: string; to: string; kind: ChronicleRelationKind; confidence: 'explicit' | 'correlated' | 'inferred' }\nexport interface ChronicleGraphResult { nodes: ChronicleEvent[]; edges: ChronicleGraphEdge[]; truncated: boolean }\n\ninterface ChronicleOrderKey {\n occurredAt: string;\n persistedAt: string;\n sequence: number;\n eventId: string;\n}\n\ninterface ChronicleSnapshotEntry {\n id: string;\n size: number;\n}\n\ninterface ChronicleCursor {\n version: 1;\n order: 'asc' | 'desc';\n queryHash: string;\n after: ChronicleOrderKey;\n snapshot: ChronicleSnapshotEntry[];\n}\n\ninterface SnapshotFile extends ChronicleSnapshotEntry {\n file: string;\n}\n\nconst MAX_CURSOR_SNAPSHOT_ENTRIES = 10_000;\n\n// \u2500\u2500 Streaming line-by-line reader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction streamLines(filePath: string, maxBytes?: number): AsyncIterableIterator<string> {\n const stream = createReadStream(filePath, {\n encoding: 'utf8',\n highWaterMark: 256 * 1024,\n ...(maxBytes !== undefined ? { end: maxBytes - 1 } : {}),\n });\n const rl = createInterface({ input: stream, crlfDelay: Infinity });\n return rl[Symbol.asyncIterator]() as AsyncIterableIterator<string>;\n}\n\n/** One dedicated full pass over a closed file to learn its true occurredAt bounds. */\nasync function computeOccurredAtRange(\n file: string,\n size: number,\n): Promise<{ min: string; max: string } | undefined> {\n let min: string | undefined;\n let max: string | undefined;\n for await (const line of streamLines(file, size)) {\n if (!line.trim()) continue;\n let event: ChronicleEvent;\n try {\n event = JSON.parse(line) as ChronicleEvent;\n if (!isChronicleEvent(event)) continue;\n } catch { continue; }\n const occurredAt = event.occurredAt ?? event.observedAt;\n if (min === undefined || occurredAt < min) min = occurredAt;\n if (max === undefined || occurredAt > max) max = occurredAt;\n }\n return min === undefined ? undefined : { min, max: max! };\n}\n\nfunction rangeOverlaps(range: ChroniclePartitionRange, query: ChronicleQuery): boolean {\n if (range.empty) return false;\n if (query.from && range.maxOccurredAt! < query.from) return false;\n if (query.to && range.minOccurredAt! > query.to) return false;\n return true;\n}\n\n// \u2500\u2500 Streaming query engine (no pre-loaded events) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** Queryable projection over immutable Chronicle JSONL partitions.\n * Events are streamed on demand \u2014 no full-file load into memory. */\nexport interface ChronicleQueryEngineOptions {\n /** Shared, longer-lived cache of closed partitions' observed occurredAt ranges. */\n rangeCache?: ChroniclePartitionRangeCache;\n}\n\nexport class ChronicleQueryEngine {\n private readonly partitionFiles: string[];\n private readonly rangeCache: ChroniclePartitionRangeCache | undefined;\n /** The one file (if any) that could still be actively appended to \u2014 never cache-checked or skipped. */\n private readonly activeFile: string | undefined;\n\n private constructor(\n files: string[],\n readonly diagnostics: { sourceFiles: number; invalidLines: number },\n rangeCache?: ChroniclePartitionRangeCache,\n activeFile?: string,\n ) {\n this.partitionFiles = files;\n this.rangeCache = rangeCache;\n this.activeFile = activeFile;\n }\n\n static async fromDirectory(\n directory: string,\n options?: ChronicleQueryEngineOptions,\n ): Promise<ChronicleQueryEngine> {\n const resolved = path.resolve(directory);\n const files = await findPartitions(resolved);\n const rangeCache = options?.rangeCache ?? new ChroniclePartitionRangeCache(resolved);\n return new ChronicleQueryEngine(\n files,\n { sourceFiles: files.length, invalidLines: 0 },\n rangeCache,\n files.at(-1),\n );\n }\n\n static async fromFiles(files: string[]): Promise<ChronicleQueryEngine> {\n return new ChronicleQueryEngine(files, { sourceFiles: files.length, invalidLines: 0 });\n }\n\n /**\n * Returns the file's observed (min, max) `occurredAt` range, computing and\n * caching it on first use. Only ever called for closed/immutable files\n * (never `this.activeFile`) \u2014 see the skip-check call sites.\n */\n private async getOrComputeRange(file: string, size: number): Promise<ChroniclePartitionRange> {\n const cached = await this.rangeCache!.get(file, size);\n if (cached) return cached;\n const computed = await computeOccurredAtRange(file, size);\n const range: ChroniclePartitionRange = computed\n ? { size, minOccurredAt: computed.min, maxOccurredAt: computed.max }\n : { size, empty: true };\n this.rangeCache!.set(file, range);\n return range;\n }\n\n /** True when a closed file's cached range provably cannot contain a match for `query`. */\n private async canSkip(file: string, size: number, query: ChronicleQuery): Promise<boolean> {\n if (!this.rangeCache || (!query.from && !query.to) || file === this.activeFile) return false;\n const range = await this.getOrComputeRange(file, size);\n return !rangeOverlaps(range, query);\n }\n\n /** Stream all partitions, filter, and return the requested page + summary. */\n async query(query: ChronicleQuery = {}): Promise<ChronicleQueryResult> {\n const order = query.order ?? 'desc';\n const limit = Math.max(1, Math.min(query.limit ?? 100, 10_000));\n const queryHash = hashQuery(query);\n const cursor = decodeCursor(query.cursor, order, queryHash);\n const snapshotFiles = cursor\n ? await resolveSnapshotFiles(this.partitionFiles, cursor.snapshot)\n : await captureSnapshot(this.partitionFiles);\n const files = order === 'asc' ? snapshotFiles : snapshotFiles.slice().reverse();\n const summaryAcc = createSummaryAccumulator();\n const orderedCandidates: ChronicleEvent[] = [];\n const pageOrder = (left: ChronicleEvent, right: ChronicleEvent) =>\n compareEvents(left, right) * (order === 'asc' ? 1 : -1);\n let totalCount = 0;\n let remainingCount = 0;\n let scannedEvents = 0;\n let invalidLines = 0;\n\n for (const snapshotFile of files) {\n try {\n if (snapshotFile.size === 0) continue;\n // A closed file whose observed occurredAt range can't overlap [from, to]\n // is skipped with zero I/O. scannedEvents/invalidLines below reflect\n // only lines actually read this call, so a skip legitimately lowers\n // them \u2014 that's the optimization working, not a regression.\n if (await this.canSkip(snapshotFile.file, snapshotFile.size, query)) continue;\n const lines = order === 'asc'\n ? streamLines(snapshotFile.file, snapshotFile.size)\n : reverseLines(snapshotFile.file, snapshotFile.size);\n\n for await (const line of lines) {\n if (!line.trim()) continue;\n let event: ChronicleEvent;\n try {\n event = JSON.parse(line) as ChronicleEvent;\n if (!isChronicleEvent(event)) { invalidLines++; continue; }\n } catch { invalidLines++; continue; }\n scannedEvents++;\n\n if (!matches(event, query)) continue;\n totalCount++;\n updateSummary(summaryAcc, event);\n\n if (cursor && compareEventToKey(event, cursor.after) * (order === 'asc' ? 1 : -1) <= 0) {\n continue;\n }\n remainingCount++;\n\n // Keyset pagination retains only this page's best `limit` matches.\n // Cursor depth and journal size therefore cannot grow page memory.\n const insertionIndex = findInsertionIndex(orderedCandidates, event, pageOrder);\n if (insertionIndex < limit) {\n orderedCandidates.splice(insertionIndex, 0, event);\n if (orderedCandidates.length > limit) orderedCandidates.pop();\n }\n }\n } catch {\n // Skip unreadable partitions\n }\n }\n\n const pageEvents = orderedCandidates;\n const lastEvent = pageEvents.at(-1);\n\n if (this.rangeCache) {\n this.rangeCache.prune(this.partitionFiles);\n await this.rangeCache.flush();\n }\n\n return {\n events: pageEvents,\n total: totalCount,\n summary: finalizeSummary(summaryAcc),\n ...(lastEvent && pageEvents.length < remainingCount\n ? { nextCursor: encodeCursor({\n version: 1,\n order,\n queryHash,\n after: orderKey(lastEvent),\n snapshot: snapshotFiles.map(({ id, size }) => ({ id, size })),\n }) } : {}),\n scannedEvents,\n sourceFiles: snapshotFiles.length,\n invalidLines,\n };\n }\n\n /** Stream all partitions once and compute value counts for every requested facet. */\n async facets(\n fields: readonly ChronicleFacet[],\n query: ChronicleQuery = {},\n limit = 100,\n ): Promise<ChronicleFacetResults> {\n const uniqueFields = [...new Set(fields)];\n if (uniqueFields.length === 0) return {};\n const counts = new Map(uniqueFields.map((field) => [field, new Map<string, number>()]));\n const snapshotFiles = await captureSnapshot(this.partitionFiles);\n let invalidLines = 0;\n for (const snapshotFile of snapshotFiles) {\n try {\n if (snapshotFile.size === 0) continue;\n if (await this.canSkip(snapshotFile.file, snapshotFile.size, query)) continue;\n for await (const line of streamLines(snapshotFile.file, snapshotFile.size)) {\n if (!line.trim()) continue;\n let event: ChronicleEvent;\n try {\n event = JSON.parse(line) as ChronicleEvent;\n if (!isChronicleEvent(event)) { invalidLines++; continue; }\n } catch { invalidLines++; continue; }\n if (!matches(event, query)) continue;\n for (const field of uniqueFields) {\n const value = facetValue(event, field);\n const fieldCounts = counts.get(field)!;\n if (value !== undefined) fieldCounts.set(value, (fieldCounts.get(value) ?? 0) + 1);\n }\n }\n } catch { /* skip unreadable */ }\n }\n this.diagnostics.invalidLines = invalidLines;\n if (this.rangeCache) {\n this.rangeCache.prune(this.partitionFiles);\n await this.rangeCache.flush();\n }\n const result: ChronicleFacetResults = {};\n for (const field of uniqueFields) {\n result[field] = [...counts.get(field)!]\n .map(([value, count]) => ({ value, count }))\n .sort((a, b) => b.count - a.count || a.value.localeCompare(b.value))\n .slice(0, Math.max(0, limit));\n }\n return result;\n }\n\n /** Stream all partitions and compute one facet's value counts. */\n async facet(field: ChronicleFacet, query: ChronicleQuery = {}, limit = 100): Promise<ChronicleFacetValue[]> {\n return (await this.facets([field], query, limit))[field] ?? [];\n }\n\n /** Expand explicit and typed correlation edges; temporal proximity alone never creates causality. */\n async graph(seed: ChronicleQuery = {}, hops = 2, maxNodes = 1_000): Promise<ChronicleGraphResult> {\n const nodeLimit = Math.max(0, Math.floor(maxNodes));\n const selected = new Map<string, ChronicleEvent>();\n let seedCount = 0;\n\n // Pass 1 retains only the bounded seed set.\n for await (const event of streamEvents(this.partitionFiles)) {\n if (!matches(event, seed)) continue;\n seedCount++;\n if (selected.size < nodeLimit) selected.set(event.eventId, event);\n }\n\n let frontier = [...selected.values()];\n const depthLimit = Math.max(0, Math.min(hops, 10));\n for (let depth = 0; depth < depthLimit && frontier.length > 0 && selected.size < nodeLimit; depth++) {\n const frontierKeys = new Set(frontier.flatMap((event) => relationKeys(event).map((relation) => relation.key)));\n const next: ChronicleEvent[] = [];\n\n // Each hop is another streaming pass. Only related nodes up to maxNodes\n // are retained, so journal size cannot determine graph memory usage.\n for await (const event of streamEvents(this.partitionFiles)) {\n if (selected.has(event.eventId)) continue;\n if (!relationKeys(event).some((relation) => frontierKeys.has(relation.key))) continue;\n selected.set(event.eventId, event);\n next.push(event);\n if (selected.size >= nodeLimit) break;\n }\n frontier = next;\n }\n\n const nodes = [...selected.values()].sort(compareEvents);\n const byKey = new Map<string, ChronicleEvent[]>();\n for (const node of nodes) for (const relation of relationKeys(node)) {\n const related = byKey.get(relation.key) ?? [];\n related.push(node);\n byKey.set(relation.key, related);\n }\n\n const edges: ChronicleGraphEdge[] = [];\n const seen = new Set<string>();\n for (const node of nodes) for (const relation of relationKeys(node)) for (const candidate of byKey.get(relation.key) ?? []) {\n if (candidate.eventId === node.eventId) continue;\n const [from, to] = compareEvents(node, candidate) <= 0 ? [node, candidate] : [candidate, node];\n const id = `${from.eventId}:${to.eventId}:${relation.kind}`;\n if (!seen.has(id)) { seen.add(id); edges.push({ from: from.eventId, to: to.eventId, kind: relation.kind, confidence: relation.confidence }); }\n }\n return { nodes, edges, truncated: seedCount > nodeLimit || selected.size >= nodeLimit };\n }\n}\n\nasync function* streamEvents(files: readonly string[]): AsyncGenerator<ChronicleEvent> {\n for (const file of files) {\n try {\n for await (const line of streamLines(file)) {\n if (!line.trim()) continue;\n try {\n const event = JSON.parse(line) as ChronicleEvent;\n if (isChronicleEvent(event)) yield event;\n } catch { /* skip invalid lines */ }\n }\n } catch { /* skip unreadable partitions */ }\n }\n}\n\n// \u2500\u2500 Reverse line reader (reads a file from end to start) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nasync function* reverseLines(filePath: string, maxBytes?: number): AsyncGenerator<string> {\n const CHUNK = 64 * 1024;\n const NEWLINE = 0x0a;\n let handle: fs.FileHandle;\n try { handle = await fs.open(filePath, 'r'); } catch { return; }\n try {\n const fileSize = (await handle.stat()).size;\n const size = Math.min(fileSize, maxBytes ?? fileSize);\n let position = size;\n let suffix = Buffer.alloc(0);\n while (position > 0) {\n const length = Math.min(CHUNK, position);\n position -= length;\n const buffer = Buffer.allocUnsafe(length);\n await handle.read(buffer, 0, length, position);\n const data = suffix.length === 0 ? buffer : Buffer.concat([buffer, suffix]);\n let lineEnd = data.length;\n let firstNewline = -1;\n for (let index = data.length - 1; index >= 0; index--) {\n if (data[index] !== NEWLINE) continue;\n const trimmed = data.subarray(index + 1, lineEnd).toString('utf8').trim();\n if (trimmed) yield trimmed;\n lineEnd = index;\n firstNewline = index;\n }\n suffix = firstNewline >= 0 ? Buffer.from(data.subarray(0, firstNewline)) : data;\n }\n const trimmed = suffix.toString('utf8').trim();\n if (trimmed) yield trimmed;\n } finally { await handle.close(); }\n}\n\n// \u2500\u2500 Running summary accumulator (replaces scan-then-summarize) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport interface SummaryAcc {\n logicalRequestIds: Set<string>;\n modelAttempts: number; completedAttempts: number; failedAttempts: number;\n scheduledRetries: number; fallbacks: number;\n providers: Set<string>; models: Set<string>;\n inputTokens: number; outputTokens: number;\n cacheReadTokens: number; cacheWriteTokens: number;\n costByScope: Map<string, { cost: number; event: ChronicleEvent }>;\n providerDurations: number[];\n toolCalls: number; completedTools: number; failedTools: number;\n toolDurations: number[];\n processes: number; failedProcesses: number;\n fileEvents: number; uniqueFiles: Set<string>;\n agentEvents: number; uniqueAgents: Set<string>;\n decisions: number; escalations: number;\n failures: number; cancellations: number;\n families: Record<ChronicleSignalFamily, number>;\n failuresByFamily: Record<ChronicleSignalFamily, number>;\n /** One-per-scope token.accounted cost snapshot. Updated when a later\n * token.accounted event has a later timestamp for the same scope. */\n}\n\n/**\n * Exported for the SQLite query engine (`sqlite-query.ts`).\n *\n * Filtering and summarisation are the parts of `ChronicleQuery` with real\n * semantics \u2014 family classification, nested `usage.*` attribute paths, cost\n * de-duplication by scope, a p95 over every matching duration. Re-expressing\n * those in SQL would create a second definition that drifts from this one, and\n * the drift would show up as quietly different numbers rather than an error.\n * The SQLite engine therefore uses SQL only to narrow candidates, then runs\n * these exact functions over the parsed events.\n */\nexport function createSummaryAccumulator(): SummaryAcc {\n return {\n logicalRequestIds: new Set(), modelAttempts: 0, completedAttempts: 0, failedAttempts: 0,\n scheduledRetries: 0, fallbacks: 0, providers: new Set(), models: new Set(),\n inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0,\n costByScope: new Map(), providerDurations: [],\n toolCalls: 0, completedTools: 0, failedTools: 0, toolDurations: [],\n processes: 0, failedProcesses: 0,\n fileEvents: 0, uniqueFiles: new Set(), agentEvents: 0, uniqueAgents: new Set(),\n decisions: 0, escalations: 0, failures: 0, cancellations: 0,\n families: { llm: 0, agent: 0, tool: 0, file: 0, memory: 0, task: 0, decision: 0, runtime: 0, finding: 0 },\n failuresByFamily: { llm: 0, agent: 0, tool: 0, file: 0, memory: 0, task: 0, decision: 0, runtime: 0, finding: 0 },\n };\n}\n\nexport function updateSummary(acc: SummaryAcc, event: ChronicleEvent): void {\n // Families\n const family = signalFamily(event);\n acc.families[family]++;\n if (isTerminalFailure(event)) acc.failuresByFamily[family]++;\n\n // Running counts per event type\n if (event.correlation.logicalRequestId) acc.logicalRequestIds.add(event.correlation.logicalRequestId);\n if (event.runtime?.providerId) acc.providers.add(event.runtime.providerId);\n if (event.runtime?.modelId) acc.models.add(event.runtime.modelId);\n\n if (event.eventType === 'provider.attempt.started') acc.modelAttempts++;\n else if (event.eventType === 'provider.attempt.completed') {\n acc.completedAttempts++;\n acc.inputTokens += numberAt(event, 'usage.input');\n acc.outputTokens += numberAt(event, 'usage.output');\n acc.cacheReadTokens += numberAt(event, 'usage.cacheRead');\n acc.cacheWriteTokens += numberAt(event, 'usage.cacheWrite');\n const dur = durationMs(event);\n if (dur > 0) acc.providerDurations.push(dur);\n } else if (event.eventType === 'provider.attempt.failed') {\n acc.failedAttempts++;\n if (event.attributes?.retryScheduled === true) acc.scheduledRetries++;\n const dur = durationMs(event);\n if (dur > 0) acc.providerDurations.push(dur);\n } else if (event.eventType === 'provider.fallback') acc.fallbacks++;\n else if (event.eventType === 'tool.started') acc.toolCalls++;\n else if (event.eventType === 'tool.executed') {\n acc.completedTools++;\n const dur = durationMs(event);\n if (dur > 0) acc.toolDurations.push(dur);\n } else if (event.eventType === 'tool.failed') {\n acc.failedTools++;\n const dur = durationMs(event);\n if (dur > 0) acc.toolDurations.push(dur);\n } else if (event.eventType === 'process.started') acc.processes++;\n else if (event.eventType === 'process.completed' && event.outcome === 'failure') acc.failedProcesses++;\n else if (event.eventType === 'decision.requested') acc.decisions++;\n else if (event.eventType === 'decision.escalated') acc.escalations++;\n\n // Token accounted \u2014 keep the latest finite snapshot per scope. Zero is a\n // meaningful reset, and compareEvents makes ties independent of scan order.\n if (event.eventType === 'token.accounted') {\n const cost = readPath(event.attributes ?? {}, 'cost.total');\n if (typeof cost === 'number' && Number.isFinite(cost)) {\n const key = scopeKey(event);\n const existing = acc.costByScope.get(key);\n if (!existing || compareEvents(event, existing.event) > 0) {\n acc.costByScope.set(key, { cost, event });\n }\n }\n }\n\n // File evidence\n if (event.resource?.kind === 'file' || event.eventType.startsWith('file.')) {\n acc.fileEvents++;\n if (event.resource?.path) acc.uniqueFiles.add(event.resource.path);\n }\n\n // Agent events\n if (family === 'agent') acc.agentEvents++;\n if (event.scope.agentId) acc.uniqueAgents.add(event.scope.agentId);\n\n // Terminal failures and cancellations\n if (isTerminalFailure(event)) acc.failures++;\n if (event.outcome === 'cancelled' || event.outcome === 'abandoned') acc.cancellations++;\n}\n\nexport function finalizeSummary(acc: SummaryAcc): ChronicleSummary {\n const sortedProviderDurations = acc.providerDurations.slice().sort((a, b) => a - b);\n const sortedToolDurations = acc.toolDurations.slice().sort((a, b) => a - b);\n const totalCost = [...acc.costByScope.values()].reduce((sum, entry) => sum + entry.cost, 0);\n return {\n logicalRequests: acc.logicalRequestIds.size,\n modelAttempts: acc.modelAttempts,\n completedAttempts: acc.completedAttempts,\n failedAttempts: acc.failedAttempts,\n scheduledRetries: acc.scheduledRetries,\n fallbacks: acc.fallbacks,\n providers: acc.providers.size,\n models: acc.models.size,\n inputTokens: acc.inputTokens,\n outputTokens: acc.outputTokens,\n cacheReadTokens: acc.cacheReadTokens,\n cacheWriteTokens: acc.cacheWriteTokens,\n estimatedCostUsd: totalCost,\n providerAvgDurationMs: average(sortedProviderDurations),\n providerP95DurationMs: percentile(sortedProviderDurations, 0.95),\n toolCalls: acc.toolCalls,\n completedTools: acc.completedTools,\n failedTools: acc.failedTools,\n toolAvgDurationMs: average(sortedToolDurations),\n processes: acc.processes,\n failedProcesses: acc.failedProcesses,\n fileEvents: acc.fileEvents,\n uniqueFiles: acc.uniqueFiles.size,\n agentEvents: acc.agentEvents,\n uniqueAgents: acc.uniqueAgents.size,\n decisions: acc.decisions,\n escalations: acc.escalations,\n failures: acc.failures,\n cancellations: acc.cancellations,\n families: acc.families,\n failuresByFamily: acc.failuresByFamily,\n };\n}\n\n// \u2500\u2500 Partition discovery (no pre-loading) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** The partition files list is stored on the prototype for legacy callers\n * that reference engine.partitionFiles directly. */\nObject.defineProperty(ChronicleQueryEngine.prototype, 'partitionFiles', {\n get() { throw new Error('ChronicleQueryEngine no longer loads events on construction. Use async query().'); },\n set(this: ChronicleQueryEngine, _val: string[]) {\n // Allow fromFiles/fromDirectory to attach the list for graph()\n Object.defineProperty(this, 'partitionFiles', { value: _val, writable: false, configurable: false });\n },\n});\n\n/** Recursively locate journal partition files under a Chronicle directory,\n * ordered family-first then rotation index. Shared with the metrics store. */\nexport async function findChroniclePartitions(root: string): Promise<string[]> {\n return findPartitions(root);\n}\n\nasync function findPartitions(root: string): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n let entries: import('node:fs').Dirent[];\n try { entries = await fs.readdir(directory, { withFileTypes: true }); } catch { return; }\n for (const entry of entries) {\n const full = path.join(directory, entry.name);\n if (entry.isDirectory()) await visit(full);\n else if (entry.isFile() && PARTITION_FILE_PATTERN.test(entry.name)) result.push(full);\n }\n };\n await visit(root);\n return result.sort(comparePartitionPaths);\n}\n\n// \u2500\u2500 Helper functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction numberAt(event: ChronicleEvent, dotPath: string): number {\n const value = readPath(event.attributes ?? {}, dotPath);\n return typeof value === 'number' && Number.isFinite(value) ? value : 0;\n}\n\nfunction durationMs(event: ChronicleEvent): number {\n const value = Number(event.durationNs ?? 0) / 1_000_000;\n return Number.isFinite(value) ? value : 0;\n}\n\nfunction average(values: number[]): number {\n return values.length ? values.reduce((sum, v) => sum + v, 0) / values.length : 0;\n}\n\nfunction percentile(sorted: number[], quantile: number): number {\n return sorted.length ? sorted[Math.min(sorted.length - 1, Math.max(0, Math.ceil(sorted.length * quantile) - 1))]! : 0;\n}\n\nfunction scopeKey(event: ChronicleEvent): string {\n return `${event.scope.projectId ?? ''}\\0${event.scope.sessionId ?? ''}\\0${event.scope.agentId ?? ''}`;\n}\n\n/** Shared with ChronicleMetricsStore so its default-view summary classifies\n * events identically to the raw-scan summary it stands in for. */\nexport function signalFamily(event: ChronicleEvent): ChronicleSignalFamily {\n if (/^(?:decision|brain|permission)\\./.test(event.eventType)) return 'decision';\n if (event.resource?.kind === 'file' || event.resource?.kind === 'symbol' || /^(?:file|worktree)\\./.test(event.eventType)) return 'file';\n if (/^(?:provider|token|context|ctx|compaction)\\./.test(event.eventType)) return 'llm';\n if (/^(?:agent|subagent|delegate|fleet|concurrency)\\./.test(event.eventType)) return 'agent';\n if (/^(?:tool|process|mcp|network)\\./.test(event.eventType)) return 'tool';\n if (/^(?:memory|storage|trust)\\./.test(event.eventType)) return 'memory';\n if (/^(?:sdd|task|kanban|checkpoint|session|iteration|in_flight)\\./.test(event.eventType)) return 'task';\n if (/^(?:finding|review)\\./.test(event.eventType)) return 'finding';\n return 'runtime';\n}\n\n/** Shared with ChronicleMetricsStore \u2014 see signalFamily(). */\nexport function isTerminalFailure(event: ChronicleEvent): boolean {\n if (event.eventType === 'provider.attempt.failed') return event.attributes?.retryScheduled !== true;\n return event.eventType === 'tool.failed' ||\n (event.eventType === 'process.completed' && event.outcome === 'failure') ||\n /^(?:agent\\.run\\.error|sdd\\.task\\.failed|compaction\\.failed|network\\.request\\.failed)$/.test(event.eventType);\n}\n\n/**\n * Exported for the SQLite engine. Which correlation keys an event carries \u2014 and\n * with what confidence \u2014 is the definition of a Chronicle edge; a second copy\n * would let the two engines draw different graphs from the same data.\n */\nexport function relationKeys(event: ChronicleEvent): Array<{ key: string; kind: ChronicleRelationKind; confidence: ChronicleGraphEdge['confidence'] }> {\n const result: Array<{ key: string; kind: ChronicleRelationKind; confidence: ChronicleGraphEdge['confidence'] }> = [];\n const add = (kind: ChronicleRelationKind, value: unknown, confidence: ChronicleGraphEdge['confidence']) => {\n if (typeof value === 'string' && value) result.push({ key: `${kind}:${value}`, kind, confidence });\n };\n add('trace', event.correlation.traceId, 'correlated');\n add('tool_call', event.correlation.toolCallId, 'explicit');\n add('logical_request', event.correlation.logicalRequestId, 'explicit');\n add('attempt', event.correlation.attemptId, 'explicit');\n add('decision', event.attributes?.decisionId, 'explicit');\n add('network_request', event.attributes?.requestId, 'explicit');\n add('prompt_manifest', (event.attributes?.promptManifest as Record<string, unknown> | undefined)?.manifestId, 'explicit');\n add('resource_lineage', event.resource?.id, 'inferred');\n // tool.resource.observed is windowed into one metrics.rollup event per\n // tool call (rollup-adapter.ts) carrying a bounded `resources` list rather\n // than a single top-level `resource` \u2014 surface each as its own edge so a\n // rolled-up \"observed\" touch still participates in the same resource\n // lineage group as a mutation event for the same resource id.\n if (event.eventType === 'metrics.rollup' && event.attributes?.signal === 'tool.resource.observed') {\n const resources = event.attributes.resources as Array<{ id?: unknown }> | undefined;\n for (const resource of resources ?? []) {\n if (typeof resource?.id === 'string') add('resource_lineage', resource.id, 'inferred');\n }\n }\n if (event.correlation.parentSpanId) add('parent_span', event.correlation.parentSpanId, 'explicit');\n add('parent_span', event.correlation.spanId, 'explicit');\n return result;\n}\n\nexport function matches(event: ChronicleEvent, query: ChronicleQuery): boolean {\n if (query.eventId && event.eventId !== query.eventId) return false;\n if (query.eventTypes && !query.eventTypes.includes(event.eventType)) return false;\n if (query.outcomes && (!event.outcome || !query.outcomes.includes(event.outcome))) return false;\n const occurredAt = event.occurredAt ?? event.observedAt;\n if (query.from && occurredAt < query.from || query.to && occurredAt > query.to) return false;\n if (!equal(query.projectId, event.scope.projectId) || !equal(query.sessionId, event.scope.sessionId)) return false;\n if (!equal(query.agentId, event.scope.agentId) || !equal(query.taskId, event.scope.taskId)) return false;\n if (!equal(query.providerId, event.runtime?.providerId) || !equal(query.modelId, event.runtime?.modelId)) return false;\n if (!equal(query.traceId, event.correlation.traceId) || !equal(query.logicalRequestId, event.correlation.logicalRequestId)) return false;\n if (!equal(query.attemptId, event.correlation.attemptId) || !equal(query.toolCallId, event.correlation.toolCallId)) return false;\n if (!equal(query.resourceKind, event.resource?.kind) || !equal(query.resourceId, event.resource?.id)) return false;\n if (query.path && normalize(event.resource?.path) !== normalize(query.path)) return false;\n if (query.line !== undefined && !lineContains(event, query.line)) return false;\n if (query.tags && !objectContains(event.tags, query.tags)) return false;\n if (query.attributes && !objectContains(event.attributes, query.attributes)) return false;\n if (query.text && !JSON.stringify(event).toLocaleLowerCase().includes(query.text.toLocaleLowerCase())) return false;\n return true;\n}\n\nfunction equal<T>(expected: T | undefined, actual: T | undefined): boolean { return expected === undefined || expected === actual; }\nfunction normalize(value: string | undefined): string | undefined { return value?.replaceAll('\\\\', '/').toLocaleLowerCase(); }\nfunction lineContains(event: ChronicleEvent, line: number): boolean {\n const start = event.resource?.lineStart; const end = event.resource?.lineEnd ?? start;\n return start !== undefined && end !== undefined && line >= start && line <= end;\n}\nfunction objectContains(actual: Record<string, unknown> | undefined, expected: Record<string, unknown>): boolean {\n return Boolean(actual && Object.entries(expected).every(([key, value]) => deepEqual(readPath(actual, key), value)));\n}\nfunction readPath(value: Record<string, unknown>, key: string): unknown {\n return key.split('.').reduce<unknown>((current, part) => current && typeof current === 'object'\n ? (current as Record<string, unknown>)[part] : undefined, value);\n}\nfunction deepEqual(left: unknown, right: unknown): boolean { return JSON.stringify(left) === JSON.stringify(right); }\nfunction findInsertionIndex(\n events: readonly ChronicleEvent[],\n event: ChronicleEvent,\n compare: (left: ChronicleEvent, right: ChronicleEvent) => number,\n): number {\n let low = 0;\n let high = events.length;\n while (low < high) {\n const middle = (low + high) >>> 1;\n if (compare(events[middle]!, event) <= 0) low = middle + 1;\n else high = middle;\n }\n return low;\n}\nexport function compareEvents(a: ChronicleEvent, b: ChronicleEvent): number {\n return compareEventToKey(a, orderKey(b));\n}\nfunction compareEventToKey(event: ChronicleEvent, key: ChronicleOrderKey): number {\n return (event.occurredAt ?? event.observedAt).localeCompare(key.occurredAt) ||\n event.persistedAt.localeCompare(key.persistedAt) || event.sequence - key.sequence ||\n event.eventId.localeCompare(key.eventId);\n}\nfunction orderKey(event: ChronicleEvent): ChronicleOrderKey {\n return {\n occurredAt: event.occurredAt ?? event.observedAt,\n persistedAt: event.persistedAt,\n sequence: event.sequence,\n eventId: event.eventId,\n };\n}\nfunction hashQuery(query: ChronicleQuery): string {\n const { cursor: _cursor, limit: _limit, order: _order, ...filters } = query;\n return createHash('sha256').update(stableStringify(filters), 'utf8').digest('base64url');\n}\nfunction encodeCursor(cursor: ChronicleCursor): string {\n return Buffer.from(JSON.stringify(cursor), 'utf8').toString('base64url');\n}\nfunction decodeCursor(\n encoded: string | undefined,\n order: 'asc' | 'desc',\n queryHash: string,\n): ChronicleCursor | undefined {\n if (!encoded) return undefined;\n if (encoded.length > 1_000_000) throw new Error('Invalid Chronicle cursor');\n try {\n const parsed = JSON.parse(Buffer.from(encoded, 'base64url').toString('utf8')) as unknown;\n if (!isCursor(parsed) || parsed.order !== order || parsed.queryHash !== queryHash) {\n throw new Error('cursor does not match the query');\n }\n return parsed;\n } catch (error) {\n throw new Error(`Invalid Chronicle cursor: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\nfunction isCursor(value: unknown): value is ChronicleCursor {\n if (!value || typeof value !== 'object') return false;\n const cursor = value as Partial<ChronicleCursor>;\n const after = cursor.after as Partial<ChronicleOrderKey> | undefined;\n if (cursor.version !== 1 || (cursor.order !== 'asc' && cursor.order !== 'desc') ||\n typeof cursor.queryHash !== 'string' || !after ||\n typeof after.occurredAt !== 'string' || typeof after.persistedAt !== 'string' ||\n !Number.isSafeInteger(after.sequence) || typeof after.eventId !== 'string' ||\n !Array.isArray(cursor.snapshot) || cursor.snapshot.length > MAX_CURSOR_SNAPSHOT_ENTRIES) return false;\n\n const snapshotIds = new Set<string>();\n for (const entry of cursor.snapshot) {\n if (!entry || typeof entry.id !== 'string' || !entry.id ||\n !Number.isSafeInteger(entry.size) || entry.size < 0 || snapshotIds.has(entry.id)) return false;\n snapshotIds.add(entry.id);\n }\n return true;\n}\nasync function captureSnapshot(files: readonly string[]): Promise<SnapshotFile[]> {\n if (files.length > MAX_CURSOR_SNAPSHOT_ENTRIES) {\n throw new Error('Chronicle snapshot contains too many partitions');\n }\n return Promise.all(files.map(async (file) => {\n let size = 0;\n try { size = (await fs.stat(file)).size; } catch { /* preserve missing source as empty */ }\n return { file, id: fileId(file), size };\n }));\n}\nasync function resolveSnapshotFiles(\n files: readonly string[],\n snapshot: readonly ChronicleSnapshotEntry[],\n): Promise<SnapshotFile[]> {\n const currentFiles = new Map(files.map((file) => [fileId(file), file]));\n return Promise.all(snapshot.map(async (entry) => {\n const file = currentFiles.get(entry.id);\n if (!file) throw new Error('Chronicle cursor snapshot has expired');\n let currentSize: number;\n try { currentSize = (await fs.stat(file)).size; } catch { throw new Error('Chronicle cursor snapshot has expired'); }\n if (currentSize < entry.size) throw new Error('Chronicle cursor snapshot has expired');\n return { file, ...entry };\n }));\n}\nfunction fileId(file: string): string {\n return createHash('sha256').update(path.resolve(file), 'utf8').digest('base64url');\n}\nfunction stableStringify(value: unknown): string {\n if (value === null || typeof value !== 'object') return JSON.stringify(value);\n if (Array.isArray(value)) return `[${value.map(stableStringify).join(',')}]`;\n const object = value as Record<string, unknown>;\n return `{${Object.keys(object).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(object[key])}`).join(',')}}`;\n}\nfunction isChronicleEvent(value: unknown): value is ChronicleEvent {\n if (!isRecord(value) || !isRecord(value.scope) || !isRecord(value.correlation)) return false;\n return value.schemaVersion === 1 &&\n typeof value.eventId === 'string' && typeof value.eventType === 'string' &&\n typeof value.occurredAt === 'string' && typeof value.observedAt === 'string' &&\n typeof value.persistedAt === 'string' && Number.isSafeInteger(value.sequence) &&\n (value.sequence as number) >= 0 && typeof value.previousHash === 'string' &&\n typeof value.hash === 'string' && typeof value.scope.installationId === 'string' &&\n typeof value.scope.machineId === 'string' && optionalStrings(value.scope, [\n 'projectId', 'repositoryId', 'workspaceId', 'worktreeId', 'sessionId', 'turnId',\n 'iterationId', 'agentId', 'goalId', 'planId', 'taskId', 'kanbanBoardId',\n ]) && typeof value.correlation.traceId === 'string' &&\n typeof value.correlation.spanId === 'string' && optionalStrings(value.correlation, [\n 'parentSpanId', 'logicalRequestId', 'attemptId', 'toolCallId',\n ]) && isRuntime(value.runtime) && isResource(value.resource) &&\n (value.attributes === undefined || isRecord(value.attributes)) &&\n (value.tags === undefined || isStringRecord(value.tags));\n}\nfunction isRuntime(value: unknown): boolean {\n return value === undefined || isRecord(value) &&\n optionalStrings(value, ['providerId', 'modelId', 'modelRevision']) &&\n optionalFiniteNumbers(value, ['processId', 'parentProcessId']);\n}\nfunction isResource(value: unknown): boolean {\n if (value === undefined) return true;\n if (!isRecord(value) || !['file', 'symbol', 'memory', 'task', 'kanban', 'process',\n 'network', 'artifact', 'other'].includes(String(value.kind)) || typeof value.id !== 'string') return false;\n return optionalStrings(value, ['path', 'contentHashBefore', 'contentHashAfter']) &&\n optionalFiniteNumbers(value, ['lineStart', 'lineEnd']);\n}\nfunction optionalStrings(value: Record<string, unknown>, keys: readonly string[]): boolean {\n return keys.every((key) => value[key] === undefined || typeof value[key] === 'string');\n}\nfunction optionalFiniteNumbers(value: Record<string, unknown>, keys: readonly string[]): boolean {\n return keys.every((key) => value[key] === undefined || typeof value[key] === 'number' && Number.isFinite(value[key]));\n}\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n return isRecord(value) && Object.values(value).every((entry) => typeof entry === 'string');\n}\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value && typeof value === 'object' && !Array.isArray(value));\n}\nexport function facetValue(event: ChronicleEvent, field: ChronicleFacet): string | undefined {\n const values: Record<ChronicleFacet, string | undefined> = {\n eventType: event.eventType, outcome: event.outcome, projectId: event.scope.projectId,\n sessionId: event.scope.sessionId, agentId: event.scope.agentId, taskId: event.scope.taskId,\n providerId: event.runtime?.providerId, modelId: event.runtime?.modelId,\n resourceKind: event.resource?.kind, resourcePath: event.resource?.path,\n toolCallId: event.correlation.toolCallId,\n };\n return values[field];\n}\n", "import * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { atomicWrite, withFileLock } from '../utils/atomic-write.js';\n\nconst CACHE_VERSION = 1;\n\nexport interface ChroniclePartitionRange {\n size: number;\n minOccurredAt?: string;\n maxOccurredAt?: string;\n /** No valid events were found in the file. */\n empty?: boolean;\n}\n\ninterface CacheFile {\n version: number;\n entries: Record<string, ChroniclePartitionRange>;\n}\n\nfunction isRange(value: unknown): value is ChroniclePartitionRange {\n if (!value || typeof value !== 'object') return false;\n const range = value as Partial<ChroniclePartitionRange>;\n return (\n typeof range.size === 'number' &&\n (range.minOccurredAt === undefined || typeof range.minOccurredAt === 'string') &&\n (range.maxOccurredAt === undefined || typeof range.maxOccurredAt === 'string') &&\n (range.empty === undefined || typeof range.empty === 'boolean')\n );\n}\n\n/**\n * Persisted cache of each closed (immutable) Chronicle partition file's\n * observed min/max `occurredAt`, so query()/facets() can skip a file\n * entirely instead of re-streaming its contents when it can't overlap a\n * time-bounded query. Keyed by (path, size) so a file whose size ever\n * unexpectedly changes just misses and gets recomputed.\n */\nexport class ChroniclePartitionRangeCache {\n private readonly cachePath: string;\n private entries: Map<string, ChroniclePartitionRange> | undefined;\n private dirty = false;\n\n constructor(private readonly directory: string) {\n this.cachePath = path.join(directory, 'range-cache.json');\n }\n\n private toKey(filePath: string): string {\n return path.relative(this.directory, filePath).split(path.sep).join('/');\n }\n\n private async load(): Promise<Map<string, ChroniclePartitionRange>> {\n if (this.entries) return this.entries;\n const entries = new Map<string, ChroniclePartitionRange>();\n try {\n const raw = await fs.readFile(this.cachePath, 'utf8');\n const parsed = JSON.parse(raw) as Partial<CacheFile>;\n if (parsed.version === CACHE_VERSION && parsed.entries && typeof parsed.entries === 'object') {\n for (const [key, range] of Object.entries(parsed.entries)) {\n if (isRange(range)) entries.set(key, range);\n }\n }\n } catch {\n // Missing, corrupt, or unreadable sidecar: self-heal by starting\n // empty rather than failing the query it's meant to speed up.\n }\n this.entries = entries;\n return entries;\n }\n\n async get(filePath: string, currentSize: number): Promise<ChroniclePartitionRange | undefined> {\n const entries = await this.load();\n const range = entries.get(this.toKey(filePath));\n return range && range.size === currentSize ? range : undefined;\n }\n\n set(filePath: string, range: ChroniclePartitionRange): void {\n this.entries ??= new Map();\n this.entries.set(this.toKey(filePath), range);\n this.dirty = true;\n }\n\n /** Drop entries for files no longer present (e.g. removed by retention purge). */\n prune(existingFiles: readonly string[]): void {\n if (!this.entries) return;\n const keep = new Set(existingFiles.map((file) => this.toKey(file)));\n for (const key of this.entries.keys()) {\n if (!keep.has(key)) {\n this.entries.delete(key);\n this.dirty = true;\n }\n }\n }\n\n async flush(): Promise<void> {\n if (!this.dirty || !this.entries) return;\n const payload: CacheFile = { version: CACHE_VERSION, entries: Object.fromEntries(this.entries) };\n try {\n await withFileLock(this.cachePath, async () => {\n await atomicWrite(this.cachePath, `${JSON.stringify(payload)}\\n`, { mode: 0o600 });\n });\n this.dirty = false;\n } catch {\n // Best-effort persistence: the cache still works in-memory for this\n // process even if the sidecar couldn't be written this time.\n }\n }\n}\n", "import { createHash } from 'node:crypto';\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport { assertUnixSocketPathWithinLimit } from '../utils/socket-path.js';\nimport { CHRONICLE_PROJECT_SERVER_PROTOCOL_VERSION } from './project-server-protocol.js';\n\nexport const CHRONICLE_PROJECT_SERVER_METADATA_FILE = 'server.json';\n\nfunction normalizedPath(value: string): string {\n const resolved = path.resolve(value);\n return process.platform === 'win32' ? resolved.toLowerCase() : resolved;\n}\n\nexport function chronicleProjectServerKey(projectDir: string): string {\n return createHash('sha256')\n .update(normalizedPath(path.join(projectDir, 'chronicle')))\n .digest('hex')\n .slice(0, 24);\n}\n\n/**\n * Deterministic per-project chronicle IPC endpoint.\n *\n * The Unix subdirectory is the short `wsch-v<V>/` (was\n * `wrongstack-chronicle-v<V>/`, which left a single byte of macOS `sun_path`\n * headroom under the ~48-byte per-user TMPDIR \u2014 see the codebase-index macOS\n * incident and `@wrongstack/persistence` socket-path helpers). ~86 bytes\n * worst-case macOS now.\n *\n * Migration: the protocol version stays embedded in the path, so this rename\n * behaves exactly like a protocol bump \u2014 old daemons keep listening on the old\n * `wrongstack-chronicle-v<V>/` path, are never contacted again, and exit on\n * their idle timeout. No coexistence window: a client build always talks only\n * to the endpoint scheme it derives. Bump\n * `CHRONICLE_PROJECT_SERVER_PROTOCOL_VERSION` for wire changes as before; the\n * prefix itself must not grow without re-checking the byte budget.\n * The Windows pipe name keeps the long prefix \u2014 named pipes have no\n * `sun_path` limit.\n */\nexport function chronicleProjectServerEndpoint(projectDir: string): string {\n const key = chronicleProjectServerKey(projectDir);\n if (process.platform === 'win32') {\n return `\\\\\\\\.\\\\pipe\\\\wrongstack-chronicle-v${CHRONICLE_PROJECT_SERVER_PROTOCOL_VERSION}-${key}`;\n }\n return path.join(\n os.tmpdir(),\n `wsch-v${CHRONICLE_PROJECT_SERVER_PROTOCOL_VERSION}`,\n `${key}.sock`,\n );\n}\n\nexport function chronicleProjectServerMetadataPath(projectDir: string): string {\n return path.join(projectDir, 'chronicle', CHRONICLE_PROJECT_SERVER_METADATA_FILE);\n}\n\nexport function ensureChronicleProjectServerSocketDirectory(endpoint: string): void {\n if (process.platform !== 'win32') {\n // ~86 bytes under a canonical macOS TMPDIR since the wsch-v1/ rename.\n // Assert so growth fails loudly instead of as a silent bind error in the\n // detached daemon (see the codebase-index macOS incident).\n assertUnixSocketPathWithinLimit(endpoint, 'chronicle');\n fs.mkdirSync(path.dirname(endpoint), { recursive: true, mode: 0o700 });\n }\n}\n", "/**\n * Re-export of the Unix socket path-length helpers from\n * `@wrongstack/persistence` so packages that depend on core (tools, sage)\n * share one implementation with packages that depend on persistence directly\n * (kanban). See `packages/persistence/src/socket-path.ts` for rationale.\n */\nexport {\n assertUnixSocketPathWithinLimit,\n checkUnixSocketPath,\n type UnixSocketPathCheck,\n unixSocketPathLimit,\n} from '@wrongstack/persistence';\n", "import type { ChronicleJournalStats, ChroniclePurgeResult } from './journal.js';\nimport type { ChronicleMetricsRefreshResult } from './metrics-store.js';\nimport type {\n ChronicleFacet,\n ChronicleFacetResults,\n ChronicleFacetValue,\n ChronicleGraphResult,\n ChronicleQuery,\n ChronicleQueryResult,\n} from './query.js';\nimport type { ChronicleEvent, ChronicleEventInput } from './types.js';\n\nexport const CHRONICLE_PROJECT_SERVER_PROTOCOL_VERSION = 2;\nexport const CHRONICLE_PROJECT_SERVER_MAX_FRAME_CHARS = 64 * 1024 * 1024;\n\nexport interface ChronicleProjectServerInfo {\n protocolVersion: number;\n pid: number;\n projectRoot: string;\n projectDir: string;\n chronicleDirectory: string;\n endpoint: string;\n startedAt: string;\n}\n\nexport interface ChronicleProjectServerHealth extends ChronicleProjectServerInfo {\n checkedAt: number;\n uptimeMs: number;\n clients: number;\n activeRequests: number;\n journal: ChronicleJournalStats;\n watcher: {\n active: boolean;\n watchedFiles: number;\n lastError?: string | undefined;\n };\n /**\n * Day families the legacy JSONL import refused to move for a broken chain.\n *\n * Present and non-empty means the journal has a known hole: those days were\n * never imported and never will be. Health surfaces it as degraded rather\n * than healthy \u2014 a store that silently serves an incomplete audit record is\n * worse than one that says which day is missing.\n */\n quarantinedFamilies?: Array<{ day: string; sequence: number; reason: string }> | undefined;\n memory: {\n rss: number;\n heapUsed: number;\n heapTotal: number;\n external: number;\n };\n}\n\nexport type ChronicleMetricsView = 'summary' | 'providers' | 'tasks' | 'files';\n\nexport interface ChronicleMetricsRequest {\n view: ChronicleMetricsView;\n /**\n * When false, serve the current derived projection immediately and refresh\n * it in the background. Latency-sensitive enrichment must not wait for a\n * multi-GB historical backlog to be indexed.\n */\n refresh?: boolean;\n providers?: { from?: string; to?: string };\n tasks?: {\n runId?: string;\n boardId?: string;\n sessionId?: string;\n status?: string;\n limit?: number;\n };\n files?: {\n path?: string;\n paths?: string[];\n latestPerPath?: boolean;\n taskId?: string;\n boardId?: string;\n sessionId?: string;\n limit?: number;\n };\n}\n\nexport interface ChronicleMetricsResponse {\n refreshed: ChronicleMetricsRefreshResult;\n data: unknown;\n}\n\nexport interface ChronicleServerOperations {\n ping: { args: Record<string, never>; result: ChronicleProjectServerHealth };\n append: { args: { inputs: ChronicleEventInput[] }; result: ChronicleEvent[] };\n flush: { args: Record<string, never>; result: void };\n purge: {\n args: { retentionDays: number; dryRun?: boolean };\n result: ChroniclePurgeResult;\n };\n query: { args: { query: ChronicleQuery }; result: ChronicleQueryResult };\n facet: {\n args: { field: ChronicleFacet; query: ChronicleQuery; limit?: number | undefined };\n result: {\n values: ChronicleFacetValue[];\n diagnostics: { sourceFiles: number; invalidLines: number };\n };\n };\n facets: {\n args: { fields: ChronicleFacet[]; query: ChronicleQuery; limit?: number | undefined };\n result: {\n values: ChronicleFacetResults;\n diagnostics: { sourceFiles: number; invalidLines: number };\n };\n };\n graph: {\n args: { seed: ChronicleQuery; hops?: number | undefined; maxNodes?: number | undefined };\n result: ChronicleGraphResult;\n };\n metrics: { args: ChronicleMetricsRequest; result: ChronicleMetricsResponse };\n}\n\nexport type ChronicleServerOperationName = keyof ChronicleServerOperations;\n\nexport type ChronicleProjectServerClientMessage =\n | {\n type: 'request';\n id: number;\n op: ChronicleServerOperationName;\n args: unknown;\n }\n | { type: 'shutdown'; id: number; reason?: string | undefined };\n\nexport type ChronicleProjectServerMessage =\n | ({ type: 'hello' } & ChronicleProjectServerInfo)\n | { type: 'response'; id: number; ok: true; result: unknown }\n | {\n type: 'response';\n id: number;\n ok: false;\n error: string;\n errorName?: string | undefined;\n };\n\nexport function encodeChronicleProjectServerMessage(message: object): string {\n return `${JSON.stringify(message)}\\n`;\n}\n", "/**\n * SQLite-backed Chronicle journal (phase 1 of `chronicle-sqlite-journal-v1`).\n *\n * Same durable contract as `ChronicleJournal`, different storage: events become\n * rows instead of lines in `<day>.events.jsonl` partitions. The tamper-evident\n * chain is unchanged and deliberately so \u2014 `sequence`, `previousHash` and\n * `hash` mean exactly what they mean in the JSONL journal, and the hash is\n * computed by the shared `event-hash.ts` so the two stores can never drift.\n *\n * Why the payload is stored verbatim: the `hash` preimage is the canonical\n * encoding of the event *minus* its own `hash`. Reconstructing an event from\n * projected columns and re-hashing it would silently depend on the column set\n * staying lossless forever. Storing `JSON.stringify(event)` and re-deriving the\n * preimage from the parsed payload keeps verification independent of the\n * projection \u2014 the columns are a read-path index, never the source of truth.\n *\n * Only the project daemon opens this database, after it has won the endpoint\n * election, so the writer is single by construction and `BEGIN IMMEDIATE` is\n * enough. See `packages/core/tests/architecture/project-daemon-boundary.test.ts`.\n */\nimport { randomUUID } from 'node:crypto';\nimport { createRequire } from 'node:module';\nimport * as path from 'node:path';\nimport type { DatabaseSync } from 'node:sqlite';\nimport { withSqliteExperimentalWarningSuppressed } from '../utils/index.js';\nimport { chronicleEventHash, GENESIS_HASH, hashValue } from './event-hash.js';\nimport type { ChronicleJournalStats, ChroniclePurgeResult } from './journal.js';\nimport {\n ChronicleSqliteQueryEngine,\n type ChronicleSqliteQueryEngineOptions,\n} from './sqlite-query.js';\nimport {\n CHRONICLE_SCHEMA_VERSION,\n type ChronicleEvent,\n type ChronicleEventInput,\n type ChronicleVerifyResult,\n} from './types.js';\n\nexport const CHRONICLE_SQLITE_FILE = 'chronicle.sqlite';\n\n/** Marker written once the legacy JSONL partitions have been imported. */\nexport const LEGACY_JSONL_MIGRATION_KEY = 'legacy-jsonl-v1';\n\n/** Day families the import refused to move, recorded so they are never retried silently. */\nexport const LEGACY_JSONL_QUARANTINE_KEY = 'legacy-jsonl-v1:quarantine';\n\nconst SCHEMA_VERSION = 1;\n\nexport interface ChronicleSqliteJournalOptions {\n /** Directory holding the journal, i.e. `<projectDir>/chronicle`. */\n directory: string;\n now?: (() => Date) | undefined;\n monotonicNow?: (() => bigint) | undefined;\n idFactory?: (() => string) | undefined;\n}\n\nexport interface ChronicleSqlitePurgeOptions {\n retentionDays: number;\n dryRun?: boolean | undefined;\n}\n\ninterface ChainAnchor {\n sequence: number;\n hash: string;\n}\n\n/** A day family the import refused to move, and why. */\nexport interface ChronicleQuarantinedFamily {\n day: string;\n sequence: number;\n reason: string;\n}\n\n/** Write surface handed to a legacy import; see {@link ChronicleSqliteJournal.runFamilyImport}. */\nexport interface ChronicleImportSink {\n /**\n * Store an event with its recorded `sequence`, `previousHash` and `hash`.\n *\n * The payload is re-serialized rather than copied byte-for-byte from the\n * JSONL line, which is safe because the hash preimage is the *canonical*\n * encoding derived from the parsed event (\u00A73.1 of the spec) \u2014 not the stored\n * bytes. `JSON.parse` round-trips it exactly, so verification is unaffected.\n */\n insert(day: string, event: ChronicleEvent): void;\n /** Carry a legacy day-family retention checkpoint over. */\n checkpoint(day: string, sequence: number, hash: string): void;\n}\n\n// \u2500\u2500\u2500 node:sqlite lazy loader (mirrors metrics-store.ts) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nlet Ctor: typeof DatabaseSync | null | undefined;\n\nfunction loadDatabaseSync(): typeof DatabaseSync {\n if (Ctor) return Ctor;\n if (Ctor === null) throw new Error('node:sqlite is unavailable in this runtime');\n try {\n Ctor = withSqliteExperimentalWarningSuppressed(\n () =>\n (createRequire(import.meta.url)('node:sqlite') as typeof import('node:sqlite')).DatabaseSync,\n );\n return Ctor;\n } catch (error) {\n Ctor = null;\n throw new Error(\n \"The Chronicle journal needs Node's built-in SQLite (node:sqlite, Node >= 22.5): \" +\n (error instanceof Error ? error.message : String(error)),\n );\n }\n}\n\n// \u2500\u2500\u2500 Store \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport class ChronicleSqliteJournal {\n private readonly db: DatabaseSync;\n private readonly dbPath: string;\n private readonly now: () => Date;\n private readonly monotonicNow: () => bigint;\n private readonly idFactory: () => string;\n\n /**\n * Cached chain head per day. Cleared wholesale on any write failure so the\n * next append rebuilds from the database rather than trusting a counter that\n * may have advanced past what actually committed.\n */\n private readonly anchors = new Map<string, ChainAnchor>();\n\n private readonly counters = {\n acceptedEvents: 0,\n persistedEvents: 0,\n rejectedEvents: 0,\n failedEvents: 0,\n batches: 0,\n maxObservedPending: 0,\n largestBatch: 0,\n };\n private lastBatchDurationMs: number | undefined;\n\n constructor(options: ChronicleSqliteJournalOptions) {\n this.dbPath = path.join(path.resolve(options.directory), CHRONICLE_SQLITE_FILE);\n this.now = options.now ?? (() => new Date());\n this.monotonicNow = options.monotonicNow ?? (() => process.hrtime.bigint());\n this.idFactory = options.idFactory ?? (() => randomUUID());\n const Database = loadDatabaseSync();\n this.db = new Database(this.dbPath);\n this.db.exec('PRAGMA journal_mode = WAL');\n this.ensureSchema();\n }\n\n close(): void {\n this.db.close();\n }\n\n stats(): ChronicleJournalStats {\n return {\n ...this.counters,\n pendingEvents: 0,\n // Retained at zero for wire compatibility: partitions do not exist here,\n // but `ChronicleJournalStats` is part of the IPC health payload.\n partitionRolls: 0,\n ...(this.lastBatchDurationMs !== undefined\n ? { lastBatchDurationMs: this.lastBatchDurationMs }\n : {}),\n };\n }\n\n /**\n * Writes are synchronous and transactional, so there is nothing buffered to\n * flush. Kept to satisfy `ChronicleEventSink`.\n */\n async flush(): Promise<void> {\n return Promise.resolve();\n }\n\n async append(input: ChronicleEventInput): Promise<ChronicleEvent> {\n const [event] = await this.appendBatch([input]);\n // appendBatch either returns one event per input or throws.\n return event as ChronicleEvent;\n }\n\n /**\n * Append a batch as one transaction.\n *\n * The chain is computed in memory from a single anchor, so a partially\n * applied batch would leave a hole in `sequence` that verification can never\n * reconcile. Rollback plus anchor invalidation is what prevents that.\n */\n async appendBatch(inputs: readonly ChronicleEventInput[]): Promise<ChronicleEvent[]> {\n if (inputs.length === 0) return [];\n const started = performance.now();\n this.counters.acceptedEvents += inputs.length;\n this.counters.batches += 1;\n this.counters.largestBatch = Math.max(this.counters.largestBatch, inputs.length);\n\n const instant = this.now().toISOString();\n // The chain scope is the wall-clock day of the append, matching the file\n // `journalForToday()` would have opened \u2014 not the event's `occurredAt`,\n // which a caller may back-date.\n const day = instant.slice(0, 10);\n const events: ChronicleEvent[] = [];\n let previous = this.readAnchor(day);\n\n for (const input of inputs) {\n const unhashed = {\n ...input,\n occurredAt: input.occurredAt ?? instant,\n monotonicNs: input.monotonicNs ?? this.monotonicNow().toString(),\n schemaVersion: CHRONICLE_SCHEMA_VERSION,\n eventId: this.idFactory(),\n observedAt: instant,\n persistedAt: instant,\n sequence: previous.sequence + 1,\n previousHash: previous.hash,\n };\n const event: ChronicleEvent = { ...unhashed, hash: hashValue(unhashed) };\n events.push(event);\n previous = { sequence: event.sequence, hash: event.hash };\n }\n\n try {\n this.db.exec('BEGIN IMMEDIATE');\n const insert = this.db.prepare(\n `INSERT INTO events (\n day, sequence, event_id, hash, previous_hash, occurred_at, event_type, outcome,\n project_id, session_id, agent_id, task_id, trace_id, logical_request_id,\n resource_kind, resource_id, resource_path, duration_ns, payload\n ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,\n );\n for (const event of events) {\n const row = projectEvent(event);\n insert.run(\n day,\n event.sequence,\n event.eventId,\n event.hash,\n event.previousHash,\n row.occurredAt,\n event.eventType,\n row.outcome,\n row.projectId,\n row.sessionId,\n row.agentId,\n row.taskId,\n row.traceId,\n row.logicalRequestId,\n row.resourceKind,\n row.resourceId,\n row.resourcePath,\n row.durationNs,\n JSON.stringify(event),\n );\n }\n this.db.exec('COMMIT');\n } catch (error) {\n try {\n this.db.exec('ROLLBACK');\n } catch {\n // A failed BEGIN leaves no transaction to roll back.\n }\n this.anchors.clear();\n this.counters.failedEvents += inputs.length;\n this.lastBatchDurationMs = performance.now() - started;\n throw error;\n }\n\n this.anchors.set(day, previous);\n this.counters.persistedEvents += events.length;\n this.lastBatchDurationMs = performance.now() - started;\n return events;\n }\n\n async readAll(): Promise<ChronicleEvent[]> {\n const rows = this.db\n .prepare('SELECT payload FROM events ORDER BY day, sequence')\n .all() as Array<{ payload: string }>;\n return rows.map((row) => JSON.parse(row.payload) as ChronicleEvent);\n }\n\n /**\n * Walk every chain and prove none has been edited.\n *\n * Chronicle chains are scoped to a day, not to the journal: the JSONL writer\n * anchors each `<day>.events.jsonl` family at `GENESIS_HASH` independently,\n * so `sequence` restarts at 1 every day. Verification mirrors that \u2014 each day\n * is validated on its own, and a break in one does not implicate the others.\n *\n * Three independent properties per day, because each catches a different\n * failure: a dense `sequence` catches deletions from the middle, the\n * `previousHash` link catches reordering, and re-hashing the payload catches\n * an in-place edit that left the links intact.\n */\n async verify(): Promise<ChronicleVerifyResult> {\n let entries = 0;\n let lastSequence = 0;\n let lastHash = GENESIS_HASH;\n\n for (const day of this.days()) {\n const checkpoint = this.readCheckpoint(day);\n let expectedSequence = (checkpoint?.sequence ?? 0) + 1;\n let previousHash = checkpoint?.hash ?? GENESIS_HASH;\n\n const rows = this.db\n .prepare(\n 'SELECT sequence, hash, previous_hash, payload FROM events WHERE day = ? ORDER BY sequence',\n )\n .all(day) as Array<{\n sequence: number;\n hash: string;\n previous_hash: string;\n payload: string;\n }>;\n\n for (const row of rows) {\n if (row.sequence !== expectedSequence) {\n return {\n ok: false,\n entries,\n brokenAt: entries,\n reason: `sequence gap in ${day}: expected ${expectedSequence}, found ${row.sequence}`,\n };\n }\n if (row.previous_hash !== previousHash) {\n return { ok: false, entries, brokenAt: entries, reason: 'previous hash mismatch' };\n }\n let event: ChronicleEvent;\n try {\n event = JSON.parse(row.payload) as ChronicleEvent;\n } catch {\n return { ok: false, entries, brokenAt: entries, reason: 'invalid payload JSON' };\n }\n if (chronicleEventHash(event) !== row.hash) {\n return { ok: false, entries, brokenAt: entries, reason: 'entry hash mismatch' };\n }\n entries += 1;\n expectedSequence = row.sequence + 1;\n previousHash = row.hash;\n }\n\n lastSequence = expectedSequence - 1;\n lastHash = previousHash;\n }\n\n return { ok: true, entries, lastSequence, lastHash };\n }\n\n /**\n * Drop events older than the retention window.\n *\n * Retention is day-granular and chains are day-scoped, so a purge removes\n * whole chains rather than truncating one. That is why nothing needs to be\n * checkpointed here: there is no surviving suffix left dangling without an\n * anchor. Any checkpoint imported from a partially-purged legacy day family\n * is dropped alongside its events.\n */\n async purge(options: ChronicleSqlitePurgeOptions): Promise<ChroniclePurgeResult> {\n const empty: ChroniclePurgeResult = {\n deletedCount: 0,\n deletedBytes: 0,\n skippedCount: 0,\n errors: [],\n };\n if (!Number.isFinite(options.retentionDays) || options.retentionDays <= 0) return empty;\n\n const cutoff = new Date(this.now().getTime() - options.retentionDays * 86_400_000)\n .toISOString()\n .slice(0, 10);\n\n const count = (\n this.db.prepare('SELECT COUNT(*) AS n FROM events WHERE day < ?').get(cutoff) as {\n n: number;\n }\n ).n;\n if (count === 0) return empty;\n\n if (options.dryRun) {\n const days = this.db\n .prepare('SELECT DISTINCT day FROM events WHERE day < ? ORDER BY day')\n .all(cutoff) as Array<{ day: string }>;\n return { ...empty, deletedCount: count, candidates: days.map((row) => row.day) };\n }\n\n try {\n this.db.exec('BEGIN IMMEDIATE');\n this.db.prepare('DELETE FROM events WHERE day < ?').run(cutoff);\n this.db.prepare('DELETE FROM chain_checkpoint WHERE day < ?').run(cutoff);\n this.db.exec('COMMIT');\n } catch (error) {\n try {\n this.db.exec('ROLLBACK');\n } catch {\n // Nothing to unwind.\n }\n return {\n ...empty,\n errors: [\n {\n file: this.dbPath,\n reason: error instanceof Error ? error.message : String(error),\n },\n ],\n };\n }\n\n this.anchors.clear();\n return { ...empty, deletedCount: count };\n }\n\n /**\n * Run one day family's legacy import inside its own transaction.\n *\n * Deliberately separate from `appendBatch`: the append path *computes*\n * `sequence`, `previousHash` and `hash`, while an import must carry them over\n * untouched. Fusing the two would put a code path one refactor away from\n * re-hashing historical events, which is the one change that silently\n * destroys their tamper evidence.\n *\n * The transaction is scoped to a single family because chains are: `sequence`\n * restarts at 1 each day, so one day's break says nothing about the next\n * day's integrity. A whole-journal transaction made every future day hostage\n * to the worst day on disk \u2014 one corrupt family and the daemon could never\n * open its store again. The family is still all-or-nothing: a break rolls\n * back that day entirely, so no partial chain is ever visible.\n */\n async runFamilyImport(load: (sink: ChronicleImportSink) => Promise<void>): Promise<void> {\n const insert = this.db.prepare(\n `INSERT INTO events (\n day, sequence, event_id, hash, previous_hash, occurred_at, event_type, outcome,\n project_id, session_id, agent_id, task_id, trace_id, logical_request_id,\n resource_kind, resource_id, resource_path, duration_ns, payload\n ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,\n );\n const checkpoint = this.db.prepare(\n `INSERT INTO chain_checkpoint (day, sequence, hash) VALUES (?, ?, ?)\n ON CONFLICT(day) DO UPDATE SET sequence = excluded.sequence, hash = excluded.hash`,\n );\n\n this.db.exec('BEGIN IMMEDIATE');\n try {\n await load({\n insert: (day, event) => {\n const row = projectEvent(event);\n insert.run(\n day,\n event.sequence,\n event.eventId,\n event.hash,\n event.previousHash,\n row.occurredAt,\n event.eventType,\n row.outcome,\n row.projectId,\n row.sessionId,\n row.agentId,\n row.taskId,\n row.traceId,\n row.logicalRequestId,\n row.resourceKind,\n row.resourceId,\n row.resourcePath,\n row.durationNs,\n JSON.stringify(event),\n );\n },\n checkpoint: (day, sequence, hash) => {\n checkpoint.run(day, sequence, hash);\n },\n });\n this.db.exec('COMMIT');\n } catch (error) {\n try {\n this.db.exec('ROLLBACK');\n } catch {\n // Nothing to unwind.\n }\n throw error;\n } finally {\n this.anchors.clear();\n }\n }\n\n /**\n * A read engine over this journal's own connection.\n *\n * Sharing the connection rather than opening a second one keeps the\n * single-writer guarantee intact and means a reader can never observe a\n * half-applied batch: SQLite serialises statements on one handle.\n */\n queryEngine(options?: ChronicleSqliteQueryEngineOptions): ChronicleSqliteQueryEngine {\n return new ChronicleSqliteQueryEngine(this.db, options);\n }\n\n /** Has the legacy JSONL import already run? */\n hasImportedLegacyJournal(): boolean {\n return this.readMeta(LEGACY_JSONL_MIGRATION_KEY) !== undefined;\n }\n\n markLegacyJournalImported(): void {\n this.db\n .prepare(\n `INSERT INTO chronicle_meta (key, value) VALUES (?, 'done')\n ON CONFLICT(key) DO UPDATE SET value = 'done'`,\n )\n .run(LEGACY_JSONL_MIGRATION_KEY);\n }\n\n /**\n * Record the day families the import refused to move.\n *\n * Persisted rather than merely logged because the import runs once: after the\n * marker is set nothing re-reads the JSONL, so this row is the only surviving\n * evidence that a day was dropped. Health reports read it back to say\n * \"degraded, and here is exactly what is missing\" instead of quietly serving\n * a journal with a hole in it.\n */\n recordQuarantinedFamilies(families: readonly ChronicleQuarantinedFamily[]): void {\n if (families.length === 0) return;\n this.db\n .prepare(\n `INSERT INTO chronicle_meta (key, value) VALUES (?, ?)\n ON CONFLICT(key) DO UPDATE SET value = excluded.value`,\n )\n .run(LEGACY_JSONL_QUARANTINE_KEY, JSON.stringify(families));\n }\n\n /**\n * Does this day already hold rows?\n *\n * Each family commits on its own, so an import interrupted between families\n * leaves a database that is complete for the days it reached. `(day,\n * sequence)` is the primary key, so re-inserting one of those days would\n * abort on a constraint violation rather than start over \u2014 this is what lets\n * the next run resume at the first day it never got to.\n */\n hasImportedDay(day: string): boolean {\n const row = this.db.prepare('SELECT 1 AS present FROM events WHERE day = ? LIMIT 1').get(day) as\n | { present: number }\n | undefined;\n return row !== undefined;\n }\n\n /** Day families the legacy import refused to move, oldest first. */\n quarantinedFamilies(): ChronicleQuarantinedFamily[] {\n const raw = this.readMeta(LEGACY_JSONL_QUARANTINE_KEY);\n if (!raw) return [];\n try {\n const parsed: unknown = JSON.parse(raw);\n return Array.isArray(parsed) ? (parsed as ChronicleQuarantinedFamily[]) : [];\n } catch {\n return [];\n }\n }\n\n // \u2500\u2500\u2500 internals \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n private readMeta(key: string): string | undefined {\n const row = this.db.prepare('SELECT value FROM chronicle_meta WHERE key = ?').get(key) as\n | { value: string }\n | undefined;\n return row?.value;\n }\n\n private readCheckpoint(day: string): ChainAnchor | undefined {\n return this.db.prepare('SELECT sequence, hash FROM chain_checkpoint WHERE day = ?').get(day) as\n | ChainAnchor\n | undefined;\n }\n\n /** Days that currently hold at least one event, oldest first. */\n private days(): string[] {\n const rows = this.db.prepare('SELECT DISTINCT day FROM events ORDER BY day').all() as Array<{\n day: string;\n }>;\n return rows.map((row) => row.day);\n }\n\n /**\n * Resolve the chain head, in the same precedence the JSONL journal uses: the\n * newest event, else the retention checkpoint (every event before it was\n * purged), else genesis.\n */\n private readAnchor(day: string): ChainAnchor {\n const cached = this.anchors.get(day);\n if (cached) return cached;\n const last = this.db\n .prepare('SELECT sequence, hash FROM events WHERE day = ? ORDER BY sequence DESC LIMIT 1')\n .get(day) as ChainAnchor | undefined;\n const anchor = last ?? this.readCheckpoint(day) ?? { sequence: 0, hash: GENESIS_HASH };\n this.anchors.set(day, anchor);\n return anchor;\n }\n\n private ensureSchema(): void {\n const version = (this.db.prepare('PRAGMA user_version').get() as { user_version: number })\n .user_version;\n this.db.exec(`\n CREATE TABLE IF NOT EXISTS events (\n day TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n event_id TEXT NOT NULL UNIQUE,\n hash TEXT NOT NULL,\n previous_hash TEXT NOT NULL,\n occurred_at TEXT NOT NULL,\n event_type TEXT NOT NULL,\n outcome TEXT,\n project_id TEXT,\n session_id TEXT,\n agent_id TEXT,\n task_id TEXT,\n trace_id TEXT,\n logical_request_id TEXT,\n resource_kind TEXT,\n resource_id TEXT,\n resource_path TEXT,\n duration_ns TEXT,\n payload TEXT NOT NULL,\n PRIMARY KEY (day, sequence)\n );\n CREATE INDEX IF NOT EXISTS events_occurred_at ON events(occurred_at);\n CREATE INDEX IF NOT EXISTS events_type_outcome ON events(event_type, outcome);\n CREATE INDEX IF NOT EXISTS events_session ON events(session_id, day, sequence);\n CREATE INDEX IF NOT EXISTS events_trace ON events(trace_id);\n CREATE INDEX IF NOT EXISTS events_logical_request ON events(logical_request_id);\n CREATE INDEX IF NOT EXISTS events_resource_path ON events(resource_path);\n\n CREATE TABLE IF NOT EXISTS chain_checkpoint (\n day TEXT PRIMARY KEY,\n sequence INTEGER NOT NULL,\n hash TEXT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS chronicle_meta (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL\n );\n `);\n if (version !== SCHEMA_VERSION) {\n this.db.exec(`PRAGMA user_version = ${SCHEMA_VERSION}`);\n }\n }\n}\n\ninterface ProjectedRow {\n occurredAt: string;\n outcome: string | null;\n projectId: string | null;\n sessionId: string | null;\n agentId: string | null;\n taskId: string | null;\n traceId: string | null;\n logicalRequestId: string | null;\n resourceKind: string | null;\n resourceId: string | null;\n resourcePath: string | null;\n durationNs: string | null;\n}\n\n/**\n * Derive the indexed columns from an event.\n *\n * Every value here is recoverable from `payload`; nothing is stored only in a\n * column. That is what lets the projection change in a later release without\n * touching a single stored hash.\n *\n * `day` is deliberately absent: it is the chain scope, not a projection. The\n * legacy writer picks it from the wall clock when the batch is appended (see\n * `journalForToday`), so an event carrying a back-dated `occurredAt` still\n * belongs to the chain of the day it was written on.\n */\nfunction projectEvent(event: ChronicleEvent): ProjectedRow {\n const occurredAt = event.occurredAt ?? event.observedAt;\n return {\n occurredAt,\n outcome: event.outcome ?? null,\n projectId: event.scope.projectId ?? null,\n sessionId: event.scope.sessionId ?? null,\n agentId: event.scope.agentId ?? null,\n taskId: event.scope.taskId ?? null,\n traceId: event.correlation?.traceId ?? null,\n logicalRequestId: event.correlation?.logicalRequestId ?? null,\n resourceKind: event.resource?.kind ?? null,\n resourceId: event.resource?.id ?? null,\n resourcePath: event.resource?.path ?? null,\n durationNs: event.durationNs ?? null,\n };\n}\n", "/**\n * SQLite read path for Chronicle (phase 3 of `chronicle-sqlite-journal-v1`).\n *\n * The division of labour is the whole point of this file:\n *\n * - **SQL narrows.** Indexed columns turn \"parse every line of every partition\n * that overlaps the range\" into an index seek. Only predicates that map\n * cleanly onto a column are pushed down.\n * - **JavaScript decides.** The pushed-down predicate is a deliberate\n * *superset*: every candidate row is parsed and then passed through the same\n * `matches()` the JSONL engine uses. Nothing is filtered out by SQL that\n * `matches()` would have kept.\n *\n * That split is what makes parity provable rather than hoped for. A SQL\n * re-expression of `ChronicleQuery` would have to restate tag/attribute\n * lookups, path normalisation and line-range containment, and each restatement\n * is a place where the two engines could silently disagree. Here they cannot\n * disagree about *which* events match \u2014 only about how fast the candidates are\n * found.\n *\n * The summary is built with the JSONL engine's own accumulator for the same\n * reason: family classification, `usage.*` paths, cost de-duplication and the\n * p95 are semantics, not arithmetic.\n */\nimport type { DatabaseSync } from 'node:sqlite';\nimport type { ChronicleEvent } from './types.js';\nimport {\n type ChronicleFacet,\n type ChronicleFacetResults,\n type ChronicleFacetValue,\n type ChronicleGraphEdge,\n type ChronicleGraphResult,\n type ChronicleQuery,\n type ChronicleQueryResult,\n compareEvents,\n createSummaryAccumulator,\n facetValue,\n finalizeSummary,\n matches,\n relationKeys,\n updateSummary,\n} from './query.js';\n\n/** Hard ceiling mirroring `ChronicleQueryEngine.query`. */\nconst MAX_LIMIT = 10_000;\n\n/**\n * Keyset position in the `(day, sequence)` total order.\n *\n * Deliberately not interchangeable with the JSONL engine's cursor, which\n * encodes a snapshot of partition files. A cursor is opaque and belongs to the\n * engine that issued it; carrying one across would be meaningless.\n */\ninterface SqliteCursor {\n day: string;\n sequence: number;\n}\n\nfunction encodeCursor(cursor: SqliteCursor): string {\n return Buffer.from(`${cursor.day}:${cursor.sequence}`, 'utf8').toString('base64url');\n}\n\nfunction decodeCursor(raw: string | undefined): SqliteCursor | undefined {\n if (!raw) return undefined;\n try {\n const [day, sequence] = Buffer.from(raw, 'base64url').toString('utf8').split(':');\n if (!day || sequence === undefined) return undefined;\n const parsed = Number(sequence);\n return Number.isSafeInteger(parsed) ? { day, sequence: parsed } : undefined;\n } catch {\n return undefined;\n }\n}\n\ninterface PushedDown {\n clause: string;\n params: (string | number)[];\n}\n\n/**\n * Translate the parts of a query that map onto indexed columns.\n *\n * Anything absent here is simply not narrowed \u2014 `matches()` still applies it.\n * Adding a predicate to this list is an optimization; forgetting one is not a\n * correctness bug. That asymmetry is intentional.\n */\nfunction pushDown(query: ChronicleQuery): PushedDown {\n const clauses: string[] = [];\n const params: (string | number)[] = [];\n\n const eq = (column: string, value: string | undefined): void => {\n if (value === undefined) return;\n clauses.push(`${column} = ?`);\n params.push(value);\n };\n\n eq('event_id', query.eventId);\n eq('project_id', query.projectId);\n eq('session_id', query.sessionId);\n eq('agent_id', query.agentId);\n eq('task_id', query.taskId);\n eq('trace_id', query.traceId);\n eq('logical_request_id', query.logicalRequestId);\n eq('resource_kind', query.resourceKind);\n eq('resource_id', query.resourceId);\n\n if (query.eventTypes?.length) {\n clauses.push(`event_type IN (${query.eventTypes.map(() => '?').join(',')})`);\n params.push(...query.eventTypes);\n }\n if (query.outcomes?.length) {\n clauses.push(`outcome IN (${query.outcomes.map(() => '?').join(',')})`);\n params.push(...query.outcomes);\n }\n // `occurred_at` is an ISO-8601 UTC string, so lexicographic comparison is\n // chronological \u2014 the same assumption `matches()` makes.\n if (query.from) {\n clauses.push('occurred_at >= ?');\n params.push(query.from);\n }\n if (query.to) {\n clauses.push('occurred_at <= ?');\n params.push(query.to);\n }\n\n return { clause: clauses.length ? clauses.join(' AND ') : '1=1', params };\n}\n\nexport interface ChronicleSqliteQueryEngineOptions {\n /** Rows pulled from SQLite per batch while streaming candidates. */\n batchSize?: number | undefined;\n}\n\nexport class ChronicleSqliteQueryEngine {\n readonly diagnostics = { sourceFiles: 1, invalidLines: 0 };\n private readonly batchSize: number;\n\n constructor(\n private readonly db: DatabaseSync,\n options: ChronicleSqliteQueryEngineOptions = {},\n ) {\n this.batchSize = Math.max(1, options.batchSize ?? 1_000);\n }\n\n async query(query: ChronicleQuery = {}): Promise<ChronicleQueryResult> {\n const order = query.order ?? 'desc';\n const limit = Math.max(1, Math.min(query.limit ?? 100, MAX_LIMIT));\n const cursor = decodeCursor(query.cursor);\n const pushed = pushDown(query);\n\n const direction = order === 'asc' ? 'ASC' : 'DESC';\n const comparison = order === 'asc' ? '>' : '<';\n const keyset = cursor ? ` AND (day, sequence) ${comparison} (?, ?)` : '';\n const sql =\n `SELECT day, sequence, payload FROM events WHERE ${pushed.clause}${keyset}` +\n ` ORDER BY day ${direction}, sequence ${direction} LIMIT ? OFFSET ?`;\n\n const summary = createSummaryAccumulator();\n const page: ChronicleEvent[] = [];\n let total = 0;\n let scannedEvents = 0;\n let last: SqliteCursor | undefined;\n let offset = 0;\n\n // Every matching event feeds the summary, which is defined over the whole\n // result set rather than the page (see `ChronicleSummary`). Candidates are\n // streamed in batches so a wide query does not materialise the table.\n for (;;) {\n const params = [...pushed.params];\n if (cursor) params.push(cursor.day, cursor.sequence);\n params.push(this.batchSize, offset);\n const rows = this.db.prepare(sql).all(...params) as Array<{\n day: string;\n sequence: number;\n payload: string;\n }>;\n if (rows.length === 0) break;\n offset += rows.length;\n\n for (const row of rows) {\n scannedEvents++;\n let event: ChronicleEvent;\n try {\n event = JSON.parse(row.payload) as ChronicleEvent;\n } catch {\n this.diagnostics.invalidLines++;\n continue;\n }\n if (!matches(event, query)) continue;\n total++;\n updateSummary(summary, event);\n if (page.length < limit) {\n page.push(event);\n last = { day: row.day, sequence: row.sequence };\n }\n }\n if (rows.length < this.batchSize) break;\n }\n\n // The JSONL engine returns the page in `compareEvents` order; keyset order\n // is `(day, sequence)`, which can differ when events share a timestamp.\n // Sorting here keeps both engines' pages identical.\n page.sort((left, right) => compareEvents(left, right) * (order === 'asc' ? 1 : -1));\n\n const result: ChronicleQueryResult = {\n events: page,\n total,\n scannedEvents,\n sourceFiles: this.diagnostics.sourceFiles,\n invalidLines: this.diagnostics.invalidLines,\n summary: finalizeSummary(summary),\n };\n if (total > page.length && last) {\n return { ...result, nextCursor: encodeCursor(last) };\n }\n return result;\n }\n\n /**\n * Value counts per facet field.\n *\n * Not a SQL `GROUP BY`: `facetValue()` reads fields that live inside the\n * payload \u2014 provider, model, tool call, tag \u2014 so grouping in SQL would only\n * work for the handful that happen to be columns and would need a second,\n * divergent definition for the rest. The narrowing is still done by SQL; the\n * counting uses the JSONL engine's own projection.\n */\n async facets(\n fields: readonly ChronicleFacet[],\n query: ChronicleQuery = {},\n limit = 100,\n ): Promise<ChronicleFacetResults> {\n const uniqueFields = [...new Set(fields)];\n if (uniqueFields.length === 0) return {};\n const counts = new Map(uniqueFields.map((field) => [field, new Map<string, number>()]));\n\n for (const event of this.eachMatch(query)) {\n for (const field of uniqueFields) {\n const value = facetValue(event, field);\n if (value === undefined) continue;\n const fieldCounts = counts.get(field);\n fieldCounts?.set(value, (fieldCounts.get(value) ?? 0) + 1);\n }\n }\n\n const result: ChronicleFacetResults = {};\n for (const field of uniqueFields) {\n result[field] = [...(counts.get(field) ?? new Map<string, number>())]\n .map(([value, count]) => ({ value, count }))\n // Ties broken by value so both engines agree on an otherwise arbitrary\n // order \u2014 the same comparator `ChronicleQueryEngine.facets` uses.\n .sort((left, right) => right.count - left.count || left.value.localeCompare(right.value))\n .slice(0, Math.max(0, limit));\n }\n return result;\n }\n\n async facet(\n field: ChronicleFacet,\n query: ChronicleQuery = {},\n limit = 100,\n ): Promise<ChronicleFacetValue[]> {\n return (await this.facets([field], query, limit))[field] ?? [];\n }\n\n /**\n * Expand explicit and typed correlation edges around a seed set.\n *\n * The traversal is the JSONL engine's, moved onto rows: `relationKeys()`\n * defines the edges, `compareEvents` orders the nodes, and each hop is\n * another ordered pass. Order is load-bearing rather than cosmetic \u2014 both\n * `maxNodes` truncations stop at whatever they reach first, so a differently\n * ordered scan would return a different subgraph rather than the same one\n * shuffled. `ORDER BY day, sequence` reproduces `comparePartitionPaths`\n * (family, then rotation index) followed by line order within a partition.\n */\n async graph(\n seed: ChronicleQuery = {},\n hops = 2,\n maxNodes = 1_000,\n ): Promise<ChronicleGraphResult> {\n const nodeLimit = Math.max(0, Math.floor(maxNodes));\n const selected = new Map<string, ChronicleEvent>();\n let seedCount = 0;\n\n for (const event of this.eachMatch(seed)) {\n seedCount++;\n if (selected.size < nodeLimit) selected.set(event.eventId, event);\n }\n\n let frontier = [...selected.values()];\n const depthLimit = Math.max(0, Math.min(hops, 10));\n for (\n let depth = 0;\n depth < depthLimit && frontier.length > 0 && selected.size < nodeLimit;\n depth++\n ) {\n const frontierKeys = new Set(\n frontier.flatMap((event) => relationKeys(event).map((relation) => relation.key)),\n );\n const next: ChronicleEvent[] = [];\n for (const event of this.eachMatch({})) {\n if (selected.has(event.eventId)) continue;\n if (!relationKeys(event).some((relation) => frontierKeys.has(relation.key))) continue;\n selected.set(event.eventId, event);\n next.push(event);\n if (selected.size >= nodeLimit) break;\n }\n frontier = next;\n }\n\n const nodes = [...selected.values()].sort(compareEvents);\n const byKey = new Map<string, ChronicleEvent[]>();\n for (const node of nodes) {\n for (const relation of relationKeys(node)) {\n const related = byKey.get(relation.key) ?? [];\n related.push(node);\n byKey.set(relation.key, related);\n }\n }\n\n const edges: ChronicleGraphEdge[] = [];\n const seen = new Set<string>();\n for (const node of nodes) {\n for (const relation of relationKeys(node)) {\n for (const candidate of byKey.get(relation.key) ?? []) {\n if (candidate.eventId === node.eventId) continue;\n const [from, to] =\n compareEvents(node, candidate) <= 0 ? [node, candidate] : [candidate, node];\n const id = `${from.eventId}:${to.eventId}:${relation.kind}`;\n if (seen.has(id)) continue;\n seen.add(id);\n edges.push({\n from: from.eventId,\n to: to.eventId,\n kind: relation.kind,\n confidence: relation.confidence,\n });\n }\n }\n }\n\n return {\n nodes,\n edges,\n truncated: seedCount > nodeLimit || selected.size >= nodeLimit,\n };\n }\n\n /** Every event satisfying `query`, pulled in batches so a wide scan stays bounded. */\n private *eachMatch(query: ChronicleQuery): Generator<ChronicleEvent> {\n const pushed = pushDown(query);\n const sql =\n `SELECT payload FROM events WHERE ${pushed.clause}` +\n ' ORDER BY day, sequence LIMIT ? OFFSET ?';\n let offset = 0;\n for (;;) {\n const rows = this.db.prepare(sql).all(...pushed.params, this.batchSize, offset) as Array<{\n payload: string;\n }>;\n if (rows.length === 0) return;\n offset += rows.length;\n for (const row of rows) {\n let event: ChronicleEvent;\n try {\n event = JSON.parse(row.payload) as ChronicleEvent;\n } catch {\n this.diagnostics.invalidLines++;\n continue;\n }\n if (matches(event, query)) yield event;\n }\n if (rows.length < this.batchSize) return;\n }\n }\n}\n"],
5
- "mappings": ";;;AASA,YAAYA,SAAQ;AACpB,YAAYC,UAAS;AACrB,YAAY,SAAS;AACrB,YAAYC,YAAU;;;ACStB,IAAI,iBAAiB;AAGd,SAAS,wBAA8B;AAC5C,mBAAiB;AACnB;;;AC1BA,SAAS,kBAAkB;AASpB,SAAS,uBACd,OACA,UAAkB,WAAW,GACX;AAClB,SAAO;AAAA,IACL,OAAO,EAAE,GAAG,MAAM;AAAA,IAClB,aAAa,EAAE,SAAS,QAAQ,WAAW,EAAE;AAAA,EAC/C;AACF;;;ACjBA,SAAS,kBAAkB;AAC3B,YAAY,SAAS;AACrB,YAAYC,WAAU;;;ACFtB,eAAsB,mBACpB,OACA,aACA,QACc;AACd,MAAI,MAAM,WAAW,EAAG,QAAO,CAAC;AAChC,QAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,WAAW,CAAC;AACjD,QAAM,UAAU,IAAI,MAAS,MAAM,MAAM;AACzC,MAAI,OAAO;AAEX,iBAAe,SAAwB;AACrC,WAAO,MAAM;AACX,YAAM,QAAQ;AACd;AACA,UAAI,SAAS,MAAM,OAAQ;AAC3B,cAAQ,KAAK,IAAI,MAAM,OAAO,MAAM,KAAK,GAAQ,KAAK;AAAA,IACxD;AAAA,EACF;AAEA,QAAM,UAAU,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,OAAO,MAAM,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC;AACpF,QAAM,QAAQ,IAAI,OAAO;AACzB,SAAO;AACT;;;ACNA,YAAY,QAAQ;AACpB,YAAY,UAAU;AAwBtB,IAAM,eAAe,uBAAO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["fs", "fsp", "path", "path", "watcher", "relative", "watcher", "stat", "createHash", "path", "randomUUID", "fs", "path", "createHash", "path", "randomUUID", "resolve", "parsed", "stat", "fs", "path", "fs", "path", "createHash", "createReadStream", "fs", "path", "createInterface", "fs", "path", "parsed", "createReadStream", "createInterface", "rangeCache", "trimmed", "normalize", "createHash", "stableStringify", "parsed", "chronicleDirectory", "durationMs", "readPath", "numberAt", "scopeKey", "createHash", "fs", "os", "path", "createHash", "endpoint", "randomUUID", "createRequire", "path", "encodeCursor", "decodeCursor", "parsed", "SCHEMA_VERSION", "Ctor", "loadDatabaseSync", "createRequire", "randomUUID", "parsed", "store", "resolve"]
7
- }