claude-code-workflow 6.1.4 → 6.2.2

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 (437) hide show
  1. package/.claude/CLAUDE.md +10 -0
  2. package/.claude/agents/action-planning-agent.md +857 -778
  3. package/.claude/agents/cli-execution-agent.md +266 -269
  4. package/.claude/agents/cli-explore-agent.md +2 -2
  5. package/.claude/agents/cli-lite-planning-agent.md +142 -92
  6. package/.claude/agents/cli-planning-agent.md +4 -4
  7. package/.claude/agents/code-developer.md +7 -6
  8. package/.claude/agents/conceptual-planning-agent.md +2 -2
  9. package/.claude/agents/context-search-agent.md +31 -32
  10. package/.claude/agents/doc-generator.md +4 -4
  11. package/.claude/agents/memory-bridge.md +93 -93
  12. package/.claude/agents/test-context-search-agent.md +8 -7
  13. package/.claude/agents/test-fix-agent.md +7 -6
  14. package/.claude/commands/clean.md +516 -0
  15. package/.claude/commands/memory/compact.md +383 -0
  16. package/.claude/commands/memory/docs-full-cli.md +471 -471
  17. package/.claude/commands/memory/docs-related-cli.md +386 -386
  18. package/.claude/commands/memory/docs.md +615 -615
  19. package/.claude/commands/memory/load.md +5 -5
  20. package/.claude/commands/memory/tech-research-rules.md +310 -0
  21. package/.claude/commands/memory/update-full.md +332 -332
  22. package/.claude/commands/memory/workflow-skill-memory.md +4 -4
  23. package/.claude/commands/task/create.md +151 -151
  24. package/.claude/commands/version.md +254 -254
  25. package/.claude/commands/workflow/brainstorm/api-designer.md +587 -585
  26. package/.claude/commands/workflow/brainstorm/artifacts.md +1 -0
  27. package/.claude/commands/workflow/brainstorm/auto-parallel.md +443 -443
  28. package/.claude/commands/workflow/brainstorm/data-architect.md +220 -220
  29. package/.claude/commands/workflow/brainstorm/product-manager.md +200 -200
  30. package/.claude/commands/workflow/brainstorm/product-owner.md +200 -200
  31. package/.claude/commands/workflow/brainstorm/scrum-master.md +200 -200
  32. package/.claude/commands/workflow/brainstorm/subject-matter-expert.md +200 -200
  33. package/.claude/commands/workflow/brainstorm/system-architect.md +389 -387
  34. package/.claude/commands/workflow/brainstorm/ui-designer.md +221 -221
  35. package/.claude/commands/workflow/brainstorm/ux-expert.md +221 -221
  36. package/.claude/commands/workflow/debug.md +321 -0
  37. package/.claude/commands/workflow/execute.md +13 -0
  38. package/.claude/commands/workflow/init.md +165 -164
  39. package/.claude/commands/workflow/lite-execute.md +119 -13
  40. package/.claude/commands/workflow/lite-fix.md +623 -621
  41. package/.claude/commands/workflow/lite-plan.md +610 -592
  42. package/.claude/commands/workflow/plan.md +5 -5
  43. package/.claude/commands/workflow/review-module-cycle.md +2 -0
  44. package/.claude/commands/workflow/review-session-cycle.md +2 -0
  45. package/.claude/commands/workflow/review.md +297 -291
  46. package/.claude/commands/workflow/session/complete.md +153 -500
  47. package/.claude/commands/workflow/session/list.md +95 -95
  48. package/.claude/commands/workflow/session/resume.md +60 -60
  49. package/.claude/commands/workflow/session/start.md +199 -199
  50. package/.claude/commands/workflow/tdd-plan.md +3 -3
  51. package/.claude/commands/workflow/tdd-verify.md +23 -9
  52. package/.claude/commands/workflow/test-cycle-execute.md +2 -0
  53. package/.claude/commands/workflow/test-fix-gen.md +699 -699
  54. package/.claude/commands/workflow/tools/conflict-resolution.md +104 -18
  55. package/.claude/commands/workflow/tools/context-gather.md +436 -434
  56. package/.claude/commands/workflow/tools/task-generate-agent.md +490 -291
  57. package/.claude/commands/workflow/tools/task-generate-tdd.md +18 -10
  58. package/.claude/commands/workflow/tools/test-concept-enhanced.md +2 -1
  59. package/.claude/commands/workflow/tools/test-context-gather.md +1 -0
  60. package/.claude/commands/workflow/tools/test-task-generate.md +1 -0
  61. package/.claude/commands/workflow/ui-design/import-from-code.md +9 -6
  62. package/.claude/skills/command-guide/SKILL.md +5 -5
  63. package/.claude/skills/command-guide/index/all-commands.json +1 -1
  64. package/.claude/skills/command-guide/index/by-category.json +1 -1
  65. package/.claude/skills/command-guide/index/by-use-case.json +1 -1
  66. package/.claude/skills/command-guide/reference/agents/action-planning-agent.md +857 -778
  67. package/.claude/skills/command-guide/reference/agents/cli-execution-agent.md +266 -269
  68. package/.claude/skills/command-guide/reference/agents/cli-explore-agent.md +2 -2
  69. package/.claude/skills/command-guide/reference/agents/cli-lite-planning-agent.md +142 -92
  70. package/.claude/skills/command-guide/reference/agents/cli-planning-agent.md +4 -4
  71. package/.claude/skills/command-guide/reference/agents/code-developer.md +7 -6
  72. package/.claude/skills/command-guide/reference/agents/conceptual-planning-agent.md +2 -2
  73. package/.claude/skills/command-guide/reference/agents/context-search-agent.md +31 -32
  74. package/.claude/skills/command-guide/reference/agents/doc-generator.md +4 -4
  75. package/.claude/skills/command-guide/reference/agents/memory-bridge.md +93 -93
  76. package/.claude/skills/command-guide/reference/agents/test-context-search-agent.md +8 -7
  77. package/.claude/skills/command-guide/reference/agents/test-fix-agent.md +7 -6
  78. package/.claude/skills/command-guide/reference/commands/memory/docs-full-cli.md +471 -471
  79. package/.claude/skills/command-guide/reference/commands/memory/docs-related-cli.md +386 -386
  80. package/.claude/skills/command-guide/reference/commands/memory/docs.md +17 -16
  81. package/.claude/skills/command-guide/reference/commands/memory/load.md +5 -5
  82. package/.claude/skills/command-guide/reference/commands/memory/tech-research.md +194 -357
  83. package/.claude/skills/command-guide/reference/commands/memory/update-full.md +332 -332
  84. package/.claude/skills/command-guide/reference/commands/memory/workflow-skill-memory.md +4 -4
  85. package/.claude/skills/command-guide/reference/commands/task/create.md +151 -151
  86. package/.claude/skills/command-guide/reference/commands/version.md +254 -254
  87. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/api-designer.md +585 -585
  88. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/auto-parallel.md +443 -443
  89. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/data-architect.md +220 -220
  90. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/product-manager.md +200 -200
  91. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/product-owner.md +200 -200
  92. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/scrum-master.md +200 -200
  93. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/subject-matter-expert.md +200 -200
  94. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/system-architect.md +387 -387
  95. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/ui-designer.md +221 -221
  96. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/ux-expert.md +221 -221
  97. package/.claude/skills/command-guide/reference/commands/workflow/execute.md +25 -20
  98. package/.claude/skills/command-guide/reference/commands/workflow/init.md +164 -164
  99. package/.claude/skills/command-guide/reference/commands/workflow/lite-execute.md +748 -686
  100. package/.claude/skills/command-guide/reference/commands/workflow/lite-fix.md +664 -621
  101. package/.claude/skills/command-guide/reference/commands/workflow/lite-plan.md +645 -592
  102. package/.claude/skills/command-guide/reference/commands/workflow/plan.md +5 -5
  103. package/.claude/skills/command-guide/reference/commands/workflow/review.md +25 -18
  104. package/.claude/skills/command-guide/reference/commands/workflow/session/complete.md +547 -500
  105. package/.claude/skills/command-guide/reference/commands/workflow/session/list.md +45 -27
  106. package/.claude/skills/command-guide/reference/commands/workflow/session/resume.md +35 -19
  107. package/.claude/skills/command-guide/reference/commands/workflow/session/start.md +90 -33
  108. package/.claude/skills/command-guide/reference/commands/workflow/tdd-plan.md +3 -3
  109. package/.claude/skills/command-guide/reference/commands/workflow/tdd-verify.md +23 -9
  110. package/.claude/skills/command-guide/reference/commands/workflow/test-fix-gen.md +699 -699
  111. package/.claude/skills/command-guide/reference/commands/workflow/tools/conflict-resolution.md +103 -17
  112. package/.claude/skills/command-guide/reference/commands/workflow/tools/context-gather.md +434 -434
  113. package/.claude/skills/command-guide/reference/commands/workflow/tools/task-generate-agent.md +487 -291
  114. package/.claude/skills/command-guide/reference/commands/workflow/tools/task-generate-tdd.md +17 -10
  115. package/.claude/skills/command-guide/reference/commands/workflow/tools/test-concept-enhanced.md +1 -1
  116. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/import-from-code.md +6 -6
  117. package/.claude/workflows/chinese-response.md +38 -0
  118. package/.claude/workflows/cli-templates/prompts/rules/rule-api.txt +122 -0
  119. package/.claude/workflows/cli-templates/prompts/rules/rule-components.txt +122 -0
  120. package/.claude/workflows/cli-templates/prompts/rules/rule-config.txt +89 -0
  121. package/.claude/workflows/cli-templates/prompts/rules/rule-core.txt +60 -0
  122. package/.claude/workflows/cli-templates/prompts/rules/rule-patterns.txt +70 -0
  123. package/.claude/workflows/cli-templates/prompts/rules/rule-testing.txt +81 -0
  124. package/.claude/workflows/cli-templates/prompts/rules/tech-rules-agent-prompt.txt +89 -0
  125. package/.claude/workflows/cli-templates/prompts/workflow/gemini-solution-design.txt +131 -131
  126. package/.claude/workflows/cli-templates/prompts/workflow/skill-conflict-patterns.txt +5 -9
  127. package/.claude/workflows/cli-templates/prompts/workflow/skill-lessons-learned.txt +5 -9
  128. package/.claude/workflows/cli-templates/protocols/analysis-protocol.md +112 -0
  129. package/.claude/workflows/cli-templates/protocols/write-protocol.md +201 -0
  130. package/.claude/workflows/cli-templates/schemas/conflict-resolution-schema.json +137 -0
  131. package/.claude/workflows/cli-templates/schemas/debug-log-json-schema.json +127 -0
  132. package/.claude/workflows/cli-templates/schemas/fix-plan-json-schema.json +25 -0
  133. package/.claude/workflows/cli-templates/schemas/plan-json-schema.json +25 -0
  134. package/.claude/workflows/cli-tools-usage.md +526 -0
  135. package/{CLAUDE.md → .claude/workflows/coding-philosophy.md} +24 -45
  136. package/.claude/workflows/context-tools.md +84 -0
  137. package/.claude/workflows/file-modification.md +64 -0
  138. package/.claude/workflows/tool-strategy.md +216 -79
  139. package/.claude/workflows/windows-platform.md +16 -0
  140. package/.claude/workflows/workflow-architecture.md +942 -942
  141. package/.codex/AGENTS.md +63 -330
  142. package/.codex/prompts/debug.md +318 -0
  143. package/.codex/prompts/execute.md +273 -0
  144. package/.codex/prompts/lite-execute.md +164 -0
  145. package/.codex/prompts/lite-plan.md +469 -0
  146. package/.codex/prompts.zip +0 -0
  147. package/.gemini/GEMINI.md +25 -164
  148. package/.qwen/QWEN.md +0 -139
  149. package/README.md +29 -9
  150. package/ccw/README.md +30 -6
  151. package/ccw/bin/ccw-mcp.js +7 -0
  152. package/ccw/bin/ccw.js +9 -9
  153. package/ccw/package.json +65 -47
  154. package/ccw/src/.workflow/.cli-history/history.db +0 -0
  155. package/ccw/src/.workflow/.cli-history/history.db-shm +0 -0
  156. package/ccw/src/.workflow/.cli-history/history.db-wal +0 -0
  157. package/ccw/src/cli.ts +244 -0
  158. package/ccw/src/commands/cli.ts +740 -0
  159. package/ccw/src/commands/core-memory.ts +770 -0
  160. package/ccw/src/commands/hook.ts +315 -0
  161. package/ccw/src/commands/install.ts +519 -0
  162. package/ccw/src/commands/{list.js → list.ts} +1 -1
  163. package/ccw/src/commands/memory.ts +1090 -0
  164. package/ccw/src/commands/{serve.js → serve.ts} +14 -5
  165. package/ccw/src/commands/session-path-resolver.ts +372 -0
  166. package/ccw/src/commands/session.ts +1141 -0
  167. package/ccw/src/commands/{stop.js → stop.ts} +16 -6
  168. package/ccw/src/commands/tool.ts +201 -0
  169. package/ccw/src/commands/{uninstall.js → uninstall.ts} +89 -40
  170. package/ccw/src/commands/{upgrade.js → upgrade.ts} +68 -23
  171. package/ccw/src/commands/{view.js → view.ts} +22 -8
  172. package/ccw/src/config/storage-paths.ts +670 -0
  173. package/ccw/src/core/cache-manager.ts +294 -0
  174. package/ccw/src/core/claude-freshness.ts +319 -0
  175. package/ccw/src/core/core-memory-store.ts +1528 -0
  176. package/ccw/src/core/{dashboard-generator-patch.js → dashboard-generator-patch.ts} +18 -0
  177. package/ccw/src/core/{dashboard-generator.js → dashboard-generator.ts} +69 -12
  178. package/ccw/src/core/data-aggregator.ts +584 -0
  179. package/ccw/src/core/history-importer.ts +625 -0
  180. package/ccw/src/core/{lite-scanner.js → lite-scanner-complete.ts} +162 -66
  181. package/ccw/src/core/lite-scanner.ts +469 -0
  182. package/ccw/src/core/{manifest.js → manifest.ts} +104 -34
  183. package/ccw/src/core/memory-embedder-bridge.ts +262 -0
  184. package/ccw/src/core/memory-store.ts +978 -0
  185. package/ccw/src/core/routes/ccw-routes.ts +96 -0
  186. package/ccw/src/core/routes/claude-routes.ts +1183 -0
  187. package/ccw/src/core/routes/cli-routes.ts +561 -0
  188. package/ccw/src/core/routes/codexlens-routes.ts +806 -0
  189. package/ccw/src/core/routes/core-memory-routes.ts +605 -0
  190. package/ccw/src/core/routes/files-routes.ts +428 -0
  191. package/ccw/src/core/routes/graph-routes.md +164 -0
  192. package/ccw/src/core/routes/graph-routes.ts +626 -0
  193. package/ccw/src/core/routes/help-routes.ts +308 -0
  194. package/ccw/src/core/routes/hooks-routes.ts +405 -0
  195. package/ccw/src/core/routes/mcp-routes.ts +1271 -0
  196. package/ccw/src/core/routes/mcp-routes.ts.backup +550 -0
  197. package/ccw/src/core/routes/mcp-templates-db.ts +268 -0
  198. package/ccw/src/core/routes/memory-routes.ts +1206 -0
  199. package/ccw/src/core/routes/rules-routes.ts +526 -0
  200. package/ccw/src/core/routes/session-routes.ts +467 -0
  201. package/ccw/src/core/routes/skills-routes.ts +599 -0
  202. package/ccw/src/core/routes/status-routes.ts +57 -0
  203. package/ccw/src/core/routes/system-routes.ts +427 -0
  204. package/ccw/src/core/server.ts +431 -0
  205. package/ccw/src/core/session-clustering-service.ts +1258 -0
  206. package/ccw/src/core/session-scanner.ts +283 -0
  207. package/ccw/src/core/websocket.ts +190 -0
  208. package/ccw/src/{index.js → index.ts} +1 -0
  209. package/ccw/src/mcp-server/index.ts +186 -0
  210. package/ccw/src/templates/assets/css/github-dark.min.css +10 -0
  211. package/ccw/src/templates/assets/css/github.min.css +10 -0
  212. package/ccw/src/templates/assets/js/cytoscape.min.js +32 -0
  213. package/ccw/src/templates/assets/js/d3.min.js +2 -0
  214. package/ccw/src/templates/assets/js/highlight.min.js +1244 -0
  215. package/ccw/src/templates/assets/js/lucide.min.js +12 -0
  216. package/ccw/src/templates/assets/js/marked.min.js +69 -0
  217. package/ccw/src/templates/assets/js/tailwind.js +83 -0
  218. package/ccw/src/templates/dashboard-css/01-base.css +11 -0
  219. package/ccw/src/templates/dashboard-css/02-session.css +22 -0
  220. package/ccw/src/templates/dashboard-css/04-lite-tasks.css +10 -0
  221. package/ccw/src/templates/dashboard-css/06-cards.css +10 -4
  222. package/ccw/src/templates/dashboard-css/07-managers.css +1178 -7
  223. package/ccw/src/templates/dashboard-css/09-explorer.css +23 -12
  224. package/ccw/src/templates/dashboard-css/10-cli-status.css +337 -0
  225. package/ccw/src/templates/dashboard-css/11-cli-history.css +271 -0
  226. package/ccw/src/templates/dashboard-css/12-cli-legacy.css +796 -0
  227. package/ccw/src/templates/dashboard-css/13-cli-ccw.css +199 -0
  228. package/ccw/src/templates/dashboard-css/14-cli-modals.css +258 -0
  229. package/ccw/src/templates/dashboard-css/15-cli-endpoints.css +305 -0
  230. package/ccw/src/templates/dashboard-css/16-cli-session.css +241 -0
  231. package/ccw/src/templates/dashboard-css/17-cli-conversation.css +283 -0
  232. package/ccw/src/templates/dashboard-css/18-cli-settings.css +160 -0
  233. package/ccw/src/templates/dashboard-css/19-cli-native-session.css +496 -0
  234. package/ccw/src/templates/dashboard-css/20-cli-taskqueue.css +188 -0
  235. package/ccw/src/templates/dashboard-css/21-cli-toolmgmt.css +310 -0
  236. package/ccw/src/templates/dashboard-css/22-cli-semantic.css +240 -0
  237. package/ccw/src/templates/dashboard-css/23-memory.css +2390 -0
  238. package/ccw/src/templates/dashboard-css/24-prompt-history.css +1089 -0
  239. package/ccw/src/templates/dashboard-css/25-skills-rules.css +326 -0
  240. package/ccw/src/templates/dashboard-css/26-claude-manager.css +908 -0
  241. package/ccw/src/templates/dashboard-css/27-graph-explorer.css +1678 -0
  242. package/ccw/src/templates/dashboard-css/28-mcp-manager.css +748 -0
  243. package/ccw/src/templates/dashboard-css/29-help.css +264 -0
  244. package/ccw/src/templates/dashboard-css/30-core-memory.css +1700 -0
  245. package/ccw/src/templates/dashboard-js/api.js +162 -142
  246. package/ccw/src/templates/dashboard-js/components/carousel.js +4 -4
  247. package/ccw/src/templates/dashboard-js/components/cli-history.js +876 -0
  248. package/ccw/src/templates/dashboard-js/components/cli-status.js +978 -0
  249. package/ccw/src/templates/dashboard-js/components/global-notifications.js +508 -219
  250. package/ccw/src/templates/dashboard-js/components/hook-manager.js +1277 -282
  251. package/ccw/src/templates/dashboard-js/components/index-manager.js +302 -0
  252. package/ccw/src/templates/dashboard-js/components/mcp-manager.js +718 -27
  253. package/ccw/src/templates/dashboard-js/components/modals.js +66 -0
  254. package/ccw/src/templates/dashboard-js/components/navigation.js +80 -12
  255. package/ccw/src/templates/dashboard-js/components/notifications.js +758 -194
  256. package/ccw/src/templates/dashboard-js/components/storage-manager.js +478 -0
  257. package/ccw/src/templates/dashboard-js/components/tabs-other.js +157 -6
  258. package/ccw/src/templates/dashboard-js/components/task-queue-sidebar.js +716 -0
  259. package/ccw/src/templates/dashboard-js/help-i18n.js +272 -0
  260. package/ccw/src/templates/dashboard-js/i18n.js +2807 -0
  261. package/ccw/src/templates/dashboard-js/main.js +15 -0
  262. package/ccw/src/templates/dashboard-js/state.js +243 -42
  263. package/ccw/src/templates/dashboard-js/utils.js +47 -1
  264. package/ccw/src/templates/dashboard-js/views/claude-manager.js +912 -0
  265. package/ccw/src/templates/dashboard-js/views/cli-manager.js +2272 -0
  266. package/ccw/src/templates/dashboard-js/views/codexlens-manager.js +964 -0
  267. package/ccw/src/templates/dashboard-js/views/core-memory-clusters.js +503 -0
  268. package/ccw/src/templates/dashboard-js/views/core-memory.js +782 -0
  269. package/ccw/src/templates/dashboard-js/views/explorer.js +888 -852
  270. package/ccw/src/templates/dashboard-js/views/graph-explorer.js +1157 -0
  271. package/ccw/src/templates/dashboard-js/views/help.js +856 -0
  272. package/ccw/src/templates/dashboard-js/views/history.js +337 -0
  273. package/ccw/src/templates/dashboard-js/views/home.js +61 -15
  274. package/ccw/src/templates/dashboard-js/views/hook-manager.js +311 -43
  275. package/ccw/src/templates/dashboard-js/views/lite-tasks.js +204 -28
  276. package/ccw/src/templates/dashboard-js/views/mcp-manager.js +2187 -411
  277. package/ccw/src/templates/dashboard-js/views/mcp-manager.js.backup +1729 -0
  278. package/ccw/src/templates/dashboard-js/views/mcp-manager.js.new +928 -0
  279. package/ccw/src/templates/dashboard-js/views/memory.js +1221 -0
  280. package/ccw/src/templates/dashboard-js/views/prompt-history.js +713 -0
  281. package/ccw/src/templates/dashboard-js/views/rules-manager.js +828 -0
  282. package/ccw/src/templates/dashboard-js/views/session-detail.js +54 -53
  283. package/ccw/src/templates/dashboard-js/views/skills-manager.js +819 -0
  284. package/ccw/src/templates/dashboard.html +185 -85
  285. package/ccw/src/templates/hooks-config-example.json +60 -0
  286. package/ccw/src/tools/classify-folders.ts +245 -0
  287. package/ccw/src/tools/cli-config-manager.ts +268 -0
  288. package/ccw/src/tools/cli-executor.ts +2014 -0
  289. package/ccw/src/tools/cli-history-store.ts +1195 -0
  290. package/ccw/src/tools/codex-lens.ts +1141 -0
  291. package/ccw/src/tools/{convert-tokens-to-css.js → convert-tokens-to-css.ts} +73 -23
  292. package/ccw/src/tools/core-memory.ts +444 -0
  293. package/ccw/src/tools/detect-changed-modules.ts +325 -0
  294. package/ccw/src/tools/{discover-design-files.js → discover-design-files.ts} +74 -24
  295. package/ccw/src/tools/edit-file.ts +568 -0
  296. package/ccw/src/tools/{generate-module-docs.js → generate-module-docs.ts} +207 -185
  297. package/ccw/src/tools/{get-modules-by-depth.js → get-modules-by-depth.ts} +120 -79
  298. package/ccw/src/tools/index.ts +370 -0
  299. package/ccw/src/tools/native-session-discovery.ts +795 -0
  300. package/ccw/src/tools/notifier.ts +129 -0
  301. package/ccw/src/tools/read-file.ts +410 -0
  302. package/ccw/src/tools/resume-strategy.ts +345 -0
  303. package/ccw/src/tools/session-content-parser.ts +619 -0
  304. package/ccw/src/tools/session-manager.ts +1026 -0
  305. package/ccw/src/tools/smart-context.ts +228 -0
  306. package/ccw/src/tools/smart-search.ts +2065 -0
  307. package/ccw/src/tools/smart-search.ts.backup +1233 -0
  308. package/ccw/src/tools/storage-manager.ts +455 -0
  309. package/ccw/src/tools/write-file.ts +222 -0
  310. package/ccw/src/types/config.ts +11 -0
  311. package/ccw/src/types/index.ts +3 -0
  312. package/ccw/src/types/session.ts +25 -0
  313. package/ccw/src/types/tool.ts +41 -0
  314. package/ccw/src/utils/{browser-launcher.js → browser-launcher.ts} +10 -8
  315. package/ccw/src/utils/file-utils.ts +48 -0
  316. package/ccw/src/utils/{path-resolver.js → path-resolver.ts} +114 -78
  317. package/ccw/src/utils/path-validator.ts +153 -0
  318. package/ccw/src/utils/{ui.js → ui.ts} +32 -25
  319. package/codex-lens/pyproject.toml +48 -0
  320. package/codex-lens/src/codexlens/.workflow/.cli-history/history.db +0 -0
  321. package/codex-lens/src/codexlens/__init__.py +28 -0
  322. package/codex-lens/src/codexlens/__main__.py +14 -0
  323. package/codex-lens/src/codexlens/__pycache__/__init__.cpython-313.pyc +0 -0
  324. package/codex-lens/src/codexlens/__pycache__/__main__.cpython-313.pyc +0 -0
  325. package/codex-lens/src/codexlens/__pycache__/config.cpython-313.pyc +0 -0
  326. package/codex-lens/src/codexlens/__pycache__/entities.cpython-313.pyc +0 -0
  327. package/codex-lens/src/codexlens/__pycache__/errors.cpython-313.pyc +0 -0
  328. package/codex-lens/src/codexlens/cli/__init__.py +27 -0
  329. package/codex-lens/src/codexlens/cli/__pycache__/__init__.cpython-313.pyc +0 -0
  330. package/codex-lens/src/codexlens/cli/__pycache__/commands.cpython-313.pyc +0 -0
  331. package/codex-lens/src/codexlens/cli/__pycache__/embedding_manager.cpython-313.pyc +0 -0
  332. package/codex-lens/src/codexlens/cli/__pycache__/model_manager.cpython-313.pyc +0 -0
  333. package/codex-lens/src/codexlens/cli/__pycache__/output.cpython-313.pyc +0 -0
  334. package/codex-lens/src/codexlens/cli/commands.py +1931 -0
  335. package/codex-lens/src/codexlens/cli/embedding_manager.py +620 -0
  336. package/codex-lens/src/codexlens/cli/model_manager.py +289 -0
  337. package/codex-lens/src/codexlens/cli/output.py +124 -0
  338. package/codex-lens/src/codexlens/config.py +201 -0
  339. package/codex-lens/src/codexlens/entities.py +121 -0
  340. package/codex-lens/src/codexlens/errors.py +55 -0
  341. package/codex-lens/src/codexlens/indexing/README.md +77 -0
  342. package/codex-lens/src/codexlens/indexing/__init__.py +4 -0
  343. package/codex-lens/src/codexlens/indexing/__pycache__/__init__.cpython-313.pyc +0 -0
  344. package/codex-lens/src/codexlens/indexing/__pycache__/symbol_extractor.cpython-313.pyc +0 -0
  345. package/codex-lens/src/codexlens/indexing/symbol_extractor.py +243 -0
  346. package/codex-lens/src/codexlens/parsers/__init__.py +8 -0
  347. package/codex-lens/src/codexlens/parsers/__pycache__/__init__.cpython-313.pyc +0 -0
  348. package/codex-lens/src/codexlens/parsers/__pycache__/encoding.cpython-313.pyc +0 -0
  349. package/codex-lens/src/codexlens/parsers/__pycache__/factory.cpython-313.pyc +0 -0
  350. package/codex-lens/src/codexlens/parsers/__pycache__/tokenizer.cpython-313.pyc +0 -0
  351. package/codex-lens/src/codexlens/parsers/__pycache__/treesitter_parser.cpython-313.pyc +0 -0
  352. package/codex-lens/src/codexlens/parsers/encoding.py +202 -0
  353. package/codex-lens/src/codexlens/parsers/factory.py +256 -0
  354. package/codex-lens/src/codexlens/parsers/tokenizer.py +98 -0
  355. package/codex-lens/src/codexlens/parsers/treesitter_parser.py +335 -0
  356. package/codex-lens/src/codexlens/search/__init__.py +15 -0
  357. package/codex-lens/src/codexlens/search/__pycache__/__init__.cpython-313.pyc +0 -0
  358. package/codex-lens/src/codexlens/search/__pycache__/chain_search.cpython-313.pyc +0 -0
  359. package/codex-lens/src/codexlens/search/__pycache__/enrichment.cpython-313.pyc +0 -0
  360. package/codex-lens/src/codexlens/search/__pycache__/hybrid_search.cpython-313.pyc +0 -0
  361. package/codex-lens/src/codexlens/search/__pycache__/query_parser.cpython-313.pyc +0 -0
  362. package/codex-lens/src/codexlens/search/__pycache__/ranking.cpython-313.pyc +0 -0
  363. package/codex-lens/src/codexlens/search/chain_search.py +647 -0
  364. package/codex-lens/src/codexlens/search/enrichment.py +150 -0
  365. package/codex-lens/src/codexlens/search/hybrid_search.py +313 -0
  366. package/codex-lens/src/codexlens/search/query_parser.py +242 -0
  367. package/codex-lens/src/codexlens/search/ranking.py +274 -0
  368. package/codex-lens/src/codexlens/semantic/__init__.py +39 -0
  369. package/codex-lens/src/codexlens/semantic/__pycache__/__init__.cpython-313.pyc +0 -0
  370. package/codex-lens/src/codexlens/semantic/__pycache__/ann_index.cpython-313.pyc +0 -0
  371. package/codex-lens/src/codexlens/semantic/__pycache__/chunker.cpython-313.pyc +0 -0
  372. package/codex-lens/src/codexlens/semantic/__pycache__/code_extractor.cpython-313.pyc +0 -0
  373. package/codex-lens/src/codexlens/semantic/__pycache__/embedder.cpython-313.pyc +0 -0
  374. package/codex-lens/src/codexlens/semantic/__pycache__/graph_analyzer.cpython-313.pyc +0 -0
  375. package/codex-lens/src/codexlens/semantic/__pycache__/llm_enhancer.cpython-313.pyc +0 -0
  376. package/codex-lens/src/codexlens/semantic/__pycache__/vector_store.cpython-313.pyc +0 -0
  377. package/codex-lens/src/codexlens/semantic/ann_index.py +414 -0
  378. package/codex-lens/src/codexlens/semantic/chunker.py +448 -0
  379. package/codex-lens/src/codexlens/semantic/code_extractor.py +274 -0
  380. package/codex-lens/src/codexlens/semantic/embedder.py +185 -0
  381. package/codex-lens/src/codexlens/semantic/vector_store.py +955 -0
  382. package/codex-lens/src/codexlens/storage/__init__.py +29 -0
  383. package/codex-lens/src/codexlens/storage/__pycache__/__init__.cpython-313.pyc +0 -0
  384. package/codex-lens/src/codexlens/storage/__pycache__/dir_index.cpython-313.pyc +0 -0
  385. package/codex-lens/src/codexlens/storage/__pycache__/file_cache.cpython-313.pyc +0 -0
  386. package/codex-lens/src/codexlens/storage/__pycache__/index_tree.cpython-313.pyc +0 -0
  387. package/codex-lens/src/codexlens/storage/__pycache__/migration_manager.cpython-313.pyc +0 -0
  388. package/codex-lens/src/codexlens/storage/__pycache__/path_mapper.cpython-313.pyc +0 -0
  389. package/codex-lens/src/codexlens/storage/__pycache__/registry.cpython-313.pyc +0 -0
  390. package/codex-lens/src/codexlens/storage/__pycache__/sqlite_store.cpython-313.pyc +0 -0
  391. package/codex-lens/src/codexlens/storage/__pycache__/sqlite_utils.cpython-313.pyc +0 -0
  392. package/codex-lens/src/codexlens/storage/dir_index.py +1850 -0
  393. package/codex-lens/src/codexlens/storage/file_cache.py +32 -0
  394. package/codex-lens/src/codexlens/storage/index_tree.py +776 -0
  395. package/codex-lens/src/codexlens/storage/migration_manager.py +154 -0
  396. package/codex-lens/src/codexlens/storage/migrations/__init__.py +1 -0
  397. package/codex-lens/src/codexlens/storage/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
  398. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_001_normalize_keywords.cpython-313.pyc +0 -0
  399. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_002_add_token_metadata.cpython-313.pyc +0 -0
  400. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_003_code_relationships.cpython-313.pyc +0 -0
  401. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_004_dual_fts.cpython-313.pyc +0 -0
  402. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_005_cleanup_unused_fields.cpython-313.pyc +0 -0
  403. package/codex-lens/src/codexlens/storage/migrations/migration_001_normalize_keywords.py +123 -0
  404. package/codex-lens/src/codexlens/storage/migrations/migration_002_add_token_metadata.py +48 -0
  405. package/codex-lens/src/codexlens/storage/migrations/migration_004_dual_fts.py +232 -0
  406. package/codex-lens/src/codexlens/storage/migrations/migration_005_cleanup_unused_fields.py +196 -0
  407. package/codex-lens/src/codexlens/storage/path_mapper.py +274 -0
  408. package/codex-lens/src/codexlens/storage/registry.py +670 -0
  409. package/codex-lens/src/codexlens/storage/sqlite_store.py +576 -0
  410. package/codex-lens/src/codexlens/storage/sqlite_utils.py +64 -0
  411. package/package.json +4 -1
  412. package/.claude/commands/memory/tech-research.md +0 -477
  413. package/.claude/scripts/classify-folders.sh +0 -39
  414. package/.claude/scripts/convert_tokens_to_css.sh +0 -229
  415. package/.claude/scripts/detect_changed_modules.sh +0 -161
  416. package/.claude/scripts/discover-design-files.sh +0 -87
  417. package/.claude/scripts/extract-animations.js +0 -243
  418. package/.claude/scripts/extract-computed-styles.js +0 -118
  419. package/.claude/scripts/extract-layout-structure.js +0 -411
  420. package/.claude/scripts/generate_module_docs.sh +0 -717
  421. package/.claude/scripts/get_modules_by_depth.sh +0 -170
  422. package/.claude/scripts/ui-generate-preview.sh +0 -395
  423. package/.claude/scripts/ui-instantiate-prototypes.sh +0 -815
  424. package/.claude/scripts/update_module_claude.sh +0 -337
  425. package/.claude/workflows/context-search-strategy.md +0 -77
  426. package/.claude/workflows/intelligent-tools-strategy.md +0 -662
  427. package/ccw/src/cli.js +0 -119
  428. package/ccw/src/commands/install.js +0 -324
  429. package/ccw/src/commands/tool.js +0 -138
  430. package/ccw/src/core/data-aggregator.js +0 -409
  431. package/ccw/src/core/server.js +0 -2063
  432. package/ccw/src/core/session-scanner.js +0 -235
  433. package/ccw/src/tools/classify-folders.js +0 -204
  434. package/ccw/src/tools/detect-changed-modules.js +0 -288
  435. package/ccw/src/tools/edit-file.js +0 -266
  436. package/ccw/src/tools/index.js +0 -176
  437. package/ccw/src/utils/file-utils.js +0 -48
@@ -0,0 +1,1183 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * CLAUDE.md Routes Module
4
+ * Handles all CLAUDE.md memory rules management endpoints
5
+ */
6
+ import type { IncomingMessage, ServerResponse } from 'http';
7
+ import { readFileSync, writeFileSync, existsSync, readdirSync, statSync } from 'fs';
8
+ import { join, relative } from 'path';
9
+ import { homedir } from 'os';
10
+
11
+ export interface RouteContext {
12
+ pathname: string;
13
+ url: URL;
14
+ req: IncomingMessage;
15
+ res: ServerResponse;
16
+ initialPath: string;
17
+ handlePostRequest: (req: IncomingMessage, res: ServerResponse, handler: (body: unknown) => Promise<any>) => void;
18
+ broadcastToClients: (data: unknown) => void;
19
+ }
20
+
21
+ interface ClaudeFile {
22
+ id: string;
23
+ level: 'user' | 'project' | 'module';
24
+ path: string;
25
+ relativePath: string;
26
+ name: string;
27
+ content?: string;
28
+ size: number;
29
+ lastModified: string;
30
+ frontmatter?: { paths?: string[] };
31
+ stats?: { lines: number; words: number; characters: number };
32
+ isMainFile: boolean;
33
+ parentDirectory?: string;
34
+ depth?: number;
35
+ }
36
+
37
+ interface ClaudeFilesHierarchy {
38
+ user: { main: ClaudeFile | null };
39
+ project: { main: ClaudeFile | null };
40
+ modules: ClaudeFile[];
41
+ summary: { totalFiles: number; totalSize: number; lastSync?: string };
42
+ }
43
+
44
+ /**
45
+ * Parse frontmatter from markdown file
46
+ * Reuses logic from rules-routes.ts
47
+ */
48
+ function parseClaudeFrontmatter(content: string) {
49
+ const result = {
50
+ paths: [] as string[],
51
+ content: content
52
+ };
53
+
54
+ if (content.startsWith('---')) {
55
+ const endIndex = content.indexOf('---', 3);
56
+ if (endIndex > 0) {
57
+ const frontmatter = content.substring(3, endIndex).trim();
58
+ result.content = content.substring(endIndex + 3).trim();
59
+
60
+ const lines = frontmatter.split('\n');
61
+ for (const line of lines) {
62
+ const colonIndex = line.indexOf(':');
63
+ if (colonIndex > 0) {
64
+ const key = line.substring(0, colonIndex).trim().toLowerCase();
65
+ const value = line.substring(colonIndex + 1).trim();
66
+
67
+ if (key === 'paths') {
68
+ result.paths = value.replace(/^\[|\]$/g, '').split(',').map(t => t.trim()).filter(Boolean);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ return result;
76
+ }
77
+
78
+ /**
79
+ * Calculate file statistics
80
+ */
81
+ function calculateFileStats(content: string) {
82
+ const lines = content.split('\n').length;
83
+ const words = content.split(/\s+/).filter(w => w.length > 0).length;
84
+ const characters = content.length;
85
+ return { lines, words, characters };
86
+ }
87
+
88
+ /**
89
+ * Create ClaudeFile object from file path
90
+ */
91
+ function createClaudeFile(
92
+ filePath: string,
93
+ level: 'user' | 'project' | 'module',
94
+ basePath: string,
95
+ isMainFile: boolean,
96
+ depth?: number
97
+ ): ClaudeFile | null {
98
+ try {
99
+ if (!existsSync(filePath)) return null;
100
+
101
+ const stat = statSync(filePath);
102
+ const content = readFileSync(filePath, 'utf8');
103
+ const parsed = parseClaudeFrontmatter(content);
104
+ const relativePath = relative(basePath, filePath).replace(/\\/g, '/');
105
+ const fileName = filePath.split(/[\\/]/).pop() || 'CLAUDE.md';
106
+
107
+ // Parent directory for module-level files
108
+ const parentDir = level === 'module'
109
+ ? filePath.split(/[\\/]/).slice(-2, -1)[0]
110
+ : undefined;
111
+
112
+ return {
113
+ id: `${level}-${relativePath}`,
114
+ level,
115
+ path: filePath,
116
+ relativePath,
117
+ name: fileName,
118
+ content: parsed.content,
119
+ size: stat.size,
120
+ lastModified: stat.mtime.toISOString(),
121
+ frontmatter: { paths: parsed.paths },
122
+ stats: calculateFileStats(content),
123
+ isMainFile,
124
+ parentDirectory: parentDir,
125
+ depth
126
+ };
127
+ } catch (e) {
128
+ console.error(`Error creating ClaudeFile for ${filePath}:`, e);
129
+ return null;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Scan rules directory (recursive)
135
+ * Adapted from rules-routes.ts::scanRulesDirectory
136
+ */
137
+ function scanClaudeRulesDirectory(dirPath: string, level: 'user' | 'project', basePath: string): ClaudeFile[] {
138
+ const files: ClaudeFile[] = [];
139
+
140
+ try {
141
+ const entries = readdirSync(dirPath, { withFileTypes: true });
142
+ for (const entry of entries) {
143
+ const fullPath = join(dirPath, entry.name);
144
+
145
+ if (entry.isFile() && entry.name.endsWith('.md')) {
146
+ const file = createClaudeFile(fullPath, level, basePath, false);
147
+ if (file) files.push(file);
148
+ } else if (entry.isDirectory()) {
149
+ const subFiles = scanClaudeRulesDirectory(fullPath, level, basePath);
150
+ files.push(...subFiles);
151
+ }
152
+ }
153
+ } catch (e) {
154
+ // Ignore errors
155
+ }
156
+
157
+ return files;
158
+ }
159
+
160
+ /**
161
+ * Scan modules for CLAUDE.md files
162
+ * Uses get-modules-by-depth logic
163
+ */
164
+ function scanModules(projectPath: string): ClaudeFile[] {
165
+ const modules: ClaudeFile[] = [];
166
+ const visited = new Set<string>();
167
+
168
+ // Directories to exclude (from get-modules-by-depth.ts)
169
+ const SYSTEM_EXCLUDES = [
170
+ '.git', '.svn', '.hg', '__pycache__', 'node_modules', '.npm', '.yarn',
171
+ 'dist', 'build', 'out', '.cache', '.venv', 'venv', 'env', 'coverage'
172
+ ];
173
+
174
+ function scanDirectory(dirPath: string, depth: number) {
175
+ try {
176
+ const entries = readdirSync(dirPath, { withFileTypes: true });
177
+
178
+ // Check for CLAUDE.md in current directory
179
+ const claudePath = join(dirPath, 'CLAUDE.md');
180
+ if (existsSync(claudePath) && !visited.has(claudePath)) {
181
+ visited.add(claudePath);
182
+ const file = createClaudeFile(claudePath, 'module', projectPath, true, depth);
183
+ if (file) modules.push(file);
184
+ }
185
+
186
+ // Recurse into subdirectories
187
+ for (const entry of entries) {
188
+ if (!entry.isDirectory()) continue;
189
+ if (SYSTEM_EXCLUDES.includes(entry.name)) continue;
190
+
191
+ const fullPath = join(dirPath, entry.name);
192
+ scanDirectory(fullPath, depth + 1);
193
+ }
194
+ } catch (e) {
195
+ // Ignore permission errors
196
+ }
197
+ }
198
+
199
+ scanDirectory(projectPath, 0);
200
+ return modules.sort((a, b) => (b.depth || 0) - (a.depth || 0)); // Deepest first
201
+ }
202
+
203
+ /**
204
+ * Scan all CLAUDE.md files
205
+ */
206
+ function scanAllClaudeFiles(projectPath: string): ClaudeFilesHierarchy {
207
+ const result: ClaudeFilesHierarchy = {
208
+ user: { main: null },
209
+ project: { main: null },
210
+ modules: [],
211
+ summary: { totalFiles: 0, totalSize: 0 }
212
+ };
213
+
214
+ // User-level files (only main CLAUDE.md, no rules)
215
+ const userHome = homedir();
216
+ const userClaudeDir = join(userHome, '.claude');
217
+ const userClaudePath = join(userClaudeDir, 'CLAUDE.md');
218
+
219
+ if (existsSync(userClaudePath)) {
220
+ result.user.main = createClaudeFile(userClaudePath, 'user', userHome, true);
221
+ }
222
+
223
+ // Project-level files (only main CLAUDE.md, no rules)
224
+ const projectClaudeDir = join(projectPath, '.claude');
225
+ const projectClaudePath = join(projectClaudeDir, 'CLAUDE.md');
226
+
227
+ if (existsSync(projectClaudePath)) {
228
+ result.project.main = createClaudeFile(projectClaudePath, 'project', projectPath, true);
229
+ }
230
+
231
+ // Module-level files
232
+ result.modules = scanModules(projectPath);
233
+
234
+ // Calculate summary (only main CLAUDE.md files, no rules)
235
+ const allFiles = [
236
+ result.user.main,
237
+ result.project.main,
238
+ ...result.modules
239
+ ].filter(f => f !== null) as ClaudeFile[];
240
+
241
+ result.summary = {
242
+ totalFiles: allFiles.length,
243
+ totalSize: allFiles.reduce((sum, f) => sum + f.size, 0),
244
+ lastSync: new Date().toISOString()
245
+ };
246
+
247
+ return result;
248
+ }
249
+
250
+ /**
251
+ * Get single file content
252
+ */
253
+ function getClaudeFile(filePath: string): ClaudeFile | null {
254
+ try {
255
+ if (!existsSync(filePath)) {
256
+ return null;
257
+ }
258
+
259
+ const stat = statSync(filePath);
260
+ const content = readFileSync(filePath, 'utf8');
261
+ const parsed = parseClaudeFrontmatter(content);
262
+
263
+ // Determine level based on path
264
+ let level: 'user' | 'project' | 'module' = 'module';
265
+ if (filePath.includes(join(homedir(), '.claude'))) {
266
+ level = 'user';
267
+ } else if (filePath.includes('.claude')) {
268
+ level = 'project';
269
+ }
270
+
271
+ const isMainFile = filePath.endsWith('CLAUDE.md') && !filePath.includes('rules');
272
+
273
+ return {
274
+ id: `${level}-${filePath}`,
275
+ level,
276
+ path: filePath,
277
+ relativePath: filePath,
278
+ name: filePath.split(/[\\/]/).pop() || 'CLAUDE.md',
279
+ content: parsed.content,
280
+ size: stat.size,
281
+ lastModified: stat.mtime.toISOString(),
282
+ frontmatter: { paths: parsed.paths },
283
+ stats: calculateFileStats(content),
284
+ isMainFile
285
+ };
286
+ } catch (error) {
287
+ console.error('Error reading CLAUDE.md file:', error);
288
+ return null;
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Save file content
294
+ */
295
+ function saveClaudeFile(filePath: string, content: string, createBackup: boolean = false): { success: boolean; error?: string } {
296
+ try {
297
+ if (!existsSync(filePath)) {
298
+ return { success: false, error: 'File not found' };
299
+ }
300
+
301
+ // Create backup if requested
302
+ if (createBackup) {
303
+ const backupPath = `${filePath}.backup-${Date.now()}`;
304
+ const originalContent = readFileSync(filePath, 'utf8');
305
+ writeFileSync(backupPath, originalContent, 'utf8');
306
+ }
307
+
308
+ // Write new content
309
+ writeFileSync(filePath, content, 'utf8');
310
+
311
+ return { success: true };
312
+ } catch (error) {
313
+ return { success: false, error: (error as Error).message };
314
+ }
315
+ }
316
+
317
+ /**
318
+ * Generate CLI prompt for syncing CLAUDE.md files
319
+ */
320
+ function generateSyncPrompt(level: 'user' | 'project' | 'module', modulePath?: string): string {
321
+ if (level === 'module' && modulePath) {
322
+ // Module-level prompt
323
+ return `PURPOSE: Generate module-level CLAUDE.md for ${modulePath}
324
+ TASK: • Analyze module's purpose and responsibilities • Document public APIs and interfaces • Identify dependencies and integration points • Note testing patterns and conventions
325
+ MODE: analysis
326
+ CONTEXT: @${modulePath}/**/* | Memory: Project conventions from .claude/CLAUDE.md
327
+ EXPECTED: Module-level CLAUDE.md with: - Module purpose (1-2 sentences) - Key files and their roles - Public API documentation - Integration points - Testing approach
328
+ RULES: $(cat ~/.claude/workflows/cli-templates/prompts/planning/02-design-component-spec.txt) | Module-level perspective only | Concrete examples | analysis=READ-ONLY`;
329
+ } else {
330
+ // User/Project level prompt
331
+ const contextPath = level === 'user' ? '~/.claude' : '.claude';
332
+ return `PURPOSE: Update CLAUDE.md with current ${level} understanding
333
+ TASK: • Analyze ${level} configuration and conventions • Identify common patterns and anti-patterns • Generate concise, actionable rules • Maintain existing structure and formatting
334
+ MODE: analysis
335
+ CONTEXT: @${contextPath}/**/*
336
+ EXPECTED: Updated CLAUDE.md content with: - Preserved existing sections - New insights appended to relevant sections - Timestamp header - Focus on ${level}-level concerns
337
+ RULES: $(cat ~/.claude/workflows/cli-templates/prompts/analysis/02-analyze-code-patterns.txt) | Maintain existing CLAUDE.md structure | Focus on actionable rules | analysis=READ-ONLY`;
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Smart merge CLAUDE.md content (update mode)
343
+ */
344
+ function smartMergeContent(existingContent: string, cliOutput: string): string {
345
+ // For now, use simple append strategy
346
+ // TODO: Implement intelligent section-based merging
347
+ const timestamp = new Date().toISOString();
348
+ const separator = '\n\n---\n\n';
349
+ const header = `## Updated: ${timestamp}\n\n`;
350
+
351
+ return existingContent + separator + header + cliOutput;
352
+ }
353
+
354
+ /**
355
+ * Scan all files in project directory
356
+ */
357
+ function scanAllProjectFiles(projectPath: string): any {
358
+ const SYSTEM_EXCLUDES = [
359
+ '.git', '.svn', '.hg', '__pycache__', 'node_modules', '.npm', '.yarn',
360
+ 'dist', 'build', 'out', '.cache', '.venv', 'venv', 'env', 'coverage',
361
+ '.next', '.nuxt', '.output', '.turbo', '.parcel-cache', 'logs', 'tmp', 'temp'
362
+ ];
363
+
364
+ const results: any = {
365
+ files: [],
366
+ summary: { totalFiles: 0, totalDirectories: 0, totalSize: 0 }
367
+ };
368
+
369
+ function scanDir(dirPath: string, depth: number = 0): any[] {
370
+ if (depth > 10) return []; // Max depth limit
371
+
372
+ const files: any[] = [];
373
+
374
+ try {
375
+ const entries = readdirSync(dirPath, { withFileTypes: true });
376
+
377
+ for (const entry of entries) {
378
+ // Skip system excludes and hidden files (except .claude and .workflow)
379
+ if (SYSTEM_EXCLUDES.includes(entry.name)) continue;
380
+ if (entry.name.startsWith('.') && entry.name !== '.claude' && entry.name !== '.workflow') continue;
381
+
382
+ const fullPath = join(dirPath, entry.name);
383
+ const relativePath = relative(projectPath, fullPath).replace(/\\/g, '/');
384
+
385
+ if (entry.isDirectory()) {
386
+ results.summary.totalDirectories++;
387
+
388
+ const dirNode: any = {
389
+ path: fullPath,
390
+ name: entry.name,
391
+ type: 'directory',
392
+ depth,
393
+ children: scanDir(fullPath, depth + 1)
394
+ };
395
+
396
+ files.push(dirNode);
397
+ } else {
398
+ const stat = statSync(fullPath);
399
+ results.summary.totalFiles++;
400
+ results.summary.totalSize += stat.size;
401
+
402
+ files.push({
403
+ path: fullPath,
404
+ name: entry.name,
405
+ type: 'file',
406
+ size: stat.size,
407
+ lastModified: stat.mtime.toISOString(),
408
+ depth
409
+ });
410
+ }
411
+ }
412
+ } catch (e) {
413
+ // Ignore permission errors
414
+ }
415
+
416
+ return files;
417
+ }
418
+
419
+ results.files = scanDir(projectPath);
420
+ return results;
421
+ }
422
+
423
+ /**
424
+ * Read single file content
425
+ */
426
+ function readSingleFile(filePath: string): { content: string; size: number; lastModified: string } | null {
427
+ try {
428
+ if (!existsSync(filePath)) return null;
429
+ const stat = statSync(filePath);
430
+ const content = readFileSync(filePath, 'utf8');
431
+ return {
432
+ content,
433
+ size: stat.size,
434
+ lastModified: stat.mtime.toISOString()
435
+ };
436
+ } catch (e) {
437
+ return null;
438
+ }
439
+ }
440
+
441
+ /**
442
+ * Delete CLAUDE.md file
443
+ */
444
+ function deleteClaudeFile(filePath: string): { success: boolean; error?: string } {
445
+ try {
446
+ if (!existsSync(filePath)) {
447
+ return { success: false, error: 'File not found' };
448
+ }
449
+
450
+ // Create backup before deletion
451
+ const backupPath = `${filePath}.deleted-${Date.now()}`;
452
+ const content = readFileSync(filePath, 'utf8');
453
+ writeFileSync(backupPath, content, 'utf8');
454
+
455
+ // Delete original file
456
+ const fs = require('fs');
457
+ fs.unlinkSync(filePath);
458
+
459
+ return { success: true };
460
+ } catch (error) {
461
+ return { success: false, error: (error as Error).message };
462
+ }
463
+ }
464
+
465
+ /**
466
+ * Create new CLAUDE.md file with template
467
+ */
468
+ function createNewClaudeFile(level: 'user' | 'project' | 'module', template: string, pathParam?: string): { success: boolean; path?: string; error?: string } {
469
+ try {
470
+ let filePath: string;
471
+ let content: string;
472
+
473
+ // Determine file path
474
+ if (level === 'user') {
475
+ filePath = join(homedir(), '.claude', 'CLAUDE.md');
476
+ } else if (level === 'project' && pathParam) {
477
+ filePath = join(pathParam, '.claude', 'CLAUDE.md');
478
+ } else if (level === 'module' && pathParam) {
479
+ filePath = join(pathParam, 'CLAUDE.md');
480
+ } else {
481
+ return { success: false, error: 'Invalid parameters' };
482
+ }
483
+
484
+ // Check if file already exists
485
+ if (existsSync(filePath)) {
486
+ return { success: false, error: 'File already exists' };
487
+ }
488
+
489
+ // Generate content based on template
490
+ const timestamp = new Date().toISOString();
491
+
492
+ if (template === 'minimal') {
493
+ content = `# CLAUDE.md (${level.toUpperCase()} Level)\n\n> Created: ${timestamp}\n\n## Purpose\n\n[Describe the purpose of this ${level}-level context]\n\n## Guidelines\n\n- [Add guideline 1]\n- [Add guideline 2]\n`;
494
+ } else if (template === 'comprehensive') {
495
+ content = `# CLAUDE.md (${level.toUpperCase()} Level)\n\n> Created: ${timestamp}\n\n## Purpose\n\n[Describe the purpose and scope]\n\n## Architecture\n\n[Describe key architectural decisions]\n\n## Coding Conventions\n\n### Naming\n\n- [Convention 1]\n- [Convention 2]\n\n### Patterns\n\n- [Pattern 1]\n- [Pattern 2]\n\n## Testing Guidelines\n\n[Testing approach and conventions]\n\n## Dependencies\n\n[Key dependencies and integration points]\n\n## Common Tasks\n\n### Task 1\n\n[Steps for task 1]\n\n### Task 2\n\n[Steps for task 2]\n`;
496
+ } else {
497
+ // default template
498
+ content = `# CLAUDE.md (${level.toUpperCase()} Level)\n\n> Created: ${timestamp}\n\n## Overview\n\n[Brief description of this ${level}-level context]\n\n## Key Conventions\n\n- [Convention 1]\n- [Convention 2]\n- [Convention 3]\n\n## Guidelines\n\n### Code Style\n\n[Style guidelines]\n\n### Best Practices\n\n[Best practices]\n`;
499
+ }
500
+
501
+ // Ensure directory exists
502
+ const dir = filePath.substring(0, filePath.lastIndexOf('/') || filePath.lastIndexOf('\\'));
503
+ const fs = require('fs');
504
+ if (!existsSync(dir)) {
505
+ fs.mkdirSync(dir, { recursive: true });
506
+ }
507
+
508
+ // Write file
509
+ writeFileSync(filePath, content, 'utf8');
510
+
511
+ return { success: true, path: filePath };
512
+ } catch (error) {
513
+ return { success: false, error: (error as Error).message };
514
+ }
515
+ }
516
+
517
+ /**
518
+ * Handle CLAUDE.md routes
519
+ */
520
+ export async function handleClaudeRoutes(ctx: RouteContext): Promise<boolean> {
521
+ const { pathname, url, req, res, initialPath, handlePostRequest, broadcastToClients } = ctx;
522
+
523
+ // API: Scan all CLAUDE.md files
524
+ if (pathname === '/api/memory/claude/scan') {
525
+ const projectPathParam = url.searchParams.get('path') || initialPath;
526
+ const filesData = scanAllClaudeFiles(projectPathParam);
527
+ res.writeHead(200, { 'Content-Type': 'application/json' });
528
+ res.end(JSON.stringify(filesData));
529
+ return true;
530
+ }
531
+
532
+ // API: Scan all project files (not just CLAUDE.md)
533
+ if (pathname === '/api/memory/claude/scan-all') {
534
+ const projectPathParam = url.searchParams.get('path') || initialPath;
535
+ const filesData = scanAllProjectFiles(projectPathParam);
536
+ res.writeHead(200, { 'Content-Type': 'application/json' });
537
+ res.end(JSON.stringify(filesData));
538
+ return true;
539
+ }
540
+
541
+ // API: Read single file
542
+ if (pathname === '/api/memory/claude/read-file' && req.method === 'GET') {
543
+ const filePath = url.searchParams.get('path');
544
+ if (!filePath) {
545
+ res.writeHead(400, { 'Content-Type': 'application/json' });
546
+ res.end(JSON.stringify({ error: 'Missing path parameter' }));
547
+ return true;
548
+ }
549
+
550
+ const fileData = readSingleFile(filePath);
551
+ if (!fileData) {
552
+ res.writeHead(404, { 'Content-Type': 'application/json' });
553
+ res.end(JSON.stringify({ error: 'File not found' }));
554
+ return true;
555
+ }
556
+
557
+ res.writeHead(200, { 'Content-Type': 'application/json' });
558
+ res.end(JSON.stringify(fileData));
559
+ return true;
560
+ }
561
+
562
+ // API: CLI Sync (analyze and update CLAUDE.md using CLI tools)
563
+ if (pathname === '/api/memory/claude/sync' && req.method === 'POST') {
564
+ handlePostRequest(req, res, async (body: any) => {
565
+ const { level, path: modulePath, tool = 'gemini', mode = 'update', targets } = body;
566
+
567
+ if (!level) {
568
+ return { error: 'Missing level parameter', status: 400 };
569
+ }
570
+
571
+ try {
572
+ // Import CLI executor
573
+ const { executeCliTool } = await import('../../tools/cli-executor.js');
574
+
575
+ // Determine file path based on level
576
+ let filePath: string;
577
+ let workingDir: string;
578
+
579
+ if (level === 'user') {
580
+ filePath = join(homedir(), '.claude', 'CLAUDE.md');
581
+ workingDir = join(homedir(), '.claude');
582
+ } else if (level === 'project') {
583
+ filePath = join(initialPath, '.claude', 'CLAUDE.md');
584
+ workingDir = join(initialPath, '.claude');
585
+ } else if (level === 'module' && modulePath) {
586
+ filePath = join(modulePath, 'CLAUDE.md');
587
+ workingDir = modulePath;
588
+ } else {
589
+ return { error: 'Invalid level or missing path for module level', status: 400 };
590
+ }
591
+
592
+ // Check if file exists (for update/append modes)
593
+ const fileExists = existsSync(filePath);
594
+ if (!fileExists && mode !== 'generate') {
595
+ return { error: 'File does not exist. Use generate mode to create it.', status: 404 };
596
+ }
597
+
598
+ // Read existing content
599
+ const existingContent = fileExists ? readFileSync(filePath, 'utf8') : '';
600
+
601
+ // Generate CLI prompt
602
+ const cliPrompt = generateSyncPrompt(level, modulePath);
603
+
604
+ // Execute CLI tool
605
+ const syncId = `claude-sync-${level}-${Date.now()}`;
606
+ const result = await executeCliTool({
607
+ tool: tool === 'qwen' ? 'qwen' : 'gemini',
608
+ prompt: cliPrompt,
609
+ mode: 'analysis',
610
+ format: 'plain',
611
+ cd: workingDir,
612
+ timeout: 600000, // 10 minutes
613
+ stream: false,
614
+ category: 'internal',
615
+ id: syncId
616
+ });
617
+
618
+ if (!result.success || !result.execution?.output) {
619
+ return {
620
+ error: 'CLI execution failed',
621
+ details: result.execution?.error || 'No output received',
622
+ status: 500
623
+ };
624
+ }
625
+
626
+ // Extract CLI output
627
+ const cliOutput = typeof result.execution.output === 'string'
628
+ ? result.execution.output
629
+ : result.execution.output.stdout || '';
630
+
631
+ if (!cliOutput || cliOutput.trim().length === 0) {
632
+ return { error: 'CLI returned empty output', status: 500 };
633
+ }
634
+
635
+ // Process content based on mode
636
+ let finalContent: string;
637
+
638
+ if (mode === 'generate') {
639
+ // Full replace
640
+ const timestamp = new Date().toISOString();
641
+ finalContent = `# CLAUDE.md (${level.toUpperCase()} Level)\n\n> Auto-generated using ${tool.toUpperCase()}\n> Last updated: ${timestamp}\n\n---\n\n${cliOutput}`;
642
+ } else if (mode === 'append') {
643
+ // Simple append
644
+ const timestamp = new Date().toISOString();
645
+ finalContent = existingContent + `\n\n---\n\n## Updated: ${timestamp}\n\n${cliOutput}`;
646
+ } else {
647
+ // Smart merge (update mode)
648
+ finalContent = smartMergeContent(existingContent, cliOutput);
649
+ }
650
+
651
+ // Write updated content
652
+ writeFileSync(filePath, finalContent, 'utf8');
653
+
654
+ // Mark file as updated for freshness tracking
655
+ try {
656
+ const { markFileAsUpdated } = await import('../claude-freshness.js');
657
+ markFileAsUpdated(filePath, level, 'cli_sync', initialPath, { tool, mode });
658
+ } catch (e) {
659
+ console.error('Failed to mark file as updated:', e);
660
+ }
661
+
662
+ // Broadcast WebSocket event
663
+ broadcastToClients({
664
+ type: 'CLAUDE_FILE_SYNCED',
665
+ payload: {
666
+ path: filePath,
667
+ level,
668
+ tool,
669
+ mode,
670
+ executionId: syncId,
671
+ timestamp: new Date().toISOString()
672
+ }
673
+ });
674
+
675
+ return {
676
+ success: true,
677
+ path: filePath,
678
+ executionId: syncId,
679
+ mode,
680
+ tool
681
+ };
682
+
683
+ } catch (error) {
684
+ console.error('Error syncing CLAUDE.md file:', error);
685
+ return {
686
+ error: 'Sync failed',
687
+ details: (error as Error).message,
688
+ status: 500
689
+ };
690
+ }
691
+ });
692
+ return true;
693
+ }
694
+
695
+ // API: Get single file
696
+ if (pathname === '/api/memory/claude/file' && req.method === 'GET') {
697
+ const filePath = url.searchParams.get('path');
698
+ if (!filePath) {
699
+ res.writeHead(400, { 'Content-Type': 'application/json' });
700
+ res.end(JSON.stringify({ error: 'Missing path parameter' }));
701
+ return true;
702
+ }
703
+
704
+ const file = getClaudeFile(filePath);
705
+ if (!file) {
706
+ res.writeHead(404, { 'Content-Type': 'application/json' });
707
+ res.end(JSON.stringify({ error: 'File not found' }));
708
+ return true;
709
+ }
710
+
711
+ res.writeHead(200, { 'Content-Type': 'application/json' });
712
+ res.end(JSON.stringify(file));
713
+ return true;
714
+ }
715
+
716
+ // API: Save file
717
+ if (pathname === '/api/memory/claude/file' && req.method === 'POST') {
718
+ handlePostRequest(req, res, async (body: any) => {
719
+ const { path: filePath, content, createBackup } = body;
720
+
721
+ if (!filePath || content === undefined) {
722
+ return { error: 'Missing path or content parameter', status: 400 };
723
+ }
724
+
725
+ const result = saveClaudeFile(filePath, content, createBackup);
726
+
727
+ if (result.success) {
728
+ // Broadcast update to all clients
729
+ ctx.broadcastToClients({
730
+ type: 'CLAUDE_FILE_UPDATED',
731
+ data: { path: filePath }
732
+ });
733
+ return { success: true, path: filePath };
734
+ } else {
735
+ return { error: result.error, status: 500 };
736
+ }
737
+ });
738
+ return true;
739
+ }
740
+
741
+ // API: Delete file
742
+ if (pathname === '/api/memory/claude/file' && req.method === 'DELETE') {
743
+ const filePath = url.searchParams.get('path');
744
+ const confirm = url.searchParams.get('confirm');
745
+
746
+ if (!filePath) {
747
+ res.writeHead(400, { 'Content-Type': 'application/json' });
748
+ res.end(JSON.stringify({ error: 'Missing path parameter' }));
749
+ return true;
750
+ }
751
+
752
+ if (confirm !== 'true') {
753
+ res.writeHead(400, { 'Content-Type': 'application/json' });
754
+ res.end(JSON.stringify({ error: 'Confirmation required' }));
755
+ return true;
756
+ }
757
+
758
+ const result = deleteClaudeFile(filePath);
759
+
760
+ if (result.success) {
761
+ broadcastToClients({
762
+ type: 'CLAUDE_FILE_DELETED',
763
+ data: { path: filePath }
764
+ });
765
+ res.writeHead(200, { 'Content-Type': 'application/json' });
766
+ res.end(JSON.stringify({ success: true }));
767
+ } else {
768
+ res.writeHead(500, { 'Content-Type': 'application/json' });
769
+ res.end(JSON.stringify({ error: result.error }));
770
+ }
771
+ return true;
772
+ }
773
+
774
+ // API: Create file
775
+ if (pathname === '/api/memory/claude/create' && req.method === 'POST') {
776
+ handlePostRequest(req, res, async (body: any) => {
777
+ const { level, path, template = 'default' } = body;
778
+
779
+ if (!level) {
780
+ return { error: 'Missing level parameter', status: 400 };
781
+ }
782
+
783
+ let result: any;
784
+
785
+ if (level === 'project') {
786
+ // For project level, use initialPath
787
+ const filePath = join(initialPath, '.claude', 'CLAUDE.md');
788
+ result = createNewClaudeFile(level, template, initialPath);
789
+ } else if (level === 'module') {
790
+ if (!path) {
791
+ return { error: 'Module path required', status: 400 };
792
+ }
793
+ result = createNewClaudeFile(level, template, path);
794
+ } else {
795
+ result = createNewClaudeFile(level, template);
796
+ }
797
+
798
+ if (result.success) {
799
+ broadcastToClients({
800
+ type: 'CLAUDE_FILE_CREATED',
801
+ data: { path: result.path, level }
802
+ });
803
+ return { success: true, path: result.path };
804
+ } else {
805
+ return { error: result.error, status: 500 };
806
+ }
807
+ });
808
+ return true;
809
+ }
810
+
811
+ // API: Get Chinese response setting status
812
+ if (pathname === '/api/language/chinese-response' && req.method === 'GET') {
813
+ try {
814
+ const userClaudePath = join(homedir(), '.claude', 'CLAUDE.md');
815
+ const chineseRefPattern = /@.*chinese-response\.md/i;
816
+
817
+ let enabled = false;
818
+ let guidelinesPath = '';
819
+
820
+ // Check if user CLAUDE.md exists and contains Chinese response reference
821
+ if (existsSync(userClaudePath)) {
822
+ const content = readFileSync(userClaudePath, 'utf8');
823
+ enabled = chineseRefPattern.test(content);
824
+ }
825
+
826
+ // Find guidelines file path - always use user-level path
827
+ const userGuidelinesPath = join(homedir(), '.claude', 'workflows', 'chinese-response.md');
828
+
829
+ if (existsSync(userGuidelinesPath)) {
830
+ guidelinesPath = userGuidelinesPath;
831
+ }
832
+
833
+ res.writeHead(200, { 'Content-Type': 'application/json' });
834
+ res.end(JSON.stringify({
835
+ enabled,
836
+ guidelinesPath,
837
+ guidelinesExists: !!guidelinesPath,
838
+ userClaudeMdExists: existsSync(userClaudePath)
839
+ }));
840
+ return true;
841
+ } catch (error) {
842
+ res.writeHead(500, { 'Content-Type': 'application/json' });
843
+ res.end(JSON.stringify({ error: (error as Error).message }));
844
+ return true;
845
+ }
846
+ }
847
+
848
+ // API: Toggle Chinese response setting
849
+ if (pathname === '/api/language/chinese-response' && req.method === 'POST') {
850
+ handlePostRequest(req, res, async (body: any) => {
851
+ const { enabled } = body;
852
+
853
+ if (typeof enabled !== 'boolean') {
854
+ return { error: 'Missing or invalid enabled parameter', status: 400 };
855
+ }
856
+
857
+ try {
858
+ const userClaudePath = join(homedir(), '.claude', 'CLAUDE.md');
859
+ const userClaudeDir = join(homedir(), '.claude');
860
+
861
+ // Find guidelines file path - always use user-level path with ~ shorthand
862
+ const userGuidelinesPath = join(homedir(), '.claude', 'workflows', 'chinese-response.md');
863
+
864
+ if (!existsSync(userGuidelinesPath)) {
865
+ return { error: 'Chinese response guidelines file not found at ~/.claude/workflows/chinese-response.md', status: 404 };
866
+ }
867
+
868
+ const guidelinesRef = '~/.claude/workflows/chinese-response.md';
869
+
870
+ const chineseRefLine = `- **中文回复准则**: @${guidelinesRef}`;
871
+ const chineseRefPattern = /^- \*\*中文回复准则\*\*:.*chinese-response\.md.*$/gm;
872
+
873
+ // Ensure user .claude directory exists
874
+ if (!existsSync(userClaudeDir)) {
875
+ const fs = require('fs');
876
+ fs.mkdirSync(userClaudeDir, { recursive: true });
877
+ }
878
+
879
+ let content = '';
880
+ if (existsSync(userClaudePath)) {
881
+ content = readFileSync(userClaudePath, 'utf8');
882
+ } else {
883
+ // Create new CLAUDE.md with header
884
+ content = '# Claude Instructions\n\n';
885
+ }
886
+
887
+ if (enabled) {
888
+ // Check if reference already exists
889
+ if (chineseRefPattern.test(content)) {
890
+ return { success: true, message: 'Already enabled' };
891
+ }
892
+
893
+ // Add reference after the header line or at the beginning
894
+ const headerMatch = content.match(/^# Claude Instructions\n\n?/);
895
+ if (headerMatch) {
896
+ const insertPosition = headerMatch[0].length;
897
+ content = content.slice(0, insertPosition) + chineseRefLine + '\n' + content.slice(insertPosition);
898
+ } else {
899
+ // Add header and reference
900
+ content = '# Claude Instructions\n\n' + chineseRefLine + '\n' + content;
901
+ }
902
+ } else {
903
+ // Remove reference
904
+ content = content.replace(chineseRefPattern, '').replace(/\n{3,}/g, '\n\n').trim();
905
+ if (content) content += '\n';
906
+ }
907
+
908
+ writeFileSync(userClaudePath, content, 'utf8');
909
+
910
+ // Broadcast update
911
+ broadcastToClients({
912
+ type: 'LANGUAGE_SETTING_CHANGED',
913
+ data: { chineseResponse: enabled }
914
+ });
915
+
916
+ return { success: true, enabled };
917
+ } catch (error) {
918
+ return { error: (error as Error).message, status: 500 };
919
+ }
920
+ });
921
+ return true;
922
+ }
923
+
924
+ // API: Get Windows platform setting status
925
+ if (pathname === '/api/language/windows-platform' && req.method === 'GET') {
926
+ try {
927
+ const userClaudePath = join(homedir(), '.claude', 'CLAUDE.md');
928
+ const windowsRefPattern = /@.*windows-platform\.md/i;
929
+
930
+ let enabled = false;
931
+ let guidelinesPath = '';
932
+
933
+ // Check if user CLAUDE.md exists and contains Windows platform reference
934
+ if (existsSync(userClaudePath)) {
935
+ const content = readFileSync(userClaudePath, 'utf8');
936
+ enabled = windowsRefPattern.test(content);
937
+ }
938
+
939
+ // Find guidelines file path - always use user-level path
940
+ const userGuidelinesPath = join(homedir(), '.claude', 'workflows', 'windows-platform.md');
941
+
942
+ if (existsSync(userGuidelinesPath)) {
943
+ guidelinesPath = userGuidelinesPath;
944
+ }
945
+
946
+ res.writeHead(200, { 'Content-Type': 'application/json' });
947
+ res.end(JSON.stringify({
948
+ enabled,
949
+ guidelinesPath,
950
+ guidelinesExists: !!guidelinesPath,
951
+ userClaudeMdExists: existsSync(userClaudePath)
952
+ }));
953
+ return true;
954
+ } catch (error) {
955
+ res.writeHead(500, { 'Content-Type': 'application/json' });
956
+ res.end(JSON.stringify({ error: (error as Error).message }));
957
+ return true;
958
+ }
959
+ }
960
+
961
+ // API: Toggle Windows platform setting
962
+ if (pathname === '/api/language/windows-platform' && req.method === 'POST') {
963
+ handlePostRequest(req, res, async (body: any) => {
964
+ const { enabled } = body;
965
+
966
+ if (typeof enabled !== 'boolean') {
967
+ return { error: 'Missing or invalid enabled parameter', status: 400 };
968
+ }
969
+
970
+ try {
971
+ const userClaudePath = join(homedir(), '.claude', 'CLAUDE.md');
972
+ const userClaudeDir = join(homedir(), '.claude');
973
+
974
+ // Find guidelines file path - always use user-level path with ~ shorthand
975
+ const userGuidelinesPath = join(homedir(), '.claude', 'workflows', 'windows-platform.md');
976
+
977
+ if (!existsSync(userGuidelinesPath)) {
978
+ return { error: 'Windows platform guidelines file not found at ~/.claude/workflows/windows-platform.md', status: 404 };
979
+ }
980
+
981
+ const guidelinesRef = '~/.claude/workflows/windows-platform.md';
982
+
983
+ const windowsRefLine = `- **Windows Platform**: @${guidelinesRef}`;
984
+ const windowsRefPattern = /^- \*\*Windows Platform\*\*:.*windows-platform\.md.*$/gm;
985
+
986
+ // Ensure user .claude directory exists
987
+ if (!existsSync(userClaudeDir)) {
988
+ const fs = require('fs');
989
+ fs.mkdirSync(userClaudeDir, { recursive: true });
990
+ }
991
+
992
+ let content = '';
993
+ if (existsSync(userClaudePath)) {
994
+ content = readFileSync(userClaudePath, 'utf8');
995
+ } else {
996
+ // Create new CLAUDE.md with header
997
+ content = '# Claude Instructions\n\n';
998
+ }
999
+
1000
+ if (enabled) {
1001
+ // Check if reference already exists
1002
+ if (windowsRefPattern.test(content)) {
1003
+ return { success: true, message: 'Already enabled' };
1004
+ }
1005
+
1006
+ // Add reference after the header line or at the beginning
1007
+ const headerMatch = content.match(/^# Claude Instructions\n\n?/);
1008
+ if (headerMatch) {
1009
+ const insertPosition = headerMatch[0].length;
1010
+ content = content.slice(0, insertPosition) + windowsRefLine + '\n' + content.slice(insertPosition);
1011
+ } else {
1012
+ // Add header and reference
1013
+ content = '# Claude Instructions\n\n' + windowsRefLine + '\n' + content;
1014
+ }
1015
+ } else {
1016
+ // Remove reference
1017
+ content = content.replace(windowsRefPattern, '').replace(/\n{3,}/g, '\n\n').trim();
1018
+ if (content) content += '\n';
1019
+ }
1020
+
1021
+ writeFileSync(userClaudePath, content, 'utf8');
1022
+
1023
+ // Broadcast update
1024
+ broadcastToClients({
1025
+ type: 'LANGUAGE_SETTING_CHANGED',
1026
+ data: { windowsPlatform: enabled }
1027
+ });
1028
+
1029
+ return { success: true, enabled };
1030
+ } catch (error) {
1031
+ return { error: (error as Error).message, status: 500 };
1032
+ }
1033
+ });
1034
+ return true;
1035
+ }
1036
+
1037
+ // API: Get freshness scores for all CLAUDE.md files
1038
+ if (pathname === '/api/memory/claude/freshness' && req.method === 'GET') {
1039
+ try {
1040
+ const { calculateAllFreshness } = await import('../claude-freshness.js');
1041
+
1042
+ const projectPathParam = url.searchParams.get('path') || initialPath;
1043
+ const threshold = parseInt(url.searchParams.get('threshold') || '20', 10);
1044
+
1045
+ // Get all CLAUDE.md files
1046
+ const filesData = scanAllClaudeFiles(projectPathParam);
1047
+
1048
+ // Prepare file list for freshness calculation
1049
+ const claudeFiles: Array<{
1050
+ path: string;
1051
+ level: 'user' | 'project' | 'module';
1052
+ lastModified: string;
1053
+ }> = [];
1054
+
1055
+ if (filesData.user.main) {
1056
+ claudeFiles.push({
1057
+ path: filesData.user.main.path,
1058
+ level: 'user',
1059
+ lastModified: filesData.user.main.lastModified
1060
+ });
1061
+ }
1062
+
1063
+ if (filesData.project.main) {
1064
+ claudeFiles.push({
1065
+ path: filesData.project.main.path,
1066
+ level: 'project',
1067
+ lastModified: filesData.project.main.lastModified
1068
+ });
1069
+ }
1070
+
1071
+ for (const module of filesData.modules) {
1072
+ claudeFiles.push({
1073
+ path: module.path,
1074
+ level: 'module',
1075
+ lastModified: module.lastModified
1076
+ });
1077
+ }
1078
+
1079
+ // Calculate freshness
1080
+ const freshnessData = calculateAllFreshness(claudeFiles, projectPathParam, threshold);
1081
+
1082
+ res.writeHead(200, { 'Content-Type': 'application/json' });
1083
+ res.end(JSON.stringify(freshnessData));
1084
+ return true;
1085
+ } catch (error) {
1086
+ console.error('Error calculating freshness:', error);
1087
+ res.writeHead(500, { 'Content-Type': 'application/json' });
1088
+ res.end(JSON.stringify({ error: (error as Error).message }));
1089
+ return true;
1090
+ }
1091
+ }
1092
+
1093
+ // API: Mark a CLAUDE.md file as updated
1094
+ if (pathname === '/api/memory/claude/mark-updated' && req.method === 'POST') {
1095
+ handlePostRequest(req, res, async (body: any) => {
1096
+ const { path: filePath, source, metadata } = body;
1097
+
1098
+ if (!filePath) {
1099
+ return { error: 'Missing path parameter', status: 400 };
1100
+ }
1101
+
1102
+ if (!source || !['manual', 'cli_sync', 'dashboard', 'api'].includes(source)) {
1103
+ return { error: 'Invalid or missing source parameter', status: 400 };
1104
+ }
1105
+
1106
+ try {
1107
+ const { markFileAsUpdated } = await import('../claude-freshness.js');
1108
+
1109
+ // Determine file level
1110
+ let level: 'user' | 'project' | 'module' = 'module';
1111
+ if (filePath.includes(join(homedir(), '.claude'))) {
1112
+ level = 'user';
1113
+ } else if (filePath.includes('.claude')) {
1114
+ level = 'project';
1115
+ }
1116
+
1117
+ const record = markFileAsUpdated(filePath, level, source, initialPath, metadata);
1118
+
1119
+ // Broadcast update
1120
+ broadcastToClients({
1121
+ type: 'CLAUDE_FRESHNESS_UPDATED',
1122
+ data: {
1123
+ path: filePath,
1124
+ level,
1125
+ updatedAt: record.updated_at,
1126
+ source
1127
+ }
1128
+ });
1129
+
1130
+ return {
1131
+ success: true,
1132
+ record: {
1133
+ id: record.id,
1134
+ updated_at: record.updated_at,
1135
+ filesChangedBeforeUpdate: record.files_changed_before_update
1136
+ }
1137
+ };
1138
+ } catch (error) {
1139
+ console.error('Error marking file as updated:', error);
1140
+ return { error: (error as Error).message, status: 500 };
1141
+ }
1142
+ });
1143
+ return true;
1144
+ }
1145
+
1146
+ // API: Get update history for a CLAUDE.md file
1147
+ if (pathname === '/api/memory/claude/history' && req.method === 'GET') {
1148
+ const filePath = url.searchParams.get('path');
1149
+ const limit = parseInt(url.searchParams.get('limit') || '50', 10);
1150
+
1151
+ if (!filePath) {
1152
+ res.writeHead(400, { 'Content-Type': 'application/json' });
1153
+ res.end(JSON.stringify({ error: 'Missing path parameter' }));
1154
+ return true;
1155
+ }
1156
+
1157
+ try {
1158
+ const { getUpdateHistory } = await import('../claude-freshness.js');
1159
+
1160
+ const records = getUpdateHistory(filePath, initialPath, limit);
1161
+
1162
+ res.writeHead(200, { 'Content-Type': 'application/json' });
1163
+ res.end(JSON.stringify({
1164
+ records: records.map(r => ({
1165
+ id: r.id,
1166
+ updated_at: r.updated_at,
1167
+ update_source: r.update_source,
1168
+ git_commit_hash: r.git_commit_hash,
1169
+ files_changed_before_update: r.files_changed_before_update,
1170
+ metadata: r.metadata ? JSON.parse(r.metadata) : undefined
1171
+ }))
1172
+ }));
1173
+ return true;
1174
+ } catch (error) {
1175
+ console.error('Error getting update history:', error);
1176
+ res.writeHead(500, { 'Content-Type': 'application/json' });
1177
+ res.end(JSON.stringify({ error: (error as Error).message }));
1178
+ return true;
1179
+ }
1180
+ }
1181
+
1182
+ return false;
1183
+ }