claude-code-workflow 6.2.2 → 6.2.3

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 (346) hide show
  1. package/ccw/dist/cli.d.ts +2 -0
  2. package/ccw/dist/cli.d.ts.map +1 -0
  3. package/ccw/dist/cli.js +219 -0
  4. package/ccw/dist/cli.js.map +1 -0
  5. package/ccw/dist/commands/cli.d.ts +32 -0
  6. package/ccw/dist/commands/cli.d.ts.map +1 -0
  7. package/ccw/dist/commands/cli.js +619 -0
  8. package/ccw/dist/commands/cli.js.map +1 -0
  9. package/ccw/dist/commands/core-memory.d.ts +32 -0
  10. package/ccw/dist/commands/core-memory.d.ts.map +1 -0
  11. package/ccw/dist/commands/core-memory.js +640 -0
  12. package/ccw/dist/commands/core-memory.js.map +1 -0
  13. package/ccw/dist/commands/hook.d.ts +16 -0
  14. package/ccw/dist/commands/hook.d.ts.map +1 -0
  15. package/ccw/dist/commands/hook.js +276 -0
  16. package/ccw/dist/commands/hook.js.map +1 -0
  17. package/ccw/dist/commands/install.d.ts +12 -0
  18. package/ccw/dist/commands/install.d.ts.map +1 -0
  19. package/ccw/dist/commands/install.js +443 -0
  20. package/ccw/dist/commands/install.js.map +1 -0
  21. package/ccw/dist/commands/list.d.ts +5 -0
  22. package/ccw/dist/commands/list.d.ts.map +1 -0
  23. package/ccw/dist/commands/list.js +32 -0
  24. package/ccw/dist/commands/list.js.map +1 -0
  25. package/ccw/dist/commands/memory.d.ts +57 -0
  26. package/ccw/dist/commands/memory.d.ts.map +1 -0
  27. package/ccw/dist/commands/memory.js +890 -0
  28. package/ccw/dist/commands/memory.js.map +1 -0
  29. package/ccw/dist/commands/serve.d.ts +12 -0
  30. package/ccw/dist/commands/serve.d.ts.map +1 -0
  31. package/ccw/dist/commands/serve.js +63 -0
  32. package/ccw/dist/commands/serve.js.map +1 -0
  33. package/ccw/dist/commands/session-path-resolver.d.ts +45 -0
  34. package/ccw/dist/commands/session-path-resolver.d.ts.map +1 -0
  35. package/ccw/dist/commands/session-path-resolver.js +302 -0
  36. package/ccw/dist/commands/session-path-resolver.js.map +1 -0
  37. package/ccw/dist/commands/session.d.ts +12 -0
  38. package/ccw/dist/commands/session.d.ts.map +1 -0
  39. package/ccw/dist/commands/session.js +954 -0
  40. package/ccw/dist/commands/session.js.map +1 -0
  41. package/ccw/dist/commands/stop.d.ts +11 -0
  42. package/ccw/dist/commands/stop.d.ts.map +1 -0
  43. package/ccw/dist/commands/stop.js +96 -0
  44. package/ccw/dist/commands/stop.js.map +1 -0
  45. package/ccw/dist/commands/tool.d.ts +29 -0
  46. package/ccw/dist/commands/tool.d.ts.map +1 -0
  47. package/ccw/dist/commands/tool.js +173 -0
  48. package/ccw/dist/commands/tool.js.map +1 -0
  49. package/ccw/dist/commands/uninstall.d.ts +9 -0
  50. package/ccw/dist/commands/uninstall.d.ts.map +1 -0
  51. package/ccw/dist/commands/uninstall.js +239 -0
  52. package/ccw/dist/commands/uninstall.js.map +1 -0
  53. package/ccw/dist/commands/upgrade.d.ts +10 -0
  54. package/ccw/dist/commands/upgrade.d.ts.map +1 -0
  55. package/ccw/dist/commands/upgrade.js +288 -0
  56. package/ccw/dist/commands/upgrade.js.map +1 -0
  57. package/ccw/dist/commands/view.d.ts +14 -0
  58. package/ccw/dist/commands/view.d.ts.map +1 -0
  59. package/ccw/dist/commands/view.js +100 -0
  60. package/ccw/dist/commands/view.js.map +1 -0
  61. package/ccw/dist/config/storage-paths.d.ts +184 -0
  62. package/ccw/dist/config/storage-paths.d.ts.map +1 -0
  63. package/ccw/dist/config/storage-paths.js +536 -0
  64. package/ccw/dist/config/storage-paths.js.map +1 -0
  65. package/ccw/dist/core/cache-manager.d.ts +80 -0
  66. package/ccw/dist/core/cache-manager.d.ts.map +1 -0
  67. package/ccw/dist/core/cache-manager.js +260 -0
  68. package/ccw/dist/core/cache-manager.js.map +1 -0
  69. package/ccw/dist/core/claude-freshness.d.ts +53 -0
  70. package/ccw/dist/core/claude-freshness.d.ts.map +1 -0
  71. package/ccw/dist/core/claude-freshness.js +232 -0
  72. package/ccw/dist/core/claude-freshness.js.map +1 -0
  73. package/ccw/dist/core/core-memory-store.d.ts +320 -0
  74. package/ccw/dist/core/core-memory-store.d.ts.map +1 -0
  75. package/ccw/dist/core/core-memory-store.js +1177 -0
  76. package/ccw/dist/core/core-memory-store.js.map +1 -0
  77. package/ccw/dist/core/dashboard-generator-patch.d.ts +2 -0
  78. package/ccw/dist/core/dashboard-generator-patch.d.ts.map +1 -0
  79. package/ccw/dist/core/dashboard-generator-patch.js +48 -0
  80. package/ccw/dist/core/dashboard-generator-patch.js.map +1 -0
  81. package/ccw/dist/core/dashboard-generator.d.ts +8 -0
  82. package/ccw/dist/core/dashboard-generator.d.ts.map +1 -0
  83. package/ccw/dist/core/dashboard-generator.js +695 -0
  84. package/ccw/dist/core/dashboard-generator.js.map +1 -0
  85. package/ccw/dist/core/data-aggregator.d.ts +145 -0
  86. package/ccw/dist/core/data-aggregator.d.ts.map +1 -0
  87. package/ccw/dist/core/data-aggregator.js +416 -0
  88. package/ccw/dist/core/data-aggregator.js.map +1 -0
  89. package/ccw/dist/core/history-importer.d.ts +102 -0
  90. package/ccw/dist/core/history-importer.d.ts.map +1 -0
  91. package/ccw/dist/core/history-importer.js +493 -0
  92. package/ccw/dist/core/history-importer.js.map +1 -0
  93. package/ccw/dist/core/lite-scanner-complete.d.ts +81 -0
  94. package/ccw/dist/core/lite-scanner-complete.d.ts.map +1 -0
  95. package/ccw/dist/core/lite-scanner-complete.js +368 -0
  96. package/ccw/dist/core/lite-scanner-complete.js.map +1 -0
  97. package/ccw/dist/core/lite-scanner.d.ts +81 -0
  98. package/ccw/dist/core/lite-scanner.d.ts.map +1 -0
  99. package/ccw/dist/core/lite-scanner.js +368 -0
  100. package/ccw/dist/core/lite-scanner.js.map +1 -0
  101. package/ccw/dist/core/manifest.d.ts +88 -0
  102. package/ccw/dist/core/manifest.d.ts.map +1 -0
  103. package/ccw/dist/core/manifest.js +214 -0
  104. package/ccw/dist/core/manifest.js.map +1 -0
  105. package/ccw/dist/core/memory-embedder-bridge.d.ts +83 -0
  106. package/ccw/dist/core/memory-embedder-bridge.d.ts.map +1 -0
  107. package/ccw/dist/core/memory-embedder-bridge.js +181 -0
  108. package/ccw/dist/core/memory-embedder-bridge.js.map +1 -0
  109. package/ccw/dist/core/memory-store.d.ts +249 -0
  110. package/ccw/dist/core/memory-store.d.ts.map +1 -0
  111. package/ccw/dist/core/memory-store.js +781 -0
  112. package/ccw/dist/core/memory-store.js.map +1 -0
  113. package/ccw/dist/core/routes/ccw-routes.d.ts +20 -0
  114. package/ccw/dist/core/routes/ccw-routes.d.ts.map +1 -0
  115. package/ccw/dist/core/routes/ccw-routes.js +70 -0
  116. package/ccw/dist/core/routes/ccw-routes.js.map +1 -0
  117. package/ccw/dist/core/routes/claude-routes.d.ts +19 -0
  118. package/ccw/dist/core/routes/claude-routes.d.ts.map +1 -0
  119. package/ccw/dist/core/routes/claude-routes.js +1017 -0
  120. package/ccw/dist/core/routes/claude-routes.js.map +1 -0
  121. package/ccw/dist/core/routes/cli-routes.d.ts +20 -0
  122. package/ccw/dist/core/routes/cli-routes.d.ts.map +1 -0
  123. package/ccw/dist/core/routes/cli-routes.js +468 -0
  124. package/ccw/dist/core/routes/cli-routes.js.map +1 -0
  125. package/ccw/dist/core/routes/codexlens-routes.d.ts +20 -0
  126. package/ccw/dist/core/routes/codexlens-routes.d.ts.map +1 -0
  127. package/ccw/dist/core/routes/codexlens-routes.js +754 -0
  128. package/ccw/dist/core/routes/codexlens-routes.js.map +1 -0
  129. package/ccw/dist/core/routes/core-memory-routes.d.ts +21 -0
  130. package/ccw/dist/core/routes/core-memory-routes.d.ts.map +1 -0
  131. package/ccw/dist/core/routes/core-memory-routes.js +520 -0
  132. package/ccw/dist/core/routes/core-memory-routes.js.map +1 -0
  133. package/ccw/dist/core/routes/files-routes.d.ts +20 -0
  134. package/ccw/dist/core/routes/files-routes.d.ts.map +1 -0
  135. package/ccw/dist/core/routes/files-routes.js +374 -0
  136. package/ccw/dist/core/routes/files-routes.js.map +1 -0
  137. package/ccw/dist/core/routes/graph-routes.d.ts +20 -0
  138. package/ccw/dist/core/routes/graph-routes.d.ts.map +1 -0
  139. package/ccw/dist/core/routes/graph-routes.js +517 -0
  140. package/ccw/dist/core/routes/graph-routes.js.map +1 -0
  141. package/ccw/dist/core/routes/help-routes.d.ts +20 -0
  142. package/ccw/dist/core/routes/help-routes.d.ts.map +1 -0
  143. package/ccw/dist/core/routes/help-routes.js +250 -0
  144. package/ccw/dist/core/routes/help-routes.js.map +1 -0
  145. package/ccw/dist/core/routes/hooks-routes.d.ts +21 -0
  146. package/ccw/dist/core/routes/hooks-routes.d.ts.map +1 -0
  147. package/ccw/dist/core/routes/hooks-routes.js +346 -0
  148. package/ccw/dist/core/routes/hooks-routes.js.map +1 -0
  149. package/ccw/dist/core/routes/mcp-routes.d.ts +20 -0
  150. package/ccw/dist/core/routes/mcp-routes.d.ts.map +1 -0
  151. package/ccw/dist/core/routes/mcp-routes.js +1129 -0
  152. package/ccw/dist/core/routes/mcp-routes.js.map +1 -0
  153. package/ccw/dist/core/routes/mcp-templates-db.d.ts +54 -0
  154. package/ccw/dist/core/routes/mcp-templates-db.d.ts.map +1 -0
  155. package/ccw/dist/core/routes/mcp-templates-db.js +226 -0
  156. package/ccw/dist/core/routes/mcp-templates-db.js.map +1 -0
  157. package/ccw/dist/core/routes/memory-routes.d.ts +21 -0
  158. package/ccw/dist/core/routes/memory-routes.d.ts.map +1 -0
  159. package/ccw/dist/core/routes/memory-routes.js +1095 -0
  160. package/ccw/dist/core/routes/memory-routes.js.map +1 -0
  161. package/ccw/dist/core/routes/rules-routes.d.ts +20 -0
  162. package/ccw/dist/core/routes/rules-routes.d.ts.map +1 -0
  163. package/ccw/dist/core/routes/rules-routes.js +442 -0
  164. package/ccw/dist/core/routes/rules-routes.js.map +1 -0
  165. package/ccw/dist/core/routes/session-routes.d.ts +20 -0
  166. package/ccw/dist/core/routes/session-routes.d.ts.map +1 -0
  167. package/ccw/dist/core/routes/session-routes.js +423 -0
  168. package/ccw/dist/core/routes/session-routes.js.map +1 -0
  169. package/ccw/dist/core/routes/skills-routes.d.ts +20 -0
  170. package/ccw/dist/core/routes/skills-routes.d.ts.map +1 -0
  171. package/ccw/dist/core/routes/skills-routes.js +533 -0
  172. package/ccw/dist/core/routes/skills-routes.js.map +1 -0
  173. package/ccw/dist/core/routes/status-routes.d.ts +20 -0
  174. package/ccw/dist/core/routes/status-routes.d.ts.map +1 -0
  175. package/ccw/dist/core/routes/status-routes.js +38 -0
  176. package/ccw/dist/core/routes/status-routes.js.map +1 -0
  177. package/ccw/dist/core/routes/system-routes.d.ts +22 -0
  178. package/ccw/dist/core/routes/system-routes.d.ts.map +1 -0
  179. package/ccw/dist/core/routes/system-routes.js +354 -0
  180. package/ccw/dist/core/routes/system-routes.js.map +1 -0
  181. package/ccw/dist/core/server.d.ts +17 -0
  182. package/ccw/dist/core/server.d.ts.map +1 -0
  183. package/ccw/dist/core/server.js +386 -0
  184. package/ccw/dist/core/server.js.map +1 -0
  185. package/ccw/dist/core/session-clustering-service.d.ts +153 -0
  186. package/ccw/dist/core/session-clustering-service.d.ts.map +1 -0
  187. package/ccw/dist/core/session-clustering-service.js +1065 -0
  188. package/ccw/dist/core/session-clustering-service.js.map +1 -0
  189. package/ccw/dist/core/session-scanner.d.ts +32 -0
  190. package/ccw/dist/core/session-scanner.d.ts.map +1 -0
  191. package/ccw/dist/core/session-scanner.js +253 -0
  192. package/ccw/dist/core/session-scanner.js.map +1 -0
  193. package/ccw/dist/core/websocket.d.ts +23 -0
  194. package/ccw/dist/core/websocket.d.ts.map +1 -0
  195. package/ccw/dist/core/websocket.js +168 -0
  196. package/ccw/dist/core/websocket.js.map +1 -0
  197. package/ccw/dist/index.d.ts +10 -0
  198. package/ccw/dist/index.d.ts.map +1 -0
  199. package/ccw/dist/index.js +10 -0
  200. package/ccw/dist/index.js.map +1 -0
  201. package/ccw/dist/mcp-server/index.d.ts +7 -0
  202. package/ccw/dist/mcp-server/index.d.ts.map +1 -0
  203. package/ccw/dist/mcp-server/index.js +157 -0
  204. package/ccw/dist/mcp-server/index.js.map +1 -0
  205. package/ccw/dist/tools/classify-folders.d.ts +26 -0
  206. package/ccw/dist/tools/classify-folders.d.ts.map +1 -0
  207. package/ccw/dist/tools/classify-folders.js +201 -0
  208. package/ccw/dist/tools/classify-folders.js.map +1 -0
  209. package/ccw/dist/tools/cli-config-manager.d.ts +62 -0
  210. package/ccw/dist/tools/cli-config-manager.d.ts.map +1 -0
  211. package/ccw/dist/tools/cli-config-manager.js +221 -0
  212. package/ccw/dist/tools/cli-config-manager.js.map +1 -0
  213. package/ccw/dist/tools/cli-executor.d.ts +373 -0
  214. package/ccw/dist/tools/cli-executor.d.ts.map +1 -0
  215. package/ccw/dist/tools/cli-executor.js +1625 -0
  216. package/ccw/dist/tools/cli-executor.js.map +1 -0
  217. package/ccw/dist/tools/cli-history-store.d.ts +330 -0
  218. package/ccw/dist/tools/cli-history-store.d.ts.map +1 -0
  219. package/ccw/dist/tools/cli-history-store.js +916 -0
  220. package/ccw/dist/tools/cli-history-store.js.map +1 -0
  221. package/ccw/dist/tools/codex-lens.d.ts +118 -0
  222. package/ccw/dist/tools/codex-lens.d.ts.map +1 -0
  223. package/ccw/dist/tools/codex-lens.js +962 -0
  224. package/ccw/dist/tools/codex-lens.js.map +1 -0
  225. package/ccw/dist/tools/convert-tokens-to-css.d.ts +14 -0
  226. package/ccw/dist/tools/convert-tokens-to-css.d.ts.map +1 -0
  227. package/ccw/dist/tools/convert-tokens-to-css.js +244 -0
  228. package/ccw/dist/tools/convert-tokens-to-css.js.map +1 -0
  229. package/ccw/dist/tools/core-memory.d.ts +66 -0
  230. package/ccw/dist/tools/core-memory.d.ts.map +1 -0
  231. package/ccw/dist/tools/core-memory.js +324 -0
  232. package/ccw/dist/tools/core-memory.js.map +1 -0
  233. package/ccw/dist/tools/detect-changed-modules.d.ts +24 -0
  234. package/ccw/dist/tools/detect-changed-modules.d.ts.map +1 -0
  235. package/ccw/dist/tools/detect-changed-modules.js +277 -0
  236. package/ccw/dist/tools/detect-changed-modules.js.map +1 -0
  237. package/ccw/dist/tools/discover-design-files.d.ts +36 -0
  238. package/ccw/dist/tools/discover-design-files.d.ts.map +1 -0
  239. package/ccw/dist/tools/discover-design-files.js +147 -0
  240. package/ccw/dist/tools/discover-design-files.js.map +1 -0
  241. package/ccw/dist/tools/edit-file.d.ts +28 -0
  242. package/ccw/dist/tools/edit-file.d.ts.map +1 -0
  243. package/ccw/dist/tools/edit-file.js +479 -0
  244. package/ccw/dist/tools/edit-file.js.map +1 -0
  245. package/ccw/dist/tools/generate-module-docs.d.ts +22 -0
  246. package/ccw/dist/tools/generate-module-docs.d.ts.map +1 -0
  247. package/ccw/dist/tools/generate-module-docs.js +379 -0
  248. package/ccw/dist/tools/generate-module-docs.js.map +1 -0
  249. package/ccw/dist/tools/get-modules-by-depth.d.ts +15 -0
  250. package/ccw/dist/tools/get-modules-by-depth.d.ts.map +1 -0
  251. package/ccw/dist/tools/get-modules-by-depth.js +296 -0
  252. package/ccw/dist/tools/get-modules-by-depth.js.map +1 -0
  253. package/ccw/dist/tools/index.d.ts +55 -0
  254. package/ccw/dist/tools/index.d.ts.map +1 -0
  255. package/ccw/dist/tools/index.js +304 -0
  256. package/ccw/dist/tools/index.js.map +1 -0
  257. package/ccw/dist/tools/native-session-discovery.d.ts +97 -0
  258. package/ccw/dist/tools/native-session-discovery.d.ts.map +1 -0
  259. package/ccw/dist/tools/native-session-discovery.js +700 -0
  260. package/ccw/dist/tools/native-session-discovery.js.map +1 -0
  261. package/ccw/dist/tools/notifier.d.ts +50 -0
  262. package/ccw/dist/tools/notifier.d.ts.map +1 -0
  263. package/ccw/dist/tools/notifier.js +90 -0
  264. package/ccw/dist/tools/notifier.js.map +1 -0
  265. package/ccw/dist/tools/read-file.d.ts +32 -0
  266. package/ccw/dist/tools/read-file.d.ts.map +1 -0
  267. package/ccw/dist/tools/read-file.js +329 -0
  268. package/ccw/dist/tools/read-file.js.map +1 -0
  269. package/ccw/dist/tools/resume-strategy.d.ts +48 -0
  270. package/ccw/dist/tools/resume-strategy.d.ts.map +1 -0
  271. package/ccw/dist/tools/resume-strategy.js +248 -0
  272. package/ccw/dist/tools/resume-strategy.js.map +1 -0
  273. package/ccw/dist/tools/session-content-parser.d.ts +58 -0
  274. package/ccw/dist/tools/session-content-parser.d.ts.map +1 -0
  275. package/ccw/dist/tools/session-content-parser.js +420 -0
  276. package/ccw/dist/tools/session-content-parser.js.map +1 -0
  277. package/ccw/dist/tools/session-manager.d.ts +9 -0
  278. package/ccw/dist/tools/session-manager.d.ts.map +1 -0
  279. package/ccw/dist/tools/session-manager.js +834 -0
  280. package/ccw/dist/tools/session-manager.js.map +1 -0
  281. package/ccw/dist/tools/smart-context.d.ts +35 -0
  282. package/ccw/dist/tools/smart-context.d.ts.map +1 -0
  283. package/ccw/dist/tools/smart-context.js +182 -0
  284. package/ccw/dist/tools/smart-context.js.map +1 -0
  285. package/ccw/dist/tools/smart-search.d.ts +105 -0
  286. package/ccw/dist/tools/smart-search.d.ts.map +1 -0
  287. package/ccw/dist/tools/smart-search.js +1753 -0
  288. package/ccw/dist/tools/smart-search.js.map +1 -0
  289. package/ccw/dist/tools/storage-manager.d.ts +114 -0
  290. package/ccw/dist/tools/storage-manager.d.ts.map +1 -0
  291. package/ccw/dist/tools/storage-manager.js +392 -0
  292. package/ccw/dist/tools/storage-manager.js.map +1 -0
  293. package/ccw/dist/tools/ui-generate-preview.d.ts +39 -0
  294. package/ccw/dist/tools/ui-generate-preview.d.ts.map +1 -0
  295. package/ccw/dist/tools/ui-generate-preview.js +300 -0
  296. package/ccw/dist/tools/ui-generate-preview.js.map +1 -0
  297. package/ccw/dist/tools/ui-instantiate-prototypes.d.ts +75 -0
  298. package/ccw/dist/tools/ui-instantiate-prototypes.d.ts.map +1 -0
  299. package/ccw/dist/tools/ui-instantiate-prototypes.js +256 -0
  300. package/ccw/dist/tools/ui-instantiate-prototypes.js.map +1 -0
  301. package/ccw/dist/tools/update-module-claude.d.ts +80 -0
  302. package/ccw/dist/tools/update-module-claude.d.ts.map +1 -0
  303. package/ccw/dist/tools/update-module-claude.js +351 -0
  304. package/ccw/dist/tools/update-module-claude.js.map +1 -0
  305. package/ccw/dist/tools/write-file.d.ts +19 -0
  306. package/ccw/dist/tools/write-file.d.ts.map +1 -0
  307. package/ccw/dist/tools/write-file.js +193 -0
  308. package/ccw/dist/tools/write-file.js.map +1 -0
  309. package/ccw/dist/types/config.d.ts +11 -0
  310. package/ccw/dist/types/config.d.ts.map +1 -0
  311. package/ccw/dist/types/config.js +2 -0
  312. package/ccw/dist/types/config.js.map +1 -0
  313. package/ccw/dist/types/index.d.ts +4 -0
  314. package/ccw/dist/types/index.d.ts.map +1 -0
  315. package/ccw/dist/types/index.js +4 -0
  316. package/ccw/dist/types/index.js.map +1 -0
  317. package/ccw/dist/types/session.d.ts +20 -0
  318. package/ccw/dist/types/session.d.ts.map +1 -0
  319. package/ccw/dist/types/session.js +2 -0
  320. package/ccw/dist/types/session.js.map +1 -0
  321. package/ccw/dist/types/tool.d.ts +36 -0
  322. package/ccw/dist/types/tool.d.ts.map +1 -0
  323. package/ccw/dist/types/tool.js +11 -0
  324. package/ccw/dist/types/tool.js.map +1 -0
  325. package/ccw/dist/utils/browser-launcher.d.ts +13 -0
  326. package/ccw/dist/utils/browser-launcher.d.ts.map +1 -0
  327. package/ccw/dist/utils/browser-launcher.js +60 -0
  328. package/ccw/dist/utils/browser-launcher.js.map +1 -0
  329. package/ccw/dist/utils/file-utils.d.ts +25 -0
  330. package/ccw/dist/utils/file-utils.d.ts.map +1 -0
  331. package/ccw/dist/utils/file-utils.js +48 -0
  332. package/ccw/dist/utils/file-utils.js.map +1 -0
  333. package/ccw/dist/utils/path-resolver.d.ts +80 -0
  334. package/ccw/dist/utils/path-resolver.d.ts.map +1 -0
  335. package/ccw/dist/utils/path-resolver.js +260 -0
  336. package/ccw/dist/utils/path-resolver.js.map +1 -0
  337. package/ccw/dist/utils/path-validator.d.ts +49 -0
  338. package/ccw/dist/utils/path-validator.d.ts.map +1 -0
  339. package/ccw/dist/utils/path-validator.js +123 -0
  340. package/ccw/dist/utils/path-validator.js.map +1 -0
  341. package/ccw/dist/utils/ui.d.ts +62 -0
  342. package/ccw/dist/utils/ui.d.ts.map +1 -0
  343. package/ccw/dist/utils/ui.js +129 -0
  344. package/ccw/dist/utils/ui.js.map +1 -0
  345. package/ccw/package.json +1 -1
  346. package/package.json +1 -1
@@ -0,0 +1,781 @@
1
+ /**
2
+ * Memory Store - SQLite Storage Backend
3
+ * Provides persistent storage for memory module with entity tracking, associations, and conversation history
4
+ */
5
+ import Database from 'better-sqlite3';
6
+ import { StoragePaths, ensureStorageDir, getProjectId } from '../config/storage-paths.js';
7
+ /**
8
+ * Memory Store using SQLite
9
+ */
10
+ export class MemoryStore {
11
+ db;
12
+ dbPath;
13
+ projectPath;
14
+ constructor(projectPath) {
15
+ this.projectPath = projectPath;
16
+ // Use centralized storage path
17
+ const paths = StoragePaths.project(projectPath);
18
+ const memoryDir = paths.memory;
19
+ ensureStorageDir(memoryDir);
20
+ this.dbPath = paths.memoryDb;
21
+ this.db = new Database(this.dbPath);
22
+ this.db.pragma('journal_mode = WAL');
23
+ this.db.pragma('synchronous = NORMAL');
24
+ this.initDatabase();
25
+ this.migrateSchema();
26
+ }
27
+ /**
28
+ * Initialize database schema
29
+ */
30
+ initDatabase() {
31
+ this.db.exec(`
32
+ -- Entity table
33
+ CREATE TABLE IF NOT EXISTS entities (
34
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
35
+ type TEXT NOT NULL,
36
+ value TEXT NOT NULL,
37
+ normalized_value TEXT NOT NULL,
38
+ first_seen_at TEXT NOT NULL,
39
+ last_seen_at TEXT NOT NULL,
40
+ metadata TEXT,
41
+ UNIQUE(type, normalized_value)
42
+ );
43
+
44
+ -- Access logs table
45
+ CREATE TABLE IF NOT EXISTS access_logs (
46
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
47
+ entity_id INTEGER NOT NULL,
48
+ action TEXT NOT NULL,
49
+ session_id TEXT,
50
+ timestamp TEXT NOT NULL,
51
+ context_summary TEXT,
52
+ FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
53
+ );
54
+
55
+ -- Entity statistics table
56
+ CREATE TABLE IF NOT EXISTS entity_stats (
57
+ entity_id INTEGER PRIMARY KEY,
58
+ read_count INTEGER DEFAULT 0,
59
+ write_count INTEGER DEFAULT 0,
60
+ mention_count INTEGER DEFAULT 0,
61
+ heat_score REAL DEFAULT 0,
62
+ FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
63
+ );
64
+
65
+ -- Associations table
66
+ CREATE TABLE IF NOT EXISTS associations (
67
+ source_id INTEGER NOT NULL,
68
+ target_id INTEGER NOT NULL,
69
+ weight INTEGER DEFAULT 0,
70
+ last_interaction_at TEXT,
71
+ PRIMARY KEY (source_id, target_id),
72
+ FOREIGN KEY (source_id) REFERENCES entities(id) ON DELETE CASCADE,
73
+ FOREIGN KEY (target_id) REFERENCES entities(id) ON DELETE CASCADE
74
+ );
75
+
76
+ -- Prompt history table
77
+ CREATE TABLE IF NOT EXISTS prompt_history (
78
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
79
+ session_id TEXT NOT NULL,
80
+ project_path TEXT,
81
+ prompt_text TEXT,
82
+ context_summary TEXT,
83
+ timestamp INTEGER,
84
+ hash TEXT UNIQUE,
85
+ quality_score INTEGER,
86
+ intent_label TEXT
87
+ );
88
+
89
+ -- Prompt patterns table
90
+ CREATE TABLE IF NOT EXISTS prompt_patterns (
91
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
92
+ pattern_type TEXT,
93
+ frequency INTEGER,
94
+ example_ids TEXT,
95
+ last_detected INTEGER
96
+ );
97
+
98
+ -- Conversations table
99
+ CREATE TABLE IF NOT EXISTS conversations (
100
+ id TEXT PRIMARY KEY,
101
+ source TEXT DEFAULT 'ccw',
102
+ external_id TEXT,
103
+ project_name TEXT,
104
+ git_branch TEXT,
105
+ created_at TEXT,
106
+ updated_at TEXT,
107
+ quality_score INTEGER,
108
+ turn_count INTEGER,
109
+ prompt_preview TEXT
110
+ );
111
+
112
+ -- Messages table
113
+ CREATE TABLE IF NOT EXISTS messages (
114
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
115
+ conversation_id TEXT NOT NULL,
116
+ role TEXT NOT NULL,
117
+ content_text TEXT,
118
+ content_json TEXT,
119
+ timestamp TEXT NOT NULL,
120
+ token_count INTEGER,
121
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE CASCADE
122
+ );
123
+
124
+ -- Tool calls table
125
+ CREATE TABLE IF NOT EXISTS tool_calls (
126
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
127
+ message_id INTEGER NOT NULL,
128
+ tool_name TEXT NOT NULL,
129
+ tool_args TEXT,
130
+ tool_output TEXT,
131
+ status TEXT,
132
+ duration_ms INTEGER,
133
+ FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE CASCADE
134
+ );
135
+
136
+ -- Indexes for efficient queries
137
+ CREATE INDEX IF NOT EXISTS idx_entities_type ON entities(type);
138
+ CREATE INDEX IF NOT EXISTS idx_entities_normalized ON entities(normalized_value);
139
+ CREATE INDEX IF NOT EXISTS idx_entities_last_seen ON entities(last_seen_at DESC);
140
+ CREATE INDEX IF NOT EXISTS idx_access_logs_entity ON access_logs(entity_id);
141
+ CREATE INDEX IF NOT EXISTS idx_access_logs_timestamp ON access_logs(timestamp DESC);
142
+ CREATE INDEX IF NOT EXISTS idx_access_logs_session ON access_logs(session_id);
143
+ CREATE INDEX IF NOT EXISTS idx_entity_stats_heat ON entity_stats(heat_score DESC);
144
+ CREATE INDEX IF NOT EXISTS idx_associations_source ON associations(source_id);
145
+ CREATE INDEX IF NOT EXISTS idx_associations_target ON associations(target_id);
146
+ CREATE INDEX IF NOT EXISTS idx_prompt_history_session ON prompt_history(session_id);
147
+ CREATE INDEX IF NOT EXISTS idx_prompt_history_timestamp ON prompt_history(timestamp DESC);
148
+ CREATE INDEX IF NOT EXISTS idx_conversations_created ON conversations(created_at DESC);
149
+ CREATE INDEX IF NOT EXISTS idx_conversations_updated ON conversations(updated_at DESC);
150
+ CREATE INDEX IF NOT EXISTS idx_messages_conversation ON messages(conversation_id);
151
+ CREATE INDEX IF NOT EXISTS idx_tool_calls_message ON tool_calls(message_id);
152
+
153
+ -- Full-text search for prompt history
154
+ CREATE VIRTUAL TABLE IF NOT EXISTS prompt_history_fts USING fts5(
155
+ prompt_text,
156
+ context_summary,
157
+ content='prompt_history',
158
+ content_rowid='id'
159
+ );
160
+
161
+ -- Triggers to keep FTS index updated
162
+ CREATE TRIGGER IF NOT EXISTS prompt_history_ai AFTER INSERT ON prompt_history BEGIN
163
+ INSERT INTO prompt_history_fts(rowid, prompt_text, context_summary)
164
+ VALUES (new.id, new.prompt_text, new.context_summary);
165
+ END;
166
+
167
+ CREATE TRIGGER IF NOT EXISTS prompt_history_ad AFTER DELETE ON prompt_history BEGIN
168
+ INSERT INTO prompt_history_fts(prompt_history_fts, rowid, prompt_text, context_summary)
169
+ VALUES('delete', old.id, old.prompt_text, old.context_summary);
170
+ END;
171
+
172
+ CREATE TRIGGER IF NOT EXISTS prompt_history_au AFTER UPDATE ON prompt_history BEGIN
173
+ INSERT INTO prompt_history_fts(prompt_history_fts, rowid, prompt_text, context_summary)
174
+ VALUES('delete', old.id, old.prompt_text, old.context_summary);
175
+ INSERT INTO prompt_history_fts(rowid, prompt_text, context_summary)
176
+ VALUES (new.id, new.prompt_text, new.context_summary);
177
+ END;
178
+ `);
179
+ }
180
+ /**
181
+ * Migrate schema for existing databases
182
+ */
183
+ migrateSchema() {
184
+ try {
185
+ // Check if hierarchical storage columns exist in conversations table
186
+ const tableInfo = this.db.prepare('PRAGMA table_info(conversations)').all();
187
+ const hasProjectRoot = tableInfo.some(col => col.name === 'project_root');
188
+ const hasRelativePath = tableInfo.some(col => col.name === 'relative_path');
189
+ // Add hierarchical storage support columns
190
+ if (!hasProjectRoot) {
191
+ console.log('[Memory Store] Migrating database: adding project_root column for hierarchical storage...');
192
+ this.db.exec(`
193
+ ALTER TABLE conversations ADD COLUMN project_root TEXT;
194
+ `);
195
+ try {
196
+ this.db.exec(`CREATE INDEX IF NOT EXISTS idx_conversations_project_root ON conversations(project_root);`);
197
+ }
198
+ catch (indexErr) {
199
+ console.warn('[Memory Store] Project root index creation warning:', indexErr.message);
200
+ }
201
+ console.log('[Memory Store] Migration complete: project_root column added');
202
+ }
203
+ if (!hasRelativePath) {
204
+ console.log('[Memory Store] Migrating database: adding relative_path column for hierarchical storage...');
205
+ this.db.exec(`
206
+ ALTER TABLE conversations ADD COLUMN relative_path TEXT;
207
+ `);
208
+ console.log('[Memory Store] Migration complete: relative_path column added');
209
+ }
210
+ // Add missing timestamp index for messages table (for time-based queries)
211
+ try {
212
+ const indexExists = this.db.prepare(`
213
+ SELECT name FROM sqlite_master
214
+ WHERE type='index' AND name='idx_messages_timestamp'
215
+ `).get();
216
+ if (!indexExists) {
217
+ console.log('[Memory Store] Adding missing timestamp index to messages table...');
218
+ this.db.exec(`CREATE INDEX IF NOT EXISTS idx_messages_timestamp ON messages(timestamp DESC);`);
219
+ console.log('[Memory Store] Migration complete: messages timestamp index added');
220
+ }
221
+ }
222
+ catch (indexErr) {
223
+ console.warn('[Memory Store] Messages timestamp index creation warning:', indexErr.message);
224
+ }
225
+ }
226
+ catch (err) {
227
+ console.error('[Memory Store] Migration error:', err.message);
228
+ // Don't throw - allow the store to continue working with existing schema
229
+ }
230
+ }
231
+ /**
232
+ * Upsert an entity
233
+ */
234
+ upsertEntity(entity) {
235
+ const stmt = this.db.prepare(`
236
+ INSERT INTO entities (type, value, normalized_value, first_seen_at, last_seen_at, metadata)
237
+ VALUES (@type, @value, @normalized_value, @first_seen_at, @last_seen_at, @metadata)
238
+ ON CONFLICT(type, normalized_value) DO UPDATE SET
239
+ value = @value,
240
+ last_seen_at = @last_seen_at,
241
+ metadata = @metadata
242
+ RETURNING id
243
+ `);
244
+ const result = stmt.get({
245
+ type: entity.type,
246
+ value: entity.value,
247
+ normalized_value: entity.normalized_value,
248
+ first_seen_at: entity.first_seen_at,
249
+ last_seen_at: entity.last_seen_at,
250
+ metadata: entity.metadata || null
251
+ });
252
+ return result.id;
253
+ }
254
+ /**
255
+ * Get entity by type and normalized value
256
+ */
257
+ getEntity(type, normalizedValue) {
258
+ const stmt = this.db.prepare(`
259
+ SELECT * FROM entities WHERE type = ? AND normalized_value = ?
260
+ `);
261
+ return stmt.get(type, normalizedValue);
262
+ }
263
+ /**
264
+ * Get entity by ID
265
+ */
266
+ getEntityById(id) {
267
+ const stmt = this.db.prepare(`SELECT * FROM entities WHERE id = ?`);
268
+ return stmt.get(id);
269
+ }
270
+ /**
271
+ * Get hot entities (by heat score)
272
+ */
273
+ getHotEntities(limit = 20) {
274
+ const stmt = this.db.prepare(`
275
+ SELECT e.*, s.read_count, s.write_count, s.mention_count, s.heat_score
276
+ FROM entities e
277
+ INNER JOIN entity_stats s ON e.id = s.entity_id
278
+ ORDER BY s.heat_score DESC
279
+ LIMIT ?
280
+ `);
281
+ const rows = stmt.all(limit);
282
+ return rows.map(row => ({
283
+ id: row.id,
284
+ type: row.type,
285
+ value: row.value,
286
+ normalized_value: row.normalized_value,
287
+ first_seen_at: row.first_seen_at,
288
+ last_seen_at: row.last_seen_at,
289
+ metadata: row.metadata,
290
+ stats: {
291
+ entity_id: row.id,
292
+ read_count: row.read_count,
293
+ write_count: row.write_count,
294
+ mention_count: row.mention_count,
295
+ heat_score: row.heat_score
296
+ }
297
+ }));
298
+ }
299
+ /**
300
+ * Log entity access
301
+ */
302
+ logAccess(log) {
303
+ const stmt = this.db.prepare(`
304
+ INSERT INTO access_logs (entity_id, action, session_id, timestamp, context_summary)
305
+ VALUES (@entity_id, @action, @session_id, @timestamp, @context_summary)
306
+ `);
307
+ stmt.run({
308
+ entity_id: log.entity_id,
309
+ action: log.action,
310
+ session_id: log.session_id || null,
311
+ timestamp: log.timestamp,
312
+ context_summary: log.context_summary || null
313
+ });
314
+ }
315
+ /**
316
+ * Get recent access logs for an entity
317
+ */
318
+ getRecentAccess(entityId, limit = 50) {
319
+ const stmt = this.db.prepare(`
320
+ SELECT * FROM access_logs
321
+ WHERE entity_id = ?
322
+ ORDER BY timestamp DESC
323
+ LIMIT ?
324
+ `);
325
+ return stmt.all(entityId, limit);
326
+ }
327
+ /**
328
+ * Update entity statistics
329
+ */
330
+ updateStats(entityId, action) {
331
+ const upsertStmt = this.db.prepare(`
332
+ INSERT INTO entity_stats (entity_id, read_count, write_count, mention_count, heat_score)
333
+ VALUES (@entity_id, 0, 0, 0, 0)
334
+ ON CONFLICT(entity_id) DO NOTHING
335
+ `);
336
+ upsertStmt.run({ entity_id: entityId });
337
+ const field = `${action}_count`;
338
+ const updateStmt = this.db.prepare(`
339
+ UPDATE entity_stats
340
+ SET ${field} = ${field} + 1
341
+ WHERE entity_id = ?
342
+ `);
343
+ updateStmt.run(entityId);
344
+ }
345
+ /**
346
+ * Get entity statistics
347
+ */
348
+ getStats(entityId) {
349
+ const stmt = this.db.prepare(`SELECT * FROM entity_stats WHERE entity_id = ?`);
350
+ return stmt.get(entityId);
351
+ }
352
+ /**
353
+ * Calculate and update heat score for an entity
354
+ */
355
+ calculateHeatScore(entityId) {
356
+ const stats = this.getStats(entityId);
357
+ if (!stats)
358
+ return 0;
359
+ const now = Date.now();
360
+ const logs = this.getRecentAccess(entityId, 100);
361
+ let recencyScore = 0;
362
+ for (const log of logs) {
363
+ const ageMs = now - new Date(log.timestamp).getTime();
364
+ const ageDays = ageMs / (1000 * 60 * 60 * 24);
365
+ const decay = Math.exp(-ageDays / 7); // 7-day half-life
366
+ recencyScore += decay;
367
+ }
368
+ const heatScore = (stats.read_count * 1 +
369
+ stats.write_count * 3 +
370
+ stats.mention_count * 2 +
371
+ recencyScore * 5);
372
+ const updateStmt = this.db.prepare(`
373
+ UPDATE entity_stats SET heat_score = ? WHERE entity_id = ?
374
+ `);
375
+ updateStmt.run(heatScore, entityId);
376
+ return heatScore;
377
+ }
378
+ /**
379
+ * Record association between entities
380
+ */
381
+ recordAssociation(sourceId, targetId, timestamp) {
382
+ const stmt = this.db.prepare(`
383
+ INSERT INTO associations (source_id, target_id, weight, last_interaction_at)
384
+ VALUES (@source_id, @target_id, 1, @last_interaction_at)
385
+ ON CONFLICT(source_id, target_id) DO UPDATE SET
386
+ weight = weight + 1,
387
+ last_interaction_at = @last_interaction_at
388
+ `);
389
+ stmt.run({
390
+ source_id: sourceId,
391
+ target_id: targetId,
392
+ last_interaction_at: timestamp || new Date().toISOString()
393
+ });
394
+ }
395
+ /**
396
+ * Get associations for an entity
397
+ */
398
+ getAssociations(entityId, limit = 20) {
399
+ const stmt = this.db.prepare(`
400
+ SELECT e.*, a.weight, a.last_interaction_at
401
+ FROM associations a
402
+ INNER JOIN entities e ON a.target_id = e.id
403
+ WHERE a.source_id = ?
404
+ ORDER BY a.weight DESC
405
+ LIMIT ?
406
+ `);
407
+ const rows = stmt.all(entityId, limit);
408
+ return rows.map(row => ({
409
+ target: {
410
+ id: row.id,
411
+ type: row.type,
412
+ value: row.value,
413
+ normalized_value: row.normalized_value,
414
+ first_seen_at: row.first_seen_at,
415
+ last_seen_at: row.last_seen_at,
416
+ metadata: row.metadata
417
+ },
418
+ weight: row.weight,
419
+ last_interaction_at: row.last_interaction_at
420
+ }));
421
+ }
422
+ /**
423
+ * Save prompt to history
424
+ */
425
+ savePrompt(prompt) {
426
+ const stmt = this.db.prepare(`
427
+ INSERT INTO prompt_history (session_id, project_path, prompt_text, context_summary, timestamp, hash, quality_score, intent_label)
428
+ VALUES (@session_id, @project_path, @prompt_text, @context_summary, @timestamp, @hash, @quality_score, @intent_label)
429
+ ON CONFLICT(hash) DO UPDATE SET
430
+ quality_score = @quality_score,
431
+ intent_label = @intent_label
432
+ RETURNING id
433
+ `);
434
+ const result = stmt.get({
435
+ session_id: prompt.session_id,
436
+ project_path: prompt.project_path || null,
437
+ prompt_text: prompt.prompt_text || null,
438
+ context_summary: prompt.context_summary || null,
439
+ timestamp: prompt.timestamp,
440
+ hash: prompt.hash || null,
441
+ quality_score: prompt.quality_score || null,
442
+ intent_label: prompt.intent_label || null
443
+ });
444
+ return result.id;
445
+ }
446
+ /**
447
+ * Get prompt history for a session
448
+ */
449
+ getPromptHistory(sessionId, limit = 50) {
450
+ const stmt = this.db.prepare(`
451
+ SELECT * FROM prompt_history
452
+ WHERE session_id = ?
453
+ ORDER BY timestamp DESC
454
+ LIMIT ?
455
+ `);
456
+ return stmt.all(sessionId, limit);
457
+ }
458
+ /**
459
+ * Search prompts by text
460
+ */
461
+ searchPrompts(query, limit = 20) {
462
+ const stmt = this.db.prepare(`
463
+ SELECT ph.* FROM prompt_history ph
464
+ INNER JOIN prompt_history_fts fts ON fts.rowid = ph.id
465
+ WHERE prompt_history_fts MATCH ?
466
+ ORDER BY ph.timestamp DESC
467
+ LIMIT ?
468
+ `);
469
+ return stmt.all(query, limit);
470
+ }
471
+ /**
472
+ * Save or update a conversation
473
+ */
474
+ saveConversation(conversation) {
475
+ const stmt = this.db.prepare(`
476
+ INSERT INTO conversations (id, source, external_id, project_name, git_branch, created_at, updated_at, quality_score, turn_count, prompt_preview, project_root, relative_path)
477
+ VALUES (@id, @source, @external_id, @project_name, @git_branch, @created_at, @updated_at, @quality_score, @turn_count, @prompt_preview, @project_root, @relative_path)
478
+ ON CONFLICT(id) DO UPDATE SET
479
+ updated_at = @updated_at,
480
+ quality_score = @quality_score,
481
+ turn_count = @turn_count,
482
+ prompt_preview = @prompt_preview,
483
+ project_root = @project_root,
484
+ relative_path = @relative_path
485
+ `);
486
+ stmt.run({
487
+ id: conversation.id,
488
+ source: conversation.source || 'ccw',
489
+ external_id: conversation.external_id || null,
490
+ project_name: conversation.project_name || null,
491
+ git_branch: conversation.git_branch || null,
492
+ created_at: conversation.created_at,
493
+ updated_at: conversation.updated_at,
494
+ quality_score: conversation.quality_score || null,
495
+ turn_count: conversation.turn_count,
496
+ prompt_preview: conversation.prompt_preview || null,
497
+ project_root: this.projectPath,
498
+ relative_path: null // For future hierarchical tracking
499
+ });
500
+ }
501
+ /**
502
+ * Get conversations
503
+ */
504
+ getConversations(limit = 50, offset = 0) {
505
+ const stmt = this.db.prepare(`
506
+ SELECT * FROM conversations
507
+ ORDER BY updated_at DESC
508
+ LIMIT ? OFFSET ?
509
+ `);
510
+ return stmt.all(limit, offset);
511
+ }
512
+ /**
513
+ * Get conversation by ID
514
+ */
515
+ getConversation(id) {
516
+ const stmt = this.db.prepare(`SELECT * FROM conversations WHERE id = ?`);
517
+ return stmt.get(id);
518
+ }
519
+ /**
520
+ * Save message
521
+ */
522
+ saveMessage(message) {
523
+ const stmt = this.db.prepare(`
524
+ INSERT INTO messages (conversation_id, role, content_text, content_json, timestamp, token_count)
525
+ VALUES (@conversation_id, @role, @content_text, @content_json, @timestamp, @token_count)
526
+ RETURNING id
527
+ `);
528
+ const result = stmt.get({
529
+ conversation_id: message.conversation_id,
530
+ role: message.role,
531
+ content_text: message.content_text || null,
532
+ content_json: message.content_json || null,
533
+ timestamp: message.timestamp,
534
+ token_count: message.token_count || null
535
+ });
536
+ return result.id;
537
+ }
538
+ /**
539
+ * Get messages for a conversation
540
+ */
541
+ getMessages(conversationId) {
542
+ const stmt = this.db.prepare(`
543
+ SELECT * FROM messages
544
+ WHERE conversation_id = ?
545
+ ORDER BY timestamp ASC
546
+ `);
547
+ return stmt.all(conversationId);
548
+ }
549
+ /**
550
+ * Save tool call
551
+ */
552
+ saveToolCall(toolCall) {
553
+ const stmt = this.db.prepare(`
554
+ INSERT INTO tool_calls (message_id, tool_name, tool_args, tool_output, status, duration_ms)
555
+ VALUES (@message_id, @tool_name, @tool_args, @tool_output, @status, @duration_ms)
556
+ RETURNING id
557
+ `);
558
+ const result = stmt.get({
559
+ message_id: toolCall.message_id,
560
+ tool_name: toolCall.tool_name,
561
+ tool_args: toolCall.tool_args || null,
562
+ tool_output: toolCall.tool_output || null,
563
+ status: toolCall.status || null,
564
+ duration_ms: toolCall.duration_ms || null
565
+ });
566
+ return result.id;
567
+ }
568
+ /**
569
+ * Get tool calls for a message
570
+ */
571
+ getToolCalls(messageId) {
572
+ const stmt = this.db.prepare(`
573
+ SELECT * FROM tool_calls
574
+ WHERE message_id = ?
575
+ `);
576
+ return stmt.all(messageId);
577
+ }
578
+ /**
579
+ * Close database connection
580
+ */
581
+ close() {
582
+ this.db.close();
583
+ }
584
+ }
585
+ // Singleton instance cache - keyed by normalized project ID for consistency
586
+ const storeCache = new Map();
587
+ /**
588
+ * Get or create a store instance for a project
589
+ * Uses normalized project ID as cache key to handle path casing differences
590
+ */
591
+ export function getMemoryStore(projectPath) {
592
+ // Use getProjectId to normalize path for consistent cache key
593
+ const cacheKey = getProjectId(projectPath);
594
+ if (!storeCache.has(cacheKey)) {
595
+ storeCache.set(cacheKey, new MemoryStore(projectPath));
596
+ }
597
+ return storeCache.get(cacheKey);
598
+ }
599
+ /**
600
+ * Get aggregated stats from parent and all child projects
601
+ * @param projectPath - Parent project path
602
+ * @returns Aggregated statistics from all projects
603
+ */
604
+ export async function getAggregatedStats(projectPath) {
605
+ const { scanChildProjectsAsync } = await import('../config/storage-paths.js');
606
+ const childProjects = await scanChildProjectsAsync(projectPath);
607
+ const projectStats = [];
608
+ let totalEntities = 0;
609
+ let totalPrompts = 0;
610
+ let totalConversations = 0;
611
+ // Get parent stats
612
+ try {
613
+ const parentStore = getMemoryStore(projectPath);
614
+ const db = parentStore.db;
615
+ const entityCount = db.prepare('SELECT COUNT(*) as count FROM entities').get().count;
616
+ const promptCount = db.prepare('SELECT COUNT(*) as count FROM prompt_history').get().count;
617
+ const conversationCount = db.prepare('SELECT COUNT(*) as count FROM conversations').get().count;
618
+ projectStats.push({
619
+ path: projectPath,
620
+ stats: { entities: entityCount, prompts: promptCount, conversations: conversationCount }
621
+ });
622
+ totalEntities += entityCount;
623
+ totalPrompts += promptCount;
624
+ totalConversations += conversationCount;
625
+ }
626
+ catch (error) {
627
+ if (process.env.DEBUG) {
628
+ console.error(`[Memory Store] Failed to get stats for parent ${projectPath}:`, error);
629
+ }
630
+ }
631
+ // Get child stats
632
+ for (const child of childProjects) {
633
+ try {
634
+ const childStore = getMemoryStore(child.projectPath);
635
+ const db = childStore.db;
636
+ const entityCount = db.prepare('SELECT COUNT(*) as count FROM entities').get().count;
637
+ const promptCount = db.prepare('SELECT COUNT(*) as count FROM prompt_history').get().count;
638
+ const conversationCount = db.prepare('SELECT COUNT(*) as count FROM conversations').get().count;
639
+ projectStats.push({
640
+ path: child.relativePath,
641
+ stats: { entities: entityCount, prompts: promptCount, conversations: conversationCount }
642
+ });
643
+ totalEntities += entityCount;
644
+ totalPrompts += promptCount;
645
+ totalConversations += conversationCount;
646
+ }
647
+ catch (error) {
648
+ if (process.env.DEBUG) {
649
+ console.error(`[Memory Store] Failed to get stats for child ${child.projectPath}:`, error);
650
+ }
651
+ }
652
+ }
653
+ return {
654
+ entities: totalEntities,
655
+ prompts: totalPrompts,
656
+ conversations: totalConversations,
657
+ total: totalEntities + totalPrompts + totalConversations,
658
+ projects: projectStats
659
+ };
660
+ }
661
+ /**
662
+ * Get aggregated entities from parent and all child projects
663
+ * @param projectPath - Parent project path
664
+ * @param options - Query options
665
+ * @returns Combined entities from all projects with source information
666
+ */
667
+ export async function getAggregatedEntities(projectPath, options = {}) {
668
+ const { scanChildProjectsAsync } = await import('../config/storage-paths.js');
669
+ const childProjects = await scanChildProjectsAsync(projectPath);
670
+ const limit = options.limit || 50;
671
+ const offset = options.offset || 0;
672
+ const allEntities = [];
673
+ // Get parent entities - apply LIMIT at SQL level
674
+ try {
675
+ const parentStore = getMemoryStore(projectPath);
676
+ const db = parentStore.db;
677
+ let query = 'SELECT * FROM entities';
678
+ const params = [];
679
+ if (options.type) {
680
+ query += ' WHERE type = ?';
681
+ params.push(options.type);
682
+ }
683
+ query += ' ORDER BY last_seen_at DESC LIMIT ?';
684
+ params.push(limit);
685
+ const stmt = db.prepare(query);
686
+ const parentEntities = stmt.all(...params);
687
+ allEntities.push(...parentEntities.map((e) => ({ ...e, stats: {}, sourceProject: projectPath })));
688
+ }
689
+ catch (error) {
690
+ if (process.env.DEBUG) {
691
+ console.error(`[Memory Store] Failed to get entities for parent ${projectPath}:`, error);
692
+ }
693
+ }
694
+ // Get child entities - apply LIMIT to each child
695
+ for (const child of childProjects) {
696
+ try {
697
+ const childStore = getMemoryStore(child.projectPath);
698
+ const db = childStore.db;
699
+ let query = 'SELECT * FROM entities';
700
+ const params = [];
701
+ if (options.type) {
702
+ query += ' WHERE type = ?';
703
+ params.push(options.type);
704
+ }
705
+ query += ' ORDER BY last_seen_at DESC LIMIT ?';
706
+ params.push(limit);
707
+ const stmt = db.prepare(query);
708
+ const childEntities = stmt.all(...params);
709
+ allEntities.push(...childEntities.map((e) => ({ ...e, stats: {}, sourceProject: child.relativePath })));
710
+ }
711
+ catch (error) {
712
+ if (process.env.DEBUG) {
713
+ console.error(`[Memory Store] Failed to get entities for child ${child.projectPath}:`, error);
714
+ }
715
+ }
716
+ }
717
+ // Sort by last_seen_at and apply final limit with offset
718
+ allEntities.sort((a, b) => {
719
+ const aTime = a.last_seen_at ? new Date(a.last_seen_at).getTime() : 0;
720
+ const bTime = b.last_seen_at ? new Date(b.last_seen_at).getTime() : 0;
721
+ return bTime - aTime;
722
+ });
723
+ return allEntities.slice(offset, offset + limit);
724
+ }
725
+ /**
726
+ * Get aggregated prompts from parent and all child projects
727
+ * @param projectPath - Parent project path
728
+ * @param limit - Maximum number of prompts to return
729
+ * @returns Combined prompts from all projects with source information
730
+ */
731
+ export async function getAggregatedPrompts(projectPath, limit = 50) {
732
+ const { scanChildProjectsAsync } = await import('../config/storage-paths.js');
733
+ const childProjects = await scanChildProjectsAsync(projectPath);
734
+ const allPrompts = [];
735
+ // Get parent prompts - use direct SQL query with LIMIT
736
+ try {
737
+ const parentStore = getMemoryStore(projectPath);
738
+ const db = parentStore.db;
739
+ const stmt = db.prepare('SELECT * FROM prompt_history ORDER BY timestamp DESC LIMIT ?');
740
+ const parentPrompts = stmt.all(limit);
741
+ allPrompts.push(...parentPrompts.map((p) => ({ ...p, sourceProject: projectPath })));
742
+ }
743
+ catch (error) {
744
+ if (process.env.DEBUG) {
745
+ console.error(`[Memory Store] Failed to get prompts for parent ${projectPath}:`, error);
746
+ }
747
+ }
748
+ // Get child prompts - apply LIMIT to each child to reduce memory footprint
749
+ for (const child of childProjects) {
750
+ try {
751
+ const childStore = getMemoryStore(child.projectPath);
752
+ const db = childStore.db;
753
+ const stmt = db.prepare('SELECT * FROM prompt_history ORDER BY timestamp DESC LIMIT ?');
754
+ const childPrompts = stmt.all(limit);
755
+ allPrompts.push(...childPrompts.map((p) => ({ ...p, sourceProject: child.relativePath })));
756
+ }
757
+ catch (error) {
758
+ if (process.env.DEBUG) {
759
+ console.error(`[Memory Store] Failed to get prompts for child ${child.projectPath}:`, error);
760
+ }
761
+ }
762
+ }
763
+ // Sort by timestamp and apply final limit
764
+ allPrompts.sort((a, b) => {
765
+ const aTime = a.timestamp ? new Date(a.timestamp).getTime() : 0;
766
+ const bTime = b.timestamp ? new Date(b.timestamp).getTime() : 0;
767
+ return bTime - aTime;
768
+ });
769
+ return allPrompts.slice(0, limit);
770
+ }
771
+ /**
772
+ * Close all store instances
773
+ */
774
+ export function closeAllStores() {
775
+ for (const store of storeCache.values()) {
776
+ store.close();
777
+ }
778
+ storeCache.clear();
779
+ }
780
+ export default MemoryStore;
781
+ //# sourceMappingURL=memory-store.js.map