codehere 0.2.2 → 0.3.0-rc.1

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 (235) hide show
  1. package/README.md +88 -68
  2. package/dist/domain/entities/task.js +4 -4
  3. package/dist/error-handler.js +4 -9
  4. package/dist/index.js +253 -1219
  5. package/dist/infrastructure/config/product-context.js +7 -6
  6. package/dist/infrastructure/hooks/claude-sdk-hook.js +335 -63
  7. package/dist/infrastructure/observability/execution-tracer.js +11 -6
  8. package/dist/infrastructure/orchestration/agent-adapter.js +13 -0
  9. package/dist/infrastructure/orchestration/agent-installer.js +101 -0
  10. package/dist/infrastructure/orchestration/agents-config-seed.js +56 -0
  11. package/dist/infrastructure/orchestration/aider-adapter.js +319 -0
  12. package/dist/infrastructure/orchestration/artifacts-extractor.js +175 -0
  13. package/dist/infrastructure/orchestration/claude-code-adapter.js +352 -0
  14. package/dist/infrastructure/orchestration/codex-adapter.js +310 -0
  15. package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
  16. package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
  17. package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
  18. package/dist/infrastructure/orchestration/readiness.js +106 -0
  19. package/dist/infrastructure/orchestration/session-manager.js +272 -0
  20. package/dist/infrastructure/orchestration/session-persistence.js +109 -0
  21. package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
  22. package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
  23. package/dist/infrastructure/protocols/ui-page.js +1827 -0
  24. package/dist/infrastructure/security/file-collection.js +115 -0
  25. package/dist/infrastructure/security/trust-scorer.js +301 -56
  26. package/dist/infrastructure/storage/task-repository.js +8 -7
  27. package/dist/monitoring.js +9 -38
  28. package/dist/presentation/cli/commands/help-command.js +96 -139
  29. package/dist/presentation/cli/commands/hook-command.js +17 -24
  30. package/dist/presentation/cli/commands/report-command.js +59 -72
  31. package/dist/presentation/cli/commands/setup-command.js +4 -4
  32. package/dist/presentation/cli/commands/status-command.js +321 -30
  33. package/dist/presentation/cli/commands/trust-command.js +84 -72
  34. package/dist/presentation/cli/error-display.js +17 -21
  35. package/dist/ui.js +11 -11
  36. package/package.json +24 -62
  37. package/dist/agents/base.js +0 -101
  38. package/dist/agents/orchestrator-model-driven.js +0 -141
  39. package/dist/agents/react-orchestrator-agent.js +0 -54
  40. package/dist/application/agents/execution-agent.js +0 -508
  41. package/dist/application/agents/multi-agent-orchestrator.js +0 -295
  42. package/dist/application/agents/planning-agent.js +0 -433
  43. package/dist/application/agents/validation-agent.js +0 -317
  44. package/dist/application/architectures/plan-and-act.js +0 -242
  45. package/dist/application/index.js +0 -12
  46. package/dist/application/services/agent-factory.js +0 -28
  47. package/dist/application/services/dependency-container.js +0 -596
  48. package/dist/application/services/git-context-service.js +0 -83
  49. package/dist/application/services/intelligent-router.js +0 -934
  50. package/dist/application/services/tool-executor-service.js +0 -94
  51. package/dist/application/use-cases/ask-question-use-case.js +0 -338
  52. package/dist/application/use-cases/edit-file-use-case.js +0 -830
  53. package/dist/application/use-cases/explain-file-use-case.js +0 -50
  54. package/dist/application/use-cases/index-codebase-use-case.js +0 -113
  55. package/dist/application/use-cases/planning-use-case.js +0 -276
  56. package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
  57. package/dist/application/use-cases/reflexion-use-case.js +0 -30
  58. package/dist/application/workflows/deterministic-workflows.js +0 -189
  59. package/dist/ast-parser.js +0 -331
  60. package/dist/cache.js +0 -180
  61. package/dist/chat.js +0 -251
  62. package/dist/code-analysis.js +0 -327
  63. package/dist/context.js +0 -187
  64. package/dist/docs.js +0 -146
  65. package/dist/domain/entities/code-chunk.js +0 -6
  66. package/dist/domain/entities/decision.js +0 -9
  67. package/dist/domain/entities/edit.js +0 -6
  68. package/dist/domain/entities/knowledge-node.js +0 -9
  69. package/dist/domain/entities/knowledge-preservation.js +0 -10
  70. package/dist/domain/entities/memory.js +0 -6
  71. package/dist/domain/entities/pattern.js +0 -7
  72. package/dist/domain/entities/plan.js +0 -6
  73. package/dist/domain/entities/query.js +0 -6
  74. package/dist/domain/errors/embeddings-not-found-error.js +0 -13
  75. package/dist/domain/index.js +0 -19
  76. package/dist/domain/interfaces/ai-service.interface.js +0 -6
  77. package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
  78. package/dist/domain/interfaces/decision-repository.interface.js +0 -9
  79. package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
  80. package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
  81. package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
  82. package/dist/domain/interfaces/memory-repository.interface.js +0 -6
  83. package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
  84. package/dist/domain/interfaces/verification-service.interface.js +0 -6
  85. package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
  86. package/dist/domain/services/decision-recorder.js +0 -223
  87. package/dist/domain/services/decision-retriever.js +0 -133
  88. package/dist/domain/services/environment-mode-manager.js +0 -22
  89. package/dist/domain/services/graded-memory-activation.js +0 -69
  90. package/dist/domain/services/knowledge-access.js +0 -132
  91. package/dist/domain/services/knowledge-extractor.js +0 -247
  92. package/dist/domain/services/knowledge-graph-builder.js +0 -268
  93. package/dist/domain/services/knowledge-graph-query.js +0 -187
  94. package/dist/domain/services/memory-retriever.js +0 -82
  95. package/dist/domain/services/memory-synthesizer.js +0 -91
  96. package/dist/domain/services/pattern-extractor.js +0 -442
  97. package/dist/domain/services/query-intent-classifier.js +0 -140
  98. package/dist/domain/services/react-loop.js +0 -186
  99. package/dist/domain/services/risk-tier-detector.js +0 -78
  100. package/dist/edit.js +0 -319
  101. package/dist/embed.js +0 -459
  102. package/dist/formatter.js +0 -168
  103. package/dist/git.js +0 -198
  104. package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
  105. package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
  106. package/dist/infrastructure/ai/model-config.js +0 -84
  107. package/dist/infrastructure/ai/provider-ai-service.js +0 -477
  108. package/dist/infrastructure/cache/embedding-cache.js +0 -175
  109. package/dist/infrastructure/cache/query-result-cache.js +0 -66
  110. package/dist/infrastructure/cache/response-cache.js +0 -48
  111. package/dist/infrastructure/cache/security-scan-cache.js +0 -47
  112. package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
  113. package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
  114. package/dist/infrastructure/context/context-compressor.js +0 -329
  115. package/dist/infrastructure/context/conversation-context.js +0 -128
  116. package/dist/infrastructure/context/session-manager.js +0 -94
  117. package/dist/infrastructure/cost/cost-tracker.js +0 -360
  118. package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
  119. package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
  120. package/dist/infrastructure/governance/policy-as-code.js +0 -258
  121. package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
  122. package/dist/infrastructure/index.js +0 -7
  123. package/dist/infrastructure/observability/prompt-versioner.js +0 -145
  124. package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
  125. package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
  126. package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
  127. package/dist/infrastructure/protocols/mcp-server.js +0 -333
  128. package/dist/infrastructure/protocols/streaming-handler.js +0 -103
  129. package/dist/infrastructure/providers/cohere-provider.js +0 -444
  130. package/dist/infrastructure/providers/fake-provider.js +0 -130
  131. package/dist/infrastructure/providers/local-llm-provider.js +0 -330
  132. package/dist/infrastructure/providers/model-config.types.js +0 -9
  133. package/dist/infrastructure/providers/model-provider.interface.js +0 -8
  134. package/dist/infrastructure/providers/openai-provider.js +0 -413
  135. package/dist/infrastructure/providers/openrouter-provider.js +0 -399
  136. package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
  137. package/dist/infrastructure/providers/provider-config-loader.js +0 -120
  138. package/dist/infrastructure/providers/provider-registry.js +0 -88
  139. package/dist/infrastructure/safety/pattern-detector.js +0 -133
  140. package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
  141. package/dist/infrastructure/security/docker-sandbox.js +0 -178
  142. package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
  143. package/dist/infrastructure/security/license-scanner.js +0 -167
  144. package/dist/infrastructure/security/provider-bias-detector.js +0 -164
  145. package/dist/infrastructure/security/sandbox-executor.js +0 -64
  146. package/dist/infrastructure/serialization/toon-serializer.js +0 -119
  147. package/dist/infrastructure/storage/memory-stream-service.js +0 -204
  148. package/dist/infrastructure/storage/plan-repository.js +0 -96
  149. package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
  150. package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
  151. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
  152. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
  153. package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
  154. package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
  155. package/dist/infrastructure/storage/task-helpers.js +0 -197
  156. package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
  157. package/dist/infrastructure/ux/appropriate-friction.js +0 -213
  158. package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
  159. package/dist/infrastructure/ux/capability-boundaries.js +0 -42
  160. package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
  161. package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
  162. package/dist/infrastructure/ux/expectation-management.js +0 -327
  163. package/dist/infrastructure/ux/feature-discovery.js +0 -14
  164. package/dist/infrastructure/ux/feedback-prompt.js +0 -45
  165. package/dist/infrastructure/ux/hitl-validation.js +0 -297
  166. package/dist/infrastructure/ux/progress-indicator.js +0 -116
  167. package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
  168. package/dist/infrastructure/ux/review-checkpoint.js +0 -72
  169. package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
  170. package/dist/infrastructure/ux/stream-markdown.js +0 -151
  171. package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
  172. package/dist/infrastructure/ux/team-standards.js +0 -196
  173. package/dist/infrastructure/ux/transparency.js +0 -71
  174. package/dist/infrastructure/validation/agent-feedback.js +0 -55
  175. package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
  176. package/dist/infrastructure/validation/review-handler.js +0 -40
  177. package/dist/infrastructure/validation/summary-aggregator.js +0 -70
  178. package/dist/infrastructure/validation/summary-extractor.js +0 -45
  179. package/dist/infrastructure/validation/trace-summary.js +0 -52
  180. package/dist/infrastructure/verification/verification-service.js +0 -47
  181. package/dist/infrastructure/xai/attention-visualizer.js +0 -172
  182. package/dist/infrastructure/xai/cot-visualizer.js +0 -283
  183. package/dist/infrastructure/xai/decision-tree-log.js +0 -212
  184. package/dist/infrastructure/xai/interactive-xai.js +0 -260
  185. package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
  186. package/dist/intelligent-retrieval.js +0 -272
  187. package/dist/intent/classifier.js +0 -2
  188. package/dist/intent/context.js +0 -2
  189. package/dist/iterative-refinement.js +0 -189
  190. package/dist/learning.js +0 -232
  191. package/dist/log.js +0 -31
  192. package/dist/migrate.js +0 -133
  193. package/dist/parallel-processor.js +0 -534
  194. package/dist/planner.js +0 -198
  195. package/dist/policy.js +0 -26
  196. package/dist/presentation/cli/commands/ask-command.js +0 -314
  197. package/dist/presentation/cli/commands/cost-command.js +0 -191
  198. package/dist/presentation/cli/commands/decision-command.js +0 -207
  199. package/dist/presentation/cli/commands/docs-command.js +0 -25
  200. package/dist/presentation/cli/commands/fix-command.js +0 -53
  201. package/dist/presentation/cli/commands/knowledge-command.js +0 -129
  202. package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
  203. package/dist/presentation/cli/commands/models-command.js +0 -194
  204. package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
  205. package/dist/presentation/cli/commands/plan-command.js +0 -246
  206. package/dist/presentation/cli/commands/product-command.js +0 -199
  207. package/dist/presentation/cli/commands/react-command.js +0 -181
  208. package/dist/presentation/cli/commands/review-command.js +0 -154
  209. package/dist/presentation/cli/commands/run-command.js +0 -188
  210. package/dist/presentation/cli/commands/smart-command.js +0 -395
  211. package/dist/presentation/cli/commands/suggest-command.js +0 -138
  212. package/dist/presentation/cli/commands/trace-command.js +0 -129
  213. package/dist/presentation/cli/commands/undo-command.js +0 -150
  214. package/dist/query-optimizer.js +0 -205
  215. package/dist/refactor.js +0 -116
  216. package/dist/review.js +0 -206
  217. package/dist/search.js +0 -163
  218. package/dist/session.js +0 -704
  219. package/dist/task-verification.js +0 -336
  220. package/dist/testgen.js +0 -166
  221. package/dist/token-optimizer.js +0 -277
  222. package/dist/tools/bash.js +0 -213
  223. package/dist/tools/edit.js +0 -235
  224. package/dist/tools/executor.js +0 -153
  225. package/dist/tools/git-tool.js +0 -292
  226. package/dist/tools/parser.js +0 -158
  227. package/dist/tools/registry.js +0 -302
  228. package/dist/tools/search.js +0 -100
  229. package/dist/types.js +0 -2
  230. package/dist/utils/check-api-status.js +0 -100
  231. package/dist/utils/diff-parser.js +0 -162
  232. package/dist/verification/backup.js +0 -259
  233. package/dist/verification/compiler.js +0 -264
  234. package/dist/verification/index.js +0 -273
  235. package/dist/verification/test-runner.js +0 -379
@@ -1,596 +0,0 @@
1
- /**
2
- * Dependency Container
3
- * Simple DI container for wiring up dependencies
4
- */
5
- import { CohereAIService } from '../../infrastructure/ai/cohere-ai-service.js';
6
- import { SQLiteEmbeddingRepository } from '../../infrastructure/storage/sqlite-embedding-repository.js';
7
- import { SQLiteMemoryRepository } from '../../infrastructure/storage/sqlite-memory-repository.js';
8
- import { MemoryStreamService } from '../../infrastructure/storage/memory-stream-service.js';
9
- import { ToolExecutorService } from './tool-executor-service.js';
10
- import { AskQuestionUseCase } from '../use-cases/ask-question-use-case.js';
11
- import { IndexCodebaseUseCase } from '../use-cases/index-codebase-use-case.js';
12
- import { ReActOrchestrationUseCase } from '../use-cases/react-orchestration-use-case.js';
13
- import { ReflexionUseCase } from '../use-cases/reflexion-use-case.js';
14
- import { EditFileUseCase } from '../use-cases/edit-file-use-case.js';
15
- import { ExplainFileUseCase } from '../use-cases/explain-file-use-case.js';
16
- import { PlanningUseCase } from '../use-cases/planning-use-case.js';
17
- import { VerificationService } from '../../infrastructure/verification/verification-service.js';
18
- import { AISASTScanner } from '../../infrastructure/security/ai-sast-scanner.js';
19
- import { LicenseScanner } from '../../infrastructure/security/license-scanner.js';
20
- import { ProviderBiasDetector } from '../../infrastructure/security/provider-bias-detector.js';
21
- import { UncertaintyQuantifier } from '../../infrastructure/xai/uncertainty-quantifier.js';
22
- import { EnhancedSecurityGate } from '../../infrastructure/security/enhanced-security-gate.js';
23
- import { DecisionTreeLog } from '../../infrastructure/xai/decision-tree-log.js';
24
- import { CoTVisualizer } from '../../infrastructure/xai/cot-visualizer.js';
25
- import { AttentionVisualizer } from '../../infrastructure/xai/attention-visualizer.js';
26
- import { InteractiveXAI } from '../../infrastructure/xai/interactive-xai.js';
27
- import { ContextCompressor } from '../../infrastructure/context/context-compressor.js';
28
- import { AppropriateFriction } from '../../infrastructure/ux/appropriate-friction.js';
29
- import { HITLValidation } from '../../infrastructure/ux/hitl-validation.js';
30
- import { BiDirectionalLearning } from '../../infrastructure/ux/bi-directional-learning.js';
31
- import { TeamStandards } from '../../infrastructure/ux/team-standards.js';
32
- import { ProgressiveDisclosure } from '../../infrastructure/ux/progressive-disclosure.js';
33
- import { ExpectationManagement } from '../../infrastructure/ux/expectation-management.js';
34
- import { NISTAIRMF } from '../../infrastructure/governance/nist-ai-rmf.js';
35
- import { PolicyAsCode } from '../../infrastructure/governance/policy-as-code.js';
36
- import { PromptToCodeLineage } from '../../infrastructure/governance/prompt-to-code-lineage.js';
37
- import { ASTCodeChunker } from '../../infrastructure/chunking/ast-code-chunker.js';
38
- import { FileScanner } from '../../infrastructure/file-scanner/file-scanner.js';
39
- import { MultiAgentOrchestrator } from '../agents/multi-agent-orchestrator.js';
40
- import { PlanningAgent } from '../agents/planning-agent.js';
41
- import { ExecutionAgent } from '../agents/execution-agent.js';
42
- import { ValidationAgent } from '../agents/validation-agent.js';
43
- import { SQLiteDecisionRepository } from '../../infrastructure/storage/sqlite-decision-repository.js';
44
- import { DecisionRecorder } from '../../domain/services/decision-recorder.js';
45
- import { DecisionRetriever } from '../../domain/services/decision-retriever.js';
46
- import { SQLitePatternRepository } from '../../infrastructure/storage/sqlite-pattern-repository.js';
47
- import { PatternExtractor } from '../../domain/services/pattern-extractor.js';
48
- import { SQLiteKnowledgePreservationRepository } from '../../infrastructure/storage/sqlite-knowledge-preservation-repository.js';
49
- import { KnowledgeExtractor } from '../../domain/services/knowledge-extractor.js';
50
- import { KnowledgeAccess } from '../../domain/services/knowledge-access.js';
51
- import { CrossTeamPatternSharing } from '../../domain/services/cross-team-pattern-sharing.js';
52
- import { ProviderRegistry } from '../../infrastructure/providers/provider-registry.js';
53
- import { CohereProvider } from '../../infrastructure/providers/cohere-provider.js';
54
- import { OpenAIProvider } from '../../infrastructure/providers/openai-provider.js';
55
- import { OpenRouterProvider } from '../../infrastructure/providers/openrouter-provider.js';
56
- import { FakeProvider } from '../../infrastructure/providers/fake-provider.js';
57
- import { LocalLLMProvider } from '../../infrastructure/providers/local-llm-provider.js';
58
- import { ProviderAIService } from '../../infrastructure/ai/provider-ai-service.js';
59
- import { loadProviderConfig, configToOperationConfig } from '../../infrastructure/providers/provider-config-loader.js';
60
- export class DependencyContainer {
61
- // Infrastructure
62
- _aiService = null;
63
- _providerRegistry = null;
64
- _embeddingRepository = null;
65
- _memoryRepository = null;
66
- // Services
67
- _memoryStreamService = null;
68
- _toolExecutorService = null;
69
- // Infrastructure Services
70
- _verificationService = null;
71
- _sastScanner = null;
72
- _licenseScanner = null;
73
- _providerBiasDetector = null;
74
- _uncertaintyQuantifier = null;
75
- _enhancedSecurityGate = null;
76
- _decisionTreeLog = null;
77
- // XAI Visualization
78
- _cotVisualizer = null;
79
- _attentionVisualizer = null;
80
- _interactiveXAI = null;
81
- // Context Compression
82
- _contextCompressor = null;
83
- // UX Systems
84
- _appropriateFriction = null;
85
- _hitlValidation = null;
86
- _biDirectionalLearning = null;
87
- _teamStandards = null;
88
- _progressiveDisclosure = null;
89
- _expectationManagement = null;
90
- // Governance Systems
91
- _nistAIRMF = null;
92
- _policyAsCode = null;
93
- _promptToCodeLineage = null;
94
- // Decision Services
95
- _decisionRepository = null;
96
- _decisionRecorder = null;
97
- _decisionRetriever = null;
98
- // Pattern Services
99
- _patternRepository = null;
100
- _patternExtractor = null;
101
- // Knowledge Preservation Services
102
- _knowledgePreservationRepository = null;
103
- _knowledgeExtractor = null;
104
- _knowledgeAccess = null;
105
- // Cross-Team Learning Services
106
- _crossTeamPatternSharing = null;
107
- // Use Cases
108
- _askQuestionUseCase = null;
109
- _indexCodebaseUseCase = null;
110
- _reactOrchestrationUseCase = null;
111
- _reflexionUseCase = null;
112
- _editFileUseCase = null;
113
- _explainFileUseCase = null;
114
- _planningUseCase = null;
115
- /**
116
- * Provider Registry
117
- * Phase 4C: Provider selection via env/config
118
- *
119
- * Provider Selection Logic:
120
- * - Always register CohereProvider (default)
121
- * - Register OpenAIProvider if CODEHERE_OPENAI_API_KEY is set
122
- * - Default provider:
123
- * - If CODEHERE_AI_PROVIDER=openai and OpenAIProvider available → OpenAI
124
- * - Else → Cohere (backward compatible)
125
- */
126
- get providerRegistry() {
127
- if (!this._providerRegistry) {
128
- this._providerRegistry = ProviderRegistry.getInstance();
129
- // Phase 4D: Register FakeProvider when CODEHERE_FAKE_AI=1 (highest priority)
130
- if (process.env.CODEHERE_FAKE_AI === '1') {
131
- try {
132
- const fakeProvider = new FakeProvider();
133
- this._providerRegistry.register(fakeProvider);
134
- this._providerRegistry.setDefault('fake');
135
- }
136
- catch (error) {
137
- console.warn('[ProviderRegistry] FakeProvider initialization failed:', error instanceof Error ? error.message : String(error));
138
- }
139
- }
140
- else {
141
- // Register real providers (Cohere, OpenAI, Local LLM)
142
- // Always register CohereProvider (default fallback)
143
- try {
144
- const cohereProvider = new CohereProvider();
145
- this._providerRegistry.register(cohereProvider);
146
- }
147
- catch (error) {
148
- // Silently skip — provider not configured
149
- }
150
- // Phase 4E: Register LocalLLMProvider if CODEHERE_AI_PROVIDER=local and base URL is set
151
- const requestedProvider = process.env.CODEHERE_AI_PROVIDER?.toLowerCase();
152
- if (requestedProvider === 'local' && process.env.CODEHERE_LOCAL_BASE_URL) {
153
- try {
154
- const localProvider = new LocalLLMProvider();
155
- this._providerRegistry.register(localProvider);
156
- this._providerRegistry.setDefault('local');
157
- }
158
- catch (error) {
159
- console.warn('[ProviderRegistry] LocalLLMProvider initialization failed:', error instanceof Error ? error.message : String(error));
160
- console.warn('[ProviderRegistry] Falling back to CohereProvider');
161
- }
162
- }
163
- // Register OpenAIProvider if API key is available
164
- if (process.env.CODEHERE_OPENAI_API_KEY || process.env.OPENAI_API_KEY) {
165
- try {
166
- const openaiProvider = new OpenAIProvider();
167
- this._providerRegistry.register(openaiProvider);
168
- }
169
- catch (error) {
170
- // Silently skip — provider not configured
171
- }
172
- }
173
- // Register OpenRouterProvider if API key is available
174
- if (process.env.OPENROUTER_API_KEY) {
175
- try {
176
- const openRouterProvider = new OpenRouterProvider();
177
- this._providerRegistry.register(openRouterProvider);
178
- }
179
- catch (error) {
180
- // Silently skip — provider not configured
181
- }
182
- }
183
- // Set default provider based on CODEHERE_AI_PROVIDER env var
184
- // Priority: local > openrouter > openai > cohere (default)
185
- if (requestedProvider === 'local' && this._providerRegistry.has('local')) {
186
- this._providerRegistry.setDefault('local');
187
- }
188
- else if (requestedProvider === 'openrouter' && this._providerRegistry.has('openrouter')) {
189
- this._providerRegistry.setDefault('openrouter');
190
- }
191
- else if (requestedProvider === 'openai' && this._providerRegistry.has('openai')) {
192
- this._providerRegistry.setDefault('openai');
193
- }
194
- else {
195
- // Default to Cohere (backward compatible)
196
- if (this._providerRegistry.has('cohere')) {
197
- this._providerRegistry.setDefault('cohere');
198
- }
199
- }
200
- }
201
- }
202
- return this._providerRegistry;
203
- }
204
- get aiService() {
205
- if (!this._aiService) {
206
- // Phase 4G: Load provider config from file (if present)
207
- const providerConfig = loadProviderConfig();
208
- const operationConfig = providerConfig ? configToOperationConfig(providerConfig) : null;
209
- const configDefault = providerConfig?.default || null;
210
- // Phase 4D: Use ProviderAIService with FakeProvider when CODEHERE_FAKE_AI=1
211
- // This unifies fake mode through the provider layer while maintaining backward compatibility
212
- // Note: FakeAIService is kept for backward compatibility but FakeProvider is preferred
213
- try {
214
- const provider = this.providerRegistry.getDefault();
215
- // Break circular dependency: Create aiService first without compressor
216
- // Phase 4G: Pass operation config and config default to ProviderAIService
217
- this._aiService = new ProviderAIService(provider, undefined, operationConfig, configDefault);
218
- // Then inject compressor if it exists (lazy injection after both are created)
219
- if (this._contextCompressor) {
220
- this._aiService._contextCompressor = this._contextCompressor;
221
- }
222
- }
223
- catch (error) {
224
- // Fallback to CohereAIService if provider registry fails
225
- console.warn('[DependencyContainer] ProviderAIService initialization failed, falling back to CohereAIService:', error instanceof Error ? error.message : String(error));
226
- this._aiService = new CohereAIService();
227
- if (this._contextCompressor) {
228
- this._aiService._contextCompressor = this._contextCompressor;
229
- }
230
- }
231
- }
232
- return this._aiService;
233
- }
234
- /**
235
- * Get embedding repository for a specific codebase
236
- * @param cwd - Current working directory for codebase root detection (defaults to process.cwd())
237
- * @returns SQLiteEmbeddingRepository instance scoped to the codebase
238
- */
239
- getEmbeddingRepository(cwd) {
240
- // Always create a new instance with the provided cwd to ensure per-repo isolation
241
- // This ensures each codebase gets its own database path
242
- return new SQLiteEmbeddingRepository(undefined, cwd);
243
- }
244
- /**
245
- * @deprecated Use getEmbeddingRepository(cwd) instead for per-repo isolation
246
- * Kept for backward compatibility
247
- */
248
- get embeddingRepository() {
249
- if (!this._embeddingRepository) {
250
- // Use process.cwd() for backward compatibility
251
- this._embeddingRepository = new SQLiteEmbeddingRepository(undefined, process.cwd());
252
- }
253
- return this._embeddingRepository;
254
- }
255
- get memoryRepository() {
256
- if (!this._memoryRepository) {
257
- this._memoryRepository = new SQLiteMemoryRepository();
258
- }
259
- return this._memoryRepository;
260
- }
261
- get memoryStreamService() {
262
- if (!this._memoryStreamService) {
263
- this._memoryStreamService = new MemoryStreamService(this.memoryRepository, this.aiService);
264
- }
265
- return this._memoryStreamService;
266
- }
267
- /**
268
- * Get ask question use case for a specific codebase
269
- * @param cwd - Current working directory for codebase root detection (defaults to process.cwd())
270
- * @returns AskQuestionUseCase instance scoped to the codebase
271
- */
272
- getAskQuestionUseCase(cwd) {
273
- const embeddingRepo = this.getEmbeddingRepository(cwd);
274
- return new AskQuestionUseCase(embeddingRepo, this.aiService, this.memoryRepository, this.uncertaintyQuantifier);
275
- }
276
- /**
277
- * @deprecated Use getAskQuestionUseCase(cwd) instead for per-repo isolation
278
- * Kept for backward compatibility
279
- */
280
- get askQuestionUseCase() {
281
- if (!this._askQuestionUseCase) {
282
- this._askQuestionUseCase = new AskQuestionUseCase(this.embeddingRepository, this.aiService, this.memoryRepository, this.uncertaintyQuantifier // Uncertainty Quantifier for XAI transparency
283
- );
284
- }
285
- return this._askQuestionUseCase;
286
- }
287
- /**
288
- * Get index codebase use case for a specific codebase
289
- * @param cwd - Current working directory for codebase root detection (defaults to process.cwd())
290
- * @returns IndexCodebaseUseCase instance scoped to the codebase
291
- */
292
- getIndexCodebaseUseCase(cwd) {
293
- const embeddingRepo = this.getEmbeddingRepository(cwd);
294
- const fileScanner = new FileScanner();
295
- const chunker = new ASTCodeChunker();
296
- return new IndexCodebaseUseCase(embeddingRepo, fileScanner, chunker, this.aiService, this.patternExtractor, // Pass pattern extractor for pattern extraction during indexing
297
- this.knowledgeExtractor // Pass knowledge extractor for knowledge extraction during indexing
298
- );
299
- }
300
- /**
301
- * @deprecated Use getIndexCodebaseUseCase(cwd) instead for per-repo isolation
302
- * Kept for backward compatibility
303
- */
304
- get indexCodebaseUseCase() {
305
- if (!this._indexCodebaseUseCase) {
306
- const fileScanner = new FileScanner();
307
- const chunker = new ASTCodeChunker();
308
- this._indexCodebaseUseCase = new IndexCodebaseUseCase(this.embeddingRepository, fileScanner, chunker, this.aiService, this.patternExtractor, // Pass pattern extractor for pattern extraction during indexing
309
- this.knowledgeExtractor // Pass knowledge extractor for knowledge extraction during indexing
310
- );
311
- }
312
- return this._indexCodebaseUseCase;
313
- }
314
- get toolExecutorService() {
315
- if (!this._toolExecutorService) {
316
- this._toolExecutorService = new ToolExecutorService();
317
- }
318
- return this._toolExecutorService;
319
- }
320
- get reactOrchestrationUseCase() {
321
- if (!this._reactOrchestrationUseCase) {
322
- this._reactOrchestrationUseCase = new ReActOrchestrationUseCase(this.aiService, this.memoryStreamService, this.toolExecutorService, this.decisionTreeLog, // Decision Tree Log for XAI auditability
323
- this.uncertaintyQuantifier, // Uncertainty Quantifier for XAI transparency
324
- this.cotVisualizer, // CoT Visualizer for reasoning transparency
325
- this.attentionVisualizer // Attention Visualizer for context grounding
326
- );
327
- }
328
- return this._reactOrchestrationUseCase;
329
- }
330
- get reflexionUseCase() {
331
- if (!this._reflexionUseCase) {
332
- this._reflexionUseCase = new ReflexionUseCase(this.aiService, this.memoryStreamService);
333
- }
334
- return this._reflexionUseCase;
335
- }
336
- get verificationService() {
337
- if (!this._verificationService) {
338
- this._verificationService = new VerificationService();
339
- }
340
- return this._verificationService;
341
- }
342
- get sastScanner() {
343
- if (!this._sastScanner) {
344
- this._sastScanner = new AISASTScanner(this.aiService);
345
- }
346
- return this._sastScanner;
347
- }
348
- get licenseScanner() {
349
- if (!this._licenseScanner) {
350
- this._licenseScanner = new LicenseScanner();
351
- }
352
- return this._licenseScanner;
353
- }
354
- get providerBiasDetector() {
355
- if (!this._providerBiasDetector) {
356
- this._providerBiasDetector = new ProviderBiasDetector();
357
- }
358
- return this._providerBiasDetector;
359
- }
360
- get uncertaintyQuantifier() {
361
- if (!this._uncertaintyQuantifier) {
362
- this._uncertaintyQuantifier = new UncertaintyQuantifier();
363
- }
364
- return this._uncertaintyQuantifier;
365
- }
366
- get enhancedSecurityGate() {
367
- if (!this._enhancedSecurityGate) {
368
- this._enhancedSecurityGate = new EnhancedSecurityGate(this.sastScanner, this.licenseScanner, this.providerBiasDetector, this.uncertaintyQuantifier);
369
- }
370
- return this._enhancedSecurityGate;
371
- }
372
- get decisionTreeLog() {
373
- if (!this._decisionTreeLog) {
374
- this._decisionTreeLog = new DecisionTreeLog();
375
- }
376
- return this._decisionTreeLog;
377
- }
378
- // XAI Visualization Getters
379
- get cotVisualizer() {
380
- if (!this._cotVisualizer) {
381
- this._cotVisualizer = new CoTVisualizer();
382
- }
383
- return this._cotVisualizer;
384
- }
385
- get attentionVisualizer() {
386
- if (!this._attentionVisualizer) {
387
- this._attentionVisualizer = new AttentionVisualizer();
388
- }
389
- return this._attentionVisualizer;
390
- }
391
- get interactiveXAI() {
392
- if (!this._interactiveXAI) {
393
- this._interactiveXAI = new InteractiveXAI();
394
- }
395
- return this._interactiveXAI;
396
- }
397
- // UX Systems Getters
398
- get appropriateFriction() {
399
- if (!this._appropriateFriction) {
400
- this._appropriateFriction = new AppropriateFriction();
401
- }
402
- return this._appropriateFriction;
403
- }
404
- get hitlValidation() {
405
- if (!this._hitlValidation) {
406
- this._hitlValidation = new HITLValidation();
407
- }
408
- return this._hitlValidation;
409
- }
410
- get biDirectionalLearning() {
411
- if (!this._biDirectionalLearning) {
412
- this._biDirectionalLearning = new BiDirectionalLearning();
413
- }
414
- return this._biDirectionalLearning;
415
- }
416
- get teamStandards() {
417
- if (!this._teamStandards) {
418
- this._teamStandards = new TeamStandards();
419
- }
420
- return this._teamStandards;
421
- }
422
- get progressiveDisclosure() {
423
- if (!this._progressiveDisclosure) {
424
- this._progressiveDisclosure = new ProgressiveDisclosure();
425
- }
426
- return this._progressiveDisclosure;
427
- }
428
- get expectationManagement() {
429
- if (!this._expectationManagement) {
430
- this._expectationManagement = new ExpectationManagement();
431
- }
432
- return this._expectationManagement;
433
- }
434
- // Governance Systems Getters
435
- get nistAIRMF() {
436
- if (!this._nistAIRMF) {
437
- this._nistAIRMF = new NISTAIRMF();
438
- }
439
- return this._nistAIRMF;
440
- }
441
- get policyAsCode() {
442
- if (!this._policyAsCode) {
443
- this._policyAsCode = new PolicyAsCode();
444
- }
445
- return this._policyAsCode;
446
- }
447
- get promptToCodeLineage() {
448
- if (!this._promptToCodeLineage) {
449
- this._promptToCodeLineage = new PromptToCodeLineage();
450
- }
451
- return this._promptToCodeLineage;
452
- }
453
- get editFileUseCase() {
454
- if (!this._editFileUseCase) {
455
- this._editFileUseCase = new EditFileUseCase(this.aiService, this.verificationService, this.sastScanner, // Legacy: Pass SAST scanner for backward compatibility
456
- this.enhancedSecurityGate, // Enhanced security gate with all scanners
457
- this.appropriateFriction, // Appropriate friction system
458
- this.hitlValidation, // HITL validation system
459
- this.biDirectionalLearning, // Bi-directional learning system
460
- this.teamStandards, // Team standards system
461
- this.promptToCodeLineage, // Prompt-to-code lineage tracking
462
- this.nistAIRMF, // NIST AI RMF for enterprise governance
463
- this.policyAsCode // Policy-as-Code for automated compliance
464
- );
465
- }
466
- return this._editFileUseCase;
467
- }
468
- get explainFileUseCase() {
469
- if (!this._explainFileUseCase) {
470
- this._explainFileUseCase = new ExplainFileUseCase(this.aiService);
471
- }
472
- return this._explainFileUseCase;
473
- }
474
- get planningUseCase() {
475
- if (!this._planningUseCase) {
476
- this._planningUseCase = new PlanningUseCase(this.aiService, this.memoryStreamService, this.memoryRepository, this.patternExtractor // Pass pattern extractor for memory synthesis integration
477
- );
478
- }
479
- return this._planningUseCase;
480
- }
481
- // Agents
482
- _planningAgent = null;
483
- _executionAgent = null;
484
- _validationAgent = null;
485
- _multiAgentOrchestrator = null;
486
- get planningAgent() {
487
- if (!this._planningAgent) {
488
- this._planningAgent = new PlanningAgent(this.aiService, this.memoryStreamService, this.memoryRepository, process.cwd(), this.decisionRecorder, // Pass decision recorder for decision extraction
489
- this.patternRepository, // Pass pattern repository for pattern suggestions
490
- this.knowledgeAccess // Pass knowledge access for knowledge retrieval
491
- );
492
- }
493
- return this._planningAgent;
494
- }
495
- get executionAgent() {
496
- if (!this._executionAgent) {
497
- this._executionAgent = new ExecutionAgent(this.aiService, this.toolExecutorService, process.cwd());
498
- }
499
- return this._executionAgent;
500
- }
501
- get validationAgent() {
502
- if (!this._validationAgent) {
503
- this._validationAgent = new ValidationAgent(this.aiService, this.verificationService);
504
- }
505
- return this._validationAgent;
506
- }
507
- get multiAgentOrchestrator() {
508
- if (!this._multiAgentOrchestrator) {
509
- this._multiAgentOrchestrator = new MultiAgentOrchestrator(this.aiService, this.memoryStreamService, this.memoryRepository, this.toolExecutorService, this.verificationService, this.sastScanner, process.cwd());
510
- }
511
- return this._multiAgentOrchestrator;
512
- }
513
- // Decision Services
514
- get decisionRepository() {
515
- if (!this._decisionRepository) {
516
- this._decisionRepository = new SQLiteDecisionRepository();
517
- }
518
- return this._decisionRepository;
519
- }
520
- get decisionRecorder() {
521
- if (!this._decisionRecorder) {
522
- this._decisionRecorder = new DecisionRecorder(this.decisionRepository);
523
- }
524
- return this._decisionRecorder;
525
- }
526
- get decisionRetriever() {
527
- if (!this._decisionRetriever) {
528
- this._decisionRetriever = new DecisionRetriever(this.decisionRepository);
529
- }
530
- return this._decisionRetriever;
531
- }
532
- // Pattern Services
533
- get patternRepository() {
534
- if (!this._patternRepository) {
535
- this._patternRepository = new SQLitePatternRepository();
536
- }
537
- return this._patternRepository;
538
- }
539
- get patternExtractor() {
540
- if (!this._patternExtractor) {
541
- this._patternExtractor = new PatternExtractor(this.patternRepository, this.aiService);
542
- }
543
- return this._patternExtractor;
544
- }
545
- // Knowledge Preservation Services
546
- get knowledgePreservationRepository() {
547
- if (!this._knowledgePreservationRepository) {
548
- this._knowledgePreservationRepository = new SQLiteKnowledgePreservationRepository();
549
- }
550
- return this._knowledgePreservationRepository;
551
- }
552
- get knowledgeExtractor() {
553
- if (!this._knowledgeExtractor) {
554
- this._knowledgeExtractor = new KnowledgeExtractor(this.knowledgePreservationRepository, this.patternRepository, this.aiService);
555
- }
556
- return this._knowledgeExtractor;
557
- }
558
- get knowledgeAccess() {
559
- if (!this._knowledgeAccess) {
560
- this._knowledgeAccess = new KnowledgeAccess(this.knowledgePreservationRepository, this.patternRepository, this.decisionRepository);
561
- }
562
- return this._knowledgeAccess;
563
- }
564
- get crossTeamPatternSharing() {
565
- if (!this._crossTeamPatternSharing) {
566
- this._crossTeamPatternSharing = new CrossTeamPatternSharing(this.patternRepository);
567
- }
568
- return this._crossTeamPatternSharing;
569
- }
570
- // Context Compression
571
- get contextCompressor() {
572
- if (!this._contextCompressor) {
573
- // Break circular dependency: Create aiService first (without compressor to avoid loop)
574
- // Create a temporary aiService just for compressor initialization
575
- // Then create compressor with that aiService
576
- // The aiService will get compressor injected lazily via property setter
577
- const tempAIService = this._aiService || (() => {
578
- try {
579
- const provider = this.providerRegistry.getDefault();
580
- return new ProviderAIService(provider);
581
- }
582
- catch {
583
- return new CohereAIService();
584
- }
585
- })();
586
- this._contextCompressor = new ContextCompressor(tempAIService);
587
- // Inject compressor into aiService if it exists (lazy injection)
588
- if (this._aiService) {
589
- this._aiService._contextCompressor = this._contextCompressor;
590
- }
591
- }
592
- return this._contextCompressor;
593
- }
594
- }
595
- export const container = new DependencyContainer();
596
- //# sourceMappingURL=dependency-container.js.map
@@ -1,83 +0,0 @@
1
- /**
2
- * Application Service: Git Context Service
3
- * Provides Git diff retrieval for code understanding
4
- *
5
- * Best Practice: Centralized Git context management for code understanding
6
- */
7
- import { GitTool } from '../../tools/git-tool.js';
8
- export class GitContextService {
9
- gitTool;
10
- constructor(cwd = process.cwd()) {
11
- this.gitTool = new GitTool(cwd);
12
- }
13
- /**
14
- * Get comprehensive Git context for code understanding
15
- */
16
- async getContext(filepath) {
17
- const status = await this.gitTool.status();
18
- const currentBranch = status.branch;
19
- // Get uncommitted changes
20
- const uncommittedDiffs = await this.gitTool.diff(undefined, undefined, filepath);
21
- // Get recent changes (last commit)
22
- const recentDiffs = await this.gitTool.diff('HEAD~1', 'HEAD', filepath);
23
- // Get file history if specific file requested
24
- let fileHistory;
25
- if (filepath) {
26
- const commits = await this.gitTool.log(5, filepath);
27
- if (commits.length > 0) {
28
- // Get diff for each commit
29
- fileHistory = [];
30
- for (let i = 0; i < commits.length - 1; i++) {
31
- const diffs = await this.gitTool.diff(commits[i + 1].hash, commits[i].hash, filepath);
32
- fileHistory.push(...diffs);
33
- }
34
- }
35
- }
36
- return {
37
- currentBranch,
38
- uncommittedChanges: uncommittedDiffs,
39
- recentChanges: recentDiffs,
40
- fileHistory,
41
- };
42
- }
43
- /**
44
- * Get diff for specific file to understand recent changes
45
- */
46
- async getFileDiff(filepath, commits = 1) {
47
- try {
48
- const commitsList = await this.gitTool.log(commits + 1, filepath);
49
- if (commitsList.length < 2) {
50
- return await this.gitTool.diff(undefined, undefined, filepath);
51
- }
52
- return await this.gitTool.diff(commitsList[commits].hash, commitsList[0].hash, filepath);
53
- }
54
- catch {
55
- // Fallback to uncommitted diff
56
- return await this.gitTool.diff(undefined, undefined, filepath);
57
- }
58
- }
59
- /**
60
- * Get diff summary for code understanding
61
- */
62
- async getDiffSummary(filepath) {
63
- const context = await this.getContext(filepath);
64
- let summary = '';
65
- if (context.currentBranch) {
66
- summary += `Current branch: ${context.currentBranch}\n`;
67
- }
68
- if (context.uncommittedChanges.length > 0) {
69
- summary += `\nUncommitted changes:\n`;
70
- for (const diff of context.uncommittedChanges) {
71
- summary += ` ${diff.filepath}: +${diff.additions} -${diff.deletions}\n`;
72
- }
73
- }
74
- if (context.recentChanges.length > 0) {
75
- summary += `\nRecent changes (last commit):\n`;
76
- for (const diff of context.recentChanges) {
77
- summary += ` ${diff.filepath}: +${diff.additions} -${diff.deletions}\n`;
78
- }
79
- }
80
- return summary;
81
- }
82
- }
83
- //# sourceMappingURL=git-context-service.js.map