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.
- package/README.md +88 -68
- package/dist/domain/entities/task.js +4 -4
- package/dist/error-handler.js +4 -9
- package/dist/index.js +253 -1219
- package/dist/infrastructure/config/product-context.js +7 -6
- package/dist/infrastructure/hooks/claude-sdk-hook.js +335 -63
- package/dist/infrastructure/observability/execution-tracer.js +11 -6
- package/dist/infrastructure/orchestration/agent-adapter.js +13 -0
- package/dist/infrastructure/orchestration/agent-installer.js +101 -0
- package/dist/infrastructure/orchestration/agents-config-seed.js +56 -0
- package/dist/infrastructure/orchestration/aider-adapter.js +319 -0
- package/dist/infrastructure/orchestration/artifacts-extractor.js +175 -0
- package/dist/infrastructure/orchestration/claude-code-adapter.js +352 -0
- package/dist/infrastructure/orchestration/codex-adapter.js +310 -0
- package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
- package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
- package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
- package/dist/infrastructure/orchestration/readiness.js +106 -0
- package/dist/infrastructure/orchestration/session-manager.js +272 -0
- package/dist/infrastructure/orchestration/session-persistence.js +109 -0
- package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
- package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
- package/dist/infrastructure/protocols/ui-page.js +1827 -0
- package/dist/infrastructure/security/file-collection.js +115 -0
- package/dist/infrastructure/security/trust-scorer.js +301 -56
- package/dist/infrastructure/storage/task-repository.js +8 -7
- package/dist/monitoring.js +10 -49
- package/dist/presentation/cli/commands/help-command.js +96 -139
- package/dist/presentation/cli/commands/hook-command.js +17 -24
- package/dist/presentation/cli/commands/report-command.js +59 -72
- package/dist/presentation/cli/commands/setup-command.js +4 -4
- package/dist/presentation/cli/commands/status-command.js +334 -43
- package/dist/presentation/cli/commands/trust-command.js +115 -99
- package/dist/presentation/cli/error-display.js +17 -21
- package/dist/ui.js +17 -12
- package/package.json +35 -67
- package/dist/agents/base.js +0 -101
- package/dist/agents/orchestrator-model-driven.js +0 -141
- package/dist/agents/react-orchestrator-agent.js +0 -54
- package/dist/application/agents/execution-agent.js +0 -508
- package/dist/application/agents/multi-agent-orchestrator.js +0 -295
- package/dist/application/agents/planning-agent.js +0 -433
- package/dist/application/agents/validation-agent.js +0 -317
- package/dist/application/architectures/plan-and-act.js +0 -242
- package/dist/application/index.js +0 -12
- package/dist/application/services/agent-factory.js +0 -28
- package/dist/application/services/dependency-container.js +0 -596
- package/dist/application/services/git-context-service.js +0 -83
- package/dist/application/services/intelligent-router.js +0 -934
- package/dist/application/services/tool-executor-service.js +0 -94
- package/dist/application/use-cases/ask-question-use-case.js +0 -338
- package/dist/application/use-cases/edit-file-use-case.js +0 -830
- package/dist/application/use-cases/explain-file-use-case.js +0 -50
- package/dist/application/use-cases/index-codebase-use-case.js +0 -113
- package/dist/application/use-cases/planning-use-case.js +0 -276
- package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
- package/dist/application/use-cases/reflexion-use-case.js +0 -30
- package/dist/application/workflows/deterministic-workflows.js +0 -189
- package/dist/ast-parser.js +0 -331
- package/dist/cache.js +0 -180
- package/dist/chat.js +0 -251
- package/dist/code-analysis.js +0 -327
- package/dist/context.js +0 -187
- package/dist/docs.js +0 -146
- package/dist/domain/entities/code-chunk.js +0 -6
- package/dist/domain/entities/decision.js +0 -9
- package/dist/domain/entities/edit.js +0 -6
- package/dist/domain/entities/knowledge-node.js +0 -9
- package/dist/domain/entities/knowledge-preservation.js +0 -10
- package/dist/domain/entities/memory.js +0 -6
- package/dist/domain/entities/pattern.js +0 -7
- package/dist/domain/entities/plan.js +0 -6
- package/dist/domain/entities/query.js +0 -6
- package/dist/domain/errors/embeddings-not-found-error.js +0 -13
- package/dist/domain/index.js +0 -19
- package/dist/domain/interfaces/ai-service.interface.js +0 -6
- package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
- package/dist/domain/interfaces/decision-repository.interface.js +0 -9
- package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
- package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
- package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
- package/dist/domain/interfaces/memory-repository.interface.js +0 -6
- package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
- package/dist/domain/interfaces/verification-service.interface.js +0 -6
- package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
- package/dist/domain/services/decision-recorder.js +0 -223
- package/dist/domain/services/decision-retriever.js +0 -133
- package/dist/domain/services/environment-mode-manager.js +0 -22
- package/dist/domain/services/graded-memory-activation.js +0 -69
- package/dist/domain/services/knowledge-access.js +0 -132
- package/dist/domain/services/knowledge-extractor.js +0 -247
- package/dist/domain/services/knowledge-graph-builder.js +0 -268
- package/dist/domain/services/knowledge-graph-query.js +0 -187
- package/dist/domain/services/memory-retriever.js +0 -82
- package/dist/domain/services/memory-synthesizer.js +0 -91
- package/dist/domain/services/pattern-extractor.js +0 -442
- package/dist/domain/services/query-intent-classifier.js +0 -140
- package/dist/domain/services/react-loop.js +0 -186
- package/dist/domain/services/risk-tier-detector.js +0 -78
- package/dist/edit.js +0 -319
- package/dist/embed.js +0 -459
- package/dist/formatter.js +0 -168
- package/dist/git.js +0 -198
- package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
- package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
- package/dist/infrastructure/ai/model-config.js +0 -84
- package/dist/infrastructure/ai/provider-ai-service.js +0 -477
- package/dist/infrastructure/cache/embedding-cache.js +0 -175
- package/dist/infrastructure/cache/query-result-cache.js +0 -66
- package/dist/infrastructure/cache/response-cache.js +0 -48
- package/dist/infrastructure/cache/security-scan-cache.js +0 -47
- package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
- package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
- package/dist/infrastructure/context/context-compressor.js +0 -329
- package/dist/infrastructure/context/conversation-context.js +0 -128
- package/dist/infrastructure/context/session-manager.js +0 -94
- package/dist/infrastructure/cost/cost-tracker.js +0 -360
- package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
- package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
- package/dist/infrastructure/governance/policy-as-code.js +0 -258
- package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
- package/dist/infrastructure/index.js +0 -7
- package/dist/infrastructure/observability/prompt-versioner.js +0 -145
- package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
- package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
- package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
- package/dist/infrastructure/protocols/mcp-server.js +0 -333
- package/dist/infrastructure/protocols/streaming-handler.js +0 -103
- package/dist/infrastructure/providers/cohere-provider.js +0 -444
- package/dist/infrastructure/providers/fake-provider.js +0 -130
- package/dist/infrastructure/providers/local-llm-provider.js +0 -330
- package/dist/infrastructure/providers/model-config.types.js +0 -9
- package/dist/infrastructure/providers/model-provider.interface.js +0 -8
- package/dist/infrastructure/providers/openai-provider.js +0 -413
- package/dist/infrastructure/providers/openrouter-provider.js +0 -399
- package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
- package/dist/infrastructure/providers/provider-config-loader.js +0 -120
- package/dist/infrastructure/providers/provider-registry.js +0 -88
- package/dist/infrastructure/safety/pattern-detector.js +0 -133
- package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
- package/dist/infrastructure/security/docker-sandbox.js +0 -178
- package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
- package/dist/infrastructure/security/license-scanner.js +0 -167
- package/dist/infrastructure/security/provider-bias-detector.js +0 -164
- package/dist/infrastructure/security/sandbox-executor.js +0 -64
- package/dist/infrastructure/serialization/toon-serializer.js +0 -119
- package/dist/infrastructure/storage/memory-stream-service.js +0 -204
- package/dist/infrastructure/storage/plan-repository.js +0 -96
- package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
- package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
- package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
- package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
- package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
- package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
- package/dist/infrastructure/storage/task-helpers.js +0 -197
- package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
- package/dist/infrastructure/ux/appropriate-friction.js +0 -213
- package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
- package/dist/infrastructure/ux/capability-boundaries.js +0 -42
- package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
- package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
- package/dist/infrastructure/ux/expectation-management.js +0 -327
- package/dist/infrastructure/ux/feature-discovery.js +0 -14
- package/dist/infrastructure/ux/feedback-prompt.js +0 -45
- package/dist/infrastructure/ux/hitl-validation.js +0 -297
- package/dist/infrastructure/ux/progress-indicator.js +0 -116
- package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
- package/dist/infrastructure/ux/review-checkpoint.js +0 -72
- package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
- package/dist/infrastructure/ux/stream-markdown.js +0 -151
- package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
- package/dist/infrastructure/ux/team-standards.js +0 -196
- package/dist/infrastructure/ux/transparency.js +0 -71
- package/dist/infrastructure/validation/agent-feedback.js +0 -55
- package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
- package/dist/infrastructure/validation/review-handler.js +0 -40
- package/dist/infrastructure/validation/summary-aggregator.js +0 -70
- package/dist/infrastructure/validation/summary-extractor.js +0 -45
- package/dist/infrastructure/validation/trace-summary.js +0 -52
- package/dist/infrastructure/verification/verification-service.js +0 -47
- package/dist/infrastructure/xai/attention-visualizer.js +0 -172
- package/dist/infrastructure/xai/cot-visualizer.js +0 -283
- package/dist/infrastructure/xai/decision-tree-log.js +0 -212
- package/dist/infrastructure/xai/interactive-xai.js +0 -260
- package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
- package/dist/intelligent-retrieval.js +0 -272
- package/dist/intent/classifier.js +0 -2
- package/dist/intent/context.js +0 -2
- package/dist/iterative-refinement.js +0 -189
- package/dist/learning.js +0 -232
- package/dist/log.js +0 -31
- package/dist/migrate.js +0 -133
- package/dist/parallel-processor.js +0 -530
- package/dist/planner.js +0 -198
- package/dist/policy.js +0 -26
- package/dist/presentation/cli/commands/ask-command.js +0 -314
- package/dist/presentation/cli/commands/cost-command.js +0 -191
- package/dist/presentation/cli/commands/decision-command.js +0 -207
- package/dist/presentation/cli/commands/docs-command.js +0 -25
- package/dist/presentation/cli/commands/fix-command.js +0 -53
- package/dist/presentation/cli/commands/knowledge-command.js +0 -129
- package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
- package/dist/presentation/cli/commands/models-command.js +0 -194
- package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
- package/dist/presentation/cli/commands/plan-command.js +0 -246
- package/dist/presentation/cli/commands/product-command.js +0 -199
- package/dist/presentation/cli/commands/react-command.js +0 -181
- package/dist/presentation/cli/commands/review-command.js +0 -154
- package/dist/presentation/cli/commands/run-command.js +0 -188
- package/dist/presentation/cli/commands/smart-command.js +0 -395
- package/dist/presentation/cli/commands/suggest-command.js +0 -138
- package/dist/presentation/cli/commands/trace-command.js +0 -129
- package/dist/presentation/cli/commands/undo-command.js +0 -150
- package/dist/query-optimizer.js +0 -205
- package/dist/refactor.js +0 -116
- package/dist/review.js +0 -206
- package/dist/search.js +0 -163
- package/dist/session.js +0 -652
- package/dist/task-verification.js +0 -336
- package/dist/testgen.js +0 -166
- package/dist/token-optimizer.js +0 -277
- package/dist/tools/bash.js +0 -213
- package/dist/tools/edit.js +0 -235
- package/dist/tools/executor.js +0 -153
- package/dist/tools/git-tool.js +0 -292
- package/dist/tools/parser.js +0 -158
- package/dist/tools/registry.js +0 -302
- package/dist/tools/search.js +0 -100
- package/dist/types.js +0 -2
- package/dist/utils/check-api-status.js +0 -100
- package/dist/utils/diff-parser.js +0 -162
- package/dist/verification/backup.js +0 -259
- package/dist/verification/compiler.js +0 -264
- package/dist/verification/index.js +0 -273
- package/dist/verification/test-runner.js +0 -379
package/dist/planner.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Intelligent Planning & Execution System
|
|
3
|
-
* Agentic behavior for complex multi-step tasks
|
|
4
|
-
*/
|
|
5
|
-
import { getEnhancedContext } from './context.js';
|
|
6
|
-
/**
|
|
7
|
-
* Decompose complex instruction into actionable tasks
|
|
8
|
-
*/
|
|
9
|
-
export async function planTask(instruction, context) {
|
|
10
|
-
const tasks = [];
|
|
11
|
-
const dependencies = new Map();
|
|
12
|
-
// Analyze instruction to determine task type
|
|
13
|
-
const lowerInstruction = instruction.toLowerCase();
|
|
14
|
-
// Search/Query tasks
|
|
15
|
-
if (lowerInstruction.includes('find') || lowerInstruction.includes('search') || lowerInstruction.includes('where') || lowerInstruction.includes('how')) {
|
|
16
|
-
tasks.push({
|
|
17
|
-
id: 'task_1',
|
|
18
|
-
description: `Search codebase: ${instruction}`,
|
|
19
|
-
type: 'search',
|
|
20
|
-
dependencies: [],
|
|
21
|
-
status: 'pending',
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
// Edit tasks
|
|
25
|
-
if (lowerInstruction.includes('add') || lowerInstruction.includes('remove') || lowerInstruction.includes('change') || lowerInstruction.includes('update') || lowerInstruction.includes('fix')) {
|
|
26
|
-
if (context?.files && context.files.length > 1) {
|
|
27
|
-
// Multi-file refactor
|
|
28
|
-
tasks.push({
|
|
29
|
-
id: 'task_1',
|
|
30
|
-
description: `Refactor multiple files: ${instruction}`,
|
|
31
|
-
type: 'refactor',
|
|
32
|
-
dependencies: [],
|
|
33
|
-
status: 'pending',
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// Single file edit
|
|
38
|
-
tasks.push({
|
|
39
|
-
id: 'task_1',
|
|
40
|
-
description: `Edit file: ${instruction}`,
|
|
41
|
-
type: 'edit',
|
|
42
|
-
dependencies: [],
|
|
43
|
-
status: 'pending',
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// Review tasks
|
|
48
|
-
if (lowerInstruction.includes('review') || lowerInstruction.includes('check') || lowerInstruction.includes('analyze')) {
|
|
49
|
-
tasks.push({
|
|
50
|
-
id: 'task_1',
|
|
51
|
-
description: `Review code: ${instruction}`,
|
|
52
|
-
type: 'review',
|
|
53
|
-
dependencies: [],
|
|
54
|
-
status: 'pending',
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
// If no specific type detected, create a search task first
|
|
58
|
-
if (tasks.length === 0) {
|
|
59
|
-
tasks.push({
|
|
60
|
-
id: 'task_1',
|
|
61
|
-
description: `Analyze: ${instruction}`,
|
|
62
|
-
type: 'analyze',
|
|
63
|
-
dependencies: [],
|
|
64
|
-
status: 'pending',
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
// Build dependency graph
|
|
68
|
-
for (const task of tasks) {
|
|
69
|
-
dependencies.set(task.id, task.dependencies);
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
tasks,
|
|
73
|
-
estimatedSteps: tasks.length,
|
|
74
|
-
dependencies,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Execute a plan step by step
|
|
79
|
-
*/
|
|
80
|
-
export async function executePlan(plan, context) {
|
|
81
|
-
const results = new Map();
|
|
82
|
-
const errors = [];
|
|
83
|
-
let completedTasks = 0;
|
|
84
|
-
// Execute tasks in dependency order
|
|
85
|
-
const taskQueue = [...plan.tasks];
|
|
86
|
-
const completed = new Set();
|
|
87
|
-
while (taskQueue.length > 0) {
|
|
88
|
-
const task = taskQueue.shift();
|
|
89
|
-
if (!task)
|
|
90
|
-
break;
|
|
91
|
-
// Check if dependencies are met
|
|
92
|
-
const depsMet = task.dependencies.every(dep => completed.has(dep));
|
|
93
|
-
if (!depsMet) {
|
|
94
|
-
// Re-queue for later
|
|
95
|
-
taskQueue.push(task);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
// Execute task
|
|
99
|
-
task.status = 'in_progress';
|
|
100
|
-
try {
|
|
101
|
-
let result;
|
|
102
|
-
switch (task.type) {
|
|
103
|
-
case 'search':
|
|
104
|
-
result = await executeSearchTask(task, context);
|
|
105
|
-
break;
|
|
106
|
-
case 'edit':
|
|
107
|
-
result = await executeEditTask(task, context);
|
|
108
|
-
break;
|
|
109
|
-
case 'refactor':
|
|
110
|
-
result = await executeRefactorTask(task, context);
|
|
111
|
-
break;
|
|
112
|
-
case 'review':
|
|
113
|
-
result = await executeReviewTask(task, context);
|
|
114
|
-
break;
|
|
115
|
-
case 'analyze':
|
|
116
|
-
result = await executeAnalyzeTask(task, context);
|
|
117
|
-
break;
|
|
118
|
-
default:
|
|
119
|
-
throw new Error(`Unknown task type: ${task.type}`);
|
|
120
|
-
}
|
|
121
|
-
task.result = result;
|
|
122
|
-
task.status = 'completed';
|
|
123
|
-
results.set(task.id, result);
|
|
124
|
-
completed.add(task.id);
|
|
125
|
-
completedTasks++;
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
task.status = 'failed';
|
|
129
|
-
task.error = error instanceof Error ? error.message : String(error);
|
|
130
|
-
errors.push({ task: task.id, error: task.error });
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
success: errors.length === 0 && completedTasks === plan.tasks.length,
|
|
135
|
-
completedTasks,
|
|
136
|
-
results,
|
|
137
|
-
errors,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async function executeSearchTask(task, context) {
|
|
141
|
-
const enhancedContext = await getEnhancedContext(context.instruction || task.description, {
|
|
142
|
-
primaryChunks: 15,
|
|
143
|
-
relatedChunks: 5,
|
|
144
|
-
includeRelationships: true,
|
|
145
|
-
});
|
|
146
|
-
return [...enhancedContext.primaryChunks, ...enhancedContext.relatedChunks];
|
|
147
|
-
}
|
|
148
|
-
async function executeEditTask(task, context) {
|
|
149
|
-
// This would integrate with the edit system
|
|
150
|
-
// For now, return placeholder
|
|
151
|
-
return {
|
|
152
|
-
file: context.files?.[0] || 'unknown',
|
|
153
|
-
success: true,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
async function executeRefactorTask(task, context) {
|
|
157
|
-
// This would integrate with the refactor system
|
|
158
|
-
return {
|
|
159
|
-
files: context.files || [],
|
|
160
|
-
success: true,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
async function executeReviewTask(task, context) {
|
|
164
|
-
// This would integrate with the review system
|
|
165
|
-
return {
|
|
166
|
-
suggestions: [],
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
async function executeAnalyzeTask(task, context) {
|
|
170
|
-
const enhancedContext = await getEnhancedContext(context.instruction || task.description, {
|
|
171
|
-
primaryChunks: 20,
|
|
172
|
-
relatedChunks: 10,
|
|
173
|
-
includeRelationships: true,
|
|
174
|
-
});
|
|
175
|
-
return {
|
|
176
|
-
analysis: `Found ${enhancedContext.totalChunks} relevant chunks from ${enhancedContext.primaryChunks.length} files`,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Format plan for display
|
|
181
|
-
*/
|
|
182
|
-
export function formatPlan(plan) {
|
|
183
|
-
let output = `Plan: ${plan.estimatedSteps} step(s)\n\n`;
|
|
184
|
-
for (const task of plan.tasks) {
|
|
185
|
-
const statusIcon = {
|
|
186
|
-
pending: '○',
|
|
187
|
-
in_progress: '⟳',
|
|
188
|
-
completed: '✓',
|
|
189
|
-
failed: '✗',
|
|
190
|
-
}[task.status];
|
|
191
|
-
output += `${statusIcon} [${task.type}] ${task.description}\n`;
|
|
192
|
-
if (task.dependencies.length > 0) {
|
|
193
|
-
output += ` Depends on: ${task.dependencies.join(', ')}\n`;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return output;
|
|
197
|
-
}
|
|
198
|
-
//# sourceMappingURL=planner.js.map
|
package/dist/policy.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export function checkPolicy(filepath, diffStats) {
|
|
2
|
-
// Check 1: Maximum 50 changed lines
|
|
3
|
-
const totalChanges = diffStats.linesAdded + diffStats.linesRemoved;
|
|
4
|
-
if (totalChanges > 50) {
|
|
5
|
-
return {
|
|
6
|
-
allowed: false,
|
|
7
|
-
reason: `Change exceeds 50 line limit (${totalChanges} lines changed)`,
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
// Check 2: Restricted folders
|
|
11
|
-
if (filepath.includes('infra/') || filepath.includes('billing/')) {
|
|
12
|
-
return {
|
|
13
|
-
allowed: false,
|
|
14
|
-
reason: `File is in restricted folder: ${filepath}`,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
// Check 3: Only one file can be changed
|
|
18
|
-
if (diffStats.filesChanged > 1) {
|
|
19
|
-
return {
|
|
20
|
-
allowed: false,
|
|
21
|
-
reason: `Patch edits ${diffStats.filesChanged} files (only 1 file allowed)`,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
return { allowed: true };
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=policy.js.map
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Command: Ask
|
|
3
|
-
* Uses clean architecture - AskQuestionUseCase
|
|
4
|
-
*/
|
|
5
|
-
import { container } from '../../../application/services/dependency-container.js';
|
|
6
|
-
import { colors, sectionHeader, formatNumber, formatPath, formatScore, createTable, newline, warning, info, separator, isMinimalStyle, printMinimalHeader, printContextSummary, } 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 executeAskCommand(question, options) {
|
|
11
|
-
// Track start time for summary statistics
|
|
12
|
-
const startTime = Date.now();
|
|
13
|
-
// Capability Boundaries: Check for unsupported operations
|
|
14
|
-
try {
|
|
15
|
-
const { CapabilityBoundaryDetector, displayCapabilityBoundary } = await import('../../../infrastructure/ux/capability-boundaries.js');
|
|
16
|
-
const detector = new CapabilityBoundaryDetector();
|
|
17
|
-
const boundary = detector.detectUnsupported(question);
|
|
18
|
-
if (boundary) {
|
|
19
|
-
displayCapabilityBoundary(boundary);
|
|
20
|
-
executionTracer.endRun();
|
|
21
|
-
return; // Don't proceed with unsupported operation
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
// Capability boundary check failed - continue anyway (non-blocking)
|
|
26
|
-
}
|
|
27
|
-
// Start execution tracing
|
|
28
|
-
const codebaseInfo = findCodebaseRoot(process.cwd());
|
|
29
|
-
const runId = executionTracer.startRun('ask', {
|
|
30
|
-
query: question,
|
|
31
|
-
codebaseId: codebaseInfo?.rootPath || process.cwd(),
|
|
32
|
-
});
|
|
33
|
-
// Get user ID for Progressive Disclosure (use codebase path or default)
|
|
34
|
-
const userId = codebaseInfo?.rootPath || process.cwd() || 'cli-user';
|
|
35
|
-
// Progressive Disclosure: Record feature usage
|
|
36
|
-
const progressiveDisclosure = container.progressiveDisclosure;
|
|
37
|
-
if (progressiveDisclosure) {
|
|
38
|
-
progressiveDisclosure.recordFeatureUsage(userId, 'ask_question');
|
|
39
|
-
}
|
|
40
|
-
// Capability assessment (silent — no disclaimer wall)
|
|
41
|
-
const expectationManagement = container.expectationManagement;
|
|
42
|
-
let capabilityAssessment = null;
|
|
43
|
-
if (expectationManagement) {
|
|
44
|
-
capabilityAssessment = expectationManagement.assessCapability('ask_question', {
|
|
45
|
-
complexity: question.split(' ').length > 20 ? 'complex' : question.split(' ').length > 10 ? 'moderate' : 'simple',
|
|
46
|
-
uncertainty: undefined,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
// Check if embeddings exist for this repository (skip check if using fake AI for testing)
|
|
51
|
-
if (process.env.CODEHERE_FAKE_AI !== '1') {
|
|
52
|
-
const embeddingRepo = container.getEmbeddingRepository(process.cwd());
|
|
53
|
-
const hasEmbeddings = await embeddingRepo.hasEmbeddings();
|
|
54
|
-
if (!hasEmbeddings) {
|
|
55
|
-
newline();
|
|
56
|
-
console.error(colors.red('No embeddings found for this repository.'));
|
|
57
|
-
newline();
|
|
58
|
-
console.log('Run:');
|
|
59
|
-
console.log(colors.cyan(' codehere index'));
|
|
60
|
-
console.log('');
|
|
61
|
-
console.log('then re-run this command.');
|
|
62
|
-
newline();
|
|
63
|
-
executionTracer.endRun();
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// Use per-repo embedding repository for codebase isolation
|
|
68
|
-
const useCase = container.getAskQuestionUseCase(process.cwd());
|
|
69
|
-
const minimal = isMinimalStyle();
|
|
70
|
-
// Print minimal header
|
|
71
|
-
if (minimal) {
|
|
72
|
-
printMinimalHeader('ask', question);
|
|
73
|
-
console.log(colors.bold('Answer:'));
|
|
74
|
-
}
|
|
75
|
-
// Enable streaming by default for better UX - disable in minimal mode for cleaner output
|
|
76
|
-
const enableStreaming = !minimal && options?.stream !== false;
|
|
77
|
-
let streamingAnswer = '';
|
|
78
|
-
// Set up streaming handler (only in verbose mode)
|
|
79
|
-
const streamHandler = enableStreaming ? {
|
|
80
|
-
onToken: (token) => {
|
|
81
|
-
process.stdout.write(token);
|
|
82
|
-
streamingAnswer += token;
|
|
83
|
-
},
|
|
84
|
-
onComplete: (fullText) => {
|
|
85
|
-
streamingAnswer = fullText;
|
|
86
|
-
},
|
|
87
|
-
onError: (error) => {
|
|
88
|
-
console.error(colors.red(`\nStreaming error: ${error.message}`));
|
|
89
|
-
},
|
|
90
|
-
} : undefined;
|
|
91
|
-
// Get conversation context and resolve references
|
|
92
|
-
const { conversationContextManager } = await import('../../../infrastructure/context/conversation-context.js');
|
|
93
|
-
const { sessionManager } = await import('../../../infrastructure/context/session-manager.js');
|
|
94
|
-
const sessionId = sessionManager.getSessionId(process.cwd());
|
|
95
|
-
const history = conversationContextManager.getHistory(sessionId, 5);
|
|
96
|
-
// Resolve references in query (e.g., "it", "that", "the previous")
|
|
97
|
-
const resolvedQuestion = conversationContextManager.resolveReferences(sessionId, question);
|
|
98
|
-
const entities = conversationContextManager.extractEntities(resolvedQuestion);
|
|
99
|
-
// Display search results first (before streaming answer)
|
|
100
|
-
const result = await useCase.execute({
|
|
101
|
-
query: resolvedQuestion,
|
|
102
|
-
maxResults: 15,
|
|
103
|
-
streamHandler,
|
|
104
|
-
conversationHistory: history.map(turn => ({
|
|
105
|
-
query: turn.query,
|
|
106
|
-
response: turn.response,
|
|
107
|
-
timestamp: typeof turn.timestamp === 'string' ? Date.parse(turn.timestamp) : turn.timestamp,
|
|
108
|
-
})),
|
|
109
|
-
});
|
|
110
|
-
// Check if this is a git status response (has answer but no chunks)
|
|
111
|
-
const isGitResponse = result.answer && result.answer.includes('Git Repository Status');
|
|
112
|
-
// With FAKE_AI, we still want to show structured output even if chunks are empty
|
|
113
|
-
// Only show "No relevant code found" for real providers when there are truly no chunks
|
|
114
|
-
if (result.chunks.length === 0 && !isGitResponse && process.env.CODEHERE_FAKE_AI !== '1') {
|
|
115
|
-
console.log('No relevant code found. Run "codehere index" first.');
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
// If git response, display it directly
|
|
119
|
-
if (isGitResponse) {
|
|
120
|
-
if (!minimal)
|
|
121
|
-
sectionHeader('Response');
|
|
122
|
-
const { formatMarkdownForTerminal } = await import('../../../infrastructure/ux/stream-markdown.js');
|
|
123
|
-
console.log(formatMarkdownForTerminal(result.answer));
|
|
124
|
-
newline();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const retrievedFiles = [...new Set(result.chunks.map(r => r.filepath))];
|
|
128
|
-
// With FAKE_AI, show at least a placeholder context even if chunks are empty
|
|
129
|
-
// This ensures tests can verify the structured output format
|
|
130
|
-
const showContext = retrievedFiles.length > 0 || process.env.CODEHERE_FAKE_AI === '1';
|
|
131
|
-
// Minimal style: skip verbose search results table
|
|
132
|
-
if (!minimal) {
|
|
133
|
-
// Display search results
|
|
134
|
-
sectionHeader('Search Results');
|
|
135
|
-
const fileTable = createTable(['File', 'Relevance', 'Preview'], result.chunks.slice(0, 10).map(r => [
|
|
136
|
-
formatPath(r.filepath),
|
|
137
|
-
formatScore(r.score),
|
|
138
|
-
colors.dim(r.content.substring(0, 50) + '...'),
|
|
139
|
-
]));
|
|
140
|
-
console.log(fileTable.toString());
|
|
141
|
-
console.log(colors.dim(`\nFound ${formatNumber(result.chunks.length)} chunks from ${formatNumber(retrievedFiles.length)} file(s)`));
|
|
142
|
-
if (result.tokenEstimate) {
|
|
143
|
-
console.log(colors.dim(`Token estimate: ${formatNumber(result.tokenEstimate)}`));
|
|
144
|
-
}
|
|
145
|
-
console.log();
|
|
146
|
-
}
|
|
147
|
-
// Display response
|
|
148
|
-
if (minimal) {
|
|
149
|
-
// In minimal mode — format markdown for terminal
|
|
150
|
-
const { formatMarkdownForTerminal } = await import('../../../infrastructure/ux/stream-markdown.js');
|
|
151
|
-
console.log(formatMarkdownForTerminal(result.answer || ''));
|
|
152
|
-
newline();
|
|
153
|
-
if (showContext) {
|
|
154
|
-
// Show context even if empty (for FAKE_AI tests) or with actual files
|
|
155
|
-
if (retrievedFiles.length > 0) {
|
|
156
|
-
printContextSummary(retrievedFiles);
|
|
157
|
-
}
|
|
158
|
-
else if (process.env.CODEHERE_FAKE_AI === '1') {
|
|
159
|
-
// For FAKE_AI tests, show a placeholder context to maintain output structure
|
|
160
|
-
console.log(colors.dim('Context:'));
|
|
161
|
-
console.log(colors.dim(' - (Using test mode - no real embeddings)'));
|
|
162
|
-
}
|
|
163
|
-
newline();
|
|
164
|
-
}
|
|
165
|
-
newline();
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
// Verbose mode
|
|
169
|
-
sectionHeader('Response');
|
|
170
|
-
if (enableStreaming && streamingAnswer) {
|
|
171
|
-
// Streaming already displayed, just add newline
|
|
172
|
-
console.log();
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
const { formatMarkdownForTerminal } = await import('../../../infrastructure/ux/stream-markdown.js');
|
|
176
|
-
console.log(formatMarkdownForTerminal(result.answer || ''));
|
|
177
|
-
}
|
|
178
|
-
newline();
|
|
179
|
-
}
|
|
180
|
-
// Verbose style: show summary statistics
|
|
181
|
-
if (!minimal) {
|
|
182
|
-
const executionTime = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
183
|
-
const summaryRows = [];
|
|
184
|
-
summaryRows.push(['Execution Time', `${executionTime}s`]);
|
|
185
|
-
// Performance metrics breakdown (if available)
|
|
186
|
-
if (result.performanceMetrics) {
|
|
187
|
-
const pm = result.performanceMetrics;
|
|
188
|
-
if (pm.embeddingGenTime && pm.embeddingGenTime > 0) {
|
|
189
|
-
summaryRows.push([' Embedding Generation', `${(pm.embeddingGenTime / 1000).toFixed(2)}s`]);
|
|
190
|
-
}
|
|
191
|
-
if (pm.searchTime && pm.searchTime > 0) {
|
|
192
|
-
summaryRows.push([' Code Search', `${(pm.searchTime / 1000).toFixed(2)}s`]);
|
|
193
|
-
}
|
|
194
|
-
if (pm.rerankTime && pm.rerankTime > 0) {
|
|
195
|
-
summaryRows.push([' Rerank', `${(pm.rerankTime / 1000).toFixed(2)}s`]);
|
|
196
|
-
}
|
|
197
|
-
if (pm.chatTime && pm.chatTime > 0) {
|
|
198
|
-
summaryRows.push([' AI Chat', `${(pm.chatTime / 1000).toFixed(2)}s`]);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (result.chunks.length > 0) {
|
|
202
|
-
summaryRows.push(['Files Found', formatNumber(result.chunks.length)]);
|
|
203
|
-
summaryRows.push(['Chunks Retrieved', formatNumber(result.chunks.length)]);
|
|
204
|
-
}
|
|
205
|
-
if (result.tokenEstimate) {
|
|
206
|
-
summaryRows.push(['Tokens', formatNumber(result.tokenEstimate)]);
|
|
207
|
-
}
|
|
208
|
-
if (result.memories && result.memories.length > 0) {
|
|
209
|
-
summaryRows.push(['Memories Used', formatNumber(result.memories.length)]);
|
|
210
|
-
}
|
|
211
|
-
if (result.compressionMetrics && result.compressionMetrics.reductionPercent > 0) {
|
|
212
|
-
summaryRows.push(['Context Compression', `${result.compressionMetrics.reductionPercent.toFixed(1)}% reduction`]);
|
|
213
|
-
summaryRows.push([' Original Tokens', formatNumber(result.compressionMetrics.originalTokens)]);
|
|
214
|
-
summaryRows.push([' Compressed Tokens', formatNumber(result.compressionMetrics.compressedTokens)]);
|
|
215
|
-
}
|
|
216
|
-
if (summaryRows.length > 1) {
|
|
217
|
-
console.log(separator('─', 80));
|
|
218
|
-
sectionHeader('Summary');
|
|
219
|
-
const summaryTable = createTable(['Metric', 'Value'], summaryRows);
|
|
220
|
-
console.log(summaryTable.toString());
|
|
221
|
-
newline();
|
|
222
|
-
}
|
|
223
|
-
// Expectation Management: Show warnings if uncertainty is high
|
|
224
|
-
if (result.uncertainty && expectationManagement) {
|
|
225
|
-
if (result.uncertainty.isHallucinationRisk) {
|
|
226
|
-
console.log(warning('\n⚠️ High uncertainty detected - please verify the response carefully.'));
|
|
227
|
-
}
|
|
228
|
-
// Update capability assessment with actual uncertainty
|
|
229
|
-
if (capabilityAssessment) {
|
|
230
|
-
const updatedAssessment = expectationManagement.assessCapability('ask_question', {
|
|
231
|
-
complexity: question.split(' ').length > 20 ? 'complex' : question.split(' ').length > 10 ? 'moderate' : 'simple',
|
|
232
|
-
uncertainty: result.uncertainty.combined.value,
|
|
233
|
-
});
|
|
234
|
-
if (updatedAssessment.warnings.length > 0 && updatedAssessment.capability === 'risky') {
|
|
235
|
-
console.log(warning(`\n⚠️ ${updatedAssessment.warnings[0]}\n`));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
// Contextual Feature Discovery: Show relevant features based on query (Task 2.2)
|
|
240
|
-
const { shouldShowContextualSuggestion } = await import('../../../infrastructure/ux/contextual-feature-discovery.js');
|
|
241
|
-
const contextualSuggestion = shouldShowContextualSuggestion(question, 'ask');
|
|
242
|
-
if (contextualSuggestion) {
|
|
243
|
-
newline();
|
|
244
|
-
console.log(colors.bold(`💡 Tip: ${contextualSuggestion.reason}`));
|
|
245
|
-
console.log(colors.dim(` Try: ${colors.cyan(contextualSuggestion.command)}`));
|
|
246
|
-
console.log(colors.dim(` ${contextualSuggestion.description}`));
|
|
247
|
-
newline();
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
// Progressive Disclosure: Suggest next features for beginner users (fallback)
|
|
251
|
-
if (progressiveDisclosure) {
|
|
252
|
-
const profile = progressiveDisclosure.getUserProfile(userId);
|
|
253
|
-
if (profile.level === 'beginner' || profile.level === 'intermediate') {
|
|
254
|
-
const nextFeatures = progressiveDisclosure.getNextSuggestedFeatures(userId, 1);
|
|
255
|
-
if (nextFeatures.length > 0) {
|
|
256
|
-
const feature = nextFeatures[0];
|
|
257
|
-
console.log(info(`💡 Tip: Try "${feature.featureName}" - ${feature.description}`));
|
|
258
|
-
console.log(colors.dim(` Run: codehere ${feature.featureId === 'edit_file' ? 'edit' : feature.featureId === 'react_loop' ? 'react' : 'help'} for more info\n`));
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
// Task 6.1: Explicit Feedback Mechanisms - Prompt for feedback after response
|
|
264
|
-
try {
|
|
265
|
-
const { promptForFeedback, storeFeedback, displayFeedbackConfirmation } = await import('../../../infrastructure/ux/feedback-prompt.js');
|
|
266
|
-
const { BiDirectionalLearning } = await import('../../../infrastructure/ux/bi-directional-learning.js');
|
|
267
|
-
// Get learning system from container (or create instance if not available)
|
|
268
|
-
const learningSystem = container.biDirectionalLearning || new BiDirectionalLearning();
|
|
269
|
-
const userId = process.env.USER || 'default-user';
|
|
270
|
-
const feedback = await promptForFeedback('ask', {
|
|
271
|
-
query: question,
|
|
272
|
-
response: result.answer,
|
|
273
|
-
sessionId: executionTracer.getCurrentRunId() || undefined,
|
|
274
|
-
});
|
|
275
|
-
if (feedback) {
|
|
276
|
-
storeFeedback(learningSystem, userId, feedback, {
|
|
277
|
-
operation: 'ask',
|
|
278
|
-
query: question,
|
|
279
|
-
response: result.answer,
|
|
280
|
-
sessionId: executionTracer.getCurrentRunId() || undefined,
|
|
281
|
-
});
|
|
282
|
-
displayFeedbackConfirmation(feedback);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
catch (feedbackError) {
|
|
286
|
-
// Don't fail the command if feedback collection fails
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
// Store conversation turn for future reference resolution (always)
|
|
290
|
-
try {
|
|
291
|
-
const { conversationContextManager } = await import('../../../infrastructure/context/conversation-context.js');
|
|
292
|
-
const { sessionManager } = await import('../../../infrastructure/context/session-manager.js');
|
|
293
|
-
const sessionId = sessionManager.getSessionId(process.cwd());
|
|
294
|
-
const response = result.answer || 'No answer generated';
|
|
295
|
-
const entities = conversationContextManager.extractEntities(resolvedQuestion);
|
|
296
|
-
conversationContextManager.addTurn(sessionId, question, response, entities, 'ask');
|
|
297
|
-
}
|
|
298
|
-
catch (error) {
|
|
299
|
-
// Don't fail if conversation tracking fails
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
catch (err) {
|
|
303
|
-
displayError(err, {
|
|
304
|
-
operation: 'ask',
|
|
305
|
-
query: question,
|
|
306
|
-
showSuggestions: true,
|
|
307
|
-
});
|
|
308
|
-
throw err;
|
|
309
|
-
}
|
|
310
|
-
finally {
|
|
311
|
-
executionTracer.endRun();
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
//# sourceMappingURL=ask-command.js.map
|