erosolar-cli 1.7.55 → 1.7.57
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/dist/shell/unifiedInputProcessor.d.ts +15 -12
- package/dist/shell/unifiedInputProcessor.d.ts.map +1 -1
- package/dist/shell/unifiedInputProcessor.js +45 -72
- package/dist/shell/unifiedInputProcessor.js.map +1 -1
- package/package.json +4 -4
- package/dist/active-stack-security.d.ts +0 -110
- package/dist/active-stack-security.js +0 -313
- package/dist/active-stack-security.js.map +0 -1
- package/dist/advanced-targeting.d.ts +0 -113
- package/dist/advanced-targeting.js +0 -252
- package/dist/advanced-targeting.js.map +0 -1
- package/dist/bin/adapters/node/index.js +0 -33
- package/dist/bin/adapters/types.js +0 -1
- package/dist/bin/alpha-zero/agentWrapper.js +0 -165
- package/dist/bin/alpha-zero/codeEvaluator.js +0 -272
- package/dist/bin/alpha-zero/competitiveRunner.js +0 -219
- package/dist/bin/alpha-zero/index.js +0 -98
- package/dist/bin/alpha-zero/introspection.js +0 -298
- package/dist/bin/alpha-zero/metricsTracker.js +0 -207
- package/dist/bin/alpha-zero/security/core.js +0 -269
- package/dist/bin/alpha-zero/security/google.js +0 -308
- package/dist/bin/alpha-zero/security/googleLoader.js +0 -40
- package/dist/bin/alpha-zero/security/index.js +0 -31
- package/dist/bin/alpha-zero/security/simulation.js +0 -274
- package/dist/bin/alpha-zero/selfModification.js +0 -231
- package/dist/bin/alpha-zero/types.js +0 -30
- package/dist/bin/bin/erosolar-optimized.js +0 -205
- package/dist/bin/capabilities/agentSpawningCapability.js +0 -116
- package/dist/bin/capabilities/bashCapability.js +0 -22
- package/dist/bin/capabilities/cloudCapability.js +0 -36
- package/dist/bin/capabilities/codeAnalysisCapability.js +0 -22
- package/dist/bin/capabilities/codeQualityCapability.js +0 -23
- package/dist/bin/capabilities/dependencySecurityCapability.js +0 -22
- package/dist/bin/capabilities/devCapability.js +0 -22
- package/dist/bin/capabilities/editCapability.js +0 -28
- package/dist/bin/capabilities/emailCapability.js +0 -20
- package/dist/bin/capabilities/enhancedGitCapability.js +0 -221
- package/dist/bin/capabilities/filesystemCapability.js +0 -22
- package/dist/bin/capabilities/globCapability.js +0 -28
- package/dist/bin/capabilities/interactionCapability.js +0 -20
- package/dist/bin/capabilities/learnCapability.js +0 -22
- package/dist/bin/capabilities/mcpCapability.js +0 -20
- package/dist/bin/capabilities/notebookCapability.js +0 -28
- package/dist/bin/capabilities/planningCapability.js +0 -27
- package/dist/bin/capabilities/refactoringCapability.js +0 -23
- package/dist/bin/capabilities/repoChecksCapability.js +0 -22
- package/dist/bin/capabilities/searchCapability.js +0 -22
- package/dist/bin/capabilities/skillCapability.js +0 -76
- package/dist/bin/capabilities/taskManagementCapability.js +0 -20
- package/dist/bin/capabilities/testingCapability.js +0 -23
- package/dist/bin/capabilities/toolManifest.js +0 -159
- package/dist/bin/capabilities/toolRegistry.js +0 -114
- package/dist/bin/capabilities/webCapability.js +0 -20
- package/dist/bin/config.js +0 -139
- package/dist/bin/contracts/v1/agent.js +0 -7
- package/dist/bin/contracts/v1/agentProfileManifest.js +0 -8
- package/dist/bin/contracts/v1/agentRules.js +0 -9
- package/dist/bin/contracts/v1/toolAccess.js +0 -8
- package/dist/bin/erosolar-optimized.d.ts +0 -12
- package/dist/bin/erosolar-optimized.d.ts.map +0 -1
- package/dist/bin/erosolar-optimized.js +0 -239
- package/dist/bin/erosolar-optimized.js.map +0 -1
- package/dist/bin/headless/headlessApp.js +0 -172
- package/dist/bin/mcp/config.js +0 -202
- package/dist/bin/mcp/stdioClient.js +0 -172
- package/dist/bin/mcp/toolBridge.js +0 -104
- package/dist/bin/mcp/types.js +0 -1
- package/dist/bin/plugins/index.js +0 -113
- package/dist/bin/plugins/providers/anthropic/index.js +0 -25
- package/dist/bin/plugins/providers/deepseek/index.js +0 -24
- package/dist/bin/plugins/providers/google/index.js +0 -26
- package/dist/bin/plugins/providers/index.js +0 -19
- package/dist/bin/plugins/providers/ollama/index.js +0 -59
- package/dist/bin/plugins/providers/openai/index.js +0 -26
- package/dist/bin/plugins/providers/xai/index.js +0 -24
- package/dist/bin/plugins/tools/agentSpawning/agentSpawningPlugin.js +0 -8
- package/dist/bin/plugins/tools/bash/localBashPlugin.js +0 -13
- package/dist/bin/plugins/tools/checks/localRepoChecksPlugin.js +0 -13
- package/dist/bin/plugins/tools/cloud/cloudPlugin.js +0 -13
- package/dist/bin/plugins/tools/codeAnalysis/codeAnalysisPlugin.js +0 -13
- package/dist/bin/plugins/tools/codeQuality/codeQualityPlugin.js +0 -13
- package/dist/bin/plugins/tools/dependency/dependencyPlugin.js +0 -11
- package/dist/bin/plugins/tools/development/devPlugin.js +0 -13
- package/dist/bin/plugins/tools/edit/editPlugin.js +0 -14
- package/dist/bin/plugins/tools/email/emailPlugin.js +0 -11
- package/dist/bin/plugins/tools/enhancedGit/enhancedGitPlugin.js +0 -8
- package/dist/bin/plugins/tools/filesystem/localFilesystemPlugin.js +0 -13
- package/dist/bin/plugins/tools/glob/globPlugin.js +0 -14
- package/dist/bin/plugins/tools/index.js +0 -2
- package/dist/bin/plugins/tools/interaction/interactionPlugin.js +0 -11
- package/dist/bin/plugins/tools/learn/learnPlugin.js +0 -13
- package/dist/bin/plugins/tools/mcp/mcpPlugin.js +0 -8
- package/dist/bin/plugins/tools/nodeDefaults.js +0 -56
- package/dist/bin/plugins/tools/notebook/notebookPlugin.js +0 -14
- package/dist/bin/plugins/tools/planning/planningPlugin.js +0 -14
- package/dist/bin/plugins/tools/refactoring/refactoringPlugin.js +0 -11
- package/dist/bin/plugins/tools/registry.js +0 -57
- package/dist/bin/plugins/tools/search/localSearchPlugin.js +0 -13
- package/dist/bin/plugins/tools/skills/skillPlugin.js +0 -8
- package/dist/bin/plugins/tools/taskManagement/taskManagementPlugin.js +0 -11
- package/dist/bin/plugins/tools/testing/testingPlugin.js +0 -11
- package/dist/bin/plugins/tools/web/webPlugin.js +0 -11
- package/dist/bin/providers/anthropicProvider.js +0 -329
- package/dist/bin/providers/googleProvider.js +0 -203
- package/dist/bin/providers/openaiChatCompletionsProvider.js +0 -208
- package/dist/bin/providers/openaiResponsesProvider.js +0 -249
- package/dist/bin/providers/providerFactory.js +0 -24
- package/dist/bin/runtime/agentController.js +0 -321
- package/dist/bin/runtime/agentHost.js +0 -153
- package/dist/bin/runtime/agentSession.js +0 -195
- package/dist/bin/runtime/node.js +0 -10
- package/dist/bin/runtime/universal.js +0 -28
- package/dist/bin/skills/skillRepository.js +0 -236
- package/dist/bin/skills/types.js +0 -1
- package/dist/bin/subagents/taskRunner.js +0 -269
- package/dist/bin/tools/backgroundBashTools.js +0 -211
- package/dist/bin/tools/bashTools.js +0 -159
- package/dist/bin/tools/cloudTools.js +0 -864
- package/dist/bin/tools/codeAnalysisTools.js +0 -641
- package/dist/bin/tools/codeQualityTools.js +0 -294
- package/dist/bin/tools/dependencyTools.js +0 -282
- package/dist/bin/tools/devTools.js +0 -238
- package/dist/bin/tools/diffUtils.js +0 -137
- package/dist/bin/tools/editTools.js +0 -134
- package/dist/bin/tools/emailTools.js +0 -448
- package/dist/bin/tools/fileTools.js +0 -282
- package/dist/bin/tools/globTools.js +0 -173
- package/dist/bin/tools/grepTools.js +0 -332
- package/dist/bin/tools/interactionTools.js +0 -170
- package/dist/bin/tools/learnTools.js +0 -1818
- package/dist/bin/tools/notebookEditTools.js +0 -196
- package/dist/bin/tools/planningTools.js +0 -46
- package/dist/bin/tools/refactoringTools.js +0 -293
- package/dist/bin/tools/repoChecksTools.js +0 -160
- package/dist/bin/tools/searchTools.js +0 -206
- package/dist/bin/tools/skillTools.js +0 -177
- package/dist/bin/tools/taskManagementTools.js +0 -156
- package/dist/bin/tools/testingTools.js +0 -232
- package/dist/bin/tools/webTools.js +0 -480
- package/dist/bin/workspace.js +0 -106
- package/dist/bin/workspace.validator.js +0 -213
- package/dist/capabilities/offensiveSecurityCapability.d.ts +0 -26
- package/dist/capabilities/offensiveSecurityCapability.d.ts.map +0 -1
- package/dist/capabilities/offensiveSecurityCapability.js +0 -58
- package/dist/capabilities/offensiveSecurityCapability.js.map +0 -1
- package/dist/capabilities/realSecurityCapability.d.ts +0 -26
- package/dist/capabilities/realSecurityCapability.d.ts.map +0 -1
- package/dist/capabilities/realSecurityCapability.js +0 -53
- package/dist/capabilities/realSecurityCapability.js.map +0 -1
- package/dist/capabilities/securityCapability.d.ts +0 -32
- package/dist/capabilities/securityCapability.d.ts.map +0 -1
- package/dist/capabilities/securityCapability.js +0 -57
- package/dist/capabilities/securityCapability.js.map +0 -1
- package/dist/capabilities/ultimateSecurityCapability.d.ts +0 -42
- package/dist/capabilities/ultimateSecurityCapability.d.ts.map +0 -1
- package/dist/capabilities/ultimateSecurityCapability.js +0 -96
- package/dist/capabilities/ultimateSecurityCapability.js.map +0 -1
- package/dist/core/designThoughtCheck.d.ts +0 -196
- package/dist/core/designThoughtCheck.d.ts.map +0 -1
- package/dist/core/designThoughtCheck.js +0 -287
- package/dist/core/designThoughtCheck.js.map +0 -1
- package/dist/core/designThoughtCheckEngine.d.ts +0 -58
- package/dist/core/designThoughtCheckEngine.d.ts.map +0 -1
- package/dist/core/designThoughtCheckEngine.js +0 -358
- package/dist/core/designThoughtCheckEngine.js.map +0 -1
- package/dist/core/designThoughtCheckIntegration.d.ts +0 -103
- package/dist/core/designThoughtCheckIntegration.d.ts.map +0 -1
- package/dist/core/designThoughtCheckIntegration.js +0 -207
- package/dist/core/designThoughtCheckIntegration.js.map +0 -1
- package/dist/core/intelligenceTools.d.ts +0 -19
- package/dist/core/intelligenceTools.d.ts.map +0 -1
- package/dist/core/intelligenceTools.js +0 -453
- package/dist/core/intelligenceTools.js.map +0 -1
- package/dist/core/operationalTools.d.ts +0 -19
- package/dist/core/operationalTools.d.ts.map +0 -1
- package/dist/core/operationalTools.js +0 -467
- package/dist/core/operationalTools.js.map +0 -1
- package/dist/offensive/core/offensive-engine.d.ts +0 -171
- package/dist/offensive/core/offensive-engine.d.ts.map +0 -1
- package/dist/offensive/core/offensive-engine.js +0 -345
- package/dist/offensive/core/offensive-engine.js.map +0 -1
- package/dist/offensive/core/offensive-integration.d.ts +0 -129
- package/dist/offensive/core/offensive-integration.d.ts.map +0 -1
- package/dist/offensive/core/offensive-integration.js +0 -364
- package/dist/offensive/core/offensive-integration.js.map +0 -1
- package/dist/offensive/core/offensive-tools.d.ts +0 -55
- package/dist/offensive/core/offensive-tools.d.ts.map +0 -1
- package/dist/offensive/core/offensive-tools.js +0 -438
- package/dist/offensive/core/offensive-tools.js.map +0 -1
- package/dist/offensive/offensive-cli.d.ts +0 -48
- package/dist/offensive/offensive-cli.d.ts.map +0 -1
- package/dist/offensive/offensive-cli.js +0 -233
- package/dist/offensive/offensive-cli.js.map +0 -1
- package/dist/security/apt-simulation-cli.d.ts +0 -57
- package/dist/security/apt-simulation-cli.d.ts.map +0 -1
- package/dist/security/apt-simulation-cli.js +0 -278
- package/dist/security/apt-simulation-cli.js.map +0 -1
- package/dist/security/apt-simulation-engine-complete.d.ts +0 -97
- package/dist/security/apt-simulation-engine-complete.d.ts.map +0 -1
- package/dist/security/apt-simulation-engine-complete.js +0 -441
- package/dist/security/apt-simulation-engine-complete.js.map +0 -1
- package/dist/security/apt-simulation-engine.d.ts +0 -97
- package/dist/security/apt-simulation-engine.d.ts.map +0 -1
- package/dist/security/apt-simulation-engine.js +0 -441
- package/dist/security/apt-simulation-engine.js.map +0 -1
- package/dist/security/authorization.d.ts +0 -45
- package/dist/security/authorization.d.ts.map +0 -1
- package/dist/security/authorization.js +0 -128
- package/dist/security/authorization.js.map +0 -1
- package/dist/security/comprehensive-security-research.d.ts +0 -84
- package/dist/security/comprehensive-security-research.d.ts.map +0 -1
- package/dist/security/comprehensive-security-research.js +0 -211
- package/dist/security/comprehensive-security-research.js.map +0 -1
- package/dist/security/offensive/exploitationEngine.d.ts +0 -54
- package/dist/security/offensive/exploitationEngine.d.ts.map +0 -1
- package/dist/security/offensive/exploitationEngine.js +0 -263
- package/dist/security/offensive/exploitationEngine.js.map +0 -1
- package/dist/security/real/networkExploitation.d.ts +0 -92
- package/dist/security/real/networkExploitation.d.ts.map +0 -1
- package/dist/security/real/networkExploitation.js +0 -316
- package/dist/security/real/networkExploitation.js.map +0 -1
- package/dist/security/real/persistenceImplementation.d.ts +0 -62
- package/dist/security/real/persistenceImplementation.d.ts.map +0 -1
- package/dist/security/real/persistenceImplementation.js +0 -323
- package/dist/security/real/persistenceImplementation.js.map +0 -1
- package/dist/security/real/vulnerabilityScanner.d.ts +0 -73
- package/dist/security/real/vulnerabilityScanner.d.ts.map +0 -1
- package/dist/security/real/vulnerabilityScanner.js +0 -341
- package/dist/security/real/vulnerabilityScanner.js.map +0 -1
- package/dist/shell/capturePastePatch.d.ts +0 -9
- package/dist/shell/capturePastePatch.d.ts.map +0 -1
- package/dist/shell/capturePastePatch.js +0 -98
- package/dist/shell/capturePastePatch.js.map +0 -1
- package/dist/shell/enhancedInteractiveShell.d.ts +0 -90
- package/dist/shell/enhancedInteractiveShell.d.ts.map +0 -1
- package/dist/shell/enhancedInteractiveShell.js +0 -248
- package/dist/shell/enhancedInteractiveShell.js.map +0 -1
- package/dist/shell/inputProcessor.d.ts +0 -56
- package/dist/shell/inputProcessor.d.ts.map +0 -1
- package/dist/shell/inputProcessor.js +0 -172
- package/dist/shell/inputProcessor.js.map +0 -1
- package/dist/shell/interactiveShell-patch.d.ts +0 -27
- package/dist/shell/interactiveShell-patch.d.ts.map +0 -1
- package/dist/shell/interactiveShell-patch.js +0 -38
- package/dist/shell/interactiveShell-patch.js.map +0 -1
- package/dist/shell/interactiveShell-robust.d.ts +0 -26
- package/dist/shell/interactiveShell-robust.d.ts.map +0 -1
- package/dist/shell/interactiveShell-robust.js +0 -34
- package/dist/shell/interactiveShell-robust.js.map +0 -1
- package/dist/shell/multiLinePasteManager.d.ts +0 -106
- package/dist/shell/multiLinePasteManager.d.ts.map +0 -1
- package/dist/shell/multiLinePasteManager.js +0 -308
- package/dist/shell/multiLinePasteManager.js.map +0 -1
- package/dist/shell/processInputBlockPatch.d.ts +0 -8
- package/dist/shell/processInputBlockPatch.d.ts.map +0 -1
- package/dist/shell/processInputBlockPatch.js +0 -133
- package/dist/shell/processInputBlockPatch.js.map +0 -1
- package/dist/tools/enhancedSecurityTools.d.ts +0 -19
- package/dist/tools/enhancedSecurityTools.d.ts.map +0 -1
- package/dist/tools/enhancedSecurityTools.js +0 -215
- package/dist/tools/enhancedSecurityTools.js.map +0 -1
- package/dist/tools/offensiveSecurityTools.d.ts +0 -16
- package/dist/tools/offensiveSecurityTools.d.ts.map +0 -1
- package/dist/tools/offensiveSecurityTools.js +0 -285
- package/dist/tools/offensiveSecurityTools.js.map +0 -1
- package/dist/tools/realSecurityTools.d.ts +0 -18
- package/dist/tools/realSecurityTools.d.ts.map +0 -1
- package/dist/tools/realSecurityTools.js +0 -468
- package/dist/tools/realSecurityTools.js.map +0 -1
- package/dist/tools/securityTools.d.ts +0 -20
- package/dist/tools/securityTools.d.ts.map +0 -1
- package/dist/tools/securityTools.js +0 -449
- package/dist/tools/securityTools.js.map +0 -1
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync, existsSync, readdirSync, statSync, mkdirSync } from 'node:fs';
|
|
2
|
-
import { join, dirname, relative } from 'node:path';
|
|
3
|
-
import { buildError } from '../core/errors.js';
|
|
4
|
-
import { buildDiffSegments, formatDiffLines } from './diffUtils.js';
|
|
5
|
-
export function createFileTools(workingDir) {
|
|
6
|
-
return [
|
|
7
|
-
{
|
|
8
|
-
name: 'read_file',
|
|
9
|
-
description: 'Read the contents of a file at the specified path',
|
|
10
|
-
parameters: {
|
|
11
|
-
type: 'object',
|
|
12
|
-
properties: {
|
|
13
|
-
path: {
|
|
14
|
-
type: 'string',
|
|
15
|
-
description: 'The file path (relative to working directory or absolute)',
|
|
16
|
-
minLength: 1,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
required: ['path'],
|
|
20
|
-
additionalProperties: false,
|
|
21
|
-
},
|
|
22
|
-
handler: async (args) => {
|
|
23
|
-
const pathArg = args['path'];
|
|
24
|
-
const requestedPath = normalizePathContext(pathArg);
|
|
25
|
-
let resolvedPath;
|
|
26
|
-
try {
|
|
27
|
-
const filePath = resolveFilePath(workingDir, pathArg);
|
|
28
|
-
resolvedPath = filePath;
|
|
29
|
-
if (!existsSync(filePath)) {
|
|
30
|
-
return `Error: File not found: ${filePath}`;
|
|
31
|
-
}
|
|
32
|
-
const content = readFileSync(filePath, 'utf-8');
|
|
33
|
-
return `File: ${filePath}\n\n${content}`;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
return buildError('reading file', error, { path: requestedPath, resolvedPath });
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'write_file',
|
|
42
|
-
description: 'Write content to a file at the specified path (creates directories if needed)',
|
|
43
|
-
parameters: {
|
|
44
|
-
type: 'object',
|
|
45
|
-
properties: {
|
|
46
|
-
path: {
|
|
47
|
-
type: 'string',
|
|
48
|
-
description: 'The file path (relative to working directory or absolute)',
|
|
49
|
-
minLength: 1,
|
|
50
|
-
},
|
|
51
|
-
content: {
|
|
52
|
-
type: 'string',
|
|
53
|
-
description: 'The content to write to the file',
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
required: ['path', 'content'],
|
|
57
|
-
additionalProperties: false,
|
|
58
|
-
},
|
|
59
|
-
handler: async (args) => {
|
|
60
|
-
const pathArg = args['path'];
|
|
61
|
-
const requestedPath = normalizePathContext(pathArg);
|
|
62
|
-
let resolvedPath;
|
|
63
|
-
try {
|
|
64
|
-
const filePath = resolveFilePath(workingDir, pathArg);
|
|
65
|
-
resolvedPath = filePath;
|
|
66
|
-
const dir = dirname(filePath);
|
|
67
|
-
if (!existsSync(dir)) {
|
|
68
|
-
mkdirSync(dir, { recursive: true });
|
|
69
|
-
}
|
|
70
|
-
const nextContent = typeof args['content'] === 'string' ? args['content'] : '';
|
|
71
|
-
const filePreviouslyExisted = existsSync(filePath);
|
|
72
|
-
const previousContent = filePreviouslyExisted ? readFileSync(filePath, 'utf-8') : '';
|
|
73
|
-
const diffSegments = buildDiffSegments(previousContent, nextContent);
|
|
74
|
-
writeFileSync(filePath, nextContent, 'utf-8');
|
|
75
|
-
return buildWriteSummary(filePath, diffSegments, workingDir, filePreviouslyExisted);
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
return buildError('writing file', error, { path: requestedPath, resolvedPath });
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: 'list_files',
|
|
84
|
-
description: 'List files and directories at the specified path',
|
|
85
|
-
parameters: {
|
|
86
|
-
type: 'object',
|
|
87
|
-
properties: {
|
|
88
|
-
path: {
|
|
89
|
-
type: 'string',
|
|
90
|
-
description: 'The directory path (defaults to current working directory)',
|
|
91
|
-
minLength: 1,
|
|
92
|
-
},
|
|
93
|
-
recursive: {
|
|
94
|
-
type: 'boolean',
|
|
95
|
-
description: 'Whether to list files recursively',
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
additionalProperties: false,
|
|
99
|
-
},
|
|
100
|
-
handler: async (args) => {
|
|
101
|
-
const pathArg = args['path'];
|
|
102
|
-
const requestedPath = normalizePathContext(pathArg);
|
|
103
|
-
let resolvedPath;
|
|
104
|
-
try {
|
|
105
|
-
const dirPath = pathArg !== undefined && pathArg !== null ? resolveFilePath(workingDir, pathArg) : workingDir;
|
|
106
|
-
resolvedPath = dirPath;
|
|
107
|
-
const recursive = args['recursive'] === true;
|
|
108
|
-
if (!existsSync(dirPath)) {
|
|
109
|
-
return `Error: Directory not found: ${dirPath}`;
|
|
110
|
-
}
|
|
111
|
-
const files = listFilesRecursive(dirPath, recursive ? 5 : 1, workingDir);
|
|
112
|
-
return `Directory: ${dirPath}\n\n${files.join('\n')}`;
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
return buildError('listing files', error, { path: requestedPath, resolvedPath });
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
name: 'search_files',
|
|
121
|
-
description: 'Search for files matching a pattern (supports glob patterns)',
|
|
122
|
-
parameters: {
|
|
123
|
-
type: 'object',
|
|
124
|
-
properties: {
|
|
125
|
-
pattern: {
|
|
126
|
-
type: 'string',
|
|
127
|
-
description: 'The search pattern (e.g., "*.ts", "src/**/*.js")',
|
|
128
|
-
minLength: 1,
|
|
129
|
-
},
|
|
130
|
-
path: {
|
|
131
|
-
type: 'string',
|
|
132
|
-
description: 'The directory to search in (defaults to current working directory)',
|
|
133
|
-
minLength: 1,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
required: ['pattern'],
|
|
137
|
-
additionalProperties: false,
|
|
138
|
-
},
|
|
139
|
-
handler: async (args) => {
|
|
140
|
-
const pathArg = args['path'];
|
|
141
|
-
const requestedPath = normalizePathContext(pathArg);
|
|
142
|
-
const patternArg = args['pattern'];
|
|
143
|
-
const requestedPattern = typeof patternArg === 'string' ? patternArg : undefined;
|
|
144
|
-
let resolvedPath;
|
|
145
|
-
try {
|
|
146
|
-
const pattern = typeof patternArg === 'string' && patternArg.trim() ? patternArg : null;
|
|
147
|
-
if (!pattern) {
|
|
148
|
-
return 'Error: pattern must be a non-empty string.';
|
|
149
|
-
}
|
|
150
|
-
const searchPath = pathArg !== undefined && pathArg !== null ? resolveFilePath(workingDir, pathArg) : workingDir;
|
|
151
|
-
resolvedPath = searchPath;
|
|
152
|
-
const results = searchFilesGlob(searchPath, pattern);
|
|
153
|
-
if (results.length === 0) {
|
|
154
|
-
return `No files found matching pattern: ${pattern}`;
|
|
155
|
-
}
|
|
156
|
-
return `Found ${results.length} files:\n\n${results.map((f) => relative(workingDir, f)).join('\n')}`;
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
return buildError('searching files', error, {
|
|
160
|
-
path: requestedPath,
|
|
161
|
-
resolvedPath,
|
|
162
|
-
pattern: requestedPattern,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
];
|
|
168
|
-
}
|
|
169
|
-
function resolveFilePath(workingDir, path) {
|
|
170
|
-
const validated = validatePathArg(path);
|
|
171
|
-
return validated.startsWith('/') ? validated : join(workingDir, validated);
|
|
172
|
-
}
|
|
173
|
-
function validatePathArg(path) {
|
|
174
|
-
if (typeof path !== 'string' || !path.trim()) {
|
|
175
|
-
throw new Error('Path must be a non-empty string.');
|
|
176
|
-
}
|
|
177
|
-
return path.trim();
|
|
178
|
-
}
|
|
179
|
-
function normalizePathContext(path) {
|
|
180
|
-
if (path === undefined || path === null) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
return String(path);
|
|
185
|
-
}
|
|
186
|
-
catch {
|
|
187
|
-
return '(unprintable)';
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
function listFilesRecursive(dir, maxDepth, baseDir, currentDepth = 0) {
|
|
191
|
-
if (currentDepth >= maxDepth) {
|
|
192
|
-
return [];
|
|
193
|
-
}
|
|
194
|
-
const ignoredDirs = new Set(['.git', 'node_modules', 'dist', '.next', 'build', 'coverage']);
|
|
195
|
-
const results = [];
|
|
196
|
-
try {
|
|
197
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
198
|
-
for (const entry of entries) {
|
|
199
|
-
if (ignoredDirs.has(entry.name)) {
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
const fullPath = join(dir, entry.name);
|
|
203
|
-
const indent = ' '.repeat(currentDepth);
|
|
204
|
-
if (entry.isDirectory()) {
|
|
205
|
-
results.push(`${indent}${entry.name}/`);
|
|
206
|
-
results.push(...listFilesRecursive(fullPath, maxDepth, baseDir, currentDepth + 1));
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
const stats = statSync(fullPath);
|
|
210
|
-
const size = formatFileSize(stats.size);
|
|
211
|
-
results.push(`${indent}${entry.name} ${size}`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
catch (error) {
|
|
216
|
-
}
|
|
217
|
-
return results;
|
|
218
|
-
}
|
|
219
|
-
function searchFilesGlob(dir, pattern) {
|
|
220
|
-
const results = [];
|
|
221
|
-
const regex = globToRegex(pattern);
|
|
222
|
-
function search(currentDir) {
|
|
223
|
-
const ignoredDirs = new Set(['.git', 'node_modules', 'dist', '.next', 'build', 'coverage']);
|
|
224
|
-
try {
|
|
225
|
-
const entries = readdirSync(currentDir, { withFileTypes: true });
|
|
226
|
-
for (const entry of entries) {
|
|
227
|
-
if (ignoredDirs.has(entry.name)) {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
const fullPath = join(currentDir, entry.name);
|
|
231
|
-
if (entry.isDirectory()) {
|
|
232
|
-
search(fullPath);
|
|
233
|
-
}
|
|
234
|
-
else if (regex.test(fullPath)) {
|
|
235
|
-
results.push(fullPath);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
catch (error) {
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
search(dir);
|
|
243
|
-
return results;
|
|
244
|
-
}
|
|
245
|
-
function buildWriteSummary(filePath, diffSegments, workingDir, filePreviouslyExisted) {
|
|
246
|
-
const readablePath = formatRelativeFilePath(filePath, workingDir);
|
|
247
|
-
const addedLines = diffSegments.filter((segment) => segment.type === 'added').length;
|
|
248
|
-
const removedLines = diffSegments.filter((segment) => segment.type === 'removed').length;
|
|
249
|
-
const hasChanges = diffSegments.length > 0;
|
|
250
|
-
const actionLabel = !filePreviouslyExisted ? 'Added' : hasChanges ? 'Edited' : 'Updated';
|
|
251
|
-
const header = `#### ${actionLabel} ${readablePath}`;
|
|
252
|
-
if (!hasChanges) {
|
|
253
|
-
return `${header}\nNo textual changes.`;
|
|
254
|
-
}
|
|
255
|
-
const statsLine = `Lines changed: +${addedLines} / -${removedLines}`;
|
|
256
|
-
const diffLines = formatDiffLines(diffSegments);
|
|
257
|
-
const diffBlock = ['```diff', ...diffLines, '```'].join('\n');
|
|
258
|
-
const sections = [header, statsLine, '', 'Diff preview:', diffBlock];
|
|
259
|
-
return sections.join('\n').trimEnd();
|
|
260
|
-
}
|
|
261
|
-
function formatRelativeFilePath(filePath, workingDir) {
|
|
262
|
-
const relPath = relative(workingDir, filePath);
|
|
263
|
-
if (!relPath || relPath.startsWith('..')) {
|
|
264
|
-
return filePath;
|
|
265
|
-
}
|
|
266
|
-
return relPath;
|
|
267
|
-
}
|
|
268
|
-
function globToRegex(pattern) {
|
|
269
|
-
const escaped = pattern
|
|
270
|
-
.replace(/\./g, '\\.')
|
|
271
|
-
.replace(/\*\*/g, '.*')
|
|
272
|
-
.replace(/\*/g, '[^/]*')
|
|
273
|
-
.replace(/\?/g, '.');
|
|
274
|
-
return new RegExp(escaped);
|
|
275
|
-
}
|
|
276
|
-
function formatFileSize(bytes) {
|
|
277
|
-
if (bytes < 1024)
|
|
278
|
-
return `${bytes}B`;
|
|
279
|
-
if (bytes < 1024 * 1024)
|
|
280
|
-
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
281
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
282
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { readdirSync, statSync } from 'node:fs';
|
|
2
|
-
import { join, relative } from 'node:path';
|
|
3
|
-
import { buildError } from '../core/errors.js';
|
|
4
|
-
/**
|
|
5
|
-
* Creates the Glob tool for fast file pattern matching
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Supports glob patterns like wildcard recursion or directory matching
|
|
9
|
-
* - Returns matching file paths sorted by modification time (newest first)
|
|
10
|
-
* - Ignores common directories (.git, node_modules, dist)
|
|
11
|
-
* - Fast pattern matching optimized for large codebases
|
|
12
|
-
*
|
|
13
|
-
* @param workingDir - The working directory for pattern matching
|
|
14
|
-
* @returns Array containing the Glob tool definition
|
|
15
|
-
*/
|
|
16
|
-
export function createGlobTools(workingDir) {
|
|
17
|
-
return [
|
|
18
|
-
{
|
|
19
|
-
name: 'Glob',
|
|
20
|
-
description: 'Fast file pattern matching tool that works with any codebase size. Supports glob patterns like "**/*.js" or "src/**/*.ts". Returns matching file paths sorted by modification time.',
|
|
21
|
-
parameters: {
|
|
22
|
-
type: 'object',
|
|
23
|
-
properties: {
|
|
24
|
-
pattern: {
|
|
25
|
-
type: 'string',
|
|
26
|
-
description: 'The glob pattern to match files against (e.g., "**/*.ts", "src/**/*.js", "*.md"). Avoid overly broad patterns like "." or "*" - be specific.',
|
|
27
|
-
},
|
|
28
|
-
path: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
description: 'The directory to search in. If not specified, the current working directory will be used.',
|
|
31
|
-
},
|
|
32
|
-
head_limit: {
|
|
33
|
-
type: 'number',
|
|
34
|
-
description: 'Maximum number of files to return. Defaults to 20. Use higher values only when necessary to reduce context usage.',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
required: ['pattern'],
|
|
38
|
-
additionalProperties: false,
|
|
39
|
-
},
|
|
40
|
-
handler: async (args) => {
|
|
41
|
-
const pattern = args['pattern'];
|
|
42
|
-
const pathArg = args['path'];
|
|
43
|
-
const headLimit = typeof args['head_limit'] === 'number' ? args['head_limit'] : 20; // Default to 20 files
|
|
44
|
-
// Validate pattern
|
|
45
|
-
if (typeof pattern !== 'string' || !pattern.trim()) {
|
|
46
|
-
return 'Error: pattern must be a non-empty string.';
|
|
47
|
-
}
|
|
48
|
-
// Warn about overly broad patterns
|
|
49
|
-
const trimmedPattern = pattern.trim();
|
|
50
|
-
if (trimmedPattern === '.' || trimmedPattern === '*' || trimmedPattern === '**/*') {
|
|
51
|
-
return `Warning: Pattern "${pattern}" is too broad and will match many files. Please use a more specific pattern like "**/*.ts" or "src/**/*.js" to reduce context usage.`;
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const searchPath = pathArg && typeof pathArg === 'string'
|
|
55
|
-
? resolveFilePath(workingDir, pathArg)
|
|
56
|
-
: workingDir;
|
|
57
|
-
// Perform glob search
|
|
58
|
-
const matches = globSearch(searchPath, pattern);
|
|
59
|
-
// Sort by modification time (newest first)
|
|
60
|
-
const sorted = matches.sort((a, b) => {
|
|
61
|
-
try {
|
|
62
|
-
const statA = statSync(a);
|
|
63
|
-
const statB = statSync(b);
|
|
64
|
-
return statB.mtimeMs - statA.mtimeMs;
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return 0;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
// Convert to relative paths
|
|
71
|
-
const relativePaths = sorted.map(filePath => {
|
|
72
|
-
const rel = relative(workingDir, filePath);
|
|
73
|
-
return rel && !rel.startsWith('..') ? rel : filePath;
|
|
74
|
-
});
|
|
75
|
-
if (relativePaths.length === 0) {
|
|
76
|
-
return `No files found matching pattern: ${pattern}`;
|
|
77
|
-
}
|
|
78
|
-
// Apply head_limit
|
|
79
|
-
const totalMatches = relativePaths.length;
|
|
80
|
-
const limited = relativePaths.slice(0, headLimit);
|
|
81
|
-
const truncated = totalMatches > headLimit;
|
|
82
|
-
const summary = totalMatches === 1
|
|
83
|
-
? '1 file found'
|
|
84
|
-
: `${totalMatches} file${totalMatches === 1 ? '' : 's'} found`;
|
|
85
|
-
let result = `${summary} matching "${pattern}":`;
|
|
86
|
-
if (truncated) {
|
|
87
|
-
result += ` (showing first ${headLimit} of ${totalMatches})`;
|
|
88
|
-
}
|
|
89
|
-
result += `\n\n${limited.join('\n')}`;
|
|
90
|
-
if (truncated) {
|
|
91
|
-
result += `\n\n... [${totalMatches - headLimit} more files truncated. Use head_limit parameter to see more]`;
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
return buildError('glob search', error, {
|
|
97
|
-
pattern: String(pattern),
|
|
98
|
-
path: pathArg ? String(pathArg) : undefined,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
function resolveFilePath(workingDir, path) {
|
|
106
|
-
const normalized = path.trim();
|
|
107
|
-
return normalized.startsWith('/') ? normalized : join(workingDir, normalized);
|
|
108
|
-
}
|
|
109
|
-
function globSearch(baseDir, pattern) {
|
|
110
|
-
const results = [];
|
|
111
|
-
const regex = globToRegex(pattern);
|
|
112
|
-
const ignoredDirs = new Set([
|
|
113
|
-
'.git',
|
|
114
|
-
'node_modules',
|
|
115
|
-
'dist',
|
|
116
|
-
'.next',
|
|
117
|
-
'build',
|
|
118
|
-
'coverage',
|
|
119
|
-
'.turbo',
|
|
120
|
-
'.cache',
|
|
121
|
-
'__pycache__',
|
|
122
|
-
'.pytest_cache',
|
|
123
|
-
'.venv',
|
|
124
|
-
'venv',
|
|
125
|
-
]);
|
|
126
|
-
function search(currentDir) {
|
|
127
|
-
try {
|
|
128
|
-
const entries = readdirSync(currentDir, { withFileTypes: true });
|
|
129
|
-
for (const entry of entries) {
|
|
130
|
-
if (ignoredDirs.has(entry.name)) {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
const fullPath = join(currentDir, entry.name);
|
|
134
|
-
if (entry.isDirectory()) {
|
|
135
|
-
search(fullPath);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
// Test the full path against the pattern
|
|
139
|
-
if (regex.test(fullPath)) {
|
|
140
|
-
results.push(fullPath);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
// Silently ignore permission errors
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
search(baseDir);
|
|
150
|
-
return results;
|
|
151
|
-
}
|
|
152
|
-
function globToRegex(pattern) {
|
|
153
|
-
// Escape special regex characters except glob wildcards
|
|
154
|
-
let escaped = pattern
|
|
155
|
-
.replace(/\./g, '\\.')
|
|
156
|
-
.replace(/\+/g, '\\+')
|
|
157
|
-
.replace(/\^/g, '\\^')
|
|
158
|
-
.replace(/\$/g, '\\$')
|
|
159
|
-
.replace(/\(/g, '\\(')
|
|
160
|
-
.replace(/\)/g, '\\)')
|
|
161
|
-
.replace(/\[/g, '\\[')
|
|
162
|
-
.replace(/\]/g, '\\]')
|
|
163
|
-
.replace(/\{/g, '\\{')
|
|
164
|
-
.replace(/\}/g, '\\}')
|
|
165
|
-
.replace(/\|/g, '\\|');
|
|
166
|
-
// Convert glob patterns to regex
|
|
167
|
-
escaped = escaped
|
|
168
|
-
.replace(/\*\*/g, '<!GLOBSTAR!>') // Placeholder for **
|
|
169
|
-
.replace(/\*/g, '[^/]*') // * matches any characters except /
|
|
170
|
-
.replace(/<!GLOBSTAR!>/g, '.*') // ** matches any characters including /
|
|
171
|
-
.replace(/\?/g, '.'); // ? matches any single character
|
|
172
|
-
return new RegExp(escaped + '$');
|
|
173
|
-
}
|