mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
## Why With the local model layer and app-server routing in place from PR1, this PR moves the active TUI runtime onto app-server notifications. The affected pieces share the same event flow, so the command surface, session state, bottom-pane prompts, chat rendering, history/status views, and tests move together to keep the stacked branch buildable. This PR also removes the obsolete compatibility surface that is no longer used after the migration. The proposed protocol-boundary verifier layer was dropped from the stack; enforcing that final boundary will be simpler once `codex-tui` no longer needs any `codex_protocol` references. This PR is part 2 of a 2-PR stack: 1. Add TUI-owned replacement models and extract app-server event routing. 2. Move the active TUI flow to app-server notifications and delete obsolete adapter code. ## What changed - Rewired app command and session handling to use app-server request and notification shapes. - Moved approval overlays, request-user-input flows, MCP elicitation, realtime events, and review commands onto the app-server-facing model surface. - Updated chat rendering, history cells, status views, multi-agent UI, replay state, and TUI tests to use app-server notifications plus the local models introduced in PR1. - Deleted `codex-rs/tui/src/app/app_server_adapter.rs` and the superseded `chatwidget/tests/background_events.rs` fixture path. ## Verification - `cargo check -p codex-tui --tests` - Top of stack: `cargo test -p codex-tui`
96 lines
3.8 KiB
Rust
96 lines
3.8 KiB
Rust
//! Compatibility projections from the canonical permission profile model into
|
|
//! legacy shapes still required by older or remote app-server APIs.
|
|
|
|
use codex_protocol::models::PermissionProfile;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use std::path::Path;
|
|
|
|
pub(crate) fn legacy_compatible_permission_profile(
|
|
permission_profile: &PermissionProfile,
|
|
cwd: &Path,
|
|
) -> PermissionProfile {
|
|
if permission_profile.to_legacy_sandbox_policy(cwd).is_ok() {
|
|
return permission_profile.clone();
|
|
}
|
|
|
|
let file_system_policy = permission_profile.file_system_sandbox_policy();
|
|
let network_policy = permission_profile.network_sandbox_policy();
|
|
let cwd_abs = AbsolutePathBuf::from_absolute_path(cwd).ok();
|
|
let writable_roots = file_system_policy
|
|
.get_writable_roots_with_cwd(cwd)
|
|
.into_iter()
|
|
.map(|root| root.root)
|
|
.filter(|root| cwd_abs.as_ref() != Some(root))
|
|
.collect::<Vec<_>>();
|
|
let tmpdir_writable = std::env::var_os("TMPDIR")
|
|
.filter(|tmpdir| !tmpdir.is_empty())
|
|
.and_then(|tmpdir| {
|
|
AbsolutePathBuf::from_absolute_path(std::path::PathBuf::from(tmpdir)).ok()
|
|
})
|
|
.is_some_and(|tmpdir| file_system_policy.can_write_path_with_cwd(tmpdir.as_path(), cwd));
|
|
let slash_tmp = Path::new("/tmp");
|
|
let slash_tmp_writable = slash_tmp.is_absolute()
|
|
&& slash_tmp.is_dir()
|
|
&& file_system_policy.can_write_path_with_cwd(slash_tmp, cwd);
|
|
|
|
PermissionProfile::workspace_write_with(
|
|
&writable_roots,
|
|
network_policy,
|
|
!tmpdir_writable,
|
|
!slash_tmp_writable,
|
|
)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use codex_app_server_protocol::FileSystemAccessMode;
|
|
use codex_app_server_protocol::FileSystemPath;
|
|
use codex_app_server_protocol::FileSystemSandboxEntry;
|
|
use codex_app_server_protocol::FileSystemSpecialPath;
|
|
use codex_app_server_protocol::PermissionProfile as AppServerPermissionProfile;
|
|
use codex_app_server_protocol::PermissionProfileFileSystemPermissions;
|
|
use codex_app_server_protocol::PermissionProfileNetworkPermissions;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn compatibility_profile_preserves_unbridgeable_write_roots() {
|
|
let cwd = AbsolutePathBuf::try_from("/workspace/project").expect("absolute cwd");
|
|
let extra_root = AbsolutePathBuf::try_from("/workspace/extra").expect("absolute root");
|
|
let permission_profile: PermissionProfile = AppServerPermissionProfile::Managed {
|
|
network: PermissionProfileNetworkPermissions { enabled: false },
|
|
file_system: PermissionProfileFileSystemPermissions::Restricted {
|
|
entries: vec![
|
|
FileSystemSandboxEntry {
|
|
path: FileSystemPath::Special {
|
|
value: FileSystemSpecialPath::Root,
|
|
},
|
|
access: FileSystemAccessMode::Read,
|
|
},
|
|
FileSystemSandboxEntry {
|
|
path: FileSystemPath::Path {
|
|
path: extra_root.clone(),
|
|
},
|
|
access: FileSystemAccessMode::Write,
|
|
},
|
|
],
|
|
glob_scan_max_depth: None,
|
|
},
|
|
}
|
|
.into();
|
|
|
|
let compatibility_profile =
|
|
legacy_compatible_permission_profile(&permission_profile, cwd.as_path());
|
|
let policy = compatibility_profile
|
|
.to_legacy_sandbox_policy(cwd.as_path())
|
|
.expect("compatibility profile should project to legacy policy");
|
|
let roots = policy
|
|
.get_writable_roots_with_cwd(cwd.as_path())
|
|
.into_iter()
|
|
.map(|root| root.root)
|
|
.collect::<Vec<_>>();
|
|
|
|
assert_eq!(roots, vec![extra_root, cwd]);
|
|
}
|
|
}
|