codehere 0.2.1 → 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 +10 -49
  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 +334 -43
  33. package/dist/presentation/cli/commands/trust-command.js +115 -99
  34. package/dist/presentation/cli/error-display.js +17 -21
  35. package/dist/ui.js +17 -12
  36. package/package.json +35 -67
  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 -530
  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 -652
  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,317 +0,0 @@
1
- /**
2
- * Application Agent: Validation Agent (Test Validator)
3
- * Specialized agent for updating/generating tests, executing test suite, analyzing results
4
- *
5
- * Based on enterprise architecture: Separate Validation Agent
6
- * Role: Validates execution results, runs tests, provides feedback
7
- */
8
- import { exec } from 'child_process';
9
- import { promisify } from 'util';
10
- import { existsSync, readFileSync } from 'fs';
11
- import { agentValidationHelper } from '../../infrastructure/validation/agent-validation-helper.js';
12
- import { findCodebaseRoot } from '../../domain/services/codebase-detector.js';
13
- const execAsync = promisify(exec);
14
- export class ValidationAgent {
15
- aiService;
16
- verificationService;
17
- cwd = process.cwd();
18
- constructor(aiService, verificationService, cwd) {
19
- this.aiService = aiService;
20
- this.verificationService = verificationService;
21
- if (cwd) {
22
- this.cwd = cwd;
23
- }
24
- }
25
- /**
26
- * Validate execution results
27
- * Runs tests, checks compilation, analyzes quality
28
- */
29
- async validate(request) {
30
- const { plan, executionResults, filesModified = [] } = request;
31
- // Start validation context
32
- const codebaseInfo = findCodebaseRoot(this.cwd);
33
- const validationContext = agentValidationHelper.startAgentOperation('validation-agent', 'validate', {
34
- query: plan.goal,
35
- codebaseId: codebaseInfo?.codebaseId,
36
- });
37
- try {
38
- // Track validation checks
39
- const validationChecks = [];
40
- const errors = [];
41
- const warnings = [];
42
- // 1. Check compilation for modified files
43
- const compilationResult = await this.checkCompilation(filesModified);
44
- // Record compilation check
45
- validationChecks.push({
46
- check: 'Compilation',
47
- passed: compilationResult.success,
48
- message: compilationResult.success
49
- ? 'All files compile successfully'
50
- : `${compilationResult.errors.length} compilation error(s)`,
51
- critical: true,
52
- });
53
- if (!compilationResult.success && compilationResult.errors.length > 0) {
54
- errors.push(...compilationResult.errors);
55
- }
56
- // Trace compilation check
57
- agentValidationHelper.trace({
58
- operationType: 'code_analysis',
59
- operationName: 'compile_check',
60
- input: { files: filesModified },
61
- output: compilationResult,
62
- error: compilationResult.success ? undefined : new Error('Compilation failed'),
63
- metadata: {
64
- filesChecked: filesModified.length,
65
- errors: compilationResult.errors.length,
66
- },
67
- });
68
- // 2. Run test suite
69
- const testResult = await this.runTests();
70
- // Record test check
71
- const testsPassed = testResult.testsPassed;
72
- if (testResult.testResults) {
73
- validationChecks.push({
74
- check: 'Tests',
75
- passed: testsPassed,
76
- message: testsPassed
77
- ? `All ${testResult.testResults.total} tests passed`
78
- : `${testResult.testResults.failed} of ${testResult.testResults.total} tests failed`,
79
- critical: true,
80
- });
81
- if (testResult.testResults.failures) {
82
- testResult.testResults.failures.forEach(failure => {
83
- errors.push(`Test failure: ${failure.test} - ${failure.error}`);
84
- });
85
- }
86
- }
87
- else {
88
- validationChecks.push({
89
- check: 'Tests',
90
- passed: true,
91
- message: 'No tests to run',
92
- });
93
- }
94
- // Trace test execution
95
- agentValidationHelper.trace({
96
- operationType: 'code_analysis',
97
- operationName: 'test_execution',
98
- input: {},
99
- output: testResult,
100
- metadata: {
101
- testsTotal: testResult.testResults?.total,
102
- testsPassed: testResult.testResults?.passed,
103
- testsFailed: testResult.testResults?.failed,
104
- },
105
- });
106
- // 3. Analyze code quality
107
- const qualityAnalysis = await this.analyzeQuality(plan, executionResults);
108
- // Calculate quality score for validation check
109
- const qualityScore = this.calculateQualityScore(compilationResult, testResult, qualityAnalysis);
110
- // Record quality check
111
- validationChecks.push({
112
- check: 'Code Quality',
113
- passed: qualityScore >= 70, // Threshold
114
- message: `Quality score: ${qualityScore}/100`,
115
- critical: false,
116
- });
117
- if (qualityAnalysis.errorRate > 0.3) {
118
- warnings.push(`High error rate: ${(qualityAnalysis.errorRate * 100).toFixed(1)}%`);
119
- }
120
- // 4. Generate recommendations
121
- const recommendations = await this.generateRecommendations(compilationResult, testResult, qualityAnalysis);
122
- const success = compilationResult.success && testResult.testsPassed;
123
- // Complete validation
124
- const validationResult = await agentValidationHelper.completeAgentOperation(validationContext, {
125
- success,
126
- testsPassed: testResult.testsPassed,
127
- compilationSuccess: compilationResult.success,
128
- testResults: testResult.testResults,
129
- compilationErrors: compilationResult.errors,
130
- recommendations,
131
- qualityScore,
132
- }, {
133
- outcome: success ? 'success' : 'failure',
134
- validationChecks,
135
- errors: errors.length > 0 ? errors : undefined,
136
- warnings: warnings.length > 0 ? warnings : undefined,
137
- metrics: {
138
- filesAnalyzed: filesModified.length,
139
- },
140
- additionalContext: {
141
- query: plan.goal,
142
- codebaseId: codebaseInfo?.codebaseId,
143
- qualityScore,
144
- testResults: testResult.testResults,
145
- },
146
- }).catch(error => {
147
- // Non-blocking
148
- console.warn('[ValidationAgent] Validation recording failed (non-critical):', error);
149
- return null;
150
- });
151
- return {
152
- success,
153
- testsPassed: testResult.testsPassed,
154
- compilationSuccess: compilationResult.success,
155
- testResults: testResult.testResults,
156
- compilationErrors: compilationResult.errors,
157
- recommendations,
158
- qualityScore,
159
- ...(validationResult ? {
160
- validationSummary: validationResult.summary,
161
- feedbackId: validationResult.feedbackId || undefined,
162
- runId: validationResult.runId || undefined,
163
- } : {}),
164
- };
165
- }
166
- catch (error) {
167
- // Record failure
168
- await agentValidationHelper.completeAgentOperation(validationContext, null, {
169
- outcome: 'failure',
170
- errors: [error instanceof Error ? error.message : String(error)],
171
- additionalContext: {
172
- query: plan.goal,
173
- codebaseId: codebaseInfo?.codebaseId,
174
- },
175
- }).catch(() => {
176
- // Non-blocking
177
- });
178
- throw error;
179
- }
180
- }
181
- /**
182
- * Check compilation for modified files
183
- */
184
- async checkCompilation(filesModified) {
185
- if (!this.verificationService || filesModified.length === 0) {
186
- return { success: true, errors: [] };
187
- }
188
- const errors = [];
189
- for (const filepath of filesModified) {
190
- try {
191
- // Use verification service verify method (includes compilation check)
192
- const result = await this.verificationService.verify(filepath);
193
- if (!result.compiled || !result.success) {
194
- errors.push(...(result.errors || []));
195
- }
196
- }
197
- catch (error) {
198
- errors.push(error instanceof Error ? error.message : String(error));
199
- }
200
- }
201
- return {
202
- success: errors.length === 0,
203
- errors,
204
- };
205
- }
206
- /**
207
- * Run test suite
208
- */
209
- async runTests() {
210
- try {
211
- // Detect test framework
212
- const packageJsonPath = 'package.json';
213
- if (!existsSync(packageJsonPath)) {
214
- return { testsPassed: true }; // No tests to run
215
- }
216
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
217
- const testScript = packageJson.scripts?.test;
218
- if (!testScript) {
219
- return { testsPassed: true }; // No test script
220
- }
221
- // Run tests (with timeout)
222
- const { stdout, stderr } = await Promise.race([
223
- execAsync(testScript, { timeout: 60000 }),
224
- new Promise((_, reject) => {
225
- setTimeout(() => reject(new Error('Test timeout')), 60000);
226
- }),
227
- ]);
228
- // Parse test results (simplified - would need framework-specific parsing)
229
- const passed = (stdout.match(/✓|passed|PASS/g) || []).length;
230
- const failed = (stdout.match(/✗|failed|FAIL/g) || []).length;
231
- const total = passed + failed;
232
- return {
233
- testsPassed: failed === 0,
234
- testResults: {
235
- passed,
236
- failed,
237
- total,
238
- failures: [], // Would parse from output
239
- },
240
- };
241
- }
242
- catch (error) {
243
- // Test execution failed
244
- return {
245
- testsPassed: false,
246
- testResults: {
247
- passed: 0,
248
- failed: 0,
249
- total: 0,
250
- failures: [
251
- {
252
- test: 'Test suite execution',
253
- error: error instanceof Error ? error.message : String(error),
254
- },
255
- ],
256
- },
257
- };
258
- }
259
- }
260
- /**
261
- * Analyze code quality
262
- */
263
- async analyzeQuality(plan, executionResults) {
264
- const successful = executionResults.filter(r => r.success).length;
265
- const total = executionResults.length;
266
- const successRate = total > 0 ? successful / total : 1.0;
267
- const durations = executionResults.map(r => r.duration);
268
- const averageDuration = durations.length > 0
269
- ? durations.reduce((a, b) => a + b, 0) / durations.length
270
- : 0;
271
- const errors = executionResults.filter(r => !r.success).length;
272
- const errorRate = total > 0 ? errors / total : 0;
273
- return {
274
- successRate,
275
- averageDuration,
276
- errorRate,
277
- };
278
- }
279
- /**
280
- * Generate recommendations based on validation results
281
- */
282
- async generateRecommendations(compilationResult, testResult, qualityAnalysis) {
283
- const recommendations = [];
284
- if (!compilationResult.success) {
285
- recommendations.push(`Fix compilation errors: ${compilationResult.errors.slice(0, 3).join(', ')}`);
286
- }
287
- if (!testResult.testsPassed) {
288
- recommendations.push('Review and fix failing tests');
289
- }
290
- if (qualityAnalysis.errorRate > 0.3) {
291
- recommendations.push('High error rate detected - review execution strategy');
292
- }
293
- if (qualityAnalysis.averageDuration > 10000) {
294
- recommendations.push('Execution duration is high - consider optimization');
295
- }
296
- if (recommendations.length === 0) {
297
- recommendations.push('All validations passed - code quality is good');
298
- }
299
- return recommendations;
300
- }
301
- /**
302
- * Calculate overall quality score
303
- */
304
- calculateQualityScore(compilationResult, testResult, qualityAnalysis) {
305
- let score = 100;
306
- if (!compilationResult.success) {
307
- score -= 30;
308
- }
309
- if (!testResult.testsPassed) {
310
- score -= 30;
311
- }
312
- score -= qualityAnalysis.errorRate * 20;
313
- score = Math.max(0, Math.min(100, score));
314
- return Math.round(score);
315
- }
316
- }
317
- //# sourceMappingURL=validation-agent.js.map
@@ -1,242 +0,0 @@
1
- /**
2
- * Application: Plan-and-Act Architecture
3
- * Separates strategic planning from tactical execution
4
- *
5
- * Based on research: Plan-and-Act: Improving Planning of Agents for Long-Horizon Tasks
6
- * - Planner: High-accuracy reasoning (reserved for high-leverage tasks)
7
- * - Executor: High-throughput, cost-efficient (for token-intensive execution)
8
- * - Impact: 75% cost reduction, better accuracy for critical decisions
9
- *
10
- * Research findings:
11
- * - GPT-5 highest accuracy config is 4x slower than GPT-4.1
12
- * - Latency proportional to cost (reasoning tokens are expensive)
13
- * - Strategic allocation maximizes throughput while controlling cost
14
- */
15
- /**
16
- * Planner Module
17
- * Uses high-accuracy reasoning models for strategic planning
18
- * Reserved for high-leverage tasks: strategizing, planning, ambiguity resolution
19
- */
20
- export class PlannerModule {
21
- plannerAIService;
22
- context;
23
- constructor(plannerAIService, // High-accuracy model (GPT-5, DeepSeek R1)
24
- context = {}) {
25
- this.plannerAIService = plannerAIService;
26
- this.context = context;
27
- }
28
- /**
29
- * Generate strategic plan from goal
30
- */
31
- async plan(goal, constraints) {
32
- // Use high-accuracy model for planning
33
- const planPrompt = this.buildPlanningPrompt(goal, constraints);
34
- const response = await this.plannerAIService.chat(planPrompt, [], []);
35
- const plan = this.parsePlan(response);
36
- // Assess complexity and allocate resources
37
- plan.estimatedComplexity = this.assessComplexity(plan);
38
- return plan;
39
- }
40
- /**
41
- * Refine plan based on execution feedback
42
- */
43
- async refinePlan(originalPlan, executionResults) {
44
- // Analyze failures and update plan
45
- const failures = executionResults.filter(r => !r.success);
46
- if (failures.length === 0) {
47
- return originalPlan; // Plan is working
48
- }
49
- // Use planner to adapt strategy
50
- const refinementPrompt = this.buildRefinementPrompt(originalPlan, failures);
51
- const refinedResponse = await this.plannerAIService.chat(refinementPrompt, [], []);
52
- return this.parsePlan(refinedResponse);
53
- }
54
- buildPlanningPrompt(goal, constraints) {
55
- return `You are a strategic planner. Create a detailed plan to achieve this goal:
56
-
57
- Goal: ${goal}
58
-
59
- ${constraints ? `Constraints: ${JSON.stringify(constraints)}` : ''}
60
-
61
- Provide a structured plan with:
62
- 1. High-level strategy
63
- 2. Sequential steps with dependencies
64
- 3. Resource requirements
65
- 4. Risk assessment
66
-
67
- Format as JSON with steps array.`;
68
- }
69
- buildRefinementPrompt(plan, failures) {
70
- return `The following plan encountered failures. Refine the strategy:
71
-
72
- Original Plan: ${JSON.stringify(plan)}
73
- Failures: ${JSON.stringify(failures)}
74
-
75
- Provide an improved plan that addresses these failures.`;
76
- }
77
- parsePlan(response) {
78
- // Parse JSON plan from LLM response
79
- try {
80
- const parsed = JSON.parse(response);
81
- return {
82
- goal: parsed.goal || '',
83
- steps: parsed.steps || [],
84
- context: parsed.context || {},
85
- estimatedComplexity: 'medium',
86
- };
87
- }
88
- catch {
89
- // Fallback: create simple plan
90
- return {
91
- goal: '',
92
- steps: [],
93
- context: {},
94
- estimatedComplexity: 'medium',
95
- };
96
- }
97
- }
98
- assessComplexity(plan) {
99
- const stepCount = plan.steps.length;
100
- const dependencyCount = plan.steps.reduce((sum, step) => sum + (step.dependencies?.length || 0), 0);
101
- if (stepCount > 10 || dependencyCount > 5) {
102
- return 'high';
103
- }
104
- if (stepCount > 5 || dependencyCount > 2) {
105
- return 'medium';
106
- }
107
- return 'low';
108
- }
109
- }
110
- /**
111
- * Executor Module
112
- * Uses high-throughput, cost-efficient models for execution
113
- * Handles token-intensive, low-leverage tasks
114
- */
115
- export class ExecutorModule {
116
- executorAIService;
117
- toolExecutor;
118
- constructor(executorAIService, // High-throughput model (GPT-4, optimized models)
119
- toolExecutor) {
120
- this.executorAIService = executorAIService;
121
- this.toolExecutor = toolExecutor;
122
- }
123
- /**
124
- * Execute a single plan step
125
- */
126
- async executeStep(step, context) {
127
- const startTime = Date.now();
128
- try {
129
- // For high-accuracy steps, delegate back to planner
130
- if (step.requiresHighAccuracy) {
131
- // This shouldn't happen - executor only gets low-leverage steps
132
- throw new Error('High-accuracy steps should use Planner, not Executor');
133
- }
134
- // Execute action using tools
135
- const output = await this.toolExecutor.execute(step.action, step.parameters, context);
136
- const latency = Date.now() - startTime;
137
- return {
138
- stepId: step.id,
139
- success: true,
140
- output,
141
- cost: step.estimatedCost,
142
- latency,
143
- };
144
- }
145
- catch (error) {
146
- const latency = Date.now() - startTime;
147
- return {
148
- stepId: step.id,
149
- success: false,
150
- output: null,
151
- error: error instanceof Error ? error.message : String(error),
152
- cost: step.estimatedCost,
153
- latency,
154
- };
155
- }
156
- }
157
- /**
158
- * Execute multiple steps in parallel (where possible)
159
- */
160
- async executeSteps(steps, context) {
161
- // Identify parallelizable steps (no dependencies)
162
- const independentSteps = steps.filter(step => !step.dependencies || step.dependencies.length === 0);
163
- // Execute independent steps in parallel
164
- const parallelResults = await Promise.all(independentSteps.map(step => this.executeStep(step, context)));
165
- // Execute dependent steps sequentially
166
- const dependentSteps = steps.filter(step => step.dependencies && step.dependencies.length > 0);
167
- const sequentialResults = [];
168
- for (const step of dependentSteps) {
169
- // Wait for dependencies
170
- const dependencyResults = sequentialResults.filter(r => step.dependencies.includes(r.stepId));
171
- // Check if all dependencies succeeded
172
- const allDependenciesSucceeded = dependencyResults.every(r => r.success);
173
- if (!allDependenciesSucceeded) {
174
- sequentialResults.push({
175
- stepId: step.id,
176
- success: false,
177
- output: null,
178
- error: 'Dependency failed',
179
- cost: step.estimatedCost,
180
- latency: 0,
181
- });
182
- continue;
183
- }
184
- // Execute step
185
- const result = await this.executeStep(step, context);
186
- sequentialResults.push(result);
187
- }
188
- return [...parallelResults, ...sequentialResults];
189
- }
190
- }
191
- /**
192
- * Plan-and-Act Orchestrator
193
- * Coordinates Planner and Executor modules
194
- */
195
- export class PlanAndActOrchestrator {
196
- planner;
197
- executor;
198
- maxRefinements;
199
- constructor(planner, executor, maxRefinements = 3) {
200
- this.planner = planner;
201
- this.executor = executor;
202
- this.maxRefinements = maxRefinements;
203
- }
204
- /**
205
- * Execute goal using Plan-and-Act architecture
206
- */
207
- async execute(goal, constraints) {
208
- // 1. Plan: Use high-accuracy model for strategy
209
- let plan = await this.planner.plan(goal, constraints);
210
- // 2. Separate steps by leverage
211
- const highLeverageSteps = plan.steps.filter(s => s.requiresHighAccuracy);
212
- const lowLeverageSteps = plan.steps.filter(s => !s.requiresHighAccuracy);
213
- // 3. Execute high-leverage steps with planner (if any)
214
- // Note: In practice, high-leverage steps might need planner assistance
215
- // For now, we assume all steps can be executed by executor
216
- // 4. Execute low-leverage steps with executor (parallelized)
217
- let executionResults = [];
218
- let refinementCount = 0;
219
- while (refinementCount < this.maxRefinements) {
220
- // Execute all steps
221
- const results = await this.executor.executeSteps(plan.steps, plan.context);
222
- executionResults = results;
223
- // Check if all succeeded
224
- const allSucceeded = results.every(r => r.success);
225
- if (allSucceeded) {
226
- break;
227
- }
228
- // Refine plan based on failures
229
- plan = await this.planner.refinePlan(plan, results);
230
- refinementCount++;
231
- }
232
- // 5. Return final results
233
- return {
234
- plan,
235
- results: executionResults,
236
- success: executionResults.every(r => r.success),
237
- totalCost: executionResults.reduce((sum, r) => sum + r.cost, 0),
238
- totalLatency: executionResults.reduce((sum, r) => sum + r.latency, 0),
239
- };
240
- }
241
- }
242
- //# sourceMappingURL=plan-and-act.js.map
@@ -1,12 +0,0 @@
1
- /**
2
- * Application Layer - Public Exports
3
- */
4
- export * from './use-cases/ask-question-use-case.js';
5
- export * from './use-cases/index-codebase-use-case.js';
6
- export * from './use-cases/react-orchestration-use-case.js';
7
- export * from './use-cases/reflexion-use-case.js';
8
- export * from './use-cases/edit-file-use-case.js';
9
- export * from './services/dependency-container.js';
10
- export * from './services/agent-factory.js';
11
- export * from './services/tool-executor-service.js';
12
- //# sourceMappingURL=index.js.map
@@ -1,28 +0,0 @@
1
- /**
2
- * Agent Factory
3
- * Creates and wires up agents with clean architecture
4
- */
5
- import { AgentRegistry } from '../../agents/base.js';
6
- import { ModelDrivenOrchestratorAgent } from '../../agents/orchestrator-model-driven.js';
7
- import { ReActOrchestratorAgent } from '../../agents/react-orchestrator-agent.js';
8
- export function createAgentRegistry(useReAct = true) {
9
- const registry = new AgentRegistry();
10
- // Create orchestrator (ReAct or Model-Driven)
11
- if (useReAct) {
12
- const reactOrchestrator = new ReActOrchestratorAgent();
13
- registry.register(reactOrchestrator);
14
- }
15
- else {
16
- const modelOrchestrator = new ModelDrivenOrchestratorAgent(registry);
17
- registry.register(modelOrchestrator);
18
- }
19
- // TODO: Register other agents as they're created
20
- // registry.register(new EditorAgent());
21
- // registry.register(new SearchAgent());
22
- // etc.
23
- return registry;
24
- }
25
- export function getDefaultOrchestrator() {
26
- return new ReActOrchestratorAgent();
27
- }
28
- //# sourceMappingURL=agent-factory.js.map