fix: add rg to path (#146)

This commit is contained in:
Charles Packer
2025-12-01 22:29:05 -08:00
committed by GitHub
parent f1f507a45d
commit bc558e5c5b
3 changed files with 47 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import type { ExecOptions } from "node:child_process";
import { exec, spawn } from "node:child_process";
import { promisify } from "node:util";
import { backgroundProcesses, getNextBashId } from "./process_manager.js";
import { getShellEnv } from "./shellEnv.js";
import { LIMITS, truncateByChars } from "./truncation.js";
import { validateRequiredParams } from "./validation.js";
@@ -60,7 +61,7 @@ export async function bash(args: BashArgs): Promise<BashResult> {
const childProcess = spawn(command, [], {
shell: true,
cwd: userCwd,
env: { ...process.env },
env: getShellEnv(),
});
backgroundProcesses.set(bashId, {
process: childProcess,
@@ -118,7 +119,7 @@ export async function bash(args: BashArgs): Promise<BashResult> {
timeout: effectiveTimeout,
maxBuffer: 10 * 1024 * 1024,
cwd: userCwd,
env: { ...process.env },
env: getShellEnv(),
signal,
};
const { stdout, stderr } = await execAsync(command, options);

View File

@@ -1,5 +1,6 @@
import { spawn } from "node:child_process";
import * as path from "node:path";
import { getShellEnv } from "./shellEnv.js";
import { validateRequiredParams } from "./validation.js";
interface ShellArgs {
@@ -50,7 +51,7 @@ export async function shell(args: ShellArgs): Promise<ShellResult> {
const child = spawn(executable, execArgs, {
cwd,
env: process.env,
env: getShellEnv(),
stdio: ["ignore", "pipe", "pipe"],
});

View File

@@ -0,0 +1,42 @@
/**
* Shell environment utilities
* Provides enhanced environment variables for shell execution,
* including bundled tools like ripgrep in PATH.
*/
import { createRequire } from "node:module";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
/**
* Get the directory containing the bundled ripgrep binary.
* Returns undefined if @vscode/ripgrep is not installed.
*/
function getRipgrepBinDir(): string | undefined {
try {
const __filename = fileURLToPath(import.meta.url);
const require = createRequire(__filename);
const rgPackage = require("@vscode/ripgrep");
// rgPath is the full path to the binary, we want the directory
return path.dirname(rgPackage.rgPath);
} catch (_error) {
return undefined;
}
}
/**
* Get enhanced environment variables for shell execution.
* Includes bundled tools (like ripgrep) in PATH.
*/
export function getShellEnv(): NodeJS.ProcessEnv {
const env = { ...process.env };
// Add ripgrep bin directory to PATH if available
const rgBinDir = getRipgrepBinDir();
if (rgBinDir) {
const currentPath = env.PATH || "";
env.PATH = `${rgBinDir}${path.delimiter}${currentPath}`;
}
return env;
}