@blockrun/runcode 2.5.6 → 2.5.7
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/tools/glob.js +5 -1
- package/dist/tools/grep.js +29 -6
- package/package.json +1 -1
package/dist/tools/glob.js
CHANGED
|
@@ -106,7 +106,11 @@ async function execute(input, ctx) {
|
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
108
|
withMtime.sort((a, b) => b.mtime - a.mtime);
|
|
109
|
-
|
|
109
|
+
// Convert to relative paths to save tokens (same as Claude Code)
|
|
110
|
+
const sorted = withMtime.map(f => {
|
|
111
|
+
const rel = path.relative(ctx.workingDir, f.path);
|
|
112
|
+
return rel.startsWith('..') ? f.path : rel;
|
|
113
|
+
});
|
|
110
114
|
if (sorted.length === 0) {
|
|
111
115
|
// Suggest recursive pattern if user used non-recursive glob
|
|
112
116
|
const hint = !pattern.includes('**') && !pattern.includes('/')
|
package/dist/tools/grep.js
CHANGED
|
@@ -32,12 +32,18 @@ async function execute(input, ctx) {
|
|
|
32
32
|
const mode = opts.output_mode || 'files_with_matches';
|
|
33
33
|
const limit = opts.head_limit ?? 250;
|
|
34
34
|
if (hasRipgrep()) {
|
|
35
|
-
return runRipgrep(opts, searchPath, mode, limit);
|
|
35
|
+
return runRipgrep(opts, searchPath, mode, limit, ctx.workingDir);
|
|
36
36
|
}
|
|
37
|
-
return runNativeGrep(opts, searchPath, mode, limit);
|
|
37
|
+
return runNativeGrep(opts, searchPath, mode, limit, ctx.workingDir);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function toRelative(absPath, cwd) {
|
|
40
|
+
const rel = path.relative(cwd, absPath);
|
|
41
|
+
return rel.startsWith('..') ? absPath : rel;
|
|
42
|
+
}
|
|
43
|
+
function runRipgrep(opts, searchPath, mode, limit, cwd) {
|
|
40
44
|
const args = [];
|
|
45
|
+
// Limit line length to prevent base64/minified content from cluttering output
|
|
46
|
+
args.push('--max-columns', '500');
|
|
41
47
|
switch (mode) {
|
|
42
48
|
case 'files_with_matches':
|
|
43
49
|
args.push('-l');
|
|
@@ -76,7 +82,17 @@ function runRipgrep(opts, searchPath, mode, limit) {
|
|
|
76
82
|
});
|
|
77
83
|
const lines = result.split('\n').filter(Boolean);
|
|
78
84
|
const limited = limit > 0 ? lines.slice(0, limit) : lines;
|
|
79
|
-
|
|
85
|
+
// Convert absolute paths to relative paths to save tokens (same as Claude Code)
|
|
86
|
+
const relativized = limited.map(line => {
|
|
87
|
+
// Lines: /abs/path or /abs/path:rest (content mode)
|
|
88
|
+
const colonIdx = line.indexOf(':');
|
|
89
|
+
if (colonIdx > 0 && line.startsWith('/')) {
|
|
90
|
+
const filePart = line.slice(0, colonIdx);
|
|
91
|
+
return toRelative(filePart, cwd) + line.slice(colonIdx);
|
|
92
|
+
}
|
|
93
|
+
return line.startsWith('/') ? toRelative(line, cwd) : line;
|
|
94
|
+
});
|
|
95
|
+
let output = relativized.join('\n');
|
|
80
96
|
if (lines.length > limited.length) {
|
|
81
97
|
output += `\n\n... (${lines.length - limited.length} more results, use head_limit to see more)`;
|
|
82
98
|
}
|
|
@@ -97,7 +113,7 @@ function runRipgrep(opts, searchPath, mode, limit) {
|
|
|
97
113
|
};
|
|
98
114
|
}
|
|
99
115
|
}
|
|
100
|
-
function runNativeGrep(opts, searchPath, mode, limit) {
|
|
116
|
+
function runNativeGrep(opts, searchPath, mode, limit, cwd) {
|
|
101
117
|
const args = ['-r', '-n'];
|
|
102
118
|
if (opts.case_insensitive)
|
|
103
119
|
args.push('-i');
|
|
@@ -128,7 +144,14 @@ function runNativeGrep(opts, searchPath, mode, limit) {
|
|
|
128
144
|
});
|
|
129
145
|
const lines = result.split('\n').filter(Boolean);
|
|
130
146
|
const limited = limit > 0 ? lines.slice(0, limit) : lines;
|
|
131
|
-
|
|
147
|
+
const relativized = limited.map(line => {
|
|
148
|
+
const colonIdx = line.indexOf(':');
|
|
149
|
+
if (colonIdx > 0 && line.startsWith('/')) {
|
|
150
|
+
return toRelative(line.slice(0, colonIdx), cwd) + line.slice(colonIdx);
|
|
151
|
+
}
|
|
152
|
+
return line.startsWith('/') ? toRelative(line, cwd) : line;
|
|
153
|
+
});
|
|
154
|
+
let output = relativized.join('\n');
|
|
132
155
|
if (lines.length > limited.length) {
|
|
133
156
|
output += `\n\n... (${lines.length - limited.length} more results)`;
|
|
134
157
|
}
|