feat(core): Re-download rg binary if it is deleted. (#8126)

This commit is contained in:
joshualitt
2025-09-11 15:18:29 -07:00
committed by GitHub
parent b2c3523ecd
commit 2ccb9839d3
2 changed files with 73 additions and 3 deletions
+13 -2
View File
@@ -20,7 +20,7 @@ import { Storage } from '../config/storage.js';
const DEFAULT_TOTAL_MAX_MATCHES = 20000;
function getRgPath() {
function getRgPath(): string {
return path.join(Storage.getGlobalBinDir(), 'rg');
}
@@ -36,6 +36,16 @@ export async function canUseRipgrep(): Promise<boolean> {
return await fileExists(getRgPath());
}
/**
* Ensures `rg` is downloaded, or throws.
*/
export async function ensureRgPath(): Promise<string> {
if (await canUseRipgrep()) {
return getRgPath();
}
throw new Error('Cannot use ripgrep.');
}
/**
* Parameters for the GrepTool
*/
@@ -310,8 +320,9 @@ class GrepToolInvocation extends BaseToolInvocation<
rgArgs.push(absolutePath);
try {
const rgPath = await ensureRgPath();
const output = await new Promise<string>((resolve, reject) => {
const child = spawn(getRgPath(), rgArgs, {
const child = spawn(rgPath, rgArgs, {
windowsHide: true,
});