codehere 0.3.0 → 0.5.0-alpha

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 (455) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +329 -65
  3. package/dist/application/agents/documentation-agent.d.ts +24 -0
  4. package/dist/application/agents/documentation-agent.d.ts.map +1 -0
  5. package/dist/application/agents/documentation-agent.js +399 -0
  6. package/dist/application/agents/documentation-agent.js.map +1 -0
  7. package/dist/application/agents/execution-agent.d.ts +11 -0
  8. package/dist/application/agents/execution-agent.d.ts.map +1 -1
  9. package/dist/application/agents/execution-agent.js +289 -80
  10. package/dist/application/agents/execution-agent.js.map +1 -1
  11. package/dist/application/agents/multi-agent-orchestrator.d.ts +4 -0
  12. package/dist/application/agents/multi-agent-orchestrator.d.ts.map +1 -1
  13. package/dist/application/agents/multi-agent-orchestrator.js +95 -2
  14. package/dist/application/agents/multi-agent-orchestrator.js.map +1 -1
  15. package/dist/application/agents/planning-agent.d.ts +3 -0
  16. package/dist/application/agents/planning-agent.d.ts.map +1 -1
  17. package/dist/application/agents/planning-agent.js +151 -71
  18. package/dist/application/agents/planning-agent.js.map +1 -1
  19. package/dist/application/agents/product-requirements-agent.d.ts +21 -0
  20. package/dist/application/agents/product-requirements-agent.d.ts.map +1 -0
  21. package/dist/application/agents/product-requirements-agent.js +247 -0
  22. package/dist/application/agents/product-requirements-agent.js.map +1 -0
  23. package/dist/application/agents/validation-agent.d.ts +5 -1
  24. package/dist/application/agents/validation-agent.d.ts.map +1 -1
  25. package/dist/application/agents/validation-agent.js +156 -21
  26. package/dist/application/agents/validation-agent.js.map +1 -1
  27. package/dist/application/reasoning/multi-model-planning-strategy.d.ts +21 -0
  28. package/dist/application/reasoning/multi-model-planning-strategy.d.ts.map +1 -0
  29. package/dist/application/reasoning/multi-model-planning-strategy.js +158 -0
  30. package/dist/application/reasoning/multi-model-planning-strategy.js.map +1 -0
  31. package/dist/application/reasoning/reasoning-config.d.ts +15 -0
  32. package/dist/application/reasoning/reasoning-config.d.ts.map +1 -0
  33. package/dist/application/reasoning/reasoning-config.js +50 -0
  34. package/dist/application/reasoning/reasoning-config.js.map +1 -0
  35. package/dist/application/reasoning/reasoning-orchestrator.d.ts +18 -0
  36. package/dist/application/reasoning/reasoning-orchestrator.d.ts.map +1 -0
  37. package/dist/application/reasoning/reasoning-orchestrator.js +170 -0
  38. package/dist/application/reasoning/reasoning-orchestrator.js.map +1 -0
  39. package/dist/application/reasoning/reasoning-strategy.interface.d.ts +24 -0
  40. package/dist/application/reasoning/reasoning-strategy.interface.d.ts.map +1 -0
  41. package/dist/application/reasoning/reasoning-strategy.interface.js +6 -0
  42. package/dist/application/reasoning/reasoning-strategy.interface.js.map +1 -0
  43. package/dist/application/reasoning/role-provider-resolver.d.ts +36 -0
  44. package/dist/application/reasoning/role-provider-resolver.d.ts.map +1 -0
  45. package/dist/application/reasoning/role-provider-resolver.js +74 -0
  46. package/dist/application/reasoning/role-provider-resolver.js.map +1 -0
  47. package/dist/application/reasoning/simple-planning-strategy.d.ts +22 -0
  48. package/dist/application/reasoning/simple-planning-strategy.d.ts.map +1 -0
  49. package/dist/application/reasoning/simple-planning-strategy.js +217 -0
  50. package/dist/application/reasoning/simple-planning-strategy.js.map +1 -0
  51. package/dist/application/reasoning/types.d.ts +65 -0
  52. package/dist/application/reasoning/types.d.ts.map +1 -0
  53. package/dist/application/reasoning/types.js +6 -0
  54. package/dist/application/reasoning/types.js.map +1 -0
  55. package/dist/application/reasoning/validator-strategy.d.ts +56 -0
  56. package/dist/application/reasoning/validator-strategy.d.ts.map +1 -0
  57. package/dist/application/reasoning/validator-strategy.js +103 -0
  58. package/dist/application/reasoning/validator-strategy.js.map +1 -0
  59. package/dist/application/services/dependency-container.d.ts +46 -2
  60. package/dist/application/services/dependency-container.d.ts.map +1 -1
  61. package/dist/application/services/dependency-container.js +198 -8
  62. package/dist/application/services/dependency-container.js.map +1 -1
  63. package/dist/application/services/intelligent-router.d.ts +19 -0
  64. package/dist/application/services/intelligent-router.d.ts.map +1 -1
  65. package/dist/application/services/intelligent-router.js +393 -91
  66. package/dist/application/services/intelligent-router.js.map +1 -1
  67. package/dist/application/use-cases/ask-question-use-case.d.ts +20 -0
  68. package/dist/application/use-cases/ask-question-use-case.d.ts.map +1 -1
  69. package/dist/application/use-cases/ask-question-use-case.js +129 -49
  70. package/dist/application/use-cases/ask-question-use-case.js.map +1 -1
  71. package/dist/application/use-cases/edit-file-use-case.d.ts.map +1 -1
  72. package/dist/application/use-cases/edit-file-use-case.js +16 -1
  73. package/dist/application/use-cases/edit-file-use-case.js.map +1 -1
  74. package/dist/application/use-cases/planning-use-case.d.ts +14 -1
  75. package/dist/application/use-cases/planning-use-case.d.ts.map +1 -1
  76. package/dist/application/use-cases/planning-use-case.js +109 -2
  77. package/dist/application/use-cases/planning-use-case.js.map +1 -1
  78. package/dist/domain/entities/documentation.d.ts +35 -0
  79. package/dist/domain/entities/documentation.d.ts.map +1 -0
  80. package/dist/domain/entities/documentation.js +6 -0
  81. package/dist/domain/entities/documentation.js.map +1 -0
  82. package/dist/domain/entities/memory.d.ts.map +1 -1
  83. package/dist/domain/entities/product-requirements.d.ts +50 -0
  84. package/dist/domain/entities/product-requirements.d.ts.map +1 -0
  85. package/dist/domain/entities/product-requirements.js +6 -0
  86. package/dist/domain/entities/product-requirements.js.map +1 -0
  87. package/dist/domain/entities/task.d.ts +152 -0
  88. package/dist/domain/entities/task.d.ts.map +1 -0
  89. package/dist/domain/entities/task.js +61 -0
  90. package/dist/domain/entities/task.js.map +1 -0
  91. package/dist/domain/errors/embeddings-not-found-error.d.ts +9 -0
  92. package/dist/domain/errors/embeddings-not-found-error.d.ts.map +1 -0
  93. package/dist/domain/errors/embeddings-not-found-error.js +13 -0
  94. package/dist/domain/errors/embeddings-not-found-error.js.map +1 -0
  95. package/dist/domain/interfaces/agent.interface.d.ts +15 -0
  96. package/dist/domain/interfaces/agent.interface.d.ts.map +1 -0
  97. package/dist/domain/interfaces/agent.interface.js +6 -0
  98. package/dist/domain/interfaces/agent.interface.js.map +1 -0
  99. package/dist/domain/interfaces/embedding-repository.interface.d.ts +5 -0
  100. package/dist/domain/interfaces/embedding-repository.interface.d.ts.map +1 -1
  101. package/dist/domain/services/environment-mode-manager.d.ts +12 -0
  102. package/dist/domain/services/environment-mode-manager.d.ts.map +1 -0
  103. package/dist/domain/services/environment-mode-manager.js +22 -0
  104. package/dist/domain/services/environment-mode-manager.js.map +1 -0
  105. package/dist/domain/services/query-intent-classifier.d.ts.map +1 -1
  106. package/dist/domain/services/query-intent-classifier.js +20 -1
  107. package/dist/domain/services/query-intent-classifier.js.map +1 -1
  108. package/dist/domain/services/risk-tier-detector.d.ts +17 -0
  109. package/dist/domain/services/risk-tier-detector.d.ts.map +1 -0
  110. package/dist/domain/services/risk-tier-detector.js +78 -0
  111. package/dist/domain/services/risk-tier-detector.js.map +1 -0
  112. package/dist/embed.d.ts.map +1 -1
  113. package/dist/embed.js +18 -8
  114. package/dist/embed.js.map +1 -1
  115. package/dist/formatter.d.ts.map +1 -1
  116. package/dist/formatter.js +10 -3
  117. package/dist/formatter.js.map +1 -1
  118. package/dist/index.js +494 -167
  119. package/dist/index.js.map +1 -1
  120. package/dist/infrastructure/ai/cohere-ai-service.d.ts.map +1 -1
  121. package/dist/infrastructure/ai/cohere-ai-service.js +19 -6
  122. package/dist/infrastructure/ai/cohere-ai-service.js.map +1 -1
  123. package/dist/infrastructure/ai/fake-ai-service.d.ts +22 -0
  124. package/dist/infrastructure/ai/fake-ai-service.d.ts.map +1 -0
  125. package/dist/infrastructure/ai/fake-ai-service.js +59 -0
  126. package/dist/infrastructure/ai/fake-ai-service.js.map +1 -0
  127. package/dist/infrastructure/ai/provider-ai-service.d.ts +59 -0
  128. package/dist/infrastructure/ai/provider-ai-service.d.ts.map +1 -0
  129. package/dist/infrastructure/ai/provider-ai-service.js +477 -0
  130. package/dist/infrastructure/ai/provider-ai-service.js.map +1 -0
  131. package/dist/infrastructure/cache/embedding-cache.d.ts +13 -1
  132. package/dist/infrastructure/cache/embedding-cache.d.ts.map +1 -1
  133. package/dist/infrastructure/cache/embedding-cache.js +80 -9
  134. package/dist/infrastructure/cache/embedding-cache.js.map +1 -1
  135. package/dist/infrastructure/cache/query-result-cache.d.ts +14 -55
  136. package/dist/infrastructure/cache/query-result-cache.d.ts.map +1 -1
  137. package/dist/infrastructure/cache/query-result-cache.js +40 -112
  138. package/dist/infrastructure/cache/query-result-cache.js.map +1 -1
  139. package/dist/infrastructure/cache/response-cache.d.ts +18 -0
  140. package/dist/infrastructure/cache/response-cache.d.ts.map +1 -0
  141. package/dist/infrastructure/cache/response-cache.js +48 -0
  142. package/dist/infrastructure/cache/response-cache.js.map +1 -0
  143. package/dist/infrastructure/cache/security-scan-cache.d.ts +8 -49
  144. package/dist/infrastructure/cache/security-scan-cache.d.ts.map +1 -1
  145. package/dist/infrastructure/cache/security-scan-cache.js +25 -102
  146. package/dist/infrastructure/cache/security-scan-cache.js.map +1 -1
  147. package/dist/infrastructure/completion/bash-completion.d.ts +2 -3
  148. package/dist/infrastructure/completion/bash-completion.d.ts.map +1 -1
  149. package/dist/infrastructure/completion/bash-completion.js +11 -87
  150. package/dist/infrastructure/completion/bash-completion.js.map +1 -1
  151. package/dist/infrastructure/completion/fish-completion.d.ts +2 -3
  152. package/dist/infrastructure/completion/fish-completion.d.ts.map +1 -1
  153. package/dist/infrastructure/completion/fish-completion.js +15 -58
  154. package/dist/infrastructure/completion/fish-completion.js.map +1 -1
  155. package/dist/infrastructure/completion/zsh-completion.d.ts +2 -3
  156. package/dist/infrastructure/completion/zsh-completion.d.ts.map +1 -1
  157. package/dist/infrastructure/completion/zsh-completion.js +18 -73
  158. package/dist/infrastructure/completion/zsh-completion.js.map +1 -1
  159. package/dist/infrastructure/config/config-manager.d.ts +10 -0
  160. package/dist/infrastructure/config/config-manager.d.ts.map +1 -1
  161. package/dist/infrastructure/config/config-manager.js +13 -2
  162. package/dist/infrastructure/config/config-manager.js.map +1 -1
  163. package/dist/infrastructure/context/conversation-context.d.ts +54 -0
  164. package/dist/infrastructure/context/conversation-context.d.ts.map +1 -0
  165. package/dist/infrastructure/context/conversation-context.js +129 -0
  166. package/dist/infrastructure/context/conversation-context.js.map +1 -0
  167. package/dist/infrastructure/context/session-manager.d.ts +42 -0
  168. package/dist/infrastructure/context/session-manager.d.ts.map +1 -0
  169. package/dist/infrastructure/context/session-manager.js +94 -0
  170. package/dist/infrastructure/context/session-manager.js.map +1 -0
  171. package/dist/infrastructure/cost/cost-tracker.d.ts +1 -0
  172. package/dist/infrastructure/cost/cost-tracker.d.ts.map +1 -1
  173. package/dist/infrastructure/cost/cost-tracker.js +12 -5
  174. package/dist/infrastructure/cost/cost-tracker.js.map +1 -1
  175. package/dist/infrastructure/governance/nist-ai-rmf.d.ts +6 -8
  176. package/dist/infrastructure/governance/nist-ai-rmf.d.ts.map +1 -1
  177. package/dist/infrastructure/governance/nist-ai-rmf.js +6 -8
  178. package/dist/infrastructure/governance/nist-ai-rmf.js.map +1 -1
  179. package/dist/infrastructure/governance/policy-as-code.d.ts +6 -8
  180. package/dist/infrastructure/governance/policy-as-code.d.ts.map +1 -1
  181. package/dist/infrastructure/governance/policy-as-code.js +6 -8
  182. package/dist/infrastructure/governance/policy-as-code.js.map +1 -1
  183. package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts +7 -9
  184. package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts.map +1 -1
  185. package/dist/infrastructure/governance/prompt-to-code-lineage.js +7 -9
  186. package/dist/infrastructure/governance/prompt-to-code-lineage.js.map +1 -1
  187. package/dist/infrastructure/protocols/a2a-metadata.js +1 -1
  188. package/dist/infrastructure/protocols/mcp-oauth.js +1 -1
  189. package/dist/infrastructure/providers/cohere-provider.d.ts +39 -0
  190. package/dist/infrastructure/providers/cohere-provider.d.ts.map +1 -0
  191. package/dist/infrastructure/providers/cohere-provider.js +444 -0
  192. package/dist/infrastructure/providers/cohere-provider.js.map +1 -0
  193. package/dist/infrastructure/providers/fake-provider.d.ts +43 -0
  194. package/dist/infrastructure/providers/fake-provider.d.ts.map +1 -0
  195. package/dist/infrastructure/providers/fake-provider.js +130 -0
  196. package/dist/infrastructure/providers/fake-provider.js.map +1 -0
  197. package/dist/infrastructure/providers/local-llm-provider.d.ts +49 -0
  198. package/dist/infrastructure/providers/local-llm-provider.d.ts.map +1 -0
  199. package/dist/infrastructure/providers/local-llm-provider.js +330 -0
  200. package/dist/infrastructure/providers/local-llm-provider.js.map +1 -0
  201. package/dist/infrastructure/providers/model-config.types.d.ts +70 -0
  202. package/dist/infrastructure/providers/model-config.types.d.ts.map +1 -0
  203. package/dist/infrastructure/providers/model-config.types.js +9 -0
  204. package/dist/infrastructure/providers/model-config.types.js.map +1 -0
  205. package/dist/infrastructure/providers/model-provider.interface.d.ts +113 -0
  206. package/dist/infrastructure/providers/model-provider.interface.d.ts.map +1 -0
  207. package/dist/infrastructure/providers/model-provider.interface.js +8 -0
  208. package/dist/infrastructure/providers/model-provider.interface.js.map +1 -0
  209. package/dist/infrastructure/providers/openai-provider.d.ts +38 -0
  210. package/dist/infrastructure/providers/openai-provider.d.ts.map +1 -0
  211. package/dist/infrastructure/providers/openai-provider.js +413 -0
  212. package/dist/infrastructure/providers/openai-provider.js.map +1 -0
  213. package/dist/infrastructure/providers/openrouter-provider.d.ts +42 -0
  214. package/dist/infrastructure/providers/openrouter-provider.d.ts.map +1 -0
  215. package/dist/infrastructure/providers/openrouter-provider.js +401 -0
  216. package/dist/infrastructure/providers/openrouter-provider.js.map +1 -0
  217. package/dist/infrastructure/providers/operation-provider-resolver.d.ts +48 -0
  218. package/dist/infrastructure/providers/operation-provider-resolver.d.ts.map +1 -0
  219. package/dist/infrastructure/providers/operation-provider-resolver.js +131 -0
  220. package/dist/infrastructure/providers/operation-provider-resolver.js.map +1 -0
  221. package/dist/infrastructure/providers/provider-config-loader.d.ts +37 -0
  222. package/dist/infrastructure/providers/provider-config-loader.d.ts.map +1 -0
  223. package/dist/infrastructure/providers/provider-config-loader.js +120 -0
  224. package/dist/infrastructure/providers/provider-config-loader.js.map +1 -0
  225. package/dist/infrastructure/providers/provider-registry.d.ts +53 -0
  226. package/dist/infrastructure/providers/provider-registry.d.ts.map +1 -0
  227. package/dist/infrastructure/providers/provider-registry.js +88 -0
  228. package/dist/infrastructure/providers/provider-registry.js.map +1 -0
  229. package/dist/infrastructure/security/input-validator.d.ts.map +1 -1
  230. package/dist/infrastructure/security/input-validator.js +19 -6
  231. package/dist/infrastructure/security/input-validator.js.map +1 -1
  232. package/dist/infrastructure/serialization/toon-serializer.d.ts +45 -0
  233. package/dist/infrastructure/serialization/toon-serializer.d.ts.map +1 -0
  234. package/dist/infrastructure/serialization/toon-serializer.js +119 -0
  235. package/dist/infrastructure/serialization/toon-serializer.js.map +1 -0
  236. package/dist/infrastructure/storage/embeddings-path.d.ts +18 -0
  237. package/dist/infrastructure/storage/embeddings-path.d.ts.map +1 -0
  238. package/dist/infrastructure/storage/embeddings-path.js +37 -0
  239. package/dist/infrastructure/storage/embeddings-path.js.map +1 -0
  240. package/dist/infrastructure/storage/plan-repository.d.ts +2 -0
  241. package/dist/infrastructure/storage/plan-repository.d.ts.map +1 -1
  242. package/dist/infrastructure/storage/plan-repository.js +36 -73
  243. package/dist/infrastructure/storage/plan-repository.js.map +1 -1
  244. package/dist/infrastructure/storage/sqlite-embedding-repository.d.ts +10 -1
  245. package/dist/infrastructure/storage/sqlite-embedding-repository.d.ts.map +1 -1
  246. package/dist/infrastructure/storage/sqlite-embedding-repository.js +37 -3
  247. package/dist/infrastructure/storage/sqlite-embedding-repository.js.map +1 -1
  248. package/dist/infrastructure/storage/task-helpers.d.ts +69 -0
  249. package/dist/infrastructure/storage/task-helpers.d.ts.map +1 -0
  250. package/dist/infrastructure/storage/task-helpers.js +197 -0
  251. package/dist/infrastructure/storage/task-helpers.js.map +1 -0
  252. package/dist/infrastructure/storage/task-repository.d.ts +68 -0
  253. package/dist/infrastructure/storage/task-repository.d.ts.map +1 -0
  254. package/dist/infrastructure/storage/task-repository.js +216 -0
  255. package/dist/infrastructure/storage/task-repository.js.map +1 -0
  256. package/dist/infrastructure/telemetry/telemetry-service.d.ts +74 -0
  257. package/dist/infrastructure/telemetry/telemetry-service.d.ts.map +1 -0
  258. package/dist/infrastructure/telemetry/telemetry-service.js +167 -0
  259. package/dist/infrastructure/telemetry/telemetry-service.js.map +1 -0
  260. package/dist/infrastructure/ux/bi-directional-learning.d.ts +22 -0
  261. package/dist/infrastructure/ux/bi-directional-learning.d.ts.map +1 -1
  262. package/dist/infrastructure/ux/bi-directional-learning.js +144 -7
  263. package/dist/infrastructure/ux/bi-directional-learning.js.map +1 -1
  264. package/dist/infrastructure/ux/capability-boundaries.d.ts +22 -0
  265. package/dist/infrastructure/ux/capability-boundaries.d.ts.map +1 -0
  266. package/dist/infrastructure/ux/capability-boundaries.js +42 -0
  267. package/dist/infrastructure/ux/capability-boundaries.js.map +1 -0
  268. package/dist/infrastructure/ux/comprehensive-formatter.d.ts +21 -0
  269. package/dist/infrastructure/ux/comprehensive-formatter.d.ts.map +1 -0
  270. package/dist/infrastructure/ux/comprehensive-formatter.js +117 -0
  271. package/dist/infrastructure/ux/comprehensive-formatter.js.map +1 -0
  272. package/dist/infrastructure/ux/contextual-feature-discovery.d.ts +5 -18
  273. package/dist/infrastructure/ux/contextual-feature-discovery.d.ts.map +1 -1
  274. package/dist/infrastructure/ux/contextual-feature-discovery.js +5 -139
  275. package/dist/infrastructure/ux/contextual-feature-discovery.js.map +1 -1
  276. package/dist/infrastructure/ux/feature-discovery.d.ts +3 -33
  277. package/dist/infrastructure/ux/feature-discovery.d.ts.map +1 -1
  278. package/dist/infrastructure/ux/feature-discovery.js +5 -181
  279. package/dist/infrastructure/ux/feature-discovery.js.map +1 -1
  280. package/dist/infrastructure/ux/feedback-prompt.d.ts +26 -0
  281. package/dist/infrastructure/ux/feedback-prompt.d.ts.map +1 -0
  282. package/dist/infrastructure/ux/feedback-prompt.js +45 -0
  283. package/dist/infrastructure/ux/feedback-prompt.js.map +1 -0
  284. package/dist/infrastructure/ux/hitl-review-portal.d.ts.map +1 -1
  285. package/dist/infrastructure/ux/hitl-review-portal.js +4 -1
  286. package/dist/infrastructure/ux/hitl-review-portal.js.map +1 -1
  287. package/dist/infrastructure/ux/hitl-validation.d.ts +35 -0
  288. package/dist/infrastructure/ux/hitl-validation.d.ts.map +1 -1
  289. package/dist/infrastructure/ux/hitl-validation.js +86 -0
  290. package/dist/infrastructure/ux/hitl-validation.js.map +1 -1
  291. package/dist/infrastructure/ux/progress-indicator.d.ts +5 -6
  292. package/dist/infrastructure/ux/progress-indicator.d.ts.map +1 -1
  293. package/dist/infrastructure/ux/progress-indicator.js +36 -41
  294. package/dist/infrastructure/ux/progress-indicator.js.map +1 -1
  295. package/dist/infrastructure/ux/proportional-friction.d.ts +73 -0
  296. package/dist/infrastructure/ux/proportional-friction.d.ts.map +1 -0
  297. package/dist/infrastructure/ux/proportional-friction.js +200 -0
  298. package/dist/infrastructure/ux/proportional-friction.js.map +1 -0
  299. package/dist/infrastructure/ux/review-checkpoint.d.ts +3 -1
  300. package/dist/infrastructure/ux/review-checkpoint.d.ts.map +1 -1
  301. package/dist/infrastructure/ux/review-checkpoint.js +33 -80
  302. package/dist/infrastructure/ux/review-checkpoint.js.map +1 -1
  303. package/dist/infrastructure/ux/staged-feature-intro.d.ts +14 -39
  304. package/dist/infrastructure/ux/staged-feature-intro.d.ts.map +1 -1
  305. package/dist/infrastructure/ux/staged-feature-intro.js +12 -132
  306. package/dist/infrastructure/ux/staged-feature-intro.js.map +1 -1
  307. package/dist/infrastructure/ux/syntax-highlighter.d.ts +1 -2
  308. package/dist/infrastructure/ux/syntax-highlighter.d.ts.map +1 -1
  309. package/dist/infrastructure/ux/syntax-highlighter.js +67 -148
  310. package/dist/infrastructure/ux/syntax-highlighter.js.map +1 -1
  311. package/dist/infrastructure/validation/agent-feedback.d.ts +51 -0
  312. package/dist/infrastructure/validation/agent-feedback.d.ts.map +1 -0
  313. package/dist/infrastructure/validation/agent-feedback.js +55 -0
  314. package/dist/infrastructure/validation/agent-feedback.js.map +1 -0
  315. package/dist/infrastructure/validation/agent-validation-helper.d.ts +75 -0
  316. package/dist/infrastructure/validation/agent-validation-helper.d.ts.map +1 -0
  317. package/dist/infrastructure/validation/agent-validation-helper.js +137 -0
  318. package/dist/infrastructure/validation/agent-validation-helper.js.map +1 -0
  319. package/dist/infrastructure/validation/feedback-stats.d.ts +99 -0
  320. package/dist/infrastructure/validation/feedback-stats.d.ts.map +1 -0
  321. package/dist/infrastructure/validation/feedback-stats.js +173 -0
  322. package/dist/infrastructure/validation/feedback-stats.js.map +1 -0
  323. package/dist/infrastructure/validation/review-handler.d.ts +26 -0
  324. package/dist/infrastructure/validation/review-handler.d.ts.map +1 -0
  325. package/dist/infrastructure/validation/review-handler.js +40 -0
  326. package/dist/infrastructure/validation/review-handler.js.map +1 -0
  327. package/dist/infrastructure/validation/summary-aggregator.d.ts +45 -0
  328. package/dist/infrastructure/validation/summary-aggregator.d.ts.map +1 -0
  329. package/dist/infrastructure/validation/summary-aggregator.js +70 -0
  330. package/dist/infrastructure/validation/summary-aggregator.js.map +1 -0
  331. package/dist/infrastructure/validation/summary-extractor.d.ts +24 -0
  332. package/dist/infrastructure/validation/summary-extractor.d.ts.map +1 -0
  333. package/dist/infrastructure/validation/summary-extractor.js +45 -0
  334. package/dist/infrastructure/validation/summary-extractor.js.map +1 -0
  335. package/dist/infrastructure/validation/trace-summary.d.ts +45 -0
  336. package/dist/infrastructure/validation/trace-summary.d.ts.map +1 -0
  337. package/dist/infrastructure/validation/trace-summary.js +52 -0
  338. package/dist/infrastructure/validation/trace-summary.js.map +1 -0
  339. package/dist/infrastructure/validation/trust-config.d.ts +27 -0
  340. package/dist/infrastructure/validation/trust-config.d.ts.map +1 -0
  341. package/dist/infrastructure/validation/trust-config.js +113 -0
  342. package/dist/infrastructure/validation/trust-config.js.map +1 -0
  343. package/dist/infrastructure/xai/attention-visualizer.d.ts +6 -8
  344. package/dist/infrastructure/xai/attention-visualizer.d.ts.map +1 -1
  345. package/dist/infrastructure/xai/attention-visualizer.js +6 -8
  346. package/dist/infrastructure/xai/attention-visualizer.js.map +1 -1
  347. package/dist/infrastructure/xai/cot-visualizer.d.ts +6 -9
  348. package/dist/infrastructure/xai/cot-visualizer.d.ts.map +1 -1
  349. package/dist/infrastructure/xai/cot-visualizer.js +6 -9
  350. package/dist/infrastructure/xai/cot-visualizer.js.map +1 -1
  351. package/dist/infrastructure/xai/decision-tree-log.d.ts +6 -10
  352. package/dist/infrastructure/xai/decision-tree-log.d.ts.map +1 -1
  353. package/dist/infrastructure/xai/decision-tree-log.js +6 -10
  354. package/dist/infrastructure/xai/decision-tree-log.js.map +1 -1
  355. package/dist/infrastructure/xai/interactive-xai.d.ts +6 -8
  356. package/dist/infrastructure/xai/interactive-xai.d.ts.map +1 -1
  357. package/dist/infrastructure/xai/interactive-xai.js +6 -8
  358. package/dist/infrastructure/xai/interactive-xai.js.map +1 -1
  359. package/dist/infrastructure/xai/uncertainty-quantifier.d.ts +6 -9
  360. package/dist/infrastructure/xai/uncertainty-quantifier.d.ts.map +1 -1
  361. package/dist/infrastructure/xai/uncertainty-quantifier.js +6 -9
  362. package/dist/infrastructure/xai/uncertainty-quantifier.js.map +1 -1
  363. package/dist/monitoring.d.ts +1 -1
  364. package/dist/monitoring.d.ts.map +1 -1
  365. package/dist/monitoring.js +12 -9
  366. package/dist/monitoring.js.map +1 -1
  367. package/dist/parallel-processor.d.ts.map +1 -1
  368. package/dist/parallel-processor.js +124 -45
  369. package/dist/parallel-processor.js.map +1 -1
  370. package/dist/presentation/cli/commands/ask-command.d.ts +2 -0
  371. package/dist/presentation/cli/commands/ask-command.d.ts.map +1 -1
  372. package/dist/presentation/cli/commands/ask-command.js +356 -87
  373. package/dist/presentation/cli/commands/ask-command.js.map +1 -1
  374. package/dist/presentation/cli/commands/config-command.d.ts.map +1 -1
  375. package/dist/presentation/cli/commands/config-command.js +22 -8
  376. package/dist/presentation/cli/commands/config-command.js.map +1 -1
  377. package/dist/presentation/cli/commands/decision-command.js +23 -6
  378. package/dist/presentation/cli/commands/decision-command.js.map +1 -1
  379. package/dist/presentation/cli/commands/docs-command.d.ts +14 -0
  380. package/dist/presentation/cli/commands/docs-command.d.ts.map +1 -0
  381. package/dist/presentation/cli/commands/docs-command.js +25 -0
  382. package/dist/presentation/cli/commands/docs-command.js.map +1 -0
  383. package/dist/presentation/cli/commands/fix-command.d.ts +10 -0
  384. package/dist/presentation/cli/commands/fix-command.d.ts.map +1 -0
  385. package/dist/presentation/cli/commands/fix-command.js +94 -0
  386. package/dist/presentation/cli/commands/fix-command.js.map +1 -0
  387. package/dist/presentation/cli/commands/help-command.d.ts.map +1 -1
  388. package/dist/presentation/cli/commands/help-command.js +23 -1
  389. package/dist/presentation/cli/commands/help-command.js.map +1 -1
  390. package/dist/presentation/cli/commands/memory-command.d.ts +17 -0
  391. package/dist/presentation/cli/commands/memory-command.d.ts.map +1 -0
  392. package/dist/presentation/cli/commands/memory-command.js +252 -0
  393. package/dist/presentation/cli/commands/memory-command.js.map +1 -0
  394. package/dist/presentation/cli/commands/models-command.d.ts +13 -0
  395. package/dist/presentation/cli/commands/models-command.d.ts.map +1 -0
  396. package/dist/presentation/cli/commands/models-command.js +194 -0
  397. package/dist/presentation/cli/commands/models-command.js.map +1 -0
  398. package/dist/presentation/cli/commands/orchestrate-command.d.ts +2 -0
  399. package/dist/presentation/cli/commands/orchestrate-command.d.ts.map +1 -1
  400. package/dist/presentation/cli/commands/orchestrate-command.js +182 -14
  401. package/dist/presentation/cli/commands/orchestrate-command.js.map +1 -1
  402. package/dist/presentation/cli/commands/plan-command.d.ts +2 -0
  403. package/dist/presentation/cli/commands/plan-command.d.ts.map +1 -1
  404. package/dist/presentation/cli/commands/plan-command.js +212 -26
  405. package/dist/presentation/cli/commands/plan-command.js.map +1 -1
  406. package/dist/presentation/cli/commands/product-command.d.ts +14 -0
  407. package/dist/presentation/cli/commands/product-command.d.ts.map +1 -0
  408. package/dist/presentation/cli/commands/product-command.js +22 -0
  409. package/dist/presentation/cli/commands/product-command.js.map +1 -0
  410. package/dist/presentation/cli/commands/react-command.d.ts.map +1 -1
  411. package/dist/presentation/cli/commands/react-command.js +8 -2
  412. package/dist/presentation/cli/commands/react-command.js.map +1 -1
  413. package/dist/presentation/cli/commands/review-command.d.ts +14 -0
  414. package/dist/presentation/cli/commands/review-command.d.ts.map +1 -0
  415. package/dist/presentation/cli/commands/review-command.js +173 -0
  416. package/dist/presentation/cli/commands/review-command.js.map +1 -0
  417. package/dist/presentation/cli/commands/run-command.d.ts +13 -0
  418. package/dist/presentation/cli/commands/run-command.d.ts.map +1 -0
  419. package/dist/presentation/cli/commands/run-command.js +188 -0
  420. package/dist/presentation/cli/commands/run-command.js.map +1 -0
  421. package/dist/presentation/cli/commands/setup-command.d.ts.map +1 -1
  422. package/dist/presentation/cli/commands/setup-command.js +15 -0
  423. package/dist/presentation/cli/commands/setup-command.js.map +1 -1
  424. package/dist/presentation/cli/commands/smart-command.d.ts +3 -1
  425. package/dist/presentation/cli/commands/smart-command.d.ts.map +1 -1
  426. package/dist/presentation/cli/commands/smart-command.js +165 -11
  427. package/dist/presentation/cli/commands/smart-command.js.map +1 -1
  428. package/dist/presentation/cli/commands/status-command.d.ts +14 -0
  429. package/dist/presentation/cli/commands/status-command.d.ts.map +1 -0
  430. package/dist/presentation/cli/commands/status-command.js +171 -0
  431. package/dist/presentation/cli/commands/status-command.js.map +1 -0
  432. package/dist/presentation/cli/commands/suggest-command.d.ts +11 -0
  433. package/dist/presentation/cli/commands/suggest-command.d.ts.map +1 -0
  434. package/dist/presentation/cli/commands/suggest-command.js +138 -0
  435. package/dist/presentation/cli/commands/suggest-command.js.map +1 -0
  436. package/dist/presentation/cli/error-display.d.ts.map +1 -1
  437. package/dist/presentation/cli/error-display.js +118 -17
  438. package/dist/presentation/cli/error-display.js.map +1 -1
  439. package/dist/search.d.ts.map +1 -1
  440. package/dist/search.js +6 -1
  441. package/dist/search.js.map +1 -1
  442. package/dist/session.d.ts +1 -0
  443. package/dist/session.d.ts.map +1 -1
  444. package/dist/session.js +69 -4
  445. package/dist/session.js.map +1 -1
  446. package/dist/tools/bash.d.ts.map +1 -1
  447. package/dist/tools/bash.js +3 -0
  448. package/dist/tools/bash.js.map +1 -1
  449. package/dist/tools/git-tool.js +7 -7
  450. package/dist/tools/git-tool.js.map +1 -1
  451. package/dist/ui.d.ts +11 -0
  452. package/dist/ui.d.ts.map +1 -1
  453. package/dist/ui.js +62 -6
  454. package/dist/ui.js.map +1 -1
  455. package/package.json +22 -4
@@ -6,6 +6,9 @@
6
6
  */
7
7
  import { QueryIntentClassifier } from '../../domain/services/query-intent-classifier.js';
8
8
  import { validateQuery } from '../../infrastructure/security/input-validator.js';
9
+ import { executionTracer } from '../../infrastructure/observability/execution-tracer.js';
10
+ import { agentFeedbackManager } from '../../infrastructure/validation/agent-feedback.js';
11
+ import { findCodebaseRoot } from '../../domain/services/codebase-detector.js';
9
12
  export class IntelligentRouter {
10
13
  intentClassifier;
11
14
  aiService;
@@ -16,104 +19,351 @@ export class IntelligentRouter {
16
19
  this.memoryStream = memoryStream;
17
20
  }
18
21
  async route(request) {
19
- // Validate input
20
- const validation = validateQuery(request.query);
21
- if (!validation.valid) {
22
- return {
23
- intent: 'error',
24
- action: 'general',
25
- result: null,
26
- success: false,
27
- error: `Invalid query: ${validation.errors.join(', ')}`,
22
+ // Start routing trace
23
+ const codebaseInfo = findCodebaseRoot(process.cwd());
24
+ const routingRunId = executionTracer.startRun('intelligent-router', {
25
+ query: request.query,
26
+ codebaseId: codebaseInfo?.codebaseId || codebaseInfo?.rootPath,
27
+ });
28
+ // Track routing decision data
29
+ let routingDecision;
30
+ try {
31
+ // Validate input
32
+ const validation = validateQuery(request.query);
33
+ if (!validation.valid) {
34
+ executionTracer.endRun();
35
+ return {
36
+ intent: 'error',
37
+ action: 'general',
38
+ result: null,
39
+ success: false,
40
+ error: `Invalid query: ${validation.errors.join(', ')}`,
41
+ routingRunId,
42
+ };
43
+ }
44
+ // Use sanitized query if validation found issues
45
+ let query = (validation.sanitized || request.query).trim();
46
+ // 2. Classify intent FIRST (needed for conversation tracking)
47
+ const classifiedIntent = this.intentClassifier.classify(query);
48
+ // Record intent classification
49
+ executionTracer.trace({
50
+ operationType: 'code_analysis',
51
+ operationName: 'intent_classification',
52
+ input: { query },
53
+ output: { intent: classifiedIntent },
54
+ metadata: {
55
+ classifier: 'QueryIntentClassifier',
56
+ },
57
+ });
58
+ // Resolve conversation references if we have history
59
+ let resolvedQuery = query;
60
+ let sessionId;
61
+ let lastIntent;
62
+ // PHASE 1 FIX: Get last intent from request context (passed from session)
63
+ // This is the most reliable source since it's the actual conversation history
64
+ if (request.context?.conversationHistory && request.context.conversationHistory.length > 0) {
65
+ const lastHistoryItem = request.context.conversationHistory[request.context.conversationHistory.length - 1];
66
+ lastIntent = lastHistoryItem.intent;
67
+ }
68
+ if (request.context?.conversationHistory && request.context.conversationHistory.length > 0) {
69
+ const { conversationContextManager } = await import('../../infrastructure/context/conversation-context.js');
70
+ sessionId = request.context.sessionId || 'default-session';
71
+ // Resolve references in query (e.g., "it", "that", "the previous")
72
+ resolvedQuery = conversationContextManager.resolveReferences(sessionId, query);
73
+ // Extract entities for context tracking
74
+ const entities = conversationContextManager.extractEntities(resolvedQuery);
75
+ // Store original query turn (will be updated with response after routing)
76
+ conversationContextManager.addTurn(sessionId, query, '', entities, classifiedIntent);
77
+ }
78
+ // Use resolved query for processing
79
+ query = resolvedQuery;
80
+ // 1. MEMORY-AWARE: Retrieve relevant memories to inform routing decision
81
+ let memories = [];
82
+ let memoryInformedIntent = null;
83
+ if (this.memoryStream) {
84
+ try {
85
+ // Retrieve memories relevant to this query
86
+ memories = await this.memoryStream.retrieve(query, 10);
87
+ // If we have memories, use them to inform intent classification
88
+ if (memories.length > 0 && this.aiService) {
89
+ memoryInformedIntent = await this.classifyIntentWithMemory(query, memories);
90
+ }
91
+ }
92
+ catch (error) {
93
+ // Fallback to basic classification if memory retrieval fails
94
+ console.warn('Memory retrieval failed, using basic classification:', error);
95
+ }
96
+ }
97
+ // CRITICAL: Compound instructions (numbered steps) MUST route to Planning Module
98
+ // Check this BEFORE memory-informed intent to prevent override
99
+ const isCompoundInstruction = query.includes('\n') && /\d+\.\s+[^\n]+\n\s*\d+\.\s+/.test(query);
100
+ // Use memory-informed intent ONLY if not a compound instruction
101
+ const intent = isCompoundInstruction && classifiedIntent === 'multi-file-modify'
102
+ ? 'multi-file-modify' // Force compound instructions to Planning Module
103
+ : (memoryInformedIntent || classifiedIntent);
104
+ const symbols = this.intentClassifier.extractSymbols(query);
105
+ // Determine which action/agent will be selected based on intent
106
+ const actionMap = {
107
+ 'explain': 'explain',
108
+ 'multi-file-modify': 'orchestrate',
109
+ 'modify': 'edit',
110
+ 'debug': 'edit',
111
+ 'implement': 'edit',
112
+ 'index': 'index',
113
+ 'plan': 'plan',
114
+ 'find': 'ask',
115
+ 'understand': 'ask',
116
+ 'general': 'ask',
28
117
  };
29
- }
30
- // Use sanitized query if validation found issues
31
- const query = (validation.sanitized || request.query).trim();
32
- // 1. MEMORY-AWARE: Retrieve relevant memories to inform routing decision
33
- let memories = [];
34
- let memoryInformedIntent = null;
35
- if (this.memoryStream) {
118
+ const selectedAction = actionMap[intent] || 'ask';
119
+ const selectedAgent = selectedAction === 'orchestrate' ? 'multi-agent-orchestrator' :
120
+ selectedAction === 'plan' ? 'planning-agent' :
121
+ selectedAction === 'react' ? 'react-orchestration' :
122
+ selectedAction === 'edit' ? 'edit-file-use-case' :
123
+ selectedAction === 'explain' ? 'explain-file-use-case' :
124
+ selectedAction === 'index' ? 'index-codebase-use-case' :
125
+ 'ask-question-use-case';
126
+ // Calculate confidence score (heuristic)
127
+ let confidence = 0.8; // Default confidence
128
+ if (memoryInformedIntent && memoryInformedIntent === classifiedIntent) {
129
+ confidence = 0.95; // High confidence when memory and classifier agree
130
+ }
131
+ else if (memoryInformedIntent) {
132
+ confidence = 0.85; // Good confidence with memory override
133
+ }
134
+ else if (isCompoundInstruction) {
135
+ confidence = 0.9; // High confidence for compound instructions
136
+ }
137
+ // Build selection reason
138
+ const selectionReason = isCompoundInstruction
139
+ ? 'Compound instruction detected - routing to orchestration'
140
+ : memoryInformedIntent && memoryInformedIntent !== classifiedIntent
141
+ ? `Memory-informed routing: ${classifiedIntent} → ${memoryInformedIntent}`
142
+ : `Intent classification: ${intent}`;
143
+ // Track alternatives considered
144
+ const alternatives = Object.keys(actionMap)
145
+ .filter(k => actionMap[k] !== selectedAction)
146
+ .map(k => actionMap[k])
147
+ .filter((v, i, arr) => arr.indexOf(v) === i) // Deduplicate
148
+ .slice(0, 3); // Top 3 alternatives
149
+ // Record routing decision
150
+ routingDecision = {
151
+ confidence,
152
+ selectedAgent,
153
+ selectionReason,
154
+ alternatives,
155
+ };
156
+ // Trace routing decision
157
+ executionTracer.trace({
158
+ operationType: 'code_analysis',
159
+ operationName: 'routing_decision',
160
+ input: { query, intent, classifiedIntent, memoryInformedIntent },
161
+ output: { selectedAction, selectedAgent, confidence },
162
+ metadata: {
163
+ intent,
164
+ selectedAction,
165
+ selectedAgent,
166
+ confidence,
167
+ memoryInformed: !!memoryInformedIntent,
168
+ memoriesUsed: memories.length,
169
+ compoundInstruction: isCompoundInstruction,
170
+ },
171
+ });
172
+ // P0 FIX: Detect conversational follow-ups and skip index check
173
+ // Check if query is conversational (no code keywords, no file paths, questions/statements)
174
+ const hasCodeKeywords = /\b(src|lib|test|\.ts|\.js|\.py|\.java|file|function|class|import|export|require|module|package)\b/i.test(query);
175
+ const isFilePath = /^[A-Z][a-z]+\.(ts|js|py|java|go|rs|rb|php)$/.test(query) || /[\w\/\-\.]+\.(ts|js|tsx|jsx|json|md|yaml|yml|txt|py|go|rs|java|cpp|h|hpp)/.test(query);
176
+ const isQuestion = /^(what|how|where|when|why|can|could|should|would|do|does|is|are|will)\b/i.test(query.trim());
177
+ const isConversationalPhrase = /^(i want|i need|i should|i don't|i can't|let me|help me|what should|how should)\b/i.test(query.trim());
178
+ // P0 FIX: Detect conversational follow-ups - either from history OR from query pattern
179
+ // If query has conversational patterns and no code keywords, treat as conversational regardless of intent
180
+ const isConversationalFollowup = (
181
+ // Pattern-based detection (most reliable)
182
+ (isQuestion || isConversationalPhrase) &&
183
+ !hasCodeKeywords &&
184
+ !isFilePath) || (
185
+ // History-based detection
186
+ (lastIntent === 'plan' || intent === 'plan' || intent === 'general') &&
187
+ !hasCodeKeywords &&
188
+ !isFilePath &&
189
+ (isQuestion || isConversationalPhrase));
190
+ // Debug logging for compound instructions
191
+ if (isCompoundInstruction) {
192
+ console.log(`[IntelligentRouter] Compound instruction detected. Classified: ${classifiedIntent}, Memory: ${memoryInformedIntent}, Using: ${intent}`);
193
+ }
194
+ // 3. Check if indexing is needed
195
+ // CRITICAL: Only require index for code-specific queries (find, understand, explain)
196
+ // Planning, brainstorming, and product queries should work without index
197
+ const needsIndex = await this.checkIfIndexingNeeded(request.context);
198
+ const codeSpecificIntents = ['find', 'understand', 'explain', 'modify', 'debug', 'implement', 'multi-file-modify'];
199
+ // Skip index check for conversational follow-ups and non-code intents
200
+ const requiresIndex = !isConversationalFollowup && needsIndex && codeSpecificIntents.includes(intent);
201
+ // Handle indexing first if needed (only for code-specific queries)
202
+ if (requiresIndex) {
203
+ executionTracer.endRun();
204
+ // Record routing decision feedback
205
+ try {
206
+ agentFeedbackManager.recordFeedback({
207
+ runId: routingRunId,
208
+ agentName: 'intelligent-router',
209
+ operation: 'route',
210
+ query: request.query,
211
+ outcome: 'failure',
212
+ userAction: 'not_required', // Error case - no review flow
213
+ errors: ['Indexing required'],
214
+ });
215
+ }
216
+ catch {
217
+ // Non-blocking
218
+ }
219
+ return {
220
+ intent: 'index',
221
+ action: 'index',
222
+ result: { message: 'Indexing required. Please run: codehere index' },
223
+ success: false,
224
+ message: 'Codebase not indexed. Run "codehere index" first, then try again.',
225
+ memoriesUsed: memories.length,
226
+ routingDecision,
227
+ routingRunId,
228
+ };
229
+ }
230
+ // Route based on intent (pass memories for context)
231
+ let routingResult;
36
232
  try {
37
- // Retrieve memories relevant to this query
38
- memories = await this.memoryStream.retrieve(query, 10);
39
- // If we have memories, use them to inform intent classification
40
- if (memories.length > 0 && this.aiService) {
41
- memoryInformedIntent = await this.classifyIntentWithMemory(query, memories);
233
+ switch (intent) {
234
+ case 'explain':
235
+ // Use deterministic workflow for faster performance (no ReAct overhead)
236
+ routingResult = await this.handleExplainWithWorkflow(query, symbols, memories);
237
+ break;
238
+ case 'multi-file-modify':
239
+ // Multi-file operations require planning AND execution
240
+ routingResult = await this.handleOrchestrate(query, memories);
241
+ break;
242
+ case 'modify':
243
+ case 'debug': // 'fix' maps to 'debug'
244
+ case 'implement':
245
+ routingResult = await this.handleEdit(query, symbols, memories);
246
+ break;
247
+ case 'index':
248
+ routingResult = await this.handleIndex(query);
249
+ break;
250
+ case 'plan':
251
+ // Complex goals need planning
252
+ routingResult = await this.handlePlan(query, memories);
253
+ // PHASE 1 FIX: Check conversation context - if last intent was non-code, skip code search
254
+ const nonCodeIntents = ['plan', 'general', 'product', 'business'];
255
+ const isFollowUpToNonCode = lastIntent && nonCodeIntents.includes(lastIntent);
256
+ // Also check if query is clearly conversational (not code-related) in empty directory
257
+ const isEmptyDirectory = await this.checkIfIndexingNeeded(request.context);
258
+ const isConversationalQuery = !query.toLowerCase().match(/\b(code|file|function|class|variable|import|export|module|package)\b/);
259
+ // If this is a follow-up to a non-code query OR a conversational query in empty directory, provide conversational response
260
+ if (isFollowUpToNonCode || (isEmptyDirectory && isConversationalQuery)) {
261
+ routingResult = await this.handleConversationalResponse(query, memories, lastIntent);
262
+ }
263
+ break;
264
+ case 'find':
265
+ case 'understand':
266
+ case 'general':
267
+ // CRITICAL FIX: Simple questions should NEVER use ReAct
268
+ // Only use ReAct for truly complex multi-step queries
269
+ // Simple questions (explain, find, understand) go directly to AskQuestionUseCase
270
+ if (this.isSimpleQuestion(query)) {
271
+ routingResult = await this.handleAsk(query, memories);
272
+ }
273
+ else {
274
+ // For complex queries, check if ReAct is appropriate
275
+ const shouldUseReAct = this.shouldUseReAct(query, memories);
276
+ if (shouldUseReAct) {
277
+ routingResult = await this.handleReAct(query, memories);
278
+ }
279
+ else {
280
+ // Default to AskQuestion for understand/general queries
281
+ routingResult = await this.handleAsk(query, memories);
282
+ }
283
+ }
284
+ break;
285
+ default:
286
+ // CRITICAL FIX: Default to AskQuestion, not ReAct
287
+ routingResult = await this.handleAsk(query, memories);
288
+ break;
42
289
  }
290
+ // Attach routing decision to result
291
+ routingResult.routingDecision = routingDecision;
292
+ routingResult.routingRunId = routingRunId;
293
+ // End routing trace
294
+ executionTracer.endRun();
295
+ // Record routing feedback
296
+ try {
297
+ agentFeedbackManager.recordFeedback({
298
+ runId: routingRunId,
299
+ agentName: 'intelligent-router',
300
+ operation: 'route',
301
+ query: request.query,
302
+ outcome: routingResult.success ? 'success' : 'failure',
303
+ userAction: 'not_required', // Internal routing - no review flow
304
+ errors: routingResult.error ? [routingResult.error] : undefined,
305
+ });
306
+ }
307
+ catch {
308
+ // Non-blocking
309
+ }
310
+ return routingResult;
43
311
  }
44
312
  catch (error) {
45
- // Fallback to basic classification if memory retrieval fails
46
- console.warn('Memory retrieval failed, using basic classification:', error);
313
+ // End run on error
314
+ executionTracer.endRun();
315
+ // Record failure
316
+ try {
317
+ agentFeedbackManager.recordFeedback({
318
+ runId: routingRunId,
319
+ agentName: 'intelligent-router',
320
+ operation: 'route',
321
+ query: request.query,
322
+ outcome: 'failure',
323
+ userAction: 'not_required', // Error case - no review flow
324
+ errors: [error instanceof Error ? error.message : String(error)],
325
+ });
326
+ }
327
+ catch {
328
+ // Non-blocking
329
+ }
330
+ return {
331
+ intent,
332
+ action: selectedAction === 'orchestrate' ? 'general' : selectedAction,
333
+ result: null,
334
+ success: false,
335
+ error: error instanceof Error ? error.message : String(error),
336
+ routingDecision,
337
+ routingRunId,
338
+ };
47
339
  }
48
340
  }
49
- // 2. Classify intent (check for compound instructions FIRST, before memory)
50
- const classifiedIntent = this.intentClassifier.classify(query);
51
- // CRITICAL: Compound instructions (numbered steps) MUST route to Planning Module
52
- // Check this BEFORE memory-informed intent to prevent override
53
- const isCompoundInstruction = query.includes('\n') && /\d+\.\s+[^\n]+\n\s*\d+\.\s+/.test(query);
54
- // Use memory-informed intent ONLY if not a compound instruction
55
- const intent = isCompoundInstruction && classifiedIntent === 'multi-file-modify'
56
- ? 'multi-file-modify' // Force compound instructions to Planning Module
57
- : (memoryInformedIntent || classifiedIntent);
58
- const symbols = this.intentClassifier.extractSymbols(query);
59
- // Debug logging for compound instructions
60
- if (isCompoundInstruction) {
61
- console.log(`[IntelligentRouter] Compound instruction detected. Classified: ${classifiedIntent}, Memory: ${memoryInformedIntent}, Using: ${intent}`);
62
- }
63
- // 3. Check if indexing is needed
64
- const needsIndex = await this.checkIfIndexingNeeded(request.context);
65
- // Handle indexing first if needed
66
- if (needsIndex && (intent === 'find' || intent === 'understand' || intent === 'explain')) {
341
+ catch (outerError) {
342
+ // Catch any errors from the outer try block (validation, classification, etc.)
343
+ executionTracer.endRun();
344
+ try {
345
+ agentFeedbackManager.recordFeedback({
346
+ runId: routingRunId,
347
+ agentName: 'intelligent-router',
348
+ operation: 'route',
349
+ query: request.query,
350
+ outcome: 'failure',
351
+ userAction: 'not_required', // Error case - no review flow
352
+ errors: [outerError instanceof Error ? outerError.message : String(outerError)],
353
+ });
354
+ }
355
+ catch {
356
+ // Non-blocking
357
+ }
67
358
  return {
68
- intent: 'index',
69
- action: 'index',
70
- result: { message: 'Indexing required. Please run: codehere index' },
359
+ intent: 'error',
360
+ action: 'general',
361
+ result: null,
71
362
  success: false,
72
- message: 'Codebase not indexed. Run "codehere index" first, then try again.',
73
- memoriesUsed: memories.length,
363
+ error: outerError instanceof Error ? outerError.message : String(outerError),
364
+ routingRunId,
74
365
  };
75
366
  }
76
- // Route based on intent (pass memories for context)
77
- switch (intent) {
78
- case 'explain':
79
- // Use deterministic workflow for faster performance (no ReAct overhead)
80
- return await this.handleExplainWithWorkflow(query, symbols, memories);
81
- case 'multi-file-modify':
82
- // Multi-file operations require planning AND execution
83
- return await this.handleOrchestrate(query, memories);
84
- case 'modify':
85
- case 'debug': // 'fix' maps to 'debug'
86
- case 'implement':
87
- return await this.handleEdit(query, symbols, memories);
88
- case 'index':
89
- return await this.handleIndex(query);
90
- case 'plan':
91
- // Complex goals need planning
92
- return await this.handlePlan(query, memories);
93
- case 'find':
94
- // For "find" queries, use AskQuestion to search the codebase
95
- return await this.handleAsk(query, memories);
96
- case 'understand':
97
- case 'general':
98
- // CRITICAL FIX: Simple questions should NEVER use ReAct
99
- // Only use ReAct for truly complex multi-step queries
100
- // Simple questions (explain, find, understand) go directly to AskQuestionUseCase
101
- if (this.isSimpleQuestion(query)) {
102
- return await this.handleAsk(query, memories);
103
- }
104
- // For complex queries, check if ReAct is appropriate
105
- const shouldUseReAct = this.shouldUseReAct(query, memories);
106
- if (shouldUseReAct) {
107
- return await this.handleReAct(query, memories);
108
- }
109
- // Default to AskQuestion for understand/general queries
110
- return await this.handleAsk(query, memories);
111
- default:
112
- // CRITICAL FIX: Default to AskQuestion, not ReAct
113
- // ReAct should only be used when explicitly needed
114
- // Most queries are simple and should use AskQuestionUseCase
115
- return await this.handleAsk(query, memories);
116
- }
117
367
  }
118
368
  /**
119
369
  * Classify intent using AI and memory context
@@ -247,12 +497,63 @@ Respond with ONLY the intent word (e.g., "explain", "plan", "understand"):`;
247
497
  // Requires multiple steps if 2+ indicators or very long query
248
498
  return indicatorCount >= 2 || query.split(' ').length > 20;
249
499
  }
500
+ /**
501
+ * Handle conversational response for follow-up queries after non-code intents
502
+ * Skips code search and provides contextual answer
503
+ */
504
+ async handleConversationalResponse(query, memories, lastIntent) {
505
+ if (!this.aiService) {
506
+ return {
507
+ intent: 'general',
508
+ action: 'ask',
509
+ result: null,
510
+ success: false,
511
+ error: 'AI service not available',
512
+ memoriesUsed: memories?.length || 0,
513
+ };
514
+ }
515
+ try {
516
+ // Build conversational prompt without code context
517
+ const memoryContext = memories && memories.length > 0
518
+ ? `\n\nRelevant context from previous interactions:\n${memories.slice(0, 3).map((m, i) => `${i + 1}. ${m.description}`).join('\n')}`
519
+ : '';
520
+ const conversationContext = lastIntent === 'plan'
521
+ ? '\n\nNote: The user previously asked about planning or brainstorming. This is a follow-up question.'
522
+ : '';
523
+ const prompt = `You are a helpful AI assistant. The user is asking a follow-up question after a previous conversation about ${lastIntent || 'general topics'}.
524
+
525
+ User's question: "${query}"
526
+ ${memoryContext}${conversationContext}
527
+
528
+ Provide a helpful, conversational response. Do NOT search for code unless the user explicitly asks about code or files.`;
529
+ const response = await this.aiService.chat(prompt, []);
530
+ return {
531
+ intent: 'general',
532
+ action: 'ask',
533
+ result: { answer: response, chunks: [] },
534
+ success: true,
535
+ message: response,
536
+ memoriesUsed: memories?.length || 0,
537
+ };
538
+ }
539
+ catch (error) {
540
+ return {
541
+ intent: 'general',
542
+ action: 'ask',
543
+ result: null,
544
+ success: false,
545
+ error: error instanceof Error ? error.message : String(error),
546
+ memoriesUsed: memories?.length || 0,
547
+ };
548
+ }
549
+ }
250
550
  async checkIfIndexingNeeded(context) {
251
551
  if (context?.hasIndex === false)
252
552
  return true;
253
553
  try {
254
554
  const { container } = await import('./dependency-container.js');
255
- const repo = container.embeddingRepository;
555
+ // Use per-repo embedding repository for codebase isolation
556
+ const repo = container.getEmbeddingRepository(process.cwd());
256
557
  // Check if any embeddings exist
257
558
  const testSearch = await repo.searchWithEmbedding([0.1], 1);
258
559
  return testSearch.length === 0;
@@ -264,7 +565,8 @@ Respond with ONLY the intent word (e.g., "explain", "plan", "understand"):`;
264
565
  async handleAsk(query, memories) {
265
566
  try {
266
567
  const { container } = await import('./dependency-container.js');
267
- const useCase = container.askQuestionUseCase;
568
+ // Use per-repo use case for codebase isolation
569
+ const useCase = container.getAskQuestionUseCase(process.cwd());
268
570
  const result = await useCase.execute({ query, maxResults: 15 });
269
571
  // Record successful routing in memory
270
572
  if (this.memoryStream && memories && memories.length > 0) {
@@ -299,7 +601,8 @@ Respond with ONLY the intent word (e.g., "explain", "plan", "understand"):`;
299
601
  try {
300
602
  const { container } = await import('./dependency-container.js');
301
603
  const { ExplainWorkflow } = await import('../workflows/deterministic-workflows.js');
302
- const explainWorkflow = new ExplainWorkflow(container.embeddingRepository, container.aiService);
604
+ // Use per-repo embedding repository for codebase isolation
605
+ const explainWorkflow = new ExplainWorkflow(container.getEmbeddingRepository(process.cwd()), container.aiService);
303
606
  const workflowResult = await explainWorkflow.execute(query);
304
607
  if (workflowResult.success) {
305
608
  return {
@@ -641,7 +944,6 @@ Respond with ONLY the intent word (e.g., "explain", "plan", "understand"):`;
641
944
  */
642
945
  fastSecurityCheck(query) {
643
946
  // Fast pattern-based check for obvious security issues (synchronous, no API calls)
644
- const lower = query.toLowerCase();
645
947
  // Dangerous patterns that should be blocked immediately
646
948
  const dangerousPatterns = [
647
949
  { pattern: /execute.*user.*input|eval.*user|exec.*user/i, reason: 'Security vulnerabilities detected: 1 critical, 0 high severity findings. Review and fix before applying.' },