diff --git a/packages/junior/src/chat/tools/sandbox/grep.ts b/packages/junior/src/chat/tools/sandbox/grep.ts index 1f32223249..0773708c94 100644 --- a/packages/junior/src/chat/tools/sandbox/grep.ts +++ b/packages/junior/src/chat/tools/sandbox/grep.ts @@ -334,7 +334,7 @@ async function grepFilesWithRipgrep(params: { cause: new Error(detail), }); } - if (/regex parse error|error parsing regex/i.test(detail)) { + if (/regex parse error|error parsing regex|is not allowed in a regex/i.test(detail)) { throw new ToolInputError(`Invalid regex pattern: ${params.pattern}`, { cause: new Error(detail), }); diff --git a/packages/junior/tests/unit/tools/sandbox/file-tools.test.ts b/packages/junior/tests/unit/tools/sandbox/file-tools.test.ts index cf65c1f4e5..988662413e 100644 --- a/packages/junior/tests/unit/tools/sandbox/file-tools.test.ts +++ b/packages/junior/tests/unit/tools/sandbox/file-tools.test.ts @@ -416,6 +416,24 @@ describe("sandbox file tools", () => { message: "Invalid glob: {foo,{bar,baz}}", }); + const literalNewline: SandboxCommandRunner = async () => ({ + exitCode: 2, + stderr: 'rg: the literal "\\n" is not allowed in a regex', + stdout: "", + }); + + await expect( + grepFiles({ + fs: memory.fs, + path: "src", + pattern: "foo\nbar", + runCommand: literalNewline, + }), + ).rejects.toMatchObject({ + name: "ToolInputError", + message: "Invalid regex pattern: foo\nbar", + }); + const lifecycleFailure = new Error("sandbox_stopped"); await expect( findFiles({