Bridge command generation to powershell when on Windows (#2319)

## What? Why? How?
- When running on Windows, codex often tries to invoke bash commands,
which commonly fail (unless WSL is installed)
- Fix: Detect if powershell is available and, if so, route commands to
it
- Also add a shell_name property to environmental context for codex to
default to powershell commands when running in that environment

## Testing
- Tested within WSL and powershell (e.g. get top 5 largest files within
a folder and validated that commands generated were powershell commands)
- Tested within Zsh
- Updated unit tests

---------

Co-authored-by: Eddy Escardo <eddy@openai.com>
This commit is contained in:
eddy-win
2025-08-20 16:30:34 -07:00
committed by GitHub
parent 5ab30c73f3
commit 050b9baeb6
6 changed files with 259 additions and 15 deletions

View File

@@ -511,6 +511,7 @@ impl Session {
turn_context.cwd.to_path_buf(),
turn_context.approval_policy,
turn_context.sandbox_policy.clone(),
sess.user_shell.clone(),
)));
sess.record_conversation_items(&conversation_items).await;
@@ -1070,6 +1071,7 @@ async fn submission_loop(
new_cwd,
new_approval_policy,
new_sandbox_policy,
sess.user_shell.clone(),
))])
.await;
}
@@ -2051,18 +2053,20 @@ pub struct ExecInvokeArgs<'a> {
pub stdout_stream: Option<StdoutStream>,
}
fn maybe_run_with_user_profile(
fn maybe_translate_shell_command(
params: ExecParams,
sess: &Session,
turn_context: &TurnContext,
) -> ExecParams {
if turn_context.shell_environment_policy.use_profile {
let command = sess
let should_translate = matches!(sess.user_shell, crate::shell::Shell::PowerShell(_))
|| turn_context.shell_environment_policy.use_profile;
if should_translate
&& let Some(command) = sess
.user_shell
.format_default_shell_invocation(params.command.clone());
if let Some(command) = command {
return ExecParams { command, ..params };
}
.format_default_shell_invocation(params.command.clone())
{
return ExecParams { command, ..params };
}
params
}
@@ -2227,7 +2231,7 @@ async fn handle_container_exec_with_params(
),
};
let params = maybe_run_with_user_profile(params, sess, turn_context);
let params = maybe_translate_shell_command(params, sess, turn_context);
let output_result = sess
.run_exec_with_events(
turn_diff_tracker,