Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/pending-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
questionnaireCurrentQuestionHasAnswer,
questionnaireIsComplete,
requestToken,
stripShellLauncher,
} from "./pending-input.js";

describe("pending-input helpers", () => {
Expand Down Expand Up @@ -270,6 +271,19 @@ Guidance:
expect(questionnaireCurrentQuestionHasAnswer(questionnaire)).toBe(true);
});

it("strips shell launcher wrappers from commands for display", () => {
expect(stripShellLauncher("/bin/zsh -lc 'git status'")).toBe("git status");
expect(stripShellLauncher("/bin/bash -lc 'npm install'")).toBe("npm install");
expect(stripShellLauncher("bash -lc 'make build'")).toBe("make build");
expect(
stripShellLauncher('zsh -lc \'git add README.md && git commit -m "docs: update"\''),
).toBe('git add README.md && git commit -m "docs: update"');
expect(stripShellLauncher("/usr/bin/zsh -lc 'cargo test'")).toBe("cargo test");
// Non-launcher commands pass through unchanged
expect(stripShellLauncher("git status")).toBe("git status");
expect(stripShellLauncher("npm install")).toBe("npm install");
});

it("parses structured request_user_input questions into questionnaire state", () => {
const state = createPendingInputState({
method: "item/tool/requestUserInput",
Expand Down
20 changes: 19 additions & 1 deletion src/pending-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,24 @@ function buildMarkdownCodeBlock(text: string, language = ""): string {
return `${fence}${languageTag}\n${normalized}\n${fence}`;
}

/**
* Strips common shell launcher wrappers from a command string for display.
* For example: `/bin/zsh -lc 'git status'` → `git status`
*
* Matches upstream Codex Desktop behavior (strip_bash_lc_and_escape in
* codex-rs/tui/src/exec_command.rs). The raw command is preserved for
* approval transport; only the displayed form is simplified.
*/
export function stripShellLauncher(command: string): string {
const match = command.match(
/^(?:\/[/\w]*\/)?(?:bash|zsh|sh|dash|ksh|tcsh|fish)\s+-lc\s+(['"])([\s\S]*)\1\s*$/,
);
if (match) {
return match[2];
}
return command;
}

export function buildPendingPromptText(params: {
method: string;
requestId: string;
Expand Down Expand Up @@ -682,7 +700,7 @@ export function buildPendingPromptText(params: {
"shellCommand",
]) ?? "";
if (command) {
lines.push("", "Command:", "", buildMarkdownCodeBlock(command, "sh"));
lines.push("", "Command:", "", buildMarkdownCodeBlock(stripShellLauncher(command), "sh"));
}
const grantRoot = findFirstStringByKeys(params.requestParams, ["grantRoot", "grant_root"]);
if (grantRoot) {
Expand Down