Skip to content

Plugin: trim shell launcher wrappers from command approvals#33

Open
huntharo wants to merge 1 commit intopwrdrvr:mainfrom
huntharo:codex/trim-shell-launcher-approvals
Open

Plugin: trim shell launcher wrappers from command approvals#33
huntharo wants to merge 1 commit intopwrdrvr:mainfrom
huntharo:codex/trim-shell-launcher-approvals

Conversation

@huntharo
Copy link
Contributor

Summary

Strips /bin/zsh -lc '...', bash -lc '...', and similar shell launcher wrappers from the Command block in approval prompts, matching the display behavior of Codex Desktop and CLI.

Why this matters

Command approval prompts currently show the full shell invocation:

/bin/zsh -lc 'git add README.md && git commit -m "docs: simplify README opening"'

The shell launcher is an implementation detail — users shouldn't need to read past it to understand what Codex is about to run. The expected display is:

git add README.md && git commit -m "docs: simplify README opening"

This matches upstream behavior documented in #9, which identifies strip_bash_lc_and_escape() in codex-rs/tui/src/exec_command.rs as the reference implementation.

Changes

  • Added stripShellLauncher(command: string): string to src/pending-input.ts. Detects the pattern [/path/]shell -lc '...' using a single regex covering bash, zsh, sh, dash, ksh, tcsh, and fish with or without an absolute path prefix. Falls back to the raw command if no match.
  • Applied stripShellLauncher() in buildPendingPromptText() (src/pending-input.ts:703) before passing to buildMarkdownCodeBlock. The raw command is unchanged for approval transport — only the display is simplified.
  • Exported stripShellLauncher so it can be tested directly.

Testing

Added 7 test cases to src/pending-input.test.ts covering:

  • /bin/zsh -lc '...'
  • /bin/bash -lc '...'
  • bash -lc '...'
  • zsh -lc '...' with double-quoted inner content
  • /usr/bin/zsh -lc '...'
  • Plain commands that pass through unchanged (git status, npm install)

All 122 tests pass (pnpm typecheck + pnpm test).

Fixes #9

This contribution was developed with AI assistance (Claude Code).

Strips /bin/zsh -lc '...', bash -lc '...', and similar wrappers from the
Command block in approval prompts. 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 display is
simplified. Adds stripShellLauncher() helper to pending-input.ts with
test coverage for all common launcher variants.

Fixes pwrdrvr#9
Copy link

@mvanhorn mvanhorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The regex handles the common launcher patterns correctly - greedy [\s\S]* with backreference matches the outermost quotes, and the fallback returns the raw command unchanged. Good call preserving the raw command for approval transport and only simplifying the display.

Recommendation

Looks good to merge.


Review assisted by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin: trim shell launcher wrappers from command approvals

2 participants