claude-code-workflow 6.3.18 → 6.3.20

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