codehere 0.2.2 → 0.3.0-rc.10

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 (238) 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 +261 -1224
  5. package/dist/infrastructure/config/product-context.js +7 -6
  6. package/dist/infrastructure/hooks/claude-sdk-hook.js +348 -72
  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/conductor-adapter.js +340 -0
  16. package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
  17. package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
  18. package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
  19. package/dist/infrastructure/orchestration/readiness.js +106 -0
  20. package/dist/infrastructure/orchestration/session-manager.js +278 -0
  21. package/dist/infrastructure/orchestration/session-persistence.js +109 -0
  22. package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
  23. package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
  24. package/dist/infrastructure/protocols/probe-port.js +36 -0
  25. package/dist/infrastructure/protocols/ui-page.js +1827 -0
  26. package/dist/infrastructure/security/file-collection.js +115 -0
  27. package/dist/infrastructure/security/trust-scorer.js +301 -56
  28. package/dist/infrastructure/storage/task-repository.js +8 -7
  29. package/dist/monitoring.js +9 -38
  30. package/dist/presentation/cli/commands/help-command.js +96 -139
  31. package/dist/presentation/cli/commands/hook-command.js +17 -24
  32. package/dist/presentation/cli/commands/report-command.js +59 -72
  33. package/dist/presentation/cli/commands/setup-command.js +4 -4
  34. package/dist/presentation/cli/commands/status-command.js +321 -30
  35. package/dist/presentation/cli/commands/trust-command.js +84 -72
  36. package/dist/presentation/cli/error-display.js +17 -21
  37. package/dist/presentation/cli/repl.js +474 -0
  38. package/dist/ui.js +11 -11
  39. package/package.json +24 -62
  40. package/dist/agents/base.js +0 -101
  41. package/dist/agents/orchestrator-model-driven.js +0 -141
  42. package/dist/agents/react-orchestrator-agent.js +0 -54
  43. package/dist/application/agents/execution-agent.js +0 -508
  44. package/dist/application/agents/multi-agent-orchestrator.js +0 -295
  45. package/dist/application/agents/planning-agent.js +0 -433
  46. package/dist/application/agents/validation-agent.js +0 -317
  47. package/dist/application/architectures/plan-and-act.js +0 -242
  48. package/dist/application/index.js +0 -12
  49. package/dist/application/services/agent-factory.js +0 -28
  50. package/dist/application/services/dependency-container.js +0 -596
  51. package/dist/application/services/git-context-service.js +0 -83
  52. package/dist/application/services/intelligent-router.js +0 -934
  53. package/dist/application/services/tool-executor-service.js +0 -94
  54. package/dist/application/use-cases/ask-question-use-case.js +0 -338
  55. package/dist/application/use-cases/edit-file-use-case.js +0 -830
  56. package/dist/application/use-cases/explain-file-use-case.js +0 -50
  57. package/dist/application/use-cases/index-codebase-use-case.js +0 -113
  58. package/dist/application/use-cases/planning-use-case.js +0 -276
  59. package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
  60. package/dist/application/use-cases/reflexion-use-case.js +0 -30
  61. package/dist/application/workflows/deterministic-workflows.js +0 -189
  62. package/dist/ast-parser.js +0 -331
  63. package/dist/cache.js +0 -180
  64. package/dist/chat.js +0 -251
  65. package/dist/code-analysis.js +0 -327
  66. package/dist/context.js +0 -187
  67. package/dist/docs.js +0 -146
  68. package/dist/domain/entities/code-chunk.js +0 -6
  69. package/dist/domain/entities/decision.js +0 -9
  70. package/dist/domain/entities/edit.js +0 -6
  71. package/dist/domain/entities/knowledge-node.js +0 -9
  72. package/dist/domain/entities/knowledge-preservation.js +0 -10
  73. package/dist/domain/entities/memory.js +0 -6
  74. package/dist/domain/entities/pattern.js +0 -7
  75. package/dist/domain/entities/plan.js +0 -6
  76. package/dist/domain/entities/query.js +0 -6
  77. package/dist/domain/errors/embeddings-not-found-error.js +0 -13
  78. package/dist/domain/index.js +0 -19
  79. package/dist/domain/interfaces/ai-service.interface.js +0 -6
  80. package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
  81. package/dist/domain/interfaces/decision-repository.interface.js +0 -9
  82. package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
  83. package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
  84. package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
  85. package/dist/domain/interfaces/memory-repository.interface.js +0 -6
  86. package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
  87. package/dist/domain/interfaces/verification-service.interface.js +0 -6
  88. package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
  89. package/dist/domain/services/decision-recorder.js +0 -223
  90. package/dist/domain/services/decision-retriever.js +0 -133
  91. package/dist/domain/services/environment-mode-manager.js +0 -22
  92. package/dist/domain/services/graded-memory-activation.js +0 -69
  93. package/dist/domain/services/knowledge-access.js +0 -132
  94. package/dist/domain/services/knowledge-extractor.js +0 -247
  95. package/dist/domain/services/knowledge-graph-builder.js +0 -268
  96. package/dist/domain/services/knowledge-graph-query.js +0 -187
  97. package/dist/domain/services/memory-retriever.js +0 -82
  98. package/dist/domain/services/memory-synthesizer.js +0 -91
  99. package/dist/domain/services/pattern-extractor.js +0 -442
  100. package/dist/domain/services/query-intent-classifier.js +0 -140
  101. package/dist/domain/services/react-loop.js +0 -186
  102. package/dist/domain/services/risk-tier-detector.js +0 -78
  103. package/dist/edit.js +0 -319
  104. package/dist/embed.js +0 -459
  105. package/dist/formatter.js +0 -168
  106. package/dist/git.js +0 -198
  107. package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
  108. package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
  109. package/dist/infrastructure/ai/model-config.js +0 -84
  110. package/dist/infrastructure/ai/provider-ai-service.js +0 -477
  111. package/dist/infrastructure/cache/embedding-cache.js +0 -175
  112. package/dist/infrastructure/cache/query-result-cache.js +0 -66
  113. package/dist/infrastructure/cache/response-cache.js +0 -48
  114. package/dist/infrastructure/cache/security-scan-cache.js +0 -47
  115. package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
  116. package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
  117. package/dist/infrastructure/context/context-compressor.js +0 -329
  118. package/dist/infrastructure/context/conversation-context.js +0 -128
  119. package/dist/infrastructure/context/session-manager.js +0 -94
  120. package/dist/infrastructure/cost/cost-tracker.js +0 -360
  121. package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
  122. package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
  123. package/dist/infrastructure/governance/policy-as-code.js +0 -258
  124. package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
  125. package/dist/infrastructure/index.js +0 -7
  126. package/dist/infrastructure/observability/prompt-versioner.js +0 -145
  127. package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
  128. package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
  129. package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
  130. package/dist/infrastructure/protocols/mcp-server.js +0 -333
  131. package/dist/infrastructure/protocols/streaming-handler.js +0 -103
  132. package/dist/infrastructure/providers/cohere-provider.js +0 -444
  133. package/dist/infrastructure/providers/fake-provider.js +0 -130
  134. package/dist/infrastructure/providers/local-llm-provider.js +0 -330
  135. package/dist/infrastructure/providers/model-config.types.js +0 -9
  136. package/dist/infrastructure/providers/model-provider.interface.js +0 -8
  137. package/dist/infrastructure/providers/openai-provider.js +0 -413
  138. package/dist/infrastructure/providers/openrouter-provider.js +0 -399
  139. package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
  140. package/dist/infrastructure/providers/provider-config-loader.js +0 -120
  141. package/dist/infrastructure/providers/provider-registry.js +0 -88
  142. package/dist/infrastructure/safety/pattern-detector.js +0 -133
  143. package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
  144. package/dist/infrastructure/security/docker-sandbox.js +0 -178
  145. package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
  146. package/dist/infrastructure/security/license-scanner.js +0 -167
  147. package/dist/infrastructure/security/provider-bias-detector.js +0 -164
  148. package/dist/infrastructure/security/sandbox-executor.js +0 -64
  149. package/dist/infrastructure/serialization/toon-serializer.js +0 -119
  150. package/dist/infrastructure/storage/memory-stream-service.js +0 -204
  151. package/dist/infrastructure/storage/plan-repository.js +0 -96
  152. package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
  153. package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
  154. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
  155. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
  156. package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
  157. package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
  158. package/dist/infrastructure/storage/task-helpers.js +0 -197
  159. package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
  160. package/dist/infrastructure/ux/appropriate-friction.js +0 -213
  161. package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
  162. package/dist/infrastructure/ux/capability-boundaries.js +0 -42
  163. package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
  164. package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
  165. package/dist/infrastructure/ux/expectation-management.js +0 -327
  166. package/dist/infrastructure/ux/feature-discovery.js +0 -14
  167. package/dist/infrastructure/ux/feedback-prompt.js +0 -45
  168. package/dist/infrastructure/ux/hitl-validation.js +0 -297
  169. package/dist/infrastructure/ux/progress-indicator.js +0 -116
  170. package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
  171. package/dist/infrastructure/ux/review-checkpoint.js +0 -72
  172. package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
  173. package/dist/infrastructure/ux/stream-markdown.js +0 -151
  174. package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
  175. package/dist/infrastructure/ux/team-standards.js +0 -196
  176. package/dist/infrastructure/ux/transparency.js +0 -71
  177. package/dist/infrastructure/validation/agent-feedback.js +0 -55
  178. package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
  179. package/dist/infrastructure/validation/review-handler.js +0 -40
  180. package/dist/infrastructure/validation/summary-aggregator.js +0 -70
  181. package/dist/infrastructure/validation/summary-extractor.js +0 -45
  182. package/dist/infrastructure/validation/trace-summary.js +0 -52
  183. package/dist/infrastructure/verification/verification-service.js +0 -47
  184. package/dist/infrastructure/xai/attention-visualizer.js +0 -172
  185. package/dist/infrastructure/xai/cot-visualizer.js +0 -283
  186. package/dist/infrastructure/xai/decision-tree-log.js +0 -212
  187. package/dist/infrastructure/xai/interactive-xai.js +0 -260
  188. package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
  189. package/dist/intelligent-retrieval.js +0 -272
  190. package/dist/intent/classifier.js +0 -2
  191. package/dist/intent/context.js +0 -2
  192. package/dist/iterative-refinement.js +0 -189
  193. package/dist/learning.js +0 -232
  194. package/dist/log.js +0 -31
  195. package/dist/migrate.js +0 -133
  196. package/dist/parallel-processor.js +0 -534
  197. package/dist/planner.js +0 -198
  198. package/dist/policy.js +0 -26
  199. package/dist/presentation/cli/commands/ask-command.js +0 -314
  200. package/dist/presentation/cli/commands/cost-command.js +0 -191
  201. package/dist/presentation/cli/commands/decision-command.js +0 -207
  202. package/dist/presentation/cli/commands/docs-command.js +0 -25
  203. package/dist/presentation/cli/commands/fix-command.js +0 -53
  204. package/dist/presentation/cli/commands/knowledge-command.js +0 -129
  205. package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
  206. package/dist/presentation/cli/commands/models-command.js +0 -194
  207. package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
  208. package/dist/presentation/cli/commands/plan-command.js +0 -246
  209. package/dist/presentation/cli/commands/product-command.js +0 -199
  210. package/dist/presentation/cli/commands/react-command.js +0 -181
  211. package/dist/presentation/cli/commands/review-command.js +0 -154
  212. package/dist/presentation/cli/commands/run-command.js +0 -188
  213. package/dist/presentation/cli/commands/smart-command.js +0 -395
  214. package/dist/presentation/cli/commands/suggest-command.js +0 -138
  215. package/dist/presentation/cli/commands/trace-command.js +0 -129
  216. package/dist/presentation/cli/commands/undo-command.js +0 -150
  217. package/dist/query-optimizer.js +0 -205
  218. package/dist/refactor.js +0 -116
  219. package/dist/review.js +0 -206
  220. package/dist/search.js +0 -163
  221. package/dist/session.js +0 -704
  222. package/dist/task-verification.js +0 -336
  223. package/dist/testgen.js +0 -166
  224. package/dist/token-optimizer.js +0 -277
  225. package/dist/tools/bash.js +0 -213
  226. package/dist/tools/edit.js +0 -235
  227. package/dist/tools/executor.js +0 -153
  228. package/dist/tools/git-tool.js +0 -292
  229. package/dist/tools/parser.js +0 -158
  230. package/dist/tools/registry.js +0 -302
  231. package/dist/tools/search.js +0 -100
  232. package/dist/types.js +0 -2
  233. package/dist/utils/check-api-status.js +0 -100
  234. package/dist/utils/diff-parser.js +0 -162
  235. package/dist/verification/backup.js +0 -259
  236. package/dist/verification/compiler.js +0 -264
  237. package/dist/verification/index.js +0 -273
  238. 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