mirror of
https://github.com/openai/codex.git
synced 2026-11-20 15:07:25 +00:00
## Summary - Move TUI permission state from legacy `SandboxPolicy` values to canonical `PermissionProfile` values across presets, app events, chat widget state, app commands, thread routing, and cached thread session state. - Keep app-server compatibility boundaries explicit: embedded sessions send `permissionProfile`, while remote sessions send only a legacy `sandbox` projection and fall back to read-only when a custom profile cannot be projected. - Update status/add-dir UI summaries and snapshots to render the active permission profile, including workspace profiles selected by the new built-in defaults. ## Verification - `rg '\bSandboxPolicy\b' codex-rs/tui -n` returns no matches. - `cargo test -p codex-tui` - `cargo check -p codex-tui --tests` - `cargo test -p codex-tui additional_dirs` - `just fmt` - `just fix -p codex-tui` --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/20008). * #20041 * #20040 * #20037 * #20035 * #20034 * #20033 * #20032 * #20030 * #20028 * #20027 * #20026 * #20024 * #20021 * #20018 * #20016 * #20015 * #20013 * #20011 * #20010 * __->__ #20008
107 lines
3.3 KiB
Rust
107 lines
3.3 KiB
Rust
//! Platform-specific app actions and small global shortcuts.
|
|
//!
|
|
//! This module owns platform state used by `App`, the side-conversation return shortcut predicate,
|
|
//! and Windows sandbox helper actions that are compiled only on Windows.
|
|
|
|
use super::*;
|
|
|
|
#[derive(Default)]
|
|
pub(super) struct WindowsSandboxState {
|
|
pub(super) setup_started_at: Option<Instant>,
|
|
// One-shot suppression of the next world-writable scan after user confirmation.
|
|
pub(super) skip_world_writable_scan_once: bool,
|
|
}
|
|
|
|
impl App {
|
|
#[cfg(target_os = "windows")]
|
|
pub(super) fn spawn_world_writable_scan(
|
|
cwd: AbsolutePathBuf,
|
|
env_map: std::collections::HashMap<String, String>,
|
|
logs_base_dir: AbsolutePathBuf,
|
|
permission_profile: PermissionProfile,
|
|
tx: AppEventSender,
|
|
) {
|
|
let Ok(sandbox_policy) = permission_profile.to_legacy_sandbox_policy(cwd.as_path()) else {
|
|
send_world_writable_scan_failed(&tx);
|
|
return;
|
|
};
|
|
|
|
tokio::task::spawn_blocking(move || {
|
|
let logs_base_dir_path = logs_base_dir.as_path();
|
|
let result = codex_windows_sandbox::apply_world_writable_scan_and_denies(
|
|
logs_base_dir_path,
|
|
cwd.as_path(),
|
|
&env_map,
|
|
&sandbox_policy,
|
|
Some(logs_base_dir_path),
|
|
);
|
|
if result.is_err() {
|
|
// Scan failed: warn without examples.
|
|
send_world_writable_scan_failed(&tx);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
fn send_world_writable_scan_failed(tx: &AppEventSender) {
|
|
tx.send(AppEvent::OpenWorldWritableWarningConfirmation {
|
|
preset: None,
|
|
sample_paths: Vec::new(),
|
|
extra_count: 0usize,
|
|
failed_scan: true,
|
|
});
|
|
}
|
|
|
|
pub(super) fn side_return_shortcut_matches(key_event: KeyEvent) -> bool {
|
|
match key_event {
|
|
KeyEvent {
|
|
code: KeyCode::Esc,
|
|
kind: KeyEventKind::Press | KeyEventKind::Repeat,
|
|
..
|
|
} => true,
|
|
KeyEvent {
|
|
code: KeyCode::Char(c),
|
|
modifiers,
|
|
kind: KeyEventKind::Press,
|
|
..
|
|
} if modifiers.contains(KeyModifiers::CONTROL) && c.eq_ignore_ascii_case(&'c') => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn side_return_shortcuts_match_esc_and_ctrl_c() {
|
|
assert!(side_return_shortcut_matches(KeyEvent::new(
|
|
KeyCode::Esc,
|
|
KeyModifiers::NONE,
|
|
)));
|
|
assert!(side_return_shortcut_matches(KeyEvent::new_with_kind(
|
|
KeyCode::Esc,
|
|
KeyModifiers::NONE,
|
|
KeyEventKind::Repeat,
|
|
)));
|
|
assert!(side_return_shortcut_matches(KeyEvent::new(
|
|
KeyCode::Char('c'),
|
|
KeyModifiers::CONTROL,
|
|
)));
|
|
assert!(side_return_shortcut_matches(KeyEvent::new(
|
|
KeyCode::Char('C'),
|
|
KeyModifiers::CONTROL,
|
|
)));
|
|
assert!(!side_return_shortcut_matches(KeyEvent::new(
|
|
KeyCode::Char('d'),
|
|
KeyModifiers::CONTROL,
|
|
)));
|
|
assert!(!side_return_shortcut_matches(KeyEvent::new_with_kind(
|
|
KeyCode::Esc,
|
|
KeyModifiers::NONE,
|
|
KeyEventKind::Release,
|
|
)));
|
|
}
|
|
}
|