claude-code-workflow 6.2.5 → 6.2.6

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 (964) hide show
  1. package/.claude/CLAUDE.md +10 -0
  2. package/.claude/agents/action-planning-agent.md +857 -0
  3. package/.claude/agents/cli-execution-agent.md +267 -0
  4. package/.claude/agents/cli-explore-agent.md +182 -0
  5. package/.claude/agents/cli-lite-planning-agent.md +446 -0
  6. package/.claude/agents/cli-planning-agent.md +558 -0
  7. package/.claude/agents/code-developer.md +311 -0
  8. package/.claude/agents/conceptual-planning-agent.md +308 -0
  9. package/.claude/agents/context-search-agent.md +581 -0
  10. package/.claude/agents/doc-generator.md +330 -0
  11. package/.claude/agents/memory-bridge.md +94 -0
  12. package/.claude/agents/test-context-search-agent.md +400 -0
  13. package/.claude/agents/test-fix-agent.md +344 -0
  14. package/.claude/agents/ui-design-agent.md +593 -0
  15. package/.claude/agents/universal-executor.md +131 -0
  16. package/.claude/commands/clean.md +516 -0
  17. package/.claude/commands/cli/cli-init.md +440 -0
  18. package/.claude/commands/enhance-prompt.md +93 -0
  19. package/.claude/commands/memory/code-map-memory.md +687 -0
  20. package/.claude/commands/memory/compact.md +383 -0
  21. package/.claude/commands/memory/docs-full-cli.md +471 -0
  22. package/.claude/commands/memory/docs-related-cli.md +386 -0
  23. package/.claude/commands/memory/docs.md +615 -0
  24. package/.claude/commands/memory/load-skill-memory.md +182 -0
  25. package/.claude/commands/memory/load.md +240 -0
  26. package/.claude/commands/memory/skill-memory.md +525 -0
  27. package/.claude/commands/memory/style-skill-memory.md +396 -0
  28. package/.claude/commands/memory/tech-research-rules.md +310 -0
  29. package/.claude/commands/memory/update-full.md +332 -0
  30. package/.claude/commands/memory/update-related.md +332 -0
  31. package/.claude/commands/memory/workflow-skill-memory.md +517 -0
  32. package/.claude/commands/task/breakdown.md +204 -0
  33. package/.claude/commands/task/create.md +152 -0
  34. package/.claude/commands/task/execute.md +270 -0
  35. package/.claude/commands/task/replan.md +437 -0
  36. package/.claude/commands/version.md +254 -0
  37. package/.claude/commands/workflow/action-plan-verify.md +447 -0
  38. package/.claude/commands/workflow/brainstorm/api-designer.md +587 -0
  39. package/.claude/commands/workflow/brainstorm/artifacts.md +453 -0
  40. package/.claude/commands/workflow/brainstorm/auto-parallel.md +443 -0
  41. package/.claude/commands/workflow/brainstorm/data-architect.md +220 -0
  42. package/.claude/commands/workflow/brainstorm/product-manager.md +200 -0
  43. package/.claude/commands/workflow/brainstorm/product-owner.md +200 -0
  44. package/.claude/commands/workflow/brainstorm/scrum-master.md +200 -0
  45. package/.claude/commands/workflow/brainstorm/subject-matter-expert.md +200 -0
  46. package/.claude/commands/workflow/brainstorm/synthesis.md +398 -0
  47. package/.claude/commands/workflow/brainstorm/system-architect.md +389 -0
  48. package/.claude/commands/workflow/brainstorm/ui-designer.md +221 -0
  49. package/.claude/commands/workflow/brainstorm/ux-expert.md +221 -0
  50. package/.claude/commands/workflow/debug.md +321 -0
  51. package/.claude/commands/workflow/execute.md +475 -0
  52. package/.claude/commands/workflow/init.md +165 -0
  53. package/.claude/commands/workflow/lite-execute.md +792 -0
  54. package/.claude/commands/workflow/lite-fix.md +623 -0
  55. package/.claude/commands/workflow/lite-plan.md +610 -0
  56. package/.claude/commands/workflow/plan.md +551 -0
  57. package/.claude/commands/workflow/replan.md +515 -0
  58. package/.claude/commands/workflow/review-fix.md +606 -0
  59. package/.claude/commands/workflow/review-module-cycle.md +767 -0
  60. package/.claude/commands/workflow/review-session-cycle.md +778 -0
  61. package/.claude/commands/workflow/review.md +297 -0
  62. package/.claude/commands/workflow/session/complete.md +153 -0
  63. package/.claude/commands/workflow/session/list.md +96 -0
  64. package/.claude/commands/workflow/session/resume.md +61 -0
  65. package/.claude/commands/workflow/session/start.md +200 -0
  66. package/.claude/commands/workflow/tdd-plan.md +460 -0
  67. package/.claude/commands/workflow/tdd-verify.md +400 -0
  68. package/.claude/commands/workflow/test-cycle-execute.md +500 -0
  69. package/.claude/commands/workflow/test-fix-gen.md +699 -0
  70. package/.claude/commands/workflow/test-gen.md +529 -0
  71. package/.claude/commands/workflow/tools/conflict-resolution.md +766 -0
  72. package/.claude/commands/workflow/tools/context-gather.md +436 -0
  73. package/.claude/commands/workflow/tools/task-generate-agent.md +490 -0
  74. package/.claude/commands/workflow/tools/task-generate-tdd.md +526 -0
  75. package/.claude/commands/workflow/tools/tdd-coverage-analysis.md +309 -0
  76. package/.claude/commands/workflow/tools/test-concept-enhanced.md +164 -0
  77. package/.claude/commands/workflow/tools/test-context-gather.md +236 -0
  78. package/.claude/commands/workflow/tools/test-task-generate.md +257 -0
  79. package/.claude/commands/workflow/ui-design/animation-extract.md +1150 -0
  80. package/.claude/commands/workflow/ui-design/codify-style.md +652 -0
  81. package/.claude/commands/workflow/ui-design/design-sync.md +454 -0
  82. package/.claude/commands/workflow/ui-design/explore-auto.md +678 -0
  83. package/.claude/commands/workflow/ui-design/generate.md +504 -0
  84. package/.claude/commands/workflow/ui-design/imitate-auto.md +745 -0
  85. package/.claude/commands/workflow/ui-design/import-from-code.md +540 -0
  86. package/.claude/commands/workflow/ui-design/layout-extract.md +788 -0
  87. package/.claude/commands/workflow/ui-design/reference-page-generator.md +356 -0
  88. package/.claude/commands/workflow/ui-design/style-extract.md +773 -0
  89. package/.claude/skills/command-guide/SKILL.md +388 -0
  90. package/.claude/skills/command-guide/UPDATE-GUIDELINE.md +592 -0
  91. package/.claude/skills/command-guide/guides/cli-tools-guide.md +410 -0
  92. package/.claude/skills/command-guide/guides/examples.md +537 -0
  93. package/.claude/skills/command-guide/guides/getting-started.md +242 -0
  94. package/.claude/skills/command-guide/guides/implementation-details.md +1010 -0
  95. package/.claude/skills/command-guide/guides/index-structure.md +326 -0
  96. package/.claude/skills/command-guide/guides/troubleshooting.md +92 -0
  97. package/.claude/skills/command-guide/guides/ui-design-workflow-guide.md +316 -0
  98. package/.claude/skills/command-guide/guides/workflow-patterns.md +662 -0
  99. package/.claude/skills/command-guide/index/all-commands.json +772 -0
  100. package/.claude/skills/command-guide/index/by-category.json +800 -0
  101. package/.claude/skills/command-guide/index/by-use-case.json +786 -0
  102. package/.claude/skills/command-guide/index/command-relationships.json +307 -0
  103. package/.claude/skills/command-guide/index/essential-commands.json +112 -0
  104. package/.claude/skills/command-guide/reference/agents/action-planning-agent.md +857 -0
  105. package/.claude/skills/command-guide/reference/agents/cli-execution-agent.md +267 -0
  106. package/.claude/skills/command-guide/reference/agents/cli-explore-agent.md +182 -0
  107. package/.claude/skills/command-guide/reference/agents/cli-lite-planning-agent.md +446 -0
  108. package/.claude/skills/command-guide/reference/agents/cli-planning-agent.md +558 -0
  109. package/.claude/skills/command-guide/reference/agents/code-developer.md +311 -0
  110. package/.claude/skills/command-guide/reference/agents/conceptual-planning-agent.md +308 -0
  111. package/.claude/skills/command-guide/reference/agents/context-search-agent.md +581 -0
  112. package/.claude/skills/command-guide/reference/agents/doc-generator.md +330 -0
  113. package/.claude/skills/command-guide/reference/agents/memory-bridge.md +94 -0
  114. package/.claude/skills/command-guide/reference/agents/test-context-search-agent.md +400 -0
  115. package/.claude/skills/command-guide/reference/agents/test-fix-agent.md +344 -0
  116. package/.claude/skills/command-guide/reference/agents/ui-design-agent.md +593 -0
  117. package/.claude/skills/command-guide/reference/agents/universal-executor.md +131 -0
  118. package/.claude/skills/command-guide/reference/commands/cli/cli-init.md +440 -0
  119. package/.claude/skills/command-guide/reference/commands/enhance-prompt.md +93 -0
  120. package/.claude/skills/command-guide/reference/commands/memory/code-map-memory.md +687 -0
  121. package/.claude/skills/command-guide/reference/commands/memory/docs-full-cli.md +471 -0
  122. package/.claude/skills/command-guide/reference/commands/memory/docs-related-cli.md +386 -0
  123. package/.claude/skills/command-guide/reference/commands/memory/docs.md +616 -0
  124. package/.claude/skills/command-guide/reference/commands/memory/load-skill-memory.md +182 -0
  125. package/.claude/skills/command-guide/reference/commands/memory/load.md +240 -0
  126. package/.claude/skills/command-guide/reference/commands/memory/skill-memory.md +525 -0
  127. package/.claude/skills/command-guide/reference/commands/memory/style-skill-memory.md +396 -0
  128. package/.claude/skills/command-guide/reference/commands/memory/tech-research.md +314 -0
  129. package/.claude/skills/command-guide/reference/commands/memory/update-full.md +332 -0
  130. package/.claude/skills/command-guide/reference/commands/memory/update-related.md +332 -0
  131. package/.claude/skills/command-guide/reference/commands/memory/workflow-skill-memory.md +517 -0
  132. package/.claude/skills/command-guide/reference/commands/task/breakdown.md +204 -0
  133. package/.claude/skills/command-guide/reference/commands/task/create.md +152 -0
  134. package/.claude/skills/command-guide/reference/commands/task/execute.md +270 -0
  135. package/.claude/skills/command-guide/reference/commands/task/replan.md +437 -0
  136. package/.claude/skills/command-guide/reference/commands/version.md +254 -0
  137. package/.claude/skills/command-guide/reference/commands/workflow/action-plan-verify.md +447 -0
  138. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/api-designer.md +585 -0
  139. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/artifacts.md +452 -0
  140. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/auto-parallel.md +443 -0
  141. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/data-architect.md +220 -0
  142. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/product-manager.md +200 -0
  143. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/product-owner.md +200 -0
  144. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/scrum-master.md +200 -0
  145. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/subject-matter-expert.md +200 -0
  146. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/synthesis.md +398 -0
  147. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/system-architect.md +387 -0
  148. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/ui-designer.md +221 -0
  149. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/ux-expert.md +221 -0
  150. package/.claude/skills/command-guide/reference/commands/workflow/execute.md +465 -0
  151. package/.claude/skills/command-guide/reference/commands/workflow/init.md +164 -0
  152. package/.claude/skills/command-guide/reference/commands/workflow/lite-execute.md +748 -0
  153. package/.claude/skills/command-guide/reference/commands/workflow/lite-fix.md +664 -0
  154. package/.claude/skills/command-guide/reference/commands/workflow/lite-plan.md +645 -0
  155. package/.claude/skills/command-guide/reference/commands/workflow/plan.md +551 -0
  156. package/.claude/skills/command-guide/reference/commands/workflow/replan.md +515 -0
  157. package/.claude/skills/command-guide/reference/commands/workflow/review-fix.md +606 -0
  158. package/.claude/skills/command-guide/reference/commands/workflow/review-module-cycle.md +765 -0
  159. package/.claude/skills/command-guide/reference/commands/workflow/review-session-cycle.md +776 -0
  160. package/.claude/skills/command-guide/reference/commands/workflow/review.md +298 -0
  161. package/.claude/skills/command-guide/reference/commands/workflow/session/complete.md +547 -0
  162. package/.claude/skills/command-guide/reference/commands/workflow/session/list.md +114 -0
  163. package/.claude/skills/command-guide/reference/commands/workflow/session/resume.md +77 -0
  164. package/.claude/skills/command-guide/reference/commands/workflow/session/start.md +257 -0
  165. package/.claude/skills/command-guide/reference/commands/workflow/tdd-plan.md +460 -0
  166. package/.claude/skills/command-guide/reference/commands/workflow/tdd-verify.md +400 -0
  167. package/.claude/skills/command-guide/reference/commands/workflow/test-cycle-execute.md +498 -0
  168. package/.claude/skills/command-guide/reference/commands/workflow/test-fix-gen.md +699 -0
  169. package/.claude/skills/command-guide/reference/commands/workflow/test-gen.md +529 -0
  170. package/.claude/skills/command-guide/reference/commands/workflow/tools/conflict-resolution.md +766 -0
  171. package/.claude/skills/command-guide/reference/commands/workflow/tools/context-gather.md +434 -0
  172. package/.claude/skills/command-guide/reference/commands/workflow/tools/task-generate-agent.md +487 -0
  173. package/.claude/skills/command-guide/reference/commands/workflow/tools/task-generate-tdd.md +525 -0
  174. package/.claude/skills/command-guide/reference/commands/workflow/tools/tdd-coverage-analysis.md +309 -0
  175. package/.claude/skills/command-guide/reference/commands/workflow/tools/test-concept-enhanced.md +163 -0
  176. package/.claude/skills/command-guide/reference/commands/workflow/tools/test-context-gather.md +235 -0
  177. package/.claude/skills/command-guide/reference/commands/workflow/tools/test-task-generate.md +256 -0
  178. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/animation-extract.md +1150 -0
  179. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/codify-style.md +652 -0
  180. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/design-sync.md +454 -0
  181. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/explore-auto.md +678 -0
  182. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/generate.md +504 -0
  183. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/imitate-auto.md +745 -0
  184. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/import-from-code.md +537 -0
  185. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/layout-extract.md +788 -0
  186. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/reference-page-generator.md +356 -0
  187. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/style-extract.md +773 -0
  188. package/.claude/skills/command-guide/scripts/analyze_commands.py +502 -0
  189. package/.claude/skills/command-guide/scripts/update-index.sh +130 -0
  190. package/.claude/skills/command-guide/templates/issue-bug.md +104 -0
  191. package/.claude/skills/command-guide/templates/issue-diagnosis.md +275 -0
  192. package/.claude/skills/command-guide/templates/issue-feature.md +97 -0
  193. package/.claude/skills/command-guide/templates/issue-question.md +141 -0
  194. package/.claude/skills/prompt-enhancer/SKILL.md +124 -0
  195. package/.claude/workflows/_template-compare-matrix.html +692 -0
  196. package/.claude/workflows/chinese-response.md +38 -0
  197. package/.claude/workflows/cli-templates/fix-plan-template.json +75 -0
  198. package/.claude/workflows/cli-templates/fix-progress-template.json +48 -0
  199. package/.claude/workflows/cli-templates/memory/style-skill-memory/skill-md-template.md +299 -0
  200. package/.claude/workflows/cli-templates/planning-roles/data-architect.md +120 -0
  201. package/.claude/workflows/cli-templates/planning-roles/product-manager.md +119 -0
  202. package/.claude/workflows/cli-templates/planning-roles/product-owner.md +261 -0
  203. package/.claude/workflows/cli-templates/planning-roles/scrum-master.md +186 -0
  204. package/.claude/workflows/cli-templates/planning-roles/subject-matter-expert.md +281 -0
  205. package/.claude/workflows/cli-templates/planning-roles/synthesis-role.md +414 -0
  206. package/.claude/workflows/cli-templates/planning-roles/system-architect.md +106 -0
  207. package/.claude/workflows/cli-templates/planning-roles/test-strategist.md +124 -0
  208. package/.claude/workflows/cli-templates/planning-roles/ui-designer.md +379 -0
  209. package/.claude/workflows/cli-templates/planning-roles/ux-expert.md +240 -0
  210. package/.claude/workflows/cli-templates/prompts/analysis/01-diagnose-bug-root-cause.txt +127 -0
  211. package/.claude/workflows/cli-templates/prompts/analysis/01-trace-code-execution.txt +115 -0
  212. package/.claude/workflows/cli-templates/prompts/analysis/02-analyze-code-patterns.txt +37 -0
  213. package/.claude/workflows/cli-templates/prompts/analysis/02-analyze-technical-document.txt +33 -0
  214. package/.claude/workflows/cli-templates/prompts/analysis/02-review-architecture.txt +29 -0
  215. package/.claude/workflows/cli-templates/prompts/analysis/02-review-code-quality.txt +28 -0
  216. package/.claude/workflows/cli-templates/prompts/analysis/03-analyze-performance.txt +29 -0
  217. package/.claude/workflows/cli-templates/prompts/analysis/03-assess-security-risks.txt +29 -0
  218. package/.claude/workflows/cli-templates/prompts/analysis/03-review-quality-standards.txt +29 -0
  219. package/.claude/workflows/cli-templates/prompts/development/02-generate-tests.txt +70 -0
  220. package/.claude/workflows/cli-templates/prompts/development/02-implement-component-ui.txt +55 -0
  221. package/.claude/workflows/cli-templates/prompts/development/02-implement-feature.txt +58 -0
  222. package/.claude/workflows/cli-templates/prompts/development/02-refactor-codebase.txt +55 -0
  223. package/.claude/workflows/cli-templates/prompts/development/03-debug-runtime-issues.txt +55 -0
  224. package/.claude/workflows/cli-templates/prompts/documentation/api.txt +15 -0
  225. package/.claude/workflows/cli-templates/prompts/documentation/folder-navigation.txt +27 -0
  226. package/.claude/workflows/cli-templates/prompts/documentation/module-readme.txt +49 -0
  227. package/.claude/workflows/cli-templates/prompts/documentation/project-architecture.txt +41 -0
  228. package/.claude/workflows/cli-templates/prompts/documentation/project-examples.txt +35 -0
  229. package/.claude/workflows/cli-templates/prompts/documentation/project-readme.txt +35 -0
  230. package/.claude/workflows/cli-templates/prompts/memory/02-document-module-structure.txt +165 -0
  231. package/.claude/workflows/cli-templates/prompts/planning/01-plan-architecture-design.txt +109 -0
  232. package/.claude/workflows/cli-templates/prompts/planning/02-breakdown-task-steps.txt +30 -0
  233. package/.claude/workflows/cli-templates/prompts/planning/02-design-component-spec.txt +28 -0
  234. package/.claude/workflows/cli-templates/prompts/planning/03-evaluate-concept-feasibility.txt +127 -0
  235. package/.claude/workflows/cli-templates/prompts/planning/03-plan-migration-strategy.txt +30 -0
  236. package/.claude/workflows/cli-templates/prompts/rules/rule-api.txt +122 -0
  237. package/.claude/workflows/cli-templates/prompts/rules/rule-components.txt +122 -0
  238. package/.claude/workflows/cli-templates/prompts/rules/rule-config.txt +89 -0
  239. package/.claude/workflows/cli-templates/prompts/rules/rule-core.txt +60 -0
  240. package/.claude/workflows/cli-templates/prompts/rules/rule-patterns.txt +70 -0
  241. package/.claude/workflows/cli-templates/prompts/rules/rule-testing.txt +81 -0
  242. package/.claude/workflows/cli-templates/prompts/rules/tech-rules-agent-prompt.txt +89 -0
  243. package/.claude/workflows/cli-templates/prompts/tech/tech-module-format.txt +359 -0
  244. package/.claude/workflows/cli-templates/prompts/tech/tech-skill-index.txt +185 -0
  245. package/.claude/workflows/cli-templates/prompts/test/test-concept-analysis.txt +179 -0
  246. package/.claude/workflows/cli-templates/prompts/universal/00-universal-creative-style.txt +95 -0
  247. package/.claude/workflows/cli-templates/prompts/universal/00-universal-rigorous-style.txt +92 -0
  248. package/.claude/workflows/cli-templates/prompts/verification/codex-technical.txt +28 -0
  249. package/.claude/workflows/cli-templates/prompts/verification/cross-validation.txt +28 -0
  250. package/.claude/workflows/cli-templates/prompts/verification/gemini-strategic.txt +27 -0
  251. package/.claude/workflows/cli-templates/prompts/workflow/analysis-results-structure.txt +224 -0
  252. package/.claude/workflows/cli-templates/prompts/workflow/codex-feasibility-validation.txt +176 -0
  253. package/.claude/workflows/cli-templates/prompts/workflow/gemini-solution-design.txt +131 -0
  254. package/.claude/workflows/cli-templates/prompts/workflow/impl-plan-template.txt +286 -0
  255. package/.claude/workflows/cli-templates/prompts/workflow/skill-aggregation.txt +172 -0
  256. package/.claude/workflows/cli-templates/prompts/workflow/skill-conflict-patterns.txt +94 -0
  257. package/.claude/workflows/cli-templates/prompts/workflow/skill-index.txt +224 -0
  258. package/.claude/workflows/cli-templates/prompts/workflow/skill-lessons-learned.txt +94 -0
  259. package/.claude/workflows/cli-templates/prompts/workflow/skill-sessions-timeline.txt +53 -0
  260. package/.claude/workflows/cli-templates/prompts/workflow/task-json-agent-mode.txt +123 -0
  261. package/.claude/workflows/cli-templates/prompts/workflow/task-json-cli-mode.txt +182 -0
  262. package/.claude/workflows/cli-templates/protocols/analysis-protocol.md +112 -0
  263. package/.claude/workflows/cli-templates/protocols/write-protocol.md +201 -0
  264. package/.claude/workflows/cli-templates/schemas/conflict-resolution-schema.json +137 -0
  265. package/.claude/workflows/cli-templates/schemas/debug-log-json-schema.json +127 -0
  266. package/.claude/workflows/cli-templates/schemas/diagnosis-json-schema.json +234 -0
  267. package/.claude/workflows/cli-templates/schemas/explore-json-schema.json +124 -0
  268. package/.claude/workflows/cli-templates/schemas/fix-plan-json-schema.json +298 -0
  269. package/.claude/workflows/cli-templates/schemas/plan-json-schema.json +244 -0
  270. package/.claude/workflows/cli-templates/schemas/project-json-schema.json +221 -0
  271. package/.claude/workflows/cli-templates/schemas/review-deep-dive-results-schema.json +82 -0
  272. package/.claude/workflows/cli-templates/schemas/review-dimension-results-schema.json +51 -0
  273. package/.claude/workflows/cli-templates/tech-stacks/go-dev.md +91 -0
  274. package/.claude/workflows/cli-templates/tech-stacks/java-dev.md +107 -0
  275. package/.claude/workflows/cli-templates/tech-stacks/javascript-dev.md +58 -0
  276. package/.claude/workflows/cli-templates/tech-stacks/python-dev.md +79 -0
  277. package/.claude/workflows/cli-templates/tech-stacks/react-dev.md +103 -0
  278. package/.claude/workflows/cli-templates/tech-stacks/typescript-dev.md +83 -0
  279. package/.claude/workflows/cli-templates/ui-design/systems/animation-tokens.json +247 -0
  280. package/.claude/workflows/cli-templates/ui-design/systems/design-tokens.json +342 -0
  281. package/.claude/workflows/cli-templates/ui-design/systems/layout-templates.json +145 -0
  282. package/.claude/workflows/cli-tools-usage.md +526 -0
  283. package/.claude/workflows/coding-philosophy.md +70 -0
  284. package/.claude/workflows/context-tools.md +84 -0
  285. package/.claude/workflows/file-modification.md +64 -0
  286. package/.claude/workflows/review-directory-specification.md +336 -0
  287. package/.claude/workflows/task-core.md +214 -0
  288. package/.claude/workflows/tool-strategy.md +216 -0
  289. package/.claude/workflows/windows-platform.md +16 -0
  290. package/.claude/workflows/workflow-architecture.md +942 -0
  291. package/.codex/AGENTS.md +63 -0
  292. package/.codex/prompts/debug.md +318 -0
  293. package/.codex/prompts/execute.md +273 -0
  294. package/.codex/prompts/lite-execute.md +164 -0
  295. package/.codex/prompts/lite-plan.md +469 -0
  296. package/.codex/prompts.zip +0 -0
  297. package/.gemini/GEMINI.md +25 -0
  298. package/.qwen/QWEN.md +25 -0
  299. package/LICENSE +21 -0
  300. package/README.md +294 -145
  301. package/ccw/README.md +145 -0
  302. package/ccw/dist/core/lite-scanner-complete.d.ts.map +1 -0
  303. package/ccw/dist/core/lite-scanner-complete.js +371 -0
  304. package/ccw/dist/core/lite-scanner-complete.js.map +1 -0
  305. package/ccw/dist/core/lite-scanner.d.ts.map +1 -0
  306. package/ccw/dist/core/lite-scanner.js +371 -0
  307. package/ccw/dist/core/lite-scanner.js.map +1 -0
  308. package/ccw/dist/core/routes/claude-routes.d.ts.map +1 -0
  309. package/ccw/dist/core/routes/claude-routes.js +1015 -0
  310. package/ccw/dist/core/routes/claude-routes.js.map +1 -0
  311. package/ccw/dist/core/routes/cli-routes.d.ts.map +1 -0
  312. package/ccw/dist/core/routes/cli-routes.js +469 -0
  313. package/ccw/dist/core/routes/cli-routes.js.map +1 -0
  314. package/ccw/dist/core/routes/rules-routes.d.ts.map +1 -0
  315. package/ccw/dist/core/routes/rules-routes.js +443 -0
  316. package/ccw/dist/core/routes/rules-routes.js.map +1 -0
  317. package/ccw/dist/core/routes/skills-routes.d.ts.map +1 -0
  318. package/ccw/dist/core/routes/skills-routes.js +651 -0
  319. package/ccw/dist/core/routes/skills-routes.js.map +1 -0
  320. package/ccw/dist/tools/cli-executor.d.ts +376 -0
  321. package/ccw/dist/tools/cli-executor.d.ts.map +1 -0
  322. package/ccw/dist/tools/cli-executor.js +1677 -0
  323. package/ccw/dist/tools/cli-executor.js.map +1 -0
  324. package/ccw/package.json +65 -0
  325. package/ccw/src/core/lite-scanner-complete.ts +473 -0
  326. package/ccw/src/core/lite-scanner.ts +473 -0
  327. package/ccw/src/core/routes/claude-routes.ts +1181 -0
  328. package/ccw/src/core/routes/cli-routes.ts +562 -0
  329. package/ccw/src/core/routes/rules-routes.ts +527 -0
  330. package/ccw/src/core/routes/skills-routes.ts +737 -0
  331. package/ccw/src/templates/dashboard-js/i18n.js +2969 -0
  332. package/ccw/src/templates/dashboard-js/views/claude-manager.js +926 -0
  333. package/ccw/src/templates/dashboard-js/views/cli-manager.js +2274 -0
  334. package/ccw/src/templates/dashboard-js/views/rules-manager.js +857 -0
  335. package/ccw/src/templates/dashboard-js/views/skills-manager.js +1183 -0
  336. package/ccw/src/tools/cli-executor.ts +2082 -0
  337. package/codex-lens/pyproject.toml +66 -0
  338. package/codex-lens/src/codexlens/.workflow/.cli-history/history.db +0 -0
  339. package/codex-lens/src/codexlens/__init__.py +28 -0
  340. package/codex-lens/src/codexlens/__main__.py +14 -0
  341. package/codex-lens/src/codexlens/__pycache__/__init__.cpython-313.pyc +0 -0
  342. package/codex-lens/src/codexlens/__pycache__/__main__.cpython-313.pyc +0 -0
  343. package/codex-lens/src/codexlens/__pycache__/config.cpython-313.pyc +0 -0
  344. package/codex-lens/src/codexlens/__pycache__/entities.cpython-313.pyc +0 -0
  345. package/codex-lens/src/codexlens/__pycache__/errors.cpython-313.pyc +0 -0
  346. package/codex-lens/src/codexlens/cli/__init__.py +27 -0
  347. package/codex-lens/src/codexlens/cli/__pycache__/__init__.cpython-313.pyc +0 -0
  348. package/codex-lens/src/codexlens/cli/__pycache__/commands.cpython-313.pyc +0 -0
  349. package/codex-lens/src/codexlens/cli/__pycache__/embedding_manager.cpython-313.pyc +0 -0
  350. package/codex-lens/src/codexlens/cli/__pycache__/model_manager.cpython-313.pyc +0 -0
  351. package/codex-lens/src/codexlens/cli/__pycache__/output.cpython-313.pyc +0 -0
  352. package/codex-lens/src/codexlens/cli/commands.py +1931 -0
  353. package/codex-lens/src/codexlens/cli/embedding_manager.py +620 -0
  354. package/codex-lens/src/codexlens/cli/model_manager.py +311 -0
  355. package/codex-lens/src/codexlens/cli/output.py +124 -0
  356. package/codex-lens/src/codexlens/config.py +201 -0
  357. package/codex-lens/src/codexlens/entities.py +121 -0
  358. package/codex-lens/src/codexlens/errors.py +55 -0
  359. package/codex-lens/src/codexlens/indexing/README.md +77 -0
  360. package/codex-lens/src/codexlens/indexing/__init__.py +4 -0
  361. package/codex-lens/src/codexlens/indexing/__pycache__/__init__.cpython-313.pyc +0 -0
  362. package/codex-lens/src/codexlens/indexing/__pycache__/symbol_extractor.cpython-313.pyc +0 -0
  363. package/codex-lens/src/codexlens/indexing/symbol_extractor.py +243 -0
  364. package/codex-lens/src/codexlens/parsers/__init__.py +8 -0
  365. package/codex-lens/src/codexlens/parsers/__pycache__/__init__.cpython-313.pyc +0 -0
  366. package/codex-lens/src/codexlens/parsers/__pycache__/encoding.cpython-313.pyc +0 -0
  367. package/codex-lens/src/codexlens/parsers/__pycache__/factory.cpython-313.pyc +0 -0
  368. package/codex-lens/src/codexlens/parsers/__pycache__/tokenizer.cpython-313.pyc +0 -0
  369. package/codex-lens/src/codexlens/parsers/__pycache__/treesitter_parser.cpython-313.pyc +0 -0
  370. package/codex-lens/src/codexlens/parsers/encoding.py +202 -0
  371. package/codex-lens/src/codexlens/parsers/factory.py +256 -0
  372. package/codex-lens/src/codexlens/parsers/tokenizer.py +98 -0
  373. package/codex-lens/src/codexlens/parsers/treesitter_parser.py +335 -0
  374. package/codex-lens/src/codexlens/search/__init__.py +15 -0
  375. package/codex-lens/src/codexlens/search/__pycache__/__init__.cpython-313.pyc +0 -0
  376. package/codex-lens/src/codexlens/search/__pycache__/chain_search.cpython-313.pyc +0 -0
  377. package/codex-lens/src/codexlens/search/__pycache__/enrichment.cpython-313.pyc +0 -0
  378. package/codex-lens/src/codexlens/search/__pycache__/hybrid_search.cpython-313.pyc +0 -0
  379. package/codex-lens/src/codexlens/search/__pycache__/query_parser.cpython-313.pyc +0 -0
  380. package/codex-lens/src/codexlens/search/__pycache__/ranking.cpython-313.pyc +0 -0
  381. package/codex-lens/src/codexlens/search/chain_search.py +647 -0
  382. package/codex-lens/src/codexlens/search/enrichment.py +150 -0
  383. package/codex-lens/src/codexlens/search/hybrid_search.py +313 -0
  384. package/codex-lens/src/codexlens/search/query_parser.py +242 -0
  385. package/codex-lens/src/codexlens/search/ranking.py +274 -0
  386. package/codex-lens/src/codexlens/semantic/__init__.py +76 -0
  387. package/codex-lens/src/codexlens/semantic/__pycache__/__init__.cpython-313.pyc +0 -0
  388. package/codex-lens/src/codexlens/semantic/__pycache__/ann_index.cpython-313.pyc +0 -0
  389. package/codex-lens/src/codexlens/semantic/__pycache__/chunker.cpython-313.pyc +0 -0
  390. package/codex-lens/src/codexlens/semantic/__pycache__/code_extractor.cpython-313.pyc +0 -0
  391. package/codex-lens/src/codexlens/semantic/__pycache__/embedder.cpython-313.pyc +0 -0
  392. package/codex-lens/src/codexlens/semantic/__pycache__/gpu_support.cpython-313.pyc +0 -0
  393. package/codex-lens/src/codexlens/semantic/__pycache__/graph_analyzer.cpython-313.pyc +0 -0
  394. package/codex-lens/src/codexlens/semantic/__pycache__/llm_enhancer.cpython-313.pyc +0 -0
  395. package/codex-lens/src/codexlens/semantic/__pycache__/ollama_backend.cpython-313.pyc +0 -0
  396. package/codex-lens/src/codexlens/semantic/__pycache__/vector_store.cpython-313.pyc +0 -0
  397. package/codex-lens/src/codexlens/semantic/ann_index.py +414 -0
  398. package/codex-lens/src/codexlens/semantic/chunker.py +448 -0
  399. package/codex-lens/src/codexlens/semantic/code_extractor.py +274 -0
  400. package/codex-lens/src/codexlens/semantic/embedder.py +244 -0
  401. package/codex-lens/src/codexlens/semantic/gpu_support.py +192 -0
  402. package/codex-lens/src/codexlens/semantic/vector_store.py +955 -0
  403. package/codex-lens/src/codexlens/storage/__init__.py +29 -0
  404. package/codex-lens/src/codexlens/storage/__pycache__/__init__.cpython-313.pyc +0 -0
  405. package/codex-lens/src/codexlens/storage/__pycache__/dir_index.cpython-313.pyc +0 -0
  406. package/codex-lens/src/codexlens/storage/__pycache__/file_cache.cpython-313.pyc +0 -0
  407. package/codex-lens/src/codexlens/storage/__pycache__/index_tree.cpython-313.pyc +0 -0
  408. package/codex-lens/src/codexlens/storage/__pycache__/migration_manager.cpython-313.pyc +0 -0
  409. package/codex-lens/src/codexlens/storage/__pycache__/path_mapper.cpython-313.pyc +0 -0
  410. package/codex-lens/src/codexlens/storage/__pycache__/registry.cpython-313.pyc +0 -0
  411. package/codex-lens/src/codexlens/storage/__pycache__/sqlite_store.cpython-313.pyc +0 -0
  412. package/codex-lens/src/codexlens/storage/__pycache__/sqlite_utils.cpython-313.pyc +0 -0
  413. package/codex-lens/src/codexlens/storage/dir_index.py +1850 -0
  414. package/codex-lens/src/codexlens/storage/file_cache.py +32 -0
  415. package/codex-lens/src/codexlens/storage/index_tree.py +776 -0
  416. package/codex-lens/src/codexlens/storage/migration_manager.py +154 -0
  417. package/codex-lens/src/codexlens/storage/migrations/__init__.py +1 -0
  418. package/codex-lens/src/codexlens/storage/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
  419. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_001_normalize_keywords.cpython-313.pyc +0 -0
  420. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_002_add_token_metadata.cpython-313.pyc +0 -0
  421. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_003_code_relationships.cpython-313.pyc +0 -0
  422. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_004_dual_fts.cpython-313.pyc +0 -0
  423. package/codex-lens/src/codexlens/storage/migrations/__pycache__/migration_005_cleanup_unused_fields.cpython-313.pyc +0 -0
  424. package/codex-lens/src/codexlens/storage/migrations/migration_001_normalize_keywords.py +123 -0
  425. package/codex-lens/src/codexlens/storage/migrations/migration_002_add_token_metadata.py +48 -0
  426. package/codex-lens/src/codexlens/storage/migrations/migration_004_dual_fts.py +232 -0
  427. package/codex-lens/src/codexlens/storage/migrations/migration_005_cleanup_unused_fields.py +196 -0
  428. package/codex-lens/src/codexlens/storage/path_mapper.py +274 -0
  429. package/codex-lens/src/codexlens/storage/registry.py +670 -0
  430. package/codex-lens/src/codexlens/storage/sqlite_store.py +576 -0
  431. package/codex-lens/src/codexlens/storage/sqlite_utils.py +64 -0
  432. package/package.json +36 -28
  433. package/dist/core/lite-scanner-complete.d.ts.map +0 -1
  434. package/dist/core/lite-scanner-complete.js +0 -368
  435. package/dist/core/lite-scanner-complete.js.map +0 -1
  436. package/dist/core/lite-scanner.d.ts.map +0 -1
  437. package/dist/core/lite-scanner.js +0 -368
  438. package/dist/core/lite-scanner.js.map +0 -1
  439. package/dist/core/routes/claude-routes.d.ts.map +0 -1
  440. package/dist/core/routes/claude-routes.js +0 -1017
  441. package/dist/core/routes/claude-routes.js.map +0 -1
  442. package/dist/core/routes/cli-routes.d.ts.map +0 -1
  443. package/dist/core/routes/cli-routes.js +0 -468
  444. package/dist/core/routes/cli-routes.js.map +0 -1
  445. package/dist/core/routes/rules-routes.d.ts.map +0 -1
  446. package/dist/core/routes/rules-routes.js +0 -442
  447. package/dist/core/routes/rules-routes.js.map +0 -1
  448. package/dist/core/routes/skills-routes.d.ts.map +0 -1
  449. package/dist/core/routes/skills-routes.js +0 -533
  450. package/dist/core/routes/skills-routes.js.map +0 -1
  451. package/dist/tools/cli-executor.d.ts +0 -373
  452. package/dist/tools/cli-executor.d.ts.map +0 -1
  453. package/dist/tools/cli-executor.js +0 -1625
  454. package/dist/tools/cli-executor.js.map +0 -1
  455. package/src/core/lite-scanner-complete.ts +0 -469
  456. package/src/core/lite-scanner.ts +0 -469
  457. package/src/core/routes/claude-routes.ts +0 -1183
  458. package/src/core/routes/cli-routes.ts +0 -561
  459. package/src/core/routes/rules-routes.ts +0 -526
  460. package/src/core/routes/skills-routes.ts +0 -599
  461. package/src/templates/dashboard-js/i18n.js +0 -2963
  462. package/src/templates/dashboard-js/views/claude-manager.js +0 -912
  463. package/src/templates/dashboard-js/views/cli-manager.js +0 -2272
  464. package/src/templates/dashboard-js/views/rules-manager.js +0 -828
  465. package/src/templates/dashboard-js/views/skills-manager.js +0 -819
  466. package/src/tools/cli-executor.ts +0 -2014
  467. /package/{bin → ccw/bin}/ccw-mcp.js +0 -0
  468. /package/{bin → ccw/bin}/ccw.js +0 -0
  469. /package/{dist → ccw/dist}/cli.d.ts +0 -0
  470. /package/{dist → ccw/dist}/cli.d.ts.map +0 -0
  471. /package/{dist → ccw/dist}/cli.js +0 -0
  472. /package/{dist → ccw/dist}/cli.js.map +0 -0
  473. /package/{dist → ccw/dist}/commands/cli.d.ts +0 -0
  474. /package/{dist → ccw/dist}/commands/cli.d.ts.map +0 -0
  475. /package/{dist → ccw/dist}/commands/cli.js +0 -0
  476. /package/{dist → ccw/dist}/commands/cli.js.map +0 -0
  477. /package/{dist → ccw/dist}/commands/core-memory.d.ts +0 -0
  478. /package/{dist → ccw/dist}/commands/core-memory.d.ts.map +0 -0
  479. /package/{dist → ccw/dist}/commands/core-memory.js +0 -0
  480. /package/{dist → ccw/dist}/commands/core-memory.js.map +0 -0
  481. /package/{dist → ccw/dist}/commands/hook.d.ts +0 -0
  482. /package/{dist → ccw/dist}/commands/hook.d.ts.map +0 -0
  483. /package/{dist → ccw/dist}/commands/hook.js +0 -0
  484. /package/{dist → ccw/dist}/commands/hook.js.map +0 -0
  485. /package/{dist → ccw/dist}/commands/install.d.ts +0 -0
  486. /package/{dist → ccw/dist}/commands/install.d.ts.map +0 -0
  487. /package/{dist → ccw/dist}/commands/install.js +0 -0
  488. /package/{dist → ccw/dist}/commands/install.js.map +0 -0
  489. /package/{dist → ccw/dist}/commands/list.d.ts +0 -0
  490. /package/{dist → ccw/dist}/commands/list.d.ts.map +0 -0
  491. /package/{dist → ccw/dist}/commands/list.js +0 -0
  492. /package/{dist → ccw/dist}/commands/list.js.map +0 -0
  493. /package/{dist → ccw/dist}/commands/memory.d.ts +0 -0
  494. /package/{dist → ccw/dist}/commands/memory.d.ts.map +0 -0
  495. /package/{dist → ccw/dist}/commands/memory.js +0 -0
  496. /package/{dist → ccw/dist}/commands/memory.js.map +0 -0
  497. /package/{dist → ccw/dist}/commands/serve.d.ts +0 -0
  498. /package/{dist → ccw/dist}/commands/serve.d.ts.map +0 -0
  499. /package/{dist → ccw/dist}/commands/serve.js +0 -0
  500. /package/{dist → ccw/dist}/commands/serve.js.map +0 -0
  501. /package/{dist → ccw/dist}/commands/session-path-resolver.d.ts +0 -0
  502. /package/{dist → ccw/dist}/commands/session-path-resolver.d.ts.map +0 -0
  503. /package/{dist → ccw/dist}/commands/session-path-resolver.js +0 -0
  504. /package/{dist → ccw/dist}/commands/session-path-resolver.js.map +0 -0
  505. /package/{dist → ccw/dist}/commands/session.d.ts +0 -0
  506. /package/{dist → ccw/dist}/commands/session.d.ts.map +0 -0
  507. /package/{dist → ccw/dist}/commands/session.js +0 -0
  508. /package/{dist → ccw/dist}/commands/session.js.map +0 -0
  509. /package/{dist → ccw/dist}/commands/stop.d.ts +0 -0
  510. /package/{dist → ccw/dist}/commands/stop.d.ts.map +0 -0
  511. /package/{dist → ccw/dist}/commands/stop.js +0 -0
  512. /package/{dist → ccw/dist}/commands/stop.js.map +0 -0
  513. /package/{dist → ccw/dist}/commands/tool.d.ts +0 -0
  514. /package/{dist → ccw/dist}/commands/tool.d.ts.map +0 -0
  515. /package/{dist → ccw/dist}/commands/tool.js +0 -0
  516. /package/{dist → ccw/dist}/commands/tool.js.map +0 -0
  517. /package/{dist → ccw/dist}/commands/uninstall.d.ts +0 -0
  518. /package/{dist → ccw/dist}/commands/uninstall.d.ts.map +0 -0
  519. /package/{dist → ccw/dist}/commands/uninstall.js +0 -0
  520. /package/{dist → ccw/dist}/commands/uninstall.js.map +0 -0
  521. /package/{dist → ccw/dist}/commands/upgrade.d.ts +0 -0
  522. /package/{dist → ccw/dist}/commands/upgrade.d.ts.map +0 -0
  523. /package/{dist → ccw/dist}/commands/upgrade.js +0 -0
  524. /package/{dist → ccw/dist}/commands/upgrade.js.map +0 -0
  525. /package/{dist → ccw/dist}/commands/view.d.ts +0 -0
  526. /package/{dist → ccw/dist}/commands/view.d.ts.map +0 -0
  527. /package/{dist → ccw/dist}/commands/view.js +0 -0
  528. /package/{dist → ccw/dist}/commands/view.js.map +0 -0
  529. /package/{dist → ccw/dist}/config/storage-paths.d.ts +0 -0
  530. /package/{dist → ccw/dist}/config/storage-paths.d.ts.map +0 -0
  531. /package/{dist → ccw/dist}/config/storage-paths.js +0 -0
  532. /package/{dist → ccw/dist}/config/storage-paths.js.map +0 -0
  533. /package/{dist → ccw/dist}/core/cache-manager.d.ts +0 -0
  534. /package/{dist → ccw/dist}/core/cache-manager.d.ts.map +0 -0
  535. /package/{dist → ccw/dist}/core/cache-manager.js +0 -0
  536. /package/{dist → ccw/dist}/core/cache-manager.js.map +0 -0
  537. /package/{dist → ccw/dist}/core/claude-freshness.d.ts +0 -0
  538. /package/{dist → ccw/dist}/core/claude-freshness.d.ts.map +0 -0
  539. /package/{dist → ccw/dist}/core/claude-freshness.js +0 -0
  540. /package/{dist → ccw/dist}/core/claude-freshness.js.map +0 -0
  541. /package/{dist → ccw/dist}/core/core-memory-store.d.ts +0 -0
  542. /package/{dist → ccw/dist}/core/core-memory-store.d.ts.map +0 -0
  543. /package/{dist → ccw/dist}/core/core-memory-store.js +0 -0
  544. /package/{dist → ccw/dist}/core/core-memory-store.js.map +0 -0
  545. /package/{dist → ccw/dist}/core/dashboard-generator-patch.d.ts +0 -0
  546. /package/{dist → ccw/dist}/core/dashboard-generator-patch.d.ts.map +0 -0
  547. /package/{dist → ccw/dist}/core/dashboard-generator-patch.js +0 -0
  548. /package/{dist → ccw/dist}/core/dashboard-generator-patch.js.map +0 -0
  549. /package/{dist → ccw/dist}/core/dashboard-generator.d.ts +0 -0
  550. /package/{dist → ccw/dist}/core/dashboard-generator.d.ts.map +0 -0
  551. /package/{dist → ccw/dist}/core/dashboard-generator.js +0 -0
  552. /package/{dist → ccw/dist}/core/dashboard-generator.js.map +0 -0
  553. /package/{dist → ccw/dist}/core/data-aggregator.d.ts +0 -0
  554. /package/{dist → ccw/dist}/core/data-aggregator.d.ts.map +0 -0
  555. /package/{dist → ccw/dist}/core/data-aggregator.js +0 -0
  556. /package/{dist → ccw/dist}/core/data-aggregator.js.map +0 -0
  557. /package/{dist → ccw/dist}/core/history-importer.d.ts +0 -0
  558. /package/{dist → ccw/dist}/core/history-importer.d.ts.map +0 -0
  559. /package/{dist → ccw/dist}/core/history-importer.js +0 -0
  560. /package/{dist → ccw/dist}/core/history-importer.js.map +0 -0
  561. /package/{dist → ccw/dist}/core/lite-scanner-complete.d.ts +0 -0
  562. /package/{dist → ccw/dist}/core/lite-scanner.d.ts +0 -0
  563. /package/{dist → ccw/dist}/core/manifest.d.ts +0 -0
  564. /package/{dist → ccw/dist}/core/manifest.d.ts.map +0 -0
  565. /package/{dist → ccw/dist}/core/manifest.js +0 -0
  566. /package/{dist → ccw/dist}/core/manifest.js.map +0 -0
  567. /package/{dist → ccw/dist}/core/memory-embedder-bridge.d.ts +0 -0
  568. /package/{dist → ccw/dist}/core/memory-embedder-bridge.d.ts.map +0 -0
  569. /package/{dist → ccw/dist}/core/memory-embedder-bridge.js +0 -0
  570. /package/{dist → ccw/dist}/core/memory-embedder-bridge.js.map +0 -0
  571. /package/{dist → ccw/dist}/core/memory-store.d.ts +0 -0
  572. /package/{dist → ccw/dist}/core/memory-store.d.ts.map +0 -0
  573. /package/{dist → ccw/dist}/core/memory-store.js +0 -0
  574. /package/{dist → ccw/dist}/core/memory-store.js.map +0 -0
  575. /package/{dist → ccw/dist}/core/routes/ccw-routes.d.ts +0 -0
  576. /package/{dist → ccw/dist}/core/routes/ccw-routes.d.ts.map +0 -0
  577. /package/{dist → ccw/dist}/core/routes/ccw-routes.js +0 -0
  578. /package/{dist → ccw/dist}/core/routes/ccw-routes.js.map +0 -0
  579. /package/{dist → ccw/dist}/core/routes/claude-routes.d.ts +0 -0
  580. /package/{dist → ccw/dist}/core/routes/cli-routes.d.ts +0 -0
  581. /package/{dist → ccw/dist}/core/routes/codexlens-routes.d.ts +0 -0
  582. /package/{dist → ccw/dist}/core/routes/codexlens-routes.d.ts.map +0 -0
  583. /package/{dist → ccw/dist}/core/routes/codexlens-routes.js +0 -0
  584. /package/{dist → ccw/dist}/core/routes/codexlens-routes.js.map +0 -0
  585. /package/{dist → ccw/dist}/core/routes/core-memory-routes.d.ts +0 -0
  586. /package/{dist → ccw/dist}/core/routes/core-memory-routes.d.ts.map +0 -0
  587. /package/{dist → ccw/dist}/core/routes/core-memory-routes.js +0 -0
  588. /package/{dist → ccw/dist}/core/routes/core-memory-routes.js.map +0 -0
  589. /package/{dist → ccw/dist}/core/routes/files-routes.d.ts +0 -0
  590. /package/{dist → ccw/dist}/core/routes/files-routes.d.ts.map +0 -0
  591. /package/{dist → ccw/dist}/core/routes/files-routes.js +0 -0
  592. /package/{dist → ccw/dist}/core/routes/files-routes.js.map +0 -0
  593. /package/{dist → ccw/dist}/core/routes/graph-routes.d.ts +0 -0
  594. /package/{dist → ccw/dist}/core/routes/graph-routes.d.ts.map +0 -0
  595. /package/{dist → ccw/dist}/core/routes/graph-routes.js +0 -0
  596. /package/{dist → ccw/dist}/core/routes/graph-routes.js.map +0 -0
  597. /package/{dist → ccw/dist}/core/routes/help-routes.d.ts +0 -0
  598. /package/{dist → ccw/dist}/core/routes/help-routes.d.ts.map +0 -0
  599. /package/{dist → ccw/dist}/core/routes/help-routes.js +0 -0
  600. /package/{dist → ccw/dist}/core/routes/help-routes.js.map +0 -0
  601. /package/{dist → ccw/dist}/core/routes/hooks-routes.d.ts +0 -0
  602. /package/{dist → ccw/dist}/core/routes/hooks-routes.d.ts.map +0 -0
  603. /package/{dist → ccw/dist}/core/routes/hooks-routes.js +0 -0
  604. /package/{dist → ccw/dist}/core/routes/hooks-routes.js.map +0 -0
  605. /package/{dist → ccw/dist}/core/routes/mcp-routes.d.ts +0 -0
  606. /package/{dist → ccw/dist}/core/routes/mcp-routes.d.ts.map +0 -0
  607. /package/{dist → ccw/dist}/core/routes/mcp-routes.js +0 -0
  608. /package/{dist → ccw/dist}/core/routes/mcp-routes.js.map +0 -0
  609. /package/{dist → ccw/dist}/core/routes/mcp-templates-db.d.ts +0 -0
  610. /package/{dist → ccw/dist}/core/routes/mcp-templates-db.d.ts.map +0 -0
  611. /package/{dist → ccw/dist}/core/routes/mcp-templates-db.js +0 -0
  612. /package/{dist → ccw/dist}/core/routes/mcp-templates-db.js.map +0 -0
  613. /package/{dist → ccw/dist}/core/routes/memory-routes.d.ts +0 -0
  614. /package/{dist → ccw/dist}/core/routes/memory-routes.d.ts.map +0 -0
  615. /package/{dist → ccw/dist}/core/routes/memory-routes.js +0 -0
  616. /package/{dist → ccw/dist}/core/routes/memory-routes.js.map +0 -0
  617. /package/{dist → ccw/dist}/core/routes/rules-routes.d.ts +0 -0
  618. /package/{dist → ccw/dist}/core/routes/session-routes.d.ts +0 -0
  619. /package/{dist → ccw/dist}/core/routes/session-routes.d.ts.map +0 -0
  620. /package/{dist → ccw/dist}/core/routes/session-routes.js +0 -0
  621. /package/{dist → ccw/dist}/core/routes/session-routes.js.map +0 -0
  622. /package/{dist → ccw/dist}/core/routes/skills-routes.d.ts +0 -0
  623. /package/{dist → ccw/dist}/core/routes/status-routes.d.ts +0 -0
  624. /package/{dist → ccw/dist}/core/routes/status-routes.d.ts.map +0 -0
  625. /package/{dist → ccw/dist}/core/routes/status-routes.js +0 -0
  626. /package/{dist → ccw/dist}/core/routes/status-routes.js.map +0 -0
  627. /package/{dist → ccw/dist}/core/routes/system-routes.d.ts +0 -0
  628. /package/{dist → ccw/dist}/core/routes/system-routes.d.ts.map +0 -0
  629. /package/{dist → ccw/dist}/core/routes/system-routes.js +0 -0
  630. /package/{dist → ccw/dist}/core/routes/system-routes.js.map +0 -0
  631. /package/{dist → ccw/dist}/core/server.d.ts +0 -0
  632. /package/{dist → ccw/dist}/core/server.d.ts.map +0 -0
  633. /package/{dist → ccw/dist}/core/server.js +0 -0
  634. /package/{dist → ccw/dist}/core/server.js.map +0 -0
  635. /package/{dist → ccw/dist}/core/session-clustering-service.d.ts +0 -0
  636. /package/{dist → ccw/dist}/core/session-clustering-service.d.ts.map +0 -0
  637. /package/{dist → ccw/dist}/core/session-clustering-service.js +0 -0
  638. /package/{dist → ccw/dist}/core/session-clustering-service.js.map +0 -0
  639. /package/{dist → ccw/dist}/core/session-scanner.d.ts +0 -0
  640. /package/{dist → ccw/dist}/core/session-scanner.d.ts.map +0 -0
  641. /package/{dist → ccw/dist}/core/session-scanner.js +0 -0
  642. /package/{dist → ccw/dist}/core/session-scanner.js.map +0 -0
  643. /package/{dist → ccw/dist}/core/websocket.d.ts +0 -0
  644. /package/{dist → ccw/dist}/core/websocket.d.ts.map +0 -0
  645. /package/{dist → ccw/dist}/core/websocket.js +0 -0
  646. /package/{dist → ccw/dist}/core/websocket.js.map +0 -0
  647. /package/{dist → ccw/dist}/index.d.ts +0 -0
  648. /package/{dist → ccw/dist}/index.d.ts.map +0 -0
  649. /package/{dist → ccw/dist}/index.js +0 -0
  650. /package/{dist → ccw/dist}/index.js.map +0 -0
  651. /package/{dist → ccw/dist}/mcp-server/index.d.ts +0 -0
  652. /package/{dist → ccw/dist}/mcp-server/index.d.ts.map +0 -0
  653. /package/{dist → ccw/dist}/mcp-server/index.js +0 -0
  654. /package/{dist → ccw/dist}/mcp-server/index.js.map +0 -0
  655. /package/{dist → ccw/dist}/tools/classify-folders.d.ts +0 -0
  656. /package/{dist → ccw/dist}/tools/classify-folders.d.ts.map +0 -0
  657. /package/{dist → ccw/dist}/tools/classify-folders.js +0 -0
  658. /package/{dist → ccw/dist}/tools/classify-folders.js.map +0 -0
  659. /package/{dist → ccw/dist}/tools/cli-config-manager.d.ts +0 -0
  660. /package/{dist → ccw/dist}/tools/cli-config-manager.d.ts.map +0 -0
  661. /package/{dist → ccw/dist}/tools/cli-config-manager.js +0 -0
  662. /package/{dist → ccw/dist}/tools/cli-config-manager.js.map +0 -0
  663. /package/{dist → ccw/dist}/tools/cli-history-store.d.ts +0 -0
  664. /package/{dist → ccw/dist}/tools/cli-history-store.d.ts.map +0 -0
  665. /package/{dist → ccw/dist}/tools/cli-history-store.js +0 -0
  666. /package/{dist → ccw/dist}/tools/cli-history-store.js.map +0 -0
  667. /package/{dist → ccw/dist}/tools/codex-lens.d.ts +0 -0
  668. /package/{dist → ccw/dist}/tools/codex-lens.d.ts.map +0 -0
  669. /package/{dist → ccw/dist}/tools/codex-lens.js +0 -0
  670. /package/{dist → ccw/dist}/tools/codex-lens.js.map +0 -0
  671. /package/{dist → ccw/dist}/tools/convert-tokens-to-css.d.ts +0 -0
  672. /package/{dist → ccw/dist}/tools/convert-tokens-to-css.d.ts.map +0 -0
  673. /package/{dist → ccw/dist}/tools/convert-tokens-to-css.js +0 -0
  674. /package/{dist → ccw/dist}/tools/convert-tokens-to-css.js.map +0 -0
  675. /package/{dist → ccw/dist}/tools/core-memory.d.ts +0 -0
  676. /package/{dist → ccw/dist}/tools/core-memory.d.ts.map +0 -0
  677. /package/{dist → ccw/dist}/tools/core-memory.js +0 -0
  678. /package/{dist → ccw/dist}/tools/core-memory.js.map +0 -0
  679. /package/{dist → ccw/dist}/tools/detect-changed-modules.d.ts +0 -0
  680. /package/{dist → ccw/dist}/tools/detect-changed-modules.d.ts.map +0 -0
  681. /package/{dist → ccw/dist}/tools/detect-changed-modules.js +0 -0
  682. /package/{dist → ccw/dist}/tools/detect-changed-modules.js.map +0 -0
  683. /package/{dist → ccw/dist}/tools/discover-design-files.d.ts +0 -0
  684. /package/{dist → ccw/dist}/tools/discover-design-files.d.ts.map +0 -0
  685. /package/{dist → ccw/dist}/tools/discover-design-files.js +0 -0
  686. /package/{dist → ccw/dist}/tools/discover-design-files.js.map +0 -0
  687. /package/{dist → ccw/dist}/tools/edit-file.d.ts +0 -0
  688. /package/{dist → ccw/dist}/tools/edit-file.d.ts.map +0 -0
  689. /package/{dist → ccw/dist}/tools/edit-file.js +0 -0
  690. /package/{dist → ccw/dist}/tools/edit-file.js.map +0 -0
  691. /package/{dist → ccw/dist}/tools/generate-module-docs.d.ts +0 -0
  692. /package/{dist → ccw/dist}/tools/generate-module-docs.d.ts.map +0 -0
  693. /package/{dist → ccw/dist}/tools/generate-module-docs.js +0 -0
  694. /package/{dist → ccw/dist}/tools/generate-module-docs.js.map +0 -0
  695. /package/{dist → ccw/dist}/tools/get-modules-by-depth.d.ts +0 -0
  696. /package/{dist → ccw/dist}/tools/get-modules-by-depth.d.ts.map +0 -0
  697. /package/{dist → ccw/dist}/tools/get-modules-by-depth.js +0 -0
  698. /package/{dist → ccw/dist}/tools/get-modules-by-depth.js.map +0 -0
  699. /package/{dist → ccw/dist}/tools/index.d.ts +0 -0
  700. /package/{dist → ccw/dist}/tools/index.d.ts.map +0 -0
  701. /package/{dist → ccw/dist}/tools/index.js +0 -0
  702. /package/{dist → ccw/dist}/tools/index.js.map +0 -0
  703. /package/{dist → ccw/dist}/tools/native-session-discovery.d.ts +0 -0
  704. /package/{dist → ccw/dist}/tools/native-session-discovery.d.ts.map +0 -0
  705. /package/{dist → ccw/dist}/tools/native-session-discovery.js +0 -0
  706. /package/{dist → ccw/dist}/tools/native-session-discovery.js.map +0 -0
  707. /package/{dist → ccw/dist}/tools/notifier.d.ts +0 -0
  708. /package/{dist → ccw/dist}/tools/notifier.d.ts.map +0 -0
  709. /package/{dist → ccw/dist}/tools/notifier.js +0 -0
  710. /package/{dist → ccw/dist}/tools/notifier.js.map +0 -0
  711. /package/{dist → ccw/dist}/tools/read-file.d.ts +0 -0
  712. /package/{dist → ccw/dist}/tools/read-file.d.ts.map +0 -0
  713. /package/{dist → ccw/dist}/tools/read-file.js +0 -0
  714. /package/{dist → ccw/dist}/tools/read-file.js.map +0 -0
  715. /package/{dist → ccw/dist}/tools/resume-strategy.d.ts +0 -0
  716. /package/{dist → ccw/dist}/tools/resume-strategy.d.ts.map +0 -0
  717. /package/{dist → ccw/dist}/tools/resume-strategy.js +0 -0
  718. /package/{dist → ccw/dist}/tools/resume-strategy.js.map +0 -0
  719. /package/{dist → ccw/dist}/tools/session-content-parser.d.ts +0 -0
  720. /package/{dist → ccw/dist}/tools/session-content-parser.d.ts.map +0 -0
  721. /package/{dist → ccw/dist}/tools/session-content-parser.js +0 -0
  722. /package/{dist → ccw/dist}/tools/session-content-parser.js.map +0 -0
  723. /package/{dist → ccw/dist}/tools/session-manager.d.ts +0 -0
  724. /package/{dist → ccw/dist}/tools/session-manager.d.ts.map +0 -0
  725. /package/{dist → ccw/dist}/tools/session-manager.js +0 -0
  726. /package/{dist → ccw/dist}/tools/session-manager.js.map +0 -0
  727. /package/{dist → ccw/dist}/tools/smart-context.d.ts +0 -0
  728. /package/{dist → ccw/dist}/tools/smart-context.d.ts.map +0 -0
  729. /package/{dist → ccw/dist}/tools/smart-context.js +0 -0
  730. /package/{dist → ccw/dist}/tools/smart-context.js.map +0 -0
  731. /package/{dist → ccw/dist}/tools/smart-search.d.ts +0 -0
  732. /package/{dist → ccw/dist}/tools/smart-search.d.ts.map +0 -0
  733. /package/{dist → ccw/dist}/tools/smart-search.js +0 -0
  734. /package/{dist → ccw/dist}/tools/smart-search.js.map +0 -0
  735. /package/{dist → ccw/dist}/tools/storage-manager.d.ts +0 -0
  736. /package/{dist → ccw/dist}/tools/storage-manager.d.ts.map +0 -0
  737. /package/{dist → ccw/dist}/tools/storage-manager.js +0 -0
  738. /package/{dist → ccw/dist}/tools/storage-manager.js.map +0 -0
  739. /package/{dist → ccw/dist}/tools/ui-generate-preview.d.ts +0 -0
  740. /package/{dist → ccw/dist}/tools/ui-generate-preview.d.ts.map +0 -0
  741. /package/{dist → ccw/dist}/tools/ui-generate-preview.js +0 -0
  742. /package/{dist → ccw/dist}/tools/ui-generate-preview.js.map +0 -0
  743. /package/{dist → ccw/dist}/tools/ui-instantiate-prototypes.d.ts +0 -0
  744. /package/{dist → ccw/dist}/tools/ui-instantiate-prototypes.d.ts.map +0 -0
  745. /package/{dist → ccw/dist}/tools/ui-instantiate-prototypes.js +0 -0
  746. /package/{dist → ccw/dist}/tools/ui-instantiate-prototypes.js.map +0 -0
  747. /package/{dist → ccw/dist}/tools/update-module-claude.d.ts +0 -0
  748. /package/{dist → ccw/dist}/tools/update-module-claude.d.ts.map +0 -0
  749. /package/{dist → ccw/dist}/tools/update-module-claude.js +0 -0
  750. /package/{dist → ccw/dist}/tools/update-module-claude.js.map +0 -0
  751. /package/{dist → ccw/dist}/tools/write-file.d.ts +0 -0
  752. /package/{dist → ccw/dist}/tools/write-file.d.ts.map +0 -0
  753. /package/{dist → ccw/dist}/tools/write-file.js +0 -0
  754. /package/{dist → ccw/dist}/tools/write-file.js.map +0 -0
  755. /package/{dist → ccw/dist}/types/config.d.ts +0 -0
  756. /package/{dist → ccw/dist}/types/config.d.ts.map +0 -0
  757. /package/{dist → ccw/dist}/types/config.js +0 -0
  758. /package/{dist → ccw/dist}/types/config.js.map +0 -0
  759. /package/{dist → ccw/dist}/types/index.d.ts +0 -0
  760. /package/{dist → ccw/dist}/types/index.d.ts.map +0 -0
  761. /package/{dist → ccw/dist}/types/index.js +0 -0
  762. /package/{dist → ccw/dist}/types/index.js.map +0 -0
  763. /package/{dist → ccw/dist}/types/session.d.ts +0 -0
  764. /package/{dist → ccw/dist}/types/session.d.ts.map +0 -0
  765. /package/{dist → ccw/dist}/types/session.js +0 -0
  766. /package/{dist → ccw/dist}/types/session.js.map +0 -0
  767. /package/{dist → ccw/dist}/types/tool.d.ts +0 -0
  768. /package/{dist → ccw/dist}/types/tool.d.ts.map +0 -0
  769. /package/{dist → ccw/dist}/types/tool.js +0 -0
  770. /package/{dist → ccw/dist}/types/tool.js.map +0 -0
  771. /package/{dist → ccw/dist}/utils/browser-launcher.d.ts +0 -0
  772. /package/{dist → ccw/dist}/utils/browser-launcher.d.ts.map +0 -0
  773. /package/{dist → ccw/dist}/utils/browser-launcher.js +0 -0
  774. /package/{dist → ccw/dist}/utils/browser-launcher.js.map +0 -0
  775. /package/{dist → ccw/dist}/utils/file-utils.d.ts +0 -0
  776. /package/{dist → ccw/dist}/utils/file-utils.d.ts.map +0 -0
  777. /package/{dist → ccw/dist}/utils/file-utils.js +0 -0
  778. /package/{dist → ccw/dist}/utils/file-utils.js.map +0 -0
  779. /package/{dist → ccw/dist}/utils/path-resolver.d.ts +0 -0
  780. /package/{dist → ccw/dist}/utils/path-resolver.d.ts.map +0 -0
  781. /package/{dist → ccw/dist}/utils/path-resolver.js +0 -0
  782. /package/{dist → ccw/dist}/utils/path-resolver.js.map +0 -0
  783. /package/{dist → ccw/dist}/utils/path-validator.d.ts +0 -0
  784. /package/{dist → ccw/dist}/utils/path-validator.d.ts.map +0 -0
  785. /package/{dist → ccw/dist}/utils/path-validator.js +0 -0
  786. /package/{dist → ccw/dist}/utils/path-validator.js.map +0 -0
  787. /package/{dist → ccw/dist}/utils/ui.d.ts +0 -0
  788. /package/{dist → ccw/dist}/utils/ui.d.ts.map +0 -0
  789. /package/{dist → ccw/dist}/utils/ui.js +0 -0
  790. /package/{dist → ccw/dist}/utils/ui.js.map +0 -0
  791. /package/{src → ccw/src}/.workflow/.cli-history/history.db +0 -0
  792. /package/{src → ccw/src}/.workflow/.cli-history/history.db-shm +0 -0
  793. /package/{src → ccw/src}/.workflow/.cli-history/history.db-wal +0 -0
  794. /package/{src → ccw/src}/cli.ts +0 -0
  795. /package/{src → ccw/src}/commands/cli.ts +0 -0
  796. /package/{src → ccw/src}/commands/core-memory.ts +0 -0
  797. /package/{src → ccw/src}/commands/hook.ts +0 -0
  798. /package/{src → ccw/src}/commands/install.ts +0 -0
  799. /package/{src → ccw/src}/commands/list.ts +0 -0
  800. /package/{src → ccw/src}/commands/memory.ts +0 -0
  801. /package/{src → ccw/src}/commands/serve.ts +0 -0
  802. /package/{src → ccw/src}/commands/session-path-resolver.ts +0 -0
  803. /package/{src → ccw/src}/commands/session.ts +0 -0
  804. /package/{src → ccw/src}/commands/stop.ts +0 -0
  805. /package/{src → ccw/src}/commands/tool.ts +0 -0
  806. /package/{src → ccw/src}/commands/uninstall.ts +0 -0
  807. /package/{src → ccw/src}/commands/upgrade.ts +0 -0
  808. /package/{src → ccw/src}/commands/view.ts +0 -0
  809. /package/{src → ccw/src}/config/storage-paths.ts +0 -0
  810. /package/{src → ccw/src}/core/cache-manager.ts +0 -0
  811. /package/{src → ccw/src}/core/claude-freshness.ts +0 -0
  812. /package/{src → ccw/src}/core/core-memory-store.ts +0 -0
  813. /package/{src → ccw/src}/core/dashboard-generator-patch.ts +0 -0
  814. /package/{src → ccw/src}/core/dashboard-generator.ts +0 -0
  815. /package/{src → ccw/src}/core/data-aggregator.ts +0 -0
  816. /package/{src → ccw/src}/core/history-importer.ts +0 -0
  817. /package/{src → ccw/src}/core/manifest.ts +0 -0
  818. /package/{src → ccw/src}/core/memory-embedder-bridge.ts +0 -0
  819. /package/{src → ccw/src}/core/memory-store.ts +0 -0
  820. /package/{src → ccw/src}/core/routes/ccw-routes.ts +0 -0
  821. /package/{src → ccw/src}/core/routes/codexlens-routes.ts +0 -0
  822. /package/{src → ccw/src}/core/routes/core-memory-routes.ts +0 -0
  823. /package/{src → ccw/src}/core/routes/files-routes.ts +0 -0
  824. /package/{src → ccw/src}/core/routes/graph-routes.md +0 -0
  825. /package/{src → ccw/src}/core/routes/graph-routes.ts +0 -0
  826. /package/{src → ccw/src}/core/routes/help-routes.ts +0 -0
  827. /package/{src → ccw/src}/core/routes/hooks-routes.ts +0 -0
  828. /package/{src → ccw/src}/core/routes/mcp-routes.ts +0 -0
  829. /package/{src → ccw/src}/core/routes/mcp-routes.ts.backup +0 -0
  830. /package/{src → ccw/src}/core/routes/mcp-templates-db.ts +0 -0
  831. /package/{src → ccw/src}/core/routes/memory-routes.ts +0 -0
  832. /package/{src → ccw/src}/core/routes/session-routes.ts +0 -0
  833. /package/{src → ccw/src}/core/routes/status-routes.ts +0 -0
  834. /package/{src → ccw/src}/core/routes/system-routes.ts +0 -0
  835. /package/{src → ccw/src}/core/server.ts +0 -0
  836. /package/{src → ccw/src}/core/session-clustering-service.ts +0 -0
  837. /package/{src → ccw/src}/core/session-scanner.ts +0 -0
  838. /package/{src → ccw/src}/core/websocket.ts +0 -0
  839. /package/{src → ccw/src}/index.ts +0 -0
  840. /package/{src → ccw/src}/mcp-server/index.ts +0 -0
  841. /package/{src → ccw/src}/templates/assets/css/github-dark.min.css +0 -0
  842. /package/{src → ccw/src}/templates/assets/css/github.min.css +0 -0
  843. /package/{src → ccw/src}/templates/assets/js/cytoscape.min.js +0 -0
  844. /package/{src → ccw/src}/templates/assets/js/d3.min.js +0 -0
  845. /package/{src → ccw/src}/templates/assets/js/highlight.min.js +0 -0
  846. /package/{src → ccw/src}/templates/assets/js/lucide.min.js +0 -0
  847. /package/{src → ccw/src}/templates/assets/js/marked.min.js +0 -0
  848. /package/{src → ccw/src}/templates/assets/js/tailwind.js +0 -0
  849. /package/{src → ccw/src}/templates/dashboard-css/01-base.css +0 -0
  850. /package/{src → ccw/src}/templates/dashboard-css/02-session.css +0 -0
  851. /package/{src → ccw/src}/templates/dashboard-css/03-tasks.css +0 -0
  852. /package/{src → ccw/src}/templates/dashboard-css/04-lite-tasks.css +0 -0
  853. /package/{src → ccw/src}/templates/dashboard-css/05-context.css +0 -0
  854. /package/{src → ccw/src}/templates/dashboard-css/06-cards.css +0 -0
  855. /package/{src → ccw/src}/templates/dashboard-css/07-managers.css +0 -0
  856. /package/{src → ccw/src}/templates/dashboard-css/08-review.css +0 -0
  857. /package/{src → ccw/src}/templates/dashboard-css/09-explorer.css +0 -0
  858. /package/{src → ccw/src}/templates/dashboard-css/10-cli-status.css +0 -0
  859. /package/{src → ccw/src}/templates/dashboard-css/11-cli-history.css +0 -0
  860. /package/{src → ccw/src}/templates/dashboard-css/12-cli-legacy.css +0 -0
  861. /package/{src → ccw/src}/templates/dashboard-css/13-cli-ccw.css +0 -0
  862. /package/{src → ccw/src}/templates/dashboard-css/14-cli-modals.css +0 -0
  863. /package/{src → ccw/src}/templates/dashboard-css/15-cli-endpoints.css +0 -0
  864. /package/{src → ccw/src}/templates/dashboard-css/16-cli-session.css +0 -0
  865. /package/{src → ccw/src}/templates/dashboard-css/17-cli-conversation.css +0 -0
  866. /package/{src → ccw/src}/templates/dashboard-css/18-cli-settings.css +0 -0
  867. /package/{src → ccw/src}/templates/dashboard-css/19-cli-native-session.css +0 -0
  868. /package/{src → ccw/src}/templates/dashboard-css/20-cli-taskqueue.css +0 -0
  869. /package/{src → ccw/src}/templates/dashboard-css/21-cli-toolmgmt.css +0 -0
  870. /package/{src → ccw/src}/templates/dashboard-css/22-cli-semantic.css +0 -0
  871. /package/{src → ccw/src}/templates/dashboard-css/23-memory.css +0 -0
  872. /package/{src → ccw/src}/templates/dashboard-css/24-prompt-history.css +0 -0
  873. /package/{src → ccw/src}/templates/dashboard-css/25-skills-rules.css +0 -0
  874. /package/{src → ccw/src}/templates/dashboard-css/26-claude-manager.css +0 -0
  875. /package/{src → ccw/src}/templates/dashboard-css/27-graph-explorer.css +0 -0
  876. /package/{src → ccw/src}/templates/dashboard-css/28-mcp-manager.css +0 -0
  877. /package/{src → ccw/src}/templates/dashboard-css/29-help.css +0 -0
  878. /package/{src → ccw/src}/templates/dashboard-css/30-core-memory.css +0 -0
  879. /package/{src → ccw/src}/templates/dashboard-js/api.js +0 -0
  880. /package/{src → ccw/src}/templates/dashboard-js/components/_conflict_tab.js +0 -0
  881. /package/{src → ccw/src}/templates/dashboard-js/components/_exp_helpers.js +0 -0
  882. /package/{src → ccw/src}/templates/dashboard-js/components/_review_tab.js +0 -0
  883. /package/{src → ccw/src}/templates/dashboard-js/components/carousel.js +0 -0
  884. /package/{src → ccw/src}/templates/dashboard-js/components/cli-history.js +0 -0
  885. /package/{src → ccw/src}/templates/dashboard-js/components/cli-status.js +0 -0
  886. /package/{src → ccw/src}/templates/dashboard-js/components/flowchart.js +0 -0
  887. /package/{src → ccw/src}/templates/dashboard-js/components/global-notifications.js +0 -0
  888. /package/{src → ccw/src}/templates/dashboard-js/components/hook-manager.js +0 -0
  889. /package/{src → ccw/src}/templates/dashboard-js/components/index-manager.js +0 -0
  890. /package/{src → ccw/src}/templates/dashboard-js/components/mcp-manager.js +0 -0
  891. /package/{src → ccw/src}/templates/dashboard-js/components/modals.js +0 -0
  892. /package/{src → ccw/src}/templates/dashboard-js/components/navigation.js +0 -0
  893. /package/{src → ccw/src}/templates/dashboard-js/components/notifications.js +0 -0
  894. /package/{src → ccw/src}/templates/dashboard-js/components/sidebar.js +0 -0
  895. /package/{src → ccw/src}/templates/dashboard-js/components/storage-manager.js +0 -0
  896. /package/{src → ccw/src}/templates/dashboard-js/components/tabs-context.js +0 -0
  897. /package/{src → ccw/src}/templates/dashboard-js/components/tabs-other.js +0 -0
  898. /package/{src → ccw/src}/templates/dashboard-js/components/task-drawer-core.js +0 -0
  899. /package/{src → ccw/src}/templates/dashboard-js/components/task-drawer-renderers.js +0 -0
  900. /package/{src → ccw/src}/templates/dashboard-js/components/task-queue-sidebar.js +0 -0
  901. /package/{src → ccw/src}/templates/dashboard-js/components/theme.js +0 -0
  902. /package/{src → ccw/src}/templates/dashboard-js/components/version-check.js +0 -0
  903. /package/{src → ccw/src}/templates/dashboard-js/help-i18n.js +0 -0
  904. /package/{src → ccw/src}/templates/dashboard-js/main.js +0 -0
  905. /package/{src → ccw/src}/templates/dashboard-js/state.js +0 -0
  906. /package/{src → ccw/src}/templates/dashboard-js/utils.js +0 -0
  907. /package/{src → ccw/src}/templates/dashboard-js/views/codexlens-manager.js +0 -0
  908. /package/{src → ccw/src}/templates/dashboard-js/views/core-memory-clusters.js +0 -0
  909. /package/{src → ccw/src}/templates/dashboard-js/views/core-memory.js +0 -0
  910. /package/{src → ccw/src}/templates/dashboard-js/views/explorer.js +0 -0
  911. /package/{src → ccw/src}/templates/dashboard-js/views/fix-session.js +0 -0
  912. /package/{src → ccw/src}/templates/dashboard-js/views/graph-explorer.js +0 -0
  913. /package/{src → ccw/src}/templates/dashboard-js/views/help.js +0 -0
  914. /package/{src → ccw/src}/templates/dashboard-js/views/history.js +0 -0
  915. /package/{src → ccw/src}/templates/dashboard-js/views/home.js +0 -0
  916. /package/{src → ccw/src}/templates/dashboard-js/views/hook-manager.js +0 -0
  917. /package/{src → ccw/src}/templates/dashboard-js/views/lite-tasks.js +0 -0
  918. /package/{src → ccw/src}/templates/dashboard-js/views/mcp-manager.js +0 -0
  919. /package/{src → ccw/src}/templates/dashboard-js/views/mcp-manager.js.backup +0 -0
  920. /package/{src → ccw/src}/templates/dashboard-js/views/mcp-manager.js.new +0 -0
  921. /package/{src → ccw/src}/templates/dashboard-js/views/memory.js +0 -0
  922. /package/{src → ccw/src}/templates/dashboard-js/views/project-overview.js +0 -0
  923. /package/{src → ccw/src}/templates/dashboard-js/views/prompt-history.js +0 -0
  924. /package/{src → ccw/src}/templates/dashboard-js/views/review-session.js +0 -0
  925. /package/{src → ccw/src}/templates/dashboard-js/views/session-detail.js +0 -0
  926. /package/{src → ccw/src}/templates/dashboard.html +0 -0
  927. /package/{src → ccw/src}/templates/hooks-config-example.json +0 -0
  928. /package/{src → ccw/src}/templates/review-cycle-dashboard.html +0 -0
  929. /package/{src → ccw/src}/templates/workflow-dashboard.html +0 -0
  930. /package/{src → ccw/src}/tools/classify-folders.ts +0 -0
  931. /package/{src → ccw/src}/tools/cli-config-manager.ts +0 -0
  932. /package/{src → ccw/src}/tools/cli-history-store.ts +0 -0
  933. /package/{src → ccw/src}/tools/codex-lens.ts +0 -0
  934. /package/{src → ccw/src}/tools/convert-tokens-to-css.ts +0 -0
  935. /package/{src → ccw/src}/tools/core-memory.ts +0 -0
  936. /package/{src → ccw/src}/tools/detect-changed-modules.ts +0 -0
  937. /package/{src → ccw/src}/tools/discover-design-files.ts +0 -0
  938. /package/{src → ccw/src}/tools/edit-file.ts +0 -0
  939. /package/{src → ccw/src}/tools/generate-module-docs.ts +0 -0
  940. /package/{src → ccw/src}/tools/get-modules-by-depth.ts +0 -0
  941. /package/{src → ccw/src}/tools/index.ts +0 -0
  942. /package/{src → ccw/src}/tools/native-session-discovery.ts +0 -0
  943. /package/{src → ccw/src}/tools/notifier.ts +0 -0
  944. /package/{src → ccw/src}/tools/read-file.ts +0 -0
  945. /package/{src → ccw/src}/tools/resume-strategy.ts +0 -0
  946. /package/{src → ccw/src}/tools/session-content-parser.ts +0 -0
  947. /package/{src → ccw/src}/tools/session-manager.ts +0 -0
  948. /package/{src → ccw/src}/tools/smart-context.ts +0 -0
  949. /package/{src → ccw/src}/tools/smart-search.ts +0 -0
  950. /package/{src → ccw/src}/tools/smart-search.ts.backup +0 -0
  951. /package/{src → ccw/src}/tools/storage-manager.ts +0 -0
  952. /package/{src → ccw/src}/tools/ui-generate-preview.js +0 -0
  953. /package/{src → ccw/src}/tools/ui-instantiate-prototypes.js +0 -0
  954. /package/{src → ccw/src}/tools/update-module-claude.js +0 -0
  955. /package/{src → ccw/src}/tools/write-file.ts +0 -0
  956. /package/{src → ccw/src}/types/config.ts +0 -0
  957. /package/{src → ccw/src}/types/index.ts +0 -0
  958. /package/{src → ccw/src}/types/session.ts +0 -0
  959. /package/{src → ccw/src}/types/tool.ts +0 -0
  960. /package/{src → ccw/src}/utils/browser-launcher.ts +0 -0
  961. /package/{src → ccw/src}/utils/file-utils.ts +0 -0
  962. /package/{src → ccw/src}/utils/path-resolver.ts +0 -0
  963. /package/{src → ccw/src}/utils/path-validator.ts +0 -0
  964. /package/{src → ccw/src}/utils/ui.ts +0 -0
@@ -0,0 +1,2082 @@
1
+ /**
2
+ * CLI Executor Tool - Unified execution for external CLI tools
3
+ * Supports Gemini, Qwen, and Codex with streaming output
4
+ */
5
+
6
+ import { z } from 'zod';
7
+ import type { ToolSchema, ToolResult } from '../types/tool.js';
8
+ import type { HistoryIndexEntry } from './cli-history-store.js';
9
+ import { spawn, ChildProcess } from 'child_process';
10
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, readdirSync, statSync } from 'fs';
11
+ import { join, relative } from 'path';
12
+
13
+ // Native resume support
14
+ import {
15
+ trackNewSession,
16
+ getNativeResumeArgs,
17
+ supportsNativeResume,
18
+ calculateProjectHash
19
+ } from './native-session-discovery.js';
20
+ import {
21
+ determineResumeStrategy,
22
+ buildContextPrefix,
23
+ getResumeModeDescription,
24
+ type ResumeDecision
25
+ } from './resume-strategy.js';
26
+ import {
27
+ isToolEnabled as isToolEnabledFromConfig,
28
+ enableTool as enableToolFromConfig,
29
+ disableTool as disableToolFromConfig,
30
+ getPrimaryModel
31
+ } from './cli-config-manager.js';
32
+ import { StoragePaths, ensureStorageDir } from '../config/storage-paths.js';
33
+
34
+ // Lazy-loaded SQLite store module
35
+ let sqliteStoreModule: typeof import('./cli-history-store.js') | null = null;
36
+
37
+ /**
38
+ * Get or initialize SQLite store (async)
39
+ */
40
+ async function getSqliteStore(baseDir: string) {
41
+ if (!sqliteStoreModule) {
42
+ sqliteStoreModule = await import('./cli-history-store.js');
43
+ }
44
+ return sqliteStoreModule.getHistoryStore(baseDir);
45
+ }
46
+
47
+ /**
48
+ * Get SQLite store (sync - uses cached module)
49
+ */
50
+ function getSqliteStoreSync(baseDir: string) {
51
+ if (!sqliteStoreModule) {
52
+ throw new Error('SQLite store not initialized. Call an async function first.');
53
+ }
54
+ return sqliteStoreModule.getHistoryStore(baseDir);
55
+ }
56
+
57
+ // Define Zod schema for validation
58
+ const ParamsSchema = z.object({
59
+ tool: z.enum(['gemini', 'qwen', 'codex']),
60
+ prompt: z.string().min(1, 'Prompt is required'),
61
+ mode: z.enum(['analysis', 'write', 'auto']).default('analysis'),
62
+ format: z.enum(['plain', 'yaml', 'json']).default('plain'), // Multi-turn prompt concatenation format
63
+ model: z.string().optional(),
64
+ cd: z.string().optional(),
65
+ includeDirs: z.string().optional(),
66
+ timeout: z.number().default(300000),
67
+ resume: z.union([z.boolean(), z.string()]).optional(), // true = last, string = single ID or comma-separated IDs
68
+ id: z.string().optional(), // Custom execution ID (e.g., IMPL-001-step1)
69
+ noNative: z.boolean().optional(), // Force prompt concatenation instead of native resume
70
+ category: z.enum(['user', 'internal', 'insight']).default('user'), // Execution category for tracking
71
+ parentExecutionId: z.string().optional(), // Parent execution ID for fork/retry scenarios
72
+ });
73
+
74
+ // Execution category types
75
+ export type ExecutionCategory = 'user' | 'internal' | 'insight';
76
+
77
+ type Params = z.infer<typeof ParamsSchema>;
78
+
79
+ // Prompt concatenation format types
80
+ type PromptFormat = 'plain' | 'yaml' | 'json';
81
+
82
+ interface ToolAvailability {
83
+ available: boolean;
84
+ path: string | null;
85
+ }
86
+
87
+ // Tool availability cache with TTL
88
+ interface CachedToolAvailability {
89
+ result: ToolAvailability;
90
+ timestamp: number;
91
+ }
92
+
93
+ // Cache storage: Map<toolName, CachedToolAvailability>
94
+ const toolAvailabilityCache = new Map<string, CachedToolAvailability>();
95
+ const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
96
+
97
+ /**
98
+ * Check if cache entry is still valid
99
+ */
100
+ function isCacheValid(cached: CachedToolAvailability): boolean {
101
+ return Date.now() - cached.timestamp < CACHE_TTL_MS;
102
+ }
103
+
104
+ /**
105
+ * Clear expired cache entries
106
+ */
107
+ function clearExpiredCache(): void {
108
+ const now = Date.now();
109
+ const entriesToDelete: string[] = [];
110
+
111
+ toolAvailabilityCache.forEach((cached, tool) => {
112
+ if (now - cached.timestamp >= CACHE_TTL_MS) {
113
+ entriesToDelete.push(tool);
114
+ }
115
+ });
116
+
117
+ entriesToDelete.forEach(tool => toolAvailabilityCache.delete(tool));
118
+ }
119
+
120
+ /**
121
+ * Clear all cache entries (useful for testing or forced refresh)
122
+ */
123
+ export function clearToolCache(): void {
124
+ toolAvailabilityCache.clear();
125
+ }
126
+
127
+ // Single turn in a conversation
128
+ interface ConversationTurn {
129
+ turn: number;
130
+ timestamp: string;
131
+ prompt: string;
132
+ duration_ms: number;
133
+ status: 'success' | 'error' | 'timeout';
134
+ exit_code: number | null;
135
+ output: {
136
+ stdout: string;
137
+ stderr: string;
138
+ truncated: boolean;
139
+ };
140
+ }
141
+
142
+ // Multi-turn conversation record
143
+ interface ConversationRecord {
144
+ id: string;
145
+ created_at: string;
146
+ updated_at: string;
147
+ tool: string;
148
+ model: string;
149
+ mode: string;
150
+ category: ExecutionCategory; // user | internal | insight
151
+ total_duration_ms: number;
152
+ turn_count: number;
153
+ latest_status: 'success' | 'error' | 'timeout';
154
+ turns: ConversationTurn[];
155
+ parent_execution_id?: string; // For fork/retry scenarios
156
+ }
157
+
158
+ // Legacy single execution record (for backward compatibility)
159
+ interface ExecutionRecord {
160
+ id: string;
161
+ timestamp: string;
162
+ tool: string;
163
+ model: string;
164
+ mode: string;
165
+ prompt: string;
166
+ status: 'success' | 'error' | 'timeout';
167
+ exit_code: number | null;
168
+ duration_ms: number;
169
+ output: {
170
+ stdout: string;
171
+ stderr: string;
172
+ truncated: boolean;
173
+ };
174
+ }
175
+
176
+ interface HistoryIndex {
177
+ version: number;
178
+ total_executions: number;
179
+ executions: {
180
+ id: string;
181
+ timestamp: string; // created_at for conversations
182
+ updated_at?: string; // last update time
183
+ tool: string;
184
+ status: string;
185
+ duration_ms: number;
186
+ turn_count?: number; // number of turns in conversation
187
+ prompt_preview: string;
188
+ }[];
189
+ }
190
+
191
+ interface ExecutionOutput {
192
+ success: boolean;
193
+ execution: ExecutionRecord;
194
+ conversation: ConversationRecord; // Full conversation record
195
+ stdout: string;
196
+ stderr: string;
197
+ }
198
+
199
+ /**
200
+ * Check if a CLI tool is available (with caching)
201
+ */
202
+ async function checkToolAvailability(tool: string): Promise<ToolAvailability> {
203
+ // Check cache first
204
+ const cached = toolAvailabilityCache.get(tool);
205
+ if (cached && isCacheValid(cached)) {
206
+ return cached.result;
207
+ }
208
+
209
+ // Clear expired entries periodically
210
+ clearExpiredCache();
211
+
212
+ // Perform actual check
213
+ return new Promise((resolve) => {
214
+ const isWindows = process.platform === 'win32';
215
+ const command = isWindows ? 'where' : 'which';
216
+
217
+ // Direct spawn - where/which are system commands that don't need shell wrapper
218
+ const child = spawn(command, [tool], {
219
+ shell: false,
220
+ stdio: ['ignore', 'pipe', 'pipe']
221
+ });
222
+
223
+ let stdout = '';
224
+ child.stdout!.on('data', (data) => { stdout += data.toString(); });
225
+
226
+ child.on('close', (code) => {
227
+ const result: ToolAvailability = code === 0 && stdout.trim()
228
+ ? { available: true, path: stdout.trim().split('\n')[0] }
229
+ : { available: false, path: null };
230
+
231
+ // Only cache positive results to avoid caching transient failures
232
+ if (result.available) {
233
+ toolAvailabilityCache.set(tool, {
234
+ result,
235
+ timestamp: Date.now()
236
+ });
237
+ }
238
+
239
+ resolve(result);
240
+ });
241
+
242
+ child.on('error', () => {
243
+ // Don't cache errors - they may be transient
244
+ resolve({ available: false, path: null });
245
+ });
246
+
247
+ // Timeout after 5 seconds
248
+ setTimeout(() => {
249
+ child.kill();
250
+ // Don't cache timeouts - they may be transient
251
+ resolve({ available: false, path: null });
252
+ }, 5000);
253
+ });
254
+ }
255
+
256
+ // Native resume configuration
257
+ interface NativeResumeConfig {
258
+ enabled: boolean;
259
+ sessionId?: string; // Native UUID
260
+ isLatest?: boolean; // Use latest/--last flag
261
+ }
262
+
263
+ /**
264
+ * Build command arguments based on tool and options
265
+ */
266
+ function buildCommand(params: {
267
+ tool: string;
268
+ prompt: string;
269
+ mode: string;
270
+ model?: string;
271
+ dir?: string;
272
+ include?: string;
273
+ nativeResume?: NativeResumeConfig;
274
+ }): { command: string; args: string[]; useStdin: boolean } {
275
+ const { tool, prompt, mode = 'analysis', model, dir, include, nativeResume } = params;
276
+
277
+ let command = tool;
278
+ let args: string[] = [];
279
+ // Default to stdin for all tools to avoid escaping issues on Windows
280
+ let useStdin = true;
281
+
282
+ switch (tool) {
283
+ case 'gemini':
284
+ // Native resume: gemini -r <uuid> or -r latest
285
+ if (nativeResume?.enabled) {
286
+ if (nativeResume.isLatest) {
287
+ args.push('-r', 'latest');
288
+ } else if (nativeResume.sessionId) {
289
+ args.push('-r', nativeResume.sessionId);
290
+ }
291
+ }
292
+ if (model) {
293
+ args.push('-m', model);
294
+ }
295
+ if (mode === 'write') {
296
+ args.push('--approval-mode', 'yolo');
297
+ }
298
+ if (include) {
299
+ args.push('--include-directories', include);
300
+ }
301
+ break;
302
+
303
+ case 'qwen':
304
+ // Native resume: qwen --continue (latest) or --resume <uuid>
305
+ if (nativeResume?.enabled) {
306
+ if (nativeResume.isLatest) {
307
+ args.push('--continue');
308
+ } else if (nativeResume.sessionId) {
309
+ args.push('--resume', nativeResume.sessionId);
310
+ }
311
+ }
312
+ if (model) {
313
+ args.push('-m', model);
314
+ }
315
+ if (mode === 'write') {
316
+ args.push('--approval-mode', 'yolo');
317
+ }
318
+ if (include) {
319
+ args.push('--include-directories', include);
320
+ }
321
+ break;
322
+
323
+ case 'codex':
324
+ // Codex supports stdin when using `-` as prompt argument
325
+ // Using stdin avoids Windows command line escaping issues with multi-line/special char prompts
326
+ useStdin = true;
327
+ // Native resume: codex resume <uuid> [prompt] or --last
328
+ if (nativeResume?.enabled) {
329
+ args.push('resume');
330
+ if (nativeResume.isLatest) {
331
+ args.push('--last');
332
+ } else if (nativeResume.sessionId) {
333
+ args.push(nativeResume.sessionId);
334
+ }
335
+ // Codex resume still supports additional flags
336
+ if (dir) {
337
+ args.push('-C', dir);
338
+ }
339
+ // Permission configuration based on mode:
340
+ // - analysis: --full-auto (read-only sandbox, no prompts) - safer for read operations
341
+ // - write/auto: --dangerously-bypass-approvals-and-sandbox (full access for modifications)
342
+ if (mode === 'write' || mode === 'auto') {
343
+ args.push('--dangerously-bypass-approvals-and-sandbox');
344
+ } else {
345
+ args.push('--full-auto');
346
+ }
347
+ if (model) {
348
+ args.push('-m', model);
349
+ }
350
+ if (include) {
351
+ const dirs = include.split(',').map(d => d.trim()).filter(d => d);
352
+ for (const addDir of dirs) {
353
+ args.push('--add-dir', addDir);
354
+ }
355
+ }
356
+ // Use `-` to indicate reading prompt from stdin
357
+ args.push('-');
358
+ } else {
359
+ // Standard exec mode
360
+ args.push('exec');
361
+ if (dir) {
362
+ args.push('-C', dir);
363
+ }
364
+ // Permission configuration based on mode:
365
+ // - analysis: --full-auto (read-only sandbox, no prompts) - safer for read operations
366
+ // - write/auto: --dangerously-bypass-approvals-and-sandbox (full access for modifications)
367
+ if (mode === 'write' || mode === 'auto') {
368
+ args.push('--dangerously-bypass-approvals-and-sandbox');
369
+ } else {
370
+ args.push('--full-auto');
371
+ }
372
+ if (model) {
373
+ args.push('-m', model);
374
+ }
375
+ if (include) {
376
+ const dirs = include.split(',').map(d => d.trim()).filter(d => d);
377
+ for (const addDir of dirs) {
378
+ args.push('--add-dir', addDir);
379
+ }
380
+ }
381
+ // Use `-` to indicate reading prompt from stdin (avoids Windows escaping issues)
382
+ args.push('-');
383
+ }
384
+ break;
385
+
386
+ case 'claude':
387
+ // Claude Code: claude -p "prompt" for non-interactive mode
388
+ args.push('-p'); // Print mode (non-interactive)
389
+ // Native resume: claude --resume <session-id> or --continue
390
+ if (nativeResume?.enabled) {
391
+ if (nativeResume.isLatest) {
392
+ args.push('--continue');
393
+ } else if (nativeResume.sessionId) {
394
+ args.push('--resume', nativeResume.sessionId);
395
+ }
396
+ }
397
+ if (model) {
398
+ args.push('--model', model);
399
+ }
400
+ // Permission modes: write/auto → bypassPermissions, analysis → default
401
+ if (mode === 'write' || mode === 'auto') {
402
+ args.push('--permission-mode', 'bypassPermissions');
403
+ } else {
404
+ args.push('--permission-mode', 'default');
405
+ }
406
+ // Output format for better parsing
407
+ args.push('--output-format', 'text');
408
+ // Add directories
409
+ if (include) {
410
+ const dirs = include.split(',').map(d => d.trim()).filter(d => d);
411
+ for (const addDir of dirs) {
412
+ args.push('--add-dir', addDir);
413
+ }
414
+ }
415
+ break;
416
+
417
+ default:
418
+ throw new Error(`Unknown CLI tool: ${tool}`);
419
+ }
420
+
421
+ return { command, args, useStdin };
422
+ }
423
+
424
+ /**
425
+ * Ensure history directory exists (uses centralized storage)
426
+ */
427
+ function ensureHistoryDir(baseDir: string): string {
428
+ const paths = StoragePaths.project(baseDir);
429
+ ensureStorageDir(paths.cliHistory);
430
+ return paths.cliHistory;
431
+ }
432
+
433
+ /**
434
+ * Save conversation to SQLite
435
+ * @param baseDir - Project base directory (NOT historyDir)
436
+ */
437
+ async function saveConversationAsync(baseDir: string, conversation: ConversationRecord): Promise<void> {
438
+ const store = await getSqliteStore(baseDir);
439
+ store.saveConversation(conversation);
440
+ }
441
+
442
+ /**
443
+ * Sync wrapper for saveConversation (uses cached SQLite module)
444
+ * @param baseDir - Project base directory (NOT historyDir)
445
+ */
446
+ function saveConversation(baseDir: string, conversation: ConversationRecord): void {
447
+ try {
448
+ const store = getSqliteStoreSync(baseDir);
449
+ store.saveConversation(conversation);
450
+ } catch {
451
+ // If sync not available, queue for async save
452
+ saveConversationAsync(baseDir, conversation).catch(err => {
453
+ console.error('[CLI Executor] Failed to save conversation:', err.message);
454
+ });
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Load existing conversation by ID from SQLite
460
+ * @param baseDir - Project base directory (NOT historyDir)
461
+ */
462
+ async function loadConversationAsync(baseDir: string, conversationId: string): Promise<ConversationRecord | null> {
463
+ const store = await getSqliteStore(baseDir);
464
+ return store.getConversation(conversationId);
465
+ }
466
+
467
+ /**
468
+ * Sync wrapper for loadConversation (uses cached SQLite module)
469
+ * @param baseDir - Project base directory (NOT historyDir)
470
+ */
471
+ function loadConversation(baseDir: string, conversationId: string): ConversationRecord | null {
472
+ try {
473
+ const store = getSqliteStoreSync(baseDir);
474
+ return store.getConversation(conversationId);
475
+ } catch {
476
+ // SQLite not initialized yet, return null
477
+ return null;
478
+ }
479
+ }
480
+
481
+ /**
482
+ * Convert legacy ExecutionRecord to ConversationRecord
483
+ */
484
+ function convertToConversation(record: ExecutionRecord): ConversationRecord {
485
+ return {
486
+ id: record.id,
487
+ created_at: record.timestamp,
488
+ updated_at: record.timestamp,
489
+ tool: record.tool,
490
+ model: record.model,
491
+ mode: record.mode,
492
+ category: 'user', // Legacy records default to user category
493
+ total_duration_ms: record.duration_ms,
494
+ turn_count: 1,
495
+ latest_status: record.status,
496
+ turns: [{
497
+ turn: 1,
498
+ timestamp: record.timestamp,
499
+ prompt: record.prompt,
500
+ duration_ms: record.duration_ms,
501
+ status: record.status,
502
+ exit_code: record.exit_code,
503
+ output: record.output
504
+ }]
505
+ };
506
+ }
507
+
508
+ /**
509
+ * Merge multiple conversations into a unified context
510
+ * Returns merged turns sorted by timestamp with source tracking
511
+ */
512
+ interface MergedTurn extends ConversationTurn {
513
+ source_id: string; // Original conversation ID
514
+ }
515
+
516
+ interface MergeResult {
517
+ mergedTurns: MergedTurn[];
518
+ sourceConversations: ConversationRecord[];
519
+ totalDuration: number;
520
+ }
521
+
522
+ function mergeConversations(conversations: ConversationRecord[]): MergeResult {
523
+ const mergedTurns: MergedTurn[] = [];
524
+
525
+ // Collect all turns with source tracking
526
+ for (const conv of conversations) {
527
+ for (const turn of conv.turns) {
528
+ mergedTurns.push({
529
+ ...turn,
530
+ source_id: conv.id
531
+ });
532
+ }
533
+ }
534
+
535
+ // Sort by timestamp
536
+ mergedTurns.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
537
+
538
+ // Re-number turns
539
+ mergedTurns.forEach((turn, idx) => {
540
+ turn.turn = idx + 1;
541
+ });
542
+
543
+ // Calculate total duration
544
+ const totalDuration = mergedTurns.reduce((sum, t) => sum + t.duration_ms, 0);
545
+
546
+ return {
547
+ mergedTurns,
548
+ sourceConversations: conversations,
549
+ totalDuration
550
+ };
551
+ }
552
+
553
+ /**
554
+ * Build prompt from merged conversations
555
+ */
556
+ function buildMergedPrompt(
557
+ mergeResult: MergeResult,
558
+ newPrompt: string,
559
+ format: PromptFormat = 'plain'
560
+ ): string {
561
+ const concatenator = createPromptConcatenator({ format });
562
+
563
+ // Set metadata for merged conversations
564
+ concatenator.setMetadata(
565
+ 'merged_sources',
566
+ mergeResult.sourceConversations.map(c => c.id).join(', ')
567
+ );
568
+
569
+ // Add all merged turns with source tracking
570
+ for (const turn of mergeResult.mergedTurns) {
571
+ concatenator.addFromConversationTurn(turn, turn.source_id);
572
+ }
573
+
574
+ return concatenator.build(newPrompt);
575
+ }
576
+
577
+ /**
578
+ * Execute CLI tool with streaming output
579
+ */
580
+ async function executeCliTool(
581
+ params: Record<string, unknown>,
582
+ onOutput?: ((data: { type: string; data: string }) => void) | null
583
+ ): Promise<ExecutionOutput> {
584
+ const parsed = ParamsSchema.safeParse(params);
585
+ if (!parsed.success) {
586
+ throw new Error(`Invalid params: ${parsed.error.message}`);
587
+ }
588
+
589
+ const { tool, prompt, mode, format, model, cd, includeDirs, timeout, resume, id: customId, noNative, category, parentExecutionId } = parsed.data;
590
+
591
+ // Determine working directory early (needed for conversation lookup)
592
+ const workingDir = cd || process.cwd();
593
+ ensureHistoryDir(workingDir); // Ensure history directory exists
594
+
595
+ // Get SQLite store for native session lookup
596
+ const store = await getSqliteStore(workingDir);
597
+
598
+ // Determine conversation ID and load existing conversation
599
+ // Logic:
600
+ // - If --resume <id1,id2,...> (multiple IDs): merge conversations
601
+ // - With --id: create new merged conversation
602
+ // - Without --id: append to ALL source conversations
603
+ // - If --resume <id> AND --id <newId>: fork - read context from resume ID, create new conversation with newId
604
+ // - If --id provided (no resume): use that ID (create new or append)
605
+ // - If --resume <id> without --id: use resume ID (append to existing)
606
+ // - No params: create new with auto-generated ID
607
+ let conversationId: string;
608
+ let existingConversation: ConversationRecord | null = null;
609
+ let contextConversation: ConversationRecord | null = null; // For fork scenario
610
+ let mergeResult: MergeResult | null = null; // For merge scenario
611
+ let sourceConversations: ConversationRecord[] = []; // All source conversations for merge
612
+
613
+ // Parse resume IDs (can be comma-separated for merge)
614
+ const resumeIds: string[] = resume
615
+ ? (typeof resume === 'string' ? resume.split(',').map(id => id.trim()).filter(Boolean) : [])
616
+ : [];
617
+ const isMerge = resumeIds.length > 1;
618
+ const resumeId = resumeIds.length === 1 ? resumeIds[0] : null;
619
+
620
+ if (isMerge) {
621
+ // Merge scenario: multiple resume IDs
622
+ sourceConversations = resumeIds
623
+ .map(id => loadConversation(workingDir, id))
624
+ .filter((c): c is ConversationRecord => c !== null);
625
+
626
+ if (sourceConversations.length === 0) {
627
+ throw new Error('No valid conversations found for merge');
628
+ }
629
+
630
+ mergeResult = mergeConversations(sourceConversations);
631
+
632
+ if (customId) {
633
+ // Create new merged conversation with custom ID
634
+ conversationId = customId;
635
+ existingConversation = loadConversation(workingDir, customId);
636
+ } else {
637
+ // Will append to ALL source conversations (handled in save logic)
638
+ // Use first source conversation ID as primary
639
+ conversationId = sourceConversations[0].id;
640
+ existingConversation = sourceConversations[0];
641
+ }
642
+ } else if (customId && resumeId) {
643
+ // Fork: read context from resume ID, but create new conversation with custom ID
644
+ conversationId = customId;
645
+ contextConversation = loadConversation(workingDir, resumeId);
646
+ existingConversation = loadConversation(workingDir, customId);
647
+ } else if (customId) {
648
+ // Use custom ID - may be new or existing
649
+ conversationId = customId;
650
+ existingConversation = loadConversation(workingDir, customId);
651
+ } else if (resumeId) {
652
+ // Resume single ID without new ID - append to existing conversation
653
+ conversationId = resumeId;
654
+ existingConversation = loadConversation(workingDir, resumeId);
655
+ } else if (resume) {
656
+ // resume=true: get last conversation for this tool
657
+ const history = getExecutionHistory(workingDir, { limit: 1, tool });
658
+ if (history.executions.length > 0) {
659
+ conversationId = history.executions[0].id;
660
+ existingConversation = loadConversation(workingDir, conversationId);
661
+ } else {
662
+ // No previous conversation, create new
663
+ conversationId = `${Date.now()}-${tool}`;
664
+ }
665
+ } else {
666
+ // New conversation with auto-generated ID
667
+ conversationId = `${Date.now()}-${tool}`;
668
+ }
669
+
670
+ // Determine resume strategy (native vs prompt-concat vs hybrid)
671
+ let resumeDecision: ResumeDecision | null = null;
672
+ let nativeResumeConfig: NativeResumeConfig | undefined;
673
+
674
+ // resume=true (latest) - use native latest if supported
675
+ if (resume === true && !noNative && supportsNativeResume(tool)) {
676
+ resumeDecision = {
677
+ strategy: 'native',
678
+ isLatest: true,
679
+ primaryConversationId: conversationId
680
+ };
681
+ }
682
+ // Use strategy engine for complex scenarios
683
+ else if (resumeIds.length > 0 && !noNative) {
684
+ resumeDecision = determineResumeStrategy({
685
+ tool,
686
+ resumeIds,
687
+ customId,
688
+ forcePromptConcat: noNative,
689
+ getNativeSessionId: (ccwId) => store.getNativeSessionId(ccwId),
690
+ getConversation: (ccwId) => loadConversation(workingDir, ccwId),
691
+ getConversationTool: (ccwId) => {
692
+ const conv = loadConversation(workingDir, ccwId);
693
+ return conv?.tool || null;
694
+ }
695
+ });
696
+ }
697
+
698
+ // Configure native resume if strategy decided to use it
699
+ if (resumeDecision && (resumeDecision.strategy === 'native' || resumeDecision.strategy === 'hybrid')) {
700
+ nativeResumeConfig = {
701
+ enabled: true,
702
+ sessionId: resumeDecision.nativeSessionId,
703
+ isLatest: resumeDecision.isLatest
704
+ };
705
+ }
706
+
707
+ // Build final prompt with conversation context
708
+ // For native: minimal prompt (native tool handles context)
709
+ // For hybrid: context prefix from other conversations + new prompt
710
+ // For prompt-concat: full multi-turn prompt
711
+ let finalPrompt = prompt;
712
+
713
+ if (resumeDecision?.strategy === 'native') {
714
+ // Native mode: just use the new prompt, tool handles context
715
+ finalPrompt = prompt;
716
+ } else if (resumeDecision?.strategy === 'hybrid' && resumeDecision.contextTurns?.length) {
717
+ // Hybrid mode: add context prefix from other conversations
718
+ const contextPrefix = buildContextPrefix(resumeDecision.contextTurns, format);
719
+ finalPrompt = contextPrefix + prompt;
720
+ } else if (mergeResult && mergeResult.mergedTurns.length > 0) {
721
+ // Full merge: use merged prompt
722
+ finalPrompt = buildMergedPrompt(mergeResult, prompt, format);
723
+ } else {
724
+ // Standard prompt-concat
725
+ const conversationForContext = contextConversation || existingConversation;
726
+ if (conversationForContext && conversationForContext.turns.length > 0) {
727
+ finalPrompt = buildMultiTurnPrompt(conversationForContext, prompt, format);
728
+ }
729
+ }
730
+
731
+ // Check tool availability
732
+ const toolStatus = await checkToolAvailability(tool);
733
+ if (!toolStatus.available) {
734
+ throw new Error(`CLI tool not available: ${tool}. Please ensure it is installed and in PATH.`);
735
+ }
736
+
737
+ // Log resume mode for debugging
738
+ if (resumeDecision) {
739
+ const modeDesc = getResumeModeDescription(resumeDecision);
740
+ if (onOutput) {
741
+ onOutput({ type: 'stderr', data: `[Resume mode: ${modeDesc}]\n` });
742
+ }
743
+ }
744
+
745
+ // Use configured primary model if no explicit model provided
746
+ const effectiveModel = model || getPrimaryModel(workingDir, tool);
747
+
748
+ // Build command
749
+ const { command, args, useStdin } = buildCommand({
750
+ tool,
751
+ prompt: finalPrompt,
752
+ mode,
753
+ model: effectiveModel,
754
+ dir: cd,
755
+ include: includeDirs,
756
+ nativeResume: nativeResumeConfig
757
+ });
758
+
759
+ const startTime = Date.now();
760
+
761
+ return new Promise((resolve, reject) => {
762
+ // Windows requires shell: true for npm global commands (.cmd files)
763
+ // Unix-like systems can use shell: false for direct execution
764
+ const isWindows = process.platform === 'win32';
765
+ const child = spawn(command, args, {
766
+ cwd: workingDir,
767
+ shell: isWindows, // Enable shell on Windows for .cmd files
768
+ stdio: [useStdin ? 'pipe' : 'ignore', 'pipe', 'pipe']
769
+ });
770
+
771
+ // Write prompt to stdin if using stdin mode (for gemini/qwen)
772
+ if (useStdin && child.stdin) {
773
+ child.stdin.write(finalPrompt);
774
+ child.stdin.end();
775
+ }
776
+
777
+ let stdout = '';
778
+ let stderr = '';
779
+ let timedOut = false;
780
+
781
+ // Handle stdout
782
+ child.stdout!.on('data', (data) => {
783
+ const text = data.toString();
784
+ stdout += text;
785
+ if (onOutput) {
786
+ onOutput({ type: 'stdout', data: text });
787
+ }
788
+ });
789
+
790
+ // Handle stderr
791
+ child.stderr!.on('data', (data) => {
792
+ const text = data.toString();
793
+ stderr += text;
794
+ if (onOutput) {
795
+ onOutput({ type: 'stderr', data: text });
796
+ }
797
+ });
798
+
799
+ // Handle completion
800
+ child.on('close', async (code) => {
801
+ const endTime = Date.now();
802
+ const duration = endTime - startTime;
803
+
804
+ // Determine status
805
+ let status: 'success' | 'error' | 'timeout' = 'success';
806
+ if (timedOut) {
807
+ status = 'timeout';
808
+ } else if (code !== 0) {
809
+ // Check if HTTP 429 but results exist (Gemini quirk)
810
+ if (stderr.includes('429') && stdout.trim()) {
811
+ status = 'success';
812
+ } else {
813
+ status = 'error';
814
+ }
815
+ }
816
+
817
+ // Create new turn
818
+ const newTurnOutput = {
819
+ stdout: stdout.substring(0, 10240), // Truncate to 10KB
820
+ stderr: stderr.substring(0, 2048), // Truncate to 2KB
821
+ truncated: stdout.length > 10240 || stderr.length > 2048
822
+ };
823
+
824
+ // Determine base turn number for merge scenarios
825
+ const baseTurnNumber = isMerge && mergeResult
826
+ ? mergeResult.mergedTurns.length + 1
827
+ : (existingConversation ? existingConversation.turns.length + 1 : 1);
828
+
829
+ const newTurn: ConversationTurn = {
830
+ turn: baseTurnNumber,
831
+ timestamp: new Date(startTime).toISOString(),
832
+ prompt,
833
+ duration_ms: duration,
834
+ status,
835
+ exit_code: code,
836
+ output: newTurnOutput
837
+ };
838
+
839
+ // Create or update conversation record
840
+ let conversation: ConversationRecord;
841
+
842
+ if (isMerge && mergeResult && !customId) {
843
+ // Merge without --id: append to ALL source conversations
844
+ // Save new turn to each source conversation
845
+ const savedConversations: ConversationRecord[] = [];
846
+ for (const srcConv of sourceConversations) {
847
+ const turnForSrc: ConversationTurn = {
848
+ ...newTurn,
849
+ turn: srcConv.turns.length + 1 // Use each conversation's turn count
850
+ };
851
+ const updatedConv: ConversationRecord = {
852
+ ...srcConv,
853
+ updated_at: new Date().toISOString(),
854
+ total_duration_ms: srcConv.total_duration_ms + duration,
855
+ turn_count: srcConv.turns.length + 1,
856
+ latest_status: status,
857
+ turns: [...srcConv.turns, turnForSrc]
858
+ };
859
+ savedConversations.push(updatedConv);
860
+ }
861
+ // Use first conversation as primary
862
+ conversation = savedConversations[0];
863
+ // Save all source conversations
864
+ try {
865
+ for (const conv of savedConversations) {
866
+ saveConversation(workingDir, conv);
867
+ }
868
+ } catch (err) {
869
+ console.error('[CLI Executor] Failed to save merged histories:', (err as Error).message);
870
+ }
871
+ } else if (isMerge && mergeResult && customId) {
872
+ // Merge with --id: create new conversation with merged turns + new turn
873
+ // Convert merged turns to regular turns (without source_id)
874
+ const mergedTurns: ConversationTurn[] = mergeResult.mergedTurns.map((mt, idx) => ({
875
+ turn: idx + 1,
876
+ timestamp: mt.timestamp,
877
+ prompt: mt.prompt,
878
+ duration_ms: mt.duration_ms,
879
+ status: mt.status,
880
+ exit_code: mt.exit_code,
881
+ output: mt.output
882
+ }));
883
+
884
+ conversation = existingConversation
885
+ ? {
886
+ ...existingConversation,
887
+ updated_at: new Date().toISOString(),
888
+ total_duration_ms: existingConversation.total_duration_ms + duration,
889
+ turn_count: existingConversation.turns.length + 1,
890
+ latest_status: status,
891
+ turns: [...existingConversation.turns, newTurn]
892
+ }
893
+ : {
894
+ id: conversationId,
895
+ created_at: new Date(startTime).toISOString(),
896
+ updated_at: new Date().toISOString(),
897
+ tool,
898
+ model: model || 'default',
899
+ mode,
900
+ category,
901
+ total_duration_ms: mergeResult.totalDuration + duration,
902
+ turn_count: mergedTurns.length + 1,
903
+ latest_status: status,
904
+ turns: [...mergedTurns, newTurn]
905
+ };
906
+ // Save merged conversation
907
+ try {
908
+ saveConversation(workingDir, conversation);
909
+ } catch (err) {
910
+ console.error('[CLI Executor] Failed to save merged conversation:', (err as Error).message);
911
+ }
912
+ } else {
913
+ // Normal scenario: single conversation
914
+ conversation = existingConversation
915
+ ? {
916
+ ...existingConversation,
917
+ updated_at: new Date().toISOString(),
918
+ total_duration_ms: existingConversation.total_duration_ms + duration,
919
+ turn_count: existingConversation.turns.length + 1,
920
+ latest_status: status,
921
+ turns: [...existingConversation.turns, newTurn]
922
+ }
923
+ : {
924
+ id: conversationId,
925
+ created_at: new Date(startTime).toISOString(),
926
+ updated_at: new Date().toISOString(),
927
+ tool,
928
+ model: model || 'default',
929
+ mode,
930
+ category,
931
+ total_duration_ms: duration,
932
+ turn_count: 1,
933
+ latest_status: status,
934
+ turns: [newTurn],
935
+ parent_execution_id: parentExecutionId
936
+ };
937
+ // Try to save conversation to history
938
+ try {
939
+ saveConversation(workingDir, conversation);
940
+ } catch (err) {
941
+ // Non-fatal: continue even if history save fails
942
+ console.error('[CLI Executor] Failed to save history:', (err as Error).message);
943
+ }
944
+ }
945
+
946
+ // Track native session after execution (awaited to prevent process hang)
947
+ // Pass prompt for precise matching in parallel execution scenarios
948
+ try {
949
+ const nativeSession = await trackNewSession(tool, new Date(startTime), workingDir, prompt);
950
+ if (nativeSession) {
951
+ // Save native session mapping
952
+ try {
953
+ store.saveNativeSessionMapping({
954
+ ccw_id: conversationId,
955
+ tool,
956
+ native_session_id: nativeSession.sessionId,
957
+ native_session_path: nativeSession.filePath,
958
+ project_hash: nativeSession.projectHash,
959
+ created_at: new Date().toISOString()
960
+ });
961
+ } catch (err) {
962
+ console.error('[CLI Executor] Failed to save native session mapping:', (err as Error).message);
963
+ }
964
+ }
965
+ } catch (err) {
966
+ console.error('[CLI Executor] Failed to track native session:', (err as Error).message);
967
+ }
968
+
969
+ // Create legacy execution record for backward compatibility
970
+ const execution: ExecutionRecord = {
971
+ id: conversationId,
972
+ timestamp: new Date(startTime).toISOString(),
973
+ tool,
974
+ model: model || 'default',
975
+ mode,
976
+ prompt,
977
+ status,
978
+ exit_code: code,
979
+ duration_ms: duration,
980
+ output: newTurnOutput
981
+ };
982
+
983
+ resolve({
984
+ success: status === 'success',
985
+ execution,
986
+ conversation,
987
+ stdout,
988
+ stderr
989
+ });
990
+ });
991
+
992
+ // Handle errors
993
+ child.on('error', (error) => {
994
+ reject(new Error(`Failed to spawn ${tool}: ${error.message}`));
995
+ });
996
+
997
+ // Timeout handling
998
+ const timeoutId = setTimeout(() => {
999
+ timedOut = true;
1000
+ child.kill('SIGTERM');
1001
+ setTimeout(() => {
1002
+ if (!child.killed) {
1003
+ child.kill('SIGKILL');
1004
+ }
1005
+ }, 5000);
1006
+ }, timeout);
1007
+
1008
+ child.on('close', () => {
1009
+ clearTimeout(timeoutId);
1010
+ });
1011
+ });
1012
+ }
1013
+
1014
+ // Tool schema for MCP
1015
+ export const schema: ToolSchema = {
1016
+ name: 'cli_executor',
1017
+ description: `Execute external CLI tools (gemini/qwen/codex) with unified interface.
1018
+ Modes:
1019
+ - analysis: Read-only operations (default)
1020
+ - write: File modifications allowed
1021
+ - auto: Full autonomous operations (codex only)`,
1022
+ inputSchema: {
1023
+ type: 'object',
1024
+ properties: {
1025
+ tool: {
1026
+ type: 'string',
1027
+ enum: ['gemini', 'qwen', 'codex'],
1028
+ description: 'CLI tool to execute'
1029
+ },
1030
+ prompt: {
1031
+ type: 'string',
1032
+ description: 'Prompt to send to the CLI tool'
1033
+ },
1034
+ mode: {
1035
+ type: 'string',
1036
+ enum: ['analysis', 'write', 'auto'],
1037
+ description: 'Execution mode (default: analysis)',
1038
+ default: 'analysis'
1039
+ },
1040
+ model: {
1041
+ type: 'string',
1042
+ description: 'Model override (tool-specific)'
1043
+ },
1044
+ cd: {
1045
+ type: 'string',
1046
+ description: 'Working directory for execution (-C for codex)'
1047
+ },
1048
+ includeDirs: {
1049
+ type: 'string',
1050
+ description: 'Additional directories (comma-separated). Maps to --include-directories for gemini/qwen, --add-dir for codex'
1051
+ },
1052
+ timeout: {
1053
+ type: 'number',
1054
+ description: 'Timeout in milliseconds (default: 300000 = 5 minutes)',
1055
+ default: 300000
1056
+ }
1057
+ },
1058
+ required: ['tool', 'prompt']
1059
+ }
1060
+ };
1061
+
1062
+ // Handler function
1063
+ export async function handler(params: Record<string, unknown>): Promise<ToolResult<ExecutionOutput>> {
1064
+ try {
1065
+ const result = await executeCliTool(params);
1066
+ return {
1067
+ success: result.success,
1068
+ result
1069
+ };
1070
+ } catch (error) {
1071
+ return {
1072
+ success: false,
1073
+ error: `CLI execution failed: ${(error as Error).message}`
1074
+ };
1075
+ }
1076
+ }
1077
+
1078
+ /**
1079
+ * Find all project directories with CLI history in centralized storage
1080
+ * Returns list of project base directories (NOT history directories)
1081
+ */
1082
+ function findProjectsWithHistory(): string[] {
1083
+ const projectDirs: string[] = [];
1084
+ const projectsRoot = join(StoragePaths.global.root(), 'projects');
1085
+
1086
+ if (!existsSync(projectsRoot)) {
1087
+ return projectDirs;
1088
+ }
1089
+
1090
+ try {
1091
+ const entries = readdirSync(projectsRoot, { withFileTypes: true });
1092
+ for (const entry of entries) {
1093
+ if (entry.isDirectory()) {
1094
+ const paths = StoragePaths.projectById(entry.name);
1095
+ if (existsSync(paths.historyDb)) {
1096
+ // Return project ID as identifier (actual project path is hashed)
1097
+ projectDirs.push(entry.name);
1098
+ }
1099
+ }
1100
+ }
1101
+ } catch {
1102
+ // Ignore permission errors
1103
+ }
1104
+
1105
+ return projectDirs;
1106
+ }
1107
+
1108
+ /**
1109
+ * Get execution history from SQLite (centralized storage)
1110
+ */
1111
+ export async function getExecutionHistoryAsync(baseDir: string, options: {
1112
+ limit?: number;
1113
+ tool?: string | null;
1114
+ status?: string | null;
1115
+ category?: ExecutionCategory | null;
1116
+ search?: string | null;
1117
+ recursive?: boolean;
1118
+ } = {}): Promise<{
1119
+ total: number;
1120
+ count: number;
1121
+ executions: (HistoryIndex['executions'][0] & { sourceDir?: string })[];
1122
+ }> {
1123
+ const { limit = 50, tool = null, status = null, category = null, search = null, recursive = false } = options;
1124
+
1125
+ // Recursive mode: aggregate data from parent and all child projects
1126
+ if (recursive) {
1127
+ const { scanChildProjectsAsync } = await import('../config/storage-paths.js');
1128
+ const childProjects = await scanChildProjectsAsync(baseDir);
1129
+
1130
+ let allExecutions: (HistoryIndex['executions'][0] & { sourceDir?: string })[] = [];
1131
+ let totalCount = 0;
1132
+
1133
+ // Query parent project - apply limit at source to reduce memory footprint
1134
+ try {
1135
+ const parentStore = await getSqliteStore(baseDir);
1136
+ const parentResult = parentStore.getHistory({ limit, tool, status, category, search });
1137
+ totalCount += parentResult.total;
1138
+
1139
+ for (const exec of parentResult.executions) {
1140
+ allExecutions.push({ ...exec, sourceDir: baseDir });
1141
+ }
1142
+ } catch (error) {
1143
+ if (process.env.DEBUG) {
1144
+ console.error(`[CLI History] Failed to query parent project ${baseDir}:`, error);
1145
+ }
1146
+ }
1147
+
1148
+ // Query all child projects - apply limit to each child
1149
+ for (const child of childProjects) {
1150
+ try {
1151
+ const childStore = await getSqliteStore(child.projectPath);
1152
+ const childResult = childStore.getHistory({ limit, tool, status, category, search });
1153
+ totalCount += childResult.total;
1154
+
1155
+ for (const exec of childResult.executions) {
1156
+ allExecutions.push({
1157
+ ...exec,
1158
+ sourceDir: child.relativePath // Show relative path for clarity
1159
+ });
1160
+ }
1161
+ } catch (error) {
1162
+ if (process.env.DEBUG) {
1163
+ console.error(`[CLI History] Failed to query child project ${child.projectPath}:`, error);
1164
+ }
1165
+ }
1166
+ }
1167
+
1168
+ // Sort by timestamp (newest first) and apply limit
1169
+ allExecutions.sort((a, b) => Number(b.timestamp) - Number(a.timestamp));
1170
+ const limitedExecutions = allExecutions.slice(0, limit);
1171
+
1172
+ return {
1173
+ total: totalCount,
1174
+ count: limitedExecutions.length,
1175
+ executions: limitedExecutions
1176
+ };
1177
+ }
1178
+
1179
+ // Non-recursive mode: only query current project
1180
+ const store = await getSqliteStore(baseDir);
1181
+ return store.getHistory({ limit, tool, status, category, search });
1182
+ }
1183
+
1184
+ /**
1185
+ * Get execution history (sync version - uses cached SQLite module)
1186
+ */
1187
+ export function getExecutionHistory(baseDir: string, options: {
1188
+ limit?: number;
1189
+ tool?: string | null;
1190
+ status?: string | null;
1191
+ recursive?: boolean;
1192
+ } = {}): {
1193
+ total: number;
1194
+ count: number;
1195
+ executions: (HistoryIndex['executions'][0] & { sourceDir?: string })[];
1196
+ } {
1197
+ const { limit = 50, tool = null, status = null, recursive = false } = options;
1198
+
1199
+ try {
1200
+ if (recursive) {
1201
+ const { scanChildProjects } = require('../config/storage-paths.js');
1202
+ const childProjects = scanChildProjects(baseDir);
1203
+
1204
+ let allExecutions: (HistoryIndex['executions'][0] & { sourceDir?: string })[] = [];
1205
+ let totalCount = 0;
1206
+
1207
+ // Query parent project - apply limit at source
1208
+ try {
1209
+ const parentStore = getSqliteStoreSync(baseDir);
1210
+ const parentResult = parentStore.getHistory({ limit, tool, status });
1211
+ totalCount += parentResult.total;
1212
+
1213
+ for (const exec of parentResult.executions) {
1214
+ allExecutions.push({ ...exec, sourceDir: baseDir });
1215
+ }
1216
+ } catch (error) {
1217
+ if (process.env.DEBUG) {
1218
+ console.error(`[CLI History Sync] Failed to query parent project ${baseDir}:`, error);
1219
+ }
1220
+ }
1221
+
1222
+ // Query all child projects - apply limit to each child
1223
+ for (const child of childProjects) {
1224
+ try {
1225
+ const childStore = getSqliteStoreSync(child.projectPath);
1226
+ const childResult = childStore.getHistory({ limit, tool, status });
1227
+ totalCount += childResult.total;
1228
+
1229
+ for (const exec of childResult.executions) {
1230
+ allExecutions.push({
1231
+ ...exec,
1232
+ sourceDir: child.relativePath
1233
+ });
1234
+ }
1235
+ } catch (error) {
1236
+ if (process.env.DEBUG) {
1237
+ console.error(`[CLI History Sync] Failed to query child project ${child.projectPath}:`, error);
1238
+ }
1239
+ }
1240
+ }
1241
+
1242
+ // Sort by timestamp (newest first) and apply limit
1243
+ allExecutions.sort((a, b) => Number(b.timestamp) - Number(a.timestamp));
1244
+
1245
+ return {
1246
+ total: totalCount,
1247
+ count: Math.min(allExecutions.length, limit),
1248
+ executions: allExecutions.slice(0, limit)
1249
+ };
1250
+ }
1251
+
1252
+ const store = getSqliteStoreSync(baseDir);
1253
+ return store.getHistory({ limit, tool, status });
1254
+ } catch {
1255
+ // SQLite not initialized, return empty
1256
+ return { total: 0, count: 0, executions: [] };
1257
+ }
1258
+ }
1259
+
1260
+ /**
1261
+ * Get conversation detail by ID (returns ConversationRecord)
1262
+ */
1263
+ export function getConversationDetail(baseDir: string, conversationId: string): ConversationRecord | null {
1264
+ // Pass baseDir directly - loadConversation will resolve the correct storage path
1265
+ return loadConversation(baseDir, conversationId);
1266
+ }
1267
+
1268
+ /**
1269
+ * Get conversation detail with native session info
1270
+ */
1271
+ export function getConversationDetailWithNativeInfo(baseDir: string, conversationId: string) {
1272
+ try {
1273
+ const store = getSqliteStoreSync(baseDir);
1274
+ return store.getConversationWithNativeInfo(conversationId);
1275
+ } catch {
1276
+ // SQLite not initialized, return null
1277
+ return null;
1278
+ }
1279
+ }
1280
+
1281
+ /**
1282
+ * Get execution detail by ID (legacy, returns ExecutionRecord for backward compatibility)
1283
+ */
1284
+ export function getExecutionDetail(baseDir: string, executionId: string): ExecutionRecord | null {
1285
+ const conversation = getConversationDetail(baseDir, executionId);
1286
+ if (!conversation) return null;
1287
+
1288
+ // Convert to legacy ExecutionRecord format (using latest turn)
1289
+ const latestTurn = conversation.turns[conversation.turns.length - 1];
1290
+ return {
1291
+ id: conversation.id,
1292
+ timestamp: conversation.created_at,
1293
+ tool: conversation.tool,
1294
+ model: conversation.model,
1295
+ mode: conversation.mode,
1296
+ prompt: latestTurn.prompt,
1297
+ status: conversation.latest_status,
1298
+ exit_code: latestTurn.exit_code,
1299
+ duration_ms: conversation.total_duration_ms,
1300
+ output: latestTurn.output
1301
+ };
1302
+ }
1303
+
1304
+ /**
1305
+ * Delete execution by ID (async version)
1306
+ */
1307
+ export async function deleteExecutionAsync(baseDir: string, executionId: string): Promise<{ success: boolean; error?: string }> {
1308
+ const store = await getSqliteStore(baseDir);
1309
+ return store.deleteConversation(executionId);
1310
+ }
1311
+
1312
+ /**
1313
+ * Delete execution by ID (sync version - uses cached SQLite module)
1314
+ */
1315
+ export function deleteExecution(baseDir: string, executionId: string): { success: boolean; error?: string } {
1316
+ try {
1317
+ const store = getSqliteStoreSync(baseDir);
1318
+ return store.deleteConversation(executionId);
1319
+ } catch {
1320
+ return { success: false, error: 'SQLite store not initialized' };
1321
+ }
1322
+ }
1323
+
1324
+ /**
1325
+ * Batch delete executions (async)
1326
+ */
1327
+ export async function batchDeleteExecutionsAsync(baseDir: string, ids: string[]): Promise<{
1328
+ success: boolean;
1329
+ deleted: number;
1330
+ total: number;
1331
+ errors?: string[];
1332
+ }> {
1333
+ const store = await getSqliteStore(baseDir);
1334
+ const result = store.batchDelete(ids);
1335
+ return { ...result, total: ids.length };
1336
+ }
1337
+
1338
+ /**
1339
+ * Get status of all CLI tools
1340
+ */
1341
+ export async function getCliToolsStatus(): Promise<Record<string, ToolAvailability>> {
1342
+ const tools = ['gemini', 'qwen', 'codex', 'claude'];
1343
+ const results: Record<string, ToolAvailability> = {};
1344
+
1345
+ await Promise.all(tools.map(async (tool) => {
1346
+ results[tool] = await checkToolAvailability(tool);
1347
+ }));
1348
+
1349
+ return results;
1350
+ }
1351
+
1352
+ // CLI tool package mapping
1353
+ const CLI_TOOL_PACKAGES: Record<string, string> = {
1354
+ gemini: '@google/gemini-cli',
1355
+ qwen: '@qwen-code/qwen-code',
1356
+ codex: '@openai/codex',
1357
+ claude: '@anthropic-ai/claude-code'
1358
+ };
1359
+
1360
+ // Disabled tools storage (in-memory fallback, main storage is in cli-config.json)
1361
+ const disabledTools = new Set<string>();
1362
+
1363
+ // Default working directory for config operations
1364
+ let configBaseDir = process.cwd();
1365
+
1366
+ /**
1367
+ * Set the base directory for config operations
1368
+ */
1369
+ export function setConfigBaseDir(dir: string): void {
1370
+ configBaseDir = dir;
1371
+ }
1372
+
1373
+ /**
1374
+ * Install a CLI tool via npm
1375
+ */
1376
+ export async function installCliTool(tool: string): Promise<{ success: boolean; error?: string }> {
1377
+ const packageName = CLI_TOOL_PACKAGES[tool];
1378
+ if (!packageName) {
1379
+ return { success: false, error: `Unknown tool: ${tool}` };
1380
+ }
1381
+
1382
+ return new Promise((resolve) => {
1383
+ const child = spawn('npm', ['install', '-g', packageName], {
1384
+ shell: true,
1385
+ stdio: ['ignore', 'pipe', 'pipe']
1386
+ });
1387
+
1388
+ let stderr = '';
1389
+ child.stderr?.on('data', (data) => { stderr += data.toString(); });
1390
+
1391
+ child.on('close', (code) => {
1392
+ // Clear cache to force re-check
1393
+ toolAvailabilityCache.delete(tool);
1394
+
1395
+ if (code === 0) {
1396
+ resolve({ success: true });
1397
+ } else {
1398
+ resolve({ success: false, error: stderr || `npm install failed with code ${code}` });
1399
+ }
1400
+ });
1401
+
1402
+ child.on('error', (err) => {
1403
+ resolve({ success: false, error: err.message });
1404
+ });
1405
+
1406
+ // Timeout after 2 minutes
1407
+ setTimeout(() => {
1408
+ child.kill();
1409
+ resolve({ success: false, error: 'Installation timed out' });
1410
+ }, 120000);
1411
+ });
1412
+ }
1413
+
1414
+ /**
1415
+ * Uninstall a CLI tool via npm
1416
+ */
1417
+ export async function uninstallCliTool(tool: string): Promise<{ success: boolean; error?: string }> {
1418
+ const packageName = CLI_TOOL_PACKAGES[tool];
1419
+ if (!packageName) {
1420
+ return { success: false, error: `Unknown tool: ${tool}` };
1421
+ }
1422
+
1423
+ return new Promise((resolve) => {
1424
+ const child = spawn('npm', ['uninstall', '-g', packageName], {
1425
+ shell: true,
1426
+ stdio: ['ignore', 'pipe', 'pipe']
1427
+ });
1428
+
1429
+ let stderr = '';
1430
+ child.stderr?.on('data', (data) => { stderr += data.toString(); });
1431
+
1432
+ child.on('close', (code) => {
1433
+ // Clear cache to force re-check
1434
+ toolAvailabilityCache.delete(tool);
1435
+
1436
+ if (code === 0) {
1437
+ resolve({ success: true });
1438
+ } else {
1439
+ resolve({ success: false, error: stderr || `npm uninstall failed with code ${code}` });
1440
+ }
1441
+ });
1442
+
1443
+ child.on('error', (err) => {
1444
+ resolve({ success: false, error: err.message });
1445
+ });
1446
+
1447
+ // Timeout after 1 minute
1448
+ setTimeout(() => {
1449
+ child.kill();
1450
+ resolve({ success: false, error: 'Uninstallation timed out' });
1451
+ }, 60000);
1452
+ });
1453
+ }
1454
+
1455
+ /**
1456
+ * Enable a CLI tool (updates config file)
1457
+ */
1458
+ export function enableCliTool(tool: string): { success: boolean } {
1459
+ try {
1460
+ enableToolFromConfig(configBaseDir, tool);
1461
+ disabledTools.delete(tool); // Also update in-memory fallback
1462
+ return { success: true };
1463
+ } catch (err) {
1464
+ console.error('[cli-executor] Error enabling tool:', err);
1465
+ disabledTools.delete(tool); // Fallback to in-memory
1466
+ return { success: true };
1467
+ }
1468
+ }
1469
+
1470
+ /**
1471
+ * Disable a CLI tool (updates config file)
1472
+ */
1473
+ export function disableCliTool(tool: string): { success: boolean } {
1474
+ try {
1475
+ disableToolFromConfig(configBaseDir, tool);
1476
+ disabledTools.add(tool); // Also update in-memory fallback
1477
+ return { success: true };
1478
+ } catch (err) {
1479
+ console.error('[cli-executor] Error disabling tool:', err);
1480
+ disabledTools.add(tool); // Fallback to in-memory
1481
+ return { success: true };
1482
+ }
1483
+ }
1484
+
1485
+ /**
1486
+ * Check if a tool is enabled (reads from config file)
1487
+ */
1488
+ export function isToolEnabled(tool: string): boolean {
1489
+ try {
1490
+ return isToolEnabledFromConfig(configBaseDir, tool);
1491
+ } catch {
1492
+ // Fallback to in-memory check
1493
+ return !disabledTools.has(tool);
1494
+ }
1495
+ }
1496
+
1497
+ /**
1498
+ * Get full status of all CLI tools including enabled state
1499
+ */
1500
+ export async function getCliToolsFullStatus(): Promise<Record<string, {
1501
+ available: boolean;
1502
+ enabled: boolean;
1503
+ path: string | null;
1504
+ packageName: string;
1505
+ }>> {
1506
+ const tools = Object.keys(CLI_TOOL_PACKAGES);
1507
+ const results: Record<string, {
1508
+ available: boolean;
1509
+ enabled: boolean;
1510
+ path: string | null;
1511
+ packageName: string;
1512
+ }> = {};
1513
+
1514
+ await Promise.all(tools.map(async (tool) => {
1515
+ const availability = await checkToolAvailability(tool);
1516
+ results[tool] = {
1517
+ available: availability.available,
1518
+ enabled: isToolEnabled(tool),
1519
+ path: availability.path,
1520
+ packageName: CLI_TOOL_PACKAGES[tool]
1521
+ };
1522
+ }));
1523
+
1524
+ return results;
1525
+ }
1526
+
1527
+ // ========== Prompt Concatenation System ==========
1528
+
1529
+ /**
1530
+ * Turn data structure for concatenation
1531
+ */
1532
+ interface TurnData {
1533
+ turn: number;
1534
+ timestamp?: string;
1535
+ role: 'user' | 'assistant';
1536
+ content: string;
1537
+ status?: string;
1538
+ duration_ms?: number;
1539
+ source_id?: string; // For merged conversations
1540
+ }
1541
+
1542
+ /**
1543
+ * Prompt concatenation options
1544
+ */
1545
+ interface ConcatOptions {
1546
+ format: PromptFormat;
1547
+ includeMetadata?: boolean;
1548
+ includeTurnMarkers?: boolean;
1549
+ maxOutputLength?: number; // Truncate output for context efficiency
1550
+ }
1551
+
1552
+ /**
1553
+ * PromptConcatenator - Dedicated class for building multi-turn prompts
1554
+ * Supports multiple output formats: plain text, YAML, JSON
1555
+ */
1556
+ class PromptConcatenator {
1557
+ private turns: TurnData[] = [];
1558
+ private options: ConcatOptions;
1559
+ private metadata: Record<string, unknown> = {};
1560
+
1561
+ constructor(options: Partial<ConcatOptions> = {}) {
1562
+ this.options = {
1563
+ format: options.format || 'plain',
1564
+ includeMetadata: options.includeMetadata ?? true,
1565
+ includeTurnMarkers: options.includeTurnMarkers ?? true,
1566
+ maxOutputLength: options.maxOutputLength || 8192
1567
+ };
1568
+ }
1569
+
1570
+ /**
1571
+ * Set metadata for the conversation
1572
+ */
1573
+ setMetadata(key: string, value: unknown): this {
1574
+ this.metadata[key] = value;
1575
+ return this;
1576
+ }
1577
+
1578
+ /**
1579
+ * Add a user turn
1580
+ */
1581
+ addUserTurn(content: string, options: Partial<Omit<TurnData, 'role' | 'content'>> = {}): this {
1582
+ this.turns.push({
1583
+ turn: this.turns.length + 1,
1584
+ role: 'user',
1585
+ content,
1586
+ ...options
1587
+ });
1588
+ return this;
1589
+ }
1590
+
1591
+ /**
1592
+ * Add an assistant turn
1593
+ */
1594
+ addAssistantTurn(content: string, options: Partial<Omit<TurnData, 'role' | 'content'>> = {}): this {
1595
+ // Truncate output if needed
1596
+ const truncatedContent = content.length > this.options.maxOutputLength!
1597
+ ? content.substring(0, this.options.maxOutputLength!) + '\n... [truncated]'
1598
+ : content;
1599
+
1600
+ this.turns.push({
1601
+ turn: this.turns.length + 1,
1602
+ role: 'assistant',
1603
+ content: truncatedContent,
1604
+ ...options
1605
+ });
1606
+ return this;
1607
+ }
1608
+
1609
+ /**
1610
+ * Add a conversation turn from ConversationTurn
1611
+ */
1612
+ addFromConversationTurn(turn: ConversationTurn, sourceId?: string): this {
1613
+ this.addUserTurn(turn.prompt, {
1614
+ turn: turn.turn * 2 - 1,
1615
+ timestamp: turn.timestamp,
1616
+ source_id: sourceId
1617
+ });
1618
+ this.addAssistantTurn(turn.output.stdout || '[No output]', {
1619
+ turn: turn.turn * 2,
1620
+ timestamp: turn.timestamp,
1621
+ status: turn.status,
1622
+ duration_ms: turn.duration_ms,
1623
+ source_id: sourceId
1624
+ });
1625
+ return this;
1626
+ }
1627
+
1628
+ /**
1629
+ * Load turns from an existing conversation
1630
+ */
1631
+ loadConversation(conversation: ConversationRecord): this {
1632
+ for (const turn of conversation.turns) {
1633
+ this.addFromConversationTurn(turn);
1634
+ }
1635
+ return this;
1636
+ }
1637
+
1638
+ /**
1639
+ * Build the final prompt in plain text format
1640
+ */
1641
+ private buildPlainText(newPrompt: string): string {
1642
+ const parts: string[] = [];
1643
+
1644
+ // Metadata section
1645
+ if (this.options.includeMetadata && Object.keys(this.metadata).length > 0) {
1646
+ parts.push('=== CONTEXT ===');
1647
+ for (const [key, value] of Object.entries(this.metadata)) {
1648
+ parts.push(`${key}: ${String(value)}`);
1649
+ }
1650
+ parts.push('');
1651
+ }
1652
+
1653
+ // Conversation history
1654
+ if (this.turns.length > 0) {
1655
+ parts.push('=== CONVERSATION HISTORY ===');
1656
+ parts.push('');
1657
+
1658
+ let currentTurn = 0;
1659
+ for (let i = 0; i < this.turns.length; i += 2) {
1660
+ currentTurn++;
1661
+ const userTurn = this.turns[i];
1662
+ const assistantTurn = this.turns[i + 1];
1663
+
1664
+ if (this.options.includeTurnMarkers) {
1665
+ const sourceMarker = userTurn.source_id ? ` [${userTurn.source_id}]` : '';
1666
+ parts.push(`--- Turn ${currentTurn}${sourceMarker} ---`);
1667
+ }
1668
+
1669
+ parts.push('USER:');
1670
+ parts.push(userTurn.content);
1671
+ parts.push('');
1672
+
1673
+ if (assistantTurn) {
1674
+ parts.push('ASSISTANT:');
1675
+ parts.push(assistantTurn.content);
1676
+ parts.push('');
1677
+ }
1678
+ }
1679
+ }
1680
+
1681
+ // New request
1682
+ parts.push('=== NEW REQUEST ===');
1683
+ parts.push('');
1684
+ parts.push(newPrompt);
1685
+
1686
+ return parts.join('\n');
1687
+ }
1688
+
1689
+ /**
1690
+ * Build the final prompt in YAML format
1691
+ */
1692
+ private buildYaml(newPrompt: string): string {
1693
+ const yamlLines: string[] = [];
1694
+
1695
+ // Metadata
1696
+ if (this.options.includeMetadata && Object.keys(this.metadata).length > 0) {
1697
+ yamlLines.push('context:');
1698
+ for (const [key, value] of Object.entries(this.metadata)) {
1699
+ yamlLines.push(` ${key}: ${this.yamlValue(value)}`);
1700
+ }
1701
+ yamlLines.push('');
1702
+ }
1703
+
1704
+ // Conversation history
1705
+ if (this.turns.length > 0) {
1706
+ yamlLines.push('conversation:');
1707
+
1708
+ let currentTurn = 0;
1709
+ for (let i = 0; i < this.turns.length; i += 2) {
1710
+ currentTurn++;
1711
+ const userTurn = this.turns[i];
1712
+ const assistantTurn = this.turns[i + 1];
1713
+
1714
+ yamlLines.push(` - turn: ${currentTurn}`);
1715
+ if (userTurn.source_id) {
1716
+ yamlLines.push(` source: ${userTurn.source_id}`);
1717
+ }
1718
+ if (userTurn.timestamp) {
1719
+ yamlLines.push(` timestamp: ${userTurn.timestamp}`);
1720
+ }
1721
+
1722
+ // User message
1723
+ yamlLines.push(' user: |');
1724
+ const userLines = userTurn.content.split('\n');
1725
+ for (const line of userLines) {
1726
+ yamlLines.push(` ${line}`);
1727
+ }
1728
+
1729
+ // Assistant message
1730
+ if (assistantTurn) {
1731
+ if (assistantTurn.status) {
1732
+ yamlLines.push(` status: ${assistantTurn.status}`);
1733
+ }
1734
+ if (assistantTurn.duration_ms) {
1735
+ yamlLines.push(` duration_ms: ${assistantTurn.duration_ms}`);
1736
+ }
1737
+ yamlLines.push(' assistant: |');
1738
+ const assistantLines = assistantTurn.content.split('\n');
1739
+ for (const line of assistantLines) {
1740
+ yamlLines.push(` ${line}`);
1741
+ }
1742
+ }
1743
+ yamlLines.push('');
1744
+ }
1745
+ }
1746
+
1747
+ // New request
1748
+ yamlLines.push('new_request: |');
1749
+ const requestLines = newPrompt.split('\n');
1750
+ for (const line of requestLines) {
1751
+ yamlLines.push(` ${line}`);
1752
+ }
1753
+
1754
+ return yamlLines.join('\n');
1755
+ }
1756
+
1757
+ /**
1758
+ * Build the final prompt in JSON format
1759
+ */
1760
+ private buildJson(newPrompt: string): string {
1761
+ const data: Record<string, unknown> = {};
1762
+
1763
+ // Metadata
1764
+ if (this.options.includeMetadata && Object.keys(this.metadata).length > 0) {
1765
+ data.context = this.metadata;
1766
+ }
1767
+
1768
+ // Conversation history
1769
+ if (this.turns.length > 0) {
1770
+ const conversation: Array<{
1771
+ turn: number;
1772
+ source?: string;
1773
+ timestamp?: string;
1774
+ user: string;
1775
+ assistant?: string;
1776
+ status?: string;
1777
+ duration_ms?: number;
1778
+ }> = [];
1779
+
1780
+ for (let i = 0; i < this.turns.length; i += 2) {
1781
+ const userTurn = this.turns[i];
1782
+ const assistantTurn = this.turns[i + 1];
1783
+
1784
+ const turnData: typeof conversation[0] = {
1785
+ turn: Math.ceil((i + 1) / 2),
1786
+ user: userTurn.content
1787
+ };
1788
+
1789
+ if (userTurn.source_id) turnData.source = userTurn.source_id;
1790
+ if (userTurn.timestamp) turnData.timestamp = userTurn.timestamp;
1791
+ if (assistantTurn) {
1792
+ turnData.assistant = assistantTurn.content;
1793
+ if (assistantTurn.status) turnData.status = assistantTurn.status;
1794
+ if (assistantTurn.duration_ms) turnData.duration_ms = assistantTurn.duration_ms;
1795
+ }
1796
+
1797
+ conversation.push(turnData);
1798
+ }
1799
+
1800
+ data.conversation = conversation;
1801
+ }
1802
+
1803
+ data.new_request = newPrompt;
1804
+
1805
+ return JSON.stringify(data, null, 2);
1806
+ }
1807
+
1808
+ /**
1809
+ * Helper to format YAML values
1810
+ */
1811
+ private yamlValue(value: unknown): string {
1812
+ if (typeof value === 'string') {
1813
+ // Quote strings that might be interpreted as other types
1814
+ if (/[:\[\]{}#&*!|>'"@`]/.test(value) || value === '') {
1815
+ return `"${value.replace(/"/g, '\\"')}"`;
1816
+ }
1817
+ return value;
1818
+ }
1819
+ if (typeof value === 'number' || typeof value === 'boolean') {
1820
+ return String(value);
1821
+ }
1822
+ if (value === null || value === undefined) {
1823
+ return 'null';
1824
+ }
1825
+ return JSON.stringify(value);
1826
+ }
1827
+
1828
+ /**
1829
+ * Build the final prompt string
1830
+ */
1831
+ build(newPrompt: string): string {
1832
+ switch (this.options.format) {
1833
+ case 'yaml':
1834
+ return this.buildYaml(newPrompt);
1835
+ case 'json':
1836
+ return this.buildJson(newPrompt);
1837
+ case 'plain':
1838
+ default:
1839
+ return this.buildPlainText(newPrompt);
1840
+ }
1841
+ }
1842
+
1843
+ /**
1844
+ * Reset the concatenator for reuse
1845
+ */
1846
+ reset(): this {
1847
+ this.turns = [];
1848
+ this.metadata = {};
1849
+ return this;
1850
+ }
1851
+ }
1852
+
1853
+ /**
1854
+ * Create a prompt concatenator with specified options
1855
+ */
1856
+ function createPromptConcatenator(options?: Partial<ConcatOptions>): PromptConcatenator {
1857
+ return new PromptConcatenator(options);
1858
+ }
1859
+
1860
+ /**
1861
+ * Quick helper to build a multi-turn prompt in any format
1862
+ */
1863
+ function buildPrompt(
1864
+ conversation: ConversationRecord,
1865
+ newPrompt: string,
1866
+ format: PromptFormat = 'plain'
1867
+ ): string {
1868
+ return createPromptConcatenator({ format })
1869
+ .loadConversation(conversation)
1870
+ .build(newPrompt);
1871
+ }
1872
+
1873
+ /**
1874
+ * Build multi-turn prompt with full conversation history
1875
+ * Uses the PromptConcatenator with plain text format by default
1876
+ */
1877
+ function buildMultiTurnPrompt(
1878
+ conversation: ConversationRecord,
1879
+ newPrompt: string,
1880
+ format: PromptFormat = 'plain'
1881
+ ): string {
1882
+ return buildPrompt(conversation, newPrompt, format);
1883
+ }
1884
+
1885
+ /**
1886
+ * Build continuation prompt with previous conversation context (legacy)
1887
+ */
1888
+ function buildContinuationPrompt(previous: ExecutionRecord, additionalPrompt?: string): string {
1889
+ const parts: string[] = [];
1890
+
1891
+ // Add previous conversation context
1892
+ parts.push('=== PREVIOUS CONVERSATION ===');
1893
+ parts.push('');
1894
+ parts.push('USER PROMPT:');
1895
+ parts.push(previous.prompt);
1896
+ parts.push('');
1897
+ parts.push('ASSISTANT RESPONSE:');
1898
+ parts.push(previous.output.stdout || '[No output recorded]');
1899
+ parts.push('');
1900
+ parts.push('=== CONTINUATION ===');
1901
+ parts.push('');
1902
+
1903
+ if (additionalPrompt) {
1904
+ parts.push(additionalPrompt);
1905
+ } else {
1906
+ parts.push('Continue from where we left off. What should we do next?');
1907
+ }
1908
+
1909
+ return parts.join('\n');
1910
+ }
1911
+
1912
+ /**
1913
+ * Get previous execution for resume
1914
+ * @param baseDir - Working directory
1915
+ * @param tool - Tool to filter by
1916
+ * @param resume - true for last, or execution ID string
1917
+ */
1918
+ function getPreviousExecution(baseDir: string, tool: string, resume: boolean | string): ExecutionRecord | null {
1919
+ if (typeof resume === 'string') {
1920
+ // Resume specific execution by ID
1921
+ return getExecutionDetail(baseDir, resume);
1922
+ } else if (resume === true) {
1923
+ // Resume last execution for this tool
1924
+ const history = getExecutionHistory(baseDir, { limit: 1, tool });
1925
+ if (history.executions.length === 0) {
1926
+ return null;
1927
+ }
1928
+ return getExecutionDetail(baseDir, history.executions[0].id);
1929
+ }
1930
+ return null;
1931
+ }
1932
+
1933
+ /**
1934
+ * Get latest execution for a specific tool
1935
+ */
1936
+ export function getLatestExecution(baseDir: string, tool?: string): ExecutionRecord | null {
1937
+ const history = getExecutionHistory(baseDir, { limit: 1, tool: tool || null });
1938
+ if (history.executions.length === 0) {
1939
+ return null;
1940
+ }
1941
+ return getExecutionDetail(baseDir, history.executions[0].id);
1942
+ }
1943
+
1944
+ // ========== Native Session Content Functions ==========
1945
+
1946
+ /**
1947
+ * Get native session content by CCW ID
1948
+ * Parses the native session file and returns full conversation data
1949
+ */
1950
+ export async function getNativeSessionContent(baseDir: string, ccwId: string) {
1951
+ const store = await getSqliteStore(baseDir);
1952
+ return store.getNativeSessionContent(ccwId);
1953
+ }
1954
+
1955
+ /**
1956
+ * Get formatted native conversation text
1957
+ */
1958
+ export async function getFormattedNativeConversation(baseDir: string, ccwId: string, options?: {
1959
+ includeThoughts?: boolean;
1960
+ includeToolCalls?: boolean;
1961
+ includeTokens?: boolean;
1962
+ maxContentLength?: number;
1963
+ }) {
1964
+ const store = await getSqliteStore(baseDir);
1965
+ return store.getFormattedNativeConversation(ccwId, options);
1966
+ }
1967
+
1968
+ /**
1969
+ * Get conversation pairs from native session
1970
+ */
1971
+ export async function getNativeConversationPairs(baseDir: string, ccwId: string) {
1972
+ const store = await getSqliteStore(baseDir);
1973
+ return store.getNativeConversationPairs(ccwId);
1974
+ }
1975
+
1976
+ /**
1977
+ * Get enriched conversation (CCW + native session merged)
1978
+ */
1979
+ export async function getEnrichedConversation(baseDir: string, ccwId: string) {
1980
+ const store = await getSqliteStore(baseDir);
1981
+ return store.getEnrichedConversation(ccwId);
1982
+ }
1983
+
1984
+ /**
1985
+ * Get history with native session info
1986
+ * Supports recursive querying of child projects
1987
+ */
1988
+ export async function getHistoryWithNativeInfo(baseDir: string, options?: {
1989
+ limit?: number;
1990
+ offset?: number;
1991
+ tool?: string | null;
1992
+ status?: string | null;
1993
+ category?: ExecutionCategory | null;
1994
+ search?: string | null;
1995
+ recursive?: boolean;
1996
+ }) {
1997
+ const { limit = 50, recursive = false, ...queryOptions } = options || {};
1998
+
1999
+ // Non-recursive mode: query single project
2000
+ if (!recursive) {
2001
+ const store = await getSqliteStore(baseDir);
2002
+ return store.getHistoryWithNativeInfo({ limit, ...queryOptions });
2003
+ }
2004
+
2005
+ // Recursive mode: aggregate data from parent and all child projects
2006
+ const { scanChildProjectsAsync } = await import('../config/storage-paths.js');
2007
+ const childProjects = await scanChildProjectsAsync(baseDir);
2008
+
2009
+ // Use the same type as store.getHistoryWithNativeInfo returns
2010
+ type ExecutionWithNativeAndSource = HistoryIndexEntry & {
2011
+ hasNativeSession: boolean;
2012
+ nativeSessionId?: string;
2013
+ nativeSessionPath?: string;
2014
+ };
2015
+
2016
+ const allExecutions: ExecutionWithNativeAndSource[] = [];
2017
+ let totalCount = 0;
2018
+
2019
+ // Query parent project
2020
+ try {
2021
+ const parentStore = await getSqliteStore(baseDir);
2022
+ const parentResult = parentStore.getHistoryWithNativeInfo({ limit, ...queryOptions });
2023
+ totalCount += parentResult.total;
2024
+
2025
+ for (const exec of parentResult.executions) {
2026
+ allExecutions.push({ ...exec, sourceDir: baseDir });
2027
+ }
2028
+ } catch (error) {
2029
+ if (process.env.DEBUG) {
2030
+ console.error(`[CLI History] Failed to query parent project ${baseDir}:`, error);
2031
+ }
2032
+ }
2033
+
2034
+ // Query all child projects
2035
+ for (const child of childProjects) {
2036
+ try {
2037
+ const childStore = await getSqliteStore(child.projectPath);
2038
+ const childResult = childStore.getHistoryWithNativeInfo({ limit, ...queryOptions });
2039
+ totalCount += childResult.total;
2040
+
2041
+ for (const exec of childResult.executions) {
2042
+ allExecutions.push({ ...exec, sourceDir: child.projectPath });
2043
+ }
2044
+ } catch (error) {
2045
+ if (process.env.DEBUG) {
2046
+ console.error(`[CLI History] Failed to query child project ${child.projectPath}:`, error);
2047
+ }
2048
+ }
2049
+ }
2050
+
2051
+ // Sort by updated_at descending and apply limit
2052
+ allExecutions.sort((a, b) => {
2053
+ const timeA = a.updated_at ? new Date(a.updated_at).getTime() : new Date(a.timestamp).getTime();
2054
+ const timeB = b.updated_at ? new Date(b.updated_at).getTime() : new Date(b.timestamp).getTime();
2055
+ return timeB - timeA;
2056
+ });
2057
+ const limitedExecutions = allExecutions.slice(0, limit);
2058
+
2059
+ return {
2060
+ total: totalCount,
2061
+ count: limitedExecutions.length,
2062
+ executions: limitedExecutions
2063
+ };
2064
+ }
2065
+
2066
+ // Export types
2067
+ export type { ConversationRecord, ConversationTurn, ExecutionRecord, PromptFormat, ConcatOptions };
2068
+
2069
+ // Export utility functions and tool definition for backward compatibility
2070
+ export { executeCliTool, checkToolAvailability };
2071
+
2072
+ // Export prompt concatenation utilities
2073
+ export { PromptConcatenator, createPromptConcatenator, buildPrompt, buildMultiTurnPrompt };
2074
+
2075
+ // Note: Async storage functions (getExecutionHistoryAsync, deleteExecutionAsync,
2076
+ // batchDeleteExecutionsAsync) are exported at declaration site - SQLite storage only
2077
+
2078
+ // Export tool definition (for legacy imports) - This allows direct calls to execute with onOutput
2079
+ export const cliExecutorTool = {
2080
+ schema,
2081
+ execute: executeCliTool // Use executeCliTool directly which supports onOutput callback
2082
+ };