## Why
`codex-rs/core/src/lib.rs` re-exported a broad set of types and modules
from `codex-protocol` and `codex-shell-command`. That made it easy for
workspace crates to import those APIs through `codex-core`, which in
turn hides dependency edges and makes it harder to reduce compile-time
coupling over time.
This change removes those public re-exports so call sites must import
from the source crates directly. Even when a crate still depends on
`codex-core` today, this makes dependency boundaries explicit and
unblocks future work to drop `codex-core` dependencies where possible.
## What Changed
- Removed public re-exports from `codex-rs/core/src/lib.rs` for:
- `codex_protocol::protocol` and related protocol/model types (including
`InitialHistory`)
- `codex_protocol::config_types` (`protocol_config_types`)
- `codex_shell_command::{bash, is_dangerous_command, is_safe_command,
parse_command, powershell}`
- Migrated workspace Rust call sites to import directly from:
- `codex_protocol::protocol`
- `codex_protocol::config_types`
- `codex_protocol::models`
- `codex_shell_command`
- Added explicit `Cargo.toml` dependencies (`codex-protocol` /
`codex-shell-command`) in crates that now import those crates directly.
- Kept `codex-core` internal modules compiling by using `pub(crate)`
aliases in `core/src/lib.rs` (internal-only, not part of the public
API).
- Updated the two utility crates that can already drop a `codex-core`
dependency edge entirely:
- `codex-utils-approval-presets`
- `codex-utils-cli`
## Verification
- `cargo test -p codex-utils-approval-presets`
- `cargo test -p codex-utils-cli`
- `cargo check --workspace --all-targets`
- `just clippy`
83 lines
2.9 KiB
Rust
83 lines
2.9 KiB
Rust
use codex_protocol::protocol::SandboxPolicy;
|
|
use std::path::PathBuf;
|
|
|
|
/// Returns a warning describing why `--add-dir` entries will be ignored for the
|
|
/// resolved sandbox policy. The caller is responsible for presenting the
|
|
/// warning to the user (for example, printing to stderr).
|
|
pub fn add_dir_warning_message(
|
|
additional_dirs: &[PathBuf],
|
|
sandbox_policy: &SandboxPolicy,
|
|
) -> Option<String> {
|
|
if additional_dirs.is_empty() {
|
|
return None;
|
|
}
|
|
|
|
match sandbox_policy {
|
|
SandboxPolicy::WorkspaceWrite { .. }
|
|
| SandboxPolicy::DangerFullAccess
|
|
| SandboxPolicy::ExternalSandbox { .. } => None,
|
|
SandboxPolicy::ReadOnly { .. } => Some(format_warning(additional_dirs)),
|
|
}
|
|
}
|
|
|
|
fn format_warning(additional_dirs: &[PathBuf]) -> String {
|
|
let joined_paths = additional_dirs
|
|
.iter()
|
|
.map(|path| path.to_string_lossy())
|
|
.collect::<Vec<_>>()
|
|
.join(", ");
|
|
format!(
|
|
"Ignoring --add-dir ({joined_paths}) because the effective sandbox mode is read-only. Switch to workspace-write or danger-full-access to allow additional writable roots."
|
|
)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::add_dir_warning_message;
|
|
use codex_protocol::protocol::NetworkAccess;
|
|
use codex_protocol::protocol::SandboxPolicy;
|
|
use pretty_assertions::assert_eq;
|
|
use std::path::PathBuf;
|
|
|
|
#[test]
|
|
fn returns_none_for_workspace_write() {
|
|
let sandbox = SandboxPolicy::new_workspace_write_policy();
|
|
let dirs = vec![PathBuf::from("/tmp/example")];
|
|
assert_eq!(add_dir_warning_message(&dirs, &sandbox), None);
|
|
}
|
|
|
|
#[test]
|
|
fn returns_none_for_danger_full_access() {
|
|
let sandbox = SandboxPolicy::DangerFullAccess;
|
|
let dirs = vec![PathBuf::from("/tmp/example")];
|
|
assert_eq!(add_dir_warning_message(&dirs, &sandbox), None);
|
|
}
|
|
|
|
#[test]
|
|
fn returns_none_for_external_sandbox() {
|
|
let sandbox = SandboxPolicy::ExternalSandbox {
|
|
network_access: NetworkAccess::Enabled,
|
|
};
|
|
let dirs = vec![PathBuf::from("/tmp/example")];
|
|
assert_eq!(add_dir_warning_message(&dirs, &sandbox), None);
|
|
}
|
|
|
|
#[test]
|
|
fn warns_for_read_only() {
|
|
let sandbox = SandboxPolicy::new_read_only_policy();
|
|
let dirs = vec![PathBuf::from("relative"), PathBuf::from("/abs")];
|
|
let message = add_dir_warning_message(&dirs, &sandbox)
|
|
.expect("expected warning for read-only sandbox");
|
|
assert_eq!(
|
|
message,
|
|
"Ignoring --add-dir (relative, /abs) because the effective sandbox mode is read-only. Switch to workspace-write or danger-full-access to allow additional writable roots."
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn returns_none_when_no_additional_dirs() {
|
|
let sandbox = SandboxPolicy::new_read_only_policy();
|
|
let dirs: Vec<PathBuf> = Vec::new();
|
|
assert_eq!(add_dir_warning_message(&dirs, &sandbox), None);
|
|
}
|
|
}
|