@animus-labs/cortex 0.2.0
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/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/budget-guard.d.ts +75 -0
- package/dist/budget-guard.d.ts.map +1 -0
- package/dist/budget-guard.js +142 -0
- package/dist/budget-guard.js.map +1 -0
- package/dist/compaction/compaction.d.ts +99 -0
- package/dist/compaction/compaction.d.ts.map +1 -0
- package/dist/compaction/compaction.js +302 -0
- package/dist/compaction/compaction.js.map +1 -0
- package/dist/compaction/failsafe.d.ts +57 -0
- package/dist/compaction/failsafe.d.ts.map +1 -0
- package/dist/compaction/failsafe.js +135 -0
- package/dist/compaction/failsafe.js.map +1 -0
- package/dist/compaction/index.d.ts +381 -0
- package/dist/compaction/index.d.ts.map +1 -0
- package/dist/compaction/index.js +979 -0
- package/dist/compaction/index.js.map +1 -0
- package/dist/compaction/microcompaction.d.ts +219 -0
- package/dist/compaction/microcompaction.d.ts.map +1 -0
- package/dist/compaction/microcompaction.js +536 -0
- package/dist/compaction/microcompaction.js.map +1 -0
- package/dist/compaction/observational/buffering.d.ts +225 -0
- package/dist/compaction/observational/buffering.d.ts.map +1 -0
- package/dist/compaction/observational/buffering.js +354 -0
- package/dist/compaction/observational/buffering.js.map +1 -0
- package/dist/compaction/observational/constants.d.ts +70 -0
- package/dist/compaction/observational/constants.d.ts.map +1 -0
- package/dist/compaction/observational/constants.js +507 -0
- package/dist/compaction/observational/constants.js.map +1 -0
- package/dist/compaction/observational/index.d.ts +219 -0
- package/dist/compaction/observational/index.d.ts.map +1 -0
- package/dist/compaction/observational/index.js +641 -0
- package/dist/compaction/observational/index.js.map +1 -0
- package/dist/compaction/observational/observer.d.ts +97 -0
- package/dist/compaction/observational/observer.d.ts.map +1 -0
- package/dist/compaction/observational/observer.js +424 -0
- package/dist/compaction/observational/observer.js.map +1 -0
- package/dist/compaction/observational/recall-tool.d.ts +27 -0
- package/dist/compaction/observational/recall-tool.d.ts.map +1 -0
- package/dist/compaction/observational/recall-tool.js +93 -0
- package/dist/compaction/observational/recall-tool.js.map +1 -0
- package/dist/compaction/observational/reflector.d.ts +94 -0
- package/dist/compaction/observational/reflector.d.ts.map +1 -0
- package/dist/compaction/observational/reflector.js +167 -0
- package/dist/compaction/observational/reflector.js.map +1 -0
- package/dist/compaction/observational/types.d.ts +271 -0
- package/dist/compaction/observational/types.d.ts.map +1 -0
- package/dist/compaction/observational/types.js +15 -0
- package/dist/compaction/observational/types.js.map +1 -0
- package/dist/context-manager.d.ts +134 -0
- package/dist/context-manager.d.ts.map +1 -0
- package/dist/context-manager.js +170 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/cortex-agent.d.ts +1020 -0
- package/dist/cortex-agent.d.ts.map +1 -0
- package/dist/cortex-agent.js +3589 -0
- package/dist/cortex-agent.js.map +1 -0
- package/dist/error-classifier.d.ts +48 -0
- package/dist/error-classifier.d.ts.map +1 -0
- package/dist/error-classifier.js +152 -0
- package/dist/error-classifier.js.map +1 -0
- package/dist/event-bridge.d.ts +166 -0
- package/dist/event-bridge.d.ts.map +1 -0
- package/dist/event-bridge.js +381 -0
- package/dist/event-bridge.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-client.d.ts +119 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +474 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/model-wrapper.d.ts +58 -0
- package/dist/model-wrapper.d.ts.map +1 -0
- package/dist/model-wrapper.js +86 -0
- package/dist/model-wrapper.js.map +1 -0
- package/dist/noop-logger.d.ts +4 -0
- package/dist/noop-logger.d.ts.map +1 -0
- package/dist/noop-logger.js +8 -0
- package/dist/noop-logger.js.map +1 -0
- package/dist/prompt-diagnostics.d.ts +47 -0
- package/dist/prompt-diagnostics.d.ts.map +1 -0
- package/dist/prompt-diagnostics.js +230 -0
- package/dist/prompt-diagnostics.js.map +1 -0
- package/dist/provider-manager.d.ts +224 -0
- package/dist/provider-manager.d.ts.map +1 -0
- package/dist/provider-manager.js +563 -0
- package/dist/provider-manager.js.map +1 -0
- package/dist/provider-registry.d.ts +115 -0
- package/dist/provider-registry.d.ts.map +1 -0
- package/dist/provider-registry.js +305 -0
- package/dist/provider-registry.js.map +1 -0
- package/dist/schema-converter.d.ts +20 -0
- package/dist/schema-converter.d.ts.map +1 -0
- package/dist/schema-converter.js +48 -0
- package/dist/schema-converter.js.map +1 -0
- package/dist/skill-preprocessor.d.ts +46 -0
- package/dist/skill-preprocessor.d.ts.map +1 -0
- package/dist/skill-preprocessor.js +237 -0
- package/dist/skill-preprocessor.js.map +1 -0
- package/dist/skill-registry.d.ts +107 -0
- package/dist/skill-registry.d.ts.map +1 -0
- package/dist/skill-registry.js +330 -0
- package/dist/skill-registry.js.map +1 -0
- package/dist/skill-tool.d.ts +54 -0
- package/dist/skill-tool.d.ts.map +1 -0
- package/dist/skill-tool.js +88 -0
- package/dist/skill-tool.js.map +1 -0
- package/dist/sub-agent-manager.d.ts +90 -0
- package/dist/sub-agent-manager.d.ts.map +1 -0
- package/dist/sub-agent-manager.js +192 -0
- package/dist/sub-agent-manager.js.map +1 -0
- package/dist/token-estimator.d.ts +23 -0
- package/dist/token-estimator.d.ts.map +1 -0
- package/dist/token-estimator.js +27 -0
- package/dist/token-estimator.js.map +1 -0
- package/dist/tool-contract.d.ts +68 -0
- package/dist/tool-contract.d.ts.map +1 -0
- package/dist/tool-contract.js +35 -0
- package/dist/tool-contract.js.map +1 -0
- package/dist/tool-result-persistence.d.ts +89 -0
- package/dist/tool-result-persistence.d.ts.map +1 -0
- package/dist/tool-result-persistence.js +152 -0
- package/dist/tool-result-persistence.js.map +1 -0
- package/dist/tools/bash/index.d.ts +71 -0
- package/dist/tools/bash/index.d.ts.map +1 -0
- package/dist/tools/bash/index.js +485 -0
- package/dist/tools/bash/index.js.map +1 -0
- package/dist/tools/bash/interactive.d.ts +47 -0
- package/dist/tools/bash/interactive.d.ts.map +1 -0
- package/dist/tools/bash/interactive.js +262 -0
- package/dist/tools/bash/interactive.js.map +1 -0
- package/dist/tools/bash/safety.d.ts +149 -0
- package/dist/tools/bash/safety.d.ts.map +1 -0
- package/dist/tools/bash/safety.js +1116 -0
- package/dist/tools/bash/safety.js.map +1 -0
- package/dist/tools/edit.d.ts +57 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +310 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +34 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +268 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +53 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +673 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +62 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/read.d.ts +43 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +459 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/runtime.d.ts +62 -0
- package/dist/tools/runtime.d.ts.map +1 -0
- package/dist/tools/runtime.js +116 -0
- package/dist/tools/runtime.js.map +1 -0
- package/dist/tools/shared/cwd-tracker.d.ts +32 -0
- package/dist/tools/shared/cwd-tracker.d.ts.map +1 -0
- package/dist/tools/shared/cwd-tracker.js +44 -0
- package/dist/tools/shared/cwd-tracker.js.map +1 -0
- package/dist/tools/shared/edit-history.d.ts +55 -0
- package/dist/tools/shared/edit-history.d.ts.map +1 -0
- package/dist/tools/shared/edit-history.js +72 -0
- package/dist/tools/shared/edit-history.js.map +1 -0
- package/dist/tools/shared/edit-matcher.d.ts +83 -0
- package/dist/tools/shared/edit-matcher.d.ts.map +1 -0
- package/dist/tools/shared/edit-matcher.js +359 -0
- package/dist/tools/shared/edit-matcher.js.map +1 -0
- package/dist/tools/shared/file-mutation-lock.d.ts +22 -0
- package/dist/tools/shared/file-mutation-lock.d.ts.map +1 -0
- package/dist/tools/shared/file-mutation-lock.js +35 -0
- package/dist/tools/shared/file-mutation-lock.js.map +1 -0
- package/dist/tools/shared/gitignore.d.ts +17 -0
- package/dist/tools/shared/gitignore.d.ts.map +1 -0
- package/dist/tools/shared/gitignore.js +59 -0
- package/dist/tools/shared/gitignore.js.map +1 -0
- package/dist/tools/shared/pdf-extractor.d.ts +96 -0
- package/dist/tools/shared/pdf-extractor.d.ts.map +1 -0
- package/dist/tools/shared/pdf-extractor.js +196 -0
- package/dist/tools/shared/pdf-extractor.js.map +1 -0
- package/dist/tools/shared/read-registry.d.ts +66 -0
- package/dist/tools/shared/read-registry.d.ts.map +1 -0
- package/dist/tools/shared/read-registry.js +65 -0
- package/dist/tools/shared/read-registry.js.map +1 -0
- package/dist/tools/shared/safe-env.d.ts +18 -0
- package/dist/tools/shared/safe-env.d.ts.map +1 -0
- package/dist/tools/shared/safe-env.js +70 -0
- package/dist/tools/shared/safe-env.js.map +1 -0
- package/dist/tools/sub-agent.d.ts +91 -0
- package/dist/tools/sub-agent.d.ts.map +1 -0
- package/dist/tools/sub-agent.js +89 -0
- package/dist/tools/sub-agent.js.map +1 -0
- package/dist/tools/task-output.d.ts +38 -0
- package/dist/tools/task-output.d.ts.map +1 -0
- package/dist/tools/task-output.js +186 -0
- package/dist/tools/task-output.js.map +1 -0
- package/dist/tools/tool-search/index.d.ts +40 -0
- package/dist/tools/tool-search/index.d.ts.map +1 -0
- package/dist/tools/tool-search/index.js +110 -0
- package/dist/tools/tool-search/index.js.map +1 -0
- package/dist/tools/tool-search/registry.d.ts +82 -0
- package/dist/tools/tool-search/registry.d.ts.map +1 -0
- package/dist/tools/tool-search/registry.js +238 -0
- package/dist/tools/tool-search/registry.js.map +1 -0
- package/dist/tools/undo-edit.d.ts +51 -0
- package/dist/tools/undo-edit.d.ts.map +1 -0
- package/dist/tools/undo-edit.js +231 -0
- package/dist/tools/undo-edit.js.map +1 -0
- package/dist/tools/web-fetch/cache.d.ts +49 -0
- package/dist/tools/web-fetch/cache.d.ts.map +1 -0
- package/dist/tools/web-fetch/cache.js +89 -0
- package/dist/tools/web-fetch/cache.js.map +1 -0
- package/dist/tools/web-fetch/index.d.ts +53 -0
- package/dist/tools/web-fetch/index.d.ts.map +1 -0
- package/dist/tools/web-fetch/index.js +513 -0
- package/dist/tools/web-fetch/index.js.map +1 -0
- package/dist/tools/write.d.ts +59 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +316 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +881 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/dist/working-tags.d.ts +44 -0
- package/dist/working-tags.d.ts.map +1 -0
- package/dist/working-tags.js +103 -0
- package/dist/working-tags.js.map +1 -0
- package/package.json +87 -0
- package/src/budget-guard.ts +170 -0
- package/src/compaction/compaction.ts +386 -0
- package/src/compaction/failsafe.ts +185 -0
- package/src/compaction/index.ts +1199 -0
- package/src/compaction/microcompaction.ts +709 -0
- package/src/compaction/observational/buffering.ts +430 -0
- package/src/compaction/observational/constants.ts +532 -0
- package/src/compaction/observational/index.ts +837 -0
- package/src/compaction/observational/observer.ts +510 -0
- package/src/compaction/observational/recall-tool.ts +130 -0
- package/src/compaction/observational/reflector.ts +221 -0
- package/src/compaction/observational/types.ts +343 -0
- package/src/context-manager.ts +237 -0
- package/src/cortex-agent.ts +4297 -0
- package/src/error-classifier.ts +199 -0
- package/src/event-bridge.ts +508 -0
- package/src/index.ts +292 -0
- package/src/mcp-client.ts +582 -0
- package/src/model-wrapper.ts +128 -0
- package/src/noop-logger.ts +9 -0
- package/src/prompt-diagnostics.ts +296 -0
- package/src/provider-manager.ts +823 -0
- package/src/provider-registry.ts +386 -0
- package/src/schema-converter.ts +51 -0
- package/src/skill-preprocessor.ts +314 -0
- package/src/skill-registry.ts +378 -0
- package/src/skill-tool.ts +130 -0
- package/src/sub-agent-manager.ts +236 -0
- package/src/token-estimator.ts +26 -0
- package/src/tool-contract.ts +113 -0
- package/src/tool-result-persistence.ts +197 -0
- package/src/tools/bash/index.ts +633 -0
- package/src/tools/bash/interactive.ts +302 -0
- package/src/tools/bash/safety.ts +1297 -0
- package/src/tools/edit.ts +422 -0
- package/src/tools/glob.ts +330 -0
- package/src/tools/grep.ts +819 -0
- package/src/tools/index.ts +110 -0
- package/src/tools/read.ts +580 -0
- package/src/tools/runtime.ts +173 -0
- package/src/tools/shared/cwd-tracker.ts +50 -0
- package/src/tools/shared/edit-history.ts +96 -0
- package/src/tools/shared/edit-matcher.ts +457 -0
- package/src/tools/shared/file-mutation-lock.ts +40 -0
- package/src/tools/shared/gitignore.ts +61 -0
- package/src/tools/shared/pdf-extractor.ts +290 -0
- package/src/tools/shared/read-registry.ts +93 -0
- package/src/tools/shared/safe-env.ts +82 -0
- package/src/tools/sub-agent.ts +171 -0
- package/src/tools/task-output.ts +236 -0
- package/src/tools/tool-search/index.ts +167 -0
- package/src/tools/tool-search/registry.ts +278 -0
- package/src/tools/undo-edit.ts +314 -0
- package/src/tools/web-fetch/cache.ts +112 -0
- package/src/tools/web-fetch/index.ts +604 -0
- package/src/tools/write.ts +385 -0
- package/src/types.ts +1057 -0
- package/src/working-tags.ts +118 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glob tool: find files by name pattern matching.
|
|
3
|
+
*
|
|
4
|
+
* Uses fast-glob for pattern matching and sorts results by
|
|
5
|
+
* modification time (newest first). Respects .gitignore rules.
|
|
6
|
+
*
|
|
7
|
+
* Reference: docs/cortex/tools/glob.md
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import { Type } from 'typebox';
|
|
12
|
+
import { readGitignorePatterns, DEFAULT_IGNORE_PATTERNS, } from './shared/gitignore.js';
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Schema
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
export const GlobParams = Type.Object({
|
|
17
|
+
pattern: Type.String({ description: 'Glob pattern to match files against (e.g., "**/*.ts", "src/**/*.test.js")' }),
|
|
18
|
+
path: Type.Optional(Type.String({ description: 'Directory to search in. Default: current working directory.' })),
|
|
19
|
+
});
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Constants
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
const MAX_RESULTS = 100;
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Helpers
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
/**
|
|
28
|
+
* Recursively walk a directory and collect files matching a glob pattern.
|
|
29
|
+
* Uses Node.js built-in fs for simplicity (fast-glob would be used in production).
|
|
30
|
+
*
|
|
31
|
+
* This implementation is a simplified glob matcher. It supports:
|
|
32
|
+
* - `*` (match any characters except /)
|
|
33
|
+
* - `**` (match any path segment)
|
|
34
|
+
* - `?` (match single character)
|
|
35
|
+
* - `{a,b}` (alternation)
|
|
36
|
+
* - `[abc]` (character class)
|
|
37
|
+
*/
|
|
38
|
+
function globPatternToRegex(pattern) {
|
|
39
|
+
let regex = '';
|
|
40
|
+
let i = 0;
|
|
41
|
+
while (i < pattern.length) {
|
|
42
|
+
const char = pattern[i];
|
|
43
|
+
if (char === '*') {
|
|
44
|
+
if (pattern[i + 1] === '*') {
|
|
45
|
+
// ** matches any path segment
|
|
46
|
+
if (pattern[i + 2] === '/' || pattern[i + 2] === undefined) {
|
|
47
|
+
regex += '(?:.+/)?';
|
|
48
|
+
i += pattern[i + 2] === '/' ? 3 : 2;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// * matches anything except /
|
|
53
|
+
regex += '[^/]*';
|
|
54
|
+
i++;
|
|
55
|
+
}
|
|
56
|
+
else if (char === '?') {
|
|
57
|
+
regex += '[^/]';
|
|
58
|
+
i++;
|
|
59
|
+
}
|
|
60
|
+
else if (char === '{') {
|
|
61
|
+
// Find the closing brace
|
|
62
|
+
const closeIdx = pattern.indexOf('}', i);
|
|
63
|
+
if (closeIdx === -1) {
|
|
64
|
+
regex += '\\{';
|
|
65
|
+
i++;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const alternatives = pattern.slice(i + 1, closeIdx).split(',');
|
|
69
|
+
regex += '(?:' + alternatives.map(escapeRegexPart).join('|') + ')';
|
|
70
|
+
i = closeIdx + 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (char === '[') {
|
|
74
|
+
const closeIdx = pattern.indexOf(']', i);
|
|
75
|
+
if (closeIdx === -1) {
|
|
76
|
+
regex += '\\[';
|
|
77
|
+
i++;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
regex += pattern.slice(i, closeIdx + 1);
|
|
81
|
+
i = closeIdx + 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (char === '.') {
|
|
85
|
+
regex += '\\.';
|
|
86
|
+
i++;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
regex += char;
|
|
90
|
+
i++;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return new RegExp(`^${regex}$`);
|
|
94
|
+
}
|
|
95
|
+
function escapeRegexPart(s) {
|
|
96
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if a path matches any of the ignore patterns.
|
|
100
|
+
*/
|
|
101
|
+
function isIgnored(relativePath, ignorePatterns) {
|
|
102
|
+
const parts = relativePath.split('/');
|
|
103
|
+
for (const pattern of ignorePatterns) {
|
|
104
|
+
// Direct directory/file name match
|
|
105
|
+
const cleanPattern = pattern.endsWith('/') ? pattern.slice(0, -1) : pattern;
|
|
106
|
+
// Check if any path component matches
|
|
107
|
+
if (!cleanPattern.includes('/')) {
|
|
108
|
+
if (parts.some((part) => {
|
|
109
|
+
if (cleanPattern.includes('*') || cleanPattern.includes('?')) {
|
|
110
|
+
return globPatternToRegex(cleanPattern).test(part);
|
|
111
|
+
}
|
|
112
|
+
return part === cleanPattern;
|
|
113
|
+
})) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Full path pattern match
|
|
119
|
+
if (globPatternToRegex(cleanPattern).test(relativePath)) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Walk a directory tree and collect file paths.
|
|
128
|
+
*/
|
|
129
|
+
async function walkDirectory(dir, baseDir, ignorePatterns) {
|
|
130
|
+
const results = [];
|
|
131
|
+
let entries;
|
|
132
|
+
try {
|
|
133
|
+
entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Skip directories we can't read
|
|
137
|
+
return results;
|
|
138
|
+
}
|
|
139
|
+
for (const entry of entries) {
|
|
140
|
+
const fullPath = path.join(dir, entry.name);
|
|
141
|
+
const relativePath = path.relative(baseDir, fullPath).split(path.sep).join('/');
|
|
142
|
+
// Check ignore patterns
|
|
143
|
+
if (isIgnored(relativePath, ignorePatterns)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (entry.isDirectory()) {
|
|
147
|
+
const subResults = await walkDirectory(fullPath, baseDir, ignorePatterns);
|
|
148
|
+
results.push(...subResults);
|
|
149
|
+
}
|
|
150
|
+
else if (entry.isFile()) {
|
|
151
|
+
results.push(fullPath);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return results;
|
|
155
|
+
}
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
// Tool factory
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
export function createGlobTool(config) {
|
|
160
|
+
const respectGitignore = config.respectGitignore ?? true;
|
|
161
|
+
return {
|
|
162
|
+
name: 'Glob',
|
|
163
|
+
description: 'Find files by name pattern. Returns paths sorted by modification time (newest first).',
|
|
164
|
+
parameters: GlobParams,
|
|
165
|
+
async execute(params) {
|
|
166
|
+
const searchPath = params.path ? path.resolve(params.path) : path.resolve(config.defaultCwd);
|
|
167
|
+
const startTime = Date.now();
|
|
168
|
+
// Verify search path exists
|
|
169
|
+
try {
|
|
170
|
+
const stat = await fs.promises.stat(searchPath);
|
|
171
|
+
if (!stat.isDirectory()) {
|
|
172
|
+
return {
|
|
173
|
+
content: [{ type: 'text', text: `Directory does not exist: ${searchPath}` }],
|
|
174
|
+
details: {
|
|
175
|
+
totalCount: 0,
|
|
176
|
+
truncated: false,
|
|
177
|
+
durationMs: Date.now() - startTime,
|
|
178
|
+
searchPath,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return {
|
|
185
|
+
content: [{ type: 'text', text: `Directory does not exist: ${searchPath}` }],
|
|
186
|
+
details: {
|
|
187
|
+
totalCount: 0,
|
|
188
|
+
truncated: false,
|
|
189
|
+
durationMs: Date.now() - startTime,
|
|
190
|
+
searchPath,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
// Collect ignore patterns
|
|
195
|
+
let ignorePatterns;
|
|
196
|
+
if (respectGitignore) {
|
|
197
|
+
const gitignorePatterns = await readGitignorePatterns(searchPath);
|
|
198
|
+
ignorePatterns = gitignorePatterns.length > 0
|
|
199
|
+
? [...DEFAULT_IGNORE_PATTERNS, ...gitignorePatterns]
|
|
200
|
+
: DEFAULT_IGNORE_PATTERNS;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
ignorePatterns = [];
|
|
204
|
+
}
|
|
205
|
+
// Walk directory tree
|
|
206
|
+
const allFiles = await walkDirectory(searchPath, searchPath, ignorePatterns);
|
|
207
|
+
// Convert glob pattern to regex for filtering
|
|
208
|
+
const pattern = params.pattern;
|
|
209
|
+
let regex;
|
|
210
|
+
try {
|
|
211
|
+
regex = globPatternToRegex(pattern);
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return {
|
|
215
|
+
content: [{ type: 'text', text: `Invalid glob pattern: ${pattern}` }],
|
|
216
|
+
details: {
|
|
217
|
+
totalCount: 0,
|
|
218
|
+
truncated: false,
|
|
219
|
+
durationMs: Date.now() - startTime,
|
|
220
|
+
searchPath,
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
// Filter files by pattern
|
|
225
|
+
const matchingFiles = allFiles.filter((filePath) => {
|
|
226
|
+
const relativePath = path.relative(searchPath, filePath).split(path.sep).join('/');
|
|
227
|
+
return regex.test(relativePath);
|
|
228
|
+
});
|
|
229
|
+
// Sort by modification time (newest first)
|
|
230
|
+
const filesWithMtime = await Promise.all(matchingFiles.map(async (filePath) => {
|
|
231
|
+
try {
|
|
232
|
+
const stat = await fs.promises.stat(filePath);
|
|
233
|
+
return { filePath, mtime: stat.mtimeMs };
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return { filePath, mtime: 0 };
|
|
237
|
+
}
|
|
238
|
+
}));
|
|
239
|
+
filesWithMtime.sort((a, b) => b.mtime - a.mtime);
|
|
240
|
+
const totalCount = filesWithMtime.length;
|
|
241
|
+
const truncated = totalCount > MAX_RESULTS;
|
|
242
|
+
const resultFiles = filesWithMtime.slice(0, MAX_RESULTS);
|
|
243
|
+
// Normalize paths to forward slashes in output
|
|
244
|
+
const outputPaths = resultFiles.map((f) => f.filePath.split(path.sep).join('/'));
|
|
245
|
+
const durationMs = Date.now() - startTime;
|
|
246
|
+
let text;
|
|
247
|
+
if (outputPaths.length === 0) {
|
|
248
|
+
text = 'No files matched the pattern.';
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
text = outputPaths.join('\n');
|
|
252
|
+
if (truncated) {
|
|
253
|
+
text += `\n\n[Showing ${MAX_RESULTS} of ${totalCount} matches. Use a more specific pattern to narrow results.]`;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
content: [{ type: 'text', text }],
|
|
258
|
+
details: {
|
|
259
|
+
totalCount,
|
|
260
|
+
truncated,
|
|
261
|
+
durationMs,
|
|
262
|
+
searchPath,
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=glob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../src/tools/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAe,MAAM,SAAS,CAAC;AAE5C,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAE/B,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,2EAA2E,EAAE,CAAC;IAClH,IAAI,EAAE,IAAI,CAAC,QAAQ,CACjB,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,6DAA6D,EAAE,CAAC,CAC5F;CACF,CAAC,CAAC;AAeH,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,WAAW,GAAG,GAAG,CAAC;AAaxB,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;;;;;GAUG;AACH,SAAS,kBAAkB,CAAC,OAAe;IACzC,IAA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AAM,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;YAC3C,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;YAEzD,+CAA+C;YAC/C,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAEjF,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YAE1C,IAAI,IAAY,CAAC;YACjB,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC7B,IAAI,GAAG,+BAA+B,CAAC;YACzC,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC9B,IAAI,SAAS,EAAE,CAAC;oBACd,IAAI,IAAI,gBAAgB,WAAW,OAAO,UAAU,2DAA2D,CAAC;gBAClH,CAAC;YACH,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;gBACjC,OAAO,EAAE;oBACP,UAAU;oBACV,SAAS;oBACT,UAAU;oBACV,UAAU;iBACX;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grep tool: search file contents using regex.
|
|
3
|
+
*
|
|
4
|
+
* Uses the bundled ripgrep (rg) binary from @vscode/ripgrep as the
|
|
5
|
+
* primary search engine. Falls back to a pure Node.js regex search
|
|
6
|
+
* if the rg binary is unavailable (e.g., postinstall failed).
|
|
7
|
+
*
|
|
8
|
+
* Three output modes: files_with_matches, content, count.
|
|
9
|
+
* Pagination via offset + head_limit.
|
|
10
|
+
*
|
|
11
|
+
* Reference: docs/cortex/tools/grep.md
|
|
12
|
+
*/
|
|
13
|
+
import { Type, type Static } from 'typebox';
|
|
14
|
+
import type { ToolContentDetails } from '../types.js';
|
|
15
|
+
export declare const GrepParams: Type.TObject<{
|
|
16
|
+
pattern: Type.TString;
|
|
17
|
+
path: Type.TOptional<Type.TString>;
|
|
18
|
+
glob: Type.TOptional<Type.TString>;
|
|
19
|
+
type: Type.TOptional<Type.TString>;
|
|
20
|
+
output_mode: Type.TOptional<Type.TUnion<[Type.TLiteral<"files_with_matches">, Type.TLiteral<"content">, Type.TLiteral<"count">]>>;
|
|
21
|
+
context: Type.TOptional<Type.TNumber>;
|
|
22
|
+
'-i': Type.TOptional<Type.TBoolean>;
|
|
23
|
+
head_limit: Type.TOptional<Type.TNumber>;
|
|
24
|
+
offset: Type.TOptional<Type.TNumber>;
|
|
25
|
+
multiline: Type.TOptional<Type.TBoolean>;
|
|
26
|
+
}>;
|
|
27
|
+
export type GrepParamsType = Static<typeof GrepParams>;
|
|
28
|
+
export interface GrepDetails {
|
|
29
|
+
totalFiles: number;
|
|
30
|
+
totalMatches: number;
|
|
31
|
+
durationMs: number;
|
|
32
|
+
/** True when results were capped by head_limit. Output size limiting is handled by the agent's result-persistence interceptor. */
|
|
33
|
+
truncated: boolean;
|
|
34
|
+
usingFallback: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface GrepToolConfig {
|
|
37
|
+
/** Default search directory when no path param is given. */
|
|
38
|
+
defaultCwd: string;
|
|
39
|
+
/** Whether to respect .gitignore. Default: true. */
|
|
40
|
+
respectGitignore?: boolean | undefined;
|
|
41
|
+
}
|
|
42
|
+
export declare function createGrepTool(config: GrepToolConfig): {
|
|
43
|
+
name: string;
|
|
44
|
+
description: string;
|
|
45
|
+
parameters: typeof GrepParams;
|
|
46
|
+
execute: (params: GrepParamsType) => Promise<ToolContentDetails<GrepDetails>>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Reset the cached ripgrep path. Used by tests to force re-detection.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export declare function _resetRipgrepCache(): void;
|
|
53
|
+
//# sourceMappingURL=grep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../src/tools/grep.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAUtD,eAAO,MAAM,UAAU;;;;;;;;;;;EAiCrB,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAMvD,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,kIAAkI;IAClI,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;CACxB;AA4CD,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACxC;AAipBD,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,OAAO,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;CAC/E,CAuBA;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
|