mirror of
https://github.com/openai/codex.git
synced 2026-11-09 20:50:33 +00:00
refactor: share shell wrapper detection
Expose the known-shell detector from codex-shell-command and map it into codex-core's runtime shell type. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -86,7 +86,6 @@ mod sandbox_tags;
|
||||
pub mod sandboxing;
|
||||
mod session_prefix;
|
||||
mod session_startup_prewarm;
|
||||
mod shell_detect;
|
||||
pub mod skills;
|
||||
pub(crate) use skills::SkillError;
|
||||
pub(crate) use skills::SkillInjections;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::shell_detect::detect_shell_type;
|
||||
use crate::shell_snapshot::ShellSnapshot;
|
||||
use codex_shell_command::shell_detect::ShellType as DetectedShellType;
|
||||
use codex_shell_command::shell_detect::detect_shell_type as detect_known_shell_type;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::path::PathBuf;
|
||||
@@ -88,6 +89,16 @@ impl PartialEq for Shell {
|
||||
|
||||
impl Eq for Shell {}
|
||||
|
||||
fn detect_shell_type(shell_path: &PathBuf) -> Option<ShellType> {
|
||||
match detect_known_shell_type(shell_path)? {
|
||||
DetectedShellType::Zsh => Some(ShellType::Zsh),
|
||||
DetectedShellType::Bash => Some(ShellType::Bash),
|
||||
DetectedShellType::PowerShell => Some(ShellType::PowerShell),
|
||||
DetectedShellType::Sh => Some(ShellType::Sh),
|
||||
DetectedShellType::Cmd => Some(ShellType::Cmd),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn get_user_shell_path() -> Option<PathBuf> {
|
||||
let uid = unsafe { libc::getuid() };
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
use crate::shell::ShellType;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub(crate) fn detect_shell_type(shell_path: &PathBuf) -> Option<ShellType> {
|
||||
let shell_text = shell_path.as_os_str().to_str()?;
|
||||
// Keep this exact: repo-local files named like shells must not inherit
|
||||
// shell-wrapper trust in approval or display decisions.
|
||||
match shell_text {
|
||||
"zsh" | "/bin/zsh" | "/usr/bin/zsh" | "/usr/local/bin/zsh" | "/opt/homebrew/bin/zsh" => {
|
||||
Some(ShellType::Zsh)
|
||||
}
|
||||
"sh" | "/bin/sh" | "/usr/bin/sh" => Some(ShellType::Sh),
|
||||
"bash"
|
||||
| "/bin/bash"
|
||||
| "/usr/bin/bash"
|
||||
| "/usr/local/bin/bash"
|
||||
| "/opt/homebrew/bin/bash" => Some(ShellType::Bash),
|
||||
"pwsh"
|
||||
| "powershell"
|
||||
| "pwsh.exe"
|
||||
| "powershell.exe"
|
||||
| "/usr/local/bin/pwsh"
|
||||
| "/usr/bin/pwsh"
|
||||
| "/bin/pwsh"
|
||||
| "/opt/homebrew/bin/pwsh" => Some(ShellType::PowerShell),
|
||||
"cmd" | "cmd.exe" => Some(ShellType::Cmd),
|
||||
_ => match shell_text.replace('\\', "/").to_ascii_lowercase().as_str() {
|
||||
"c:/windows/system32/cmd.exe" => Some(ShellType::Cmd),
|
||||
"c:/windows/system32/windowspowershell/v1.0/powershell.exe"
|
||||
| "c:/program files/powershell/7/pwsh.exe" => Some(ShellType::PowerShell),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Command parsing and safety utilities shared across Codex crates.
|
||||
|
||||
mod shell_detect;
|
||||
pub mod shell_detect;
|
||||
|
||||
pub mod bash;
|
||||
pub(crate) mod command_safety;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Shell executable families that Codex treats as known command wrappers.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub(crate) enum ShellType {
|
||||
pub enum ShellType {
|
||||
Zsh,
|
||||
Bash,
|
||||
PowerShell,
|
||||
@@ -9,7 +10,7 @@ pub(crate) enum ShellType {
|
||||
Cmd,
|
||||
}
|
||||
|
||||
pub(crate) fn detect_shell_type(shell_path: &PathBuf) -> Option<ShellType> {
|
||||
pub fn detect_shell_type(shell_path: &PathBuf) -> Option<ShellType> {
|
||||
let shell_text = shell_path.as_os_str().to_str()?;
|
||||
// Keep this exact: repo-local files named like shells must not inherit
|
||||
// shell-wrapper trust in approval or display decisions.
|
||||
|
||||
Reference in New Issue
Block a user