claude-code-workflow 6.3.18 → 6.3.20

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