fix: improve shell wrapper stripping to handle quoted cd paths

This commit is contained in:
Mohamed Boudra
2026-02-03 16:29:48 +07:00
parent 14b0db55b0
commit 4c5651fddc
4 changed files with 51 additions and 10 deletions
@@ -65,6 +65,21 @@ describe("parseToolCallDisplay", () => {
}
});
test("strips shell + cd wrapper from command (Codex exec_command style)", () => {
const input = {
command:
'/bin/zsh -lc "cd /Users/moboudra/dev/paseo && nl -ba packages/app/src/utils/tool-call-parsers.test.ts | sed -n \'150,260p\'"',
};
const display: ToolCallDisplay = parseToolCallDisplay("shell", input, undefined);
expect(display.type).toBe("shell");
if (display.type === "shell") {
expect(display.command).toBe(
"nl -ba packages/app/src/utils/tool-call-parsers.test.ts | sed -n '150,260p'"
);
}
});
test("handles command as array", () => {
const input = { command: ["git", "status"] };
const result = { type: "command", output: "On branch main" };
+3 -1
View File
@@ -1,5 +1,6 @@
import stripAnsi from "strip-ansi";
import { z } from "zod";
import { stripShellWrapperPrefix } from "@paseo/server/utils/tool-call-parsers";
import { getNowMs, isPerfLoggingEnabled, perfLog } from "./perf";
const TOOL_CALL_DIFF_LOG_TAG = "[ToolCallDiff]";
@@ -964,9 +965,10 @@ const ShellToolCallSchema = z
result: z.unknown(),
})
.transform((data) => {
const command = Array.isArray(data.input.command)
const commandRaw = Array.isArray(data.input.command)
? data.input.command.join(" ")
: data.input.command;
const command = stripShellWrapperPrefix(commandRaw);
// Try parsing as success result first
const resultParsed = ShellResultSchema.safeParse(data.result);