codehere 0.2.2 → 0.3.0-rc.2
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 +348 -72
- 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 +9 -38
- 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 +321 -30
- package/dist/presentation/cli/commands/trust-command.js +84 -72
- package/dist/presentation/cli/error-display.js +17 -21
- package/dist/ui.js +11 -11
- package/package.json +24 -62
- 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 -534
- 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 -704
- 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/tools/edit.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Edit Tool
|
|
3
|
-
* String replacement-based file editing (like Claude Code)
|
|
4
|
-
* Requires exact matches for safety
|
|
5
|
-
*/
|
|
6
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
7
|
-
import { resolve, dirname } from 'path';
|
|
8
|
-
// Undo stack (simple in-memory, could be persisted later)
|
|
9
|
-
const undoStack = new Map();
|
|
10
|
-
/**
|
|
11
|
-
* View file content
|
|
12
|
-
*/
|
|
13
|
-
export function viewFile(filepath, options = {}) {
|
|
14
|
-
const absPath = resolve(options.cwd || process.cwd(), filepath);
|
|
15
|
-
if (!existsSync(absPath)) {
|
|
16
|
-
return {
|
|
17
|
-
success: false,
|
|
18
|
-
filepath: absPath,
|
|
19
|
-
operation: 'view',
|
|
20
|
-
error: `File not found: ${absPath}`,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
const content = readFileSync(absPath, 'utf-8');
|
|
25
|
-
return {
|
|
26
|
-
success: true,
|
|
27
|
-
filepath: absPath,
|
|
28
|
-
operation: 'view',
|
|
29
|
-
content,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
return {
|
|
34
|
-
success: false,
|
|
35
|
-
filepath: absPath,
|
|
36
|
-
operation: 'view',
|
|
37
|
-
error: error instanceof Error ? error.message : String(error),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Create a new file
|
|
43
|
-
*/
|
|
44
|
-
export function createFile(filepath, content, options = {}) {
|
|
45
|
-
const absPath = resolve(options.cwd || process.cwd(), filepath);
|
|
46
|
-
// Check if file exists
|
|
47
|
-
if (existsSync(absPath) && !options.createIfNotExists) {
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
filepath: absPath,
|
|
51
|
-
operation: 'create',
|
|
52
|
-
error: `File already exists: ${absPath}`,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
// Ensure directory exists
|
|
57
|
-
const dir = dirname(absPath);
|
|
58
|
-
if (!existsSync(dir)) {
|
|
59
|
-
mkdirSync(dir, { recursive: true });
|
|
60
|
-
}
|
|
61
|
-
// Save to undo stack
|
|
62
|
-
if (existsSync(absPath)) {
|
|
63
|
-
const oldContent = readFileSync(absPath, 'utf-8');
|
|
64
|
-
if (!undoStack.has(absPath)) {
|
|
65
|
-
undoStack.set(absPath, []);
|
|
66
|
-
}
|
|
67
|
-
undoStack.get(absPath).push(oldContent);
|
|
68
|
-
}
|
|
69
|
-
// Write file
|
|
70
|
-
writeFileSync(absPath, content, 'utf-8');
|
|
71
|
-
return {
|
|
72
|
-
success: true,
|
|
73
|
-
filepath: absPath,
|
|
74
|
-
operation: 'create',
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
return {
|
|
79
|
-
success: false,
|
|
80
|
-
filepath: absPath,
|
|
81
|
-
operation: 'create',
|
|
82
|
-
error: error instanceof Error ? error.message : String(error),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* String replacement (exact match required)
|
|
88
|
-
* CRITICAL: Must match exactly, or error if multiple matches
|
|
89
|
-
*/
|
|
90
|
-
export function strReplace(filepath, oldString, newString, options = {}) {
|
|
91
|
-
const absPath = resolve(options.cwd || process.cwd(), filepath);
|
|
92
|
-
if (!existsSync(absPath)) {
|
|
93
|
-
return {
|
|
94
|
-
success: false,
|
|
95
|
-
filepath: absPath,
|
|
96
|
-
operation: 'str_replace',
|
|
97
|
-
error: `File not found: ${absPath}`,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
// Read file
|
|
102
|
-
const content = readFileSync(absPath, 'utf-8');
|
|
103
|
-
// Save to undo stack
|
|
104
|
-
if (!undoStack.has(absPath)) {
|
|
105
|
-
undoStack.set(absPath, []);
|
|
106
|
-
}
|
|
107
|
-
undoStack.get(absPath).push(content);
|
|
108
|
-
// Count matches
|
|
109
|
-
const matches = content.split(oldString).length - 1;
|
|
110
|
-
if (matches === 0) {
|
|
111
|
-
return {
|
|
112
|
-
success: false,
|
|
113
|
-
filepath: absPath,
|
|
114
|
-
operation: 'str_replace',
|
|
115
|
-
error: `String not found in file. Exact match required.`,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
if (matches > 1) {
|
|
119
|
-
return {
|
|
120
|
-
success: false,
|
|
121
|
-
filepath: absPath,
|
|
122
|
-
operation: 'str_replace',
|
|
123
|
-
error: `Multiple matches found (${matches}). Provide more context to make the match unique.`,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
// Perform replacement
|
|
127
|
-
const newContent = content.replace(oldString, newString);
|
|
128
|
-
// Write file
|
|
129
|
-
writeFileSync(absPath, newContent, 'utf-8');
|
|
130
|
-
return {
|
|
131
|
-
success: true,
|
|
132
|
-
filepath: absPath,
|
|
133
|
-
operation: 'str_replace',
|
|
134
|
-
replacements: 1,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
return {
|
|
139
|
-
success: false,
|
|
140
|
-
filepath: absPath,
|
|
141
|
-
operation: 'str_replace',
|
|
142
|
-
error: error instanceof Error ? error.message : String(error),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Undo last edit
|
|
148
|
-
*/
|
|
149
|
-
export function undoEdit(filepath, options = {}) {
|
|
150
|
-
const absPath = resolve(options.cwd || process.cwd(), filepath);
|
|
151
|
-
const stack = undoStack.get(absPath);
|
|
152
|
-
if (!stack || stack.length === 0) {
|
|
153
|
-
return {
|
|
154
|
-
success: false,
|
|
155
|
-
filepath: absPath,
|
|
156
|
-
operation: 'undo',
|
|
157
|
-
error: 'No undo history available',
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const previousContent = stack.pop();
|
|
162
|
-
writeFileSync(absPath, previousContent, 'utf-8');
|
|
163
|
-
return {
|
|
164
|
-
success: true,
|
|
165
|
-
filepath: absPath,
|
|
166
|
-
operation: 'undo',
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
return {
|
|
171
|
-
success: false,
|
|
172
|
-
filepath: absPath,
|
|
173
|
-
operation: 'undo',
|
|
174
|
-
error: error instanceof Error ? error.message : String(error),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Tool description for the model
|
|
180
|
-
* This is critical - the model needs to understand how to use this tool
|
|
181
|
-
*/
|
|
182
|
-
export const EDIT_TOOL_DESCRIPTION = `
|
|
183
|
-
Edit Tool - String replacement-based file editing
|
|
184
|
-
|
|
185
|
-
DESCRIPTION:
|
|
186
|
-
Edit files using string replacement. Requires exact matches for safety.
|
|
187
|
-
|
|
188
|
-
AVAILABLE OPERATIONS:
|
|
189
|
-
1. **view(filepath)**: View file content
|
|
190
|
-
2. **create(filepath, content)**: Create new file
|
|
191
|
-
3. **str_replace(filepath, oldString, newString)**: Replace string in file
|
|
192
|
-
4. **undo(filepath)**: Undo last edit
|
|
193
|
-
|
|
194
|
-
CRITICAL RULES:
|
|
195
|
-
1. **Exact Match Required**: oldString must match EXACTLY in the file
|
|
196
|
-
2. **Unique Match Required**: If multiple matches found, provide more context
|
|
197
|
-
3. **Absolute Paths**: All paths are resolved to absolute paths automatically
|
|
198
|
-
4. **Context for Uniqueness**: Include surrounding lines if needed to make match unique
|
|
199
|
-
|
|
200
|
-
STRING REPLACEMENT:
|
|
201
|
-
- oldString must appear EXACTLY ONCE in the file
|
|
202
|
-
- If 0 matches: Error - string not found
|
|
203
|
-
- If 2+ matches: Error - provide more context
|
|
204
|
-
- Include surrounding code/whitespace to ensure uniqueness
|
|
205
|
-
|
|
206
|
-
EXAMPLES:
|
|
207
|
-
- str_replace('/path/to/file.ts', 'function old()', 'function new()')
|
|
208
|
-
- str_replace('/path/to/file.ts', 'const x = 1;\\n', 'const x = 2;\\n')
|
|
209
|
-
- Include context: str_replace('/path/to/file.ts', ' // Comment\\n function old()', ' // Comment\\n function new()')
|
|
210
|
-
|
|
211
|
-
PATH HANDLING:
|
|
212
|
-
- All paths are resolved to absolute paths
|
|
213
|
-
- Use absolute paths or paths relative to cwd
|
|
214
|
-
- Example: '/Users/username/project/file.ts' (absolute)
|
|
215
|
-
- Example: './file.ts' (relative to cwd)
|
|
216
|
-
|
|
217
|
-
UNDO:
|
|
218
|
-
- undo() restores file to previous state
|
|
219
|
-
- Only one level of undo (last edit)
|
|
220
|
-
- Undo stack is in-memory (lost on restart)
|
|
221
|
-
|
|
222
|
-
ERROR HANDLING:
|
|
223
|
-
- Check success field in result
|
|
224
|
-
- Check error field for error message
|
|
225
|
-
- Common errors:
|
|
226
|
-
- File not found
|
|
227
|
-
- String not found (0 matches)
|
|
228
|
-
- Multiple matches (need more context)
|
|
229
|
-
|
|
230
|
-
SECURITY:
|
|
231
|
-
- All paths are validated
|
|
232
|
-
- No file system traversal beyond project directory
|
|
233
|
-
- Exact match requirement prevents accidental replacements
|
|
234
|
-
`;
|
|
235
|
-
//# sourceMappingURL=edit.js.map
|
package/dist/tools/executor.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Executor
|
|
3
|
-
* Execute tools with error handling and result formatting
|
|
4
|
-
*/
|
|
5
|
-
import { getToolRegistry } from './registry.js';
|
|
6
|
-
export class ToolExecutor {
|
|
7
|
-
/**
|
|
8
|
-
* Execute a single tool call
|
|
9
|
-
*/
|
|
10
|
-
async execute(call) {
|
|
11
|
-
const startTime = Date.now();
|
|
12
|
-
const registry = getToolRegistry();
|
|
13
|
-
const tool = registry.get(call.tool);
|
|
14
|
-
// Import execution tracer dynamically to avoid circular dependencies
|
|
15
|
-
const { executionTracer } = await import('../infrastructure/observability/execution-tracer.js');
|
|
16
|
-
// Trace tool invocation
|
|
17
|
-
const traceId = executionTracer.trace({
|
|
18
|
-
operationType: 'tool_invocation',
|
|
19
|
-
operationName: call.tool,
|
|
20
|
-
input: { parameters: call.parameters },
|
|
21
|
-
metadata: {
|
|
22
|
-
toolId: call.id,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
if (!tool) {
|
|
26
|
-
const duration = Date.now() - startTime;
|
|
27
|
-
executionTracer.trace({
|
|
28
|
-
operationType: 'tool_invocation',
|
|
29
|
-
operationName: call.tool,
|
|
30
|
-
error: new Error(`Tool not found: ${call.tool}`),
|
|
31
|
-
duration,
|
|
32
|
-
metadata: { toolId: call.id },
|
|
33
|
-
});
|
|
34
|
-
return {
|
|
35
|
-
success: false,
|
|
36
|
-
tool: call.tool,
|
|
37
|
-
error: `Tool not found: ${call.tool}`,
|
|
38
|
-
duration,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
// Validate parameters
|
|
43
|
-
const validation = validateParameters(call.parameters, tool.parameters);
|
|
44
|
-
if (!validation.valid) {
|
|
45
|
-
const duration = Date.now() - startTime;
|
|
46
|
-
const error = new Error(`Invalid parameters: ${validation.errors.join(', ')}`);
|
|
47
|
-
executionTracer.trace({
|
|
48
|
-
operationType: 'tool_invocation',
|
|
49
|
-
operationName: call.tool,
|
|
50
|
-
error,
|
|
51
|
-
duration,
|
|
52
|
-
metadata: { toolId: call.id },
|
|
53
|
-
});
|
|
54
|
-
return {
|
|
55
|
-
success: false,
|
|
56
|
-
tool: call.tool,
|
|
57
|
-
error: error.message,
|
|
58
|
-
duration,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
// Execute tool
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
-
const result = await tool.execute(...Object.values(call.parameters));
|
|
64
|
-
const duration = Date.now() - startTime;
|
|
65
|
-
// Trace successful execution
|
|
66
|
-
executionTracer.trace({
|
|
67
|
-
operationType: 'tool_invocation',
|
|
68
|
-
operationName: call.tool,
|
|
69
|
-
output: {
|
|
70
|
-
success: true,
|
|
71
|
-
resultType: typeof result,
|
|
72
|
-
resultSize: JSON.stringify(result).length,
|
|
73
|
-
},
|
|
74
|
-
duration,
|
|
75
|
-
metadata: { toolId: call.id },
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
success: true,
|
|
79
|
-
tool: call.tool,
|
|
80
|
-
result,
|
|
81
|
-
duration,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
const duration = Date.now() - startTime;
|
|
86
|
-
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
87
|
-
executionTracer.trace({
|
|
88
|
-
operationType: 'tool_invocation',
|
|
89
|
-
operationName: call.tool,
|
|
90
|
-
error: errorObj,
|
|
91
|
-
duration,
|
|
92
|
-
metadata: { toolId: call.id },
|
|
93
|
-
});
|
|
94
|
-
return {
|
|
95
|
-
success: false,
|
|
96
|
-
tool: call.tool,
|
|
97
|
-
error: errorObj.message,
|
|
98
|
-
duration,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Execute multiple tool calls in sequence
|
|
104
|
-
* Stops on first error
|
|
105
|
-
*/
|
|
106
|
-
async executeAll(calls) {
|
|
107
|
-
const results = [];
|
|
108
|
-
for (const call of calls) {
|
|
109
|
-
const result = await this.execute(call);
|
|
110
|
-
results.push(result);
|
|
111
|
-
if (!result.success) {
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return results;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Validate parameters against schema
|
|
120
|
-
*/
|
|
121
|
-
function validateParameters(params, schema) {
|
|
122
|
-
if (!schema) {
|
|
123
|
-
return { valid: true, errors: [] };
|
|
124
|
-
}
|
|
125
|
-
const errors = [];
|
|
126
|
-
// Check required parameters
|
|
127
|
-
for (const [key, def] of Object.entries(schema)) {
|
|
128
|
-
if (def.required && !(key in params)) {
|
|
129
|
-
errors.push(`Missing required parameter: ${key}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// Check parameter types
|
|
133
|
-
for (const [key, value] of Object.entries(params)) {
|
|
134
|
-
const def = schema[key];
|
|
135
|
-
if (def) {
|
|
136
|
-
const expectedType = def.type;
|
|
137
|
-
const actualType = typeof value;
|
|
138
|
-
if (expectedType === 'array') {
|
|
139
|
-
if (!Array.isArray(value)) {
|
|
140
|
-
errors.push(`Parameter ${key} must be an array`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else if (expectedType !== actualType && expectedType !== 'any') {
|
|
144
|
-
errors.push(`Parameter ${key} must be of type ${expectedType}, got ${actualType}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
valid: errors.length === 0,
|
|
150
|
-
errors,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
//# sourceMappingURL=executor.js.map
|
package/dist/tools/git-tool.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool: Git Operations
|
|
3
|
-
* Provides Git-Context-Controller functionality
|
|
4
|
-
* Integrates COMMIT, BRANCH, MERGE operations into reasoning loop
|
|
5
|
-
*
|
|
6
|
-
* Based on enterprise architecture: Git semantics in LLM reasoning
|
|
7
|
-
*/
|
|
8
|
-
import { exec } from 'child_process';
|
|
9
|
-
import { promisify } from 'util';
|
|
10
|
-
const execAsync = promisify(exec);
|
|
11
|
-
/**
|
|
12
|
-
* Git Tool - Version Control Operations
|
|
13
|
-
*
|
|
14
|
-
* Available operations:
|
|
15
|
-
* - COMMIT: Create checkpoint of changes
|
|
16
|
-
* - BRANCH: Create/switch branches for exploration
|
|
17
|
-
* - MERGE: Combine branches
|
|
18
|
-
* - DIFF: Get changes between commits/branches
|
|
19
|
-
* - LOG: Query commit history
|
|
20
|
-
* - STATUS: Get current repository state
|
|
21
|
-
*/
|
|
22
|
-
export class GitTool {
|
|
23
|
-
cwd;
|
|
24
|
-
constructor(cwd = process.cwd()) {
|
|
25
|
-
this.cwd = cwd;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* COMMIT: Create checkpoint of current changes
|
|
29
|
-
*/
|
|
30
|
-
async commit(message, files) {
|
|
31
|
-
try {
|
|
32
|
-
// Stage files if specified, otherwise stage all
|
|
33
|
-
if (files && files.length > 0) {
|
|
34
|
-
await execAsync(`git add ${files.join(' ')}`, { cwd: this.cwd });
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
await execAsync('git add -A', { cwd: this.cwd });
|
|
38
|
-
}
|
|
39
|
-
// Create commit
|
|
40
|
-
const { stdout, stderr } = await execAsync(`git commit -m "${message.replace(/"/g, '\\"')}"`, { cwd: this.cwd });
|
|
41
|
-
return {
|
|
42
|
-
success: true,
|
|
43
|
-
output: stdout,
|
|
44
|
-
error: stderr || undefined,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
output: '',
|
|
51
|
-
error: error.message || String(error),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* BRANCH: Create or switch to branch
|
|
57
|
-
*/
|
|
58
|
-
async branch(name, create = false, switchTo = false) {
|
|
59
|
-
try {
|
|
60
|
-
if (create) {
|
|
61
|
-
const { stdout, stderr } = await execAsync(`git branch ${name}`, { cwd: this.cwd });
|
|
62
|
-
return {
|
|
63
|
-
success: true,
|
|
64
|
-
output: stdout,
|
|
65
|
-
error: stderr || undefined,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
if (switchTo) {
|
|
69
|
-
const { stdout, stderr } = await execAsync(`git checkout ${name}`, { cwd: this.cwd });
|
|
70
|
-
return {
|
|
71
|
-
success: true,
|
|
72
|
-
output: stdout,
|
|
73
|
-
error: stderr || undefined,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
// List branches
|
|
77
|
-
const { stdout } = await execAsync('git branch', { cwd: this.cwd });
|
|
78
|
-
return {
|
|
79
|
-
success: true,
|
|
80
|
-
output: stdout,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
return {
|
|
85
|
-
success: false,
|
|
86
|
-
output: '',
|
|
87
|
-
error: error.message || String(error),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* MERGE: Combine branches
|
|
93
|
-
*/
|
|
94
|
-
async merge(branch, strategy = 'merge') {
|
|
95
|
-
try {
|
|
96
|
-
let command;
|
|
97
|
-
if (strategy === 'rebase') {
|
|
98
|
-
command = `git rebase ${branch}`;
|
|
99
|
-
}
|
|
100
|
-
else if (strategy === 'squash') {
|
|
101
|
-
command = `git merge --squash ${branch}`;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
command = `git merge ${branch}`;
|
|
105
|
-
}
|
|
106
|
-
const { stdout, stderr } = await execAsync(command, { cwd: this.cwd });
|
|
107
|
-
return {
|
|
108
|
-
success: true,
|
|
109
|
-
output: stdout,
|
|
110
|
-
error: stderr || undefined,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
return {
|
|
115
|
-
success: false,
|
|
116
|
-
output: '',
|
|
117
|
-
error: error.message || String(error),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* DIFF: Get changes between commits/branches/files
|
|
123
|
-
*/
|
|
124
|
-
async diff(source, target, filepath) {
|
|
125
|
-
try {
|
|
126
|
-
let command = 'git diff';
|
|
127
|
-
if (source && target) {
|
|
128
|
-
command += ` ${source}..${target}`;
|
|
129
|
-
}
|
|
130
|
-
else if (source) {
|
|
131
|
-
command += ` ${source}`;
|
|
132
|
-
}
|
|
133
|
-
if (filepath) {
|
|
134
|
-
command += ` -- ${filepath}`;
|
|
135
|
-
}
|
|
136
|
-
const { stdout } = await execAsync(command, { cwd: this.cwd });
|
|
137
|
-
// Parse diff output
|
|
138
|
-
return this.parseDiff(stdout);
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* LOG: Query commit history
|
|
146
|
-
*/
|
|
147
|
-
async log(limit = 10, filepath) {
|
|
148
|
-
try {
|
|
149
|
-
let command = `git log -n ${limit} --pretty=format:"%H|%s|%an|%ad" --date=iso`;
|
|
150
|
-
if (filepath) {
|
|
151
|
-
command += ` -- ${filepath}`;
|
|
152
|
-
}
|
|
153
|
-
const { stdout } = await execAsync(command, { cwd: this.cwd });
|
|
154
|
-
const lines = stdout.split('\n').filter(l => l.trim());
|
|
155
|
-
return lines.map(line => {
|
|
156
|
-
const [hash, message, author, dateStr] = line.split('|');
|
|
157
|
-
return {
|
|
158
|
-
hash: hash.substring(0, 8),
|
|
159
|
-
message,
|
|
160
|
-
author,
|
|
161
|
-
date: new Date(dateStr),
|
|
162
|
-
files: [], // Would need separate call to get files
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
return [];
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* STATUS: Get current repository state
|
|
172
|
-
*/
|
|
173
|
-
async status() {
|
|
174
|
-
try {
|
|
175
|
-
const { stdout } = await execAsync('git status --porcelain', { cwd: this.cwd });
|
|
176
|
-
const branchOutput = await execAsync('git branch --show-current', { cwd: this.cwd });
|
|
177
|
-
const branch = branchOutput.stdout.trim();
|
|
178
|
-
const modified = [];
|
|
179
|
-
const staged = [];
|
|
180
|
-
const untracked = [];
|
|
181
|
-
stdout.split('\n').forEach(line => {
|
|
182
|
-
if (!line.trim())
|
|
183
|
-
return;
|
|
184
|
-
const status = line.substring(0, 2);
|
|
185
|
-
const filepath = line.substring(3);
|
|
186
|
-
if (status.startsWith('??')) {
|
|
187
|
-
untracked.push(filepath);
|
|
188
|
-
}
|
|
189
|
-
else if (status.startsWith(' ')) {
|
|
190
|
-
modified.push(filepath);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
staged.push(filepath);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
return { branch, modified, staged, untracked };
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
return {
|
|
200
|
-
branch: 'unknown',
|
|
201
|
-
modified: [],
|
|
202
|
-
staged: [],
|
|
203
|
-
untracked: [],
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Check if directory is a Git repository
|
|
209
|
-
*/
|
|
210
|
-
async isRepository() {
|
|
211
|
-
try {
|
|
212
|
-
await execAsync('git rev-parse --git-dir', { cwd: this.cwd });
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
catch {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Parse diff output into structured format
|
|
221
|
-
*/
|
|
222
|
-
parseDiff(diffOutput) {
|
|
223
|
-
const diffs = [];
|
|
224
|
-
const filePattern = /^diff --git a\/(.+?) b\/(.+?)$/gm;
|
|
225
|
-
let currentFile = null;
|
|
226
|
-
let currentDiff = '';
|
|
227
|
-
const lines = diffOutput.split('\n');
|
|
228
|
-
for (let i = 0; i < lines.length; i++) {
|
|
229
|
-
const line = lines[i];
|
|
230
|
-
const fileMatch = line.match(/^diff --git a\/(.+?) b\/(.+?)$/);
|
|
231
|
-
if (fileMatch) {
|
|
232
|
-
if (currentFile) {
|
|
233
|
-
currentFile.diff = currentDiff;
|
|
234
|
-
diffs.push(currentFile);
|
|
235
|
-
}
|
|
236
|
-
currentFile = {
|
|
237
|
-
filepath: fileMatch[1],
|
|
238
|
-
additions: 0,
|
|
239
|
-
deletions: 0,
|
|
240
|
-
diff: '',
|
|
241
|
-
};
|
|
242
|
-
currentDiff = line + '\n';
|
|
243
|
-
}
|
|
244
|
-
else if (currentFile) {
|
|
245
|
-
currentDiff += line + '\n';
|
|
246
|
-
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
247
|
-
currentFile.additions++;
|
|
248
|
-
}
|
|
249
|
-
else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
250
|
-
currentFile.deletions++;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
if (currentFile) {
|
|
255
|
-
currentFile.diff = currentDiff;
|
|
256
|
-
diffs.push(currentFile);
|
|
257
|
-
}
|
|
258
|
-
return diffs;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Tool description for the model
|
|
263
|
-
*/
|
|
264
|
-
export const GIT_TOOL_DESCRIPTION = `
|
|
265
|
-
Git Tool - Version Control Operations (Git-Context-Controller)
|
|
266
|
-
|
|
267
|
-
DESCRIPTION:
|
|
268
|
-
Provides Git operations integrated into the reasoning loop. Enables the agent to
|
|
269
|
-
create checkpoints (COMMIT), explore alternatives (BRANCH), combine changes (MERGE),
|
|
270
|
-
and query history (LOG, DIFF) for structural reasoning about codebase changes.
|
|
271
|
-
|
|
272
|
-
AVAILABLE OPERATIONS:
|
|
273
|
-
- commit(message, files?): Create checkpoint of changes
|
|
274
|
-
- branch(name, create?, switchTo?): Create or switch branches
|
|
275
|
-
- merge(branch, strategy?): Combine branches (merge/rebase/squash)
|
|
276
|
-
- diff(source?, target?, filepath?): Get changes between commits/branches
|
|
277
|
-
- log(limit?, filepath?): Query commit history
|
|
278
|
-
- status(): Get current repository state
|
|
279
|
-
|
|
280
|
-
USE CASES:
|
|
281
|
-
- Before major refactoring: Create branch for exploration
|
|
282
|
-
- After successful changes: COMMIT to create checkpoint
|
|
283
|
-
- When exploring alternatives: Use BRANCH to try different approaches
|
|
284
|
-
- When debugging: Use DIFF to see what changed
|
|
285
|
-
- When planning: Use LOG to understand project history
|
|
286
|
-
|
|
287
|
-
INTEGRATION:
|
|
288
|
-
These operations are integrated into the ReAct reasoning loop, allowing the agent
|
|
289
|
-
to reason about codebase state over time and manage long-horizon tasks with
|
|
290
|
-
version control semantics.
|
|
291
|
-
`;
|
|
292
|
-
//# sourceMappingURL=git-tool.js.map
|