Skip to content

Commit 684d3ac

Browse files
committed
feat: Bash RUNCODE env var, Grep before/after context params (v1.6.4)
1 parent 5ab2044 commit 684d3ac

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

dist/tools/bash.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ async function execute(input, ctx) {
1414
const shell = process.env.SHELL || '/bin/bash';
1515
const child = spawn(shell, ['-c', command], {
1616
cwd: ctx.workingDir,
17-
env: { ...process.env },
17+
env: {
18+
...process.env,
19+
RUNCODE: '1', // Let scripts detect they're running inside runcode
20+
RUNCODE_WORKDIR: ctx.workingDir,
21+
},
1822
stdio: ['ignore', 'pipe', 'pipe'],
1923
});
2024
let stdout = '';

dist/tools/grep.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ function runRipgrep(opts, searchPath, mode, limit) {
4949
if (opts.context && opts.context > 0) {
5050
args.push(`-C${opts.context}`);
5151
}
52+
else {
53+
if (opts.before_context && opts.before_context > 0)
54+
args.push(`-B${opts.before_context}`);
55+
if (opts.after_context && opts.after_context > 0)
56+
args.push(`-A${opts.after_context}`);
57+
}
5258
break;
5359
}
5460
if (opts.case_insensitive)
@@ -142,6 +148,8 @@ export const grepCapability = {
142148
description: 'Output mode: "content" (matching lines), "files_with_matches" (file paths), "count" (match counts). Default: files_with_matches',
143149
},
144150
context: { type: 'number', description: 'Lines of context around each match (content mode only)' },
151+
before_context: { type: 'number', description: 'Lines before each match (-B, content mode)' },
152+
after_context: { type: 'number', description: 'Lines after each match (-A, content mode)' },
145153
case_insensitive: { type: 'boolean', description: 'Case-insensitive search' },
146154
head_limit: { type: 'number', description: 'Max results to return. Default: 250' },
147155
multiline: { type: 'boolean', description: 'Enable multiline mode (patterns span lines). Default: false' },

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blockrun/runcode",
3-
"version": "1.6.3",
3+
"version": "1.6.4",
44
"description": "RunCode — AI coding agent powered by 41+ models. Pay per use with USDC.",
55
"type": "module",
66
"bin": {

src/tools/bash.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ async function execute(input: Record<string, unknown>, ctx: ExecutionScope): Pro
2626
const shell = process.env.SHELL || '/bin/bash';
2727
const child = spawn(shell, ['-c', command], {
2828
cwd: ctx.workingDir,
29-
env: { ...process.env },
29+
env: {
30+
...process.env,
31+
RUNCODE: '1', // Let scripts detect they're running inside runcode
32+
RUNCODE_WORKDIR: ctx.workingDir,
33+
},
3034
stdio: ['ignore', 'pipe', 'pipe'],
3135
});
3236

src/tools/grep.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface GrepInput {
1313
glob?: string;
1414
output_mode?: 'content' | 'files_with_matches' | 'count';
1515
context?: number;
16+
before_context?: number;
17+
after_context?: number;
1618
case_insensitive?: boolean;
1719
head_limit?: number;
1820
multiline?: boolean;
@@ -73,6 +75,9 @@ function runRipgrep(
7375
args.push('-n');
7476
if (opts.context && opts.context > 0) {
7577
args.push(`-C${opts.context}`);
78+
} else {
79+
if (opts.before_context && opts.before_context > 0) args.push(`-B${opts.before_context}`);
80+
if (opts.after_context && opts.after_context > 0) args.push(`-A${opts.after_context}`);
7681
}
7782
break;
7883
}
@@ -183,6 +188,8 @@ export const grepCapability: CapabilityHandler = {
183188
description: 'Output mode: "content" (matching lines), "files_with_matches" (file paths), "count" (match counts). Default: files_with_matches',
184189
},
185190
context: { type: 'number', description: 'Lines of context around each match (content mode only)' },
191+
before_context: { type: 'number', description: 'Lines before each match (-B, content mode)' },
192+
after_context: { type: 'number', description: 'Lines after each match (-A, content mode)' },
186193
case_insensitive: { type: 'boolean', description: 'Case-insensitive search' },
187194
head_limit: { type: 'number', description: 'Max results to return. Default: 250' },
188195
multiline: { type: 'boolean', description: 'Enable multiline mode (patterns span lines). Default: false' },

0 commit comments

Comments
 (0)