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,890 @@
1
+ /**
2
+ * Memory Command - Context tracking and prompt optimization
3
+ * Provides CLI interface for Memory module operations
4
+ */
5
+ import chalk from 'chalk';
6
+ import { getMemoryStore } from '../core/memory-store.js';
7
+ import { HistoryImporter } from '../core/history-importer.js';
8
+ import { notifyMemoryUpdate, notifyRefreshRequired } from '../tools/notifier.js';
9
+ import { join } from 'path';
10
+ import { existsSync, readdirSync } from 'fs';
11
+ import { StoragePaths } from '../config/storage-paths.js';
12
+ import { generateEmbeddings, searchMemories, getEmbeddingStatus, isEmbedderAvailable } from '../core/memory-embedder-bridge.js';
13
+ import { getCoreMemoryStore } from '../core/core-memory-store.js';
14
+ import { CliHistoryStore } from '../tools/cli-history-store.js';
15
+ /**
16
+ * Read JSON data from stdin (for Claude Code hooks)
17
+ */
18
+ async function readStdin() {
19
+ return new Promise((resolve) => {
20
+ let data = '';
21
+ process.stdin.setEncoding('utf8');
22
+ process.stdin.on('readable', () => {
23
+ let chunk;
24
+ while ((chunk = process.stdin.read()) !== null) {
25
+ data += chunk;
26
+ }
27
+ });
28
+ process.stdin.on('end', () => {
29
+ resolve(data);
30
+ });
31
+ // Handle case where stdin is empty or not piped
32
+ if (process.stdin.isTTY) {
33
+ resolve('');
34
+ }
35
+ });
36
+ }
37
+ /**
38
+ * Normalize file path for consistent storage
39
+ */
40
+ function normalizePath(filePath) {
41
+ // Convert Windows paths to forward slashes and remove drive letter variations
42
+ return filePath
43
+ .replace(/\\/g, '/')
44
+ .replace(/^[A-Za-z]:/, (match) => match.toLowerCase());
45
+ }
46
+ /**
47
+ * Get project path from hook data or current working directory
48
+ */
49
+ function getProjectPath(hookCwd) {
50
+ // Prefer hook's cwd (actual project workspace) over process.cwd()
51
+ return hookCwd || process.cwd();
52
+ }
53
+ /**
54
+ * Track entity access (used by hooks)
55
+ */
56
+ async function trackAction(options) {
57
+ let { type, action, value, session, stdin } = options;
58
+ let hookCwd;
59
+ // If --stdin flag is set, read from stdin (Claude Code hook format)
60
+ if (stdin) {
61
+ try {
62
+ const stdinData = await readStdin();
63
+ if (stdinData) {
64
+ const hookData = JSON.parse(stdinData);
65
+ session = hookData.session_id || session;
66
+ hookCwd = hookData.cwd; // Extract workspace path from hook
67
+ // Extract value based on hook event
68
+ if (hookData.tool_input) {
69
+ // PostToolUse event
70
+ value = hookData.tool_input.file_path ||
71
+ hookData.tool_input.paths ||
72
+ hookData.tool_input.path ||
73
+ JSON.stringify(hookData.tool_input);
74
+ }
75
+ else if (hookData.prompt) {
76
+ // UserPromptSubmit event
77
+ value = hookData.prompt;
78
+ }
79
+ }
80
+ }
81
+ catch {
82
+ // Silently continue if stdin parsing fails
83
+ }
84
+ }
85
+ if (!type || !action) {
86
+ console.error(chalk.red('Error: --type and --action are required'));
87
+ console.error(chalk.gray('Usage: ccw memory track --type file --action read --value "path" --session "id"'));
88
+ console.error(chalk.gray(' ccw memory track --type file --action read --stdin'));
89
+ process.exit(1);
90
+ }
91
+ // Validate type and action
92
+ const validTypes = ['file', 'module', 'topic', 'url'];
93
+ const validActions = ['read', 'write', 'mention'];
94
+ if (!validTypes.includes(type)) {
95
+ if (!stdin) {
96
+ console.error(chalk.red(`Error: Invalid type "${type}". Must be one of: ${validTypes.join(', ')}`));
97
+ }
98
+ process.exit(stdin ? 0 : 1);
99
+ }
100
+ if (!validActions.includes(action)) {
101
+ if (!stdin) {
102
+ console.error(chalk.red(`Error: Invalid action "${action}". Must be one of: ${validActions.join(', ')}`));
103
+ }
104
+ process.exit(stdin ? 0 : 1);
105
+ }
106
+ // Skip if no value provided
107
+ if (!value) {
108
+ if (stdin) {
109
+ process.exit(0);
110
+ }
111
+ console.error(chalk.red('Error: --value is required'));
112
+ process.exit(1);
113
+ }
114
+ try {
115
+ const projectPath = getProjectPath(hookCwd);
116
+ const store = getMemoryStore(projectPath);
117
+ const now = new Date().toISOString();
118
+ // Normalize value for file types
119
+ const normalizedValue = type === 'file' ? normalizePath(value) : value.toLowerCase();
120
+ // Upsert entity
121
+ const entityId = store.upsertEntity({
122
+ type: type,
123
+ value: value,
124
+ normalized_value: normalizedValue,
125
+ first_seen_at: now,
126
+ last_seen_at: now
127
+ });
128
+ // Log access
129
+ store.logAccess({
130
+ entity_id: entityId,
131
+ action: action,
132
+ session_id: session,
133
+ timestamp: now
134
+ });
135
+ // Update statistics
136
+ store.updateStats(entityId, action);
137
+ // Calculate heat score periodically (every 10th access)
138
+ const stats = store.getStats(entityId);
139
+ if (stats) {
140
+ const totalAccess = stats.read_count + stats.write_count + stats.mention_count;
141
+ if (totalAccess % 10 === 0) {
142
+ store.calculateHeatScore(entityId);
143
+ }
144
+ }
145
+ // Notify server of memory update (best-effort, non-blocking)
146
+ notifyMemoryUpdate({
147
+ entityType: type,
148
+ entityId: String(entityId),
149
+ action: action
150
+ }).catch(() => { });
151
+ if (stdin) {
152
+ // Silent mode for hooks - just exit successfully
153
+ process.exit(0);
154
+ }
155
+ console.log(chalk.green('✓ Tracked:'), chalk.cyan(`${type}:${action}`), chalk.gray(value));
156
+ }
157
+ catch (error) {
158
+ if (stdin) {
159
+ // Silent failure for hooks
160
+ process.exit(0);
161
+ }
162
+ console.error(chalk.red(`Error tracking: ${error.message}`));
163
+ process.exit(1);
164
+ }
165
+ }
166
+ /**
167
+ * Import Claude Code history
168
+ */
169
+ async function importAction(options) {
170
+ const { source = 'all', project } = options;
171
+ console.log(chalk.bold.cyan('\n Importing Claude Code History\n'));
172
+ console.log(chalk.gray(` Source: ${source}`));
173
+ if (project) {
174
+ console.log(chalk.gray(` Project: ${project}`));
175
+ }
176
+ try {
177
+ const projectPath = getProjectPath();
178
+ const paths = StoragePaths.project(projectPath);
179
+ const dbPath = join(paths.memory, 'history.db');
180
+ // Ensure memory directory exists
181
+ const { mkdirSync } = await import('fs');
182
+ if (!existsSync(paths.memory)) {
183
+ mkdirSync(paths.memory, { recursive: true });
184
+ }
185
+ const importer = new HistoryImporter(dbPath);
186
+ let totalImported = 0;
187
+ let totalSkipped = 0;
188
+ let totalErrors = 0;
189
+ // Import global history
190
+ if (source === 'all' || source === 'history') {
191
+ console.log(chalk.gray('\n Importing global history...'));
192
+ const globalResult = await importer.importGlobalHistory();
193
+ totalImported += globalResult.imported;
194
+ totalSkipped += globalResult.skipped;
195
+ totalErrors += globalResult.errors;
196
+ console.log(chalk.gray(` Imported: ${globalResult.imported}, Skipped: ${globalResult.skipped}, Errors: ${globalResult.errors}`));
197
+ }
198
+ // Import project sessions
199
+ if (source === 'all' || source === 'sessions') {
200
+ const claudeHome = process.env.USERPROFILE || process.env.HOME || '';
201
+ const projectsDir = join(claudeHome, '.claude', 'projects');
202
+ if (existsSync(projectsDir)) {
203
+ const projects = project
204
+ ? [project]
205
+ : readdirSync(projectsDir).filter(f => {
206
+ const fullPath = join(projectsDir, f);
207
+ return existsSync(fullPath) && require('fs').statSync(fullPath).isDirectory();
208
+ });
209
+ for (const proj of projects) {
210
+ console.log(chalk.gray(`\n Importing sessions for: ${proj}...`));
211
+ const sessionResult = await importer.importProjectSessions(proj);
212
+ totalImported += sessionResult.imported;
213
+ totalSkipped += sessionResult.skipped;
214
+ totalErrors += sessionResult.errors;
215
+ console.log(chalk.gray(` Imported: ${sessionResult.imported}, Skipped: ${sessionResult.skipped}, Errors: ${sessionResult.errors}`));
216
+ }
217
+ }
218
+ }
219
+ importer.close();
220
+ console.log(chalk.bold.green('\n Import Complete\n'));
221
+ console.log(chalk.gray(` Total Imported: ${totalImported}`));
222
+ console.log(chalk.gray(` Total Skipped: ${totalSkipped}`));
223
+ console.log(chalk.gray(` Total Errors: ${totalErrors}`));
224
+ console.log(chalk.gray(` Database: ${dbPath}\n`));
225
+ // Notify server to refresh memory data
226
+ if (totalImported > 0) {
227
+ notifyRefreshRequired('memory').catch(() => { });
228
+ }
229
+ }
230
+ catch (error) {
231
+ console.error(chalk.red(`\n Error importing: ${error.message}\n`));
232
+ process.exit(1);
233
+ }
234
+ }
235
+ /**
236
+ * Show hotspot statistics
237
+ */
238
+ async function statsAction(options) {
239
+ const { type, limit = '20', sort = 'heat', json } = options;
240
+ const limitNum = parseInt(limit, 10);
241
+ try {
242
+ const projectPath = getProjectPath();
243
+ const store = getMemoryStore(projectPath);
244
+ // Get hot entities
245
+ const hotEntities = store.getHotEntities(limitNum * 2); // Get more to filter
246
+ // Filter by type if specified
247
+ let filtered = type
248
+ ? hotEntities.filter((e) => e.type === type)
249
+ : hotEntities;
250
+ // Sort by specified field
251
+ if (sort === 'reads') {
252
+ filtered.sort((a, b) => b.stats.read_count - a.stats.read_count);
253
+ }
254
+ else if (sort === 'writes') {
255
+ filtered.sort((a, b) => b.stats.write_count - a.stats.write_count);
256
+ }
257
+ // Default is already sorted by heat_score
258
+ // Limit results
259
+ filtered = filtered.slice(0, limitNum);
260
+ if (json) {
261
+ const output = filtered.map((e) => ({
262
+ type: e.type,
263
+ value: e.value,
264
+ reads: e.stats.read_count,
265
+ writes: e.stats.write_count,
266
+ mentions: e.stats.mention_count,
267
+ heat: Math.round(e.stats.heat_score * 100) / 100,
268
+ lastSeen: e.last_seen_at
269
+ }));
270
+ console.log(JSON.stringify(output, null, 2));
271
+ return;
272
+ }
273
+ console.log(chalk.bold.cyan('\n Memory Hotspot Statistics\n'));
274
+ if (type) {
275
+ console.log(chalk.gray(` Type: ${type}`));
276
+ }
277
+ console.log(chalk.gray(` Sort: ${sort} | Limit: ${limit}\n`));
278
+ if (filtered.length === 0) {
279
+ console.log(chalk.yellow(' No data yet. Use hooks to track file access or run:'));
280
+ console.log(chalk.gray(' ccw memory track --type file --action read --value "path/to/file"'));
281
+ console.log(chalk.gray(' ccw memory import --source all\n'));
282
+ return;
283
+ }
284
+ // Display table header
285
+ console.log(chalk.gray(' ─────────────────────────────────────────────────────────────────'));
286
+ console.log(chalk.bold(' Type ') +
287
+ chalk.bold('Heat ') +
288
+ chalk.bold('R ') +
289
+ chalk.bold('W ') +
290
+ chalk.bold('M ') +
291
+ chalk.bold('Value'));
292
+ console.log(chalk.gray(' ─────────────────────────────────────────────────────────────────'));
293
+ for (const entity of filtered) {
294
+ const typeStr = entity.type.padEnd(8);
295
+ const heatStr = entity.stats.heat_score.toFixed(1).padStart(6);
296
+ const readStr = String(entity.stats.read_count).padStart(3);
297
+ const writeStr = String(entity.stats.write_count).padStart(3);
298
+ const mentionStr = String(entity.stats.mention_count).padStart(3);
299
+ // Truncate value if too long
300
+ const maxValueLen = 40;
301
+ let valueStr = entity.value;
302
+ if (valueStr.length > maxValueLen) {
303
+ valueStr = '...' + valueStr.slice(-maxValueLen + 3);
304
+ }
305
+ // Color based on type
306
+ const typeColor = entity.type === 'file' ? chalk.blue :
307
+ entity.type === 'module' ? chalk.magenta :
308
+ entity.type === 'topic' ? chalk.yellow : chalk.gray;
309
+ console.log(' ' +
310
+ typeColor(typeStr) +
311
+ chalk.cyan(heatStr) + ' ' +
312
+ chalk.green(readStr) + ' ' +
313
+ chalk.red(writeStr) + ' ' +
314
+ chalk.yellow(mentionStr) + ' ' +
315
+ chalk.gray(valueStr));
316
+ }
317
+ console.log(chalk.gray(' ─────────────────────────────────────────────────────────────────'));
318
+ console.log(chalk.gray(`\n R=Reads, W=Writes, M=Mentions, Heat=Composite score\n`));
319
+ }
320
+ catch (error) {
321
+ if (json) {
322
+ console.log(JSON.stringify({ error: error.message }, null, 2));
323
+ }
324
+ else {
325
+ console.error(chalk.red(`\n Error: ${error.message}\n`));
326
+ }
327
+ process.exit(1);
328
+ }
329
+ }
330
+ /**
331
+ * Search through prompt history
332
+ */
333
+ async function searchAction(query, options) {
334
+ if (!query) {
335
+ console.error(chalk.red('Error: Search query is required'));
336
+ console.error(chalk.gray('Usage: ccw memory search "<query>"'));
337
+ process.exit(1);
338
+ }
339
+ const { limit = '20', json } = options;
340
+ const limitNum = parseInt(limit, 10);
341
+ try {
342
+ const projectPath = getProjectPath();
343
+ const store = getMemoryStore(projectPath);
344
+ // Search prompts using FTS
345
+ const results = store.searchPrompts(query, limitNum);
346
+ if (json) {
347
+ const output = results.map((p) => ({
348
+ id: p.id,
349
+ sessionId: p.session_id,
350
+ prompt: p.prompt_text?.substring(0, 200) + (p.prompt_text && p.prompt_text.length > 200 ? '...' : ''),
351
+ timestamp: p.timestamp,
352
+ intentLabel: p.intent_label
353
+ }));
354
+ console.log(JSON.stringify(output, null, 2));
355
+ return;
356
+ }
357
+ console.log(chalk.bold.cyan('\n Searching Prompt History\n'));
358
+ console.log(chalk.gray(` Query: ${query}`));
359
+ console.log(chalk.gray(` Limit: ${limit}\n`));
360
+ if (results.length === 0) {
361
+ console.log(chalk.yellow(' No results found.'));
362
+ console.log(chalk.gray(' Try importing history first: ccw memory import --source all\n'));
363
+ return;
364
+ }
365
+ console.log(chalk.gray(' ─────────────────────────────────────────────────────────────────'));
366
+ for (const prompt of results) {
367
+ const timestamp = new Date(prompt.timestamp).toLocaleString();
368
+ const preview = prompt.prompt_text?.substring(0, 80).replace(/\n/g, ' ') || '(no content)';
369
+ console.log(chalk.gray(` ${timestamp}`));
370
+ console.log(chalk.white(` ${preview}${preview.length >= 80 ? '...' : ''}`));
371
+ if (prompt.intent_label) {
372
+ console.log(chalk.cyan(` Intent: ${prompt.intent_label}`));
373
+ }
374
+ console.log(chalk.gray(' ─────────────────────────────────────────────────────────────────'));
375
+ }
376
+ console.log(chalk.gray(`\n Found ${results.length} result(s)\n`));
377
+ }
378
+ catch (error) {
379
+ if (json) {
380
+ console.log(JSON.stringify({ error: error.message }, null, 2));
381
+ }
382
+ else {
383
+ console.error(chalk.red(`\n Error: ${error.message}\n`));
384
+ }
385
+ process.exit(1);
386
+ }
387
+ }
388
+ /**
389
+ * Get optimization suggestions based on similar successful prompts
390
+ */
391
+ async function suggestAction(options) {
392
+ const { context, limit = '5', json } = options;
393
+ const limitNum = parseInt(limit, 10);
394
+ try {
395
+ const projectPath = getProjectPath();
396
+ const store = getMemoryStore(projectPath);
397
+ // Get hot entities for suggestions
398
+ const hotEntities = store.getHotEntities(limitNum);
399
+ const suggestions = hotEntities.map((e) => ({
400
+ type: e.type,
401
+ value: e.value,
402
+ reason: `Frequently accessed (${e.stats.read_count} reads, ${e.stats.write_count} writes)`,
403
+ heat: e.stats.heat_score
404
+ }));
405
+ if (json) {
406
+ console.log(JSON.stringify({ suggestions, context }, null, 2));
407
+ return;
408
+ }
409
+ console.log(chalk.bold.cyan('\n Memory Optimization Suggestions\n'));
410
+ if (context) {
411
+ console.log(chalk.gray(` Context: ${context}\n`));
412
+ }
413
+ if (suggestions.length === 0) {
414
+ console.log(chalk.yellow(' No suggestions available yet.'));
415
+ console.log(chalk.gray(' Track more file access to get suggestions.\n'));
416
+ return;
417
+ }
418
+ console.log(chalk.gray(' Based on your access patterns:\n'));
419
+ for (let i = 0; i < suggestions.length; i++) {
420
+ const s = suggestions[i];
421
+ console.log(chalk.cyan(` ${i + 1}. ${s.type}: `) + chalk.white(s.value));
422
+ console.log(chalk.gray(` ${s.reason}`));
423
+ }
424
+ console.log(chalk.gray('\n Tip: Include frequently accessed files in your context for better results.\n'));
425
+ }
426
+ catch (error) {
427
+ if (json) {
428
+ console.log(JSON.stringify({ error: error.message }, null, 2));
429
+ }
430
+ else {
431
+ console.error(chalk.red(`\n Error: ${error.message}\n`));
432
+ }
433
+ process.exit(1);
434
+ }
435
+ }
436
+ /**
437
+ * Parse age string to milliseconds
438
+ */
439
+ function parseAge(ageStr) {
440
+ const match = ageStr.match(/^(\d+)([dhm])$/);
441
+ if (!match) {
442
+ throw new Error(`Invalid age format: ${ageStr}. Use format like 30d, 24h, or 60m`);
443
+ }
444
+ const value = parseInt(match[1], 10);
445
+ const unit = match[2];
446
+ switch (unit) {
447
+ case 'd': return value * 24 * 60 * 60 * 1000;
448
+ case 'h': return value * 60 * 60 * 1000;
449
+ case 'm': return value * 60 * 1000;
450
+ default: throw new Error(`Unknown unit: ${unit}`);
451
+ }
452
+ }
453
+ /**
454
+ * Clean up old data
455
+ */
456
+ async function pruneAction(options) {
457
+ const { olderThan = '30d', dryRun } = options;
458
+ console.log(chalk.bold.cyan('\n Pruning Memory Data\n'));
459
+ console.log(chalk.gray(` Older than: ${olderThan}`));
460
+ console.log(chalk.gray(` Mode: ${dryRun ? 'Dry run (preview)' : 'Delete'}\n`));
461
+ try {
462
+ const ageMs = parseAge(olderThan);
463
+ const cutoffDate = new Date(Date.now() - ageMs);
464
+ const cutoffStr = cutoffDate.toISOString();
465
+ const projectPath = getProjectPath();
466
+ const paths = StoragePaths.project(projectPath);
467
+ if (!existsSync(paths.memoryDb)) {
468
+ console.log(chalk.yellow(' No memory database found. Nothing to prune.\n'));
469
+ return;
470
+ }
471
+ // Use direct database access for pruning
472
+ const Database = require('better-sqlite3');
473
+ const db = new Database(paths.memoryDb);
474
+ // Count records to prune
475
+ const accessLogsCount = db.prepare(`
476
+ SELECT COUNT(*) as count FROM access_logs WHERE timestamp < ?
477
+ `).get(cutoffStr);
478
+ const entitiesCount = db.prepare(`
479
+ SELECT COUNT(*) as count FROM entities WHERE last_seen_at < ?
480
+ `).get(cutoffStr);
481
+ console.log(chalk.gray(` Access logs to prune: ${accessLogsCount.count}`));
482
+ console.log(chalk.gray(` Entities to prune: ${entitiesCount.count}`));
483
+ if (dryRun) {
484
+ console.log(chalk.yellow('\n Dry run - no changes made.\n'));
485
+ db.close();
486
+ return;
487
+ }
488
+ if (accessLogsCount.count === 0 && entitiesCount.count === 0) {
489
+ console.log(chalk.green('\n Nothing to prune.\n'));
490
+ db.close();
491
+ return;
492
+ }
493
+ // Delete old access logs
494
+ const deleteAccessLogs = db.prepare(`DELETE FROM access_logs WHERE timestamp < ?`);
495
+ const accessResult = deleteAccessLogs.run(cutoffStr);
496
+ // Delete entities not seen recently (and their stats)
497
+ const deleteStats = db.prepare(`
498
+ DELETE FROM entity_stats WHERE entity_id IN (
499
+ SELECT id FROM entities WHERE last_seen_at < ?
500
+ )
501
+ `);
502
+ deleteStats.run(cutoffStr);
503
+ const deleteEntities = db.prepare(`DELETE FROM entities WHERE last_seen_at < ?`);
504
+ const entitiesResult = deleteEntities.run(cutoffStr);
505
+ db.close();
506
+ console.log(chalk.green(`\n Pruned ${accessResult.changes} access logs`));
507
+ console.log(chalk.green(` Pruned ${entitiesResult.changes} entities\n`));
508
+ // Notify server to refresh memory data
509
+ if (accessResult.changes > 0 || entitiesResult.changes > 0) {
510
+ notifyRefreshRequired('memory').catch(() => { });
511
+ }
512
+ }
513
+ catch (error) {
514
+ console.error(chalk.red(`\n Error: ${error.message}\n`));
515
+ process.exit(1);
516
+ }
517
+ }
518
+ /**
519
+ * Chunk and prepare memories for embedding
520
+ */
521
+ async function chunkMemoriesForEmbedding(projectPath, sourceId, force) {
522
+ const coreMemoryStore = getCoreMemoryStore(projectPath);
523
+ let chunksCreated = 0;
524
+ // 1. Chunk core memories
525
+ const memories = coreMemoryStore.getMemories({ archived: false, limit: 1000 });
526
+ for (const memory of memories) {
527
+ if (sourceId && memory.id !== sourceId)
528
+ continue;
529
+ // Check if already chunked (skip unless force)
530
+ const existingChunks = coreMemoryStore.getChunks(memory.id);
531
+ if (existingChunks.length > 0 && !force)
532
+ continue;
533
+ // Delete old chunks if force
534
+ if (force && existingChunks.length > 0) {
535
+ coreMemoryStore.deleteChunks(memory.id);
536
+ }
537
+ // Chunk the memory content
538
+ const chunks = coreMemoryStore.chunkContent(memory.content, memory.id, 'core_memory');
539
+ // Insert chunks
540
+ for (let i = 0; i < chunks.length; i++) {
541
+ coreMemoryStore.insertChunk({
542
+ source_id: memory.id,
543
+ source_type: 'core_memory',
544
+ chunk_index: i,
545
+ content: chunks[i],
546
+ created_at: new Date().toISOString()
547
+ });
548
+ chunksCreated++;
549
+ }
550
+ }
551
+ // 2. Chunk CLI history
552
+ try {
553
+ const cliHistoryStore = new CliHistoryStore(projectPath);
554
+ const history = cliHistoryStore.getHistory({ limit: 500 });
555
+ for (const exec of history.executions) {
556
+ if (sourceId && exec.id !== sourceId)
557
+ continue;
558
+ // Check if already chunked
559
+ const existingChunks = coreMemoryStore.getChunks(exec.id);
560
+ if (existingChunks.length > 0 && !force)
561
+ continue;
562
+ // Delete old chunks if force
563
+ if (force && existingChunks.length > 0) {
564
+ coreMemoryStore.deleteChunks(exec.id);
565
+ }
566
+ // Get conversation content
567
+ const conversation = cliHistoryStore.getConversation(exec.id);
568
+ if (!conversation || !conversation.turns || conversation.turns.length === 0)
569
+ continue;
570
+ // Create content from turns
571
+ const content = conversation.turns
572
+ .map((t) => `Prompt: ${t.prompt}\nOutput: ${(t.stdout || '').substring(0, 500)}`)
573
+ .join('\n---\n');
574
+ // Chunk the content
575
+ const chunks = coreMemoryStore.chunkContent(content, exec.id, 'cli_history');
576
+ // Insert chunks
577
+ for (let i = 0; i < chunks.length; i++) {
578
+ coreMemoryStore.insertChunk({
579
+ source_id: exec.id,
580
+ source_type: 'cli_history',
581
+ chunk_index: i,
582
+ content: chunks[i],
583
+ created_at: new Date().toISOString()
584
+ });
585
+ chunksCreated++;
586
+ }
587
+ }
588
+ }
589
+ catch {
590
+ // CLI history might not exist, continue
591
+ }
592
+ return chunksCreated;
593
+ }
594
+ /**
595
+ * Generate embeddings for memory chunks
596
+ */
597
+ async function embedAction(options) {
598
+ const { id, force, batchSize } = options;
599
+ try {
600
+ // Check embedder availability
601
+ if (!isEmbedderAvailable()) {
602
+ console.error(chalk.red('\nError: Memory embedder not available'));
603
+ console.error(chalk.gray('Ensure CodexLens venv exists at ~/.codexlens/venv\n'));
604
+ process.exit(1);
605
+ }
606
+ const projectPath = getProjectPath();
607
+ const paths = StoragePaths.project(projectPath);
608
+ const dbPath = join(paths.root, 'core-memory', 'core_memory.db');
609
+ if (!existsSync(dbPath)) {
610
+ console.error(chalk.red('\nError: Core memory database not found'));
611
+ console.error(chalk.gray('Create memories first using "ccw core-memory import"\n'));
612
+ process.exit(1);
613
+ }
614
+ // Step 1: Chunk memories first
615
+ console.log(chalk.cyan('Chunking memories...'));
616
+ const chunksCreated = await chunkMemoriesForEmbedding(projectPath, id, force);
617
+ if (chunksCreated > 0) {
618
+ console.log(chalk.green(` Created ${chunksCreated} new chunks`));
619
+ }
620
+ // Step 2: Generate embeddings
621
+ console.log(chalk.cyan('Generating embeddings...'));
622
+ const embedOptions = {
623
+ sourceId: id,
624
+ force: force || false,
625
+ batchSize: batchSize ? parseInt(batchSize, 10) : 8
626
+ };
627
+ const result = await generateEmbeddings(dbPath, embedOptions);
628
+ if (!result.success) {
629
+ console.error(chalk.red(`\nError: ${result.error}\n`));
630
+ process.exit(1);
631
+ }
632
+ console.log(chalk.green(`\n✓ Processed ${result.chunks_processed} chunks in ${result.elapsed_time.toFixed(1)}s`));
633
+ // Get status to show breakdown by type
634
+ const status = await getEmbeddingStatus(dbPath);
635
+ if (status.success && Object.keys(status.by_type).length > 0) {
636
+ for (const [type, stats] of Object.entries(status.by_type)) {
637
+ if (stats.total > 0) {
638
+ console.log(chalk.white(` - ${type}: ${stats.embedded} chunks`));
639
+ }
640
+ }
641
+ }
642
+ console.log();
643
+ }
644
+ catch (error) {
645
+ console.error(chalk.red(`\nError: ${error.message}\n`));
646
+ process.exit(1);
647
+ }
648
+ }
649
+ /**
650
+ * Search memories using semantic search
651
+ */
652
+ async function searchEmbedAction(query, options) {
653
+ if (!query) {
654
+ console.error(chalk.red('Error: Search query is required'));
655
+ console.error(chalk.gray('Usage: ccw memory search "<query>"'));
656
+ process.exit(1);
657
+ }
658
+ const { topK = '10', type, minScore = '0.5', json } = options;
659
+ try {
660
+ // Check embedder availability
661
+ if (!isEmbedderAvailable()) {
662
+ console.error(chalk.red('\nError: Memory embedder not available'));
663
+ console.error(chalk.gray('Ensure CodexLens venv exists at ~/.codexlens/venv\n'));
664
+ process.exit(1);
665
+ }
666
+ const projectPath = getProjectPath();
667
+ const paths = StoragePaths.project(projectPath);
668
+ const dbPath = join(paths.root, 'core-memory', 'core_memory.db');
669
+ if (!existsSync(dbPath)) {
670
+ console.error(chalk.red('\nError: Core memory database not found'));
671
+ console.error(chalk.gray('Create memories first using "ccw core-memory import"\n'));
672
+ process.exit(1);
673
+ }
674
+ const searchOptions = {
675
+ topK: parseInt(topK, 10),
676
+ minScore: parseFloat(minScore),
677
+ sourceType: type
678
+ };
679
+ const result = await searchMemories(dbPath, query, searchOptions);
680
+ if (!result.success) {
681
+ console.error(chalk.red(`\nError: ${result.error}\n`));
682
+ process.exit(1);
683
+ }
684
+ if (json) {
685
+ const output = result.matches.map(m => ({
686
+ sourceId: m.source_id,
687
+ sourceType: m.source_type,
688
+ score: m.score,
689
+ content: m.content,
690
+ restoreCommand: m.restore_command
691
+ }));
692
+ console.log(JSON.stringify(output, null, 2));
693
+ return;
694
+ }
695
+ console.log(chalk.bold.cyan(`\nFound ${result.matches.length} matches for "${query}":\n`));
696
+ if (result.matches.length === 0) {
697
+ console.log(chalk.yellow('No results found. Try:'));
698
+ console.log(chalk.gray(' - Using different keywords'));
699
+ console.log(chalk.gray(' - Lowering --min-score threshold'));
700
+ console.log(chalk.gray(' - Running "ccw memory embed" to generate embeddings\n'));
701
+ return;
702
+ }
703
+ for (let i = 0; i < result.matches.length; i++) {
704
+ const match = result.matches[i];
705
+ const preview = match.content.length > 80
706
+ ? match.content.substring(0, 80) + '...'
707
+ : match.content;
708
+ console.log(chalk.bold.white(`${i + 1}. [${match.score.toFixed(2)}] ${match.source_id}`) + chalk.gray(` (${match.source_type})`));
709
+ console.log(chalk.white(` "${preview}"`));
710
+ console.log(chalk.cyan(` → ${match.restore_command}`));
711
+ console.log();
712
+ }
713
+ }
714
+ catch (error) {
715
+ if (json) {
716
+ console.log(JSON.stringify({ error: error.message }, null, 2));
717
+ }
718
+ else {
719
+ console.error(chalk.red(`\nError: ${error.message}\n`));
720
+ }
721
+ process.exit(1);
722
+ }
723
+ }
724
+ /**
725
+ * Show embedding status
726
+ */
727
+ async function embedStatusAction(options) {
728
+ const { json } = options;
729
+ try {
730
+ // Check embedder availability
731
+ if (!isEmbedderAvailable()) {
732
+ console.error(chalk.red('\nError: Memory embedder not available'));
733
+ console.error(chalk.gray('Ensure CodexLens venv exists at ~/.codexlens/venv\n'));
734
+ process.exit(1);
735
+ }
736
+ const projectPath = getProjectPath();
737
+ const paths = StoragePaths.project(projectPath);
738
+ const dbPath = join(paths.root, 'core-memory', 'core_memory.db');
739
+ if (!existsSync(dbPath)) {
740
+ console.error(chalk.red('\nError: Core memory database not found'));
741
+ console.error(chalk.gray('Create memories first using "ccw core-memory import"\n'));
742
+ process.exit(1);
743
+ }
744
+ const status = await getEmbeddingStatus(dbPath);
745
+ if (!status.success) {
746
+ console.error(chalk.red(`\nError: ${status.error}\n`));
747
+ process.exit(1);
748
+ }
749
+ if (json) {
750
+ console.log(JSON.stringify(status, null, 2));
751
+ return;
752
+ }
753
+ const embeddedPercent = status.total_chunks > 0
754
+ ? Math.round((status.embedded_chunks / status.total_chunks) * 100)
755
+ : 0;
756
+ console.log(chalk.bold.cyan('\nEmbedding Status:'));
757
+ console.log(chalk.white(` Total chunks: ${status.total_chunks}`));
758
+ console.log(chalk.white(` Embedded: ${status.embedded_chunks} (${embeddedPercent}%)`));
759
+ console.log(chalk.white(` Pending: ${status.pending_chunks}`));
760
+ if (Object.keys(status.by_type).length > 0) {
761
+ console.log(chalk.bold.white('\nBy Type:'));
762
+ for (const [type, stats] of Object.entries(status.by_type)) {
763
+ const typePercent = stats.total > 0
764
+ ? Math.round((stats.embedded / stats.total) * 100)
765
+ : 0;
766
+ console.log(chalk.cyan(` ${type}: `) + chalk.white(`${stats.embedded}/${stats.total} (${typePercent}%)`));
767
+ }
768
+ }
769
+ console.log();
770
+ }
771
+ catch (error) {
772
+ if (json) {
773
+ console.log(JSON.stringify({ error: error.message }, null, 2));
774
+ }
775
+ else {
776
+ console.error(chalk.red(`\nError: ${error.message}\n`));
777
+ }
778
+ process.exit(1);
779
+ }
780
+ }
781
+ /**
782
+ * Memory command entry point
783
+ * @param {string} subcommand - Subcommand (track, import, stats, search, suggest, prune, embed, embed-status)
784
+ * @param {string|string[]} args - Arguments array
785
+ * @param {Object} options - CLI options
786
+ */
787
+ export async function memoryCommand(subcommand, args, options) {
788
+ const argsArray = Array.isArray(args) ? args : (args ? [args] : []);
789
+ switch (subcommand) {
790
+ case 'track':
791
+ await trackAction(options);
792
+ break;
793
+ case 'import':
794
+ await importAction(options);
795
+ break;
796
+ case 'stats':
797
+ await statsAction(options);
798
+ break;
799
+ case 'search':
800
+ // Check if this is semantic search (has --top-k or --min-score) or prompt history search
801
+ if ('topK' in options || 'minScore' in options) {
802
+ await searchEmbedAction(argsArray[0], options);
803
+ }
804
+ else {
805
+ await searchAction(argsArray[0], options);
806
+ }
807
+ break;
808
+ case 'suggest':
809
+ await suggestAction(options);
810
+ break;
811
+ case 'prune':
812
+ await pruneAction(options);
813
+ break;
814
+ case 'embed':
815
+ await embedAction(options);
816
+ break;
817
+ case 'embed-status':
818
+ await embedStatusAction(options);
819
+ break;
820
+ default:
821
+ console.log(chalk.bold.cyan('\n CCW Memory Module\n'));
822
+ console.log(' Context tracking and prompt optimization.\n');
823
+ console.log(' Subcommands:');
824
+ console.log(chalk.gray(' track Track entity access (used by hooks)'));
825
+ console.log(chalk.gray(' import Import Claude Code history'));
826
+ console.log(chalk.gray(' stats Show hotspot statistics'));
827
+ console.log(chalk.gray(' search <query> Search through prompt history (semantic or FTS)'));
828
+ console.log(chalk.gray(' suggest Get optimization suggestions'));
829
+ console.log(chalk.gray(' prune Clean up old data'));
830
+ console.log(chalk.gray(' embed Generate embeddings for semantic search'));
831
+ console.log(chalk.gray(' embed-status Show embedding generation status'));
832
+ console.log();
833
+ console.log(' Track Options:');
834
+ console.log(chalk.gray(' --type <type> Entity type: file, module, topic'));
835
+ console.log(chalk.gray(' --action <action> Action: read, write, mention'));
836
+ console.log(chalk.gray(' --value <value> Entity value (file path, etc.)'));
837
+ console.log(chalk.gray(' --session <id> Session ID (optional)'));
838
+ console.log();
839
+ console.log(' Import Options:');
840
+ console.log(chalk.gray(' --source <source> Source: history, sessions, all (default: all)'));
841
+ console.log(chalk.gray(' --project <name> Project name filter (optional)'));
842
+ console.log();
843
+ console.log(' Stats Options:');
844
+ console.log(chalk.gray(' --type <type> Filter: file, module, topic (optional)'));
845
+ console.log(chalk.gray(' --limit <n> Number of results (default: 20)'));
846
+ console.log(chalk.gray(' --sort <field> Sort by: heat, reads, writes (default: heat)'));
847
+ console.log(chalk.gray(' --json Output as JSON'));
848
+ console.log();
849
+ console.log(' Search Options (Prompt History):');
850
+ console.log(chalk.gray(' --limit <n> Number of results (default: 20)'));
851
+ console.log(chalk.gray(' --json Output as JSON'));
852
+ console.log();
853
+ console.log(' Search Options (Semantic - requires embeddings):');
854
+ console.log(chalk.gray(' --top-k <n> Number of results (default: 10)'));
855
+ console.log(chalk.gray(' --min-score <f> Minimum similarity score (default: 0.5)'));
856
+ console.log(chalk.gray(' --type <type> Filter: core_memory, workflow, cli_history'));
857
+ console.log(chalk.gray(' --json Output as JSON'));
858
+ console.log();
859
+ console.log(' Embed Options:');
860
+ console.log(chalk.gray(' --id <id> Specific memory/session ID to embed'));
861
+ console.log(chalk.gray(' --force Force re-embed all chunks'));
862
+ console.log(chalk.gray(' --batch-size <n> Batch size for embedding (default: 8)'));
863
+ console.log();
864
+ console.log(' Embed Status Options:');
865
+ console.log(chalk.gray(' --json Output as JSON'));
866
+ console.log();
867
+ console.log(' Suggest Options:');
868
+ console.log(chalk.gray(' --context <text> Current task context (optional)'));
869
+ console.log(chalk.gray(' --limit <n> Number of suggestions (default: 5)'));
870
+ console.log(chalk.gray(' --json Output as JSON'));
871
+ console.log();
872
+ console.log(' Prune Options:');
873
+ console.log(chalk.gray(' --older-than <age> Age threshold (default: 30d)'));
874
+ console.log(chalk.gray(' --dry-run Preview without deleting'));
875
+ console.log();
876
+ console.log(' Examples:');
877
+ console.log(chalk.gray(' ccw memory track --type file --action read --value "src/auth.ts"'));
878
+ console.log(chalk.gray(' ccw memory import --source history --project "my-app"'));
879
+ console.log(chalk.gray(' ccw memory stats --type file --sort heat --limit 10'));
880
+ console.log(chalk.gray(' ccw memory search "authentication patterns" # FTS search'));
881
+ console.log(chalk.gray(' ccw memory embed # Generate all embeddings'));
882
+ console.log(chalk.gray(' ccw memory embed --id CMEM-xxx # Embed specific memory'));
883
+ console.log(chalk.gray(' ccw memory embed-status # Check embedding status'));
884
+ console.log(chalk.gray(' ccw memory search "auth patterns" --top-k 5 # Semantic search'));
885
+ console.log(chalk.gray(' ccw memory suggest --context "implementing JWT auth"'));
886
+ console.log(chalk.gray(' ccw memory prune --older-than 60d --dry-run'));
887
+ console.log();
888
+ }
889
+ }
890
+ //# sourceMappingURL=memory.js.map