@blockrun/runcode 2.5.5 → 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/agent/optimize.js +3 -3
- package/dist/tools/glob.js +5 -1
- package/dist/tools/grep.js +32 -9
- package/package.json +1 -1
package/dist/agent/optimize.js
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* 5. Pre-compact stripping — remove images/docs before summarization
|
|
10
10
|
*/
|
|
11
11
|
// ─── Constants ─────────────────────────────────────────────────────────────
|
|
12
|
-
/** Max chars per individual tool result before truncation */
|
|
13
|
-
const MAX_TOOL_RESULT_CHARS =
|
|
12
|
+
/** Max chars per individual tool result before truncation (history-level safety net) */
|
|
13
|
+
const MAX_TOOL_RESULT_CHARS = 32_000;
|
|
14
14
|
/** Max aggregate tool result chars per user message */
|
|
15
|
-
const MAX_TOOL_RESULTS_PER_MESSAGE_CHARS =
|
|
15
|
+
const MAX_TOOL_RESULTS_PER_MESSAGE_CHARS = 100_000;
|
|
16
16
|
/** Preview size when truncating */
|
|
17
17
|
const PREVIEW_CHARS = 2_000;
|
|
18
18
|
/** Default max_tokens (low to save output slot reservation) */
|
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');
|
|
@@ -64,8 +70,8 @@ function runRipgrep(opts, searchPath, mode, limit) {
|
|
|
64
70
|
args.push('-U', '--multiline-dotall');
|
|
65
71
|
if (opts.glob)
|
|
66
72
|
args.push(`--glob=${opts.glob}`);
|
|
67
|
-
// Always exclude common noise
|
|
68
|
-
args.push('--glob=!node_modules', '--glob=!.git', '--glob=!dist');
|
|
73
|
+
// Always exclude common noise + lock files (huge, rarely useful)
|
|
74
|
+
args.push('--glob=!node_modules', '--glob=!.git', '--glob=!dist', '--glob=!*.lock', '--glob=!package-lock.json', '--glob=!pnpm-lock.yaml');
|
|
69
75
|
args.push('--', opts.pattern);
|
|
70
76
|
args.push(searchPath);
|
|
71
77
|
try {
|
|
@@ -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');
|
|
@@ -118,7 +134,7 @@ function runNativeGrep(opts, searchPath, mode, limit) {
|
|
|
118
134
|
.replace(/\*\*/, '*'); // Convert ** to * for flat matching
|
|
119
135
|
args.push(`--include=${nativeGlob}`);
|
|
120
136
|
}
|
|
121
|
-
args.push('--exclude-dir=node_modules', '--exclude-dir=.git', '--exclude-dir=dist');
|
|
137
|
+
args.push('--exclude-dir=node_modules', '--exclude-dir=.git', '--exclude-dir=dist', '--exclude=*.lock', '--exclude=package-lock.json', '--exclude=pnpm-lock.yaml');
|
|
122
138
|
args.push('-e', opts.pattern, searchPath);
|
|
123
139
|
try {
|
|
124
140
|
const result = execFileSync('grep', args, {
|
|
@@ -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
|
}
|