From 0a77da779a056fa3db8265bd9a7d2108688c966c Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 29 May 2026 14:23:17 +0800 Subject: [PATCH] fix(agent-core): handle ripgrep cross-device install --- .changeset/fix-ripgrep-cross-device-copy.md | 6 ++++++ packages/agent-core/src/tools/support/rg-locator.ts | 13 ++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changeset/fix-ripgrep-cross-device-copy.md diff --git a/.changeset/fix-ripgrep-cross-device-copy.md b/.changeset/fix-ripgrep-cross-device-copy.md new file mode 100644 index 0000000000..a4b15a9cb5 --- /dev/null +++ b/.changeset/fix-ripgrep-cross-device-copy.md @@ -0,0 +1,6 @@ +--- +"@moonshot-ai/agent-core": patch +"@moonshot-ai/kimi-code": patch +--- + +Fix automatic ripgrep installation when temporary files are on another filesystem. diff --git a/packages/agent-core/src/tools/support/rg-locator.ts b/packages/agent-core/src/tools/support/rg-locator.ts index f8b0ec002f..88ae3610f6 100644 --- a/packages/agent-core/src/tools/support/rg-locator.ts +++ b/packages/agent-core/src/tools/support/rg-locator.ts @@ -14,7 +14,7 @@ import { createHash } from 'node:crypto'; import { createWriteStream, existsSync } from 'node:fs'; -import { chmod, mkdir, mkdtemp, readFile, rename, rm, stat } from 'node:fs/promises'; +import { chmod, copyFile, mkdir, mkdtemp, readFile, rename, rm, stat } from 'node:fs/promises'; import { homedir, tmpdir } from 'node:os'; import { basename, join } from 'pathe'; import { Readable } from 'node:stream'; @@ -243,8 +243,15 @@ async function downloadAndInstallRg(shareDir: string): Promise { 'CDN content may have changed.', ); } - await rename(extracted, destination); - await chmod(destination, 0o755); + const installDir = await mkdtemp(join(binDir, '.rg-install-')); + const staged = join(installDir, rgBinaryName()); + try { + await copyFile(extracted, staged); + await chmod(staged, 0o755); + await rename(staged, destination); + } finally { + await rm(installDir, { recursive: true, force: true }); + } } return destination; } finally {