Commit Graph

5 Commits

  • [codex] Handle PowerShell UTF-8 setup failures (#24949)
    Fixes #12496.
    
    ## Why
    
    Windows sandboxed PowerShell commands can run under
    `ConstrainedLanguage` on some machines, especially enterprise-managed
    Windows environments. In that mode, our PowerShell command prelude could
    fail before every command because it directly assigned
    `[Console]::OutputEncoding` to UTF-8. The actual user command still ran,
    but Codex surfaced noisy `Cannot set property. Property setting is
    supported only on core types in this language mode.` output for every
    shell call.
    
    ## What Changed
    
    - Makes the PowerShell UTF-8 output encoding prelude best-effort by
    wrapping the assignment in `try { ... } catch {}`.
    - Keeps the existing UTF-8 behavior when PowerShell allows the
    assignment.
    - Adds focused tests for adding the prelude and avoiding duplicate
    prelude insertion.
    
    ## Validation
    
    - `cargo fmt -p codex-shell-command`
    - `cargo check -p codex-shell-command`
    - `git diff --check`
    - Verified a local `ConstrainedLanguage` PowerShell probe prints only
    the command output with no property-setting error.
    - Verified `codex exec` from a temporary `chcp 437` context reports
    `utf-8` / `65001` and preserves non-ASCII output (`café`, `漢字`).
  • execpolicy: unwrap PowerShell -Command wrappers on Windows (#20336)
    ## Why
    On Windows, Codex runs shell commands through a top-level
    `powershell.exe -NoProfile -Command ...` wrapper. `execpolicy` was
    matching that wrapper instead of the inner command, so prefix rules like
    `["git", "push"]` did not fire for PowerShell-wrapped commands even
    though the same normalization already happens for `bash -lc` on Unix.
    
    This change makes the Windows shell wrapper transparent to rule matching
    while preserving the existing Windows unmatched-command safelist and
    dangerous-command heuristics.
    
    ## What changed
    - add `parse_powershell_command_plain_commands()` in
    `shell-command/src/powershell.rs` to unwrap the top-level PowerShell
    `-Command` body with `extract_powershell_command()` and parse it with
    the existing PowerShell AST parser
    - update `core/src/exec_policy.rs` so `commands_for_exec_policy()`
    treats top-level PowerShell wrappers like `bash -lc` and evaluates rules
    against the parsed inner commands
    - carry a small `ExecPolicyCommandOrigin` through unmatched-command
    evaluation and expose `is_safe_powershell_words()` /
    `is_dangerous_powershell_words()` so Windows safelist and
    dangerous-command checks still work after unwrap
    - add Windows-focused tests for wrapped PowerShell prompt/allow matches,
    wrapper parsing, and unmatched safe/dangerous inner commands, and
    re-enable the end-to-end `execpolicy_blocks_shell_invocation` test on
    Windows
    
    ## Testing
    - `cargo test -p codex-shell-command`
  • [codex] Remove unused Rust helpers (#17146)
    ## Summary
    
    Removes high-confidence unused Rust helper functions and exports across
    `codex-tui`, `codex-shell-command`, and utility crates.
    
    The cleanup includes dead TUI helper methods, unused
    path/string/elapsed/fuzzy-match utilities, an unused Windows PowerShell
    lookup helper, and the unused terminal palette version counter. This
    keeps the remaining public surface smaller without changing behavior.
    
    ## Validation
    
    - `just fmt`
    - `cargo test -p codex-tui -p codex-shell-command -p codex-utils-elapsed
    -p codex-utils-fuzzy-match -p codex-utils-string -p codex-utils-path`
    - `just fix -p codex-tui -p codex-shell-command -p codex-utils-elapsed
    -p codex-utils-fuzzy-match -p codex-utils-string -p codex-utils-path`
    - `git diff --check`
  • [codex] Make AbsolutePathBuf joins infallible (#16981)
    Having to check for errors every time join is called is painful and
    unnecessary.
  • chore: rename codex-command to codex-shell-command (#11378)
    This addresses some post-merge feedback on
    https://github.com/openai/codex/pull/11361:
    
    - crate rename
    - reuse `detect_shell_type()` utility