claude-code-workflow 6.3.18 → 6.3.19

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