Skip to content

Commit 15901b8

Browse files
Merge pull request #102 from ScriptedAlchemy/sync-upstream-2025-12-12-2
chore: sync upstream/main (2025-12-12-2)
2 parents 47e4a20 + 37fb515 commit 15901b8

7 files changed

Lines changed: 198 additions & 35 deletions

File tree

‎codex-rs/core/src/command_safety/is_safe_command.rs‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,47 @@ fn is_safe_to_call_with_exec(command: &[String]) -> bool {
4747
.file_name()
4848
.and_then(|osstr| osstr.to_str())
4949
{
50+
Some(cmd) if cfg!(target_os = "linux") && matches!(cmd, "numfmt" | "tac") => true,
51+
5052
#[rustfmt::skip]
5153
Some(
5254
"cat" |
5355
"cd" |
56+
"cut" |
5457
"echo" |
58+
"expr" |
5559
"false" |
5660
"grep" |
5761
"head" |
62+
"id" |
5863
"ls" |
5964
"nl" |
65+
"paste" |
6066
"pwd" |
67+
"rev" |
68+
"seq" |
69+
"stat" |
6170
"tail" |
71+
"tr" |
6272
"true" |
73+
"uname" |
74+
"uniq" |
6375
"wc" |
64-
"which") => {
76+
"which" |
77+
"whoami") => {
6578
true
6679
},
6780

81+
Some("base64") => {
82+
const UNSAFE_BASE64_OPTIONS: &[&str] = &["-o", "--output"];
83+
84+
!command.iter().skip(1).any(|arg| {
85+
UNSAFE_BASE64_OPTIONS.contains(&arg.as_str())
86+
|| arg.starts_with("--output=")
87+
|| (arg.starts_with("-o") && arg != "-o")
88+
})
89+
}
90+
6891
Some("find") => {
6992
// Certain options to `find` can delete files, write to files, or
7093
// execute arbitrary commands, so we cannot auto-approve the
@@ -184,6 +207,7 @@ mod tests {
184207
fn known_safe_examples() {
185208
assert!(is_safe_to_call_with_exec(&vec_str(&["ls"])));
186209
assert!(is_safe_to_call_with_exec(&vec_str(&["git", "status"])));
210+
assert!(is_safe_to_call_with_exec(&vec_str(&["base64"])));
187211
assert!(is_safe_to_call_with_exec(&vec_str(&[
188212
"sed", "-n", "1,5p", "file.txt"
189213
])));
@@ -197,6 +221,14 @@ mod tests {
197221
assert!(is_safe_to_call_with_exec(&vec_str(&[
198222
"find", ".", "-name", "file.txt"
199223
])));
224+
225+
if cfg!(target_os = "linux") {
226+
assert!(is_safe_to_call_with_exec(&vec_str(&["numfmt", "1000"])));
227+
assert!(is_safe_to_call_with_exec(&vec_str(&["tac", "Cargo.toml"])));
228+
} else {
229+
assert!(!is_safe_to_call_with_exec(&vec_str(&["numfmt", "1000"])));
230+
assert!(!is_safe_to_call_with_exec(&vec_str(&["tac", "Cargo.toml"])));
231+
}
200232
}
201233

202234
#[test]
@@ -233,6 +265,21 @@ mod tests {
233265
}
234266
}
235267

268+
#[test]
269+
fn base64_output_options_are_unsafe() {
270+
for args in [
271+
vec_str(&["base64", "-o", "out.bin"]),
272+
vec_str(&["base64", "--output", "out.bin"]),
273+
vec_str(&["base64", "--output=out.bin"]),
274+
vec_str(&["base64", "-ob64.txt"]),
275+
] {
276+
assert!(
277+
!is_safe_to_call_with_exec(&args),
278+
"expected {args:?} to be considered unsafe due to output option"
279+
);
280+
}
281+
}
282+
236283
#[test]
237284
fn ripgrep_rules() {
238285
// Safe ripgrep invocations – none of the unsafe flags are present.

‎codex-rs/core/src/powershell.rs‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use std::path::PathBuf;
22

3+
#[cfg(windows)]
4+
use codex_utils_absolute_path::AbsolutePathBuf;
5+
36
use crate::shell::ShellType;
47
use crate::shell::detect_shell_type;
58

@@ -40,6 +43,93 @@ pub fn extract_powershell_command(command: &[String]) -> Option<(&str, &str)> {
4043
None
4144
}
4245

46+
/// This function attempts to find a valid PowerShell executable on the system.
47+
/// It first tries to find pwsh.exe, and if that fails, it tries to find
48+
/// powershell.exe.
49+
#[cfg(windows)]
50+
#[allow(dead_code)]
51+
pub(crate) fn try_find_powershellish_executable_blocking() -> Option<AbsolutePathBuf> {
52+
if let Some(pwsh_path) = try_find_pwsh_executable_blocking() {
53+
Some(pwsh_path)
54+
} else {
55+
try_find_powershell_executable_blocking()
56+
}
57+
}
58+
59+
/// This function attempts to find a powershell.exe executable on the system.
60+
#[cfg(windows)]
61+
pub(crate) fn try_find_powershell_executable_blocking() -> Option<AbsolutePathBuf> {
62+
try_find_powershellish_executable_in_path(&["powershell.exe"])
63+
}
64+
65+
/// This function attempts to find a pwsh.exe executable on the system.
66+
/// Note that pwsh.exe and powershell.exe are different executables:
67+
///
68+
/// - pwsh.exe is the cross-platform PowerShell Core (v6+) executable
69+
/// - powershell.exe is the Windows PowerShell (v5.1 and earlier) executable
70+
///
71+
/// Further, while powershell.exe is included by default on Windows systems,
72+
/// pwsh.exe must be installed separately by the user. And even when the user
73+
/// has installed pwsh.exe, it may not be available in the system PATH, in which
74+
/// case we attempt to locate it via other means.
75+
#[cfg(windows)]
76+
pub(crate) fn try_find_pwsh_executable_blocking() -> Option<AbsolutePathBuf> {
77+
if let Some(ps_home) = std::process::Command::new("cmd")
78+
.args(["/C", "pwsh", "-NoProfile", "-Command", "$PSHOME"])
79+
.output()
80+
.ok()
81+
.and_then(|out| {
82+
if !out.status.success() {
83+
return None;
84+
}
85+
let stdout = String::from_utf8_lossy(&out.stdout);
86+
let trimmed = stdout.trim();
87+
(!trimmed.is_empty()).then(|| trimmed.to_string())
88+
})
89+
{
90+
let candidate = AbsolutePathBuf::resolve_path_against_base("pwsh.exe", &ps_home);
91+
92+
if let Ok(candidate_abs_path) = candidate
93+
&& is_powershellish_executable_available(candidate_abs_path.as_path())
94+
{
95+
return Some(candidate_abs_path);
96+
}
97+
}
98+
99+
try_find_powershellish_executable_in_path(&["pwsh.exe"])
100+
}
101+
102+
#[cfg(windows)]
103+
fn try_find_powershellish_executable_in_path(candidates: &[&str]) -> Option<AbsolutePathBuf> {
104+
for candidate in candidates {
105+
let Ok(resolved_path) = which::which(candidate) else {
106+
continue;
107+
};
108+
109+
if !is_powershellish_executable_available(&resolved_path) {
110+
continue;
111+
}
112+
113+
let Ok(abs_path) = AbsolutePathBuf::from_absolute_path(resolved_path) else {
114+
continue;
115+
};
116+
117+
return Some(abs_path);
118+
}
119+
120+
None
121+
}
122+
123+
#[cfg(windows)]
124+
fn is_powershellish_executable_available(powershell_or_pwsh_exe: &std::path::Path) -> bool {
125+
// This test works for both powershell.exe and pwsh.exe.
126+
std::process::Command::new(powershell_or_pwsh_exe)
127+
.args(["-NoLogo", "-NoProfile", "-Command", "Write-Output ok"])
128+
.output()
129+
.map(|output| output.status.success())
130+
.unwrap_or(false)
131+
}
132+
43133
#[cfg(test)]
44134
mod tests {
45135
use super::extract_powershell_command;

‎codex-rs/core/src/skills/loader.rs‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ struct SkillFrontmatter {
2222
const SKILLS_FILENAME: &str = "SKILL.md";
2323
const SKILLS_DIR_NAME: &str = "skills";
2424
const REPO_ROOT_CONFIG_DIR_NAME: &str = ".codex";
25-
const MAX_NAME_LEN: usize = 100;
26-
const MAX_DESCRIPTION_LEN: usize = 500;
25+
const MAX_NAME_LEN: usize = 64;
26+
const MAX_DESCRIPTION_LEN: usize = 1024;
2727

2828
#[derive(Debug)]
2929
enum SkillParseError {
@@ -171,7 +171,7 @@ fn validate_field(
171171
if value.is_empty() {
172172
return Err(SkillParseError::MissingField(field_name));
173173
}
174-
if value.len() > max_len {
174+
if value.chars().count() > max_len {
175175
return Err(SkillParseError::InvalidField {
176176
field: field_name,
177177
reason: format!("exceeds maximum length of {max_len} characters"),
@@ -295,12 +295,22 @@ mod tests {
295295
#[test]
296296
fn enforces_length_limits() {
297297
let codex_home = tempfile::tempdir().expect("tempdir");
298-
let long_desc = "a".repeat(MAX_DESCRIPTION_LEN + 1);
299-
write_skill(&codex_home, "too-long", "toolong", &long_desc);
298+
let max_desc = "\u{1F4A1}".repeat(MAX_DESCRIPTION_LEN);
299+
write_skill(&codex_home, "max-len", "max-len", &max_desc);
300300
let cfg = make_config(&codex_home);
301301

302302
let outcome = load_skills(&cfg);
303-
assert_eq!(outcome.skills.len(), 0);
303+
assert!(
304+
outcome.errors.is_empty(),
305+
"unexpected errors: {:?}",
306+
outcome.errors
307+
);
308+
assert_eq!(outcome.skills.len(), 1);
309+
310+
let too_long_desc = "\u{1F4A1}".repeat(MAX_DESCRIPTION_LEN + 1);
311+
write_skill(&codex_home, "too-long", "too-long", &too_long_desc);
312+
let outcome = load_skills(&cfg);
313+
assert_eq!(outcome.skills.len(), 1);
304314
assert_eq!(outcome.errors.len(), 1);
305315
assert!(
306316
outcome.errors[0].message.contains("invalid description"),

‎codex-rs/tui/src/chatwidget.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,8 @@ impl ChatWidget {
23972397
format!("⚠ {effort_label} reasoning effort can quickly consume Plus plan rate limits.")
23982398
});
23992399
let warn_for_model = preset.model.starts_with("gpt-5.1-codex")
2400-
|| preset.model.starts_with("gpt-5.1-codex-max");
2400+
|| preset.model.starts_with("gpt-5.1-codex-max")
2401+
|| preset.model.starts_with("gpt-5.2");
24012402

24022403
struct EffortChoice {
24032404
stored: Option<ReasoningEffortConfig>,

‎codex-rs/tui/src/tui.rs‎

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -277,33 +277,42 @@ impl Tui {
277277
let event_stream = async_stream::stream! {
278278
loop {
279279
select! {
280-
Some(Ok(event)) = crossterm_events.next() => {
281-
match event {
282-
Event::Key(key_event) => {
283-
#[cfg(unix)]
284-
if SUSPEND_KEY.is_press(key_event) {
285-
let _ = suspend_context.suspend(&alt_screen_active);
286-
// We continue here after resume.
287-
yield TuiEvent::Draw;
288-
continue;
280+
event_result = crossterm_events.next() => {
281+
match event_result {
282+
Some(Ok(event)) => {
283+
match event {
284+
Event::Key(key_event) => {
285+
#[cfg(unix)]
286+
if SUSPEND_KEY.is_press(key_event) {
287+
let _ = suspend_context.suspend(&alt_screen_active);
288+
// We continue here after resume.
289+
yield TuiEvent::Draw;
290+
continue;
291+
}
292+
yield TuiEvent::Key(key_event);
293+
}
294+
Event::Resize(_, _) => {
295+
yield TuiEvent::Draw;
296+
}
297+
Event::Paste(pasted) => {
298+
yield TuiEvent::Paste(pasted);
299+
}
300+
Event::FocusGained => {
301+
terminal_focused.store(true, Ordering::Relaxed);
302+
crate::terminal_palette::requery_default_colors();
303+
yield TuiEvent::Draw;
304+
}
305+
Event::FocusLost => {
306+
terminal_focused.store(false, Ordering::Relaxed);
307+
}
308+
_ => {}
289309
}
290-
yield TuiEvent::Key(key_event);
291310
}
292-
Event::Resize(_, _) => {
293-
yield TuiEvent::Draw;
294-
}
295-
Event::Paste(pasted) => {
296-
yield TuiEvent::Paste(pasted);
297-
}
298-
Event::FocusGained => {
299-
terminal_focused.store(true, Ordering::Relaxed);
300-
crate::terminal_palette::requery_default_colors();
301-
yield TuiEvent::Draw;
302-
}
303-
Event::FocusLost => {
304-
terminal_focused.store(false, Ordering::Relaxed);
311+
Some(Err(_)) | None => {
312+
// Exit the loop in case of broken pipe as we will never
313+
// recover from it
314+
break;
305315
}
306-
_ => {}
307316
}
308317
}
309318
result = draw_rx.recv() => {
@@ -316,7 +325,9 @@ impl Tui {
316325
yield TuiEvent::Draw;
317326
}
318327
Err(tokio::sync::broadcast::error::RecvError::Closed) => {
319-
// Sender dropped; stop emitting draws from this source.
328+
// Sender dropped. This stream likely outlived its owning `Tui`;
329+
// exit to avoid spinning on a permanently-closed receiver.
330+
break;
320331
}
321332
}
322333
}

‎codex-rs/tui2/src/chatwidget.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2379,7 +2379,8 @@ impl ChatWidget {
23792379
format!("⚠ {effort_label} reasoning effort can quickly consume Plus plan rate limits.")
23802380
});
23812381
let warn_for_model = preset.model.starts_with("gpt-5.1-codex")
2382-
|| preset.model.starts_with("gpt-5.1-codex-max");
2382+
|| preset.model.starts_with("gpt-5.1-codex-max")
2383+
|| preset.model.starts_with("gpt-5.2");
23832384

23842385
struct EffortChoice {
23852386
stored: Option<ReasoningEffortConfig>,

‎codex-rs/utils/pty/src/lib.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl ExecCommandSession {
5454
pub fn new(
5555
writer_tx: mpsc::Sender<Vec<u8>>,
5656
output_tx: broadcast::Sender<Vec<u8>>,
57+
initial_output_rx: broadcast::Receiver<Vec<u8>>,
5758
killer: Box<dyn portable_pty::ChildKiller + Send + Sync>,
5859
reader_handle: JoinHandle<()>,
5960
writer_handle: JoinHandle<()>,
@@ -62,7 +63,6 @@ impl ExecCommandSession {
6263
exit_code: Arc<StdMutex<Option<i32>>>,
6364
pair: PtyPairWrapper,
6465
) -> (Self, broadcast::Receiver<Vec<u8>>) {
65-
let initial_output_rx = output_tx.subscribe();
6666
(
6767
Self {
6868
writer_tx,
@@ -177,6 +177,8 @@ pub async fn spawn_pty_process(
177177

178178
let (writer_tx, mut writer_rx) = mpsc::channel::<Vec<u8>>(128);
179179
let (output_tx, _) = broadcast::channel::<Vec<u8>>(256);
180+
// Subscribe before starting the reader thread.
181+
let initial_output_rx = output_tx.subscribe();
180182

181183
let mut reader = pair.master.try_clone_reader()?;
182184
let output_tx_clone = output_tx.clone();
@@ -242,6 +244,7 @@ pub async fn spawn_pty_process(
242244
let (session, output_rx) = ExecCommandSession::new(
243245
writer_tx,
244246
output_tx,
247+
initial_output_rx,
245248
killer,
246249
reader_handle,
247250
writer_handle,

0 commit comments

Comments
 (0)