claude-code-workflow 6.1.4 → 6.2.1

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 (879) hide show
  1. package/README.md +145 -274
  2. package/bin/ccw-mcp.js +7 -0
  3. package/bin/ccw.js +10 -0
  4. package/dist/cli.d.ts +2 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +219 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/commands/cli.d.ts +32 -0
  9. package/dist/commands/cli.d.ts.map +1 -0
  10. package/dist/commands/cli.js +619 -0
  11. package/dist/commands/cli.js.map +1 -0
  12. package/dist/commands/core-memory.d.ts +32 -0
  13. package/dist/commands/core-memory.d.ts.map +1 -0
  14. package/dist/commands/core-memory.js +640 -0
  15. package/dist/commands/core-memory.js.map +1 -0
  16. package/dist/commands/hook.d.ts +16 -0
  17. package/dist/commands/hook.d.ts.map +1 -0
  18. package/dist/commands/hook.js +276 -0
  19. package/dist/commands/hook.js.map +1 -0
  20. package/dist/commands/install.d.ts +12 -0
  21. package/dist/commands/install.d.ts.map +1 -0
  22. package/dist/commands/install.js +443 -0
  23. package/dist/commands/install.js.map +1 -0
  24. package/dist/commands/list.d.ts +5 -0
  25. package/dist/commands/list.d.ts.map +1 -0
  26. package/dist/commands/list.js +32 -0
  27. package/dist/commands/list.js.map +1 -0
  28. package/dist/commands/memory.d.ts +57 -0
  29. package/dist/commands/memory.d.ts.map +1 -0
  30. package/dist/commands/memory.js +890 -0
  31. package/dist/commands/memory.js.map +1 -0
  32. package/dist/commands/serve.d.ts +12 -0
  33. package/dist/commands/serve.d.ts.map +1 -0
  34. package/dist/commands/serve.js +63 -0
  35. package/dist/commands/serve.js.map +1 -0
  36. package/dist/commands/session-path-resolver.d.ts +45 -0
  37. package/dist/commands/session-path-resolver.d.ts.map +1 -0
  38. package/dist/commands/session-path-resolver.js +302 -0
  39. package/dist/commands/session-path-resolver.js.map +1 -0
  40. package/dist/commands/session.d.ts +12 -0
  41. package/dist/commands/session.d.ts.map +1 -0
  42. package/dist/commands/session.js +954 -0
  43. package/dist/commands/session.js.map +1 -0
  44. package/dist/commands/stop.d.ts +11 -0
  45. package/dist/commands/stop.d.ts.map +1 -0
  46. package/dist/commands/stop.js +96 -0
  47. package/dist/commands/stop.js.map +1 -0
  48. package/dist/commands/tool.d.ts +29 -0
  49. package/dist/commands/tool.d.ts.map +1 -0
  50. package/dist/commands/tool.js +173 -0
  51. package/dist/commands/tool.js.map +1 -0
  52. package/dist/commands/uninstall.d.ts +9 -0
  53. package/dist/commands/uninstall.d.ts.map +1 -0
  54. package/dist/commands/uninstall.js +239 -0
  55. package/dist/commands/uninstall.js.map +1 -0
  56. package/dist/commands/upgrade.d.ts +10 -0
  57. package/dist/commands/upgrade.d.ts.map +1 -0
  58. package/dist/commands/upgrade.js +288 -0
  59. package/dist/commands/upgrade.js.map +1 -0
  60. package/dist/commands/view.d.ts +14 -0
  61. package/dist/commands/view.d.ts.map +1 -0
  62. package/dist/commands/view.js +100 -0
  63. package/dist/commands/view.js.map +1 -0
  64. package/dist/config/storage-paths.d.ts +184 -0
  65. package/dist/config/storage-paths.d.ts.map +1 -0
  66. package/dist/config/storage-paths.js +536 -0
  67. package/dist/config/storage-paths.js.map +1 -0
  68. package/dist/core/cache-manager.d.ts +80 -0
  69. package/dist/core/cache-manager.d.ts.map +1 -0
  70. package/dist/core/cache-manager.js +260 -0
  71. package/dist/core/cache-manager.js.map +1 -0
  72. package/dist/core/claude-freshness.d.ts +53 -0
  73. package/dist/core/claude-freshness.d.ts.map +1 -0
  74. package/dist/core/claude-freshness.js +232 -0
  75. package/dist/core/claude-freshness.js.map +1 -0
  76. package/dist/core/core-memory-store.d.ts +320 -0
  77. package/dist/core/core-memory-store.d.ts.map +1 -0
  78. package/dist/core/core-memory-store.js +1177 -0
  79. package/dist/core/core-memory-store.js.map +1 -0
  80. package/dist/core/dashboard-generator-patch.d.ts +2 -0
  81. package/dist/core/dashboard-generator-patch.d.ts.map +1 -0
  82. package/dist/core/dashboard-generator-patch.js +48 -0
  83. package/dist/core/dashboard-generator-patch.js.map +1 -0
  84. package/dist/core/dashboard-generator.d.ts +8 -0
  85. package/dist/core/dashboard-generator.d.ts.map +1 -0
  86. package/dist/core/dashboard-generator.js +695 -0
  87. package/dist/core/dashboard-generator.js.map +1 -0
  88. package/dist/core/data-aggregator.d.ts +145 -0
  89. package/dist/core/data-aggregator.d.ts.map +1 -0
  90. package/dist/core/data-aggregator.js +416 -0
  91. package/dist/core/data-aggregator.js.map +1 -0
  92. package/dist/core/history-importer.d.ts +102 -0
  93. package/dist/core/history-importer.d.ts.map +1 -0
  94. package/dist/core/history-importer.js +493 -0
  95. package/dist/core/history-importer.js.map +1 -0
  96. package/dist/core/lite-scanner-complete.d.ts +81 -0
  97. package/dist/core/lite-scanner-complete.d.ts.map +1 -0
  98. package/dist/core/lite-scanner-complete.js +368 -0
  99. package/dist/core/lite-scanner-complete.js.map +1 -0
  100. package/dist/core/lite-scanner.d.ts +81 -0
  101. package/dist/core/lite-scanner.d.ts.map +1 -0
  102. package/dist/core/lite-scanner.js +368 -0
  103. package/dist/core/lite-scanner.js.map +1 -0
  104. package/dist/core/manifest.d.ts +88 -0
  105. package/dist/core/manifest.d.ts.map +1 -0
  106. package/dist/core/manifest.js +214 -0
  107. package/dist/core/manifest.js.map +1 -0
  108. package/dist/core/memory-embedder-bridge.d.ts +83 -0
  109. package/dist/core/memory-embedder-bridge.d.ts.map +1 -0
  110. package/dist/core/memory-embedder-bridge.js +181 -0
  111. package/dist/core/memory-embedder-bridge.js.map +1 -0
  112. package/dist/core/memory-store.d.ts +249 -0
  113. package/dist/core/memory-store.d.ts.map +1 -0
  114. package/dist/core/memory-store.js +781 -0
  115. package/dist/core/memory-store.js.map +1 -0
  116. package/dist/core/routes/ccw-routes.d.ts +20 -0
  117. package/dist/core/routes/ccw-routes.d.ts.map +1 -0
  118. package/dist/core/routes/ccw-routes.js +70 -0
  119. package/dist/core/routes/ccw-routes.js.map +1 -0
  120. package/dist/core/routes/claude-routes.d.ts +19 -0
  121. package/dist/core/routes/claude-routes.d.ts.map +1 -0
  122. package/dist/core/routes/claude-routes.js +1017 -0
  123. package/dist/core/routes/claude-routes.js.map +1 -0
  124. package/dist/core/routes/cli-routes.d.ts +20 -0
  125. package/dist/core/routes/cli-routes.d.ts.map +1 -0
  126. package/dist/core/routes/cli-routes.js +468 -0
  127. package/dist/core/routes/cli-routes.js.map +1 -0
  128. package/dist/core/routes/codexlens-routes.d.ts +20 -0
  129. package/dist/core/routes/codexlens-routes.d.ts.map +1 -0
  130. package/dist/core/routes/codexlens-routes.js +754 -0
  131. package/dist/core/routes/codexlens-routes.js.map +1 -0
  132. package/dist/core/routes/core-memory-routes.d.ts +21 -0
  133. package/dist/core/routes/core-memory-routes.d.ts.map +1 -0
  134. package/dist/core/routes/core-memory-routes.js +520 -0
  135. package/dist/core/routes/core-memory-routes.js.map +1 -0
  136. package/dist/core/routes/files-routes.d.ts +20 -0
  137. package/dist/core/routes/files-routes.d.ts.map +1 -0
  138. package/dist/core/routes/files-routes.js +374 -0
  139. package/dist/core/routes/files-routes.js.map +1 -0
  140. package/dist/core/routes/graph-routes.d.ts +20 -0
  141. package/dist/core/routes/graph-routes.d.ts.map +1 -0
  142. package/dist/core/routes/graph-routes.js +517 -0
  143. package/dist/core/routes/graph-routes.js.map +1 -0
  144. package/dist/core/routes/help-routes.d.ts +20 -0
  145. package/dist/core/routes/help-routes.d.ts.map +1 -0
  146. package/dist/core/routes/help-routes.js +250 -0
  147. package/dist/core/routes/help-routes.js.map +1 -0
  148. package/dist/core/routes/hooks-routes.d.ts +21 -0
  149. package/dist/core/routes/hooks-routes.d.ts.map +1 -0
  150. package/dist/core/routes/hooks-routes.js +346 -0
  151. package/dist/core/routes/hooks-routes.js.map +1 -0
  152. package/dist/core/routes/mcp-routes.d.ts +20 -0
  153. package/dist/core/routes/mcp-routes.d.ts.map +1 -0
  154. package/dist/core/routes/mcp-routes.js +1129 -0
  155. package/dist/core/routes/mcp-routes.js.map +1 -0
  156. package/dist/core/routes/mcp-templates-db.d.ts +54 -0
  157. package/dist/core/routes/mcp-templates-db.d.ts.map +1 -0
  158. package/dist/core/routes/mcp-templates-db.js +226 -0
  159. package/dist/core/routes/mcp-templates-db.js.map +1 -0
  160. package/dist/core/routes/memory-routes.d.ts +21 -0
  161. package/dist/core/routes/memory-routes.d.ts.map +1 -0
  162. package/dist/core/routes/memory-routes.js +1095 -0
  163. package/dist/core/routes/memory-routes.js.map +1 -0
  164. package/dist/core/routes/rules-routes.d.ts +20 -0
  165. package/dist/core/routes/rules-routes.d.ts.map +1 -0
  166. package/dist/core/routes/rules-routes.js +442 -0
  167. package/dist/core/routes/rules-routes.js.map +1 -0
  168. package/dist/core/routes/session-routes.d.ts +20 -0
  169. package/dist/core/routes/session-routes.d.ts.map +1 -0
  170. package/dist/core/routes/session-routes.js +423 -0
  171. package/dist/core/routes/session-routes.js.map +1 -0
  172. package/dist/core/routes/skills-routes.d.ts +20 -0
  173. package/dist/core/routes/skills-routes.d.ts.map +1 -0
  174. package/dist/core/routes/skills-routes.js +533 -0
  175. package/dist/core/routes/skills-routes.js.map +1 -0
  176. package/dist/core/routes/status-routes.d.ts +20 -0
  177. package/dist/core/routes/status-routes.d.ts.map +1 -0
  178. package/dist/core/routes/status-routes.js +38 -0
  179. package/dist/core/routes/status-routes.js.map +1 -0
  180. package/dist/core/routes/system-routes.d.ts +22 -0
  181. package/dist/core/routes/system-routes.d.ts.map +1 -0
  182. package/dist/core/routes/system-routes.js +354 -0
  183. package/dist/core/routes/system-routes.js.map +1 -0
  184. package/dist/core/server.d.ts +17 -0
  185. package/dist/core/server.d.ts.map +1 -0
  186. package/dist/core/server.js +386 -0
  187. package/dist/core/server.js.map +1 -0
  188. package/dist/core/session-clustering-service.d.ts +153 -0
  189. package/dist/core/session-clustering-service.d.ts.map +1 -0
  190. package/dist/core/session-clustering-service.js +1065 -0
  191. package/dist/core/session-clustering-service.js.map +1 -0
  192. package/dist/core/session-scanner.d.ts +32 -0
  193. package/dist/core/session-scanner.d.ts.map +1 -0
  194. package/dist/core/session-scanner.js +253 -0
  195. package/dist/core/session-scanner.js.map +1 -0
  196. package/dist/core/websocket.d.ts +23 -0
  197. package/dist/core/websocket.d.ts.map +1 -0
  198. package/dist/core/websocket.js +168 -0
  199. package/dist/core/websocket.js.map +1 -0
  200. package/dist/index.d.ts +10 -0
  201. package/dist/index.d.ts.map +1 -0
  202. package/dist/index.js +10 -0
  203. package/dist/index.js.map +1 -0
  204. package/dist/mcp-server/index.d.ts +7 -0
  205. package/dist/mcp-server/index.d.ts.map +1 -0
  206. package/dist/mcp-server/index.js +157 -0
  207. package/dist/mcp-server/index.js.map +1 -0
  208. package/dist/tools/classify-folders.d.ts +26 -0
  209. package/dist/tools/classify-folders.d.ts.map +1 -0
  210. package/dist/tools/classify-folders.js +201 -0
  211. package/dist/tools/classify-folders.js.map +1 -0
  212. package/dist/tools/cli-config-manager.d.ts +62 -0
  213. package/dist/tools/cli-config-manager.d.ts.map +1 -0
  214. package/dist/tools/cli-config-manager.js +221 -0
  215. package/dist/tools/cli-config-manager.js.map +1 -0
  216. package/dist/tools/cli-executor.d.ts +373 -0
  217. package/dist/tools/cli-executor.d.ts.map +1 -0
  218. package/dist/tools/cli-executor.js +1625 -0
  219. package/dist/tools/cli-executor.js.map +1 -0
  220. package/dist/tools/cli-history-store.d.ts +330 -0
  221. package/dist/tools/cli-history-store.d.ts.map +1 -0
  222. package/dist/tools/cli-history-store.js +916 -0
  223. package/dist/tools/cli-history-store.js.map +1 -0
  224. package/dist/tools/codex-lens.d.ts +118 -0
  225. package/dist/tools/codex-lens.d.ts.map +1 -0
  226. package/dist/tools/codex-lens.js +962 -0
  227. package/dist/tools/codex-lens.js.map +1 -0
  228. package/dist/tools/convert-tokens-to-css.d.ts +14 -0
  229. package/dist/tools/convert-tokens-to-css.d.ts.map +1 -0
  230. package/dist/tools/convert-tokens-to-css.js +244 -0
  231. package/dist/tools/convert-tokens-to-css.js.map +1 -0
  232. package/dist/tools/core-memory.d.ts +66 -0
  233. package/dist/tools/core-memory.d.ts.map +1 -0
  234. package/dist/tools/core-memory.js +324 -0
  235. package/dist/tools/core-memory.js.map +1 -0
  236. package/dist/tools/detect-changed-modules.d.ts +24 -0
  237. package/dist/tools/detect-changed-modules.d.ts.map +1 -0
  238. package/dist/tools/detect-changed-modules.js +277 -0
  239. package/dist/tools/detect-changed-modules.js.map +1 -0
  240. package/dist/tools/discover-design-files.d.ts +36 -0
  241. package/dist/tools/discover-design-files.d.ts.map +1 -0
  242. package/dist/tools/discover-design-files.js +147 -0
  243. package/dist/tools/discover-design-files.js.map +1 -0
  244. package/dist/tools/edit-file.d.ts +28 -0
  245. package/dist/tools/edit-file.d.ts.map +1 -0
  246. package/dist/tools/edit-file.js +479 -0
  247. package/dist/tools/edit-file.js.map +1 -0
  248. package/dist/tools/generate-module-docs.d.ts +22 -0
  249. package/dist/tools/generate-module-docs.d.ts.map +1 -0
  250. package/dist/tools/generate-module-docs.js +379 -0
  251. package/dist/tools/generate-module-docs.js.map +1 -0
  252. package/dist/tools/get-modules-by-depth.d.ts +15 -0
  253. package/dist/tools/get-modules-by-depth.d.ts.map +1 -0
  254. package/dist/tools/get-modules-by-depth.js +296 -0
  255. package/dist/tools/get-modules-by-depth.js.map +1 -0
  256. package/dist/tools/index.d.ts +55 -0
  257. package/dist/tools/index.d.ts.map +1 -0
  258. package/dist/tools/index.js +304 -0
  259. package/dist/tools/index.js.map +1 -0
  260. package/dist/tools/native-session-discovery.d.ts +97 -0
  261. package/dist/tools/native-session-discovery.d.ts.map +1 -0
  262. package/dist/tools/native-session-discovery.js +700 -0
  263. package/dist/tools/native-session-discovery.js.map +1 -0
  264. package/dist/tools/notifier.d.ts +50 -0
  265. package/dist/tools/notifier.d.ts.map +1 -0
  266. package/dist/tools/notifier.js +90 -0
  267. package/dist/tools/notifier.js.map +1 -0
  268. package/dist/tools/read-file.d.ts +32 -0
  269. package/dist/tools/read-file.d.ts.map +1 -0
  270. package/dist/tools/read-file.js +329 -0
  271. package/dist/tools/read-file.js.map +1 -0
  272. package/dist/tools/resume-strategy.d.ts +48 -0
  273. package/dist/tools/resume-strategy.d.ts.map +1 -0
  274. package/dist/tools/resume-strategy.js +248 -0
  275. package/dist/tools/resume-strategy.js.map +1 -0
  276. package/dist/tools/session-content-parser.d.ts +58 -0
  277. package/dist/tools/session-content-parser.d.ts.map +1 -0
  278. package/dist/tools/session-content-parser.js +420 -0
  279. package/dist/tools/session-content-parser.js.map +1 -0
  280. package/dist/tools/session-manager.d.ts +9 -0
  281. package/dist/tools/session-manager.d.ts.map +1 -0
  282. package/dist/tools/session-manager.js +834 -0
  283. package/dist/tools/session-manager.js.map +1 -0
  284. package/dist/tools/smart-context.d.ts +35 -0
  285. package/dist/tools/smart-context.d.ts.map +1 -0
  286. package/dist/tools/smart-context.js +182 -0
  287. package/dist/tools/smart-context.js.map +1 -0
  288. package/dist/tools/smart-search.d.ts +105 -0
  289. package/dist/tools/smart-search.d.ts.map +1 -0
  290. package/dist/tools/smart-search.js +1753 -0
  291. package/dist/tools/smart-search.js.map +1 -0
  292. package/dist/tools/storage-manager.d.ts +114 -0
  293. package/dist/tools/storage-manager.d.ts.map +1 -0
  294. package/dist/tools/storage-manager.js +392 -0
  295. package/dist/tools/storage-manager.js.map +1 -0
  296. package/dist/tools/ui-generate-preview.d.ts +39 -0
  297. package/dist/tools/ui-generate-preview.d.ts.map +1 -0
  298. package/dist/tools/ui-generate-preview.js +300 -0
  299. package/dist/tools/ui-generate-preview.js.map +1 -0
  300. package/dist/tools/ui-instantiate-prototypes.d.ts +75 -0
  301. package/dist/tools/ui-instantiate-prototypes.d.ts.map +1 -0
  302. package/dist/tools/ui-instantiate-prototypes.js +256 -0
  303. package/dist/tools/ui-instantiate-prototypes.js.map +1 -0
  304. package/dist/tools/update-module-claude.d.ts +80 -0
  305. package/dist/tools/update-module-claude.d.ts.map +1 -0
  306. package/dist/tools/update-module-claude.js +351 -0
  307. package/dist/tools/update-module-claude.js.map +1 -0
  308. package/dist/tools/write-file.d.ts +19 -0
  309. package/dist/tools/write-file.d.ts.map +1 -0
  310. package/dist/tools/write-file.js +193 -0
  311. package/dist/tools/write-file.js.map +1 -0
  312. package/dist/types/config.d.ts +11 -0
  313. package/dist/types/config.d.ts.map +1 -0
  314. package/dist/types/config.js +2 -0
  315. package/dist/types/config.js.map +1 -0
  316. package/dist/types/index.d.ts +4 -0
  317. package/dist/types/index.d.ts.map +1 -0
  318. package/dist/types/index.js +4 -0
  319. package/dist/types/index.js.map +1 -0
  320. package/dist/types/session.d.ts +20 -0
  321. package/dist/types/session.d.ts.map +1 -0
  322. package/dist/types/session.js +2 -0
  323. package/dist/types/session.js.map +1 -0
  324. package/dist/types/tool.d.ts +36 -0
  325. package/dist/types/tool.d.ts.map +1 -0
  326. package/dist/types/tool.js +11 -0
  327. package/dist/types/tool.js.map +1 -0
  328. package/dist/utils/browser-launcher.d.ts +13 -0
  329. package/dist/utils/browser-launcher.d.ts.map +1 -0
  330. package/dist/utils/browser-launcher.js +60 -0
  331. package/dist/utils/browser-launcher.js.map +1 -0
  332. package/dist/utils/file-utils.d.ts +25 -0
  333. package/dist/utils/file-utils.d.ts.map +1 -0
  334. package/dist/utils/file-utils.js +48 -0
  335. package/dist/utils/file-utils.js.map +1 -0
  336. package/dist/utils/path-resolver.d.ts +80 -0
  337. package/dist/utils/path-resolver.d.ts.map +1 -0
  338. package/dist/utils/path-resolver.js +260 -0
  339. package/dist/utils/path-resolver.js.map +1 -0
  340. package/dist/utils/path-validator.d.ts +49 -0
  341. package/dist/utils/path-validator.d.ts.map +1 -0
  342. package/dist/utils/path-validator.js +123 -0
  343. package/dist/utils/path-validator.js.map +1 -0
  344. package/dist/utils/ui.d.ts +62 -0
  345. package/dist/utils/ui.d.ts.map +1 -0
  346. package/dist/utils/ui.js +129 -0
  347. package/dist/utils/ui.js.map +1 -0
  348. package/package.json +32 -34
  349. package/src/.workflow/.cli-history/history.db +0 -0
  350. package/src/.workflow/.cli-history/history.db-shm +0 -0
  351. package/src/.workflow/.cli-history/history.db-wal +0 -0
  352. package/src/cli.ts +244 -0
  353. package/src/commands/cli.ts +740 -0
  354. package/src/commands/core-memory.ts +770 -0
  355. package/src/commands/hook.ts +315 -0
  356. package/src/commands/install.ts +519 -0
  357. package/src/commands/list.ts +37 -0
  358. package/src/commands/memory.ts +1090 -0
  359. package/src/commands/serve.ts +76 -0
  360. package/src/commands/session-path-resolver.ts +372 -0
  361. package/src/commands/session.ts +1141 -0
  362. package/src/commands/stop.ts +111 -0
  363. package/src/commands/tool.ts +201 -0
  364. package/src/commands/uninstall.ts +287 -0
  365. package/src/commands/upgrade.ts +352 -0
  366. package/src/commands/view.ts +119 -0
  367. package/src/config/storage-paths.ts +670 -0
  368. package/src/core/cache-manager.ts +294 -0
  369. package/src/core/claude-freshness.ts +319 -0
  370. package/src/core/core-memory-store.ts +1528 -0
  371. package/src/core/dashboard-generator-patch.ts +47 -0
  372. package/src/core/dashboard-generator.ts +739 -0
  373. package/src/core/data-aggregator.ts +584 -0
  374. package/src/core/history-importer.ts +625 -0
  375. package/src/core/lite-scanner-complete.ts +469 -0
  376. package/src/core/lite-scanner.ts +469 -0
  377. package/src/core/manifest.ts +271 -0
  378. package/src/core/memory-embedder-bridge.ts +262 -0
  379. package/src/core/memory-store.ts +978 -0
  380. package/src/core/routes/ccw-routes.ts +96 -0
  381. package/src/core/routes/claude-routes.ts +1183 -0
  382. package/src/core/routes/cli-routes.ts +561 -0
  383. package/src/core/routes/codexlens-routes.ts +806 -0
  384. package/src/core/routes/core-memory-routes.ts +605 -0
  385. package/src/core/routes/files-routes.ts +428 -0
  386. package/src/core/routes/graph-routes.md +164 -0
  387. package/src/core/routes/graph-routes.ts +626 -0
  388. package/src/core/routes/help-routes.ts +308 -0
  389. package/src/core/routes/hooks-routes.ts +405 -0
  390. package/src/core/routes/mcp-routes.ts +1271 -0
  391. package/src/core/routes/mcp-routes.ts.backup +550 -0
  392. package/src/core/routes/mcp-templates-db.ts +268 -0
  393. package/src/core/routes/memory-routes.ts +1206 -0
  394. package/src/core/routes/rules-routes.ts +526 -0
  395. package/src/core/routes/session-routes.ts +467 -0
  396. package/src/core/routes/skills-routes.ts +599 -0
  397. package/src/core/routes/status-routes.ts +57 -0
  398. package/src/core/routes/system-routes.ts +427 -0
  399. package/src/core/server.ts +431 -0
  400. package/src/core/session-clustering-service.ts +1258 -0
  401. package/src/core/session-scanner.ts +283 -0
  402. package/src/core/websocket.ts +190 -0
  403. package/src/index.ts +10 -0
  404. package/src/mcp-server/index.ts +186 -0
  405. package/src/templates/assets/css/github-dark.min.css +10 -0
  406. package/src/templates/assets/css/github.min.css +10 -0
  407. package/src/templates/assets/js/cytoscape.min.js +32 -0
  408. package/src/templates/assets/js/d3.min.js +2 -0
  409. package/src/templates/assets/js/highlight.min.js +1244 -0
  410. package/src/templates/assets/js/lucide.min.js +12 -0
  411. package/src/templates/assets/js/marked.min.js +69 -0
  412. package/src/templates/assets/js/tailwind.js +83 -0
  413. package/src/templates/dashboard-css/01-base.css +302 -0
  414. package/src/templates/dashboard-css/02-session.css +748 -0
  415. package/src/templates/dashboard-css/04-lite-tasks.css +1181 -0
  416. package/src/templates/dashboard-css/06-cards.css +1576 -0
  417. package/src/templates/dashboard-css/07-managers.css +2107 -0
  418. package/src/templates/dashboard-css/09-explorer.css +1408 -0
  419. package/src/templates/dashboard-css/10-cli-status.css +337 -0
  420. package/src/templates/dashboard-css/11-cli-history.css +271 -0
  421. package/src/templates/dashboard-css/12-cli-legacy.css +796 -0
  422. package/src/templates/dashboard-css/13-cli-ccw.css +199 -0
  423. package/src/templates/dashboard-css/14-cli-modals.css +258 -0
  424. package/src/templates/dashboard-css/15-cli-endpoints.css +305 -0
  425. package/src/templates/dashboard-css/16-cli-session.css +241 -0
  426. package/src/templates/dashboard-css/17-cli-conversation.css +283 -0
  427. package/src/templates/dashboard-css/18-cli-settings.css +160 -0
  428. package/src/templates/dashboard-css/19-cli-native-session.css +496 -0
  429. package/src/templates/dashboard-css/20-cli-taskqueue.css +188 -0
  430. package/src/templates/dashboard-css/21-cli-toolmgmt.css +310 -0
  431. package/src/templates/dashboard-css/22-cli-semantic.css +240 -0
  432. package/src/templates/dashboard-css/23-memory.css +2390 -0
  433. package/src/templates/dashboard-css/24-prompt-history.css +1089 -0
  434. package/src/templates/dashboard-css/25-skills-rules.css +326 -0
  435. package/src/templates/dashboard-css/26-claude-manager.css +908 -0
  436. package/src/templates/dashboard-css/27-graph-explorer.css +1678 -0
  437. package/src/templates/dashboard-css/28-mcp-manager.css +748 -0
  438. package/src/templates/dashboard-css/29-help.css +264 -0
  439. package/src/templates/dashboard-css/30-core-memory.css +1700 -0
  440. package/src/templates/dashboard-js/api.js +220 -0
  441. package/src/templates/dashboard-js/components/carousel.js +398 -0
  442. package/src/templates/dashboard-js/components/cli-history.js +876 -0
  443. package/src/templates/dashboard-js/components/cli-status.js +978 -0
  444. package/src/templates/dashboard-js/components/global-notifications.js +508 -0
  445. package/src/templates/dashboard-js/components/hook-manager.js +1278 -0
  446. package/src/templates/dashboard-js/components/index-manager.js +302 -0
  447. package/src/templates/dashboard-js/components/mcp-manager.js +1219 -0
  448. package/src/templates/dashboard-js/components/modals.js +326 -0
  449. package/src/templates/dashboard-js/components/navigation.js +313 -0
  450. package/src/templates/dashboard-js/components/notifications.js +758 -0
  451. package/src/templates/dashboard-js/components/storage-manager.js +478 -0
  452. package/src/templates/dashboard-js/components/tabs-other.js +424 -0
  453. package/src/templates/dashboard-js/components/task-queue-sidebar.js +716 -0
  454. package/src/templates/dashboard-js/help-i18n.js +272 -0
  455. package/src/templates/dashboard-js/i18n.js +2807 -0
  456. package/src/templates/dashboard-js/main.js +87 -0
  457. package/src/templates/dashboard-js/state.js +243 -0
  458. package/src/templates/dashboard-js/utils.js +199 -0
  459. package/src/templates/dashboard-js/views/claude-manager.js +912 -0
  460. package/src/templates/dashboard-js/views/cli-manager.js +2272 -0
  461. package/src/templates/dashboard-js/views/codexlens-manager.js +964 -0
  462. package/src/templates/dashboard-js/views/core-memory-clusters.js +503 -0
  463. package/src/templates/dashboard-js/views/core-memory.js +782 -0
  464. package/src/templates/dashboard-js/views/explorer.js +888 -0
  465. package/src/templates/dashboard-js/views/graph-explorer.js +1157 -0
  466. package/src/templates/dashboard-js/views/help.js +856 -0
  467. package/src/templates/dashboard-js/views/history.js +337 -0
  468. package/src/templates/dashboard-js/views/home.js +243 -0
  469. package/src/templates/dashboard-js/views/hook-manager.js +660 -0
  470. package/src/templates/dashboard-js/views/lite-tasks.js +861 -0
  471. package/src/templates/dashboard-js/views/mcp-manager.js +2187 -0
  472. package/src/templates/dashboard-js/views/mcp-manager.js.backup +1729 -0
  473. package/src/templates/dashboard-js/views/mcp-manager.js.new +928 -0
  474. package/src/templates/dashboard-js/views/memory.js +1221 -0
  475. package/src/templates/dashboard-js/views/prompt-history.js +713 -0
  476. package/src/templates/dashboard-js/views/rules-manager.js +828 -0
  477. package/src/templates/dashboard-js/views/session-detail.js +781 -0
  478. package/src/templates/dashboard-js/views/skills-manager.js +819 -0
  479. package/src/templates/dashboard.html +831 -0
  480. package/src/templates/hooks-config-example.json +60 -0
  481. package/src/tools/classify-folders.ts +245 -0
  482. package/src/tools/cli-config-manager.ts +268 -0
  483. package/src/tools/cli-executor.ts +2014 -0
  484. package/src/tools/cli-history-store.ts +1195 -0
  485. package/src/tools/codex-lens.ts +1141 -0
  486. package/src/tools/convert-tokens-to-css.ts +300 -0
  487. package/src/tools/core-memory.ts +444 -0
  488. package/src/tools/detect-changed-modules.ts +325 -0
  489. package/src/tools/discover-design-files.ts +184 -0
  490. package/src/tools/edit-file.ts +568 -0
  491. package/src/tools/generate-module-docs.ts +438 -0
  492. package/src/tools/get-modules-by-depth.ts +349 -0
  493. package/src/tools/index.ts +370 -0
  494. package/src/tools/native-session-discovery.ts +795 -0
  495. package/src/tools/notifier.ts +129 -0
  496. package/src/tools/read-file.ts +410 -0
  497. package/src/tools/resume-strategy.ts +345 -0
  498. package/src/tools/session-content-parser.ts +619 -0
  499. package/src/tools/session-manager.ts +1026 -0
  500. package/src/tools/smart-context.ts +228 -0
  501. package/src/tools/smart-search.ts +2065 -0
  502. package/src/tools/smart-search.ts.backup +1233 -0
  503. package/src/tools/storage-manager.ts +455 -0
  504. package/src/tools/write-file.ts +222 -0
  505. package/src/types/config.ts +11 -0
  506. package/src/types/index.ts +3 -0
  507. package/src/types/session.ts +25 -0
  508. package/src/types/tool.ts +41 -0
  509. package/src/utils/browser-launcher.ts +62 -0
  510. package/src/utils/file-utils.ts +48 -0
  511. package/src/utils/path-resolver.ts +315 -0
  512. package/src/utils/path-validator.ts +153 -0
  513. package/src/utils/ui.ts +155 -0
  514. package/.claude/agents/action-planning-agent.md +0 -778
  515. package/.claude/agents/cli-execution-agent.md +0 -270
  516. package/.claude/agents/cli-explore-agent.md +0 -182
  517. package/.claude/agents/cli-lite-planning-agent.md +0 -396
  518. package/.claude/agents/cli-planning-agent.md +0 -558
  519. package/.claude/agents/code-developer.md +0 -310
  520. package/.claude/agents/conceptual-planning-agent.md +0 -308
  521. package/.claude/agents/context-search-agent.md +0 -582
  522. package/.claude/agents/doc-generator.md +0 -330
  523. package/.claude/agents/memory-bridge.md +0 -94
  524. package/.claude/agents/test-context-search-agent.md +0 -399
  525. package/.claude/agents/test-fix-agent.md +0 -343
  526. package/.claude/agents/ui-design-agent.md +0 -593
  527. package/.claude/agents/universal-executor.md +0 -131
  528. package/.claude/commands/cli/cli-init.md +0 -440
  529. package/.claude/commands/enhance-prompt.md +0 -93
  530. package/.claude/commands/memory/code-map-memory.md +0 -687
  531. package/.claude/commands/memory/docs-full-cli.md +0 -471
  532. package/.claude/commands/memory/docs-related-cli.md +0 -386
  533. package/.claude/commands/memory/docs.md +0 -615
  534. package/.claude/commands/memory/load-skill-memory.md +0 -182
  535. package/.claude/commands/memory/load.md +0 -240
  536. package/.claude/commands/memory/skill-memory.md +0 -525
  537. package/.claude/commands/memory/style-skill-memory.md +0 -396
  538. package/.claude/commands/memory/tech-research.md +0 -477
  539. package/.claude/commands/memory/update-full.md +0 -332
  540. package/.claude/commands/memory/update-related.md +0 -332
  541. package/.claude/commands/memory/workflow-skill-memory.md +0 -517
  542. package/.claude/commands/task/breakdown.md +0 -204
  543. package/.claude/commands/task/create.md +0 -152
  544. package/.claude/commands/task/execute.md +0 -270
  545. package/.claude/commands/task/replan.md +0 -437
  546. package/.claude/commands/version.md +0 -254
  547. package/.claude/commands/workflow/action-plan-verify.md +0 -447
  548. package/.claude/commands/workflow/brainstorm/api-designer.md +0 -585
  549. package/.claude/commands/workflow/brainstorm/artifacts.md +0 -452
  550. package/.claude/commands/workflow/brainstorm/auto-parallel.md +0 -443
  551. package/.claude/commands/workflow/brainstorm/data-architect.md +0 -220
  552. package/.claude/commands/workflow/brainstorm/product-manager.md +0 -200
  553. package/.claude/commands/workflow/brainstorm/product-owner.md +0 -200
  554. package/.claude/commands/workflow/brainstorm/scrum-master.md +0 -200
  555. package/.claude/commands/workflow/brainstorm/subject-matter-expert.md +0 -200
  556. package/.claude/commands/workflow/brainstorm/synthesis.md +0 -398
  557. package/.claude/commands/workflow/brainstorm/system-architect.md +0 -387
  558. package/.claude/commands/workflow/brainstorm/ui-designer.md +0 -221
  559. package/.claude/commands/workflow/brainstorm/ux-expert.md +0 -221
  560. package/.claude/commands/workflow/execute.md +0 -462
  561. package/.claude/commands/workflow/init.md +0 -164
  562. package/.claude/commands/workflow/lite-execute.md +0 -686
  563. package/.claude/commands/workflow/lite-fix.md +0 -621
  564. package/.claude/commands/workflow/lite-plan.md +0 -592
  565. package/.claude/commands/workflow/plan.md +0 -551
  566. package/.claude/commands/workflow/replan.md +0 -515
  567. package/.claude/commands/workflow/review-fix.md +0 -606
  568. package/.claude/commands/workflow/review-module-cycle.md +0 -765
  569. package/.claude/commands/workflow/review-session-cycle.md +0 -776
  570. package/.claude/commands/workflow/review.md +0 -291
  571. package/.claude/commands/workflow/session/complete.md +0 -500
  572. package/.claude/commands/workflow/session/list.md +0 -96
  573. package/.claude/commands/workflow/session/resume.md +0 -61
  574. package/.claude/commands/workflow/session/start.md +0 -200
  575. package/.claude/commands/workflow/tdd-plan.md +0 -460
  576. package/.claude/commands/workflow/tdd-verify.md +0 -386
  577. package/.claude/commands/workflow/test-cycle-execute.md +0 -498
  578. package/.claude/commands/workflow/test-fix-gen.md +0 -699
  579. package/.claude/commands/workflow/test-gen.md +0 -529
  580. package/.claude/commands/workflow/tools/conflict-resolution.md +0 -680
  581. package/.claude/commands/workflow/tools/context-gather.md +0 -434
  582. package/.claude/commands/workflow/tools/task-generate-agent.md +0 -291
  583. package/.claude/commands/workflow/tools/task-generate-tdd.md +0 -518
  584. package/.claude/commands/workflow/tools/tdd-coverage-analysis.md +0 -309
  585. package/.claude/commands/workflow/tools/test-concept-enhanced.md +0 -163
  586. package/.claude/commands/workflow/tools/test-context-gather.md +0 -235
  587. package/.claude/commands/workflow/tools/test-task-generate.md +0 -256
  588. package/.claude/commands/workflow/ui-design/animation-extract.md +0 -1150
  589. package/.claude/commands/workflow/ui-design/codify-style.md +0 -652
  590. package/.claude/commands/workflow/ui-design/design-sync.md +0 -454
  591. package/.claude/commands/workflow/ui-design/explore-auto.md +0 -678
  592. package/.claude/commands/workflow/ui-design/generate.md +0 -504
  593. package/.claude/commands/workflow/ui-design/imitate-auto.md +0 -745
  594. package/.claude/commands/workflow/ui-design/import-from-code.md +0 -537
  595. package/.claude/commands/workflow/ui-design/layout-extract.md +0 -788
  596. package/.claude/commands/workflow/ui-design/reference-page-generator.md +0 -356
  597. package/.claude/commands/workflow/ui-design/style-extract.md +0 -773
  598. package/.claude/scripts/classify-folders.sh +0 -39
  599. package/.claude/scripts/convert_tokens_to_css.sh +0 -229
  600. package/.claude/scripts/detect_changed_modules.sh +0 -161
  601. package/.claude/scripts/discover-design-files.sh +0 -87
  602. package/.claude/scripts/extract-animations.js +0 -243
  603. package/.claude/scripts/extract-computed-styles.js +0 -118
  604. package/.claude/scripts/extract-layout-structure.js +0 -411
  605. package/.claude/scripts/generate_module_docs.sh +0 -717
  606. package/.claude/scripts/get_modules_by_depth.sh +0 -170
  607. package/.claude/scripts/ui-generate-preview.sh +0 -395
  608. package/.claude/scripts/ui-instantiate-prototypes.sh +0 -815
  609. package/.claude/scripts/update_module_claude.sh +0 -337
  610. package/.claude/skills/command-guide/SKILL.md +0 -388
  611. package/.claude/skills/command-guide/UPDATE-GUIDELINE.md +0 -592
  612. package/.claude/skills/command-guide/guides/cli-tools-guide.md +0 -410
  613. package/.claude/skills/command-guide/guides/examples.md +0 -537
  614. package/.claude/skills/command-guide/guides/getting-started.md +0 -242
  615. package/.claude/skills/command-guide/guides/implementation-details.md +0 -1010
  616. package/.claude/skills/command-guide/guides/index-structure.md +0 -326
  617. package/.claude/skills/command-guide/guides/troubleshooting.md +0 -92
  618. package/.claude/skills/command-guide/guides/ui-design-workflow-guide.md +0 -316
  619. package/.claude/skills/command-guide/guides/workflow-patterns.md +0 -662
  620. package/.claude/skills/command-guide/index/all-commands.json +0 -772
  621. package/.claude/skills/command-guide/index/by-category.json +0 -800
  622. package/.claude/skills/command-guide/index/by-use-case.json +0 -786
  623. package/.claude/skills/command-guide/index/command-relationships.json +0 -307
  624. package/.claude/skills/command-guide/index/essential-commands.json +0 -112
  625. package/.claude/skills/command-guide/reference/agents/action-planning-agent.md +0 -778
  626. package/.claude/skills/command-guide/reference/agents/cli-execution-agent.md +0 -270
  627. package/.claude/skills/command-guide/reference/agents/cli-explore-agent.md +0 -182
  628. package/.claude/skills/command-guide/reference/agents/cli-lite-planning-agent.md +0 -396
  629. package/.claude/skills/command-guide/reference/agents/cli-planning-agent.md +0 -558
  630. package/.claude/skills/command-guide/reference/agents/code-developer.md +0 -310
  631. package/.claude/skills/command-guide/reference/agents/conceptual-planning-agent.md +0 -308
  632. package/.claude/skills/command-guide/reference/agents/context-search-agent.md +0 -582
  633. package/.claude/skills/command-guide/reference/agents/doc-generator.md +0 -330
  634. package/.claude/skills/command-guide/reference/agents/memory-bridge.md +0 -94
  635. package/.claude/skills/command-guide/reference/agents/test-context-search-agent.md +0 -399
  636. package/.claude/skills/command-guide/reference/agents/test-fix-agent.md +0 -343
  637. package/.claude/skills/command-guide/reference/agents/ui-design-agent.md +0 -593
  638. package/.claude/skills/command-guide/reference/agents/universal-executor.md +0 -131
  639. package/.claude/skills/command-guide/reference/commands/cli/cli-init.md +0 -440
  640. package/.claude/skills/command-guide/reference/commands/enhance-prompt.md +0 -93
  641. package/.claude/skills/command-guide/reference/commands/memory/code-map-memory.md +0 -687
  642. package/.claude/skills/command-guide/reference/commands/memory/docs-full-cli.md +0 -471
  643. package/.claude/skills/command-guide/reference/commands/memory/docs-related-cli.md +0 -386
  644. package/.claude/skills/command-guide/reference/commands/memory/docs.md +0 -615
  645. package/.claude/skills/command-guide/reference/commands/memory/load-skill-memory.md +0 -182
  646. package/.claude/skills/command-guide/reference/commands/memory/load.md +0 -240
  647. package/.claude/skills/command-guide/reference/commands/memory/skill-memory.md +0 -525
  648. package/.claude/skills/command-guide/reference/commands/memory/style-skill-memory.md +0 -396
  649. package/.claude/skills/command-guide/reference/commands/memory/tech-research.md +0 -477
  650. package/.claude/skills/command-guide/reference/commands/memory/update-full.md +0 -332
  651. package/.claude/skills/command-guide/reference/commands/memory/update-related.md +0 -332
  652. package/.claude/skills/command-guide/reference/commands/memory/workflow-skill-memory.md +0 -517
  653. package/.claude/skills/command-guide/reference/commands/task/breakdown.md +0 -204
  654. package/.claude/skills/command-guide/reference/commands/task/create.md +0 -152
  655. package/.claude/skills/command-guide/reference/commands/task/execute.md +0 -270
  656. package/.claude/skills/command-guide/reference/commands/task/replan.md +0 -437
  657. package/.claude/skills/command-guide/reference/commands/version.md +0 -254
  658. package/.claude/skills/command-guide/reference/commands/workflow/action-plan-verify.md +0 -447
  659. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/api-designer.md +0 -585
  660. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/artifacts.md +0 -452
  661. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/auto-parallel.md +0 -443
  662. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/data-architect.md +0 -220
  663. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/product-manager.md +0 -200
  664. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/product-owner.md +0 -200
  665. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/scrum-master.md +0 -200
  666. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/subject-matter-expert.md +0 -200
  667. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/synthesis.md +0 -398
  668. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/system-architect.md +0 -387
  669. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/ui-designer.md +0 -221
  670. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/ux-expert.md +0 -221
  671. package/.claude/skills/command-guide/reference/commands/workflow/execute.md +0 -460
  672. package/.claude/skills/command-guide/reference/commands/workflow/init.md +0 -164
  673. package/.claude/skills/command-guide/reference/commands/workflow/lite-execute.md +0 -686
  674. package/.claude/skills/command-guide/reference/commands/workflow/lite-fix.md +0 -621
  675. package/.claude/skills/command-guide/reference/commands/workflow/lite-plan.md +0 -592
  676. package/.claude/skills/command-guide/reference/commands/workflow/plan.md +0 -551
  677. package/.claude/skills/command-guide/reference/commands/workflow/replan.md +0 -515
  678. package/.claude/skills/command-guide/reference/commands/workflow/review-fix.md +0 -606
  679. package/.claude/skills/command-guide/reference/commands/workflow/review-module-cycle.md +0 -765
  680. package/.claude/skills/command-guide/reference/commands/workflow/review-session-cycle.md +0 -776
  681. package/.claude/skills/command-guide/reference/commands/workflow/review.md +0 -291
  682. package/.claude/skills/command-guide/reference/commands/workflow/session/complete.md +0 -500
  683. package/.claude/skills/command-guide/reference/commands/workflow/session/list.md +0 -96
  684. package/.claude/skills/command-guide/reference/commands/workflow/session/resume.md +0 -61
  685. package/.claude/skills/command-guide/reference/commands/workflow/session/start.md +0 -200
  686. package/.claude/skills/command-guide/reference/commands/workflow/tdd-plan.md +0 -460
  687. package/.claude/skills/command-guide/reference/commands/workflow/tdd-verify.md +0 -386
  688. package/.claude/skills/command-guide/reference/commands/workflow/test-cycle-execute.md +0 -498
  689. package/.claude/skills/command-guide/reference/commands/workflow/test-fix-gen.md +0 -699
  690. package/.claude/skills/command-guide/reference/commands/workflow/test-gen.md +0 -529
  691. package/.claude/skills/command-guide/reference/commands/workflow/tools/conflict-resolution.md +0 -680
  692. package/.claude/skills/command-guide/reference/commands/workflow/tools/context-gather.md +0 -434
  693. package/.claude/skills/command-guide/reference/commands/workflow/tools/task-generate-agent.md +0 -291
  694. package/.claude/skills/command-guide/reference/commands/workflow/tools/task-generate-tdd.md +0 -518
  695. package/.claude/skills/command-guide/reference/commands/workflow/tools/tdd-coverage-analysis.md +0 -309
  696. package/.claude/skills/command-guide/reference/commands/workflow/tools/test-concept-enhanced.md +0 -163
  697. package/.claude/skills/command-guide/reference/commands/workflow/tools/test-context-gather.md +0 -235
  698. package/.claude/skills/command-guide/reference/commands/workflow/tools/test-task-generate.md +0 -256
  699. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/animation-extract.md +0 -1150
  700. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/codify-style.md +0 -652
  701. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/design-sync.md +0 -454
  702. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/explore-auto.md +0 -678
  703. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/generate.md +0 -504
  704. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/imitate-auto.md +0 -745
  705. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/import-from-code.md +0 -537
  706. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/layout-extract.md +0 -788
  707. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/reference-page-generator.md +0 -356
  708. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/style-extract.md +0 -773
  709. package/.claude/skills/command-guide/scripts/analyze_commands.py +0 -502
  710. package/.claude/skills/command-guide/scripts/update-index.sh +0 -130
  711. package/.claude/skills/command-guide/templates/issue-bug.md +0 -104
  712. package/.claude/skills/command-guide/templates/issue-diagnosis.md +0 -275
  713. package/.claude/skills/command-guide/templates/issue-feature.md +0 -97
  714. package/.claude/skills/command-guide/templates/issue-question.md +0 -141
  715. package/.claude/skills/prompt-enhancer/SKILL.md +0 -124
  716. package/.claude/workflows/_template-compare-matrix.html +0 -692
  717. package/.claude/workflows/cli-templates/fix-plan-template.json +0 -75
  718. package/.claude/workflows/cli-templates/fix-progress-template.json +0 -48
  719. package/.claude/workflows/cli-templates/memory/style-skill-memory/skill-md-template.md +0 -299
  720. package/.claude/workflows/cli-templates/planning-roles/data-architect.md +0 -120
  721. package/.claude/workflows/cli-templates/planning-roles/product-manager.md +0 -119
  722. package/.claude/workflows/cli-templates/planning-roles/product-owner.md +0 -261
  723. package/.claude/workflows/cli-templates/planning-roles/scrum-master.md +0 -186
  724. package/.claude/workflows/cli-templates/planning-roles/subject-matter-expert.md +0 -281
  725. package/.claude/workflows/cli-templates/planning-roles/synthesis-role.md +0 -414
  726. package/.claude/workflows/cli-templates/planning-roles/system-architect.md +0 -106
  727. package/.claude/workflows/cli-templates/planning-roles/test-strategist.md +0 -124
  728. package/.claude/workflows/cli-templates/planning-roles/ui-designer.md +0 -379
  729. package/.claude/workflows/cli-templates/planning-roles/ux-expert.md +0 -240
  730. package/.claude/workflows/cli-templates/prompts/analysis/01-diagnose-bug-root-cause.txt +0 -127
  731. package/.claude/workflows/cli-templates/prompts/analysis/01-trace-code-execution.txt +0 -115
  732. package/.claude/workflows/cli-templates/prompts/analysis/02-analyze-code-patterns.txt +0 -37
  733. package/.claude/workflows/cli-templates/prompts/analysis/02-analyze-technical-document.txt +0 -33
  734. package/.claude/workflows/cli-templates/prompts/analysis/02-review-architecture.txt +0 -29
  735. package/.claude/workflows/cli-templates/prompts/analysis/02-review-code-quality.txt +0 -28
  736. package/.claude/workflows/cli-templates/prompts/analysis/03-analyze-performance.txt +0 -29
  737. package/.claude/workflows/cli-templates/prompts/analysis/03-assess-security-risks.txt +0 -29
  738. package/.claude/workflows/cli-templates/prompts/analysis/03-review-quality-standards.txt +0 -29
  739. package/.claude/workflows/cli-templates/prompts/development/02-generate-tests.txt +0 -70
  740. package/.claude/workflows/cli-templates/prompts/development/02-implement-component-ui.txt +0 -55
  741. package/.claude/workflows/cli-templates/prompts/development/02-implement-feature.txt +0 -58
  742. package/.claude/workflows/cli-templates/prompts/development/02-refactor-codebase.txt +0 -55
  743. package/.claude/workflows/cli-templates/prompts/development/03-debug-runtime-issues.txt +0 -55
  744. package/.claude/workflows/cli-templates/prompts/documentation/api.txt +0 -15
  745. package/.claude/workflows/cli-templates/prompts/documentation/folder-navigation.txt +0 -27
  746. package/.claude/workflows/cli-templates/prompts/documentation/module-readme.txt +0 -49
  747. package/.claude/workflows/cli-templates/prompts/documentation/project-architecture.txt +0 -41
  748. package/.claude/workflows/cli-templates/prompts/documentation/project-examples.txt +0 -35
  749. package/.claude/workflows/cli-templates/prompts/documentation/project-readme.txt +0 -35
  750. package/.claude/workflows/cli-templates/prompts/memory/02-document-module-structure.txt +0 -165
  751. package/.claude/workflows/cli-templates/prompts/planning/01-plan-architecture-design.txt +0 -109
  752. package/.claude/workflows/cli-templates/prompts/planning/02-breakdown-task-steps.txt +0 -30
  753. package/.claude/workflows/cli-templates/prompts/planning/02-design-component-spec.txt +0 -28
  754. package/.claude/workflows/cli-templates/prompts/planning/03-evaluate-concept-feasibility.txt +0 -127
  755. package/.claude/workflows/cli-templates/prompts/planning/03-plan-migration-strategy.txt +0 -30
  756. package/.claude/workflows/cli-templates/prompts/tech/tech-module-format.txt +0 -359
  757. package/.claude/workflows/cli-templates/prompts/tech/tech-skill-index.txt +0 -185
  758. package/.claude/workflows/cli-templates/prompts/test/test-concept-analysis.txt +0 -179
  759. package/.claude/workflows/cli-templates/prompts/universal/00-universal-creative-style.txt +0 -95
  760. package/.claude/workflows/cli-templates/prompts/universal/00-universal-rigorous-style.txt +0 -92
  761. package/.claude/workflows/cli-templates/prompts/verification/codex-technical.txt +0 -28
  762. package/.claude/workflows/cli-templates/prompts/verification/cross-validation.txt +0 -28
  763. package/.claude/workflows/cli-templates/prompts/verification/gemini-strategic.txt +0 -27
  764. package/.claude/workflows/cli-templates/prompts/workflow/analysis-results-structure.txt +0 -224
  765. package/.claude/workflows/cli-templates/prompts/workflow/codex-feasibility-validation.txt +0 -176
  766. package/.claude/workflows/cli-templates/prompts/workflow/gemini-solution-design.txt +0 -131
  767. package/.claude/workflows/cli-templates/prompts/workflow/impl-plan-template.txt +0 -286
  768. package/.claude/workflows/cli-templates/prompts/workflow/skill-aggregation.txt +0 -172
  769. package/.claude/workflows/cli-templates/prompts/workflow/skill-conflict-patterns.txt +0 -98
  770. package/.claude/workflows/cli-templates/prompts/workflow/skill-index.txt +0 -224
  771. package/.claude/workflows/cli-templates/prompts/workflow/skill-lessons-learned.txt +0 -98
  772. package/.claude/workflows/cli-templates/prompts/workflow/skill-sessions-timeline.txt +0 -53
  773. package/.claude/workflows/cli-templates/prompts/workflow/task-json-agent-mode.txt +0 -123
  774. package/.claude/workflows/cli-templates/prompts/workflow/task-json-cli-mode.txt +0 -182
  775. package/.claude/workflows/cli-templates/schemas/diagnosis-json-schema.json +0 -234
  776. package/.claude/workflows/cli-templates/schemas/explore-json-schema.json +0 -124
  777. package/.claude/workflows/cli-templates/schemas/fix-plan-json-schema.json +0 -273
  778. package/.claude/workflows/cli-templates/schemas/plan-json-schema.json +0 -219
  779. package/.claude/workflows/cli-templates/schemas/project-json-schema.json +0 -221
  780. package/.claude/workflows/cli-templates/schemas/review-deep-dive-results-schema.json +0 -82
  781. package/.claude/workflows/cli-templates/schemas/review-dimension-results-schema.json +0 -51
  782. package/.claude/workflows/cli-templates/tech-stacks/go-dev.md +0 -91
  783. package/.claude/workflows/cli-templates/tech-stacks/java-dev.md +0 -107
  784. package/.claude/workflows/cli-templates/tech-stacks/javascript-dev.md +0 -58
  785. package/.claude/workflows/cli-templates/tech-stacks/python-dev.md +0 -79
  786. package/.claude/workflows/cli-templates/tech-stacks/react-dev.md +0 -103
  787. package/.claude/workflows/cli-templates/tech-stacks/typescript-dev.md +0 -83
  788. package/.claude/workflows/cli-templates/ui-design/systems/animation-tokens.json +0 -247
  789. package/.claude/workflows/cli-templates/ui-design/systems/design-tokens.json +0 -342
  790. package/.claude/workflows/cli-templates/ui-design/systems/layout-templates.json +0 -145
  791. package/.claude/workflows/context-search-strategy.md +0 -77
  792. package/.claude/workflows/intelligent-tools-strategy.md +0 -662
  793. package/.claude/workflows/review-directory-specification.md +0 -336
  794. package/.claude/workflows/task-core.md +0 -214
  795. package/.claude/workflows/tool-strategy.md +0 -79
  796. package/.claude/workflows/workflow-architecture.md +0 -942
  797. package/.codex/AGENTS.md +0 -330
  798. package/.gemini/GEMINI.md +0 -164
  799. package/.qwen/QWEN.md +0 -164
  800. package/CLAUDE.md +0 -91
  801. package/LICENSE +0 -21
  802. package/ccw/README.md +0 -121
  803. package/ccw/bin/ccw.js +0 -10
  804. package/ccw/package.json +0 -47
  805. package/ccw/src/cli.js +0 -119
  806. package/ccw/src/commands/install.js +0 -324
  807. package/ccw/src/commands/list.js +0 -37
  808. package/ccw/src/commands/serve.js +0 -67
  809. package/ccw/src/commands/stop.js +0 -101
  810. package/ccw/src/commands/tool.js +0 -138
  811. package/ccw/src/commands/uninstall.js +0 -238
  812. package/ccw/src/commands/upgrade.js +0 -307
  813. package/ccw/src/commands/view.js +0 -105
  814. package/ccw/src/core/dashboard-generator-patch.js +0 -29
  815. package/ccw/src/core/dashboard-generator.js +0 -682
  816. package/ccw/src/core/data-aggregator.js +0 -409
  817. package/ccw/src/core/lite-scanner.js +0 -373
  818. package/ccw/src/core/manifest.js +0 -201
  819. package/ccw/src/core/server.js +0 -2063
  820. package/ccw/src/core/session-scanner.js +0 -235
  821. package/ccw/src/index.js +0 -9
  822. package/ccw/src/templates/dashboard-css/01-base.css +0 -291
  823. package/ccw/src/templates/dashboard-css/02-session.css +0 -726
  824. package/ccw/src/templates/dashboard-css/04-lite-tasks.css +0 -1171
  825. package/ccw/src/templates/dashboard-css/06-cards.css +0 -1570
  826. package/ccw/src/templates/dashboard-css/07-managers.css +0 -936
  827. package/ccw/src/templates/dashboard-css/09-explorer.css +0 -1397
  828. package/ccw/src/templates/dashboard-js/api.js +0 -200
  829. package/ccw/src/templates/dashboard-js/components/carousel.js +0 -398
  830. package/ccw/src/templates/dashboard-js/components/global-notifications.js +0 -219
  831. package/ccw/src/templates/dashboard-js/components/hook-manager.js +0 -283
  832. package/ccw/src/templates/dashboard-js/components/mcp-manager.js +0 -528
  833. package/ccw/src/templates/dashboard-js/components/modals.js +0 -260
  834. package/ccw/src/templates/dashboard-js/components/navigation.js +0 -245
  835. package/ccw/src/templates/dashboard-js/components/notifications.js +0 -194
  836. package/ccw/src/templates/dashboard-js/components/tabs-other.js +0 -273
  837. package/ccw/src/templates/dashboard-js/main.js +0 -72
  838. package/ccw/src/templates/dashboard-js/state.js +0 -42
  839. package/ccw/src/templates/dashboard-js/utils.js +0 -153
  840. package/ccw/src/templates/dashboard-js/views/explorer.js +0 -852
  841. package/ccw/src/templates/dashboard-js/views/home.js +0 -197
  842. package/ccw/src/templates/dashboard-js/views/hook-manager.js +0 -392
  843. package/ccw/src/templates/dashboard-js/views/lite-tasks.js +0 -685
  844. package/ccw/src/templates/dashboard-js/views/mcp-manager.js +0 -411
  845. package/ccw/src/templates/dashboard-js/views/session-detail.js +0 -780
  846. package/ccw/src/templates/dashboard.html +0 -731
  847. package/ccw/src/tools/classify-folders.js +0 -204
  848. package/ccw/src/tools/convert-tokens-to-css.js +0 -250
  849. package/ccw/src/tools/detect-changed-modules.js +0 -288
  850. package/ccw/src/tools/discover-design-files.js +0 -134
  851. package/ccw/src/tools/edit-file.js +0 -266
  852. package/ccw/src/tools/generate-module-docs.js +0 -416
  853. package/ccw/src/tools/get-modules-by-depth.js +0 -308
  854. package/ccw/src/tools/index.js +0 -176
  855. package/ccw/src/utils/browser-launcher.js +0 -60
  856. package/ccw/src/utils/file-utils.js +0 -48
  857. package/ccw/src/utils/path-resolver.js +0 -279
  858. package/ccw/src/utils/ui.js +0 -148
  859. /package/{ccw/src → src}/templates/dashboard-css/03-tasks.css +0 -0
  860. /package/{ccw/src → src}/templates/dashboard-css/05-context.css +0 -0
  861. /package/{ccw/src → src}/templates/dashboard-css/08-review.css +0 -0
  862. /package/{ccw/src → src}/templates/dashboard-js/components/_conflict_tab.js +0 -0
  863. /package/{ccw/src → src}/templates/dashboard-js/components/_exp_helpers.js +0 -0
  864. /package/{ccw/src → src}/templates/dashboard-js/components/_review_tab.js +0 -0
  865. /package/{ccw/src → src}/templates/dashboard-js/components/flowchart.js +0 -0
  866. /package/{ccw/src → src}/templates/dashboard-js/components/sidebar.js +0 -0
  867. /package/{ccw/src → src}/templates/dashboard-js/components/tabs-context.js +0 -0
  868. /package/{ccw/src → src}/templates/dashboard-js/components/task-drawer-core.js +0 -0
  869. /package/{ccw/src → src}/templates/dashboard-js/components/task-drawer-renderers.js +0 -0
  870. /package/{ccw/src → src}/templates/dashboard-js/components/theme.js +0 -0
  871. /package/{ccw/src → src}/templates/dashboard-js/components/version-check.js +0 -0
  872. /package/{ccw/src → src}/templates/dashboard-js/views/fix-session.js +0 -0
  873. /package/{ccw/src → src}/templates/dashboard-js/views/project-overview.js +0 -0
  874. /package/{ccw/src → src}/templates/dashboard-js/views/review-session.js +0 -0
  875. /package/{ccw/src → src}/templates/review-cycle-dashboard.html +0 -0
  876. /package/{ccw/src → src}/templates/workflow-dashboard.html +0 -0
  877. /package/{ccw/src → src}/tools/ui-generate-preview.js +0 -0
  878. /package/{ccw/src → src}/tools/ui-instantiate-prototypes.js +0 -0
  879. /package/{ccw/src → src}/tools/update-module-claude.js +0 -0
@@ -0,0 +1,2065 @@
1
+ /**
2
+ * Smart Search Tool - Unified intelligent search with CodexLens integration
3
+ *
4
+ * Features:
5
+ * - Intent classification with automatic mode selection
6
+ * - CodexLens integration (init, hybrid, vector, semantic)
7
+ * - Ripgrep fallback for exact mode
8
+ * - Index status checking and warnings
9
+ * - Multi-backend search routing with RRF ranking
10
+ *
11
+ * Actions:
12
+ * - init: Initialize CodexLens index
13
+ * - search: Intelligent search with auto mode selection
14
+ * - status: Check index status
15
+ */
16
+
17
+ import { z } from 'zod';
18
+ import type { ToolSchema, ToolResult } from '../types/tool.js';
19
+ import { spawn, execSync } from 'child_process';
20
+ import {
21
+ ensureReady as ensureCodexLensReady,
22
+ executeCodexLens,
23
+ } from './codex-lens.js';
24
+ import type { ProgressInfo } from './codex-lens.js';
25
+ import { getProjectRoot } from '../utils/path-validator.js';
26
+
27
+ // Define Zod schema for validation
28
+ const ParamsSchema = z.object({
29
+ // Action: search (content), find_files (path/name pattern), init, status
30
+ // Note: search_files is deprecated, use search with output_mode='files_only'
31
+ action: z.enum(['init', 'search', 'search_files', 'find_files', 'status']).default('search'),
32
+ query: z.string().optional().describe('Content search query (for action="search")'),
33
+ pattern: z.string().optional().describe('Glob pattern for path matching (for action="find_files")'),
34
+ mode: z.enum(['auto', 'hybrid', 'exact', 'ripgrep', 'priority']).default('auto'),
35
+ output_mode: z.enum(['full', 'files_only', 'count']).default('full'),
36
+ path: z.string().optional(),
37
+ paths: z.array(z.string()).default([]),
38
+ contextLines: z.number().default(0),
39
+ maxResults: z.number().default(20), // Increased default
40
+ includeHidden: z.boolean().default(false),
41
+ languages: z.array(z.string()).optional(),
42
+ limit: z.number().default(20), // Increased default
43
+ offset: z.number().default(0), // NEW: Pagination offset (start_index)
44
+ enrich: z.boolean().default(false),
45
+ // Search modifiers for ripgrep mode
46
+ regex: z.boolean().default(true), // Use regex pattern matching (default: enabled)
47
+ caseSensitive: z.boolean().default(true), // Case sensitivity (default: case-sensitive)
48
+ tokenize: z.boolean().default(true), // Tokenize multi-word queries for OR matching (default: enabled)
49
+ // Fuzzy matching is implicit in hybrid mode (RRF fusion)
50
+ });
51
+
52
+ type Params = z.infer<typeof ParamsSchema>;
53
+
54
+ // Search mode constants
55
+ const SEARCH_MODES = ['auto', 'hybrid', 'exact', 'ripgrep', 'priority'] as const;
56
+
57
+ // Classification confidence threshold
58
+ const CONFIDENCE_THRESHOLD = 0.7;
59
+
60
+ // File filtering configuration (ported from code-index)
61
+ const FILTER_CONFIG = {
62
+ exclude_directories: new Set([
63
+ '.git', '.svn', '.hg', '.bzr',
64
+ 'node_modules', '__pycache__', '.venv', 'venv', 'vendor', 'bower_components',
65
+ 'dist', 'build', 'target', 'out', 'bin', 'obj',
66
+ '.idea', '.vscode', '.vs', '.sublime-workspace',
67
+ '.pytest_cache', '.coverage', '.tox', '.nyc_output', 'coverage', 'htmlcov',
68
+ '.next', '.nuxt', '.cache', '.parcel-cache',
69
+ '.DS_Store', 'Thumbs.db',
70
+ ]),
71
+ exclude_files: new Set([
72
+ '*.tmp', '*.temp', '*.swp', '*.swo', '*.bak', '*~', '*.orig', '*.log',
73
+ 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'Pipfile.lock',
74
+ ]),
75
+ // Windows device files - must use **/ pattern to match in any directory
76
+ // These cause "os error 1" on Windows when accessed
77
+ windows_device_files: new Set([
78
+ 'nul', 'con', 'aux', 'prn',
79
+ 'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9',
80
+ 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9',
81
+ ]),
82
+ };
83
+
84
+ function buildExcludeArgs(): string[] {
85
+ const args: string[] = [];
86
+ for (const dir of FILTER_CONFIG.exclude_directories) {
87
+ args.push('--glob', `!**/${dir}/**`);
88
+ }
89
+ for (const pattern of FILTER_CONFIG.exclude_files) {
90
+ args.push('--glob', `!${pattern}`);
91
+ }
92
+ // Windows device files need case-insensitive matching in any directory
93
+ for (const device of FILTER_CONFIG.windows_device_files) {
94
+ args.push('--glob', `!**/${device}`);
95
+ args.push('--glob', `!**/${device.toUpperCase()}`);
96
+ }
97
+ return args;
98
+ }
99
+
100
+ /**
101
+ * Tokenize query for multi-word OR matching
102
+ * Splits on whitespace and common delimiters, filters stop words and short tokens
103
+ * @param query - The search query
104
+ * @returns Array of tokens
105
+ */
106
+ function tokenizeQuery(query: string): string[] {
107
+ // Stop words for filtering (common English + programming keywords)
108
+ const stopWords = new Set([
109
+ 'the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
110
+ 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
111
+ 'should', 'may', 'might', 'must', 'can', 'to', 'of', 'in', 'for', 'on',
112
+ 'with', 'at', 'by', 'from', 'as', 'into', 'through', 'and', 'but', 'if',
113
+ 'or', 'not', 'this', 'that', 'these', 'those', 'it', 'its', 'how', 'what',
114
+ 'where', 'when', 'why', 'which', 'who', 'whom',
115
+ ]);
116
+
117
+ // Split on whitespace and common delimiters, keep meaningful tokens
118
+ const tokens = query
119
+ .split(/[\s,;:]+/)
120
+ .map(token => token.trim())
121
+ .filter(token => {
122
+ // Keep tokens that are:
123
+ // - At least 2 characters long
124
+ // - Not a stop word (case-insensitive)
125
+ // - Or look like identifiers (contain underscore/camelCase)
126
+ if (token.length < 2) return false;
127
+ if (stopWords.has(token.toLowerCase()) && !token.includes('_') && !/[A-Z]/.test(token)) {
128
+ return false;
129
+ }
130
+ return true;
131
+ });
132
+
133
+ return tokens;
134
+ }
135
+
136
+ /**
137
+ * Score results based on token match count for ranking
138
+ * @param results - Search results
139
+ * @param tokens - Query tokens
140
+ * @returns Results with match scores
141
+ */
142
+ function scoreByTokenMatch(results: ExactMatch[], tokens: string[]): ExactMatch[] {
143
+ if (tokens.length <= 1) return results;
144
+
145
+ // Create case-insensitive patterns for each token
146
+ const tokenPatterns = tokens.map(t => {
147
+ const escaped = t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
148
+ return new RegExp(escaped, 'i');
149
+ });
150
+
151
+ return results.map(r => {
152
+ const content = r.content || '';
153
+ const file = r.file || '';
154
+ const searchText = `${file} ${content}`;
155
+
156
+ // Count how many tokens match
157
+ let matchCount = 0;
158
+ for (const pattern of tokenPatterns) {
159
+ if (pattern.test(searchText)) {
160
+ matchCount++;
161
+ }
162
+ }
163
+
164
+ // Calculate match ratio (0 to 1)
165
+ const matchRatio = matchCount / tokens.length;
166
+
167
+ return {
168
+ ...r,
169
+ matchScore: matchRatio,
170
+ matchCount,
171
+ };
172
+ }).sort((a, b) => {
173
+ // Sort by match ratio (descending), then by line number
174
+ if (b.matchScore !== a.matchScore) {
175
+ return b.matchScore - a.matchScore;
176
+ }
177
+ return (a.line || 0) - (b.line || 0);
178
+ });
179
+ }
180
+
181
+ interface Classification {
182
+ mode: string;
183
+ confidence: number;
184
+ reasoning: string;
185
+ }
186
+
187
+ interface ExactMatch {
188
+ file: string;
189
+ line: number;
190
+ column: number;
191
+ content: string;
192
+ matchScore?: number; // Token match ratio (0-1) for multi-word queries
193
+ matchCount?: number; // Number of tokens matched
194
+ }
195
+
196
+ interface RelationshipInfo {
197
+ type: string; // 'calls', 'imports', 'called_by', 'imported_by'
198
+ direction: 'outgoing' | 'incoming';
199
+ target?: string; // Target symbol name (for outgoing)
200
+ source?: string; // Source symbol name (for incoming)
201
+ file: string; // File path
202
+ line?: number; // Line number
203
+ }
204
+
205
+ interface SemanticMatch {
206
+ file: string;
207
+ score: number;
208
+ content: string;
209
+ symbol: string | null;
210
+ relationships?: RelationshipInfo[];
211
+ }
212
+
213
+ interface GraphMatch {
214
+ file: string;
215
+ symbols: unknown;
216
+ relationships: unknown[];
217
+ }
218
+
219
+ // File match for find_files action (path-based search)
220
+ interface FileMatch {
221
+ path: string;
222
+ type: 'file' | 'directory';
223
+ name: string; // Filename only
224
+ extension?: string; // File extension (without dot)
225
+ }
226
+
227
+ interface PaginationInfo {
228
+ offset: number; // Starting index of returned results
229
+ limit: number; // Number of results requested
230
+ total: number; // Total number of results found
231
+ has_more: boolean; // True if more results are available
232
+ }
233
+
234
+ interface SearchMetadata {
235
+ mode?: string;
236
+ backend?: string;
237
+ count?: number;
238
+ query?: string;
239
+ pattern?: string; // For find_files action
240
+ classified_as?: string;
241
+ confidence?: number;
242
+ reasoning?: string;
243
+ embeddings_coverage_percent?: number;
244
+ warning?: string;
245
+ note?: string;
246
+ index_status?: 'indexed' | 'not_indexed' | 'partial';
247
+ fallback?: string; // Fallback mode used (e.g., 'fuzzy')
248
+ fallback_history?: string[];
249
+ suggested_weights?: Record<string, number>;
250
+ // Tokenization metadata (ripgrep mode)
251
+ tokens?: string[]; // Query tokens used for multi-word search
252
+ tokenized?: boolean; // Whether tokenization was applied
253
+ // Pagination metadata
254
+ pagination?: PaginationInfo;
255
+ // Init action specific
256
+ action?: string;
257
+ path?: string;
258
+ progress?: {
259
+ stage: string;
260
+ message: string;
261
+ percent: number;
262
+ filesProcessed?: number;
263
+ totalFiles?: number;
264
+ };
265
+ progressHistory?: ProgressInfo[];
266
+ }
267
+
268
+ interface SearchResult {
269
+ success: boolean;
270
+ results?: ExactMatch[] | SemanticMatch[] | GraphMatch[] | FileMatch[] | unknown;
271
+ output?: string;
272
+ metadata?: SearchMetadata;
273
+ error?: string;
274
+ status?: unknown;
275
+ message?: string;
276
+ }
277
+
278
+ interface IndexStatus {
279
+ indexed: boolean;
280
+ has_embeddings: boolean;
281
+ file_count?: number;
282
+ embeddings_coverage_percent?: number;
283
+ warning?: string;
284
+ }
285
+
286
+ /**
287
+ * Strip ANSI color codes from string (for JSON parsing)
288
+ */
289
+ function stripAnsi(str: string): string {
290
+ return str.replace(/\x1b\[[0-9;]*m/g, '');
291
+ }
292
+
293
+ /**
294
+ * Check if CodexLens index exists for current directory
295
+ * @param path - Directory path to check
296
+ * @returns Index status
297
+ */
298
+ async function checkIndexStatus(path: string = '.'): Promise<IndexStatus> {
299
+ try {
300
+ const result = await executeCodexLens(['status', '--json'], { cwd: path });
301
+
302
+ if (!result.success) {
303
+ return {
304
+ indexed: false,
305
+ has_embeddings: false,
306
+ warning: 'No CodexLens index found. Run smart_search(action="init") to create index for better search results.',
307
+ };
308
+ }
309
+
310
+ // Parse status output
311
+ try {
312
+ // Strip ANSI color codes from JSON output
313
+ const cleanOutput = stripAnsi(result.output || '{}');
314
+ const parsed = JSON.parse(cleanOutput);
315
+ // Handle both direct and nested response formats (status returns {success, result: {...}})
316
+ const status = parsed.result || parsed;
317
+ const indexed = status.projects_count > 0 || status.total_files > 0;
318
+
319
+ // Get embeddings coverage from comprehensive status
320
+ const embeddingsData = status.embeddings || {};
321
+ const embeddingsCoverage = embeddingsData.coverage_percent || 0;
322
+ const has_embeddings = embeddingsCoverage >= 50; // Threshold: 50%
323
+
324
+ let warning: string | undefined;
325
+ if (!indexed) {
326
+ warning = 'No CodexLens index found. Run smart_search(action="init") to create index for better search results.';
327
+ } else if (embeddingsCoverage === 0) {
328
+ warning = 'Index exists but no embeddings generated. Run: codexlens embeddings-generate --recursive';
329
+ } else if (embeddingsCoverage < 50) {
330
+ warning = `Embeddings coverage is ${embeddingsCoverage.toFixed(1)}% (below 50%). Hybrid search will use exact mode. Run: codexlens embeddings-generate --recursive`;
331
+ }
332
+
333
+ return {
334
+ indexed,
335
+ has_embeddings,
336
+ file_count: status.total_files,
337
+ embeddings_coverage_percent: embeddingsCoverage,
338
+ warning,
339
+ };
340
+ } catch {
341
+ return {
342
+ indexed: false,
343
+ has_embeddings: false,
344
+ warning: 'Failed to parse index status',
345
+ };
346
+ }
347
+ } catch {
348
+ return {
349
+ indexed: false,
350
+ has_embeddings: false,
351
+ warning: 'CodexLens not available',
352
+ };
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Detection heuristics for intent classification
358
+ */
359
+
360
+ /**
361
+ * Detect literal string query (simple alphanumeric or quoted strings)
362
+ */
363
+ function detectLiteral(query: string): boolean {
364
+ return /^[a-zA-Z0-9_-]+$/.test(query) || /^["'].*["']$/.test(query);
365
+ }
366
+
367
+ /**
368
+ * Detect regex pattern (contains regex metacharacters)
369
+ */
370
+ function detectRegex(query: string): boolean {
371
+ return /[.*+?^${}()|[\]\\]/.test(query);
372
+ }
373
+
374
+ /**
375
+ * Detect natural language query (sentence structure, questions, multi-word phrases)
376
+ */
377
+ function detectNaturalLanguage(query: string): boolean {
378
+ return query.split(/\s+/).length >= 3 || /\?$/.test(query);
379
+ }
380
+
381
+ /**
382
+ * Detect file path query (path separators, file extensions)
383
+ */
384
+ function detectFilePath(query: string): boolean {
385
+ return /[/\\]/.test(query) || /\.[a-z]{2,4}$/i.test(query);
386
+ }
387
+
388
+ /**
389
+ * Detect relationship query (import, export, dependency keywords)
390
+ */
391
+ function detectRelationship(query: string): boolean {
392
+ return /(import|export|uses?|depends?|calls?|extends?)\s/i.test(query);
393
+ }
394
+
395
+ function looksLikeCodeQuery(query: string): boolean {
396
+ if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(query)) return true;
397
+ if (/[:.<>\-=(){}[\]]/.test(query) && query.split(/\s+/).length <= 2) return true;
398
+ if (/\.\*|\\\(|\\\[|\\s/.test(query)) return true;
399
+ if (/^[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]*$/.test(query)) return true;
400
+ return false;
401
+ }
402
+
403
+ /**
404
+ * Classify query intent and recommend search mode
405
+ * Simple mapping: hybrid (NL + index + embeddings) | exact (index or insufficient embeddings) | ripgrep (no index)
406
+ * @param query - Search query string
407
+ * @param hasIndex - Whether CodexLens index exists
408
+ * @param hasSufficientEmbeddings - Whether embeddings coverage >= 50%
409
+ * @returns Classification result
410
+ */
411
+ function classifyIntent(query: string, hasIndex: boolean = false, hasSufficientEmbeddings: boolean = false): Classification {
412
+ const isNaturalLanguage = detectNaturalLanguage(query);
413
+ const isCodeQuery = looksLikeCodeQuery(query);
414
+ const isRegexPattern = detectRegex(query);
415
+
416
+ let mode: string;
417
+ let confidence: number;
418
+
419
+ if (!hasIndex) {
420
+ mode = 'ripgrep';
421
+ confidence = 1.0;
422
+ } else if (isCodeQuery || isRegexPattern) {
423
+ mode = 'exact';
424
+ confidence = 0.95;
425
+ } else if (isNaturalLanguage && hasSufficientEmbeddings) {
426
+ mode = 'hybrid';
427
+ confidence = 0.9;
428
+ } else {
429
+ mode = 'exact';
430
+ confidence = 0.8;
431
+ }
432
+
433
+ const detectedPatterns: string[] = [];
434
+ if (detectLiteral(query)) detectedPatterns.push('literal');
435
+ if (detectRegex(query)) detectedPatterns.push('regex');
436
+ if (detectNaturalLanguage(query)) detectedPatterns.push('natural language');
437
+ if (detectFilePath(query)) detectedPatterns.push('file path');
438
+ if (detectRelationship(query)) detectedPatterns.push('relationship');
439
+ if (isCodeQuery) detectedPatterns.push('code identifier');
440
+
441
+ const reasoning = `Query classified as ${mode} (confidence: ${confidence.toFixed(2)}, detected: ${detectedPatterns.join(', ')}, index: ${hasIndex ? 'available' : 'not available'}, embeddings: ${hasSufficientEmbeddings ? 'sufficient' : 'insufficient'})`;
442
+
443
+ return { mode, confidence, reasoning };
444
+ }
445
+
446
+ /**
447
+ * Check if a tool is available in PATH
448
+ * @param toolName - Tool executable name
449
+ * @returns True if available
450
+ */
451
+ function checkToolAvailability(toolName: string): boolean {
452
+ try {
453
+ const isWindows = process.platform === 'win32';
454
+ const command = isWindows ? 'where' : 'which';
455
+ execSync(`${command} ${toolName}`, { stdio: 'ignore' });
456
+ return true;
457
+ } catch {
458
+ return false;
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Build ripgrep command arguments
464
+ * Supports tokenized multi-word queries with OR matching
465
+ * @param params - Search parameters
466
+ * @returns Command, arguments, and tokens used
467
+ */
468
+ function buildRipgrepCommand(params: {
469
+ query: string;
470
+ paths: string[];
471
+ contextLines: number;
472
+ maxResults: number;
473
+ includeHidden: boolean;
474
+ regex?: boolean;
475
+ caseSensitive?: boolean;
476
+ tokenize?: boolean;
477
+ }): { command: string; args: string[]; tokens: string[] } {
478
+ const { query, paths = ['.'], contextLines = 0, maxResults = 10, includeHidden = false, regex = false, caseSensitive = true, tokenize = true } = params;
479
+
480
+ const args = [
481
+ '-n',
482
+ '--color=never',
483
+ '--json',
484
+ ];
485
+
486
+ // Add file filtering (unless includeHidden is true)
487
+ if (!includeHidden) {
488
+ args.push(...buildExcludeArgs());
489
+ }
490
+
491
+ // Case sensitivity
492
+ if (!caseSensitive) {
493
+ args.push('--ignore-case');
494
+ }
495
+
496
+ if (contextLines > 0) {
497
+ args.push('-C', contextLines.toString());
498
+ }
499
+
500
+ if (maxResults > 0) {
501
+ args.push('--max-count', maxResults.toString());
502
+ }
503
+
504
+ if (includeHidden) {
505
+ args.push('--hidden');
506
+ }
507
+
508
+ // Tokenize query for multi-word OR matching
509
+ const tokens = tokenize ? tokenizeQuery(query) : [query];
510
+
511
+ if (tokens.length > 1) {
512
+ // Multi-token: use multiple -e patterns (OR matching)
513
+ // Each token is escaped for regex safety unless regex mode is enabled
514
+ for (const token of tokens) {
515
+ if (regex) {
516
+ args.push('-e', token);
517
+ } else {
518
+ // Escape regex special chars for literal matching
519
+ const escaped = token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
520
+ args.push('-e', escaped);
521
+ }
522
+ }
523
+ } else {
524
+ // Single token or no tokenization: use original behavior
525
+ if (regex) {
526
+ args.push('-e', query);
527
+ } else {
528
+ args.push('-F', query);
529
+ }
530
+ }
531
+
532
+ args.push(...paths);
533
+
534
+ return { command: 'rg', args, tokens };
535
+ }
536
+
537
+ /**
538
+ * Action: init - Initialize CodexLens index (FTS only, no embeddings)
539
+ * For semantic/vector search, use ccw view dashboard or codexlens CLI directly
540
+ */
541
+ async function executeInitAction(params: Params): Promise<SearchResult> {
542
+ const { path = '.', languages } = params;
543
+
544
+ // Check CodexLens availability
545
+ const readyStatus = await ensureCodexLensReady();
546
+ if (!readyStatus.ready) {
547
+ return {
548
+ success: false,
549
+ error: `CodexLens not available: ${readyStatus.error}. CodexLens will be auto-installed on first use.`,
550
+ };
551
+ }
552
+
553
+ // Build args with --no-embeddings for FTS-only index (faster)
554
+ const args = ['init', path, '--no-embeddings'];
555
+ if (languages && languages.length > 0) {
556
+ args.push('--languages', languages.join(','));
557
+ }
558
+
559
+ // Track progress updates
560
+ const progressUpdates: ProgressInfo[] = [];
561
+ let lastProgress: ProgressInfo | null = null;
562
+
563
+ const result = await executeCodexLens(args, {
564
+ cwd: path,
565
+ timeout: 1800000, // 30 minutes for large codebases
566
+ onProgress: (progress: ProgressInfo) => {
567
+ progressUpdates.push(progress);
568
+ lastProgress = progress;
569
+ },
570
+ });
571
+
572
+ // Build metadata with progress info
573
+ const metadata: SearchMetadata = {
574
+ action: 'init',
575
+ path,
576
+ };
577
+
578
+ if (lastProgress !== null) {
579
+ const p = lastProgress as ProgressInfo;
580
+ metadata.progress = {
581
+ stage: p.stage,
582
+ message: p.message,
583
+ percent: p.percent,
584
+ filesProcessed: p.filesProcessed,
585
+ totalFiles: p.totalFiles,
586
+ };
587
+ }
588
+
589
+ if (progressUpdates.length > 0) {
590
+ metadata.progressHistory = progressUpdates.slice(-5); // Keep last 5 progress updates
591
+ }
592
+
593
+ const successMessage = result.success
594
+ ? `FTS index created for ${path}. Note: For semantic/vector search, create vector index via "ccw view" dashboard or run "codexlens init ${path}" (without --no-embeddings).`
595
+ : undefined;
596
+
597
+ return {
598
+ success: result.success,
599
+ error: result.error,
600
+ message: successMessage,
601
+ metadata,
602
+ };
603
+ }
604
+
605
+ /**
606
+ * Action: status - Check CodexLens index status
607
+ */
608
+ async function executeStatusAction(params: Params): Promise<SearchResult> {
609
+ const { path = '.' } = params;
610
+
611
+ const indexStatus = await checkIndexStatus(path);
612
+
613
+ return {
614
+ success: true,
615
+ status: indexStatus,
616
+ message: indexStatus.warning || `Index status: ${indexStatus.indexed ? 'indexed' : 'not indexed'}, embeddings: ${indexStatus.has_embeddings ? 'available' : 'not available'}`,
617
+ };
618
+ }
619
+
620
+ /**
621
+ * Mode: auto - Intent classification and mode selection
622
+ * Routes to: hybrid (NL + index) | exact (index) | ripgrep (no index)
623
+ */
624
+ async function executeAutoMode(params: Params): Promise<SearchResult> {
625
+ const { query, path = '.' } = params;
626
+
627
+ if (!query) {
628
+ return {
629
+ success: false,
630
+ error: 'Query is required for search action',
631
+ };
632
+ }
633
+
634
+ // Check index status
635
+ const indexStatus = await checkIndexStatus(path);
636
+
637
+ // Classify intent with index and embeddings awareness
638
+ const classification = classifyIntent(
639
+ query,
640
+ indexStatus.indexed,
641
+ indexStatus.has_embeddings // This now considers 50% threshold
642
+ );
643
+
644
+ // Route to appropriate mode based on classification
645
+ let result: SearchResult;
646
+
647
+ switch (classification.mode) {
648
+ case 'hybrid':
649
+ result = await executeHybridMode(params);
650
+ break;
651
+
652
+ case 'exact':
653
+ result = await executeCodexLensExactMode(params);
654
+ break;
655
+
656
+ case 'ripgrep':
657
+ result = await executeRipgrepMode(params);
658
+ break;
659
+
660
+ default:
661
+ // Fallback to ripgrep
662
+ result = await executeRipgrepMode(params);
663
+ break;
664
+ }
665
+
666
+ // Add classification metadata
667
+ if (result.metadata) {
668
+ result.metadata.classified_as = classification.mode;
669
+ result.metadata.confidence = classification.confidence;
670
+ result.metadata.reasoning = classification.reasoning;
671
+ result.metadata.embeddings_coverage_percent = indexStatus.embeddings_coverage_percent;
672
+ result.metadata.index_status = indexStatus.indexed
673
+ ? (indexStatus.has_embeddings ? 'indexed' : 'partial')
674
+ : 'not_indexed';
675
+
676
+ // Add warning if needed
677
+ if (indexStatus.warning) {
678
+ result.metadata.warning = indexStatus.warning;
679
+ }
680
+ }
681
+
682
+ return result;
683
+ }
684
+
685
+ /**
686
+ * Mode: ripgrep - Fast literal string matching using ripgrep
687
+ * No index required, fallback to CodexLens if ripgrep unavailable
688
+ * Supports tokenized multi-word queries with OR matching and result ranking
689
+ */
690
+ async function executeRipgrepMode(params: Params): Promise<SearchResult> {
691
+ const { query, paths = [], contextLines = 0, maxResults = 10, includeHidden = false, path = '.', regex = true, caseSensitive = true, tokenize = true } = params;
692
+
693
+ if (!query) {
694
+ return {
695
+ success: false,
696
+ error: 'Query is required for search',
697
+ };
698
+ }
699
+
700
+ // Check if ripgrep is available
701
+ const hasRipgrep = checkToolAvailability('rg');
702
+
703
+ // If ripgrep not available, fall back to CodexLens exact mode
704
+ if (!hasRipgrep) {
705
+ const readyStatus = await ensureCodexLensReady();
706
+ if (!readyStatus.ready) {
707
+ return {
708
+ success: false,
709
+ error: 'Neither ripgrep nor CodexLens available. Install ripgrep (rg) or CodexLens for search functionality.',
710
+ };
711
+ }
712
+
713
+ // Use CodexLens exact mode as fallback
714
+ const args = ['search', query, '--limit', maxResults.toString(), '--mode', 'exact', '--json'];
715
+ const result = await executeCodexLens(args, { cwd: path });
716
+
717
+ if (!result.success) {
718
+ return {
719
+ success: false,
720
+ error: result.error,
721
+ metadata: {
722
+ mode: 'ripgrep',
723
+ backend: 'codexlens-fallback',
724
+ count: 0,
725
+ query,
726
+ },
727
+ };
728
+ }
729
+
730
+ // Parse results
731
+ let results: SemanticMatch[] = [];
732
+ try {
733
+ const parsed = JSON.parse(stripAnsi(result.output || '{}'));
734
+ const data = parsed.result?.results || parsed.results || parsed;
735
+ results = (Array.isArray(data) ? data : []).map((item: any) => ({
736
+ file: item.path || item.file,
737
+ score: item.score || 0,
738
+ content: item.excerpt || item.content || '',
739
+ symbol: item.symbol || null,
740
+ }));
741
+ } catch {
742
+ // Keep empty results
743
+ }
744
+
745
+ return {
746
+ success: true,
747
+ results,
748
+ metadata: {
749
+ mode: 'ripgrep',
750
+ backend: 'codexlens-fallback',
751
+ count: results.length,
752
+ query,
753
+ note: 'Using CodexLens exact mode (ripgrep not available)',
754
+ },
755
+ };
756
+ }
757
+
758
+ // Use ripgrep
759
+ const { command, args, tokens } = buildRipgrepCommand({
760
+ query,
761
+ paths: paths.length > 0 ? paths : [path],
762
+ contextLines,
763
+ maxResults,
764
+ includeHidden,
765
+ regex,
766
+ caseSensitive,
767
+ tokenize,
768
+ });
769
+
770
+ return new Promise((resolve) => {
771
+ const child = spawn(command, args, {
772
+ cwd: path || getProjectRoot(),
773
+ stdio: ['ignore', 'pipe', 'pipe'],
774
+ });
775
+
776
+ let stdout = '';
777
+ let stderr = '';
778
+ let resultLimitReached = false;
779
+
780
+ child.stdout.on('data', (data) => {
781
+ stdout += data.toString();
782
+ });
783
+
784
+ child.stderr.on('data', (data) => {
785
+ stderr += data.toString();
786
+ });
787
+
788
+ child.on('close', (code) => {
789
+ const results: ExactMatch[] = [];
790
+ const lines = stdout.split('\n').filter((line) => line.trim());
791
+ // Limit total results to prevent memory overflow (--max-count only limits per-file)
792
+ const effectiveLimit = maxResults > 0 ? maxResults : 500;
793
+
794
+ for (const line of lines) {
795
+ // Stop collecting if we've reached the limit
796
+ if (results.length >= effectiveLimit) {
797
+ resultLimitReached = true;
798
+ break;
799
+ }
800
+
801
+ try {
802
+ const item = JSON.parse(line);
803
+
804
+ if (item.type === 'match') {
805
+ const match: ExactMatch = {
806
+ file: item.data.path.text,
807
+ line: item.data.line_number,
808
+ column:
809
+ item.data.submatches && item.data.submatches[0]
810
+ ? item.data.submatches[0].start + 1
811
+ : 1,
812
+ content: item.data.lines.text.trim(),
813
+ };
814
+ results.push(match);
815
+ }
816
+ } catch {
817
+ continue;
818
+ }
819
+ }
820
+
821
+ // Handle Windows device file errors gracefully (os error 1)
822
+ // If we have results despite the error, return them as partial success
823
+ const isWindowsDeviceError = stderr.includes('os error 1') || stderr.includes('函数不正确');
824
+
825
+ // Apply token-based scoring and sorting for multi-word queries
826
+ // Results matching more tokens are ranked higher (exact matches first)
827
+ const scoredResults = tokens.length > 1 ? scoreByTokenMatch(results, tokens) : results;
828
+
829
+ if (code === 0 || code === 1 || (isWindowsDeviceError && scoredResults.length > 0)) {
830
+ // Build warning message for various conditions
831
+ const warnings: string[] = [];
832
+ if (resultLimitReached) {
833
+ warnings.push(`Result limit reached (${effectiveLimit}). Use a more specific query or increase limit.`);
834
+ }
835
+ if (isWindowsDeviceError) {
836
+ warnings.push('Some Windows device files were skipped');
837
+ }
838
+
839
+ resolve({
840
+ success: true,
841
+ results: scoredResults,
842
+ metadata: {
843
+ mode: 'ripgrep',
844
+ backend: 'ripgrep',
845
+ count: scoredResults.length,
846
+ query,
847
+ tokens: tokens.length > 1 ? tokens : undefined, // Include tokens in metadata for debugging
848
+ tokenized: tokens.length > 1,
849
+ ...(warnings.length > 0 && { warning: warnings.join('; ') }),
850
+ },
851
+ });
852
+ } else if (isWindowsDeviceError && results.length === 0) {
853
+ // Windows device error but no results - might be the only issue
854
+ resolve({
855
+ success: true,
856
+ results: [],
857
+ metadata: {
858
+ mode: 'ripgrep',
859
+ backend: 'ripgrep',
860
+ count: 0,
861
+ query,
862
+ warning: 'No matches found (some Windows device files were skipped)',
863
+ },
864
+ });
865
+ } else {
866
+ resolve({
867
+ success: false,
868
+ error: `ripgrep execution failed with code ${code}: ${stderr}`,
869
+ results: [],
870
+ });
871
+ }
872
+ });
873
+
874
+ child.on('error', (error) => {
875
+ resolve({
876
+ success: false,
877
+ error: `Failed to spawn ripgrep: ${error.message}`,
878
+ results: [],
879
+ });
880
+ });
881
+ });
882
+ }
883
+
884
+ /**
885
+ * Mode: exact - CodexLens exact/FTS search
886
+ * Requires index
887
+ */
888
+ async function executeCodexLensExactMode(params: Params): Promise<SearchResult> {
889
+ const { query, path = '.', maxResults = 10, enrich = false } = params;
890
+
891
+ if (!query) {
892
+ return {
893
+ success: false,
894
+ error: 'Query is required for search',
895
+ };
896
+ }
897
+
898
+ // Check CodexLens availability
899
+ const readyStatus = await ensureCodexLensReady();
900
+ if (!readyStatus.ready) {
901
+ return {
902
+ success: false,
903
+ error: `CodexLens not available: ${readyStatus.error}`,
904
+ };
905
+ }
906
+
907
+ // Check index status
908
+ const indexStatus = await checkIndexStatus(path);
909
+
910
+ const args = ['search', query, '--limit', maxResults.toString(), '--mode', 'exact', '--json'];
911
+ if (enrich) {
912
+ args.push('--enrich');
913
+ }
914
+ const result = await executeCodexLens(args, { cwd: path });
915
+
916
+ if (!result.success) {
917
+ return {
918
+ success: false,
919
+ error: result.error,
920
+ metadata: {
921
+ mode: 'exact',
922
+ backend: 'codexlens',
923
+ count: 0,
924
+ query,
925
+ warning: indexStatus.warning,
926
+ },
927
+ };
928
+ }
929
+
930
+ // Parse results
931
+ let results: SemanticMatch[] = [];
932
+ try {
933
+ const parsed = JSON.parse(stripAnsi(result.output || '{}'));
934
+ const data = parsed.result?.results || parsed.results || parsed;
935
+ results = (Array.isArray(data) ? data : []).map((item: any) => ({
936
+ file: item.path || item.file,
937
+ score: item.score || 0,
938
+ content: item.excerpt || item.content || '',
939
+ symbol: item.symbol || null,
940
+ }));
941
+ } catch {
942
+ // Keep empty results
943
+ }
944
+
945
+ // Fallback to fuzzy mode if exact returns no results
946
+ if (results.length === 0) {
947
+ const fuzzyArgs = ['search', query, '--limit', maxResults.toString(), '--mode', 'fuzzy', '--json'];
948
+ if (enrich) {
949
+ fuzzyArgs.push('--enrich');
950
+ }
951
+ const fuzzyResult = await executeCodexLens(fuzzyArgs, { cwd: path });
952
+
953
+ if (fuzzyResult.success) {
954
+ try {
955
+ const parsed = JSON.parse(stripAnsi(fuzzyResult.output || '{}'));
956
+ const data = parsed.result?.results || parsed.results || parsed;
957
+ results = (Array.isArray(data) ? data : []).map((item: any) => ({
958
+ file: item.path || item.file,
959
+ score: item.score || 0,
960
+ content: item.excerpt || item.content || '',
961
+ symbol: item.symbol || null,
962
+ }));
963
+ } catch {
964
+ // Keep empty results
965
+ }
966
+
967
+ if (results.length > 0) {
968
+ return {
969
+ success: true,
970
+ results,
971
+ metadata: {
972
+ mode: 'exact',
973
+ backend: 'codexlens',
974
+ count: results.length,
975
+ query,
976
+ warning: indexStatus.warning,
977
+ note: 'No exact matches found, showing fuzzy results',
978
+ fallback: 'fuzzy',
979
+ },
980
+ };
981
+ }
982
+ }
983
+ }
984
+
985
+ return {
986
+ success: true,
987
+ results,
988
+ metadata: {
989
+ mode: 'exact',
990
+ backend: 'codexlens',
991
+ count: results.length,
992
+ query,
993
+ warning: indexStatus.warning,
994
+ },
995
+ };
996
+ }
997
+
998
+ /**
999
+ * Mode: hybrid - Best quality search with RRF fusion
1000
+ * Uses CodexLens hybrid mode (exact + fuzzy + vector)
1001
+ * Requires index with embeddings
1002
+ */
1003
+ async function executeHybridMode(params: Params): Promise<SearchResult> {
1004
+ const { query, path = '.', maxResults = 10, enrich = false } = params;
1005
+
1006
+ if (!query) {
1007
+ return {
1008
+ success: false,
1009
+ error: 'Query is required for search',
1010
+ };
1011
+ }
1012
+
1013
+ // Check CodexLens availability
1014
+ const readyStatus = await ensureCodexLensReady();
1015
+ if (!readyStatus.ready) {
1016
+ return {
1017
+ success: false,
1018
+ error: `CodexLens not available: ${readyStatus.error}`,
1019
+ };
1020
+ }
1021
+
1022
+ // Check index status
1023
+ const indexStatus = await checkIndexStatus(path);
1024
+
1025
+ const args = ['search', query, '--limit', maxResults.toString(), '--mode', 'hybrid', '--json'];
1026
+ if (enrich) {
1027
+ args.push('--enrich');
1028
+ }
1029
+ const result = await executeCodexLens(args, { cwd: path });
1030
+
1031
+ if (!result.success) {
1032
+ return {
1033
+ success: false,
1034
+ error: result.error,
1035
+ metadata: {
1036
+ mode: 'hybrid',
1037
+ backend: 'codexlens',
1038
+ count: 0,
1039
+ query,
1040
+ warning: indexStatus.warning,
1041
+ },
1042
+ };
1043
+ }
1044
+
1045
+ // Parse results
1046
+ let results: SemanticMatch[] = [];
1047
+ let baselineInfo: { score: number; count: number } | null = null;
1048
+ let initialCount = 0;
1049
+
1050
+ try {
1051
+ const parsed = JSON.parse(stripAnsi(result.output || '{}'));
1052
+ const data = parsed.result?.results || parsed.results || parsed;
1053
+ results = (Array.isArray(data) ? data : []).map((item: any) => {
1054
+ const rawScore = item.score || 0;
1055
+ // Hybrid mode returns distance scores (lower is better).
1056
+ // Convert to similarity scores (higher is better) for consistency.
1057
+ // Formula: similarity = 1 / (1 + distance)
1058
+ const similarityScore = rawScore > 0 ? 1 / (1 + rawScore) : 1;
1059
+ return {
1060
+ file: item.path || item.file,
1061
+ score: similarityScore,
1062
+ content: item.excerpt || item.content || '',
1063
+ symbol: item.symbol || null,
1064
+ };
1065
+ });
1066
+
1067
+ initialCount = results.length;
1068
+
1069
+ // Post-processing pipeline to improve semantic search quality
1070
+ // 0. Filter dominant baseline scores (hot spot detection)
1071
+ const baselineResult = filterDominantBaselineScores(results);
1072
+ results = baselineResult.filteredResults;
1073
+ baselineInfo = baselineResult.baselineInfo;
1074
+
1075
+ // 1. Filter noisy files (coverage, node_modules, etc.)
1076
+ results = filterNoisyFiles(results);
1077
+ // 2. Boost results containing query keywords
1078
+ results = applyKeywordBoosting(results, query);
1079
+ // 3. Enforce score diversity (penalize identical scores)
1080
+ results = enforceScoreDiversity(results);
1081
+ // 4. Re-sort by adjusted scores
1082
+ results.sort((a, b) => b.score - a.score);
1083
+ } catch {
1084
+ return {
1085
+ success: true,
1086
+ results: [],
1087
+ output: result.output,
1088
+ metadata: {
1089
+ mode: 'hybrid',
1090
+ backend: 'codexlens',
1091
+ count: 0,
1092
+ query,
1093
+ warning: indexStatus.warning || 'Failed to parse JSON output',
1094
+ },
1095
+ };
1096
+ }
1097
+
1098
+ // Build metadata with baseline info if detected
1099
+ let note = 'Hybrid mode uses RRF fusion (exact + fuzzy + vector) for best results';
1100
+ if (baselineInfo) {
1101
+ note += ` | Filtered ${initialCount - results.length} hot-spot results with baseline score ~${baselineInfo.score.toFixed(4)}`;
1102
+ }
1103
+
1104
+ return {
1105
+ success: true,
1106
+ results,
1107
+ metadata: {
1108
+ mode: 'hybrid',
1109
+ backend: 'codexlens',
1110
+ count: results.length,
1111
+ query,
1112
+ note,
1113
+ warning: indexStatus.warning,
1114
+ suggested_weights: getRRFWeights(query),
1115
+ },
1116
+ };
1117
+ }
1118
+
1119
+ const RRF_WEIGHTS = {
1120
+ code: { exact: 0.7, fuzzy: 0.2, vector: 0.1 },
1121
+ natural: { exact: 0.4, fuzzy: 0.2, vector: 0.4 },
1122
+ default: { exact: 0.5, fuzzy: 0.2, vector: 0.3 },
1123
+ };
1124
+
1125
+ function getRRFWeights(query: string): Record<string, number> {
1126
+ const isCode = looksLikeCodeQuery(query);
1127
+ const isNatural = detectNaturalLanguage(query);
1128
+ if (isCode) return RRF_WEIGHTS.code;
1129
+ if (isNatural) return RRF_WEIGHTS.natural;
1130
+ return RRF_WEIGHTS.default;
1131
+ }
1132
+
1133
+ /**
1134
+ * Post-processing: Filter noisy files from semantic search results
1135
+ * Uses FILTER_CONFIG patterns to remove irrelevant files.
1136
+ * Optimized: pre-compiled regexes, accurate path segment matching.
1137
+ */
1138
+ // Pre-compile file exclusion regexes once (avoid recompilation in loop)
1139
+ const FILE_EXCLUDE_REGEXES = [...FILTER_CONFIG.exclude_files].map(pattern =>
1140
+ new RegExp('^' + pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\\\*/g, '.*') + '$')
1141
+ );
1142
+
1143
+ function filterNoisyFiles(results: SemanticMatch[]): SemanticMatch[] {
1144
+ return results.filter(r => {
1145
+ const filePath = r.file || '';
1146
+ if (!filePath) return true;
1147
+
1148
+ const segments = filePath.split(/[/\\]/);
1149
+
1150
+ // Accurate directory check: segment must exactly match excluded directory
1151
+ if (segments.some(segment => FILTER_CONFIG.exclude_directories.has(segment))) {
1152
+ return false;
1153
+ }
1154
+
1155
+ // Accurate file check: pattern matches filename only (not full path)
1156
+ const filename = segments.pop() || '';
1157
+ if (FILE_EXCLUDE_REGEXES.some(regex => regex.test(filename))) {
1158
+ return false;
1159
+ }
1160
+
1161
+ return true;
1162
+ });
1163
+ }
1164
+
1165
+ /**
1166
+ * Post-processing: Boost results containing query keywords
1167
+ * Extracts keywords from query and boosts matching results.
1168
+ * Optimized: uses whole-word matching with regex for accuracy.
1169
+ */
1170
+ // Helper to escape regex special characters
1171
+ function escapeRegExp(str: string): string {
1172
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1173
+ }
1174
+
1175
+ function applyKeywordBoosting(results: SemanticMatch[], query: string): SemanticMatch[] {
1176
+ // Extract meaningful keywords (ignore common words)
1177
+ const stopWords = new Set(['the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could', 'should', 'may', 'might', 'must', 'shall', 'can', 'need', 'dare', 'ought', 'used', 'to', 'of', 'in', 'for', 'on', 'with', 'at', 'by', 'from', 'as', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'between', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 'just', 'and', 'but', 'if', 'or', 'because', 'until', 'while', 'although', 'though', 'after', 'before', 'when', 'whenever', 'where', 'wherever', 'whether', 'which', 'who', 'whom', 'whose', 'what', 'whatever', 'whichever', 'whoever', 'whomever', 'this', 'that', 'these', 'those', 'it', 'its']);
1178
+
1179
+ const keywords = query
1180
+ .toLowerCase()
1181
+ .split(/[\s,.;:()"{}[\]-]+/) // More robust splitting on punctuation
1182
+ .filter(word => word.length > 2 && !stopWords.has(word));
1183
+
1184
+ if (keywords.length === 0) return results;
1185
+
1186
+ // Create case-insensitive regexes for whole-word matching
1187
+ const keywordRegexes = keywords.map(kw => new RegExp(`\\b${escapeRegExp(kw)}\\b`, 'i'));
1188
+
1189
+ return results.map(r => {
1190
+ const content = r.content || '';
1191
+ const file = r.file || '';
1192
+
1193
+ // Count keyword matches using whole-word regex
1194
+ let matchCount = 0;
1195
+ for (const regex of keywordRegexes) {
1196
+ if (regex.test(content) || regex.test(file)) {
1197
+ matchCount++;
1198
+ }
1199
+ }
1200
+
1201
+ // Apply boost only if there are matches
1202
+ if (matchCount > 0) {
1203
+ const matchRatio = matchCount / keywords.length;
1204
+ const boost = 1 + (matchRatio * 0.3); // Up to 30% boost for full match
1205
+ return {
1206
+ ...r,
1207
+ score: r.score * boost,
1208
+ };
1209
+ }
1210
+
1211
+ return r;
1212
+ });
1213
+ }
1214
+
1215
+ /**
1216
+ * Post-processing: Enforce score diversity
1217
+ * Penalizes results with identical scores (indicates undifferentiated matching)
1218
+ */
1219
+ function enforceScoreDiversity(results: SemanticMatch[]): SemanticMatch[] {
1220
+ if (results.length < 2) return results;
1221
+
1222
+ // Count occurrences of each score (rounded to 3 decimal places for comparison)
1223
+ const scoreCounts = new Map<number, number>();
1224
+ for (const r of results) {
1225
+ const roundedScore = Math.round(r.score * 1000) / 1000;
1226
+ scoreCounts.set(roundedScore, (scoreCounts.get(roundedScore) || 0) + 1);
1227
+ }
1228
+
1229
+ // Apply penalty to scores that appear more than twice
1230
+ return results.map(r => {
1231
+ const roundedScore = Math.round(r.score * 1000) / 1000;
1232
+ const count = scoreCounts.get(roundedScore) || 1;
1233
+
1234
+ if (count > 2) {
1235
+ // Progressive penalty: more duplicates = bigger penalty
1236
+ const penalty = Math.max(0.7, 1 - (count * 0.05));
1237
+ return { ...r, score: r.score * penalty };
1238
+ }
1239
+ return r;
1240
+ });
1241
+ }
1242
+
1243
+ /**
1244
+ * Post-processing: Filter results with dominant baseline score (hot spot detection)
1245
+ * When backend returns default "hot spot" files with identical high scores,
1246
+ * this function detects and removes them.
1247
+ *
1248
+ * Detection criteria:
1249
+ * - A single score appears in >50% of results
1250
+ * - That score is suspiciously high (>0.9)
1251
+ * - This indicates fallback mechanism returned placeholder results
1252
+ */
1253
+ function filterDominantBaselineScores(
1254
+ results: SemanticMatch[]
1255
+ ): { filteredResults: SemanticMatch[]; baselineInfo: { score: number; count: number } | null } {
1256
+ if (results.length < 4) {
1257
+ return { filteredResults: results, baselineInfo: null };
1258
+ }
1259
+
1260
+ // Count occurrences of each score (rounded to 4 decimal places)
1261
+ const scoreCounts = new Map<number, number>();
1262
+ results.forEach(r => {
1263
+ const rounded = Math.round(r.score * 10000) / 10000;
1264
+ scoreCounts.set(rounded, (scoreCounts.get(rounded) || 0) + 1);
1265
+ });
1266
+
1267
+ // Find the most dominant score
1268
+ let dominantScore: number | null = null;
1269
+ let dominantCount = 0;
1270
+ scoreCounts.forEach((count, score) => {
1271
+ if (count > dominantCount) {
1272
+ dominantCount = count;
1273
+ dominantScore = score;
1274
+ }
1275
+ });
1276
+
1277
+ // If a single score is present in >50% of results and is high (>0.9),
1278
+ // treat it as a suspicious baseline score and filter it out
1279
+ const BASELINE_THRESHOLD = 0.5; // >50% of results have same score
1280
+ const HIGH_SCORE_THRESHOLD = 0.9; // Score above 0.9 is suspiciously high
1281
+
1282
+ if (
1283
+ dominantScore !== null &&
1284
+ dominantCount > results.length * BASELINE_THRESHOLD &&
1285
+ dominantScore > HIGH_SCORE_THRESHOLD
1286
+ ) {
1287
+ const filteredResults = results.filter(r => {
1288
+ const rounded = Math.round(r.score * 10000) / 10000;
1289
+ return rounded !== dominantScore;
1290
+ });
1291
+
1292
+ return {
1293
+ filteredResults,
1294
+ baselineInfo: { score: dominantScore, count: dominantCount },
1295
+ };
1296
+ }
1297
+
1298
+ return { filteredResults: results, baselineInfo: null };
1299
+ }
1300
+
1301
+ /**
1302
+ * TypeScript implementation of Reciprocal Rank Fusion
1303
+ * Reference: codex-lens/src/codexlens/search/ranking.py
1304
+ * Formula: score(d) = Σ weight_source / (k + rank_source(d))
1305
+ */
1306
+ function applyRRFFusion(
1307
+ resultsMap: Map<string, any[]>,
1308
+ weights: Record<string, number>,
1309
+ limit: number,
1310
+ k: number = 60,
1311
+ ): any[] {
1312
+ const pathScores = new Map<string, { score: number; result: any; sources: string[] }>();
1313
+
1314
+ resultsMap.forEach((results, source) => {
1315
+ const weight = weights[source] || 0;
1316
+ if (weight === 0 || !results) return;
1317
+
1318
+ results.forEach((result, rank) => {
1319
+ const path = result.file || result.path;
1320
+ if (!path) return;
1321
+
1322
+ const rrfContribution = weight / (k + rank + 1);
1323
+
1324
+ if (!pathScores.has(path)) {
1325
+ pathScores.set(path, { score: 0, result, sources: [] });
1326
+ }
1327
+ const entry = pathScores.get(path)!;
1328
+ entry.score += rrfContribution;
1329
+ if (!entry.sources.includes(source)) {
1330
+ entry.sources.push(source);
1331
+ }
1332
+ });
1333
+ });
1334
+
1335
+ // Sort by fusion score descending
1336
+ return Array.from(pathScores.values())
1337
+ .sort((a, b) => b.score - a.score)
1338
+ .slice(0, limit)
1339
+ .map(item => ({
1340
+ ...item.result,
1341
+ fusion_score: item.score,
1342
+ matched_backends: item.sources,
1343
+ }));
1344
+ }
1345
+
1346
+ /**
1347
+ * Promise wrapper with timeout support
1348
+ * @param promise - The promise to wrap
1349
+ * @param ms - Timeout in milliseconds
1350
+ * @param modeName - Name of the mode for error message
1351
+ * @returns A new promise that rejects on timeout
1352
+ */
1353
+ function withTimeout<T>(promise: Promise<T>, ms: number, modeName: string): Promise<T> {
1354
+ return new Promise((resolve, reject) => {
1355
+ const timer = setTimeout(() => {
1356
+ reject(new Error(`'${modeName}' search timed out after ${ms}ms`));
1357
+ }, ms);
1358
+
1359
+ promise
1360
+ .then(resolve)
1361
+ .catch(reject)
1362
+ .finally(() => clearTimeout(timer));
1363
+ });
1364
+ }
1365
+
1366
+ /**
1367
+ * Mode: priority - Fallback search strategy: hybrid -> exact -> ripgrep
1368
+ * Returns results from the first backend that succeeds and provides results.
1369
+ * More efficient than parallel mode - stops as soon as valid results are found.
1370
+ */
1371
+ async function executePriorityFallbackMode(params: Params): Promise<SearchResult> {
1372
+ const { query, path = '.' } = params;
1373
+ const fallbackHistory: string[] = [];
1374
+
1375
+ if (!query) {
1376
+ return { success: false, error: 'Query is required for search' };
1377
+ }
1378
+
1379
+ // Check index status first
1380
+ const indexStatus = await checkIndexStatus(path);
1381
+
1382
+ // 1. Try Hybrid search (highest priority) - 90s timeout for large indexes
1383
+ if (indexStatus.indexed && indexStatus.has_embeddings) {
1384
+ try {
1385
+ const hybridResult = await withTimeout(executeHybridMode(params), 90000, 'hybrid');
1386
+ if (hybridResult.success && hybridResult.results && (hybridResult.results as any[]).length > 0) {
1387
+ fallbackHistory.push('hybrid: success');
1388
+ return {
1389
+ ...hybridResult,
1390
+ metadata: {
1391
+ ...hybridResult.metadata,
1392
+ mode: 'priority',
1393
+ note: 'Result from hybrid search (semantic + vector).',
1394
+ fallback_history: fallbackHistory,
1395
+ },
1396
+ };
1397
+ }
1398
+ fallbackHistory.push('hybrid: no results');
1399
+ } catch (error) {
1400
+ fallbackHistory.push(`hybrid: ${(error as Error).message}`);
1401
+ }
1402
+ } else {
1403
+ fallbackHistory.push(`hybrid: skipped (${!indexStatus.indexed ? 'no index' : 'no embeddings'})`);
1404
+ }
1405
+
1406
+ // 2. Fallback to Exact search - 10s timeout
1407
+ if (indexStatus.indexed) {
1408
+ try {
1409
+ const exactResult = await withTimeout(executeCodexLensExactMode(params), 10000, 'exact');
1410
+ if (exactResult.success && exactResult.results && (exactResult.results as any[]).length > 0) {
1411
+ fallbackHistory.push('exact: success');
1412
+ return {
1413
+ ...exactResult,
1414
+ metadata: {
1415
+ ...exactResult.metadata,
1416
+ mode: 'priority',
1417
+ note: 'Result from exact/FTS search (fallback from hybrid).',
1418
+ fallback_history: fallbackHistory,
1419
+ },
1420
+ };
1421
+ }
1422
+ fallbackHistory.push('exact: no results');
1423
+ } catch (error) {
1424
+ fallbackHistory.push(`exact: ${(error as Error).message}`);
1425
+ }
1426
+ } else {
1427
+ fallbackHistory.push('exact: skipped (no index)');
1428
+ }
1429
+
1430
+ // 3. Final fallback to Ripgrep - 5s timeout
1431
+ try {
1432
+ const ripgrepResult = await withTimeout(executeRipgrepMode(params), 5000, 'ripgrep');
1433
+ fallbackHistory.push(ripgrepResult.success ? 'ripgrep: success' : 'ripgrep: failed');
1434
+ return {
1435
+ ...ripgrepResult,
1436
+ metadata: {
1437
+ ...ripgrepResult.metadata,
1438
+ mode: 'priority',
1439
+ note: 'Result from ripgrep search (final fallback).',
1440
+ fallback_history: fallbackHistory,
1441
+ },
1442
+ };
1443
+ } catch (error) {
1444
+ fallbackHistory.push(`ripgrep: ${(error as Error).message}`);
1445
+ }
1446
+
1447
+ // All modes failed
1448
+ return {
1449
+ success: false,
1450
+ error: 'All search backends in priority mode failed or returned no results.',
1451
+ metadata: {
1452
+ mode: 'priority',
1453
+ query,
1454
+ fallback_history: fallbackHistory,
1455
+ } as any,
1456
+ };
1457
+ }
1458
+
1459
+ // Tool schema for MCP
1460
+ export const schema: ToolSchema = {
1461
+ name: 'smart_search',
1462
+ description: `Unified code search tool with content search, file discovery, and semantic search capabilities.
1463
+
1464
+ **Actions:**
1465
+ - search: Search file content (default)
1466
+ - find_files: Find files by path/name pattern (glob matching)
1467
+ - init: Create FTS index
1468
+ - status: Check index status
1469
+
1470
+ **Content Search (action="search"):**
1471
+ smart_search(query="authentication logic") # auto mode - routes to best backend
1472
+ smart_search(query="MyClass", mode="exact") # exact mode - precise FTS matching
1473
+ smart_search(query="auth", mode="ripgrep") # ripgrep mode - fast literal search
1474
+ smart_search(query="how to auth", mode="hybrid") # hybrid mode - semantic + fuzzy search
1475
+
1476
+ **File Discovery (action="find_files"):**
1477
+ smart_search(action="find_files", pattern="*.ts") # find all TypeScript files
1478
+ smart_search(action="find_files", pattern="src/**/*.js") # recursive glob pattern
1479
+ smart_search(action="find_files", pattern="test_*.py") # find test files
1480
+ smart_search(action="find_files", pattern="*.tsx", offset=20, limit=10) # pagination
1481
+
1482
+ **Pagination:** All actions support offset/limit for paginated results:
1483
+ smart_search(query="auth", limit=10, offset=0) # first page
1484
+ smart_search(query="auth", limit=10, offset=10) # second page
1485
+
1486
+ **Multi-Word Search (ripgrep mode with tokenization):**
1487
+ smart_search(query="CCW_PROJECT_ROOT CCW_ALLOWED_DIRS", mode="ripgrep") # tokenized OR matching
1488
+ smart_search(query="auth login user", mode="ripgrep") # matches any token, ranks by match count
1489
+ smart_search(query="exact phrase", mode="ripgrep", tokenize=false) # disable tokenization
1490
+
1491
+ **Regex Search (ripgrep mode):**
1492
+ smart_search(query="class.*Builder") # auto-detects regex pattern
1493
+ smart_search(query="def.*\\(.*\\):") # find function definitions
1494
+ smart_search(query="import.*from", caseSensitive=false) # case-insensitive
1495
+
1496
+ **Modes:** auto (intelligent routing), hybrid (semantic+fuzzy), exact (FTS), ripgrep (fast with tokenization), priority (fallback chain)`,
1497
+ inputSchema: {
1498
+ type: 'object',
1499
+ properties: {
1500
+ action: {
1501
+ type: 'string',
1502
+ enum: ['init', 'search', 'find_files', 'status', 'search_files'],
1503
+ description: 'Action: search (content search), find_files (path pattern matching), init (create index), status (check index). Note: search_files is deprecated.',
1504
+ default: 'search',
1505
+ },
1506
+ query: {
1507
+ type: 'string',
1508
+ description: 'Content search query (for action="search")',
1509
+ },
1510
+ pattern: {
1511
+ type: 'string',
1512
+ description: 'Glob pattern for file discovery (for action="find_files"). Examples: "*.ts", "src/**/*.js", "test_*.py"',
1513
+ },
1514
+ mode: {
1515
+ type: 'string',
1516
+ enum: SEARCH_MODES,
1517
+ description: 'Search mode: auto (default), hybrid (best quality), exact (CodexLens FTS), ripgrep (fast, no index), priority (fallback: hybrid->exact->ripgrep)',
1518
+ default: 'auto',
1519
+ },
1520
+ output_mode: {
1521
+ type: 'string',
1522
+ enum: ['full', 'files_only', 'count'],
1523
+ description: 'Output format: full (default), files_only (paths only), count (per-file counts)',
1524
+ default: 'full',
1525
+ },
1526
+ path: {
1527
+ type: 'string',
1528
+ description: 'Directory path for init/search actions (default: current directory)',
1529
+ },
1530
+ paths: {
1531
+ type: 'array',
1532
+ description: 'Multiple paths to search within (for search action)',
1533
+ items: {
1534
+ type: 'string',
1535
+ },
1536
+ default: [],
1537
+ },
1538
+ contextLines: {
1539
+ type: 'number',
1540
+ description: 'Number of context lines around matches (exact mode only)',
1541
+ default: 0,
1542
+ },
1543
+ maxResults: {
1544
+ type: 'number',
1545
+ description: 'Maximum number of results (default: 20)',
1546
+ default: 20,
1547
+ },
1548
+ limit: {
1549
+ type: 'number',
1550
+ description: 'Alias for maxResults (default: 20)',
1551
+ default: 20,
1552
+ },
1553
+ offset: {
1554
+ type: 'number',
1555
+ description: 'Pagination offset - skip first N results (default: 0)',
1556
+ default: 0,
1557
+ },
1558
+ includeHidden: {
1559
+ type: 'boolean',
1560
+ description: 'Include hidden files/directories',
1561
+ default: false,
1562
+ },
1563
+ languages: {
1564
+ type: 'array',
1565
+ items: { type: 'string' },
1566
+ description: 'Languages to index (for init action). Example: ["javascript", "typescript"]',
1567
+ },
1568
+ enrich: {
1569
+ type: 'boolean',
1570
+ description: 'Enrich search results with code graph relationships (calls, imports, called_by, imported_by).',
1571
+ default: false,
1572
+ },
1573
+ regex: {
1574
+ type: 'boolean',
1575
+ description: 'Use regex pattern matching instead of literal string (ripgrep mode only). Default: enabled. Example: smart_search(query="class.*Builder")',
1576
+ default: true,
1577
+ },
1578
+ caseSensitive: {
1579
+ type: 'boolean',
1580
+ description: 'Case-sensitive search (default: true). Set to false for case-insensitive matching.',
1581
+ default: true,
1582
+ },
1583
+ tokenize: {
1584
+ type: 'boolean',
1585
+ description: 'Tokenize multi-word queries for OR matching (ripgrep mode). Default: true. Results are ranked by token match count (exact matches first).',
1586
+ default: true,
1587
+ },
1588
+ },
1589
+ required: [],
1590
+ },
1591
+ };
1592
+
1593
+ /**
1594
+ * Action: find_files - Find files by path/name pattern (glob matching)
1595
+ * Unlike search which looks inside file content, find_files matches file paths
1596
+ */
1597
+ async function executeFindFilesAction(params: Params): Promise<SearchResult> {
1598
+ const { pattern, path = '.', limit = 20, offset = 0, includeHidden = false, caseSensitive = true } = params;
1599
+
1600
+ if (!pattern) {
1601
+ return {
1602
+ success: false,
1603
+ error: 'Pattern is required for find_files action. Use glob patterns like "*.ts", "src/**/*.js", or "test_*.py"',
1604
+ };
1605
+ }
1606
+
1607
+ // Use ripgrep with --files flag for fast file listing with glob pattern
1608
+ const hasRipgrep = checkToolAvailability('rg');
1609
+
1610
+ if (!hasRipgrep) {
1611
+ // Fallback to CodexLens file listing if available
1612
+ const readyStatus = await ensureCodexLensReady();
1613
+ if (!readyStatus.ready) {
1614
+ return {
1615
+ success: false,
1616
+ error: 'Neither ripgrep nor CodexLens available for file discovery.',
1617
+ };
1618
+ }
1619
+
1620
+ // Try CodexLens file list command
1621
+ const args = ['list-files', '--json'];
1622
+ const result = await executeCodexLens(args, { cwd: path });
1623
+
1624
+ if (!result.success) {
1625
+ return {
1626
+ success: false,
1627
+ error: `Failed to list files: ${result.error}`,
1628
+ };
1629
+ }
1630
+
1631
+ // Parse and filter results by pattern
1632
+ let files: string[] = [];
1633
+ try {
1634
+ const parsed = JSON.parse(stripAnsi(result.output || '[]'));
1635
+ files = Array.isArray(parsed) ? parsed : (parsed.files || []);
1636
+ } catch {
1637
+ return {
1638
+ success: false,
1639
+ error: 'Failed to parse file list from CodexLens',
1640
+ };
1641
+ }
1642
+
1643
+ // Apply glob pattern matching using minimatch-style regex
1644
+ const globRegex = globToRegex(pattern, caseSensitive);
1645
+ const matchedFiles = files.filter(f => globRegex.test(f));
1646
+
1647
+ // Apply pagination
1648
+ const total = matchedFiles.length;
1649
+ const paginatedFiles = matchedFiles.slice(offset, offset + limit);
1650
+
1651
+ const results: FileMatch[] = paginatedFiles.map(filePath => {
1652
+ const parts = filePath.split(/[/\\]/);
1653
+ const name = parts[parts.length - 1] || '';
1654
+ const ext = name.includes('.') ? name.split('.').pop() : undefined;
1655
+ return {
1656
+ path: filePath,
1657
+ type: 'file' as const,
1658
+ name,
1659
+ extension: ext,
1660
+ };
1661
+ });
1662
+
1663
+ return {
1664
+ success: true,
1665
+ results,
1666
+ metadata: {
1667
+ pattern,
1668
+ backend: 'codexlens',
1669
+ count: results.length,
1670
+ pagination: {
1671
+ offset,
1672
+ limit,
1673
+ total,
1674
+ has_more: offset + limit < total,
1675
+ },
1676
+ },
1677
+ };
1678
+ }
1679
+
1680
+ // Use ripgrep --files with glob pattern for fast file discovery
1681
+ return new Promise((resolve) => {
1682
+ const args = ['--files'];
1683
+
1684
+ // Add exclude patterns
1685
+ if (!includeHidden) {
1686
+ args.push(...buildExcludeArgs());
1687
+ } else {
1688
+ args.push('--hidden');
1689
+ }
1690
+
1691
+ // Add glob pattern
1692
+ args.push('--glob', pattern);
1693
+
1694
+ // Case sensitivity for glob matching
1695
+ if (!caseSensitive) {
1696
+ args.push('--iglob', pattern);
1697
+ // Remove the case-sensitive glob and use iglob instead
1698
+ const globIndex = args.indexOf('--glob');
1699
+ if (globIndex !== -1) {
1700
+ args.splice(globIndex, 2);
1701
+ }
1702
+ }
1703
+
1704
+ const child = spawn('rg', args, {
1705
+ cwd: path || getProjectRoot(),
1706
+ stdio: ['ignore', 'pipe', 'pipe'],
1707
+ });
1708
+
1709
+ let stdout = '';
1710
+ let stderr = '';
1711
+
1712
+ child.stdout.on('data', (data) => {
1713
+ stdout += data.toString();
1714
+ });
1715
+
1716
+ child.stderr.on('data', (data) => {
1717
+ stderr += data.toString();
1718
+ });
1719
+
1720
+ child.on('close', (code) => {
1721
+ // ripgrep returns 1 when no matches found, which is not an error
1722
+ if (code !== 0 && code !== 1 && !stderr.includes('os error 1')) {
1723
+ resolve({
1724
+ success: false,
1725
+ error: `ripgrep file search failed: ${stderr}`,
1726
+ });
1727
+ return;
1728
+ }
1729
+
1730
+ const allFiles = stdout.split('\n').filter(line => line.trim());
1731
+ const total = allFiles.length;
1732
+
1733
+ // Apply pagination
1734
+ const paginatedFiles = allFiles.slice(offset, offset + limit);
1735
+
1736
+ const results: FileMatch[] = paginatedFiles.map(filePath => {
1737
+ const normalizedPath = filePath.replace(/\\/g, '/');
1738
+ const parts = normalizedPath.split('/');
1739
+ const name = parts[parts.length - 1] || '';
1740
+ const ext = name.includes('.') ? name.split('.').pop() : undefined;
1741
+ return {
1742
+ path: normalizedPath,
1743
+ type: 'file' as const,
1744
+ name,
1745
+ extension: ext,
1746
+ };
1747
+ });
1748
+
1749
+ resolve({
1750
+ success: true,
1751
+ results,
1752
+ metadata: {
1753
+ pattern,
1754
+ backend: 'ripgrep',
1755
+ count: results.length,
1756
+ pagination: {
1757
+ offset,
1758
+ limit,
1759
+ total,
1760
+ has_more: offset + limit < total,
1761
+ },
1762
+ },
1763
+ });
1764
+ });
1765
+
1766
+ child.on('error', (error) => {
1767
+ resolve({
1768
+ success: false,
1769
+ error: `Failed to spawn ripgrep: ${error.message}`,
1770
+ });
1771
+ });
1772
+ });
1773
+ }
1774
+
1775
+ /**
1776
+ * Convert glob pattern to regex for file matching
1777
+ * Supports: *, **, ?, [abc], [!abc]
1778
+ */
1779
+ function globToRegex(pattern: string, caseSensitive: boolean = true): RegExp {
1780
+ let i = 0;
1781
+ const out: string[] = [];
1782
+ const special = '.^$+{}|()';
1783
+
1784
+ while (i < pattern.length) {
1785
+ const c = pattern[i];
1786
+
1787
+ if (c === '*') {
1788
+ if (i + 1 < pattern.length && pattern[i + 1] === '*') {
1789
+ // ** matches any path including /
1790
+ out.push('.*');
1791
+ i += 2;
1792
+ // Skip following / if present
1793
+ if (pattern[i] === '/') {
1794
+ i++;
1795
+ }
1796
+ continue;
1797
+ } else {
1798
+ // * matches any character except /
1799
+ out.push('[^/]*');
1800
+ }
1801
+ } else if (c === '?') {
1802
+ out.push('[^/]');
1803
+ } else if (c === '[') {
1804
+ // Character class
1805
+ let j = i + 1;
1806
+ let negated = false;
1807
+ if (pattern[j] === '!' || pattern[j] === '^') {
1808
+ negated = true;
1809
+ j++;
1810
+ }
1811
+ let classContent = '';
1812
+ while (j < pattern.length && pattern[j] !== ']') {
1813
+ classContent += pattern[j];
1814
+ j++;
1815
+ }
1816
+ if (negated) {
1817
+ out.push(`[^${classContent}]`);
1818
+ } else {
1819
+ out.push(`[${classContent}]`);
1820
+ }
1821
+ i = j;
1822
+ } else if (special.includes(c)) {
1823
+ out.push('\\' + c);
1824
+ } else {
1825
+ out.push(c);
1826
+ }
1827
+ i++;
1828
+ }
1829
+
1830
+ const flags = caseSensitive ? '' : 'i';
1831
+ return new RegExp('^' + out.join('') + '$', flags);
1832
+ }
1833
+
1834
+ /**
1835
+ * Apply pagination to search results and add pagination metadata
1836
+ */
1837
+ function applyPagination<T>(
1838
+ results: T[],
1839
+ offset: number,
1840
+ limit: number
1841
+ ): { paginatedResults: T[]; pagination: PaginationInfo } {
1842
+ const total = results.length;
1843
+ const paginatedResults = results.slice(offset, offset + limit);
1844
+
1845
+ return {
1846
+ paginatedResults,
1847
+ pagination: {
1848
+ offset,
1849
+ limit,
1850
+ total,
1851
+ has_more: offset + limit < total,
1852
+ },
1853
+ };
1854
+ }
1855
+
1856
+ /**
1857
+ * Transform results based on output_mode
1858
+ */
1859
+ function transformOutput(
1860
+ results: ExactMatch[] | SemanticMatch[] | GraphMatch[] | unknown[],
1861
+ outputMode: 'full' | 'files_only' | 'count'
1862
+ ): unknown {
1863
+ if (!Array.isArray(results)) {
1864
+ return results;
1865
+ }
1866
+
1867
+ switch (outputMode) {
1868
+ case 'files_only': {
1869
+ // Extract unique file paths
1870
+ const files = [...new Set(results.map((r: any) => r.file))].filter(Boolean);
1871
+ return { files, count: files.length };
1872
+ }
1873
+ case 'count': {
1874
+ // Count matches per file
1875
+ const counts: Record<string, number> = {};
1876
+ for (const r of results) {
1877
+ const file = (r as any).file;
1878
+ if (file) {
1879
+ counts[file] = (counts[file] || 0) + 1;
1880
+ }
1881
+ }
1882
+ return {
1883
+ files: Object.entries(counts).map(([file, count]) => ({ file, count })),
1884
+ total: results.length,
1885
+ };
1886
+ }
1887
+ case 'full':
1888
+ default:
1889
+ return results;
1890
+ }
1891
+ }
1892
+
1893
+ // Handler function
1894
+ export async function handler(params: Record<string, unknown>): Promise<ToolResult<SearchResult>> {
1895
+ const parsed = ParamsSchema.safeParse(params);
1896
+ if (!parsed.success) {
1897
+ return { success: false, error: `Invalid params: ${parsed.error.message}` };
1898
+ }
1899
+
1900
+ const { action, mode, output_mode, offset = 0 } = parsed.data;
1901
+
1902
+ // Sync limit and maxResults - use the larger of the two if both provided
1903
+ // This ensures user-provided values take precedence over defaults
1904
+ const effectiveLimit = Math.max(parsed.data.limit || 20, parsed.data.maxResults || 20);
1905
+ parsed.data.maxResults = effectiveLimit;
1906
+ parsed.data.limit = effectiveLimit;
1907
+
1908
+ // Track if search_files was used (deprecated)
1909
+ let deprecationWarning: string | undefined;
1910
+
1911
+ try {
1912
+ let result: SearchResult;
1913
+
1914
+ // Handle actions
1915
+ switch (action) {
1916
+ case 'init':
1917
+ result = await executeInitAction(parsed.data);
1918
+ break;
1919
+
1920
+ case 'status':
1921
+ result = await executeStatusAction(parsed.data);
1922
+ break;
1923
+
1924
+ case 'find_files':
1925
+ // NEW: File path/name pattern matching (glob-based)
1926
+ result = await executeFindFilesAction(parsed.data);
1927
+ break;
1928
+
1929
+ case 'search_files':
1930
+ // DEPRECATED: Redirect to search with files_only output
1931
+ deprecationWarning = 'action="search_files" is deprecated. Use action="search" with output_mode="files_only" for content-to-files search, or action="find_files" for path pattern matching.';
1932
+ parsed.data.output_mode = 'files_only';
1933
+ // Fall through to search
1934
+
1935
+ case 'search':
1936
+ default:
1937
+ // Handle search modes: auto | hybrid | exact | ripgrep | priority
1938
+ switch (mode) {
1939
+ case 'auto':
1940
+ result = await executeAutoMode(parsed.data);
1941
+ break;
1942
+ case 'hybrid':
1943
+ result = await executeHybridMode(parsed.data);
1944
+ break;
1945
+ case 'exact':
1946
+ result = await executeCodexLensExactMode(parsed.data);
1947
+ break;
1948
+ case 'ripgrep':
1949
+ result = await executeRipgrepMode(parsed.data);
1950
+ break;
1951
+ case 'priority':
1952
+ result = await executePriorityFallbackMode(parsed.data);
1953
+ break;
1954
+ default:
1955
+ throw new Error(`Unsupported mode: ${mode}. Use: auto, hybrid, exact, ripgrep, or priority`);
1956
+ }
1957
+ break;
1958
+ }
1959
+
1960
+ // Transform output based on output_mode (for search actions only)
1961
+ if (action === 'search' || action === 'search_files') {
1962
+ if (result.success && result.results && output_mode !== 'full') {
1963
+ result.results = transformOutput(result.results as any[], output_mode);
1964
+ }
1965
+
1966
+ // Add pagination metadata for search results if not already present
1967
+ if (result.success && result.results && Array.isArray(result.results)) {
1968
+ const totalResults = (result.results as any[]).length;
1969
+ if (!result.metadata) {
1970
+ result.metadata = {};
1971
+ }
1972
+ if (!result.metadata.pagination) {
1973
+ result.metadata.pagination = {
1974
+ offset: 0,
1975
+ limit: effectiveLimit,
1976
+ total: totalResults,
1977
+ has_more: false, // Already limited by backend
1978
+ };
1979
+ }
1980
+ }
1981
+ }
1982
+
1983
+ // Add deprecation warning if applicable
1984
+ if (deprecationWarning && result.metadata) {
1985
+ result.metadata.warning = deprecationWarning;
1986
+ }
1987
+
1988
+ return result.success ? { success: true, result } : { success: false, error: result.error };
1989
+ } catch (error) {
1990
+ return { success: false, error: (error as Error).message };
1991
+ }
1992
+ }
1993
+
1994
+ /**
1995
+ * Execute init action with external progress callback
1996
+ * Used by MCP server for streaming progress
1997
+ */
1998
+ export async function executeInitWithProgress(
1999
+ params: Record<string, unknown>,
2000
+ onProgress?: (progress: ProgressInfo) => void
2001
+ ): Promise<SearchResult> {
2002
+ const path = (params.path as string) || '.';
2003
+ const languages = params.languages as string[] | undefined;
2004
+
2005
+ // Check CodexLens availability
2006
+ const readyStatus = await ensureCodexLensReady();
2007
+ if (!readyStatus.ready) {
2008
+ return {
2009
+ success: false,
2010
+ error: `CodexLens not available: ${readyStatus.error}. CodexLens will be auto-installed on first use.`,
2011
+ };
2012
+ }
2013
+
2014
+ const args = ['init', path];
2015
+ if (languages && languages.length > 0) {
2016
+ args.push('--languages', languages.join(','));
2017
+ }
2018
+
2019
+ // Track progress updates
2020
+ const progressUpdates: ProgressInfo[] = [];
2021
+ let lastProgress: ProgressInfo | null = null;
2022
+
2023
+ const result = await executeCodexLens(args, {
2024
+ cwd: path,
2025
+ timeout: 1800000, // 30 minutes for large codebases
2026
+ onProgress: (progress: ProgressInfo) => {
2027
+ progressUpdates.push(progress);
2028
+ lastProgress = progress;
2029
+ // Call external progress callback if provided
2030
+ if (onProgress) {
2031
+ onProgress(progress);
2032
+ }
2033
+ },
2034
+ });
2035
+
2036
+ // Build metadata with progress info
2037
+ const metadata: SearchMetadata = {
2038
+ action: 'init',
2039
+ path,
2040
+ };
2041
+
2042
+ if (lastProgress !== null) {
2043
+ const p = lastProgress as ProgressInfo;
2044
+ metadata.progress = {
2045
+ stage: p.stage,
2046
+ message: p.message,
2047
+ percent: p.percent,
2048
+ filesProcessed: p.filesProcessed,
2049
+ totalFiles: p.totalFiles,
2050
+ };
2051
+ }
2052
+
2053
+ if (progressUpdates.length > 0) {
2054
+ metadata.progressHistory = progressUpdates.slice(-5);
2055
+ }
2056
+
2057
+ return {
2058
+ success: result.success,
2059
+ error: result.error,
2060
+ message: result.success
2061
+ ? `CodexLens index created successfully for ${path}`
2062
+ : undefined,
2063
+ metadata,
2064
+ };
2065
+ }