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
@@ -0,0 +1,1533 @@
1
+ /**
2
+ * CLI Executor Tool - Unified execution for external CLI tools
3
+ * Supports Gemini, Qwen, and Codex with streaming output
4
+ */
5
+
6
+ import { z } from 'zod';
7
+ import type { ToolSchema, ToolResult } from '../types/tool.js';
8
+ import { spawn, ChildProcess } from 'child_process';
9
+ import { validatePath } from '../utils/path-resolver.js';
10
+ import { escapeWindowsArg } from '../utils/shell-escape.js';
11
+ import { buildCommand, checkToolAvailability, clearToolCache, debugLog, errorLog, type NativeResumeConfig, type ToolAvailability } from './cli-executor-utils.js';
12
+ import type { ConversationRecord, ConversationTurn, ExecutionOutput, ExecutionRecord } from './cli-executor-state.js';
13
+ import {
14
+ createOutputParser,
15
+ type CliOutputUnit,
16
+ type IOutputParser,
17
+ flattenOutputUnits
18
+ } from './cli-output-converter.js';
19
+ import {
20
+ buildMergedPrompt,
21
+ buildMultiTurnPrompt,
22
+ mergeConversations,
23
+ type MergeResult
24
+ } from './cli-prompt-builder.js';
25
+ import {
26
+ convertToConversation,
27
+ ensureHistoryDir,
28
+ getExecutionDetail,
29
+ getExecutionHistory,
30
+ getSqliteStore,
31
+ loadConversation,
32
+ saveConversation
33
+ } from './cli-executor-state.js';
34
+
35
+ // Track current running child process for cleanup on interruption
36
+ let currentChildProcess: ChildProcess | null = null;
37
+ let killTimeout: NodeJS.Timeout | null = null;
38
+ let killTimeoutProcess: ChildProcess | null = null;
39
+
40
+ /**
41
+ * Kill the current running CLI child process
42
+ * Called when parent process receives SIGINT/SIGTERM
43
+ */
44
+ export function killCurrentCliProcess(): boolean {
45
+ const child = currentChildProcess;
46
+ if (!child || child.killed) return false;
47
+
48
+ debugLog('KILL', 'Killing current child process', { pid: child.pid });
49
+
50
+ try {
51
+ child.kill('SIGTERM');
52
+ } catch {
53
+ // Ignore kill errors (process may already be gone)
54
+ }
55
+
56
+ if (killTimeout) {
57
+ clearTimeout(killTimeout);
58
+ killTimeout = null;
59
+ killTimeoutProcess = null;
60
+ }
61
+
62
+ // Force kill after 2 seconds if still running.
63
+ killTimeoutProcess = child;
64
+ killTimeout = setTimeout(() => {
65
+ const target = killTimeoutProcess;
66
+ if (!target || target !== currentChildProcess) return;
67
+ if (target.killed) return;
68
+
69
+ try {
70
+ target.kill('SIGKILL');
71
+ } catch {
72
+ // Ignore kill errors (process may already be gone)
73
+ }
74
+ }, 2000);
75
+
76
+ return true;
77
+ }
78
+
79
+ // LiteLLM integration
80
+ import { executeLiteLLMEndpoint } from './litellm-executor.js';
81
+ import { findEndpointById } from '../config/litellm-api-config-manager.js';
82
+
83
+ // CLI Settings (CLI封装) integration
84
+ import { loadEndpointSettings, getSettingsFilePath, findEndpoint } from '../config/cli-settings-manager.js';
85
+ import { loadClaudeCliTools } from './claude-cli-tools.js';
86
+
87
+ /**
88
+ * Execute Claude CLI with custom settings file (CLI封装)
89
+ */
90
+ interface ClaudeWithSettingsParams {
91
+ prompt: string;
92
+ settingsPath: string;
93
+ endpointId: string;
94
+ mode: 'analysis' | 'write' | 'auto';
95
+ workingDir: string;
96
+ cd?: string;
97
+ includeDirs?: string[];
98
+ customId?: string;
99
+ onOutput?: (unit: CliOutputUnit) => void;
100
+ }
101
+
102
+ async function executeClaudeWithSettings(params: ClaudeWithSettingsParams): Promise<ExecutionOutput> {
103
+ const { prompt, settingsPath, endpointId, mode, workingDir, cd, includeDirs, customId, onOutput } = params;
104
+
105
+ const startTime = Date.now();
106
+ const conversationId = customId || `${Date.now()}-${endpointId}`;
107
+
108
+ // Build claude command with --settings flag
109
+ const args: string[] = [
110
+ '--settings', settingsPath,
111
+ '--print' // Non-interactive mode
112
+ ];
113
+
114
+ // Add mode-specific flags
115
+ if (mode === 'write') {
116
+ args.push('--dangerously-skip-permissions');
117
+ }
118
+
119
+ // Add working directory if specified
120
+ if (cd) {
121
+ args.push('--cd', cd);
122
+ }
123
+
124
+ // Add include directories
125
+ if (includeDirs && includeDirs.length > 0) {
126
+ for (const dir of includeDirs) {
127
+ args.push('--add-dir', dir);
128
+ }
129
+ }
130
+
131
+ // Add prompt as argument
132
+ args.push('-p', prompt);
133
+
134
+ debugLog('CLAUDE_SETTINGS', `Executing claude with settings`, {
135
+ settingsPath,
136
+ endpointId,
137
+ mode,
138
+ workingDir,
139
+ args
140
+ });
141
+
142
+ return new Promise((resolve, reject) => {
143
+ const isWindows = process.platform === 'win32';
144
+ const command = 'claude';
145
+ const commandToSpawn = isWindows ? escapeWindowsArg(command) : command;
146
+ const argsToSpawn = isWindows ? args.map(escapeWindowsArg) : args;
147
+
148
+ const child = spawn(commandToSpawn, argsToSpawn, {
149
+ cwd: workingDir,
150
+ shell: isWindows,
151
+ stdio: ['ignore', 'pipe', 'pipe']
152
+ });
153
+
154
+ // Track current child process for cleanup
155
+ currentChildProcess = child;
156
+
157
+ let stdout = '';
158
+ let stderr = '';
159
+ const outputUnits: CliOutputUnit[] = [];
160
+
161
+ child.stdout!.on('data', (data: Buffer) => {
162
+ const text = data.toString();
163
+ stdout += text;
164
+
165
+ const unit: CliOutputUnit = {
166
+ type: 'stdout',
167
+ content: text,
168
+ timestamp: new Date().toISOString()
169
+ };
170
+ outputUnits.push(unit);
171
+
172
+ if (onOutput) {
173
+ onOutput(unit);
174
+ }
175
+ });
176
+
177
+ child.stderr!.on('data', (data: Buffer) => {
178
+ const text = data.toString();
179
+ stderr += text;
180
+
181
+ const unit: CliOutputUnit = {
182
+ type: 'stderr',
183
+ content: text,
184
+ timestamp: new Date().toISOString()
185
+ };
186
+ outputUnits.push(unit);
187
+
188
+ if (onOutput) {
189
+ onOutput(unit);
190
+ }
191
+ });
192
+
193
+ child.on('close', (code) => {
194
+ currentChildProcess = null;
195
+
196
+ const endTime = Date.now();
197
+ const duration = endTime - startTime;
198
+
199
+ // Determine status
200
+ let status: 'success' | 'error' = 'success';
201
+ if (code !== 0) {
202
+ const hasValidOutput = stdout.trim().length > 0;
203
+ const hasFatalError = stderr.includes('FATAL') ||
204
+ stderr.includes('Authentication failed') ||
205
+ stderr.includes('API key');
206
+
207
+ if (hasValidOutput && !hasFatalError) {
208
+ status = 'success';
209
+ } else {
210
+ status = 'error';
211
+ }
212
+ }
213
+
214
+ const execution: ExecutionRecord = {
215
+ id: conversationId,
216
+ timestamp: new Date(startTime).toISOString(),
217
+ tool: 'claude',
218
+ model: endpointId, // Use endpoint ID as model identifier
219
+ mode,
220
+ prompt,
221
+ status,
222
+ exit_code: code,
223
+ duration_ms: duration,
224
+ output: {
225
+ stdout: stdout.substring(0, 10240),
226
+ stderr: stderr.substring(0, 2048),
227
+ truncated: stdout.length > 10240 || stderr.length > 2048
228
+ }
229
+ };
230
+
231
+ const conversation = convertToConversation(execution);
232
+
233
+ // Save to history
234
+ try {
235
+ saveConversation(workingDir, conversation);
236
+ } catch (err) {
237
+ console.error('[CLI Executor] Failed to save CLI封装 history:', (err as Error).message);
238
+ }
239
+
240
+ resolve({
241
+ success: status === 'success',
242
+ execution,
243
+ conversation,
244
+ stdout,
245
+ stderr
246
+ });
247
+ });
248
+
249
+ child.on('error', (error) => {
250
+ currentChildProcess = null;
251
+ reject(new Error(`Failed to spawn claude: ${error.message}`));
252
+ });
253
+ });
254
+ }
255
+
256
+ // Native resume support
257
+ import {
258
+ trackNewSession,
259
+ getNativeResumeArgs,
260
+ supportsNativeResume,
261
+ calculateProjectHash
262
+ } from './native-session-discovery.js';
263
+ import {
264
+ determineResumeStrategy,
265
+ buildContextPrefix,
266
+ getResumeModeDescription,
267
+ type ResumeDecision
268
+ } from './resume-strategy.js';
269
+ import {
270
+ isToolEnabled as isToolEnabledFromConfig,
271
+ enableTool as enableToolFromConfig,
272
+ disableTool as disableToolFromConfig,
273
+ getPrimaryModel
274
+ } from './cli-config-manager.js';
275
+
276
+ // Built-in CLI tools
277
+ const BUILTIN_CLI_TOOLS = ['gemini', 'qwen', 'codex', 'opencode', 'claude'] as const;
278
+ type BuiltinCliTool = typeof BUILTIN_CLI_TOOLS[number];
279
+
280
+ // Define Zod schema for validation
281
+ // tool accepts built-in tools or custom endpoint IDs (CLI封装)
282
+ const ParamsSchema = z.object({
283
+ tool: z.string().min(1, 'Tool is required'), // Accept any tool ID (built-in or custom endpoint)
284
+ prompt: z.string().min(1, 'Prompt is required'),
285
+ mode: z.enum(['analysis', 'write', 'auto']).default('analysis'),
286
+ format: z.enum(['plain', 'yaml', 'json']).default('plain'), // Multi-turn prompt concatenation format
287
+ model: z.string().optional(),
288
+ cd: z.string().optional(),
289
+ includeDirs: z.string().optional(),
290
+ timeout: z.number().default(0), // 0 = no internal timeout, controlled by external caller (e.g., bash timeout)
291
+ resume: z.union([z.boolean(), z.string()]).optional(), // true = last, string = single ID or comma-separated IDs
292
+ id: z.string().optional(), // Custom execution ID (e.g., IMPL-001-step1)
293
+ noNative: z.boolean().optional(), // Force prompt concatenation instead of native resume
294
+ category: z.enum(['user', 'internal', 'insight']).default('user'), // Execution category for tracking
295
+ parentExecutionId: z.string().optional(), // Parent execution ID for fork/retry scenarios
296
+ stream: z.boolean().default(false), // false = cache full output (default), true = stream output via callback
297
+ outputFormat: z.enum(['text', 'json-lines']).optional().default('json-lines'), // Output parsing format (default: json-lines for type badges)
298
+ });
299
+
300
+ type Params = z.infer<typeof ParamsSchema>;
301
+
302
+ type NonEmptyArray<T> = [T, ...T[]];
303
+
304
+ function assertNonEmptyArray<T>(items: T[], message: string): asserts items is NonEmptyArray<T> {
305
+ if (items.length === 0) {
306
+ throw new Error(message);
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Execute CLI tool with streaming output
312
+ */
313
+ async function executeCliTool(
314
+ params: Record<string, unknown>,
315
+ onOutput?: ((unit: CliOutputUnit) => void) | null
316
+ ): Promise<ExecutionOutput> {
317
+ const parsed = ParamsSchema.safeParse(params);
318
+ if (!parsed.success) {
319
+ throw new Error(`Invalid params: ${parsed.error.message}`);
320
+ }
321
+
322
+ const { tool, prompt, mode, format, model, cd, includeDirs, timeout, resume, id: customId, noNative, category, parentExecutionId, outputFormat } = parsed.data;
323
+
324
+ // Validate and determine working directory early (needed for conversation lookup)
325
+ let workingDir: string;
326
+ if (cd) {
327
+ const validation = validatePath(cd, { mustExist: true });
328
+ if (!validation.valid) {
329
+ throw new Error(`Invalid working directory (--cd): ${validation.error}. Path: ${cd}`);
330
+ }
331
+ workingDir = validation.path!;
332
+ } else {
333
+ workingDir = process.cwd();
334
+ }
335
+ ensureHistoryDir(workingDir); // Ensure history directory exists
336
+
337
+ // NEW: Check if model is a custom LiteLLM endpoint ID
338
+ if (model) {
339
+ const endpoint = findEndpointById(workingDir, model);
340
+ if (endpoint) {
341
+ // Route to LiteLLM executor
342
+ if (onOutput) {
343
+ onOutput({
344
+ type: 'stderr',
345
+ content: `[Routing to LiteLLM endpoint: ${model}]\n`,
346
+ timestamp: new Date().toISOString()
347
+ });
348
+ }
349
+
350
+ const result = await executeLiteLLMEndpoint({
351
+ prompt,
352
+ endpointId: model,
353
+ baseDir: workingDir,
354
+ cwd: cd,
355
+ includeDirs: includeDirs ? includeDirs.split(',').map(d => d.trim()) : undefined,
356
+ enableCache: true,
357
+ onOutput: onOutput || undefined,
358
+ });
359
+
360
+ // Convert LiteLLM result to ExecutionOutput format
361
+ const startTime = Date.now();
362
+ const endTime = Date.now();
363
+ const duration = endTime - startTime;
364
+
365
+ const execution: ExecutionRecord = {
366
+ id: customId || `${Date.now()}-litellm`,
367
+ timestamp: new Date(startTime).toISOString(),
368
+ tool: 'litellm',
369
+ model: result.model,
370
+ mode,
371
+ prompt,
372
+ status: result.success ? 'success' : 'error',
373
+ exit_code: result.success ? 0 : 1,
374
+ duration_ms: duration,
375
+ output: {
376
+ stdout: result.output,
377
+ stderr: result.error || '',
378
+ truncated: false,
379
+ },
380
+ };
381
+
382
+ const conversation = convertToConversation(execution);
383
+
384
+ // Try to save to history
385
+ try {
386
+ saveConversation(workingDir, conversation);
387
+ } catch (err) {
388
+ console.error('[CLI Executor] Failed to save LiteLLM history:', (err as Error).message);
389
+ }
390
+
391
+ return {
392
+ success: result.success,
393
+ execution,
394
+ conversation,
395
+ stdout: result.output,
396
+ stderr: result.error || '',
397
+ };
398
+ }
399
+ }
400
+
401
+ // Check if tool is a custom CLI封装 endpoint (not a built-in tool)
402
+ const isBuiltinTool = BUILTIN_CLI_TOOLS.includes(tool as BuiltinCliTool);
403
+ if (!isBuiltinTool) {
404
+ // Check if it's a CLI封装 endpoint (by ID or name)
405
+ const cliSettings = findEndpoint(tool);
406
+ if (cliSettings && cliSettings.enabled) {
407
+ // Route to Claude CLI with --settings flag
408
+ const settingsPath = getSettingsFilePath(cliSettings.id);
409
+ const displayName = cliSettings.name !== cliSettings.id ? `${cliSettings.name} (${cliSettings.id})` : cliSettings.id;
410
+ if (onOutput) {
411
+ onOutput({
412
+ type: 'stderr',
413
+ content: `[Routing to CLI封装 endpoint: ${displayName} via claude --settings]\n`,
414
+ timestamp: new Date().toISOString()
415
+ });
416
+ }
417
+
418
+ // Execute claude CLI with settings file
419
+ const result = await executeClaudeWithSettings({
420
+ prompt,
421
+ settingsPath,
422
+ endpointId: cliSettings.id,
423
+ mode,
424
+ workingDir,
425
+ cd,
426
+ includeDirs: includeDirs ? includeDirs.split(',').map(d => d.trim()) : undefined,
427
+ customId,
428
+ onOutput: onOutput || undefined
429
+ });
430
+
431
+ return result;
432
+ }
433
+
434
+ // Check cli-tools.json for CLI wrapper tools or API endpoints
435
+ const cliToolsConfig = loadClaudeCliTools(workingDir);
436
+
437
+ // First check if tool is a cli-wrapper in tools section
438
+ const cliWrapperTool = Object.entries(cliToolsConfig.tools).find(
439
+ ([name, t]) => name.toLowerCase() === tool.toLowerCase() && t.type === 'cli-wrapper' && t.enabled
440
+ );
441
+ if (cliWrapperTool) {
442
+ const [toolName] = cliWrapperTool;
443
+ // Check if there's a corresponding CLI封装 settings file
444
+ const cliSettingsForTool = findEndpoint(toolName);
445
+ if (cliSettingsForTool) {
446
+ const settingsPath = getSettingsFilePath(cliSettingsForTool.id);
447
+ if (onOutput) {
448
+ onOutput({
449
+ type: 'stderr',
450
+ content: `[Routing to CLI wrapper tool: ${toolName} via claude --settings]\n`,
451
+ timestamp: new Date().toISOString()
452
+ });
453
+ }
454
+
455
+ const result = await executeClaudeWithSettings({
456
+ prompt,
457
+ settingsPath,
458
+ endpointId: cliSettingsForTool.id,
459
+ mode,
460
+ workingDir,
461
+ cd,
462
+ includeDirs: includeDirs ? includeDirs.split(',').map(d => d.trim()) : undefined,
463
+ customId,
464
+ onOutput: onOutput || undefined
465
+ });
466
+
467
+ return result;
468
+ }
469
+ }
470
+
471
+ // Check tools with type: 'api-endpoint' -> route to LiteLLM
472
+ const apiEndpointTool = Object.entries(cliToolsConfig.tools).find(
473
+ ([name, t]) => t.type === 'api-endpoint' && t.enabled &&
474
+ (t.id === tool || name === tool || name.toLowerCase() === tool.toLowerCase())
475
+ );
476
+ if (apiEndpointTool) {
477
+ const [toolName, toolConfig] = apiEndpointTool;
478
+ // id field is the LiteLLM endpoint ID (e.g., "g25")
479
+ const litellmEndpointId = toolConfig.id || toolName;
480
+
481
+ // Find LiteLLM endpoint configuration
482
+ const litellmEndpoint = findEndpointById(workingDir, litellmEndpointId);
483
+ if (litellmEndpoint) {
484
+ if (onOutput) {
485
+ onOutput({
486
+ type: 'stderr',
487
+ content: `[Routing to LiteLLM API endpoint: ${toolName} (${litellmEndpointId})]\n`,
488
+ timestamp: new Date().toISOString()
489
+ });
490
+ }
491
+
492
+ // Execute via LiteLLM
493
+ const result = await executeLiteLLMEndpoint({
494
+ prompt,
495
+ endpointId: litellmEndpointId,
496
+ baseDir: workingDir,
497
+ cwd: cd || workingDir,
498
+ includeDirs: includeDirs ? includeDirs.split(',').map(d => d.trim()) : undefined,
499
+ onOutput: onOutput || undefined,
500
+ });
501
+
502
+ // Convert LiteLLM result to ExecutionOutput format
503
+ const startTime = Date.now();
504
+ const endTime = Date.now();
505
+ const duration = endTime - startTime;
506
+
507
+ const execution: ExecutionRecord = {
508
+ id: customId || `${Date.now()}-litellm`,
509
+ timestamp: new Date(startTime).toISOString(),
510
+ tool: toolName,
511
+ model: litellmEndpoint.model,
512
+ mode,
513
+ prompt,
514
+ status: result.success ? 'success' : 'error',
515
+ exit_code: result.success ? 0 : 1,
516
+ duration_ms: duration,
517
+ output: {
518
+ stdout: result.output,
519
+ stderr: result.error || '',
520
+ truncated: false
521
+ }
522
+ };
523
+
524
+ const conversation = convertToConversation(execution);
525
+
526
+ // Try to save to history
527
+ try {
528
+ saveConversation(workingDir, conversation);
529
+ } catch (err) {
530
+ console.error('[CLI Executor] Failed to save LiteLLM history:', (err as Error).message);
531
+ }
532
+
533
+ return {
534
+ success: result.success,
535
+ execution,
536
+ conversation,
537
+ stdout: result.output,
538
+ stderr: result.error || '',
539
+ };
540
+ }
541
+ }
542
+
543
+ // Tool not found
544
+ throw new Error(`Unknown tool: ${tool}. Use one of: ${BUILTIN_CLI_TOOLS.join(', ')} or a registered CLI封装 endpoint name.`);
545
+ }
546
+
547
+ // Get SQLite store for native session lookup
548
+ const store = await getSqliteStore(workingDir);
549
+
550
+ // Determine conversation ID and load existing conversation
551
+ // Logic:
552
+ // - If --resume <id1,id2,...> (multiple IDs): merge conversations
553
+ // - With --id: create new merged conversation
554
+ // - Without --id: append to ALL source conversations
555
+ // - If --resume <id> AND --id <newId>: fork - read context from resume ID, create new conversation with newId
556
+ // - If --id provided (no resume): use that ID (create new or append)
557
+ // - If --resume <id> without --id: use resume ID (append to existing)
558
+ // - No params: create new with auto-generated ID
559
+ let conversationId: string;
560
+ let existingConversation: ConversationRecord | null = null;
561
+ let contextConversation: ConversationRecord | null = null; // For fork scenario
562
+ let mergeResult: MergeResult | null = null; // For merge scenario
563
+ let sourceConversations: ConversationRecord[] = []; // All source conversations for merge
564
+
565
+ // Parse resume IDs (can be comma-separated for merge)
566
+ const resumeIds: string[] = resume
567
+ ? (typeof resume === 'string' ? resume.split(',').map(id => id.trim()).filter(Boolean) : [])
568
+ : [];
569
+ const isMerge = resumeIds.length > 1;
570
+ const resumeId = resumeIds.length === 1 ? resumeIds[0] : null;
571
+
572
+ if (isMerge) {
573
+ // Merge scenario: multiple resume IDs
574
+ sourceConversations = resumeIds
575
+ .map(id => loadConversation(workingDir, id))
576
+ .filter((c): c is ConversationRecord => c !== null);
577
+
578
+ // Guard against empty merge sources before accessing sourceConversations[0].
579
+ assertNonEmptyArray(
580
+ sourceConversations,
581
+ `No valid conversations found for merge: ${resumeIds.join(', ')}`
582
+ );
583
+
584
+ mergeResult = mergeConversations(sourceConversations);
585
+ debugLog('MERGE', 'Merged conversations', {
586
+ sourceConversationCount: sourceConversations.length,
587
+ resumeIds
588
+ });
589
+
590
+ if (customId) {
591
+ // Create new merged conversation with custom ID
592
+ conversationId = customId;
593
+ existingConversation = loadConversation(workingDir, customId);
594
+ } else {
595
+ // Will append to ALL source conversations (handled in save logic)
596
+ // Use first source conversation ID as primary
597
+ conversationId = sourceConversations[0].id;
598
+ existingConversation = sourceConversations[0];
599
+ }
600
+ } else if (customId && resumeId) {
601
+ // Fork: read context from resume ID, but create new conversation with custom ID
602
+ conversationId = customId;
603
+ contextConversation = loadConversation(workingDir, resumeId);
604
+ existingConversation = loadConversation(workingDir, customId);
605
+ } else if (customId) {
606
+ // Use custom ID - may be new or existing
607
+ conversationId = customId;
608
+ existingConversation = loadConversation(workingDir, customId);
609
+ } else if (resumeId) {
610
+ // Resume single ID without new ID - append to existing conversation
611
+ conversationId = resumeId;
612
+ existingConversation = loadConversation(workingDir, resumeId);
613
+ } else if (resume) {
614
+ // resume=true: get last conversation for this tool
615
+ const history = getExecutionHistory(workingDir, { limit: 1, tool });
616
+ if (history.executions.length > 0) {
617
+ conversationId = history.executions[0].id;
618
+ existingConversation = loadConversation(workingDir, conversationId);
619
+ } else {
620
+ // No previous conversation, create new
621
+ conversationId = `${Date.now()}-${tool}`;
622
+ }
623
+ } else {
624
+ // New conversation with auto-generated ID
625
+ conversationId = `${Date.now()}-${tool}`;
626
+ }
627
+
628
+ // Determine resume strategy (native vs prompt-concat vs hybrid)
629
+ let resumeDecision: ResumeDecision | null = null;
630
+ let nativeResumeConfig: NativeResumeConfig | undefined;
631
+
632
+ // resume=true (latest) - use native latest if supported
633
+ if (resume === true && !noNative && supportsNativeResume(tool)) {
634
+ resumeDecision = {
635
+ strategy: 'native',
636
+ isLatest: true,
637
+ primaryConversationId: conversationId
638
+ };
639
+ }
640
+ // Use strategy engine for complex scenarios
641
+ else if (resumeIds.length > 0 && !noNative) {
642
+ resumeDecision = determineResumeStrategy({
643
+ tool,
644
+ resumeIds,
645
+ customId,
646
+ // Force prompt-concat if noNative flag is set OR if tool doesn't support native resume
647
+ // (e.g., codex resume requires TTY which spawn() doesn't provide)
648
+ forcePromptConcat: noNative || !supportsNativeResume(tool),
649
+ getNativeSessionId: (ccwId) => store.getNativeSessionId(ccwId),
650
+ getConversation: (ccwId) => loadConversation(workingDir, ccwId),
651
+ getConversationTool: (ccwId) => {
652
+ const conv = loadConversation(workingDir, ccwId);
653
+ return conv?.tool || null;
654
+ }
655
+ });
656
+ }
657
+
658
+ // Configure native resume if strategy decided to use it
659
+ if (resumeDecision && (resumeDecision.strategy === 'native' || resumeDecision.strategy === 'hybrid')) {
660
+ nativeResumeConfig = {
661
+ enabled: true,
662
+ sessionId: resumeDecision.nativeSessionId,
663
+ isLatest: resumeDecision.isLatest
664
+ };
665
+ }
666
+
667
+ // Build final prompt with conversation context
668
+ // For native: minimal prompt (native tool handles context)
669
+ // For hybrid: context prefix from other conversations + new prompt
670
+ // For prompt-concat: full multi-turn prompt
671
+ let finalPrompt = prompt;
672
+
673
+ if (resumeDecision?.strategy === 'native') {
674
+ // Native mode: just use the new prompt, tool handles context
675
+ finalPrompt = prompt;
676
+ } else if (resumeDecision?.strategy === 'hybrid' && resumeDecision.contextTurns?.length) {
677
+ // Hybrid mode: add context prefix from other conversations
678
+ const contextPrefix = buildContextPrefix(resumeDecision.contextTurns, format);
679
+ finalPrompt = contextPrefix + prompt;
680
+ } else if (mergeResult && mergeResult.mergedTurns.length > 0) {
681
+ // Full merge: use merged prompt
682
+ finalPrompt = buildMergedPrompt(mergeResult, prompt, format);
683
+ } else {
684
+ // Standard prompt-concat
685
+ const conversationForContext = contextConversation || existingConversation;
686
+ if (conversationForContext && conversationForContext.turns.length > 0) {
687
+ finalPrompt = buildMultiTurnPrompt(conversationForContext, prompt, format);
688
+ }
689
+ }
690
+
691
+ // Check tool availability
692
+ const toolStatus = await checkToolAvailability(tool);
693
+ if (!toolStatus.available) {
694
+ throw new Error(`CLI tool not available: ${tool}. Please ensure it is installed and in PATH.`);
695
+ }
696
+
697
+ // Log resume mode for debugging
698
+ if (resumeDecision) {
699
+ const modeDesc = getResumeModeDescription(resumeDecision);
700
+ if (onOutput) {
701
+ onOutput({
702
+ type: 'stderr',
703
+ content: `[Resume mode: ${modeDesc}]\n`,
704
+ timestamp: new Date().toISOString()
705
+ });
706
+ }
707
+ }
708
+
709
+ // Use configured primary model if no explicit model provided
710
+ const effectiveModel = model || getPrimaryModel(workingDir, tool);
711
+
712
+ // Build command
713
+ const { command, args, useStdin } = buildCommand({
714
+ tool,
715
+ prompt: finalPrompt,
716
+ mode,
717
+ model: effectiveModel,
718
+ dir: cd,
719
+ include: includeDirs,
720
+ nativeResume: nativeResumeConfig
721
+ });
722
+
723
+ // Create output parser and IR storage
724
+ const parser = createOutputParser(outputFormat);
725
+ const allOutputUnits: CliOutputUnit[] = [];
726
+
727
+ const startTime = Date.now();
728
+
729
+ debugLog('EXEC', `Starting CLI execution`, {
730
+ tool,
731
+ mode,
732
+ workingDir,
733
+ conversationId,
734
+ promptLength: finalPrompt.length,
735
+ hasResume: !!resume,
736
+ hasCustomId: !!customId,
737
+ outputFormat
738
+ });
739
+
740
+ return new Promise((resolve, reject) => {
741
+ // Windows requires shell: true for npm global commands (.cmd files)
742
+ // Unix-like systems can use shell: false for direct execution
743
+ const isWindows = process.platform === 'win32';
744
+
745
+ // When using cmd.exe via `shell: true`, escape args to prevent metacharacter injection.
746
+ const commandToSpawn = isWindows ? escapeWindowsArg(command) : command;
747
+ const argsToSpawn = isWindows ? args.map(escapeWindowsArg) : args;
748
+
749
+ debugLog('SPAWN', `Spawning process`, {
750
+ command,
751
+ args,
752
+ cwd: workingDir,
753
+ shell: isWindows,
754
+ useStdin,
755
+ platform: process.platform,
756
+ fullCommand: `${command} ${args.join(' ')}`,
757
+ ...(isWindows ? { escapedCommand: commandToSpawn, escapedArgs: argsToSpawn, escapedFullCommand: `${commandToSpawn} ${argsToSpawn.join(' ')}` } : {})
758
+ });
759
+
760
+ const child = spawn(commandToSpawn, argsToSpawn, {
761
+ cwd: workingDir,
762
+ shell: isWindows, // Enable shell on Windows for .cmd files
763
+ stdio: [useStdin ? 'pipe' : 'ignore', 'pipe', 'pipe']
764
+ });
765
+
766
+ // Track current child process for cleanup on interruption
767
+ currentChildProcess = child;
768
+
769
+ debugLog('SPAWN', `Process spawned`, { pid: child.pid });
770
+
771
+ // Write prompt to stdin if using stdin mode (for gemini/qwen)
772
+ if (useStdin && child.stdin) {
773
+ debugLog('STDIN', `Writing prompt to stdin (${finalPrompt.length} bytes)`);
774
+ child.stdin.write(finalPrompt);
775
+ child.stdin.end();
776
+ }
777
+
778
+ let stdout = '';
779
+ let stderr = '';
780
+ let timedOut = false;
781
+
782
+ // Handle stdout
783
+ child.stdout!.on('data', (data: Buffer) => {
784
+ const text = data.toString();
785
+ stdout += text;
786
+
787
+ // Parse into IR units
788
+ const units = parser.parse(data, 'stdout');
789
+ allOutputUnits.push(...units);
790
+
791
+ if (onOutput) {
792
+ // Send each IR unit to callback
793
+ for (const unit of units) {
794
+ onOutput(unit);
795
+ }
796
+ }
797
+ });
798
+
799
+ // Handle stderr
800
+ child.stderr!.on('data', (data: Buffer) => {
801
+ const text = data.toString();
802
+ stderr += text;
803
+
804
+ // Parse into IR units
805
+ const units = parser.parse(data, 'stderr');
806
+ allOutputUnits.push(...units);
807
+
808
+ if (onOutput) {
809
+ // Send each IR unit to callback
810
+ for (const unit of units) {
811
+ onOutput(unit);
812
+ }
813
+ }
814
+ });
815
+
816
+ // Handle completion
817
+ child.on('close', async (code) => {
818
+ if (killTimeout && killTimeoutProcess === child) {
819
+ clearTimeout(killTimeout);
820
+ killTimeout = null;
821
+ killTimeoutProcess = null;
822
+ }
823
+
824
+ // Clear current child process reference
825
+ currentChildProcess = null;
826
+
827
+ // Flush remaining buffer from parser
828
+ const remainingUnits = parser.flush();
829
+ allOutputUnits.push(...remainingUnits);
830
+ if (onOutput) {
831
+ for (const unit of remainingUnits) {
832
+ onOutput(unit);
833
+ }
834
+ }
835
+
836
+ const endTime = Date.now();
837
+ const duration = endTime - startTime;
838
+
839
+ debugLog('CLOSE', `Process closed`, {
840
+ exitCode: code,
841
+ duration: `${duration}ms`,
842
+ timedOut,
843
+ stdoutLength: stdout.length,
844
+ stderrLength: stderr.length,
845
+ outputUnitsCount: allOutputUnits.length
846
+ });
847
+
848
+ // Determine status - prioritize output content over exit code
849
+ let status: 'success' | 'error' | 'timeout' = 'success';
850
+ if (timedOut) {
851
+ status = 'timeout';
852
+ debugLog('STATUS', `Execution timed out after ${duration}ms`);
853
+ } else if (code !== 0) {
854
+ // Non-zero exit code doesn't always mean failure
855
+ // Check if there's valid output (AI response) - treat as success
856
+ const hasValidOutput = stdout.trim().length > 0;
857
+ const hasFatalError = stderr.includes('FATAL') ||
858
+ stderr.includes('Authentication failed') ||
859
+ stderr.includes('API key') ||
860
+ stderr.includes('rate limit exceeded');
861
+
862
+ debugLog('STATUS', `Non-zero exit code analysis`, {
863
+ exitCode: code,
864
+ hasValidOutput,
865
+ hasFatalError,
866
+ stderrPreview: stderr.substring(0, 500)
867
+ });
868
+
869
+ if (hasValidOutput && !hasFatalError) {
870
+ // Has output and no fatal errors - treat as success despite exit code
871
+ status = 'success';
872
+ debugLog('STATUS', `Treating as success (has valid output, no fatal errors)`);
873
+ } else {
874
+ status = 'error';
875
+ errorLog('EXEC', `CLI execution failed`, undefined, {
876
+ exitCode: code,
877
+ tool,
878
+ command,
879
+ args,
880
+ workingDir,
881
+ stderrFull: stderr,
882
+ stdoutPreview: stdout.substring(0, 200)
883
+ });
884
+ }
885
+ } else {
886
+ debugLog('STATUS', `Execution successful (exit code 0)`);
887
+ }
888
+
889
+ // Create new turn - cache full output when not streaming (default)
890
+ const shouldCache = !parsed.data.stream;
891
+ const newTurnOutput = {
892
+ stdout: stdout.substring(0, 10240), // Truncate preview to 10KB
893
+ stderr: stderr.substring(0, 2048), // Truncate preview to 2KB
894
+ truncated: stdout.length > 10240 || stderr.length > 2048,
895
+ cached: shouldCache,
896
+ stdout_full: shouldCache ? stdout : undefined,
897
+ stderr_full: shouldCache ? stderr : undefined,
898
+ structured: allOutputUnits // Save structured IR units
899
+ };
900
+
901
+ // Determine base turn number for merge scenarios
902
+ const baseTurnNumber = isMerge && mergeResult
903
+ ? mergeResult.mergedTurns.length + 1
904
+ : (existingConversation ? existingConversation.turns.length + 1 : 1);
905
+
906
+ const newTurn: ConversationTurn = {
907
+ turn: baseTurnNumber,
908
+ timestamp: new Date(startTime).toISOString(),
909
+ prompt,
910
+ duration_ms: duration,
911
+ status,
912
+ exit_code: code,
913
+ output: newTurnOutput
914
+ };
915
+
916
+ // Create or update conversation record
917
+ let conversation: ConversationRecord;
918
+
919
+ if (isMerge && mergeResult && !customId) {
920
+ // Merge without --id: append to ALL source conversations
921
+ // Save new turn to each source conversation
922
+ const savedConversations: ConversationRecord[] = [];
923
+ for (const srcConv of sourceConversations) {
924
+ const turnForSrc: ConversationTurn = {
925
+ ...newTurn,
926
+ turn: srcConv.turns.length + 1 // Use each conversation's turn count
927
+ };
928
+ const updatedConv: ConversationRecord = {
929
+ ...srcConv,
930
+ updated_at: new Date().toISOString(),
931
+ total_duration_ms: srcConv.total_duration_ms + duration,
932
+ turn_count: srcConv.turns.length + 1,
933
+ latest_status: status,
934
+ turns: [...srcConv.turns, turnForSrc]
935
+ };
936
+ savedConversations.push(updatedConv);
937
+ }
938
+ // Use first conversation as primary
939
+ conversation = savedConversations[0];
940
+ // Save all source conversations
941
+ try {
942
+ for (const conv of savedConversations) {
943
+ saveConversation(workingDir, conv);
944
+ }
945
+ } catch (err) {
946
+ console.error('[CLI Executor] Failed to save merged histories:', (err as Error).message);
947
+ }
948
+ } else if (isMerge && mergeResult && customId) {
949
+ // Merge with --id: create new conversation with merged turns + new turn
950
+ // Convert merged turns to regular turns (without source_id)
951
+ const mergedTurns: ConversationTurn[] = mergeResult.mergedTurns.map((mt, idx) => ({
952
+ turn: idx + 1,
953
+ timestamp: mt.timestamp,
954
+ prompt: mt.prompt,
955
+ duration_ms: mt.duration_ms,
956
+ status: mt.status,
957
+ exit_code: mt.exit_code,
958
+ output: mt.output
959
+ }));
960
+
961
+ conversation = existingConversation
962
+ ? {
963
+ ...existingConversation,
964
+ updated_at: new Date().toISOString(),
965
+ total_duration_ms: existingConversation.total_duration_ms + duration,
966
+ turn_count: existingConversation.turns.length + 1,
967
+ latest_status: status,
968
+ turns: [...existingConversation.turns, newTurn]
969
+ }
970
+ : {
971
+ id: conversationId,
972
+ created_at: new Date(startTime).toISOString(),
973
+ updated_at: new Date().toISOString(),
974
+ tool,
975
+ model: model || 'default',
976
+ mode,
977
+ category,
978
+ total_duration_ms: mergeResult.totalDuration + duration,
979
+ turn_count: mergedTurns.length + 1,
980
+ latest_status: status,
981
+ turns: [...mergedTurns, newTurn]
982
+ };
983
+ // Save merged conversation
984
+ try {
985
+ saveConversation(workingDir, conversation);
986
+ } catch (err) {
987
+ console.error('[CLI Executor] Failed to save merged conversation:', (err as Error).message);
988
+ }
989
+ } else {
990
+ // Normal scenario: single conversation
991
+ conversation = existingConversation
992
+ ? {
993
+ ...existingConversation,
994
+ updated_at: new Date().toISOString(),
995
+ total_duration_ms: existingConversation.total_duration_ms + duration,
996
+ turn_count: existingConversation.turns.length + 1,
997
+ latest_status: status,
998
+ turns: [...existingConversation.turns, newTurn]
999
+ }
1000
+ : {
1001
+ id: conversationId,
1002
+ created_at: new Date(startTime).toISOString(),
1003
+ updated_at: new Date().toISOString(),
1004
+ tool,
1005
+ model: model || 'default',
1006
+ mode,
1007
+ category,
1008
+ total_duration_ms: duration,
1009
+ turn_count: 1,
1010
+ latest_status: status,
1011
+ turns: [newTurn],
1012
+ parent_execution_id: parentExecutionId
1013
+ };
1014
+ // Try to save conversation to history
1015
+ try {
1016
+ saveConversation(workingDir, conversation);
1017
+ } catch (err) {
1018
+ // Non-fatal: continue even if history save fails
1019
+ console.error('[CLI Executor] Failed to save history:', (err as Error).message);
1020
+ }
1021
+ }
1022
+
1023
+ // Track native session after execution (awaited to prevent process hang)
1024
+ // Pass prompt for precise matching in parallel execution scenarios
1025
+ try {
1026
+ const nativeSession = await trackNewSession(tool, new Date(startTime), workingDir, prompt);
1027
+ if (nativeSession) {
1028
+ // Save native session mapping
1029
+ try {
1030
+ store.saveNativeSessionMapping({
1031
+ ccw_id: conversationId,
1032
+ tool,
1033
+ native_session_id: nativeSession.sessionId,
1034
+ native_session_path: nativeSession.filePath,
1035
+ project_hash: nativeSession.projectHash,
1036
+ created_at: new Date().toISOString()
1037
+ });
1038
+ } catch (err) {
1039
+ console.error('[CLI Executor] Failed to save native session mapping:', (err as Error).message);
1040
+ }
1041
+ }
1042
+ } catch (err) {
1043
+ console.error('[CLI Executor] Failed to track native session:', (err as Error).message);
1044
+ }
1045
+
1046
+ // Create legacy execution record for backward compatibility
1047
+ const execution: ExecutionRecord = {
1048
+ id: conversationId,
1049
+ timestamp: new Date(startTime).toISOString(),
1050
+ tool,
1051
+ model: effectiveModel || 'default',
1052
+ mode,
1053
+ prompt,
1054
+ status,
1055
+ exit_code: code,
1056
+ duration_ms: duration,
1057
+ output: newTurnOutput,
1058
+ parsedOutput: flattenOutputUnits(allOutputUnits, {
1059
+ excludeTypes: ['stderr', 'progress', 'metadata', 'system']
1060
+ })
1061
+ };
1062
+
1063
+ resolve({
1064
+ success: status === 'success',
1065
+ execution,
1066
+ conversation,
1067
+ stdout,
1068
+ stderr,
1069
+ parsedOutput: execution.parsedOutput
1070
+ });
1071
+ });
1072
+
1073
+ // Handle errors
1074
+ child.on('error', (error) => {
1075
+ errorLog('SPAWN', `Failed to spawn process`, error, {
1076
+ tool,
1077
+ command,
1078
+ args,
1079
+ workingDir,
1080
+ fullCommand: `${command} ${args.join(' ')}`,
1081
+ platform: process.platform,
1082
+ path: process.env.PATH?.split(process.platform === 'win32' ? ';' : ':').slice(0, 10).join('\n ') + '...'
1083
+ });
1084
+ reject(new Error(`Failed to spawn ${tool}: ${error.message}\n Command: ${command} ${args.join(' ')}\n Working Dir: ${workingDir}`));
1085
+ });
1086
+
1087
+ // Timeout handling (timeout=0 disables internal timeout, controlled by external caller)
1088
+ let timeoutId: NodeJS.Timeout | null = null;
1089
+ if (timeout > 0) {
1090
+ timeoutId = setTimeout(() => {
1091
+ timedOut = true;
1092
+ child.kill('SIGTERM');
1093
+ setTimeout(() => {
1094
+ if (!child.killed) {
1095
+ child.kill('SIGKILL');
1096
+ }
1097
+ }, 5000);
1098
+ }, timeout);
1099
+ }
1100
+
1101
+ child.on('close', () => {
1102
+ if (timeoutId) {
1103
+ clearTimeout(timeoutId);
1104
+ }
1105
+ });
1106
+ });
1107
+ }
1108
+
1109
+ // Tool schema for MCP
1110
+ export const schema: ToolSchema = {
1111
+ name: 'cli_executor',
1112
+ description: `Execute external CLI tools (gemini/qwen/codex) with unified interface.
1113
+ Modes:
1114
+ - analysis: Read-only operations (default)
1115
+ - write: File modifications allowed
1116
+ - auto: Full autonomous operations (codex only)`,
1117
+ inputSchema: {
1118
+ type: 'object',
1119
+ properties: {
1120
+ tool: {
1121
+ type: 'string',
1122
+ enum: ['gemini', 'qwen', 'codex'],
1123
+ description: 'CLI tool to execute'
1124
+ },
1125
+ prompt: {
1126
+ type: 'string',
1127
+ description: 'Prompt to send to the CLI tool'
1128
+ },
1129
+ mode: {
1130
+ type: 'string',
1131
+ enum: ['analysis', 'write', 'auto'],
1132
+ description: 'Execution mode (default: analysis)',
1133
+ default: 'analysis'
1134
+ },
1135
+ model: {
1136
+ type: 'string',
1137
+ description: 'Model override (tool-specific)'
1138
+ },
1139
+ cd: {
1140
+ type: 'string',
1141
+ description: 'Working directory for execution (-C for codex)'
1142
+ },
1143
+ includeDirs: {
1144
+ type: 'string',
1145
+ description: 'Additional directories (comma-separated). Maps to --include-directories for gemini/qwen, --add-dir for codex'
1146
+ },
1147
+ timeout: {
1148
+ type: 'number',
1149
+ description: 'Timeout in milliseconds (default: 0 = disabled, controlled by external caller)',
1150
+ default: 0
1151
+ }
1152
+ },
1153
+ required: ['tool', 'prompt']
1154
+ }
1155
+ };
1156
+
1157
+ // Handler function
1158
+ export async function handler(params: Record<string, unknown>): Promise<ToolResult<ExecutionOutput>> {
1159
+ try {
1160
+ const result = await executeCliTool(params);
1161
+ return {
1162
+ success: result.success,
1163
+ result
1164
+ };
1165
+ } catch (error) {
1166
+ return {
1167
+ success: false,
1168
+ error: `CLI execution failed: ${(error as Error).message}`
1169
+ };
1170
+ }
1171
+ }
1172
+
1173
+ export {
1174
+ batchDeleteExecutionsAsync,
1175
+ deleteExecution,
1176
+ deleteExecutionAsync,
1177
+ getConversationDetail,
1178
+ getConversationDetailWithNativeInfo,
1179
+ getExecutionDetail,
1180
+ getExecutionHistory,
1181
+ getExecutionHistoryAsync
1182
+ } from './cli-executor-state.js';
1183
+
1184
+ /**
1185
+ * Get status of all CLI tools
1186
+ * Dynamically reads tools from config file
1187
+ * Handles different tool types:
1188
+ * - builtin: Check system PATH availability
1189
+ * - cli-wrapper: Check CLI Settings configuration exists
1190
+ * - api-endpoint: Check LiteLLM endpoint configuration exists
1191
+ */
1192
+ export async function getCliToolsStatus(): Promise<Record<string, ToolAvailability>> {
1193
+ // Default built-in tools
1194
+ const builtInTools = ['gemini', 'qwen', 'codex', 'claude', 'opencode'];
1195
+
1196
+ // Try to get tools from config with their types
1197
+ interface ToolInfo {
1198
+ name: string;
1199
+ type?: 'builtin' | 'cli-wrapper' | 'api-endpoint';
1200
+ enabled?: boolean;
1201
+ id?: string; // For api-endpoint type
1202
+ }
1203
+ let toolsInfo: ToolInfo[] = builtInTools.map(name => ({ name, type: 'builtin' }));
1204
+
1205
+ try {
1206
+ // Dynamic import to avoid circular dependencies
1207
+ const { loadClaudeCliTools } = await import('./claude-cli-tools.js');
1208
+ const config = loadClaudeCliTools(configBaseDir);
1209
+ if (config.tools && typeof config.tools === 'object') {
1210
+ // Build complete tool info list from config
1211
+ const configToolsInfo: ToolInfo[] = Object.entries(config.tools).map(([name, toolConfig]) => ({
1212
+ name,
1213
+ type: toolConfig.type || 'builtin',
1214
+ enabled: toolConfig.enabled !== false,
1215
+ id: toolConfig.id
1216
+ }));
1217
+
1218
+ // Merge: config tools take precedence over built-in defaults
1219
+ const toolsMap = new Map<string, ToolInfo>();
1220
+ toolsInfo.forEach(t => toolsMap.set(t.name, t));
1221
+ configToolsInfo.forEach(t => toolsMap.set(t.name, t));
1222
+ toolsInfo = Array.from(toolsMap.values());
1223
+ }
1224
+ } catch (e) {
1225
+ // Fallback to built-in tools if config load fails
1226
+ debugLog('cli-executor', `Using built-in tools (config load failed: ${(e as Error).message})`);
1227
+ }
1228
+
1229
+ const results: Record<string, ToolAvailability> = {};
1230
+
1231
+ await Promise.all(toolsInfo.map(async (toolInfo) => {
1232
+ const { name, type, enabled, id } = toolInfo;
1233
+
1234
+ // Check availability based on tool type
1235
+ if (type === 'cli-wrapper') {
1236
+ // For cli-wrapper: check if CLI Settings configuration exists
1237
+ try {
1238
+ const { findEndpoint } = await import('../config/cli-settings-manager.js');
1239
+ const endpoint = findEndpoint(name);
1240
+ if (endpoint && endpoint.enabled) {
1241
+ results[name] = {
1242
+ available: true,
1243
+ path: `cli-settings:${endpoint.id}` // Virtual path indicating CLI Settings source
1244
+ };
1245
+ } else {
1246
+ results[name] = { available: false, path: null };
1247
+ }
1248
+ } catch (e) {
1249
+ debugLog('cli-executor', `Failed to check cli-wrapper ${name}: ${(e as Error).message}`);
1250
+ results[name] = { available: false, path: null };
1251
+ }
1252
+ } else if (type === 'api-endpoint') {
1253
+ // For api-endpoint: check if LiteLLM endpoint configuration exists
1254
+ try {
1255
+ const { findEndpointById } = await import('../config/litellm-api-config-manager.js');
1256
+ const endpointId = id || name;
1257
+ const endpoint = findEndpointById(configBaseDir, endpointId);
1258
+ if (endpoint && enabled !== false) {
1259
+ results[name] = {
1260
+ available: true,
1261
+ path: `litellm:${endpointId}` // Virtual path indicating LiteLLM source
1262
+ };
1263
+ } else {
1264
+ results[name] = { available: false, path: null };
1265
+ }
1266
+ } catch (e) {
1267
+ debugLog('cli-executor', `Failed to check api-endpoint ${name}: ${(e as Error).message}`);
1268
+ results[name] = { available: false, path: null };
1269
+ }
1270
+ } else {
1271
+ // For builtin: check system PATH availability
1272
+ results[name] = await checkToolAvailability(name);
1273
+ }
1274
+ }));
1275
+
1276
+ return results;
1277
+ }
1278
+
1279
+ // CLI tool package mapping
1280
+ const CLI_TOOL_PACKAGES: Record<string, string> = {
1281
+ gemini: '@google/gemini-cli',
1282
+ qwen: '@qwen-code/qwen-code',
1283
+ codex: '@openai/codex',
1284
+ claude: '@anthropic-ai/claude-code',
1285
+ opencode: 'opencode' // https://opencode.ai - installed via npm/pnpm/bun/brew
1286
+ };
1287
+
1288
+ // Disabled tools storage (in-memory fallback, main storage is in cli-config.json)
1289
+ const disabledTools = new Set<string>();
1290
+
1291
+ // Default working directory for config operations
1292
+ let configBaseDir = process.cwd();
1293
+
1294
+ /**
1295
+ * Set the base directory for config operations
1296
+ */
1297
+ export function setConfigBaseDir(dir: string): void {
1298
+ configBaseDir = dir;
1299
+ }
1300
+
1301
+ /**
1302
+ * Install a CLI tool via npm
1303
+ */
1304
+ export async function installCliTool(tool: string): Promise<{ success: boolean; error?: string }> {
1305
+ const packageName = CLI_TOOL_PACKAGES[tool];
1306
+ if (!packageName) {
1307
+ return { success: false, error: `Unknown tool: ${tool}` };
1308
+ }
1309
+
1310
+ return new Promise((resolve) => {
1311
+ const child = spawn('npm', ['install', '-g', packageName], {
1312
+ shell: true,
1313
+ stdio: ['ignore', 'pipe', 'pipe']
1314
+ });
1315
+
1316
+ let stderr = '';
1317
+ child.stderr?.on('data', (data) => { stderr += data.toString(); });
1318
+
1319
+ child.on('close', (code) => {
1320
+ // Clear cache to force re-check
1321
+ clearToolCache();
1322
+
1323
+ if (code === 0) {
1324
+ resolve({ success: true });
1325
+ } else {
1326
+ resolve({ success: false, error: stderr || `npm install failed with code ${code}` });
1327
+ }
1328
+ });
1329
+
1330
+ child.on('error', (err) => {
1331
+ resolve({ success: false, error: err.message });
1332
+ });
1333
+
1334
+ // Timeout after 2 minutes
1335
+ setTimeout(() => {
1336
+ child.kill();
1337
+ resolve({ success: false, error: 'Installation timed out' });
1338
+ }, 120000);
1339
+ });
1340
+ }
1341
+
1342
+ /**
1343
+ * Uninstall a CLI tool via npm
1344
+ */
1345
+ export async function uninstallCliTool(tool: string): Promise<{ success: boolean; error?: string }> {
1346
+ const packageName = CLI_TOOL_PACKAGES[tool];
1347
+ if (!packageName) {
1348
+ return { success: false, error: `Unknown tool: ${tool}` };
1349
+ }
1350
+
1351
+ return new Promise((resolve) => {
1352
+ const child = spawn('npm', ['uninstall', '-g', packageName], {
1353
+ shell: true,
1354
+ stdio: ['ignore', 'pipe', 'pipe']
1355
+ });
1356
+
1357
+ let stderr = '';
1358
+ child.stderr?.on('data', (data) => { stderr += data.toString(); });
1359
+
1360
+ child.on('close', (code) => {
1361
+ // Clear cache to force re-check
1362
+ clearToolCache();
1363
+
1364
+ if (code === 0) {
1365
+ resolve({ success: true });
1366
+ } else {
1367
+ resolve({ success: false, error: stderr || `npm uninstall failed with code ${code}` });
1368
+ }
1369
+ });
1370
+
1371
+ child.on('error', (err) => {
1372
+ resolve({ success: false, error: err.message });
1373
+ });
1374
+
1375
+ // Timeout after 1 minute
1376
+ setTimeout(() => {
1377
+ child.kill();
1378
+ resolve({ success: false, error: 'Uninstallation timed out' });
1379
+ }, 60000);
1380
+ });
1381
+ }
1382
+
1383
+ /**
1384
+ * Enable a CLI tool (updates config file)
1385
+ */
1386
+ export function enableCliTool(tool: string): { success: boolean } {
1387
+ try {
1388
+ enableToolFromConfig(configBaseDir, tool);
1389
+ disabledTools.delete(tool); // Also update in-memory fallback
1390
+ return { success: true };
1391
+ } catch (err) {
1392
+ console.error('[cli-executor] Error enabling tool:', err);
1393
+ disabledTools.delete(tool); // Fallback to in-memory
1394
+ return { success: true };
1395
+ }
1396
+ }
1397
+
1398
+ /**
1399
+ * Disable a CLI tool (updates config file)
1400
+ */
1401
+ export function disableCliTool(tool: string): { success: boolean } {
1402
+ try {
1403
+ disableToolFromConfig(configBaseDir, tool);
1404
+ disabledTools.add(tool); // Also update in-memory fallback
1405
+ return { success: true };
1406
+ } catch (err) {
1407
+ console.error('[cli-executor] Error disabling tool:', err);
1408
+ disabledTools.add(tool); // Fallback to in-memory
1409
+ return { success: true };
1410
+ }
1411
+ }
1412
+
1413
+ /**
1414
+ * Check if a tool is enabled (reads from config file)
1415
+ */
1416
+ export function isToolEnabled(tool: string): boolean {
1417
+ try {
1418
+ return isToolEnabledFromConfig(configBaseDir, tool);
1419
+ } catch {
1420
+ // Fallback to in-memory check
1421
+ return !disabledTools.has(tool);
1422
+ }
1423
+ }
1424
+
1425
+ /**
1426
+ * Get full status of all CLI tools including enabled state
1427
+ */
1428
+ export async function getCliToolsFullStatus(): Promise<Record<string, {
1429
+ available: boolean;
1430
+ enabled: boolean;
1431
+ path: string | null;
1432
+ packageName: string;
1433
+ }>> {
1434
+ const tools = Object.keys(CLI_TOOL_PACKAGES);
1435
+ const results: Record<string, {
1436
+ available: boolean;
1437
+ enabled: boolean;
1438
+ path: string | null;
1439
+ packageName: string;
1440
+ }> = {};
1441
+
1442
+ await Promise.all(tools.map(async (tool) => {
1443
+ const availability = await checkToolAvailability(tool);
1444
+ results[tool] = {
1445
+ available: availability.available,
1446
+ enabled: isToolEnabled(tool),
1447
+ path: availability.path,
1448
+ packageName: CLI_TOOL_PACKAGES[tool]
1449
+ };
1450
+ }));
1451
+
1452
+ return results;
1453
+ }
1454
+
1455
+
1456
+ /**
1457
+ * Build continuation prompt with previous conversation context (legacy)
1458
+ */
1459
+ function buildContinuationPrompt(previous: ExecutionRecord, additionalPrompt?: string): string {
1460
+ const parts: string[] = [];
1461
+
1462
+ // Add previous conversation context
1463
+ parts.push('=== PREVIOUS CONVERSATION ===');
1464
+ parts.push('');
1465
+ parts.push('USER PROMPT:');
1466
+ parts.push(previous.prompt);
1467
+ parts.push('');
1468
+ parts.push('ASSISTANT RESPONSE:');
1469
+ parts.push(previous.output.stdout || '[No output recorded]');
1470
+ parts.push('');
1471
+ parts.push('=== CONTINUATION ===');
1472
+ parts.push('');
1473
+
1474
+ if (additionalPrompt) {
1475
+ parts.push(additionalPrompt);
1476
+ } else {
1477
+ parts.push('Continue from where we left off. What should we do next?');
1478
+ }
1479
+
1480
+ return parts.join('\n');
1481
+ }
1482
+
1483
+ /**
1484
+ * Get previous execution for resume
1485
+ * @param baseDir - Working directory
1486
+ * @param tool - Tool to filter by
1487
+ * @param resume - true for last, or execution ID string
1488
+ */
1489
+ function getPreviousExecution(baseDir: string, tool: string, resume: boolean | string): ExecutionRecord | null {
1490
+ if (typeof resume === 'string') {
1491
+ // Resume specific execution by ID
1492
+ return getExecutionDetail(baseDir, resume);
1493
+ } else if (resume === true) {
1494
+ // Resume last execution for this tool
1495
+ const history = getExecutionHistory(baseDir, { limit: 1, tool });
1496
+ if (history.executions.length === 0) {
1497
+ return null;
1498
+ }
1499
+ return getExecutionDetail(baseDir, history.executions[0].id);
1500
+ }
1501
+ return null;
1502
+ }
1503
+
1504
+ /**
1505
+ * Latest execution + native session history functions are re-exported from state.
1506
+ */
1507
+ export {
1508
+ getEnrichedConversation,
1509
+ getFormattedNativeConversation,
1510
+ getHistoryWithNativeInfo,
1511
+ getLatestExecution,
1512
+ getNativeConversationPairs,
1513
+ getNativeSessionContent
1514
+ } from './cli-executor-state.js';
1515
+
1516
+ // Export types
1517
+ export type { ExecutionCategory, ConversationRecord, ConversationTurn, ExecutionRecord } from './cli-executor-state.js';
1518
+ export type { PromptFormat, ConcatOptions } from './cli-prompt-builder.js';
1519
+
1520
+ // Export utility functions and tool definition for backward compatibility
1521
+ export { executeCliTool, checkToolAvailability, clearToolCache };
1522
+
1523
+ // Export prompt concatenation utilities
1524
+ export { PromptConcatenator, createPromptConcatenator, buildPrompt, buildMultiTurnPrompt } from './cli-prompt-builder.js';
1525
+
1526
+ // Note: Async storage functions (getExecutionHistoryAsync, deleteExecutionAsync,
1527
+ // batchDeleteExecutionsAsync) are exported at declaration site - SQLite storage only
1528
+
1529
+ // Export tool definition (for legacy imports) - This allows direct calls to execute with onOutput
1530
+ export const cliExecutorTool = {
1531
+ schema,
1532
+ execute: executeCliTool // Use executeCliTool directly which supports onOutput callback
1533
+ };