codehere 0.2.2 → 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 +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/parser.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Call Parser
|
|
3
|
-
* Parse tool calls from LLM responses
|
|
4
|
-
* Handles JSON extraction and validation
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Parse tool calls from LLM response
|
|
8
|
-
* Handles various formats:
|
|
9
|
-
* - JSON object: {"tool": "bash", "parameters": {...}}
|
|
10
|
-
* - JSON array: [{"tool": "bash", ...}, ...]
|
|
11
|
-
* - Markdown code blocks: ```json {...} ```
|
|
12
|
-
* - Inline JSON: tool: bash, params: {...}
|
|
13
|
-
*/
|
|
14
|
-
export function parseToolCalls(response) {
|
|
15
|
-
const calls = [];
|
|
16
|
-
// 1. Try to parse the entire response as JSON (Handles Test 1 & 2)
|
|
17
|
-
try {
|
|
18
|
-
const parsed = JSON.parse(response.trim());
|
|
19
|
-
if (Array.isArray(parsed)) {
|
|
20
|
-
parsed.forEach(item => {
|
|
21
|
-
const validated = validateToolCall(item);
|
|
22
|
-
if (validated)
|
|
23
|
-
calls.push(validated);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const validated = validateToolCall(parsed);
|
|
28
|
-
if (validated)
|
|
29
|
-
calls.push(validated);
|
|
30
|
-
}
|
|
31
|
-
if (calls.length > 0)
|
|
32
|
-
return calls;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// Not valid JSON, continue to other methods
|
|
36
|
-
}
|
|
37
|
-
// 2. Try to extract JSON from markdown code blocks (Handles Test 3)
|
|
38
|
-
const codeBlockMatch = response.match(/```(?:json)?\s*(\[[\s\S]*?\]|{[\s\S]*?})\s*```/);
|
|
39
|
-
if (codeBlockMatch) {
|
|
40
|
-
try {
|
|
41
|
-
const parsed = JSON.parse(codeBlockMatch[1]);
|
|
42
|
-
if (Array.isArray(parsed)) {
|
|
43
|
-
parsed.forEach(item => {
|
|
44
|
-
const validated = validateToolCall(item);
|
|
45
|
-
if (validated)
|
|
46
|
-
calls.push(validated);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const validated = validateToolCall(parsed);
|
|
51
|
-
if (validated)
|
|
52
|
-
calls.push(validated);
|
|
53
|
-
}
|
|
54
|
-
return calls;
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
// Fall through to other parsing methods
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// 3. Try to find JSON object/array in response (Fallback)
|
|
61
|
-
const jsonMatch = response.match(/(\[[\s\S]*?\]|{[\s\S]*?})/);
|
|
62
|
-
if (jsonMatch) {
|
|
63
|
-
try {
|
|
64
|
-
const parsed = JSON.parse(jsonMatch[1]);
|
|
65
|
-
if (Array.isArray(parsed)) {
|
|
66
|
-
parsed.forEach(item => {
|
|
67
|
-
const validated = validateToolCall(item);
|
|
68
|
-
if (validated)
|
|
69
|
-
calls.push(validated);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
const validated = validateToolCall(parsed);
|
|
74
|
-
if (validated)
|
|
75
|
-
calls.push(validated);
|
|
76
|
-
}
|
|
77
|
-
// Only return if we actually found valid tool calls
|
|
78
|
-
if (calls.length > 0)
|
|
79
|
-
return calls;
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
// Fall through to other parsing methods
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// 4. Try to parse structured text format (Handles Test 5 - Error Recovery)
|
|
86
|
-
// Format: tool: name, parameters: {...}
|
|
87
|
-
const textMatch = response.match(/tool:\s*(\w+)[\s\S]*?parameters?:\s*({[\s\S]*?})/i);
|
|
88
|
-
if (textMatch) {
|
|
89
|
-
try {
|
|
90
|
-
const toolName = textMatch[1];
|
|
91
|
-
const paramsStr = textMatch[2];
|
|
92
|
-
const parameters = JSON.parse(paramsStr);
|
|
93
|
-
const call = validateToolCall({ tool: toolName, parameters });
|
|
94
|
-
if (call) {
|
|
95
|
-
calls.push(call);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
// Ignore parsing errors
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return calls;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Validate and normalize a tool call
|
|
106
|
-
*/
|
|
107
|
-
function validateToolCall(call) {
|
|
108
|
-
if (!call || typeof call !== 'object') {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
// Check required fields
|
|
112
|
-
if (!call.tool || typeof call.tool !== 'string') {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
// Normalize parameters
|
|
116
|
-
const parameters = call.parameters || call.params || call.args || {};
|
|
117
|
-
if (typeof parameters !== 'object') {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
tool: call.tool.trim().toLowerCase(),
|
|
122
|
-
parameters,
|
|
123
|
-
id: call.id || call.callId || undefined,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Handle partial/malformed responses
|
|
128
|
-
* Attempts to fix common issues
|
|
129
|
-
*/
|
|
130
|
-
export function fixToolCall(response) {
|
|
131
|
-
let fixed = response;
|
|
132
|
-
// Fix common JSON issues
|
|
133
|
-
// 1. Missing quotes around keys
|
|
134
|
-
fixed = fixed.replace(/([{,]\s*)(\w+)(\s*:)/g, '$1"$2"$3');
|
|
135
|
-
// 2. Single quotes instead of double quotes
|
|
136
|
-
fixed = fixed.replace(/'/g, '"');
|
|
137
|
-
// 3. Trailing commas
|
|
138
|
-
fixed = fixed.replace(/,(\s*[}\]])/g, '$1');
|
|
139
|
-
// 4. Comments in JSON
|
|
140
|
-
fixed = fixed.replace(/\/\/.*$/gm, '');
|
|
141
|
-
fixed = fixed.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
142
|
-
return fixed;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Extract tool calls with error recovery
|
|
146
|
-
* Tries multiple parsing strategies
|
|
147
|
-
*/
|
|
148
|
-
export function extractToolCalls(response) {
|
|
149
|
-
// Try normal parsing first
|
|
150
|
-
let calls = parseToolCalls(response);
|
|
151
|
-
// If no calls found, try fixing common issues
|
|
152
|
-
if (calls.length === 0) {
|
|
153
|
-
const fixed = fixToolCall(response);
|
|
154
|
-
calls = parseToolCalls(fixed);
|
|
155
|
-
}
|
|
156
|
-
return calls;
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=parser.js.map
|
package/dist/tools/registry.js
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Registry
|
|
3
|
-
* Central registry for all available tools
|
|
4
|
-
* Provides tool lookup and description access
|
|
5
|
-
*/
|
|
6
|
-
import { executeBash, BASH_TOOL_DESCRIPTION } from './bash.js';
|
|
7
|
-
import { viewFile, createFile, strReplace, undoEdit, EDIT_TOOL_DESCRIPTION } from './edit.js';
|
|
8
|
-
import { searchCodebase, SEARCH_TOOL_DESCRIPTION } from './search.js';
|
|
9
|
-
import { GitTool, GIT_TOOL_DESCRIPTION } from './git-tool.js';
|
|
10
|
-
/**
|
|
11
|
-
* Tool Registry
|
|
12
|
-
* Singleton registry for all tools
|
|
13
|
-
*/
|
|
14
|
-
export class ToolRegistry {
|
|
15
|
-
tools = new Map();
|
|
16
|
-
constructor() {
|
|
17
|
-
this.registerAllTools();
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Register all available tools
|
|
21
|
-
*/
|
|
22
|
-
registerAllTools() {
|
|
23
|
-
// Bash Tool
|
|
24
|
-
this.register({
|
|
25
|
-
name: 'bash',
|
|
26
|
-
description: 'Execute shell commands safely',
|
|
27
|
-
modelDescription: BASH_TOOL_DESCRIPTION,
|
|
28
|
-
execute: async (command, options) => {
|
|
29
|
-
return await executeBash(command, options);
|
|
30
|
-
},
|
|
31
|
-
parameters: {
|
|
32
|
-
command: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
required: true,
|
|
35
|
-
description: 'Shell command to execute',
|
|
36
|
-
},
|
|
37
|
-
options: {
|
|
38
|
-
type: 'object',
|
|
39
|
-
required: false,
|
|
40
|
-
description: 'Bash options (cwd, timeout, maxOutputSize, env)',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
// Edit Tool - view
|
|
45
|
-
this.register({
|
|
46
|
-
name: 'edit_view',
|
|
47
|
-
description: 'View file content',
|
|
48
|
-
modelDescription: EDIT_TOOL_DESCRIPTION,
|
|
49
|
-
execute: async (filepath, options) => {
|
|
50
|
-
return viewFile(filepath, options);
|
|
51
|
-
},
|
|
52
|
-
parameters: {
|
|
53
|
-
filepath: {
|
|
54
|
-
type: 'string',
|
|
55
|
-
required: true,
|
|
56
|
-
description: 'File path to view',
|
|
57
|
-
},
|
|
58
|
-
options: {
|
|
59
|
-
type: 'object',
|
|
60
|
-
required: false,
|
|
61
|
-
description: 'Edit options (cwd, createIfNotExists)',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
// Edit Tool - create
|
|
66
|
-
this.register({
|
|
67
|
-
name: 'edit_create',
|
|
68
|
-
description: 'Create a new file',
|
|
69
|
-
modelDescription: EDIT_TOOL_DESCRIPTION,
|
|
70
|
-
execute: async (filepath, content, options) => {
|
|
71
|
-
return createFile(filepath, content, options);
|
|
72
|
-
},
|
|
73
|
-
parameters: {
|
|
74
|
-
filepath: {
|
|
75
|
-
type: 'string',
|
|
76
|
-
required: true,
|
|
77
|
-
description: 'File path to create',
|
|
78
|
-
},
|
|
79
|
-
content: {
|
|
80
|
-
type: 'string',
|
|
81
|
-
required: true,
|
|
82
|
-
description: 'File content',
|
|
83
|
-
},
|
|
84
|
-
options: {
|
|
85
|
-
type: 'object',
|
|
86
|
-
required: false,
|
|
87
|
-
description: 'Edit options (cwd, createIfNotExists)',
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
// Edit Tool - str_replace
|
|
92
|
-
this.register({
|
|
93
|
-
name: 'edit_replace',
|
|
94
|
-
description: 'Replace string in file (exact match required)',
|
|
95
|
-
modelDescription: EDIT_TOOL_DESCRIPTION,
|
|
96
|
-
execute: async (filepath, oldString, newString, options) => {
|
|
97
|
-
return strReplace(filepath, oldString, newString, options);
|
|
98
|
-
},
|
|
99
|
-
parameters: {
|
|
100
|
-
filepath: {
|
|
101
|
-
type: 'string',
|
|
102
|
-
required: true,
|
|
103
|
-
description: 'File path to edit',
|
|
104
|
-
},
|
|
105
|
-
oldString: {
|
|
106
|
-
type: 'string',
|
|
107
|
-
required: true,
|
|
108
|
-
description: 'String to replace (must match exactly)',
|
|
109
|
-
},
|
|
110
|
-
newString: {
|
|
111
|
-
type: 'string',
|
|
112
|
-
required: true,
|
|
113
|
-
description: 'Replacement string',
|
|
114
|
-
},
|
|
115
|
-
options: {
|
|
116
|
-
type: 'object',
|
|
117
|
-
required: false,
|
|
118
|
-
description: 'Edit options (cwd)',
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
// Edit Tool - undo
|
|
123
|
-
this.register({
|
|
124
|
-
name: 'edit_undo',
|
|
125
|
-
description: 'Undo last edit',
|
|
126
|
-
modelDescription: EDIT_TOOL_DESCRIPTION,
|
|
127
|
-
execute: async (filepath, options) => {
|
|
128
|
-
return undoEdit(filepath, options);
|
|
129
|
-
},
|
|
130
|
-
parameters: {
|
|
131
|
-
filepath: {
|
|
132
|
-
type: 'string',
|
|
133
|
-
required: true,
|
|
134
|
-
description: 'File path to undo',
|
|
135
|
-
},
|
|
136
|
-
options: {
|
|
137
|
-
type: 'object',
|
|
138
|
-
required: false,
|
|
139
|
-
description: 'Edit options (cwd)',
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
// Search Tool
|
|
144
|
-
this.register({
|
|
145
|
-
name: 'search',
|
|
146
|
-
description: 'Search codebase using intelligent retrieval',
|
|
147
|
-
modelDescription: SEARCH_TOOL_DESCRIPTION,
|
|
148
|
-
execute: async (query, options) => {
|
|
149
|
-
return await searchCodebase(query, options);
|
|
150
|
-
},
|
|
151
|
-
parameters: {
|
|
152
|
-
query: {
|
|
153
|
-
type: 'string',
|
|
154
|
-
required: true,
|
|
155
|
-
description: 'Search query',
|
|
156
|
-
},
|
|
157
|
-
options: {
|
|
158
|
-
type: 'object',
|
|
159
|
-
required: false,
|
|
160
|
-
description: 'Search options (baseDir, maxResults, fileTypes, minScore)',
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
// Git Tool
|
|
165
|
-
this.register({
|
|
166
|
-
name: 'git',
|
|
167
|
-
description: 'Git version control operations (COMMIT, BRANCH, MERGE, DIFF, LOG)',
|
|
168
|
-
modelDescription: GIT_TOOL_DESCRIPTION,
|
|
169
|
-
execute: async (operation, params) => {
|
|
170
|
-
const gitTool = new GitTool();
|
|
171
|
-
switch (operation.toLowerCase()) {
|
|
172
|
-
case 'commit':
|
|
173
|
-
return await gitTool.commit(params?.message || 'Codehere commit', params?.files);
|
|
174
|
-
case 'branch':
|
|
175
|
-
return await gitTool.branch(params?.branch || 'main', params?.create || false, params?.switchTo || false);
|
|
176
|
-
case 'merge':
|
|
177
|
-
return await gitTool.merge(params?.branch || 'main', params?.strategy || 'merge');
|
|
178
|
-
case 'diff':
|
|
179
|
-
return await gitTool.diff(params?.source, params?.target, params?.filepath);
|
|
180
|
-
case 'log':
|
|
181
|
-
return await gitTool.log(params?.limit || 10, params?.filepath);
|
|
182
|
-
case 'status':
|
|
183
|
-
return await gitTool.status();
|
|
184
|
-
default:
|
|
185
|
-
return {
|
|
186
|
-
success: false,
|
|
187
|
-
output: '',
|
|
188
|
-
error: `Unknown git operation: ${operation}`,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
parameters: {
|
|
193
|
-
operation: {
|
|
194
|
-
type: 'string',
|
|
195
|
-
required: true,
|
|
196
|
-
description: 'Git operation: commit, branch, merge, diff, log, status',
|
|
197
|
-
},
|
|
198
|
-
message: {
|
|
199
|
-
type: 'string',
|
|
200
|
-
required: false,
|
|
201
|
-
description: 'Commit message (for commit operation)',
|
|
202
|
-
},
|
|
203
|
-
branch: {
|
|
204
|
-
type: 'string',
|
|
205
|
-
required: false,
|
|
206
|
-
description: 'Branch name (for branch/merge operations)',
|
|
207
|
-
},
|
|
208
|
-
files: {
|
|
209
|
-
type: 'array',
|
|
210
|
-
required: false,
|
|
211
|
-
description: 'File paths (for commit operation)',
|
|
212
|
-
},
|
|
213
|
-
source: {
|
|
214
|
-
type: 'string',
|
|
215
|
-
required: false,
|
|
216
|
-
description: 'Source commit/branch (for diff operation)',
|
|
217
|
-
},
|
|
218
|
-
target: {
|
|
219
|
-
type: 'string',
|
|
220
|
-
required: false,
|
|
221
|
-
description: 'Target commit/branch (for diff operation)',
|
|
222
|
-
},
|
|
223
|
-
limit: {
|
|
224
|
-
type: 'number',
|
|
225
|
-
required: false,
|
|
226
|
-
description: 'Number of commits to return (for log operation)',
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Register a tool
|
|
233
|
-
*/
|
|
234
|
-
register(tool) {
|
|
235
|
-
if (this.tools.has(tool.name)) {
|
|
236
|
-
throw new Error(`Tool "${tool.name}" is already registered`);
|
|
237
|
-
}
|
|
238
|
-
this.tools.set(tool.name, tool);
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Get a tool by name
|
|
242
|
-
*/
|
|
243
|
-
get(name) {
|
|
244
|
-
return this.tools.get(name);
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Get all tools
|
|
248
|
-
*/
|
|
249
|
-
getAll() {
|
|
250
|
-
return Array.from(this.tools.values());
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Get all tool names
|
|
254
|
-
*/
|
|
255
|
-
getNames() {
|
|
256
|
-
return Array.from(this.tools.keys());
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Check if a tool exists
|
|
260
|
-
*/
|
|
261
|
-
has(name) {
|
|
262
|
-
return this.tools.has(name);
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Get tool descriptions for the model
|
|
266
|
-
* Returns formatted string with all tool descriptions
|
|
267
|
-
*/
|
|
268
|
-
getModelDescriptions() {
|
|
269
|
-
const tools = this.getAll();
|
|
270
|
-
return tools.map(tool => {
|
|
271
|
-
return `## ${tool.name}\n${tool.modelDescription}`;
|
|
272
|
-
}).join('\n\n---\n\n');
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Get tool list summary for the model
|
|
276
|
-
* Returns compact list of available tools
|
|
277
|
-
*/
|
|
278
|
-
getToolList() {
|
|
279
|
-
const tools = this.getAll();
|
|
280
|
-
return tools.map(tool => {
|
|
281
|
-
return `- ${tool.name}: ${tool.description}`;
|
|
282
|
-
}).join('\n');
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
// Singleton instance
|
|
286
|
-
let registryInstance = null;
|
|
287
|
-
/**
|
|
288
|
-
* Get the global tool registry instance
|
|
289
|
-
*/
|
|
290
|
-
export function getToolRegistry() {
|
|
291
|
-
if (!registryInstance) {
|
|
292
|
-
registryInstance = new ToolRegistry();
|
|
293
|
-
}
|
|
294
|
-
return registryInstance;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Reset the registry (for testing)
|
|
298
|
-
*/
|
|
299
|
-
export function resetToolRegistry() {
|
|
300
|
-
registryInstance = null;
|
|
301
|
-
}
|
|
302
|
-
//# sourceMappingURL=registry.js.map
|
package/dist/tools/search.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Search Tool
|
|
3
|
-
* Leverages our intelligent retrieval (competitive advantage)
|
|
4
|
-
* Provides semantic codebase search with AST-based context
|
|
5
|
-
*/
|
|
6
|
-
import { searchIntelligent } from '../search.js';
|
|
7
|
-
/**
|
|
8
|
-
* Search codebase using intelligent retrieval
|
|
9
|
-
*
|
|
10
|
-
* This is our competitive advantage - uses AST-based context retrieval
|
|
11
|
-
* instead of naive cosine similarity
|
|
12
|
-
*/
|
|
13
|
-
export async function searchCodebase(query, options = {}) {
|
|
14
|
-
try {
|
|
15
|
-
const result = await searchIntelligent(query, {
|
|
16
|
-
baseDir: options.baseDir || process.cwd(),
|
|
17
|
-
maxTokens: 2000, // Default token limit
|
|
18
|
-
});
|
|
19
|
-
// Filter results by maxResults if specified
|
|
20
|
-
let chunks = result.chunks;
|
|
21
|
-
if (options.maxResults) {
|
|
22
|
-
chunks = chunks.slice(0, options.maxResults);
|
|
23
|
-
}
|
|
24
|
-
// Apply file type filter if specified
|
|
25
|
-
if (options.fileTypes && options.fileTypes.length > 0) {
|
|
26
|
-
chunks = chunks.filter(chunk => {
|
|
27
|
-
const ext = chunk.filepath.split('.').pop()?.toLowerCase();
|
|
28
|
-
return ext && options.fileTypes.includes(ext);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
// Apply min score filter if specified
|
|
32
|
-
if (options.minScore) {
|
|
33
|
-
chunks = chunks.filter(chunk => chunk.score >= options.minScore);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
success: true,
|
|
37
|
-
results: chunks,
|
|
38
|
-
totalChunks: chunks.length,
|
|
39
|
-
reductionPercent: result.reductionPercent,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
return {
|
|
44
|
-
success: false,
|
|
45
|
-
results: [],
|
|
46
|
-
totalChunks: 0,
|
|
47
|
-
reductionPercent: 0,
|
|
48
|
-
error: error instanceof Error ? error.message : String(error),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Tool description for the model
|
|
54
|
-
* This highlights our competitive advantage
|
|
55
|
-
*/
|
|
56
|
-
export const SEARCH_TOOL_DESCRIPTION = `
|
|
57
|
-
Search Tool - Intelligent codebase search (Our Competitive Advantage)
|
|
58
|
-
|
|
59
|
-
DESCRIPTION:
|
|
60
|
-
Search codebase using intelligent retrieval with AST-based context understanding.
|
|
61
|
-
This is more powerful than naive cosine similarity - understands code structure.
|
|
62
|
-
|
|
63
|
-
AVAILABLE OPERATIONS:
|
|
64
|
-
- searchCodebase(query, options): Search codebase with intelligent retrieval
|
|
65
|
-
|
|
66
|
-
FEATURES (Our Competitive Advantage):
|
|
67
|
-
1. **AST-Based Context**: Understands code structure, not just text similarity
|
|
68
|
-
2. **Caller/Callee Analysis**: Finds related functions automatically
|
|
69
|
-
3. **Type-Aware Search**: Understands TypeScript/JavaScript types
|
|
70
|
-
4. **Token Optimization**: Reduces context size by 80-90% while maintaining relevance
|
|
71
|
-
5. **Intelligent Chunking**: Chunks code semantically, not just by size
|
|
72
|
-
|
|
73
|
-
SEARCH OPTIONS:
|
|
74
|
-
- baseDir: Base directory (default: current directory)
|
|
75
|
-
- maxResults: Maximum results (default: 15)
|
|
76
|
-
- fileTypes: Filter by file types (e.g., ['ts', 'tsx'])
|
|
77
|
-
- minScore: Minimum relevance score 0-1 (default: 0.3)
|
|
78
|
-
|
|
79
|
-
RETURNS:
|
|
80
|
-
- results: Array of code chunks with metadata
|
|
81
|
-
- Each chunk includes: filepath, content, score, metadata
|
|
82
|
-
- reductionPercent: Token reduction achieved (typically 80-90%)
|
|
83
|
-
|
|
84
|
-
EXAMPLES:
|
|
85
|
-
- searchCodebase('How does authentication work?')
|
|
86
|
-
- searchCodebase('Find all API endpoints', { fileTypes: ['ts'] })
|
|
87
|
-
- searchCodebase('Where is user validation?', { maxResults: 10 })
|
|
88
|
-
|
|
89
|
-
ADVANTAGES OVER NAIVE SEARCH:
|
|
90
|
-
1. **Semantic Understanding**: Understands code meaning, not just keywords
|
|
91
|
-
2. **Context-Aware**: Includes related functions, types, imports
|
|
92
|
-
3. **Efficient**: 80-90% token reduction while maintaining accuracy
|
|
93
|
-
4. **Accurate**: AST-based matching is more precise than text similarity
|
|
94
|
-
|
|
95
|
-
REQUIREMENTS:
|
|
96
|
-
- Codebase must be indexed first (run 'codehere index')
|
|
97
|
-
- Indexing creates embeddings and AST analysis
|
|
98
|
-
- Search uses both embeddings and AST for best results
|
|
99
|
-
`;
|
|
100
|
-
//# sourceMappingURL=search.js.map
|
package/dist/types.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility: Check API Status
|
|
3
|
-
* Checks if any AI provider API is available
|
|
4
|
-
*/
|
|
5
|
-
import { config } from 'dotenv';
|
|
6
|
-
import { join, dirname } from 'path';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = dirname(__filename);
|
|
10
|
-
// Load .env
|
|
11
|
-
try {
|
|
12
|
-
const agentDir = join(__dirname, '../../..');
|
|
13
|
-
config({ path: join(agentDir, '.env') });
|
|
14
|
-
}
|
|
15
|
-
catch { }
|
|
16
|
-
config();
|
|
17
|
-
export async function checkAPIStatus() {
|
|
18
|
-
const hasKey = !!(process.env.ANTHROPIC_API_KEY || process.env.OPENAI_API_KEY || process.env.COHERE_API_KEY);
|
|
19
|
-
if (!hasKey) {
|
|
20
|
-
return {
|
|
21
|
-
available: false,
|
|
22
|
-
rateLimited: false,
|
|
23
|
-
message: 'No API key found (ANTHROPIC_API_KEY, OPENAI_API_KEY, or COHERE_API_KEY)',
|
|
24
|
-
canProceed: false,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
// Quick health check with whichever provider is available
|
|
29
|
-
if (process.env.ANTHROPIC_API_KEY) {
|
|
30
|
-
const r = await fetch('https://api.anthropic.com/v1/messages', {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
headers: { 'x-api-key': process.env.ANTHROPIC_API_KEY, 'anthropic-version': '2023-06-01', 'content-type': 'application/json' },
|
|
33
|
-
body: JSON.stringify({ model: 'claude-sonnet-4-20250514', max_tokens: 1, messages: [{ role: 'user', content: 'hi' }] }),
|
|
34
|
-
});
|
|
35
|
-
if (!r.ok && r.status === 429)
|
|
36
|
-
throw Object.assign(new Error('Rate limited'), { status: 429 });
|
|
37
|
-
if (!r.ok)
|
|
38
|
-
throw new Error(`Anthropic API error: ${r.status}`);
|
|
39
|
-
}
|
|
40
|
-
else if (process.env.OPENAI_API_KEY) {
|
|
41
|
-
const r = await fetch('https://api.openai.com/v1/models', {
|
|
42
|
-
headers: { 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` },
|
|
43
|
-
});
|
|
44
|
-
if (!r.ok && r.status === 429)
|
|
45
|
-
throw Object.assign(new Error('Rate limited'), { status: 429 });
|
|
46
|
-
if (!r.ok)
|
|
47
|
-
throw new Error(`OpenAI API error: ${r.status}`);
|
|
48
|
-
}
|
|
49
|
-
else if (process.env.COHERE_API_KEY) {
|
|
50
|
-
const { CohereClient } = require('cohere-ai');
|
|
51
|
-
const client = new CohereClient({ token: process.env.COHERE_API_KEY });
|
|
52
|
-
await client.embed({ texts: ['test'], model: 'embed-english-v3.0', inputType: 'search_document' });
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
available: true,
|
|
56
|
-
rateLimited: false,
|
|
57
|
-
message: 'API is available and ready',
|
|
58
|
-
canProceed: true,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
const errorMsg = error?.message || String(error);
|
|
63
|
-
const statusCode = error?.status || error?.statusCode;
|
|
64
|
-
// Check for rate limiting
|
|
65
|
-
const isRateLimit = statusCode === 429 ||
|
|
66
|
-
errorMsg.includes('429') ||
|
|
67
|
-
errorMsg.includes('rate limit') ||
|
|
68
|
-
errorMsg.includes('TooManyRequests') ||
|
|
69
|
-
errorMsg.includes('1000 API calls');
|
|
70
|
-
if (isRateLimit) {
|
|
71
|
-
return {
|
|
72
|
-
available: false,
|
|
73
|
-
rateLimited: true,
|
|
74
|
-
message: 'API rate limit reached. Trial key limited to 1000 calls/month.',
|
|
75
|
-
canProceed: false,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
// Other error (network, auth, etc.)
|
|
79
|
-
return {
|
|
80
|
-
available: false,
|
|
81
|
-
rateLimited: false,
|
|
82
|
-
message: `API error: ${errorMsg.substring(0, 100)}`,
|
|
83
|
-
canProceed: false,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// CLI usage
|
|
88
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
89
|
-
checkAPIStatus().then(status => {
|
|
90
|
-
if (status.canProceed) {
|
|
91
|
-
console.log('✅', status.message);
|
|
92
|
-
process.exit(0);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
console.log('❌', status.message);
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=check-api-status.js.map
|