Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): support just-bash search compatibility (#1545)

prha279b5e6b368f
diff --git a/.changeset/clean-mount-search.md b/.changeset/clean-mount-search.md
new file mode 100644
index 000000000..d371ea327
--- /dev/null
+++ b/.changeset/clean-mount-search.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Use compatible POSIX search fallbacks in sandboxes whose `rg` implementation lacks the options required by eve, and surface command errors instead of reporting them as empty results.
diff --git a/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts b/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts
index 656b963de..e36ba53b2 100644
--- a/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts
@@ -10,6 +10,8 @@ import {
createJustBashSandboxBackend,
pruneJustBashSandboxTemplates,
} from "#execution/sandbox/bindings/just-bash.js";
+import { executeGlobOnSandbox } from "#execution/sandbox/glob-tool.js";
+import { executeGrepOnSandbox } from "#execution/sandbox/grep-tool.js";
import type { SandboxBackend } from "#public/definitions/sandbox-backend.js";
import { justbash } from "#public/sandbox/backends/just-bash.js";
@@ -101,6 +103,20 @@ describe("just-bash sandbox file API", () => {
expect(factoryCalls).toBe(1);
expect(await handle.session.readTextFile({ path: "/source/instructions.md" })).toBe("before");
+ await expect(
+ executeGlobOnSandbox(handle.session, { path: "/source", pattern: "*" }),
+ ).resolves.toMatchObject({
+ content: "/source/instructions.md",
+ count: 1,
+ path: "/source",
+ });
+ await expect(
+ executeGrepOnSandbox(handle.session, { path: "/source", pattern: "before" }),
+ ).resolves.toMatchObject({
+ content: "/source/instructions.md:1:before",
+ matchCount: 1,
+ path: "/source",
+ });
await handle.session.writeTextFile({
content: "after",
path: "/source/instructions.md",
diff --git a/packages/eve/src/execution/sandbox/glob-tool.ts b/packages/eve/src/execution/sandbox/glob-tool.ts
index ca7ed5704..08b84ebe5 100644
--- a/packages/eve/src/execution/sandbox/glob-tool.ts
+++ b/packages/eve/src/execution/sandbox/glob-tool.ts
@@ -67,7 +67,10 @@ export async function executeGlobOnSandbox(
// missing) indicates a real failure. Surface these as structured
// errors rather than silently pretending the search returned zero
// files.
- if (result.exitCode !== 0 && result.exitCode !== 1) {
+ if (
+ (result.exitCode !== 0 && result.exitCode !== 1) ||
+ (result.exitCode === 1 && result.stderr.trim().length > 0)
+ ) {
throw buildGlobExecutionError(command, result.exitCode, result.stderr);
}
@@ -148,7 +151,7 @@ function buildRipgrepCommand(input: BuildCommandInput): string {
"rg --files --hidden",
"--glob '!.git/*'",
`--glob ${shellQuote(input.pattern)}`,
- `-- ${shellQuote(input.normalizedPath)}`,
+ shellQuote(input.normalizedPath),
].join(" ");
}
diff --git a/packages/eve/src/execution/sandbox/grep-tool.ts b/packages/eve/src/execution/sandbox/grep-tool.ts
index 334ece417..3fdb4413d 100644
--- a/packages/eve/src/execution/sandbox/grep-tool.ts
+++ b/packages/eve/src/execution/sandbox/grep-tool.ts
@@ -87,7 +87,10 @@ export async function executeGrepOnSandbox(
// Any other exit code (e.g. 127 from bash when the tool is missing)
// indicates a real failure. Surface these as structured errors
// rather than silently pretending the search returned zero matches.
- if (result.exitCode !== 0 && result.exitCode !== 1) {
+ if (
+ (result.exitCode !== 0 && result.exitCode !== 1) ||
+ (result.exitCode === 1 && result.stderr.trim().length > 0)
+ ) {
throw buildGrepExecutionError(command, result.exitCode, result.stderr);
}
@@ -162,7 +165,7 @@ function buildRipgrepCommand(input: BuildCommandInput): string {
* Builds the POSIX fallback form of the grep command using `grep -rn`.
*/
function buildPosixGrepCommand(input: BuildCommandInput): string {
- const parts: string[] = ["grep", "-r", "-n", "--color=never", "--exclude-dir=.git"];
+ const parts: string[] = ["grep", "-r", "-n", "--exclude-dir=.git"];
if (input.ignoreCase) {
parts.push("-i");
@@ -186,8 +189,7 @@ function buildPosixGrepCommand(input: BuildCommandInput): string {
// `-m` limits matches per file, analogous to ripgrep's `--max-count`.
parts.push(`-m ${input.effectiveLimit}`);
- parts.push("--");
- parts.push(shellQuote(input.pattern));
+ parts.push(`-e ${shellQuote(input.pattern)}`);
parts.push(shellQuote(input.normalizedPath));
return parts.join(" ");
diff --git a/packages/eve/src/execution/sandbox/ripgrep-probe.ts b/packages/eve/src/execution/sandbox/ripgrep-probe.ts
index 2a7ef17ca..08ab59f70 100644
--- a/packages/eve/src/execution/sandbox/ripgrep-probe.ts
+++ b/packages/eve/src/execution/sandbox/ripgrep-probe.ts
@@ -1,14 +1,18 @@
import type { SandboxSession } from "#public/definitions/sandbox.js";
/**
- * Memoizes the result of probing for `rg` (ripgrep) once per sandbox
- * session. The probe runs exactly one `command -v rg` per distinct
- * session object, regardless of how many grep/glob tool calls happen.
+ * Memoizes the result of probing for a compatible `rg` (ripgrep) once per
+ * sandbox session, regardless of how many grep/glob tool calls happen.
*/
const probes = new Map<string, Promise<boolean>>();
+const RIPGREP_PROBE_COMMAND =
+ "command -v rg >/dev/null 2>&1 || exit 127; " +
+ "rg --line-number --color=never --hidden --glob '!.git/*' --max-count 1 -- " +
+ "'__eve_ripgrep_probe_never_matches__' /workspace";
+
/**
- * Returns `true` when `rg` is on PATH in the given sandbox session,
+ * Returns `true` when `rg` is on PATH and supports the options used by eve,
* `false` otherwise. Result is cached per session.
*
* Framework `grep` and `glob` tools call this to decide whether to use
@@ -36,6 +40,6 @@ export async function ripgrepIsAvailable(session: SandboxSession): Promise<boole
}
async function runProbe(session: SandboxSession): Promise<boolean> {
- const result = await session.run({ command: "command -v rg >/dev/null 2>&1" });
- return result.exitCode === 0;
+ const result = await session.run({ command: RIPGREP_PROBE_COMMAND });
+ return (result.exitCode === 0 || result.exitCode === 1) && result.stderr.trim().length === 0;
}
diff --git a/packages/eve/test/glob-tool.test.ts b/packages/eve/test/glob-tool.test.ts
index a32f9c90f..aadbeb496 100644
--- a/packages/eve/test/glob-tool.test.ts
+++ b/packages/eve/test/glob-tool.test.ts
@@ -15,15 +15,18 @@ import type { SandboxSession } from "../src/shared/sandbox-session.js";
interface FakeAccessOptions {
readonly pathResolver?: (path: string) => string;
/**
- * Exit code returned by the `command -v rg` probe that runs before
+ * Exit code returned by the ripgrep capability probe that runs before
* each glob call. Defaults to `0` (ripgrep is available) so tests
* exercise the ripgrep code path by default. Set to a non-zero
- * code to force the POSIX fallback branch.
+ * code other than `0` or `1` to force the POSIX fallback branch.
*/
readonly probeExitCode?: number;
}
-const PROBE_COMMAND = "command -v rg >/dev/null 2>&1";
+const PROBE_COMMAND =
+ "command -v rg >/dev/null 2>&1 || exit 127; " +
+ "rg --line-number --color=never --hidden --glob '!.git/*' --max-count 1 -- " +
+ "'__eve_ripgrep_probe_never_matches__' /workspace";
const HOME_PROBE_COMMAND = `printf '%s\\n' "$HOME"`;
function createFakeAccess(
@@ -329,7 +332,7 @@ describe("executeGlobOnSandbox", () => {
(sandbox) => executeGlobOnSandbox(sandbox, { pattern: "**/*.ts" }),
);
- expect(capturedCommand).toMatch(/-- '\/workspace'/);
+ expect(capturedCommand).toMatch(/'\/workspace'$/);
});
it("preserves /workspace-rooted output paths exactly as emitted", async () => {
@@ -368,7 +371,7 @@ describe("executeGlobOnSandbox", () => {
};
},
(sandbox) => executeGlobOnSandbox(sandbox, { pattern: "**/*.ts" }),
- { probeExitCode: 1 },
+ { probeExitCode: 127 },
)) as GlobResult;
// POSIX find, not ripgrep.
@@ -390,6 +393,15 @@ describe("executeGlobOnSandbox", () => {
).rejects.toThrow(/glob failed \(exit 2\).*IO error/s);
});
+ it("throws when ripgrep exits 1 with an error message", async () => {
+ await expect(
+ runInContext(
+ () => ({ exitCode: 1, stderr: "rg: unrecognized option '--'\n", stdout: "" }),
+ (sandbox) => executeGlobOnSandbox(sandbox, { pattern: "**/*.ts" }),
+ ),
+ ).rejects.toThrow(/glob failed \(exit 1\).*unrecognized option/s);
+ });
+
it("treats exit 1 as legitimate 'no files'", async () => {
const result = (await runInContext(
() => ({ exitCode: 1, stderr: "", stdout: "" }),
diff --git a/packages/eve/test/grep-tool.test.ts b/packages/eve/test/grep-tool.test.ts
index 452895d9b..bdf0680af 100644
--- a/packages/eve/test/grep-tool.test.ts
+++ b/packages/eve/test/grep-tool.test.ts
@@ -15,15 +15,18 @@ import type { SandboxSession } from "../src/shared/sandbox-session.js";
interface FakeAccessOptions {
readonly pathResolver?: (path: string) => string;
/**
- * Exit code returned by the `command -v rg` probe that runs before
+ * Exit code returned by the ripgrep capability probe that runs before
* each grep call. Defaults to `0` (ripgrep is available) so the
- * tests exercise the ripgrep code path by default. Set to a
- * non-zero code to force the POSIX fallback branch.
+ * tests exercise the ripgrep code path by default. Set to a code
+ * other than `0` or `1` to force the POSIX fallback branch.
*/
readonly probeExitCode?: number;
}
-const PROBE_COMMAND = "command -v rg >/dev/null 2>&1";
+const PROBE_COMMAND =
+ "command -v rg >/dev/null 2>&1 || exit 127; " +
+ "rg --line-number --color=never --hidden --glob '!.git/*' --max-count 1 -- " +
+ "'__eve_ripgrep_probe_never_matches__' /workspace";
const HOME_PROBE_COMMAND = `printf '%s\\n' "$HOME"`;
function createFakeAccess(
@@ -490,7 +493,7 @@ describe("executeGrepOnSandbox", () => {
};
},
(sandbox) => executeGrepOnSandbox(sandbox, { pattern: "foo" }),
- { probeExitCode: 1 },
+ { probeExitCode: 127 },
)) as GrepResult;
// POSIX grep with -r -n, not ripgrep.
@@ -509,7 +512,7 @@ describe("executeGrepOnSandbox", () => {
stdout: "",
}),
(sandbox) => executeGrepOnSandbox(sandbox, { pattern: "foo" }),
- { probeExitCode: 1 },
+ { probeExitCode: 127 },
),
).rejects.toThrow(/grep failed \(exit 2\).*IO error/s);
});
@@ -540,6 +543,15 @@ describe("executeGrepOnSandbox", () => {
expect(capturedCommand).not.toContain("--no-messages");
});
+ it("throws when ripgrep exits 1 with an error message", async () => {
+ await expect(
+ runInContext(
+ () => ({ exitCode: 1, stderr: "rg: invalid option\n", stdout: "" }),
+ (sandbox) => executeGrepOnSandbox(sandbox, { pattern: "needle" }),
+ ),
+ ).rejects.toThrow(/grep failed \(exit 1\).*invalid option/s);
+ });
+
it("treats exit 1 as legitimate 'no matches'", async () => {
const result = (await runInContext(
() => ({ exitCode: 1, stderr: "", stdout: "" }),