claude-code-workflow 6.2.2 → 6.2.4

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 +5 -2
@@ -0,0 +1,1177 @@
1
+ /**
2
+ * Core Memory Store - Independent storage system for core memories
3
+ * Provides persistent storage for high-level architectural and strategic context
4
+ */
5
+ import Database from 'better-sqlite3';
6
+ import { existsSync } from 'fs';
7
+ import { join } from 'path';
8
+ import { StoragePaths, ensureStorageDir } from '../config/storage-paths.js';
9
+ /**
10
+ * Core Memory Store using SQLite
11
+ */
12
+ export class CoreMemoryStore {
13
+ db;
14
+ dbPath;
15
+ projectPath;
16
+ constructor(projectPath) {
17
+ this.projectPath = projectPath;
18
+ // Use centralized storage path
19
+ const paths = StoragePaths.project(projectPath);
20
+ const coreMemoryDir = join(paths.root, 'core-memory');
21
+ ensureStorageDir(coreMemoryDir);
22
+ this.dbPath = join(coreMemoryDir, 'core_memory.db');
23
+ this.db = new Database(this.dbPath);
24
+ this.db.pragma('journal_mode = WAL');
25
+ this.db.pragma('synchronous = NORMAL');
26
+ this.initDatabase();
27
+ }
28
+ /**
29
+ * Initialize database schema
30
+ */
31
+ initDatabase() {
32
+ // Migrate old tables
33
+ this.migrateDatabase();
34
+ this.db.exec(`
35
+ -- Core memories table
36
+ CREATE TABLE IF NOT EXISTS memories (
37
+ id TEXT PRIMARY KEY,
38
+ content TEXT NOT NULL,
39
+ summary TEXT,
40
+ raw_output TEXT,
41
+ created_at TEXT NOT NULL,
42
+ updated_at TEXT NOT NULL,
43
+ archived INTEGER DEFAULT 0,
44
+ metadata TEXT
45
+ );
46
+
47
+ -- Session clusters table
48
+ CREATE TABLE IF NOT EXISTS session_clusters (
49
+ id TEXT PRIMARY KEY,
50
+ name TEXT NOT NULL,
51
+ description TEXT,
52
+ intent TEXT,
53
+ created_at TEXT NOT NULL,
54
+ updated_at TEXT NOT NULL,
55
+ status TEXT DEFAULT 'active',
56
+ metadata TEXT
57
+ );
58
+
59
+ -- Cluster members table
60
+ CREATE TABLE IF NOT EXISTS cluster_members (
61
+ cluster_id TEXT NOT NULL,
62
+ session_id TEXT NOT NULL,
63
+ session_type TEXT NOT NULL,
64
+ sequence_order INTEGER NOT NULL,
65
+ added_at TEXT NOT NULL,
66
+ relevance_score REAL DEFAULT 1.0,
67
+ PRIMARY KEY (cluster_id, session_id),
68
+ FOREIGN KEY (cluster_id) REFERENCES session_clusters(id) ON DELETE CASCADE
69
+ );
70
+
71
+ -- Cluster relations table
72
+ CREATE TABLE IF NOT EXISTS cluster_relations (
73
+ source_cluster_id TEXT NOT NULL,
74
+ target_cluster_id TEXT NOT NULL,
75
+ relation_type TEXT NOT NULL,
76
+ created_at TEXT NOT NULL,
77
+ PRIMARY KEY (source_cluster_id, target_cluster_id),
78
+ FOREIGN KEY (source_cluster_id) REFERENCES session_clusters(id) ON DELETE CASCADE,
79
+ FOREIGN KEY (target_cluster_id) REFERENCES session_clusters(id) ON DELETE CASCADE
80
+ );
81
+
82
+ -- Session metadata cache table
83
+ CREATE TABLE IF NOT EXISTS session_metadata_cache (
84
+ session_id TEXT PRIMARY KEY,
85
+ session_type TEXT NOT NULL,
86
+ title TEXT,
87
+ summary TEXT,
88
+ keywords TEXT,
89
+ token_estimate INTEGER,
90
+ file_patterns TEXT,
91
+ created_at TEXT,
92
+ last_accessed TEXT,
93
+ access_count INTEGER DEFAULT 0
94
+ );
95
+
96
+ -- Memory chunks table for embeddings
97
+ CREATE TABLE IF NOT EXISTS memory_chunks (
98
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
99
+ source_id TEXT NOT NULL,
100
+ source_type TEXT NOT NULL,
101
+ chunk_index INTEGER NOT NULL,
102
+ content TEXT NOT NULL,
103
+ embedding BLOB,
104
+ metadata TEXT,
105
+ created_at TEXT NOT NULL,
106
+ UNIQUE(source_id, chunk_index)
107
+ );
108
+
109
+ -- CLAUDE.md update history table
110
+ CREATE TABLE IF NOT EXISTS claude_update_history (
111
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
112
+ file_path TEXT NOT NULL,
113
+ file_level TEXT NOT NULL CHECK(file_level IN ('user', 'project', 'module')),
114
+ module_path TEXT,
115
+ updated_at TEXT NOT NULL,
116
+ update_source TEXT NOT NULL CHECK(update_source IN ('manual', 'cli_sync', 'dashboard', 'api')),
117
+ git_commit_hash TEXT,
118
+ files_changed_before_update INTEGER DEFAULT 0,
119
+ metadata TEXT,
120
+ UNIQUE(file_path, updated_at)
121
+ );
122
+
123
+ -- Indexes for efficient queries
124
+ CREATE INDEX IF NOT EXISTS idx_memories_created ON memories(created_at DESC);
125
+ CREATE INDEX IF NOT EXISTS idx_memories_updated ON memories(updated_at DESC);
126
+ CREATE INDEX IF NOT EXISTS idx_memories_archived ON memories(archived);
127
+ CREATE INDEX IF NOT EXISTS idx_session_clusters_status ON session_clusters(status);
128
+ CREATE INDEX IF NOT EXISTS idx_cluster_members_cluster ON cluster_members(cluster_id);
129
+ CREATE INDEX IF NOT EXISTS idx_cluster_members_session ON cluster_members(session_id);
130
+ CREATE INDEX IF NOT EXISTS idx_session_metadata_type ON session_metadata_cache(session_type);
131
+ CREATE INDEX IF NOT EXISTS idx_memory_chunks_source ON memory_chunks(source_id, source_type);
132
+ CREATE INDEX IF NOT EXISTS idx_memory_chunks_embedded ON memory_chunks(embedding IS NOT NULL);
133
+ CREATE INDEX IF NOT EXISTS idx_claude_history_path ON claude_update_history(file_path);
134
+ CREATE INDEX IF NOT EXISTS idx_claude_history_updated ON claude_update_history(updated_at DESC);
135
+ CREATE INDEX IF NOT EXISTS idx_claude_history_module ON claude_update_history(module_path);
136
+ `);
137
+ }
138
+ /**
139
+ * Migrate database by removing old tables, views, and triggers
140
+ */
141
+ migrateDatabase() {
142
+ const oldTables = ['knowledge_graph', 'knowledge_graph_edges', 'evolution_history'];
143
+ try {
144
+ // Disable foreign key constraints during migration
145
+ this.db.pragma('foreign_keys = OFF');
146
+ // Drop any triggers that might reference old tables
147
+ const triggers = this.db.prepare(`SELECT name FROM sqlite_master WHERE type='trigger'`).all();
148
+ for (const trigger of triggers) {
149
+ try {
150
+ this.db.exec(`DROP TRIGGER IF EXISTS "${trigger.name}"`);
151
+ }
152
+ catch (e) {
153
+ // Ignore trigger drop errors
154
+ }
155
+ }
156
+ // Drop any views that might reference old tables
157
+ const views = this.db.prepare(`SELECT name FROM sqlite_master WHERE type='view'`).all();
158
+ for (const view of views) {
159
+ try {
160
+ this.db.exec(`DROP VIEW IF EXISTS "${view.name}"`);
161
+ }
162
+ catch (e) {
163
+ // Ignore view drop errors
164
+ }
165
+ }
166
+ // Now drop the old tables
167
+ for (const table of oldTables) {
168
+ try {
169
+ this.db.exec(`DROP TABLE IF EXISTS "${table}"`);
170
+ }
171
+ catch (e) {
172
+ // Ignore if table doesn't exist
173
+ }
174
+ }
175
+ // Re-enable foreign key constraints
176
+ this.db.pragma('foreign_keys = ON');
177
+ }
178
+ catch (e) {
179
+ // If migration fails, continue - tables may not exist
180
+ try {
181
+ this.db.pragma('foreign_keys = ON');
182
+ }
183
+ catch (_) {
184
+ // Ignore
185
+ }
186
+ }
187
+ }
188
+ /**
189
+ * Generate timestamp-based ID for core memory
190
+ */
191
+ generateId() {
192
+ const now = new Date();
193
+ const year = now.getFullYear();
194
+ const month = String(now.getMonth() + 1).padStart(2, '0');
195
+ const day = String(now.getDate()).padStart(2, '0');
196
+ const hours = String(now.getHours()).padStart(2, '0');
197
+ const minutes = String(now.getMinutes()).padStart(2, '0');
198
+ const seconds = String(now.getSeconds()).padStart(2, '0');
199
+ return `CMEM-${year}${month}${day}-${hours}${minutes}${seconds}`;
200
+ }
201
+ /**
202
+ * Generate cluster ID
203
+ */
204
+ generateClusterId() {
205
+ const now = new Date();
206
+ const year = now.getFullYear();
207
+ const month = String(now.getMonth() + 1).padStart(2, '0');
208
+ const day = String(now.getDate()).padStart(2, '0');
209
+ const hours = String(now.getHours()).padStart(2, '0');
210
+ const minutes = String(now.getMinutes()).padStart(2, '0');
211
+ const seconds = String(now.getSeconds()).padStart(2, '0');
212
+ const ms = String(now.getMilliseconds()).padStart(3, '0');
213
+ // Add random 4-digit suffix to ensure uniqueness (10000 combinations)
214
+ const random = String(Math.floor(Math.random() * 10000)).padStart(4, '0');
215
+ return `CLST-${year}${month}${day}-${hours}${minutes}${seconds}${ms}${random}`;
216
+ }
217
+ /**
218
+ * Upsert a core memory
219
+ */
220
+ upsertMemory(memory) {
221
+ const now = new Date().toISOString();
222
+ const id = memory.id || this.generateId();
223
+ // Check if memory exists
224
+ const existingMemory = this.getMemory(id);
225
+ if (existingMemory) {
226
+ // Update existing memory
227
+ const stmt = this.db.prepare(`
228
+ UPDATE memories
229
+ SET content = ?, summary = ?, raw_output = ?, updated_at = ?, archived = ?, metadata = ?
230
+ WHERE id = ?
231
+ `);
232
+ stmt.run(memory.content, memory.summary || existingMemory.summary, memory.raw_output || existingMemory.raw_output, now, memory.archived !== undefined ? (memory.archived ? 1 : 0) : existingMemory.archived ? 1 : 0, memory.metadata || existingMemory.metadata, id);
233
+ return this.getMemory(id);
234
+ }
235
+ else {
236
+ // Insert new memory
237
+ const stmt = this.db.prepare(`
238
+ INSERT INTO memories (id, content, summary, raw_output, created_at, updated_at, archived, metadata)
239
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
240
+ `);
241
+ stmt.run(id, memory.content, memory.summary || '', memory.raw_output || null, now, now, memory.archived ? 1 : 0, memory.metadata || null);
242
+ return this.getMemory(id);
243
+ }
244
+ }
245
+ /**
246
+ * Get memory by ID
247
+ */
248
+ getMemory(id) {
249
+ const stmt = this.db.prepare(`SELECT * FROM memories WHERE id = ?`);
250
+ const row = stmt.get(id);
251
+ if (!row)
252
+ return null;
253
+ return {
254
+ id: row.id,
255
+ content: row.content,
256
+ summary: row.summary,
257
+ raw_output: row.raw_output,
258
+ created_at: row.created_at,
259
+ updated_at: row.updated_at,
260
+ archived: Boolean(row.archived),
261
+ metadata: row.metadata
262
+ };
263
+ }
264
+ /**
265
+ * Get all memories
266
+ */
267
+ getMemories(options = {}) {
268
+ const { archived = false, limit = 50, offset = 0 } = options;
269
+ const stmt = this.db.prepare(`
270
+ SELECT * FROM memories
271
+ WHERE archived = ?
272
+ ORDER BY updated_at DESC
273
+ LIMIT ? OFFSET ?
274
+ `);
275
+ const rows = stmt.all(archived ? 1 : 0, limit, offset);
276
+ return rows.map(row => ({
277
+ id: row.id,
278
+ content: row.content,
279
+ summary: row.summary,
280
+ raw_output: row.raw_output,
281
+ created_at: row.created_at,
282
+ updated_at: row.updated_at,
283
+ archived: Boolean(row.archived),
284
+ metadata: row.metadata
285
+ }));
286
+ }
287
+ /**
288
+ * Archive a memory
289
+ */
290
+ archiveMemory(id) {
291
+ const stmt = this.db.prepare(`
292
+ UPDATE memories
293
+ SET archived = 1, updated_at = ?
294
+ WHERE id = ?
295
+ `);
296
+ stmt.run(new Date().toISOString(), id);
297
+ }
298
+ /**
299
+ * Delete a memory
300
+ */
301
+ deleteMemory(id) {
302
+ const stmt = this.db.prepare(`DELETE FROM memories WHERE id = ?`);
303
+ stmt.run(id);
304
+ }
305
+ /**
306
+ * Generate summary for a memory using CLI tool
307
+ */
308
+ async generateSummary(memoryId, tool = 'gemini') {
309
+ const memory = this.getMemory(memoryId);
310
+ if (!memory)
311
+ throw new Error('Memory not found');
312
+ // Import CLI executor
313
+ const { executeCliTool } = await import('../tools/cli-executor.js');
314
+ const prompt = `
315
+ PURPOSE: Generate a concise summary (2-3 sentences) of the following core memory content
316
+ TASK: Extract key architectural decisions, strategic insights, and important context
317
+ MODE: analysis
318
+ EXPECTED: Plain text summary without markdown or formatting
319
+ RULES: Be concise. Focus on high-level understanding. No technical jargon unless essential.
320
+
321
+ CONTENT:
322
+ ${memory.content}
323
+ `;
324
+ const result = await executeCliTool({
325
+ tool,
326
+ prompt,
327
+ mode: 'analysis',
328
+ timeout: 60000,
329
+ cd: this.projectPath,
330
+ category: 'internal'
331
+ });
332
+ const summary = result.stdout?.trim() || 'Failed to generate summary';
333
+ // Update memory with summary
334
+ const stmt = this.db.prepare(`
335
+ UPDATE memories
336
+ SET summary = ?, updated_at = ?
337
+ WHERE id = ?
338
+ `);
339
+ stmt.run(summary, new Date().toISOString(), memoryId);
340
+ return summary;
341
+ }
342
+ /**
343
+ * Create a new session cluster
344
+ */
345
+ createCluster(cluster) {
346
+ const now = new Date().toISOString();
347
+ const id = cluster.id || this.generateClusterId();
348
+ const stmt = this.db.prepare(`
349
+ INSERT INTO session_clusters (id, name, description, intent, created_at, updated_at, status, metadata)
350
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
351
+ `);
352
+ stmt.run(id, cluster.name, cluster.description || null, cluster.intent || null, now, now, cluster.status || 'active', cluster.metadata || null);
353
+ return this.getCluster(id);
354
+ }
355
+ /**
356
+ * Get cluster by ID
357
+ */
358
+ getCluster(id) {
359
+ const stmt = this.db.prepare(`SELECT * FROM session_clusters WHERE id = ?`);
360
+ const row = stmt.get(id);
361
+ if (!row)
362
+ return null;
363
+ return {
364
+ id: row.id,
365
+ name: row.name,
366
+ description: row.description,
367
+ intent: row.intent,
368
+ created_at: row.created_at,
369
+ updated_at: row.updated_at,
370
+ status: row.status,
371
+ metadata: row.metadata
372
+ };
373
+ }
374
+ /**
375
+ * List all clusters
376
+ */
377
+ listClusters(status) {
378
+ let query = 'SELECT * FROM session_clusters';
379
+ const params = [];
380
+ if (status) {
381
+ query += ' WHERE status = ?';
382
+ params.push(status);
383
+ }
384
+ query += ' ORDER BY updated_at DESC';
385
+ const stmt = this.db.prepare(query);
386
+ const rows = stmt.all(...params);
387
+ return rows.map(row => ({
388
+ id: row.id,
389
+ name: row.name,
390
+ description: row.description,
391
+ intent: row.intent,
392
+ created_at: row.created_at,
393
+ updated_at: row.updated_at,
394
+ status: row.status,
395
+ metadata: row.metadata
396
+ }));
397
+ }
398
+ /**
399
+ * Update cluster
400
+ */
401
+ updateCluster(id, updates) {
402
+ const existing = this.getCluster(id);
403
+ if (!existing)
404
+ return null;
405
+ const now = new Date().toISOString();
406
+ const stmt = this.db.prepare(`
407
+ UPDATE session_clusters
408
+ SET name = ?, description = ?, intent = ?, updated_at = ?, status = ?, metadata = ?
409
+ WHERE id = ?
410
+ `);
411
+ stmt.run(updates.name || existing.name, updates.description !== undefined ? updates.description : existing.description, updates.intent !== undefined ? updates.intent : existing.intent, now, updates.status || existing.status, updates.metadata !== undefined ? updates.metadata : existing.metadata, id);
412
+ return this.getCluster(id);
413
+ }
414
+ /**
415
+ * Delete cluster
416
+ */
417
+ deleteCluster(id) {
418
+ const stmt = this.db.prepare(`DELETE FROM session_clusters WHERE id = ?`);
419
+ const result = stmt.run(id);
420
+ return result.changes > 0;
421
+ }
422
+ /**
423
+ * Merge multiple clusters into one
424
+ * Keeps the first cluster and moves all members from others into it
425
+ * @param targetClusterId The cluster to keep
426
+ * @param sourceClusterIds The clusters to merge into target (will be deleted)
427
+ * @returns Number of members moved
428
+ */
429
+ mergeClusters(targetClusterId, sourceClusterIds) {
430
+ const targetCluster = this.getCluster(targetClusterId);
431
+ if (!targetCluster) {
432
+ throw new Error(`Target cluster not found: ${targetClusterId}`);
433
+ }
434
+ let membersMoved = 0;
435
+ const existingMembers = new Set(this.getClusterMembers(targetClusterId).map(m => m.session_id));
436
+ for (const sourceId of sourceClusterIds) {
437
+ if (sourceId === targetClusterId)
438
+ continue;
439
+ const sourceMembers = this.getClusterMembers(sourceId);
440
+ const maxOrder = this.getClusterMembers(targetClusterId).length;
441
+ for (const member of sourceMembers) {
442
+ // Skip if already exists in target
443
+ if (existingMembers.has(member.session_id))
444
+ continue;
445
+ // Move member to target cluster
446
+ this.addClusterMember({
447
+ cluster_id: targetClusterId,
448
+ session_id: member.session_id,
449
+ session_type: member.session_type,
450
+ sequence_order: maxOrder + membersMoved + 1,
451
+ relevance_score: member.relevance_score
452
+ });
453
+ existingMembers.add(member.session_id);
454
+ membersMoved++;
455
+ }
456
+ // Delete source cluster
457
+ this.deleteCluster(sourceId);
458
+ }
459
+ // Update target cluster description
460
+ const finalMembers = this.getClusterMembers(targetClusterId);
461
+ this.updateCluster(targetClusterId, {
462
+ description: `Merged cluster with ${finalMembers.length} sessions`
463
+ });
464
+ return membersMoved;
465
+ }
466
+ /**
467
+ * Add member to cluster
468
+ */
469
+ addClusterMember(member) {
470
+ const now = new Date().toISOString();
471
+ const stmt = this.db.prepare(`
472
+ INSERT INTO cluster_members (cluster_id, session_id, session_type, sequence_order, added_at, relevance_score)
473
+ VALUES (?, ?, ?, ?, ?, ?)
474
+ `);
475
+ stmt.run(member.cluster_id, member.session_id, member.session_type, member.sequence_order, now, member.relevance_score);
476
+ return {
477
+ ...member,
478
+ added_at: now
479
+ };
480
+ }
481
+ /**
482
+ * Remove member from cluster
483
+ */
484
+ removeClusterMember(clusterId, sessionId) {
485
+ const stmt = this.db.prepare(`
486
+ DELETE FROM cluster_members
487
+ WHERE cluster_id = ? AND session_id = ?
488
+ `);
489
+ const result = stmt.run(clusterId, sessionId);
490
+ return result.changes > 0;
491
+ }
492
+ /**
493
+ * Get all members of a cluster
494
+ */
495
+ getClusterMembers(clusterId) {
496
+ const stmt = this.db.prepare(`
497
+ SELECT * FROM cluster_members
498
+ WHERE cluster_id = ?
499
+ ORDER BY sequence_order ASC
500
+ `);
501
+ const rows = stmt.all(clusterId);
502
+ return rows.map(row => ({
503
+ cluster_id: row.cluster_id,
504
+ session_id: row.session_id,
505
+ session_type: row.session_type,
506
+ sequence_order: row.sequence_order,
507
+ added_at: row.added_at,
508
+ relevance_score: row.relevance_score
509
+ }));
510
+ }
511
+ /**
512
+ * Get all clusters that contain a session
513
+ */
514
+ getSessionClusters(sessionId) {
515
+ const stmt = this.db.prepare(`
516
+ SELECT sc.*
517
+ FROM session_clusters sc
518
+ INNER JOIN cluster_members cm ON sc.id = cm.cluster_id
519
+ WHERE cm.session_id = ?
520
+ ORDER BY sc.updated_at DESC
521
+ `);
522
+ const rows = stmt.all(sessionId);
523
+ return rows.map(row => ({
524
+ id: row.id,
525
+ name: row.name,
526
+ description: row.description,
527
+ intent: row.intent,
528
+ created_at: row.created_at,
529
+ updated_at: row.updated_at,
530
+ status: row.status,
531
+ metadata: row.metadata
532
+ }));
533
+ }
534
+ /**
535
+ * Add relation between clusters
536
+ */
537
+ addClusterRelation(relation) {
538
+ const now = new Date().toISOString();
539
+ const stmt = this.db.prepare(`
540
+ INSERT INTO cluster_relations (source_cluster_id, target_cluster_id, relation_type, created_at)
541
+ VALUES (?, ?, ?, ?)
542
+ `);
543
+ stmt.run(relation.source_cluster_id, relation.target_cluster_id, relation.relation_type, now);
544
+ return {
545
+ ...relation,
546
+ created_at: now
547
+ };
548
+ }
549
+ /**
550
+ * Remove relation between clusters
551
+ */
552
+ removeClusterRelation(sourceId, targetId) {
553
+ const stmt = this.db.prepare(`
554
+ DELETE FROM cluster_relations
555
+ WHERE source_cluster_id = ? AND target_cluster_id = ?
556
+ `);
557
+ const result = stmt.run(sourceId, targetId);
558
+ return result.changes > 0;
559
+ }
560
+ /**
561
+ * Get all relations for a cluster
562
+ */
563
+ getClusterRelations(clusterId) {
564
+ const stmt = this.db.prepare(`
565
+ SELECT * FROM cluster_relations
566
+ WHERE source_cluster_id = ? OR target_cluster_id = ?
567
+ ORDER BY created_at DESC
568
+ `);
569
+ const rows = stmt.all(clusterId, clusterId);
570
+ return rows.map(row => ({
571
+ source_cluster_id: row.source_cluster_id,
572
+ target_cluster_id: row.target_cluster_id,
573
+ relation_type: row.relation_type,
574
+ created_at: row.created_at
575
+ }));
576
+ }
577
+ /**
578
+ * Upsert session metadata
579
+ */
580
+ upsertSessionMetadata(metadata) {
581
+ const now = new Date().toISOString();
582
+ const existing = this.getSessionMetadata(metadata.session_id);
583
+ if (existing) {
584
+ const stmt = this.db.prepare(`
585
+ UPDATE session_metadata_cache
586
+ SET session_type = ?, title = ?, summary = ?, keywords = ?, token_estimate = ?,
587
+ file_patterns = ?, last_accessed = ?, access_count = ?
588
+ WHERE session_id = ?
589
+ `);
590
+ stmt.run(metadata.session_type, metadata.title || null, metadata.summary || null, metadata.keywords ? JSON.stringify(metadata.keywords) : null, metadata.token_estimate || null, metadata.file_patterns ? JSON.stringify(metadata.file_patterns) : null, now, existing.access_count + 1, metadata.session_id);
591
+ }
592
+ else {
593
+ const stmt = this.db.prepare(`
594
+ INSERT INTO session_metadata_cache
595
+ (session_id, session_type, title, summary, keywords, token_estimate, file_patterns, created_at, last_accessed, access_count)
596
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
597
+ `);
598
+ stmt.run(metadata.session_id, metadata.session_type, metadata.title || null, metadata.summary || null, metadata.keywords ? JSON.stringify(metadata.keywords) : null, metadata.token_estimate || null, metadata.file_patterns ? JSON.stringify(metadata.file_patterns) : null, metadata.created_at || now, now, metadata.access_count || 1);
599
+ }
600
+ return this.getSessionMetadata(metadata.session_id);
601
+ }
602
+ /**
603
+ * Get session metadata
604
+ */
605
+ getSessionMetadata(sessionId) {
606
+ const stmt = this.db.prepare(`SELECT * FROM session_metadata_cache WHERE session_id = ?`);
607
+ const row = stmt.get(sessionId);
608
+ if (!row)
609
+ return null;
610
+ return {
611
+ session_id: row.session_id,
612
+ session_type: row.session_type,
613
+ title: row.title,
614
+ summary: row.summary,
615
+ keywords: row.keywords ? JSON.parse(row.keywords) : undefined,
616
+ token_estimate: row.token_estimate,
617
+ file_patterns: row.file_patterns ? JSON.parse(row.file_patterns) : undefined,
618
+ created_at: row.created_at,
619
+ last_accessed: row.last_accessed,
620
+ access_count: row.access_count
621
+ };
622
+ }
623
+ /**
624
+ * Search sessions by keyword
625
+ */
626
+ searchSessionsByKeyword(keyword) {
627
+ const stmt = this.db.prepare(`
628
+ SELECT * FROM session_metadata_cache
629
+ WHERE title LIKE ? OR summary LIKE ? OR keywords LIKE ?
630
+ ORDER BY access_count DESC, last_accessed DESC
631
+ `);
632
+ const pattern = `%${keyword}%`;
633
+ const rows = stmt.all(pattern, pattern, pattern);
634
+ return rows.map(row => ({
635
+ session_id: row.session_id,
636
+ session_type: row.session_type,
637
+ title: row.title,
638
+ summary: row.summary,
639
+ keywords: row.keywords ? JSON.parse(row.keywords) : undefined,
640
+ token_estimate: row.token_estimate,
641
+ file_patterns: row.file_patterns ? JSON.parse(row.file_patterns) : undefined,
642
+ created_at: row.created_at,
643
+ last_accessed: row.last_accessed,
644
+ access_count: row.access_count
645
+ }));
646
+ }
647
+ // ============================================================================
648
+ // Memory Chunks CRUD Operations
649
+ // ============================================================================
650
+ /**
651
+ * Chunk content into smaller pieces for embedding
652
+ * @param content Content to chunk
653
+ * @param sourceId Source identifier (e.g., memory ID)
654
+ * @param sourceType Type of source
655
+ * @returns Array of chunk content strings
656
+ */
657
+ chunkContent(content, sourceId, sourceType) {
658
+ const CHUNK_SIZE = 1500;
659
+ const OVERLAP = 200;
660
+ const chunks = [];
661
+ // Split by paragraph boundaries first
662
+ const paragraphs = content.split(/\n\n+/);
663
+ let currentChunk = '';
664
+ for (const paragraph of paragraphs) {
665
+ // If adding this paragraph would exceed chunk size
666
+ if (currentChunk.length + paragraph.length > CHUNK_SIZE && currentChunk.length > 0) {
667
+ // Save current chunk
668
+ chunks.push(currentChunk.trim());
669
+ // Start new chunk with overlap
670
+ const overlapText = currentChunk.slice(-OVERLAP);
671
+ currentChunk = overlapText + '\n\n' + paragraph;
672
+ }
673
+ else {
674
+ // Add paragraph to current chunk
675
+ currentChunk += (currentChunk ? '\n\n' : '') + paragraph;
676
+ }
677
+ }
678
+ // Add remaining chunk
679
+ if (currentChunk.trim()) {
680
+ chunks.push(currentChunk.trim());
681
+ }
682
+ // If no paragraphs or chunks are still too large, split by sentences
683
+ const finalChunks = [];
684
+ for (const chunk of chunks) {
685
+ if (chunk.length <= CHUNK_SIZE) {
686
+ finalChunks.push(chunk);
687
+ }
688
+ else {
689
+ // Split by sentence boundaries
690
+ const sentences = chunk.split(/\. +/);
691
+ let sentenceChunk = '';
692
+ for (const sentence of sentences) {
693
+ const sentenceWithPeriod = sentence + '. ';
694
+ if (sentenceChunk.length + sentenceWithPeriod.length > CHUNK_SIZE && sentenceChunk.length > 0) {
695
+ finalChunks.push(sentenceChunk.trim());
696
+ const overlapText = sentenceChunk.slice(-OVERLAP);
697
+ sentenceChunk = overlapText + sentenceWithPeriod;
698
+ }
699
+ else {
700
+ sentenceChunk += sentenceWithPeriod;
701
+ }
702
+ }
703
+ if (sentenceChunk.trim()) {
704
+ finalChunks.push(sentenceChunk.trim());
705
+ }
706
+ }
707
+ }
708
+ return finalChunks.length > 0 ? finalChunks : [content];
709
+ }
710
+ /**
711
+ * Insert a single chunk
712
+ */
713
+ insertChunk(chunk) {
714
+ const now = new Date().toISOString();
715
+ const stmt = this.db.prepare(`
716
+ INSERT INTO memory_chunks (source_id, source_type, chunk_index, content, embedding, metadata, created_at)
717
+ VALUES (?, ?, ?, ?, ?, ?, ?)
718
+ `);
719
+ const result = stmt.run(chunk.source_id, chunk.source_type, chunk.chunk_index, chunk.content, chunk.embedding || null, chunk.metadata || null, chunk.created_at || now);
720
+ return result.lastInsertRowid;
721
+ }
722
+ /**
723
+ * Insert multiple chunks in a batch
724
+ */
725
+ insertChunksBatch(chunks) {
726
+ const now = new Date().toISOString();
727
+ const insert = this.db.prepare(`
728
+ INSERT INTO memory_chunks (source_id, source_type, chunk_index, content, embedding, metadata, created_at)
729
+ VALUES (?, ?, ?, ?, ?, ?, ?)
730
+ `);
731
+ const transaction = this.db.transaction((chunks) => {
732
+ for (const chunk of chunks) {
733
+ insert.run(chunk.source_id, chunk.source_type, chunk.chunk_index, chunk.content, chunk.embedding || null, chunk.metadata || null, chunk.created_at || now);
734
+ }
735
+ });
736
+ transaction(chunks);
737
+ }
738
+ /**
739
+ * Get all chunks for a source
740
+ */
741
+ getChunks(sourceId) {
742
+ const stmt = this.db.prepare(`
743
+ SELECT * FROM memory_chunks
744
+ WHERE source_id = ?
745
+ ORDER BY chunk_index ASC
746
+ `);
747
+ const rows = stmt.all(sourceId);
748
+ return rows.map(row => ({
749
+ id: row.id,
750
+ source_id: row.source_id,
751
+ source_type: row.source_type,
752
+ chunk_index: row.chunk_index,
753
+ content: row.content,
754
+ embedding: row.embedding,
755
+ metadata: row.metadata,
756
+ created_at: row.created_at
757
+ }));
758
+ }
759
+ /**
760
+ * Get chunks by source type
761
+ */
762
+ getChunksByType(sourceType) {
763
+ const stmt = this.db.prepare(`
764
+ SELECT * FROM memory_chunks
765
+ WHERE source_type = ?
766
+ ORDER BY source_id, chunk_index ASC
767
+ `);
768
+ const rows = stmt.all(sourceType);
769
+ return rows.map(row => ({
770
+ id: row.id,
771
+ source_id: row.source_id,
772
+ source_type: row.source_type,
773
+ chunk_index: row.chunk_index,
774
+ content: row.content,
775
+ embedding: row.embedding,
776
+ metadata: row.metadata,
777
+ created_at: row.created_at
778
+ }));
779
+ }
780
+ /**
781
+ * Get chunks without embeddings
782
+ */
783
+ getUnembeddedChunks(limit) {
784
+ const query = `
785
+ SELECT * FROM memory_chunks
786
+ WHERE embedding IS NULL
787
+ ORDER BY created_at ASC
788
+ ${limit ? 'LIMIT ?' : ''}
789
+ `;
790
+ const stmt = this.db.prepare(query);
791
+ const rows = (limit ? stmt.all(limit) : stmt.all());
792
+ return rows.map(row => ({
793
+ id: row.id,
794
+ source_id: row.source_id,
795
+ source_type: row.source_type,
796
+ chunk_index: row.chunk_index,
797
+ content: row.content,
798
+ embedding: row.embedding,
799
+ metadata: row.metadata,
800
+ created_at: row.created_at
801
+ }));
802
+ }
803
+ /**
804
+ * Update embedding for a chunk
805
+ */
806
+ updateChunkEmbedding(chunkId, embedding) {
807
+ const stmt = this.db.prepare(`
808
+ UPDATE memory_chunks
809
+ SET embedding = ?
810
+ WHERE id = ?
811
+ `);
812
+ stmt.run(embedding, chunkId);
813
+ }
814
+ /**
815
+ * Update embeddings for multiple chunks in a batch
816
+ */
817
+ updateChunkEmbeddingsBatch(updates) {
818
+ const update = this.db.prepare(`
819
+ UPDATE memory_chunks
820
+ SET embedding = ?
821
+ WHERE id = ?
822
+ `);
823
+ const transaction = this.db.transaction((updates) => {
824
+ for (const { id, embedding } of updates) {
825
+ update.run(embedding, id);
826
+ }
827
+ });
828
+ transaction(updates);
829
+ }
830
+ /**
831
+ * Delete all chunks for a source
832
+ */
833
+ deleteChunks(sourceId) {
834
+ const stmt = this.db.prepare(`
835
+ DELETE FROM memory_chunks
836
+ WHERE source_id = ?
837
+ `);
838
+ stmt.run(sourceId);
839
+ }
840
+ // ============================================================================
841
+ // CLAUDE.md Update History CRUD Operations
842
+ // ============================================================================
843
+ /**
844
+ * Insert a CLAUDE.md update record
845
+ */
846
+ insertClaudeUpdateRecord(record) {
847
+ const stmt = this.db.prepare(`
848
+ INSERT INTO claude_update_history
849
+ (file_path, file_level, module_path, updated_at, update_source, git_commit_hash, files_changed_before_update, metadata)
850
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
851
+ `);
852
+ const result = stmt.run(record.file_path, record.file_level, record.module_path || null, record.updated_at, record.update_source, record.git_commit_hash || null, record.files_changed_before_update, record.metadata || null);
853
+ return {
854
+ id: result.lastInsertRowid,
855
+ ...record
856
+ };
857
+ }
858
+ /**
859
+ * Get the last update record for a file
860
+ */
861
+ getLastClaudeUpdate(filePath) {
862
+ const stmt = this.db.prepare(`
863
+ SELECT * FROM claude_update_history
864
+ WHERE file_path = ?
865
+ ORDER BY updated_at DESC
866
+ LIMIT 1
867
+ `);
868
+ const row = stmt.get(filePath);
869
+ if (!row)
870
+ return null;
871
+ return {
872
+ id: row.id,
873
+ file_path: row.file_path,
874
+ file_level: row.file_level,
875
+ module_path: row.module_path,
876
+ updated_at: row.updated_at,
877
+ update_source: row.update_source,
878
+ git_commit_hash: row.git_commit_hash,
879
+ files_changed_before_update: row.files_changed_before_update,
880
+ metadata: row.metadata
881
+ };
882
+ }
883
+ /**
884
+ * Get update history for a file
885
+ */
886
+ getClaudeUpdateHistory(filePath, limit = 50) {
887
+ const stmt = this.db.prepare(`
888
+ SELECT * FROM claude_update_history
889
+ WHERE file_path = ?
890
+ ORDER BY updated_at DESC
891
+ LIMIT ?
892
+ `);
893
+ const rows = stmt.all(filePath, limit);
894
+ return rows.map(row => ({
895
+ id: row.id,
896
+ file_path: row.file_path,
897
+ file_level: row.file_level,
898
+ module_path: row.module_path,
899
+ updated_at: row.updated_at,
900
+ update_source: row.update_source,
901
+ git_commit_hash: row.git_commit_hash,
902
+ files_changed_before_update: row.files_changed_before_update,
903
+ metadata: row.metadata
904
+ }));
905
+ }
906
+ /**
907
+ * Get all CLAUDE.md update records for freshness calculation
908
+ */
909
+ getAllClaudeUpdateRecords() {
910
+ const stmt = this.db.prepare(`
911
+ SELECT * FROM claude_update_history
912
+ WHERE id IN (
913
+ SELECT MAX(id) FROM claude_update_history
914
+ GROUP BY file_path
915
+ )
916
+ ORDER BY updated_at DESC
917
+ `);
918
+ const rows = stmt.all();
919
+ return rows.map(row => ({
920
+ id: row.id,
921
+ file_path: row.file_path,
922
+ file_level: row.file_level,
923
+ module_path: row.module_path,
924
+ updated_at: row.updated_at,
925
+ update_source: row.update_source,
926
+ git_commit_hash: row.git_commit_hash,
927
+ files_changed_before_update: row.files_changed_before_update,
928
+ metadata: row.metadata
929
+ }));
930
+ }
931
+ /**
932
+ * Delete update records for a file
933
+ */
934
+ deleteClaudeUpdateRecords(filePath) {
935
+ const stmt = this.db.prepare(`
936
+ DELETE FROM claude_update_history
937
+ WHERE file_path = ?
938
+ `);
939
+ const result = stmt.run(filePath);
940
+ return result.changes;
941
+ }
942
+ /**
943
+ * Close database connection
944
+ */
945
+ close() {
946
+ this.db.close();
947
+ }
948
+ }
949
+ // Singleton instance cache
950
+ const storeCache = new Map();
951
+ /**
952
+ * Get or create a store instance for a project
953
+ */
954
+ export function getCoreMemoryStore(projectPath) {
955
+ const normalizedPath = projectPath.toLowerCase().replace(/\\/g, '/');
956
+ if (!storeCache.has(normalizedPath)) {
957
+ storeCache.set(normalizedPath, new CoreMemoryStore(projectPath));
958
+ }
959
+ return storeCache.get(normalizedPath);
960
+ }
961
+ // ============================================================================
962
+ // Cross-workspace management functions
963
+ // ============================================================================
964
+ import { readdirSync, writeFileSync, readFileSync } from 'fs';
965
+ import { homedir } from 'os';
966
+ /**
967
+ * Get CCW home directory
968
+ */
969
+ function getCCWHome() {
970
+ return process.env.CCW_DATA_DIR || join(homedir(), '.ccw');
971
+ }
972
+ /**
973
+ * List all projects with their memory counts
974
+ */
975
+ export function listAllProjects() {
976
+ const projectsDir = join(getCCWHome(), 'projects');
977
+ if (!existsSync(projectsDir)) {
978
+ return [];
979
+ }
980
+ const projects = [];
981
+ const entries = readdirSync(projectsDir, { withFileTypes: true });
982
+ for (const entry of entries) {
983
+ if (!entry.isDirectory())
984
+ continue;
985
+ const projectId = entry.name;
986
+ const coreMemoryDb = join(projectsDir, projectId, 'core-memory', 'core_memory.db');
987
+ let memoriesCount = 0;
988
+ let clustersCount = 0;
989
+ let lastUpdated;
990
+ if (existsSync(coreMemoryDb)) {
991
+ try {
992
+ const db = new Database(coreMemoryDb, { readonly: true });
993
+ // Count memories
994
+ const memResult = db.prepare('SELECT COUNT(*) as count FROM memories').get();
995
+ memoriesCount = memResult?.count || 0;
996
+ // Count clusters
997
+ try {
998
+ const clusterResult = db.prepare('SELECT COUNT(*) as count FROM session_clusters').get();
999
+ clustersCount = clusterResult?.count || 0;
1000
+ }
1001
+ catch {
1002
+ // Table might not exist
1003
+ }
1004
+ // Get last update time
1005
+ const lastMemory = db.prepare('SELECT MAX(updated_at) as last FROM memories').get();
1006
+ lastUpdated = lastMemory?.last;
1007
+ db.close();
1008
+ }
1009
+ catch {
1010
+ // Database might be locked or corrupted
1011
+ }
1012
+ }
1013
+ // Convert project ID back to approximate path
1014
+ const approximatePath = projectId
1015
+ .replace(/^([a-z])--/, '$1:/') // d-- -> d:/
1016
+ .replace(/--/g, '/')
1017
+ .replace(/-/g, ' ');
1018
+ projects.push({
1019
+ id: projectId,
1020
+ path: approximatePath,
1021
+ memoriesCount,
1022
+ clustersCount,
1023
+ lastUpdated
1024
+ });
1025
+ }
1026
+ // Sort by last updated (most recent first)
1027
+ return projects.sort((a, b) => {
1028
+ if (!a.lastUpdated)
1029
+ return 1;
1030
+ if (!b.lastUpdated)
1031
+ return -1;
1032
+ return b.lastUpdated.localeCompare(a.lastUpdated);
1033
+ });
1034
+ }
1035
+ /**
1036
+ * Get memories from another project by ID
1037
+ */
1038
+ export function getMemoriesFromProject(projectId) {
1039
+ const projectsDir = join(getCCWHome(), 'projects');
1040
+ const coreMemoryDb = join(projectsDir, projectId, 'core-memory', 'core_memory.db');
1041
+ if (!existsSync(coreMemoryDb)) {
1042
+ throw new Error(`Project not found: ${projectId}`);
1043
+ }
1044
+ const db = new Database(coreMemoryDb, { readonly: true });
1045
+ const stmt = db.prepare('SELECT * FROM memories ORDER BY updated_at DESC');
1046
+ const rows = stmt.all();
1047
+ db.close();
1048
+ return rows.map(row => ({
1049
+ id: row.id,
1050
+ content: row.content,
1051
+ summary: row.summary || '',
1052
+ raw_output: row.raw_output,
1053
+ created_at: row.created_at,
1054
+ updated_at: row.updated_at,
1055
+ archived: Boolean(row.archived),
1056
+ metadata: row.metadata
1057
+ }));
1058
+ }
1059
+ /**
1060
+ * Find a memory by ID across all projects
1061
+ * Searches through all project databases to locate a specific memory
1062
+ */
1063
+ export function findMemoryAcrossProjects(memoryId) {
1064
+ const projectsDir = join(getCCWHome(), 'projects');
1065
+ if (!existsSync(projectsDir)) {
1066
+ return null;
1067
+ }
1068
+ const entries = readdirSync(projectsDir, { withFileTypes: true });
1069
+ for (const entry of entries) {
1070
+ if (!entry.isDirectory())
1071
+ continue;
1072
+ const projectId = entry.name;
1073
+ const coreMemoryDb = join(projectsDir, projectId, 'core-memory', 'core_memory.db');
1074
+ if (!existsSync(coreMemoryDb))
1075
+ continue;
1076
+ try {
1077
+ const db = new Database(coreMemoryDb, { readonly: true });
1078
+ const row = db.prepare('SELECT * FROM memories WHERE id = ?').get(memoryId);
1079
+ db.close();
1080
+ if (row) {
1081
+ return {
1082
+ memory: {
1083
+ id: row.id,
1084
+ content: row.content,
1085
+ summary: row.summary || '',
1086
+ raw_output: row.raw_output,
1087
+ created_at: row.created_at,
1088
+ updated_at: row.updated_at,
1089
+ archived: Boolean(row.archived),
1090
+ metadata: row.metadata
1091
+ },
1092
+ projectId
1093
+ };
1094
+ }
1095
+ }
1096
+ catch {
1097
+ // Database might be locked or corrupted, skip
1098
+ }
1099
+ }
1100
+ return null;
1101
+ }
1102
+ /**
1103
+ * Export memories to a JSON file
1104
+ */
1105
+ export function exportMemories(projectPath, outputPath, options) {
1106
+ const store = getCoreMemoryStore(projectPath);
1107
+ let memories = store.getMemories({ archived: options?.includeArchived || false, limit: 10000 });
1108
+ // Filter by IDs if specified
1109
+ if (options?.ids && options.ids.length > 0) {
1110
+ const idSet = new Set(options.ids);
1111
+ memories = memories.filter(m => idSet.has(m.id));
1112
+ }
1113
+ const exportData = {
1114
+ version: '1.0',
1115
+ exportedAt: new Date().toISOString(),
1116
+ sourceProject: projectPath,
1117
+ memories
1118
+ };
1119
+ writeFileSync(outputPath, JSON.stringify(exportData, null, 2), 'utf-8');
1120
+ return memories.length;
1121
+ }
1122
+ /**
1123
+ * Import memories from a JSON file or another project
1124
+ */
1125
+ export function importMemories(targetProjectPath, source, // File path or project ID
1126
+ options) {
1127
+ const store = getCoreMemoryStore(targetProjectPath);
1128
+ let memories;
1129
+ // Check if source is a file or project ID
1130
+ if (existsSync(source) && source.endsWith('.json')) {
1131
+ // Import from file
1132
+ const content = readFileSync(source, 'utf-8');
1133
+ const data = JSON.parse(content);
1134
+ memories = data.memories;
1135
+ }
1136
+ else {
1137
+ // Import from project ID
1138
+ memories = getMemoriesFromProject(source);
1139
+ }
1140
+ let imported = 0;
1141
+ let skipped = 0;
1142
+ for (const memory of memories) {
1143
+ // Generate new ID with optional prefix
1144
+ let newId = memory.id;
1145
+ if (options?.prefix) {
1146
+ newId = `${options.prefix}-${memory.id}`;
1147
+ }
1148
+ // Check if already exists
1149
+ const existing = store.getMemory(newId);
1150
+ if (existing && !options?.overwrite) {
1151
+ skipped++;
1152
+ continue;
1153
+ }
1154
+ // Import memory
1155
+ store.upsertMemory({
1156
+ id: newId,
1157
+ content: memory.content,
1158
+ summary: memory.summary,
1159
+ raw_output: memory.raw_output,
1160
+ metadata: memory.metadata
1161
+ });
1162
+ imported++;
1163
+ }
1164
+ return { imported, skipped };
1165
+ }
1166
+ /**
1167
+ * Close all store instances
1168
+ */
1169
+ export function closeAllStores() {
1170
+ const stores = Array.from(storeCache.values());
1171
+ for (const store of stores) {
1172
+ store.close();
1173
+ }
1174
+ storeCache.clear();
1175
+ }
1176
+ export default CoreMemoryStore;
1177
+ //# sourceMappingURL=core-memory-store.js.map