Skip to content

Commit 2bd0700

Browse files
viyatb-oaicodex
andcommitted
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>
1 parent 25cf5d7 commit 2bd0700

5 files changed

Lines changed: 16 additions & 39 deletions

File tree

codex-rs/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ mod sandbox_tags;
8686
pub mod sandboxing;
8787
mod session_prefix;
8888
mod session_startup_prewarm;
89-
mod shell_detect;
9089
pub mod skills;
9190
pub(crate) use skills::SkillError;
9291
pub(crate) use skills::SkillInjections;

codex-rs/core/src/shell.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::shell_detect::detect_shell_type;
21
use crate::shell_snapshot::ShellSnapshot;
2+
use codex_shell_command::shell_detect::ShellType as DetectedShellType;
3+
use codex_shell_command::shell_detect::detect_shell_type as detect_known_shell_type;
34
use serde::Deserialize;
45
use serde::Serialize;
56
use std::path::PathBuf;
@@ -88,6 +89,16 @@ impl PartialEq for Shell {
8889

8990
impl Eq for Shell {}
9091

92+
fn detect_shell_type(shell_path: &PathBuf) -> Option<ShellType> {
93+
match detect_known_shell_type(shell_path)? {
94+
DetectedShellType::Zsh => Some(ShellType::Zsh),
95+
DetectedShellType::Bash => Some(ShellType::Bash),
96+
DetectedShellType::PowerShell => Some(ShellType::PowerShell),
97+
DetectedShellType::Sh => Some(ShellType::Sh),
98+
DetectedShellType::Cmd => Some(ShellType::Cmd),
99+
}
100+
}
101+
91102
#[cfg(unix)]
92103
fn get_user_shell_path() -> Option<PathBuf> {
93104
let uid = unsafe { libc::getuid() };

codex-rs/core/src/shell_detect.rs

Lines changed: 0 additions & 34 deletions
This file was deleted.

codex-rs/shell-command/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Command parsing and safety utilities shared across Codex crates.
22
3-
mod shell_detect;
3+
pub mod shell_detect;
44

55
pub mod bash;
66
pub(crate) mod command_safety;

codex-rs/shell-command/src/shell_detect.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use std::path::PathBuf;
22

3+
/// Shell executable families that Codex treats as known command wrappers.
34
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
4-
pub(crate) enum ShellType {
5+
pub enum ShellType {
56
Zsh,
67
Bash,
78
PowerShell,
89
Sh,
910
Cmd,
1011
}
1112

12-
pub(crate) fn detect_shell_type(shell_path: &PathBuf) -> Option<ShellType> {
13+
pub fn detect_shell_type(shell_path: &PathBuf) -> Option<ShellType> {
1314
let shell_text = shell_path.as_os_str().to_str()?;
1415
// Keep this exact: repo-local files named like shells must not inherit
1516
// shell-wrapper trust in approval or display decisions.

0 commit comments

Comments
 (0)