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,1141 @@
1
+ /**
2
+ * Session Command - Workflow session lifecycle management
3
+ * Adapter for session_manager tool providing direct CLI access
4
+ */
5
+
6
+ import chalk from 'chalk';
7
+ import http from 'http';
8
+ import { executeTool } from '../tools/index.js';
9
+ import { resolveFilePath, PathResolutionError, type ResolverContext } from './session-path-resolver.js';
10
+
11
+ // Handle EPIPE errors gracefully (occurs when piping to head/jq that closes early)
12
+ process.stdout.on('error', (err: NodeJS.ErrnoException) => {
13
+ if (err.code === 'EPIPE') {
14
+ process.exit(0);
15
+ }
16
+ throw err;
17
+ });
18
+
19
+ interface ListOptions {
20
+ location?: string;
21
+ metadata?: boolean;
22
+ }
23
+
24
+ interface InitOptions {
25
+ type?: string;
26
+ content?: string; // JSON string for custom metadata
27
+ location?: string; // Session location: active | lite-plan | lite-fix
28
+ }
29
+
30
+ interface ReadOptions {
31
+ type?: string;
32
+ taskId?: string;
33
+ filename?: string;
34
+ dimension?: string;
35
+ iteration?: string;
36
+ raw?: boolean;
37
+ }
38
+
39
+ interface WriteOptions {
40
+ type?: string;
41
+ content?: string;
42
+ taskId?: string;
43
+ filename?: string;
44
+ dimension?: string;
45
+ iteration?: string;
46
+ }
47
+
48
+ interface UpdateOptions {
49
+ type?: string;
50
+ content?: string;
51
+ taskId?: string;
52
+ }
53
+
54
+ interface ArchiveOptions {
55
+ updateStatus?: boolean;
56
+ }
57
+
58
+ interface MkdirOptions {
59
+ subdir?: string;
60
+ }
61
+
62
+ interface StatsOptions {}
63
+
64
+ /**
65
+ * Notify dashboard of granular events (fire and forget)
66
+ * @param {Object} data - Event data
67
+ */
68
+ function notifyDashboard(data: any): void {
69
+ const DASHBOARD_PORT = process.env.CCW_PORT || 3456;
70
+ const payload = JSON.stringify({
71
+ ...data,
72
+ timestamp: new Date().toISOString()
73
+ });
74
+
75
+ const req = http.request({
76
+ hostname: 'localhost',
77
+ port: DASHBOARD_PORT,
78
+ path: '/api/hook',
79
+ method: 'POST',
80
+ headers: {
81
+ 'Content-Type': 'application/json',
82
+ 'Content-Length': Buffer.byteLength(payload)
83
+ }
84
+ });
85
+
86
+ // Fire and forget - log errors only in debug mode
87
+ req.on('error', (err) => {
88
+ if (process.env.DEBUG) console.error('[Dashboard] Notification failed:', err.message);
89
+ });
90
+ req.write(payload);
91
+ req.end();
92
+ }
93
+
94
+ /**
95
+ * List sessions
96
+ * @param {Object} options - CLI options
97
+ */
98
+ async function listAction(options: ListOptions): Promise<void> {
99
+ const params = {
100
+ operation: 'list',
101
+ location: options.location || 'both',
102
+ include_metadata: options.metadata !== false
103
+ };
104
+
105
+ const result = await executeTool('session_manager', params);
106
+
107
+ if (!result.success) {
108
+ console.error(chalk.red(`Error: ${result.error}`));
109
+ process.exit(1);
110
+ }
111
+
112
+ const { active = [], archived = [], total } = (result.result as any);
113
+
114
+ console.log(chalk.bold.cyan('\nWorkflow Sessions\n'));
115
+
116
+ if (active.length > 0) {
117
+ console.log(chalk.bold.white('Active Sessions:'));
118
+ for (const session of active) {
119
+ const meta = session.metadata || {};
120
+ console.log(chalk.green(` [ACTIVE] ${session.session_id}`));
121
+ if (meta.description) console.log(chalk.gray(` ${meta.description}`));
122
+ if (meta.status) console.log(chalk.gray(` Status: ${meta.status}`));
123
+ }
124
+ console.log();
125
+ }
126
+
127
+ if (archived.length > 0) {
128
+ console.log(chalk.bold.white('Archived Sessions:'));
129
+ for (const session of archived) {
130
+ const meta = session.metadata || {};
131
+ console.log(chalk.blue(` [ARCHIVED] ${session.session_id}`));
132
+ if (meta.description) console.log(chalk.gray(` ${meta.description}`));
133
+ }
134
+ console.log();
135
+ }
136
+
137
+ if (total === 0) {
138
+ console.log(chalk.yellow('No sessions found'));
139
+ } else {
140
+ console.log(chalk.gray(`Total: ${total} session(s)`));
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Initialize a new session
146
+ * @param {string} sessionId - Session ID
147
+ * @param {Object} options - CLI options
148
+ */
149
+ async function initAction(sessionId: string | undefined, options: InitOptions): Promise<void> {
150
+ if (!sessionId) {
151
+ console.error(chalk.red('Session ID is required'));
152
+ console.error(chalk.gray('Usage: ccw session init <session_id> [--location <location>] [--type <type>] [--content <json>]'));
153
+ process.exit(1);
154
+ }
155
+
156
+ // Auto-infer location from type if not explicitly provided
157
+ // When type is 'lite-plan' or 'lite-fix', default location should match the type
158
+ const sessionLocation = options.location ||
159
+ (options.type === 'lite-plan' ? 'lite-plan' :
160
+ options.type === 'lite-fix' ? 'lite-fix' :
161
+ 'active');
162
+
163
+ // Infer type from location if not explicitly provided
164
+ const sessionType = options.type || (sessionLocation === 'active' ? 'workflow' : sessionLocation);
165
+
166
+ // Parse custom metadata from --content if provided
167
+ let customMetadata: any = {};
168
+ if (options.content) {
169
+ try {
170
+ customMetadata = JSON.parse(options.content);
171
+ } catch (e) {
172
+ const error = e as Error;
173
+ console.error(chalk.red('Invalid JSON in --content parameter'));
174
+ console.error(chalk.gray(`Parse error: ${error.message}`));
175
+ process.exit(1);
176
+ }
177
+ }
178
+
179
+ // Filter custom metadata: only allow safe fields, block system-critical fields
180
+ const blockedFields = ['session_id', 'type', 'status', 'created_at', 'updated_at', 'archived_at'];
181
+ const filteredCustomMetadata: any = {};
182
+ for (const key in customMetadata) {
183
+ if (!blockedFields.includes(key)) {
184
+ filteredCustomMetadata[key] = customMetadata[key];
185
+ } else {
186
+ console.warn(chalk.yellow(`⚠ WARNING: Field '${key}' in --content is reserved and will be ignored`));
187
+ }
188
+ }
189
+
190
+ // Merge metadata: defaults < custom (filtered) < required fields
191
+ const metadata: any = Object.assign(
192
+ {
193
+ session_id: sessionId,
194
+ type: sessionType,
195
+ status: 'planning',
196
+ created_at: new Date().toISOString()
197
+ },
198
+ filteredCustomMetadata, // User custom fields (filtered)
199
+ {
200
+ session_id: sessionId, // Force override - always use CLI param
201
+ type: sessionType // Force override - always use --type or default
202
+ }
203
+ );
204
+
205
+ const params: any = {
206
+ operation: 'init',
207
+ session_id: sessionId,
208
+ metadata: metadata,
209
+ location: sessionLocation // Always pass location to session_manager
210
+ };
211
+
212
+ const result = await executeTool('session_manager', params);
213
+
214
+ if (!result.success) {
215
+ console.error(chalk.red(`Error: ${result.error}`));
216
+ process.exit(1);
217
+ }
218
+
219
+ // Emit SESSION_CREATED event
220
+ notifyDashboard({
221
+ type: 'SESSION_CREATED',
222
+ sessionId: sessionId,
223
+ payload: result.result
224
+ });
225
+
226
+ // Lite sessions (lite-plan, lite-fix) use session-metadata.json, others use workflow-session.json
227
+ const metadataFile = sessionLocation.startsWith('lite-') ? 'session-metadata.json' : 'workflow-session.json';
228
+
229
+ console.log(chalk.green(`✓ Session "${sessionId}" initialized`));
230
+ console.log(chalk.gray(` Location: ${(result.result as any).path}`));
231
+ console.log(chalk.gray(` Metadata: ${metadataFile} created`));
232
+ }
233
+
234
+ /**
235
+ * Get session information (location and path)
236
+ * Helper function for path resolution
237
+ */
238
+ async function getSessionInfo(sessionId: string): Promise<{ path: string; location: 'active' | 'archived' | 'lite-plan' | 'lite-fix' }> {
239
+ // Use session_manager to find the session
240
+ const findParams = {
241
+ operation: 'list',
242
+ location: 'all',
243
+ include_metadata: false
244
+ };
245
+
246
+ const result = await executeTool('session_manager', findParams);
247
+
248
+ if (!result.success) {
249
+ throw new Error(`Failed to list sessions: ${result.error}`);
250
+ }
251
+
252
+ const resultData = result.result as any;
253
+ const allSessions = [
254
+ ...(resultData.active || []).map((s: any) => ({ ...s, location: 'active' as const })),
255
+ ...(resultData.archived || []).map((s: any) => ({ ...s, location: 'archived' as const })),
256
+ ...(resultData.litePlan || []).map((s: any) => ({ ...s, location: 'lite-plan' as const })),
257
+ ...(resultData.liteFix || []).map((s: any) => ({ ...s, location: 'lite-fix' as const })),
258
+ ];
259
+
260
+ const session = allSessions.find((s: any) => s.session_id === sessionId || s.id === sessionId);
261
+
262
+ if (!session) {
263
+ throw new Error(`Session "${sessionId}" not found in active, archived, lite-plan, or lite-fix locations`);
264
+ }
265
+
266
+ // Return actual session path from the session object
267
+ return {
268
+ path: session.path || '',
269
+ location: session.location
270
+ };
271
+ }
272
+
273
+ /**
274
+ * Read session content (NEW - with path resolution)
275
+ * @param {string} sessionId - Session ID
276
+ * @param {string} filename - Filename or relative path
277
+ * @param {Object} options - CLI options
278
+ */
279
+ async function readAction(
280
+ sessionId: string | undefined,
281
+ filename: string | undefined,
282
+ options: ReadOptions
283
+ ): Promise<void> {
284
+ if (!sessionId) {
285
+ console.error(chalk.red('Session ID is required'));
286
+ console.error(chalk.gray('Usage: ccw session <session-id> read <filename|path>'));
287
+ process.exit(1);
288
+ }
289
+
290
+ // Backward compatibility: if --type is provided, use legacy implementation
291
+ if (options.type) {
292
+ console.warn(chalk.yellow('⚠ WARNING: --type parameter is deprecated'));
293
+ console.warn(chalk.gray(' Old: ccw session read WFS-001 --type task --task-id IMPL-001'));
294
+ console.warn(chalk.gray(' New: ccw session WFS-001 read IMPL-001.json'));
295
+ console.log();
296
+ return readActionLegacy(sessionId, options);
297
+ }
298
+
299
+ if (!filename) {
300
+ console.error(chalk.red('Filename is required'));
301
+ console.error(chalk.gray('Usage: ccw session <session-id> read <filename|path>'));
302
+ console.error(chalk.gray(''));
303
+ console.error(chalk.gray('Examples:'));
304
+ console.error(chalk.gray(' ccw session WFS-001 read IMPL-001.json'));
305
+ console.error(chalk.gray(' ccw session WFS-001 read IMPL_PLAN.md'));
306
+ console.error(chalk.gray(' ccw session WFS-001 read .task/IMPL-001.json'));
307
+ process.exit(1);
308
+ }
309
+
310
+ try {
311
+ // Get session context
312
+ const session = await getSessionInfo(sessionId);
313
+ const context: ResolverContext = {
314
+ sessionPath: session.path,
315
+ sessionLocation: session.location
316
+ };
317
+
318
+ // Resolve filename to content_type
319
+ const resolved = resolveFilePath(filename, context);
320
+
321
+ // Call session_manager tool
322
+ const params: any = {
323
+ operation: 'read',
324
+ session_id: sessionId,
325
+ content_type: resolved.contentType,
326
+ };
327
+
328
+ if (resolved.pathParams) {
329
+ params.path_params = resolved.pathParams;
330
+ }
331
+
332
+ const result = await executeTool('session_manager', params);
333
+
334
+ if (!result.success) {
335
+ console.error(chalk.red(`Error: ${result.error}`));
336
+ process.exit(1);
337
+ }
338
+
339
+ // Output raw content for piping
340
+ if (options.raw) {
341
+ console.log(typeof (result.result as any).content === 'string'
342
+ ? (result.result as any).content
343
+ : JSON.stringify((result.result as any).content, null, 2));
344
+ } else {
345
+ console.log(JSON.stringify(result, null, 2));
346
+ }
347
+ } catch (error: any) {
348
+ if (error instanceof PathResolutionError) {
349
+ console.error(chalk.red(`Error: ${error.message}`));
350
+ if (error.suggestions.length > 0) {
351
+ console.log(chalk.yellow('\nSuggestions:'));
352
+ error.suggestions.forEach(s => console.log(chalk.gray(` ${s}`)));
353
+ }
354
+ process.exit(1);
355
+ }
356
+ throw error;
357
+ }
358
+ }
359
+
360
+ /**
361
+ * Read session content (LEGACY - with --type parameter)
362
+ * @param {string} sessionId - Session ID
363
+ * @param {Object} options - CLI options
364
+ */
365
+ async function readActionLegacy(sessionId: string | undefined, options: ReadOptions): Promise<void> {
366
+ if (!sessionId) {
367
+ console.error(chalk.red('Session ID is required'));
368
+ console.error(chalk.gray('Usage: ccw session read <session_id> --type <content_type>'));
369
+ process.exit(1);
370
+ }
371
+
372
+ const params: any = {
373
+ operation: 'read',
374
+ session_id: sessionId,
375
+ content_type: options.type || 'session'
376
+ };
377
+
378
+ // Add path_params if provided
379
+ if (options.taskId) params.path_params = { ...(params.path_params || {}), task_id: options.taskId };
380
+ if (options.filename) params.path_params = { ...(params.path_params || {}), filename: options.filename };
381
+ if (options.dimension) params.path_params = { ...(params.path_params || {}), dimension: options.dimension };
382
+ if (options.iteration) params.path_params = { ...(params.path_params || {}), iteration: options.iteration };
383
+
384
+ const result = await executeTool('session_manager', params);
385
+
386
+ if (!result.success) {
387
+ console.error(chalk.red(`Error: ${result.error}`));
388
+ process.exit(1);
389
+ }
390
+
391
+ // Output raw content for piping
392
+ if (options.raw) {
393
+ console.log(typeof (result.result as any).content === 'string'
394
+ ? (result.result as any).content
395
+ : JSON.stringify((result.result as any).content, null, 2));
396
+ } else {
397
+ console.log(JSON.stringify(result, null, 2));
398
+ }
399
+ }
400
+
401
+ /**
402
+ * Write session content (NEW - with path resolution)
403
+ * @param {string} sessionId - Session ID
404
+ * @param {string} filename - Filename or relative path
405
+ * @param {string} contentString - Content to write
406
+ * @param {Object} options - CLI options
407
+ */
408
+ async function writeAction(
409
+ sessionId: string | undefined,
410
+ filename: string | undefined,
411
+ contentString: string | undefined,
412
+ options: WriteOptions
413
+ ): Promise<void> {
414
+ if (!sessionId) {
415
+ console.error(chalk.red('Session ID is required'));
416
+ console.error(chalk.gray('Usage: ccw session <session-id> write <filename|path> <content>'));
417
+ process.exit(1);
418
+ }
419
+
420
+ // Backward compatibility: if --type is provided, use legacy implementation
421
+ if (options.type) {
422
+ console.warn(chalk.yellow('⚠ WARNING: --type parameter is deprecated'));
423
+ console.warn(chalk.gray(' Old: ccw session write WFS-001 --type plan --content "# Plan"'));
424
+ console.warn(chalk.gray(' New: ccw session WFS-001 write IMPL_PLAN.md "# Plan"'));
425
+ console.log();
426
+ return writeActionLegacy(sessionId, options);
427
+ }
428
+
429
+ if (!filename || !contentString) {
430
+ console.error(chalk.red('Filename and content are required'));
431
+ console.error(chalk.gray('Usage: ccw session <session-id> write <filename|path> <content>'));
432
+ console.error(chalk.gray(''));
433
+ console.error(chalk.gray('Examples:'));
434
+ console.error(chalk.gray(' ccw session WFS-001 write IMPL_PLAN.md "# Implementation Plan"'));
435
+ console.error(chalk.gray(' ccw session WFS-001 write IMPL-001.json \'{"id":"IMPL-001","status":"pending"}\''));
436
+ console.error(chalk.gray(' ccw session WFS-001 write .task/IMPL-001.json \'{"status":"completed"}\''));
437
+ process.exit(1);
438
+ }
439
+
440
+ try {
441
+ // Get session context
442
+ const session = await getSessionInfo(sessionId);
443
+ const context: ResolverContext = {
444
+ sessionPath: session.path,
445
+ sessionLocation: session.location
446
+ };
447
+
448
+ // Resolve filename to content_type
449
+ const resolved = resolveFilePath(filename, context);
450
+
451
+ // Parse content (try JSON first, fallback to string)
452
+ let content: any;
453
+ try {
454
+ content = JSON.parse(contentString);
455
+ } catch {
456
+ content = contentString;
457
+ }
458
+
459
+ // Call session_manager tool
460
+ const params: any = {
461
+ operation: 'write',
462
+ session_id: sessionId,
463
+ content_type: resolved.contentType,
464
+ content,
465
+ };
466
+
467
+ if (resolved.pathParams) {
468
+ params.path_params = resolved.pathParams;
469
+ }
470
+
471
+ const result = await executeTool('session_manager', params);
472
+
473
+ if (!result.success) {
474
+ console.error(chalk.red(`Error: ${result.error}`));
475
+ process.exit(1);
476
+ }
477
+
478
+ // Emit granular event based on content_type
479
+ const contentType = resolved.contentType;
480
+ let eventType = 'CONTENT_WRITTEN';
481
+ let entityId = null;
482
+
483
+ switch (contentType) {
484
+ case 'task':
485
+ eventType = 'TASK_CREATED';
486
+ entityId = resolved.pathParams?.task_id || content.task_id;
487
+ break;
488
+ case 'summary':
489
+ eventType = 'SUMMARY_WRITTEN';
490
+ entityId = resolved.pathParams?.task_id;
491
+ break;
492
+ case 'plan':
493
+ eventType = 'PLAN_UPDATED';
494
+ break;
495
+ case 'review-dim':
496
+ eventType = 'REVIEW_UPDATED';
497
+ entityId = resolved.pathParams?.dimension;
498
+ break;
499
+ case 'review-iter':
500
+ eventType = 'REVIEW_UPDATED';
501
+ entityId = resolved.pathParams?.iteration;
502
+ break;
503
+ case 'review-fix':
504
+ eventType = 'REVIEW_UPDATED';
505
+ entityId = resolved.pathParams?.filename;
506
+ break;
507
+ case 'session':
508
+ eventType = 'SESSION_UPDATED';
509
+ break;
510
+ }
511
+
512
+ notifyDashboard({
513
+ type: eventType,
514
+ sessionId: sessionId,
515
+ entityId: entityId,
516
+ contentType: contentType,
517
+ payload: (result.result as any).written_content || content
518
+ });
519
+
520
+ console.log(chalk.green(`✓ Content written to ${resolved.resolvedPath}`));
521
+ } catch (error: any) {
522
+ if (error instanceof PathResolutionError) {
523
+ console.error(chalk.red(`Error: ${error.message}`));
524
+ if (error.suggestions.length > 0) {
525
+ console.log(chalk.yellow('\nSuggestions:'));
526
+ error.suggestions.forEach(s => console.log(chalk.gray(` ${s}`)));
527
+ }
528
+ process.exit(1);
529
+ }
530
+ throw error;
531
+ }
532
+ }
533
+
534
+ /**
535
+ * Write session content (LEGACY - with --type parameter)
536
+ * @param {string} sessionId - Session ID
537
+ * @param {Object} options - CLI options
538
+ */
539
+ async function writeActionLegacy(sessionId: string | undefined, options: WriteOptions): Promise<void> {
540
+ if (!sessionId) {
541
+ console.error(chalk.red('Session ID is required'));
542
+ console.error(chalk.gray('Usage: ccw session write <session_id> --type <content_type> --content <json>'));
543
+ process.exit(1);
544
+ }
545
+
546
+ if (!options.content) {
547
+ console.error(chalk.red('Content is required (--content)'));
548
+ process.exit(1);
549
+ }
550
+
551
+ let content: any;
552
+ try {
553
+ content = JSON.parse(options.content);
554
+ } catch {
555
+ // If not JSON, treat as string content
556
+ content = options.content;
557
+ }
558
+
559
+ const params: any = {
560
+ operation: 'write',
561
+ session_id: sessionId,
562
+ content_type: options.type || 'session',
563
+ content
564
+ };
565
+
566
+ // Add path_params if provided
567
+ if (options.taskId) params.path_params = { ...(params.path_params || {}), task_id: options.taskId };
568
+ if (options.filename) params.path_params = { ...(params.path_params || {}), filename: options.filename };
569
+
570
+ const result = await executeTool('session_manager', params);
571
+
572
+ if (!result.success) {
573
+ console.error(chalk.red(`Error: ${result.error}`));
574
+ process.exit(1);
575
+ }
576
+
577
+ // Emit granular event based on content_type
578
+ const contentType = params.content_type;
579
+ let eventType = 'CONTENT_WRITTEN';
580
+ let entityId = null;
581
+
582
+ switch (contentType) {
583
+ case 'task':
584
+ eventType = 'TASK_CREATED';
585
+ entityId = options.taskId || content.task_id;
586
+ break;
587
+ case 'summary':
588
+ eventType = 'SUMMARY_WRITTEN';
589
+ entityId = options.taskId;
590
+ break;
591
+ case 'plan':
592
+ eventType = 'PLAN_UPDATED';
593
+ break;
594
+ case 'review-dim':
595
+ eventType = 'REVIEW_UPDATED';
596
+ entityId = options.dimension;
597
+ break;
598
+ case 'review-iter':
599
+ eventType = 'REVIEW_UPDATED';
600
+ entityId = options.iteration;
601
+ break;
602
+ case 'review-fix':
603
+ eventType = 'REVIEW_UPDATED';
604
+ entityId = options.filename;
605
+ break;
606
+ case 'session':
607
+ eventType = 'SESSION_UPDATED';
608
+ break;
609
+ }
610
+
611
+ notifyDashboard({
612
+ type: eventType,
613
+ sessionId: sessionId,
614
+ entityId: entityId,
615
+ contentType: contentType,
616
+ payload: (result.result as any).written_content || content
617
+ });
618
+
619
+ console.log(chalk.green(`✓ Content written to ${(result.result as any).path}`));
620
+ }
621
+
622
+ /**
623
+ * Update session content (merge)
624
+ * @param {string} sessionId - Session ID
625
+ * @param {Object} options - CLI options
626
+ */
627
+ async function updateAction(sessionId: string | undefined, options: UpdateOptions): Promise<void> {
628
+ if (!sessionId) {
629
+ console.error(chalk.red('Session ID is required'));
630
+ console.error(chalk.gray('Usage: ccw session update <session_id> --content <json>'));
631
+ process.exit(1);
632
+ }
633
+
634
+ if (!options.content) {
635
+ console.error(chalk.red('Content is required (--content)'));
636
+ process.exit(1);
637
+ }
638
+
639
+ let content: any;
640
+ try {
641
+ content = JSON.parse(options.content);
642
+ } catch (e) {
643
+ const error = e as Error;
644
+ console.error(chalk.red('Content must be valid JSON for update operation'));
645
+ console.error(chalk.gray(`Parse error: ${error.message}`));
646
+ process.exit(1);
647
+ }
648
+
649
+ const params: any = {
650
+ operation: 'update',
651
+ session_id: sessionId,
652
+ content_type: options.type || 'session',
653
+ content
654
+ };
655
+
656
+ // Add path_params if task update
657
+ if (options.taskId) params.path_params = { task_id: options.taskId };
658
+
659
+ const result = await executeTool('session_manager', params);
660
+
661
+ if (!result.success) {
662
+ console.error(chalk.red(`Error: ${result.error}`));
663
+ process.exit(1);
664
+ }
665
+
666
+ // Emit granular event based on content_type
667
+ const eventType = params.content_type === 'task' ? 'TASK_UPDATED' : 'SESSION_UPDATED';
668
+ notifyDashboard({
669
+ type: eventType,
670
+ sessionId: sessionId,
671
+ entityId: options.taskId || null,
672
+ payload: (result.result as any).merged_data || content
673
+ });
674
+
675
+ console.log(chalk.green(`✓ Session "${sessionId}" updated`));
676
+ }
677
+
678
+ /**
679
+ * Archive a session
680
+ * @param {string} sessionId - Session ID
681
+ * @param {Object} options - CLI options
682
+ */
683
+ async function archiveAction(sessionId: string | undefined, options: ArchiveOptions): Promise<void> {
684
+ if (!sessionId) {
685
+ console.error(chalk.red('Session ID is required'));
686
+ console.error(chalk.gray('Usage: ccw session archive <session_id>'));
687
+ process.exit(1);
688
+ }
689
+
690
+ const params = {
691
+ operation: 'archive',
692
+ session_id: sessionId,
693
+ update_status: options.updateStatus !== false
694
+ };
695
+
696
+ const result = await executeTool('session_manager', params);
697
+
698
+ if (!result.success) {
699
+ console.error(chalk.red(`Error: ${result.error}`));
700
+ process.exit(1);
701
+ }
702
+
703
+ // Emit SESSION_ARCHIVED event
704
+ notifyDashboard({
705
+ type: 'SESSION_ARCHIVED',
706
+ sessionId: sessionId,
707
+ payload: result.result
708
+ });
709
+
710
+ console.log(chalk.green(`✓ Session "${sessionId}" archived`));
711
+ console.log(chalk.gray(` Location: ${(result.result as any).destination}`));
712
+ }
713
+
714
+ /**
715
+ * Update session status (shortcut)
716
+ * @param {string} sessionId - Session ID
717
+ * @param {string} newStatus - New status value
718
+ */
719
+ async function statusAction(sessionId: string | undefined, newStatus: string | undefined): Promise<void> {
720
+ if (!sessionId) {
721
+ console.error(chalk.red('Session ID is required'));
722
+ console.error(chalk.gray('Usage: ccw session status <session_id> <status>'));
723
+ process.exit(1);
724
+ }
725
+
726
+ if (!newStatus) {
727
+ console.error(chalk.red('Status is required'));
728
+ console.error(chalk.gray('Valid statuses: planning, active, implementing, reviewing, completed, paused'));
729
+ process.exit(1);
730
+ }
731
+
732
+ const validStatuses = ['planning', 'active', 'implementing', 'reviewing', 'completed', 'paused'];
733
+ if (!validStatuses.includes(newStatus)) {
734
+ console.error(chalk.red(`Invalid status: ${newStatus}`));
735
+ console.error(chalk.gray(`Valid statuses: ${validStatuses.join(', ')}`));
736
+ process.exit(1);
737
+ }
738
+
739
+ const params = {
740
+ operation: 'update',
741
+ session_id: sessionId,
742
+ content_type: 'session',
743
+ content: { status: newStatus, updated_at: new Date().toISOString() }
744
+ };
745
+
746
+ const result = await executeTool('session_manager', params);
747
+
748
+ if (!result.success) {
749
+ console.error(chalk.red(`Error: ${result.error}`));
750
+ process.exit(1);
751
+ }
752
+
753
+ // Emit SESSION_UPDATED event
754
+ notifyDashboard({
755
+ type: 'SESSION_UPDATED',
756
+ sessionId: sessionId,
757
+ payload: { status: newStatus }
758
+ });
759
+
760
+ console.log(chalk.green(`✓ Session "${sessionId}" status → ${newStatus}`));
761
+ }
762
+
763
+ /**
764
+ * Update task status (shortcut)
765
+ * @param {string} sessionId - Session ID
766
+ * @param {string} taskId - Task ID
767
+ * @param {string} newStatus - New status value
768
+ */
769
+ async function taskAction(
770
+ sessionId: string | undefined,
771
+ taskId: string | undefined,
772
+ newStatus: string | undefined
773
+ ): Promise<void> {
774
+ if (!sessionId) {
775
+ console.error(chalk.red('Session ID is required'));
776
+ console.error(chalk.gray('Usage: ccw session task <session_id> <task_id> <status>'));
777
+ process.exit(1);
778
+ }
779
+
780
+ if (!taskId) {
781
+ console.error(chalk.red('Task ID is required'));
782
+ console.error(chalk.gray('Usage: ccw session task <session_id> <task_id> <status>'));
783
+ process.exit(1);
784
+ }
785
+
786
+ if (!newStatus) {
787
+ console.error(chalk.red('Status is required'));
788
+ console.error(chalk.gray('Valid statuses: pending, in_progress, completed, blocked, cancelled'));
789
+ process.exit(1);
790
+ }
791
+
792
+ const validStatuses = ['pending', 'in_progress', 'completed', 'blocked', 'cancelled'];
793
+ if (!validStatuses.includes(newStatus)) {
794
+ console.error(chalk.red(`Invalid status: ${newStatus}`));
795
+ console.error(chalk.gray(`Valid statuses: ${validStatuses.join(', ')}`));
796
+ process.exit(1);
797
+ }
798
+
799
+ // First, read the current task to get existing status
800
+ const readParams = {
801
+ operation: 'read',
802
+ session_id: sessionId,
803
+ content_type: 'task',
804
+ path_params: { task_id: taskId }
805
+ };
806
+
807
+ const readResult = await executeTool('session_manager', readParams);
808
+
809
+ let currentTask: any = {};
810
+ let oldStatus = 'unknown';
811
+
812
+ if (readResult.success) {
813
+ currentTask = (readResult.result as any).content || {};
814
+ oldStatus = currentTask.status || 'unknown';
815
+ }
816
+
817
+ // Build status history entry
818
+ const historyEntry = {
819
+ from: oldStatus,
820
+ to: newStatus,
821
+ changed_at: new Date().toISOString()
822
+ };
823
+
824
+ // Update task with new status and appended history
825
+ const params = {
826
+ operation: 'update',
827
+ session_id: sessionId,
828
+ content_type: 'task',
829
+ path_params: { task_id: taskId },
830
+ content: {
831
+ status: newStatus,
832
+ updated_at: new Date().toISOString(),
833
+ status_history: [...(currentTask.status_history || []), historyEntry]
834
+ }
835
+ };
836
+
837
+ const result = await executeTool('session_manager', params);
838
+
839
+ if (!result.success) {
840
+ console.error(chalk.red(`Error: ${result.error}`));
841
+ process.exit(1);
842
+ }
843
+
844
+ // Emit TASK_UPDATED event
845
+ notifyDashboard({
846
+ type: 'TASK_UPDATED',
847
+ sessionId: sessionId,
848
+ entityId: taskId,
849
+ payload: { status: newStatus }
850
+ });
851
+
852
+ console.log(chalk.green(`✓ Task "${taskId}" status → ${newStatus}`));
853
+ }
854
+
855
+ /**
856
+ * Create directory within session
857
+ * @param {string} sessionId - Session ID
858
+ * @param {Object} options - CLI options
859
+ */
860
+ async function mkdirAction(sessionId: string | undefined, options: MkdirOptions): Promise<void> {
861
+ if (!sessionId) {
862
+ console.error(chalk.red('Session ID is required'));
863
+ console.error(chalk.gray('Usage: ccw session mkdir <session_id> --subdir <subdir>'));
864
+ process.exit(1);
865
+ }
866
+
867
+ if (!options.subdir) {
868
+ console.error(chalk.red('Subdirectory is required (--subdir)'));
869
+ process.exit(1);
870
+ }
871
+
872
+ const params = {
873
+ operation: 'mkdir',
874
+ session_id: sessionId,
875
+ dirs: [options.subdir] // Convert single subdir to array
876
+ };
877
+
878
+ const result = await executeTool('session_manager', params);
879
+
880
+ if (!result.success) {
881
+ console.error(chalk.red(`Error: ${result.error}`));
882
+ process.exit(1);
883
+ }
884
+
885
+ // Emit DIRECTORY_CREATED event
886
+ notifyDashboard({
887
+ type: 'DIRECTORY_CREATED',
888
+ sessionId: sessionId,
889
+ payload: { directories: (result.result as any).directories_created }
890
+ });
891
+
892
+ console.log(chalk.green(`✓ Directory created: ${(result.result as any).directories_created.join(', ')}`));
893
+ }
894
+
895
+ /**
896
+ * Delete file within session
897
+ * @param {string} sessionId - Session ID
898
+ * @param {string} filePath - Relative file path
899
+ */
900
+ async function deleteAction(sessionId: string | undefined, filePath: string | undefined): Promise<void> {
901
+ if (!sessionId) {
902
+ console.error(chalk.red('Session ID is required'));
903
+ console.error(chalk.gray('Usage: ccw session delete <session_id> <file_path>'));
904
+ process.exit(1);
905
+ }
906
+
907
+ if (!filePath) {
908
+ console.error(chalk.red('File path is required'));
909
+ console.error(chalk.gray('Usage: ccw session delete <session_id> <file_path>'));
910
+ process.exit(1);
911
+ }
912
+
913
+ const params = {
914
+ operation: 'delete',
915
+ session_id: sessionId,
916
+ file_path: filePath
917
+ };
918
+
919
+ const result = await executeTool('session_manager', params);
920
+
921
+ if (!result.success) {
922
+ console.error(chalk.red(`Error: ${result.error}`));
923
+ process.exit(1);
924
+ }
925
+
926
+ // Emit FILE_DELETED event
927
+ notifyDashboard({
928
+ type: 'FILE_DELETED',
929
+ sessionId: sessionId,
930
+ payload: { file_path: filePath }
931
+ });
932
+
933
+ console.log(chalk.green(`✓ File deleted: ${(result.result as any).deleted}`));
934
+ }
935
+
936
+ /**
937
+ * Get session statistics
938
+ * @param {string} sessionId - Session ID
939
+ */
940
+ async function statsAction(sessionId: string | undefined, options: StatsOptions = {}): Promise<void> {
941
+ if (!sessionId) {
942
+ console.error(chalk.red('Session ID is required'));
943
+ console.error(chalk.gray('Usage: ccw session stats <session_id>'));
944
+ process.exit(1);
945
+ }
946
+
947
+ const params = {
948
+ operation: 'stats',
949
+ session_id: sessionId
950
+ };
951
+
952
+ const result = await executeTool('session_manager', params);
953
+
954
+ if (!result.success) {
955
+ console.error(chalk.red(`Error: ${result.error}`));
956
+ process.exit(1);
957
+ }
958
+
959
+ const { tasks, summaries, has_plan, location } = (result.result as any);
960
+
961
+ console.log(chalk.bold.cyan(`\nSession Statistics: ${sessionId}`));
962
+ console.log(chalk.gray(`Location: ${location}\n`));
963
+
964
+ console.log(chalk.bold.white('Tasks:'));
965
+ console.log(chalk.gray(` Total: ${tasks.total}`));
966
+ console.log(chalk.green(` Completed: ${tasks.completed}`));
967
+ console.log(chalk.yellow(` In Progress: ${tasks.in_progress}`));
968
+ console.log(chalk.blue(` Pending: ${tasks.pending}`));
969
+ console.log(chalk.red(` Blocked: ${tasks.blocked}`));
970
+ console.log(chalk.gray(` Cancelled: ${tasks.cancelled}\n`));
971
+
972
+ console.log(chalk.bold.white('Documentation:'));
973
+ console.log(chalk.gray(` Summaries: ${summaries}`));
974
+ console.log(chalk.gray(` Plan: ${has_plan ? 'Yes' : 'No'}`));
975
+ }
976
+
977
+ async function execAction(jsonParams: string | undefined): Promise<void> {
978
+ if (!jsonParams) {
979
+ console.error(chalk.red('JSON parameters required'));
980
+ console.error(chalk.gray('Usage: ccw session exec \'{"operation":"list","location":"active"}\''));
981
+ process.exit(1);
982
+ }
983
+
984
+ let params: any;
985
+ try {
986
+ params = JSON.parse(jsonParams);
987
+ } catch (e) {
988
+ const error = e as Error;
989
+ console.error(chalk.red('Invalid JSON'));
990
+ console.error(chalk.gray(`Parse error: ${error.message}`));
991
+ process.exit(1);
992
+ }
993
+
994
+ const result = await executeTool('session_manager', params);
995
+
996
+ // Emit notification for write operations
997
+ if (result.success && params.operation) {
998
+ const writeOps = ['init', 'write', 'update', 'archive', 'mkdir', 'delete'];
999
+ if (writeOps.includes(params.operation)) {
1000
+ const eventMap: Record<string, string> = {
1001
+ init: 'SESSION_CREATED',
1002
+ write: 'CONTENT_WRITTEN',
1003
+ update: 'SESSION_UPDATED',
1004
+ archive: 'SESSION_ARCHIVED',
1005
+ mkdir: 'DIRECTORY_CREATED',
1006
+ delete: 'FILE_DELETED'
1007
+ };
1008
+ notifyDashboard({
1009
+ type: eventMap[params.operation] || 'SESSION_UPDATED',
1010
+ sessionId: params.session_id,
1011
+ operation: params.operation,
1012
+ payload: result.result
1013
+ });
1014
+ }
1015
+ }
1016
+
1017
+ console.log(JSON.stringify(result, null, 2));
1018
+ }
1019
+
1020
+ /**
1021
+ * Session command entry point
1022
+ * @param {string} subcommand - Subcommand
1023
+ * @param {string[]} args - Arguments
1024
+ * @param {Object} options - CLI options
1025
+ */
1026
+ export async function sessionCommand(
1027
+ subcommand: string,
1028
+ args: string | string[],
1029
+ options: any
1030
+ ): Promise<void> {
1031
+ let argsArray = Array.isArray(args) ? args : (args ? [args] : []);
1032
+
1033
+ // Detect new format: ccw session WFS-xxx <operation> <args>
1034
+ // If subcommand looks like a session ID, rearrange parameters
1035
+ // Exception: 'init' should always use traditional format (ccw session init WFS-xxx)
1036
+ const isSessionId = subcommand && (
1037
+ subcommand.startsWith('WFS-') ||
1038
+ subcommand === 'manifest' ||
1039
+ subcommand === 'project' ||
1040
+ /^[A-Z][A-Z0-9]*-[A-Z0-9]+/.test(subcommand) // Generic session ID pattern (uppercase prefix + dash + alphanumeric)
1041
+ );
1042
+
1043
+ if (isSessionId && argsArray.length > 0) {
1044
+ const operation = argsArray[0];
1045
+
1046
+ // Reject new format for init operation (semantic error)
1047
+ if (operation === 'init') {
1048
+ console.error(chalk.red('Error: Invalid format for init operation'));
1049
+ console.error(chalk.gray('Correct: ccw session init <session-id>'));
1050
+ console.error(chalk.gray(`Wrong: ccw session <session-id> init`));
1051
+ console.error(chalk.yellow('\nReason: Session must be initialized before it can be referenced'));
1052
+ process.exit(1);
1053
+ }
1054
+
1055
+ // New format detected: session-id comes first
1056
+ const sessionId = subcommand;
1057
+ const operationArgs = argsArray.slice(1);
1058
+
1059
+ // Rearrange: operation becomes subcommand, session-id goes into args
1060
+ subcommand = operation;
1061
+ argsArray = [sessionId, ...operationArgs];
1062
+ }
1063
+
1064
+ switch (subcommand) {
1065
+ case 'list':
1066
+ await listAction(options);
1067
+ break;
1068
+ case 'init':
1069
+ await initAction(argsArray[0], options);
1070
+ break;
1071
+ case 'read':
1072
+ // args[0] = session-id, args[1] = filename (optional for backward compat)
1073
+ await readAction(argsArray[0], argsArray[1], options);
1074
+ break;
1075
+ case 'write':
1076
+ // args[0] = session-id, args[1] = filename, args[2] = content
1077
+ await writeAction(argsArray[0], argsArray[1], argsArray[2], options);
1078
+ break;
1079
+ case 'update':
1080
+ await updateAction(argsArray[0], options);
1081
+ break;
1082
+ case 'archive':
1083
+ await archiveAction(argsArray[0], options);
1084
+ break;
1085
+ case 'status':
1086
+ await statusAction(argsArray[0], argsArray[1]);
1087
+ break;
1088
+ case 'task':
1089
+ await taskAction(argsArray[0], argsArray[1], argsArray[2]);
1090
+ break;
1091
+ case 'mkdir':
1092
+ await mkdirAction(argsArray[0], options);
1093
+ break;
1094
+ case 'delete':
1095
+ await deleteAction(argsArray[0], argsArray[1]);
1096
+ break;
1097
+ case 'stats':
1098
+ await statsAction(argsArray[0], options);
1099
+ break;
1100
+ case 'exec':
1101
+ await execAction(argsArray[0]);
1102
+ break;
1103
+ default:
1104
+ console.log(chalk.bold.cyan('\nCCW Session Management\n'));
1105
+ console.log('Subcommands:');
1106
+ console.log(chalk.gray(' list List all sessions'));
1107
+ console.log(chalk.gray(' <session-id> init [metadata] Initialize new session'));
1108
+ console.log(chalk.gray(' <session-id> read <filename|path> Read session content'));
1109
+ console.log(chalk.gray(' <session-id> write <filename> <content> Write session content'));
1110
+ console.log(chalk.gray(' <session-id> stats Get session statistics'));
1111
+ console.log(chalk.gray(' <session-id> archive Archive session'));
1112
+ console.log(chalk.gray(' <session-id> status <status> Update session status'));
1113
+ console.log(chalk.gray(' <session-id> task <task-id> <status> Update task status'));
1114
+ console.log(chalk.gray(' <session-id> delete <file-path> Delete file within session'));
1115
+ console.log(chalk.gray(' <session-id> update Update session (merge)'));
1116
+ console.log(chalk.gray(' <session-id> mkdir Create subdirectory'));
1117
+ console.log(chalk.gray(' exec <json> Execute raw operation'));
1118
+ console.log();
1119
+ console.log('Filename/Path Examples:');
1120
+ console.log(chalk.gray(' IMPL-001.json Task file (auto: .task/)'));
1121
+ console.log(chalk.gray(' .task/IMPL-001.json Task file (explicit path)'));
1122
+ console.log(chalk.gray(' IMPL_PLAN.md Implementation plan'));
1123
+ console.log(chalk.gray(' TODO_LIST.md TODO list'));
1124
+ console.log(chalk.gray(' workflow-session.json Session metadata'));
1125
+ console.log(chalk.gray(' .review/dimensions/security.json Review dimension'));
1126
+ console.log();
1127
+ console.log('Status Values:');
1128
+ console.log(chalk.gray(' Session: planning, active, implementing, reviewing, completed, paused'));
1129
+ console.log(chalk.gray(' Task: pending, in_progress, completed, blocked, cancelled'));
1130
+ console.log();
1131
+ console.log('Examples:');
1132
+ console.log(chalk.gray(' ccw session list'));
1133
+ console.log(chalk.gray(' ccw session WFS-001 init'));
1134
+ console.log(chalk.gray(' ccw session WFS-001 read IMPL_PLAN.md'));
1135
+ console.log(chalk.gray(' ccw session WFS-001 read IMPL-001.json'));
1136
+ console.log(chalk.gray(' ccw session WFS-001 write IMPL_PLAN.md "# Plan"'));
1137
+ console.log(chalk.gray(' ccw session WFS-001 write IMPL-001.json \'{"status":"pending"}\''));
1138
+ console.log(chalk.gray(' ccw session WFS-001 stats'));
1139
+ console.log(chalk.gray(' ccw session WFS-001 archive'));
1140
+ }
1141
+ }