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,246 +0,0 @@
1
- /**
2
- * CLI Command: Plan
3
- * Memory-based hierarchical planning
4
- */
5
- import { container } from '../../../application/services/dependency-container.js';
6
- import { colors, sectionHeader, success, warning, newline, createBanner, createSpinner, isMinimalStyle, } from '../../../ui.js';
7
- import { findCodebaseRoot } from '../../../domain/services/codebase-detector.js';
8
- import { executionTracer } from '../../../infrastructure/observability/execution-tracer.js';
9
- import { displayError } from '../error-display.js';
10
- import { summaryExtractor } from '../../../infrastructure/validation/summary-extractor.js';
11
- import { reviewHandler } from '../../../infrastructure/validation/review-handler.js';
12
- import { createPlanTask } from '../../../infrastructure/storage/task-helpers.js';
13
- export async function executePlanCommand(goal, options = {}) {
14
- // TODO: Create task after plan generation
15
- // Task mode: PLAN
16
- // Status: CREATED → PLANNED
17
- // Risk tier: Detect from plan (use risk tier detector)
18
- // Store plan in task.plan
19
- // Set task.clarificationUsed = true if clarification flow was used
20
- // See: .internal/ARCHITECTURE.md (internal docs)
21
- // Detect codebase context (for codebase-aware planning)
22
- const codebaseInfo = findCodebaseRoot(process.cwd());
23
- const userId = codebaseInfo?.rootPath || process.cwd() || 'cli-user';
24
- // Progressive Disclosure: Check feature access
25
- const progressiveDisclosure = container.progressiveDisclosure;
26
- if (progressiveDisclosure) {
27
- const { checkFeatureAccess, displayFeatureAvailability } = await import('../../../infrastructure/ux/staged-feature-intro.js');
28
- const profile = progressiveDisclosure.getUserProfile(userId);
29
- const access = checkFeatureAccess(progressiveDisclosure, userId, 'planning');
30
- if (!access.shouldContinue) {
31
- return;
32
- }
33
- displayFeatureAvailability('Hierarchical Planning', 'advanced', profile.level);
34
- progressiveDisclosure.recordFeatureUsage(userId, 'planning');
35
- }
36
- // Header is handled by index.ts, only show banner in verbose mode
37
- if (!isMinimalStyle()) {
38
- console.log(createBanner('Memory-Based Planning', 'Hierarchical plan synthesis from memories'));
39
- newline();
40
- console.log(colors.bold('Goal:'));
41
- console.log(colors.cyan(' ' + goal));
42
- newline();
43
- }
44
- // Start execution tracing
45
- const runId = executionTracer.startRun('plan', {
46
- query: goal,
47
- codebaseId: codebaseInfo?.rootPath || process.cwd(),
48
- });
49
- if (codebaseInfo) {
50
- console.log(colors.dim(`Codebase: ${codebaseInfo.rootPath} (${codebaseInfo.type})`));
51
- newline();
52
- }
53
- // Set up streaming handler for plan generation progress
54
- const streamHandler = {
55
- onProgress: (stage, message) => {
56
- // Clear spinner and show progress
57
- process.stdout.write('\r' + ' '.repeat(50) + '\r'); // Clear line
58
- process.stdout.write(colors.cyan(` ${stage}: ${message}\n`));
59
- },
60
- onToken: (token) => {
61
- // Stream plan generation tokens
62
- process.stdout.write(token);
63
- },
64
- onError: (error) => {
65
- console.error(colors.red(`\nStreaming error: ${error.message}`));
66
- },
67
- };
68
- // Enhanced progress indicator with stages
69
- const planningSpinner = createSpinner('Synthesizing memories into plan...');
70
- planningSpinner.start();
71
- // Update spinner text based on streaming progress
72
- const originalOnProgress = streamHandler.onProgress;
73
- streamHandler.onProgress = (stage, message) => {
74
- planningSpinner.text = colors.dim(`${stage}: ${message}`);
75
- originalOnProgress(stage, message);
76
- };
77
- try {
78
- const useCase = container.planningUseCase;
79
- const result = await useCase.execute({
80
- goal,
81
- planningMode: 'hybrid', // Plan-then-Execute with iterative refinement
82
- context: {
83
- currentDirectory: process.cwd(),
84
- },
85
- streamHandler, // Pass streaming handler for real-time progress
86
- });
87
- planningSpinner.stop();
88
- // Display plan
89
- sectionHeader('Generated Plan');
90
- console.log(colors.bold(`Goal: ${result.plan.goal}`));
91
- console.log(colors.dim(`Complexity: ${result.plan.metadata?.complexity || 'medium'}`));
92
- if (result.plan.metadata?.estimatedDuration) {
93
- console.log(colors.dim(`Estimated Duration: ${result.plan.metadata.estimatedDuration} minutes`));
94
- }
95
- newline();
96
- console.log(colors.bold('Sub-Plans:'));
97
- result.plan.subPlans.forEach((subPlan, i) => {
98
- const statusIcon = {
99
- pending: '○',
100
- in_progress: '⟳',
101
- completed: '✓',
102
- failed: '✗',
103
- }[subPlan.status];
104
- console.log(` ${statusIcon} [${subPlan.type}] ${subPlan.description}`);
105
- if (subPlan.dependencies.length > 0) {
106
- console.log(colors.dim(` Depends on: ${subPlan.dependencies.join(', ')}`));
107
- }
108
- console.log(colors.dim(` Estimated steps: ${subPlan.estimatedSteps}`));
109
- });
110
- if (result.plan.dependencies.length > 0) {
111
- newline();
112
- console.log(colors.bold('Dependencies:'));
113
- result.plan.dependencies.forEach(dep => {
114
- console.log(colors.dim(` ${dep.from} → ${dep.to} (${dep.type})`));
115
- });
116
- }
117
- if (result.reflections.length > 0) {
118
- newline();
119
- sectionHeader('Insights from Past Experiences');
120
- const { formatContent } = await import('../../../infrastructure/ux/comprehensive-formatter.js');
121
- result.reflections.slice(0, 5).forEach((reflection, i) => {
122
- console.log('');
123
- console.log(colors.bold.cyan(`${i + 1}. ${reflection.question}`));
124
- const formattedInsight = formatContent(reflection.insight, { indent: 4, maxWidth: 72 });
125
- console.log(formattedInsight);
126
- });
127
- }
128
- newline();
129
- console.log(colors.dim(`Memories used: ${result.memoriesUsed} | Synthesis time: ${result.synthesisTime}ms`));
130
- // Show plan ID for later execution
131
- if (result.plan.id) {
132
- newline();
133
- console.log(colors.dim(`Plan ID: ${result.plan.id}`));
134
- console.log(colors.dim(`To execute this plan later: codehere orchestrate "${result.plan.goal}" --plan-id ${result.plan.id}`));
135
- }
136
- // Create task (non-breaking, silent failure)
137
- try {
138
- await createPlanTask({
139
- goal,
140
- plan: result.plan,
141
- codebaseInfo,
142
- runId,
143
- });
144
- }
145
- catch {
146
- // Silent failure - don't break user workflow
147
- // Task creation is optional in Phase 1
148
- }
149
- if (options.execute) {
150
- newline();
151
- sectionHeader('Executing Plan');
152
- try {
153
- const orchestrator = container.multiAgentOrchestrator;
154
- const executionResult = await orchestrator.orchestrate({
155
- goal: result.plan.goal,
156
- mode: 'execute-only',
157
- context: {
158
- plan: result.plan,
159
- },
160
- });
161
- // Get review decision - single source of truth for userAction
162
- // All CLI commands use this same pattern: getReviewDecision() → use decision.userAction
163
- const reviewRequested = Boolean(options.review);
164
- const summarySource = summaryExtractor.extractFromOrchestration(executionResult);
165
- const decision = summarySource
166
- ? await reviewHandler.getReviewDecision(summarySource.summary, reviewRequested)
167
- : { approved: true, proceed: true, userAction: 'not_required' };
168
- if (!decision.approved) {
169
- console.log(warning('Operation cancelled by user.'));
170
- newline();
171
- // Record feedback for rejection
172
- if (executionResult.compositeSummary) {
173
- const { agentFeedbackManager } = await import('../../../infrastructure/validation/agent-feedback.js');
174
- agentFeedbackManager.recordFeedback({
175
- runId: executionResult.unifiedRunId || runId,
176
- agentName: 'multi-agent-orchestrator',
177
- operation: 'orchestrate',
178
- query: goal,
179
- outcome: 'cancelled',
180
- userAction: decision.userAction,
181
- filesChanged: executionResult.compositeSummary.filesChanged,
182
- filesCreated: executionResult.compositeSummary.filesCreated,
183
- filesDeleted: executionResult.compositeSummary.filesDeleted,
184
- errors: executionResult.compositeSummary.errors,
185
- warnings: executionResult.compositeSummary.warnings,
186
- validationChecks: executionResult.compositeSummary.validationChecks,
187
- metrics: executionResult.compositeSummary.metrics,
188
- });
189
- }
190
- return;
191
- }
192
- // Record feedback with userAction from review decision
193
- if (executionResult.compositeSummary) {
194
- const { agentFeedbackManager } = await import('../../../infrastructure/validation/agent-feedback.js');
195
- agentFeedbackManager.recordFeedback({
196
- runId: executionResult.unifiedRunId || runId,
197
- agentName: 'multi-agent-orchestrator',
198
- operation: 'orchestrate',
199
- query: goal,
200
- outcome: executionResult.success ? 'success' : 'failure',
201
- userAction: decision.userAction,
202
- filesChanged: executionResult.compositeSummary.filesChanged,
203
- filesCreated: executionResult.compositeSummary.filesCreated,
204
- filesDeleted: executionResult.compositeSummary.filesDeleted,
205
- errors: executionResult.compositeSummary.errors,
206
- warnings: executionResult.compositeSummary.warnings,
207
- validationChecks: executionResult.compositeSummary.validationChecks,
208
- metrics: executionResult.compositeSummary.metrics,
209
- });
210
- }
211
- newline();
212
- if (executionResult.success) {
213
- console.log(success('Plan done.'));
214
- }
215
- else {
216
- displayError(new Error('Plan execution completed with errors'), {
217
- operation: 'plan-execute',
218
- query: goal,
219
- showSuggestions: true,
220
- });
221
- }
222
- }
223
- catch (err) {
224
- displayError(err, {
225
- operation: 'plan-execute',
226
- query: goal,
227
- showSuggestions: true,
228
- });
229
- }
230
- }
231
- }
232
- catch (err) {
233
- planningSpinner.stop();
234
- const { displayError } = await import('../error-display.js');
235
- displayError(err, {
236
- operation: 'plan',
237
- query: goal,
238
- showSuggestions: true,
239
- });
240
- throw err;
241
- }
242
- finally {
243
- executionTracer.endRun();
244
- }
245
- }
246
- //# sourceMappingURL=plan-command.js.map
@@ -1,199 +0,0 @@
1
- /**
2
- * CLI Command: product
3
- *
4
- * Initializes and manages the "product brain" — a lightweight project context
5
- * that makes trust scores and recommendations context-aware.
6
- *
7
- * Usage:
8
- * codehere product init # interactive setup (2 minutes)
9
- * codehere product show # display current config
10
- * codehere product set --risk high # update a single field
11
- *
12
- * Stored in: .codehere/product.json (per-project)
13
- * Read by: trust, report, intelligent router
14
- */
15
- import * as readline from 'readline';
16
- import { colors, success, error, warning, info, newline, sectionHeader } from '../../../ui.js';
17
- import { loadProductContext, saveProductContext, } from '../../../infrastructure/config/product-context.js';
18
- // ── helpers ───────────────────────────────────────────────────────────────────
19
- function ask(rl, question) {
20
- return new Promise(resolve => rl.question(question, resolve));
21
- }
22
- function riskColor(level) {
23
- return level === 'critical' ? colors.red(level)
24
- : level === 'high' ? colors.yellow(level)
25
- : level === 'medium' ? colors.cyan(level)
26
- : colors.green(level);
27
- }
28
- // ── command ───────────────────────────────────────────────────────────────────
29
- export async function executeProductCommand(subcommand, options = {}) {
30
- const sub = subcommand ?? 'show';
31
- const cwd = process.cwd();
32
- switch (sub) {
33
- case 'init': {
34
- const existing = loadProductContext(cwd);
35
- if (existing && !options.force) {
36
- console.log(warning('Product brain already configured for this project.'));
37
- console.log(colors.dim(' Run `codehere product show` to see it.'));
38
- console.log(colors.dim(' Run `codehere product init --force` to redo setup.'));
39
- newline();
40
- return;
41
- }
42
- sectionHeader('Product Brain Setup');
43
- newline();
44
- console.log(colors.dim(' 2 minutes. Helps codehere give context-aware recommendations.'));
45
- newline();
46
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
47
- try {
48
- const nameDefault = existing?.name ?? 'my-project';
49
- const name = ((await ask(rl, ` Project name [${nameDefault}]: `)).trim()) || nameDefault;
50
- const descDefault = existing?.description ?? '';
51
- const descPrompt = descDefault ? ` What does it do? [${descDefault}]: ` : ' What does it do? (one line): ';
52
- const description = ((await ask(rl, descPrompt)).trim()) || descDefault || 'A software project';
53
- const prodDefault = existing?.productionApp ? 'y' : 'n';
54
- const prodAnswer = ((await ask(rl, ` Production app? [${prodDefault}] (y/n): `)).trim().toLowerCase()) || prodDefault;
55
- const productionApp = prodAnswer === 'y' || prodAnswer === 'yes';
56
- console.log(` Risk level options: ${colors.green('low')} / ${colors.cyan('medium')} / ${colors.yellow('high')} / ${colors.red('critical')}`);
57
- const riskDefault = existing?.riskLevel ?? (productionApp ? 'medium' : 'low');
58
- const riskAnswer = ((await ask(rl, ` How sensitive are security issues here? [${riskDefault}]: `)).trim().toLowerCase()) || riskDefault;
59
- const riskLevel = riskAnswer === 'critical' ? 'critical'
60
- : riskAnswer === 'high' ? 'high'
61
- : riskAnswer === 'low' ? 'low'
62
- : 'medium';
63
- const existingSensitive = existing?.sensitiveAreas?.join(',') ?? '';
64
- const sensitivePrompt = existingSensitive
65
- ? ` Sensitive areas [${existingSensitive}]: `
66
- : ' Sensitive areas (e.g. auth,billing,api-keys — or leave blank): ';
67
- const sensitiveParts = ((await ask(rl, sensitivePrompt)).trim()) || existingSensitive;
68
- const sensitiveAreas = sensitiveParts
69
- ? sensitiveParts.split(',').map(s => s.trim()).filter(Boolean)
70
- : [];
71
- const notesDefault = existing?.notes ?? '';
72
- const notesPrompt = notesDefault ? ` Anything else? [${notesDefault}]: ` : ' Anything else to know? (optional): ';
73
- const rawNotes = (await ask(rl, notesPrompt)).trim();
74
- const notes = rawNotes || notesDefault || undefined;
75
- rl.close();
76
- const now = new Date().toISOString();
77
- const ctx = {
78
- name,
79
- description,
80
- riskLevel,
81
- productionApp,
82
- sensitiveAreas,
83
- notes: notes ?? undefined,
84
- createdAt: existing?.createdAt ?? now,
85
- updatedAt: now,
86
- };
87
- saveProductContext(ctx, cwd);
88
- newline();
89
- console.log(success('Product brain saved.'));
90
- newline();
91
- console.log(` ${colors.bold(name)} ${colors.dim('·')} ${description}`);
92
- console.log(` Risk: ${riskColor(riskLevel)} · Production: ${productionApp ? colors.yellow('yes') : 'no'}`);
93
- if (sensitiveAreas.length > 0) {
94
- console.log(` Watching: ${sensitiveAreas.map(s => colors.cyan(s)).join(', ')}`);
95
- }
96
- newline();
97
- console.log(colors.dim(' trust and report will now include project context.'));
98
- newline();
99
- }
100
- catch {
101
- rl.close();
102
- newline();
103
- console.log(colors.dim('Cancelled.'));
104
- }
105
- break;
106
- }
107
- case 'show': {
108
- const ctx = loadProductContext(cwd);
109
- if (!ctx) {
110
- console.log(info('No product brain configured.'));
111
- console.log(colors.dim(' Run `codehere product init` to set it up.'));
112
- newline();
113
- return;
114
- }
115
- sectionHeader('Product Brain');
116
- newline();
117
- console.log(` ${colors.bold(ctx.name)} ${colors.dim('·')} ${ctx.description}`);
118
- newline();
119
- console.log(` Risk level: ${riskColor(ctx.riskLevel)}`);
120
- console.log(` Production: ${ctx.productionApp ? colors.yellow('yes') : colors.green('no')}`);
121
- if (ctx.sensitiveAreas.length > 0) {
122
- console.log(` Sensitive: ${ctx.sensitiveAreas.map(s => colors.cyan(s)).join(', ')}`);
123
- }
124
- if (ctx.notes) {
125
- console.log(` Notes: ${colors.dim(ctx.notes)}`);
126
- }
127
- newline();
128
- console.log(colors.dim(` Updated: ${new Date(ctx.updatedAt).toLocaleDateString()}`));
129
- newline();
130
- break;
131
- }
132
- case 'set': {
133
- const ctx = loadProductContext(cwd);
134
- if (!ctx) {
135
- console.log(warning('No product brain yet. Run `codehere product init` first.'));
136
- return;
137
- }
138
- let changed = false;
139
- if (options.risk) {
140
- const level = options.risk.toLowerCase();
141
- if (!['low', 'medium', 'high', 'critical'].includes(level)) {
142
- console.error(error(`Invalid risk level: ${options.risk}. Options: low, medium, high, critical`));
143
- process.exit(1);
144
- }
145
- ctx.riskLevel = level;
146
- changed = true;
147
- }
148
- if (options.production !== undefined) {
149
- ctx.productionApp = options.production;
150
- changed = true;
151
- }
152
- if (options.name) {
153
- ctx.name = options.name;
154
- changed = true;
155
- }
156
- if (!changed) {
157
- console.log(info('Nothing to update. Use --risk, --production, or --name.'));
158
- return;
159
- }
160
- ctx.updatedAt = new Date().toISOString();
161
- saveProductContext(ctx, cwd);
162
- console.log(success('Updated.'));
163
- newline();
164
- break;
165
- }
166
- // Legacy: `codehere product spec "goal"` — show brain context + acknowledge goal
167
- case 'spec': {
168
- const ctx = loadProductContext(cwd);
169
- // In legacy usage, options.name is used as the goal argument passed via commander
170
- const goalArg = options.name ?? '';
171
- sectionHeader('Product Requirements');
172
- newline();
173
- if (goalArg) {
174
- console.log(` Goal: ${goalArg}`);
175
- newline();
176
- }
177
- if (ctx) {
178
- console.log(` Project: ${colors.bold(ctx.name)} ${colors.dim('·')} ${ctx.description}`);
179
- console.log(` Risk: ${riskColor(ctx.riskLevel)} · Production: ${ctx.productionApp ? colors.yellow('yes') : 'no'}`);
180
- if (ctx.sensitiveAreas.length > 0) {
181
- console.log(` Sensitive: ${ctx.sensitiveAreas.join(', ')}`);
182
- }
183
- }
184
- else {
185
- console.log(info('No product brain configured. Run `codehere product init` to set context.'));
186
- }
187
- newline();
188
- console.log(colors.dim(' For full PRD generation, use an AI assistant with project context.'));
189
- newline();
190
- break;
191
- }
192
- default: {
193
- console.log(error(`Unknown subcommand: ${sub}`));
194
- console.log(colors.dim('Usage: codehere product init|show|set'));
195
- process.exit(1);
196
- }
197
- }
198
- }
199
- //# sourceMappingURL=product-command.js.map
@@ -1,181 +0,0 @@
1
- /**
2
- * CLI Command: React
3
- * Execute query using ReAct loop
4
- */
5
- import { container } from '../../../application/services/dependency-container.js';
6
- import { colors, sectionHeader, formatNumber, newline, createBanner, } from '../../../ui.js';
7
- import { executionTracer } from '../../../infrastructure/observability/execution-tracer.js';
8
- import { findCodebaseRoot } from '../../../domain/services/codebase-detector.js';
9
- import { displayError } from '../error-display.js';
10
- export async function executeReactCommand(query, options) {
11
- // Start execution tracing
12
- const codebaseInfo = findCodebaseRoot(process.cwd());
13
- const runId = executionTracer.startRun('react', {
14
- query,
15
- codebaseId: codebaseInfo?.rootPath || process.cwd(),
16
- });
17
- // Progressive Disclosure: Check feature access
18
- const userId = codebaseInfo?.rootPath || process.cwd() || 'cli-user';
19
- const progressiveDisclosure = container.progressiveDisclosure;
20
- if (progressiveDisclosure) {
21
- const { checkFeatureAccess, displayFeatureAvailability } = await import('../../../infrastructure/ux/staged-feature-intro.js');
22
- const profile = progressiveDisclosure.getUserProfile(userId);
23
- const access = checkFeatureAccess(progressiveDisclosure, userId, 'react-orchestration');
24
- if (!access.shouldContinue) {
25
- executionTracer.endRun();
26
- return;
27
- }
28
- // Display feature level
29
- displayFeatureAvailability('ReAct Orchestration', 'advanced', profile.level);
30
- // Record usage
31
- progressiveDisclosure.recordFeatureUsage(userId, 'react-orchestration');
32
- }
33
- const useCase = container.reactOrchestrationUseCase;
34
- console.log(createBanner('ReAct Reasoning', 'Iterative reasoning with tools'));
35
- newline();
36
- console.log(colors.bold('Query:'));
37
- console.log(colors.cyan(' ' + query));
38
- newline();
39
- try {
40
- // Enable streaming by default for better UX
41
- const enableStreaming = options?.stream !== false;
42
- const stepOutputs = [];
43
- // Set up streaming handler for real-time feedback
44
- const streamHandler = enableStreaming ? {
45
- onThought: (thought) => {
46
- process.stdout.write(colors.dim(` [THOUGHT] ${thought.substring(0, 80)}...\n`));
47
- stepOutputs.push(`Thought: ${thought}`);
48
- },
49
- onAction: (action) => {
50
- process.stdout.write(colors.cyan(` [ACTION] ${action}\n`));
51
- stepOutputs.push(`Action: ${action}`);
52
- },
53
- onObservation: (observation) => {
54
- process.stdout.write(colors.green(` ✓ ${observation.substring(0, 80)}\n`));
55
- stepOutputs.push(`Observation: ${observation}`);
56
- },
57
- onToken: (token) => {
58
- // Stream tokens for thought/action generation
59
- process.stdout.write(token);
60
- },
61
- onError: (error) => {
62
- console.error(colors.red(`\nStreaming error: ${error.message}`));
63
- },
64
- } : undefined;
65
- const result = await useCase.execute({
66
- query,
67
- maxTurns: 15,
68
- streamHandler,
69
- });
70
- // Display trajectory (enhanced CoT visualization)
71
- if (result.trajectory.steps.length > 0) {
72
- newline();
73
- // Use CoTVisualizer if cotTrajectory is available (enhanced display)
74
- if (result.cotTrajectory && container.cotVisualizer) {
75
- sectionHeader('Chain of Thought Reasoning');
76
- // Enhanced CoT display with reasoning quality indicators
77
- const cotSteps = result.cotTrajectory.steps;
78
- const decisionSteps = cotSteps.filter(s => s.type === 'decision');
79
- const hasLongReasoning = cotSteps.some(s => s.content.length > 200);
80
- // Show summary first
81
- console.log(colors.dim(`Completed ${result.trajectory.steps.length} reasoning steps`));
82
- if (decisionSteps.length > 0) {
83
- console.log(colors.cyan(` ${decisionSteps.length} key decision point(s)`));
84
- }
85
- if (hasLongReasoning) {
86
- console.log(colors.yellow(` ⚠ Some steps contain detailed reasoning (shown in compact view)`));
87
- }
88
- newline();
89
- // Display enhanced CoT trajectory
90
- const formatted = container.cotVisualizer.formatForConsole(result.cotTrajectory, {
91
- showMetadata: true,
92
- compact: hasLongReasoning, // Use compact mode for long reasoning
93
- });
94
- console.log(formatted);
95
- // Highlight key decision points
96
- if (decisionSteps.length > 0) {
97
- newline();
98
- sectionHeader('Key Decision Points');
99
- decisionSteps.forEach((decision, idx) => {
100
- console.log(colors.bold(`\nDecision ${idx + 1} (Step ${decision.stepNumber}):`));
101
- console.log(colors.cyan(` ${decision.content}`));
102
- if (decision.metadata?.options) {
103
- console.log(colors.dim(` Options: ${decision.metadata.options.join(', ')}`));
104
- console.log(colors.green(` Chosen: ${decision.metadata.chosen}`));
105
- }
106
- if (decision.metadata?.reasoning) {
107
- console.log(colors.dim(` Reasoning: ${decision.metadata.reasoning}`));
108
- }
109
- if (decision.metadata?.confidence !== undefined) {
110
- const conf = decision.metadata.confidence;
111
- const confColor = conf >= 0.8 ? colors.green : conf >= 0.6 ? colors.yellow : colors.red;
112
- console.log(confColor(` Confidence: ${(conf * 100).toFixed(0)}%`));
113
- }
114
- });
115
- newline();
116
- }
117
- }
118
- else {
119
- // Fallback to basic display if CoT trajectory not available
120
- if (enableStreaming && stepOutputs.length > 0) {
121
- sectionHeader('Reasoning Steps Summary');
122
- console.log(colors.dim(`Completed ${result.trajectory.steps.length} reasoning steps`));
123
- }
124
- else {
125
- sectionHeader('Reasoning Steps');
126
- result.trajectory.steps.forEach((step, i) => {
127
- console.log(colors.bold(`\nStep ${i + 1}:`));
128
- console.log(colors.dim(` Thought: ${step.thought.content.substring(0, 100)}...`));
129
- console.log(colors.cyan(` Action: ${step.action.type} - ${step.action.name}`));
130
- console.log(step.observation.success
131
- ? colors.green(` Result: ${String(step.observation.result).substring(0, 100)}...`)
132
- : colors.red(` Error: ${step.observation.error || 'Unknown error'}`));
133
- });
134
- }
135
- }
136
- newline();
137
- }
138
- // Display final answer
139
- sectionHeader('Final Answer');
140
- const { formatContent } = await import('../../../infrastructure/ux/comprehensive-formatter.js');
141
- const formattedAnswer = formatContent(result.answer, { indent: 0, maxWidth: 76 });
142
- console.log(formattedAnswer);
143
- newline();
144
- // Display attention map if available (XAI Foundation - Attention Visualization)
145
- if (result.attentionMap && result.attentionMap.spans.length > 0) {
146
- newline();
147
- sectionHeader('Attention Map');
148
- const attentionVisualizer = container.attentionVisualizer;
149
- if (attentionVisualizer) {
150
- const formatted = attentionVisualizer.formatForConsole(result.attentionMap, { maxSpans: 5 });
151
- console.log(formatted);
152
- }
153
- }
154
- // Display uncertainty if available (XAI Foundation - Uncertainty Quantification)
155
- if (result.uncertainty && result.uncertainty.isHallucinationRisk) {
156
- newline();
157
- sectionHeader('Uncertainty Assessment');
158
- console.log(colors.yellow(`⚠️ High epistemic uncertainty detected (${(result.uncertainty.epistemic.value * 100).toFixed(1)}%)`));
159
- console.log(colors.dim(' Possible hallucination risk - please verify the response carefully.'));
160
- newline();
161
- }
162
- // Display metadata
163
- if (result.memoriesUsed.length > 0) {
164
- console.log(colors.dim(`Used ${formatNumber(result.memoriesUsed.length)} relevant memories`));
165
- }
166
- console.log(colors.dim(`Completed in ${formatNumber(result.trajectory.steps.length)} steps`));
167
- newline();
168
- }
169
- catch (err) {
170
- displayError(err, {
171
- operation: 'react',
172
- query,
173
- showSuggestions: true,
174
- });
175
- throw err;
176
- }
177
- finally {
178
- executionTracer.endRun();
179
- }
180
- }
181
- //# sourceMappingURL=react-command.js.map