Skip to content

Commit 413c1e1

Browse files
authored
[codex] reduce module visibility (openai#16978)
## Summary - reduce public module visibility across Rust crates, preferring private or crate-private modules with explicit crate-root public exports - update external call sites and tests to use the intended public crate APIs instead of reaching through module trees - add the module visibility guideline to AGENTS.md ## Validation - `cargo check --workspace --all-targets --message-format=short` passed before the final fix/format pass - `just fix` completed successfully - `just fmt` completed successfully - `git diff --check` passed
1 parent 89f1a44 commit 413c1e1

129 files changed

Lines changed: 695 additions & 496 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ In the codex-rs folder where the rust code lives:
2121
- Newly added traits should include doc comments that explain their role and how implementations are expected to use them.
2222
- When writing tests, prefer comparing the equality of entire objects over fields one by one.
2323
- When making a change that adds or changes an API, ensure that the documentation in the `docs/` folder is up to date if applicable.
24+
- Prefer private modules and explicitly exported public crate API.
2425
- If you change `ConfigToml` or nested config types, run `just write-config-schema` to update `codex-rs/core/config.schema.json`.
2526
- If you change Rust dependencies (`Cargo.toml` or `Cargo.lock`), run `just bazel-lock-update` from the
2627
repo root to refresh `MODULE.bazel.lock`, and include that lockfile update in the same change.

codex-rs/app-server/src/codex_message_processor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ use codex_login::default_client::set_default_client_residency_requirement;
248248
use codex_login::login_with_api_key;
249249
use codex_login::request_device_code;
250250
use codex_login::run_login_server;
251-
use codex_mcp::mcp::McpSnapshotDetail;
252-
use codex_mcp::mcp::auth::discover_supported_scopes;
253-
use codex_mcp::mcp::auth::resolve_oauth_scopes;
254-
use codex_mcp::mcp::collect_mcp_snapshot_with_detail;
255-
use codex_mcp::mcp::effective_mcp_servers;
256-
use codex_mcp::mcp::qualified_mcp_tool_name_prefix;
251+
use codex_mcp::McpSnapshotDetail;
252+
use codex_mcp::collect_mcp_snapshot_with_detail;
253+
use codex_mcp::discover_supported_scopes;
254+
use codex_mcp::effective_mcp_servers;
255+
use codex_mcp::qualified_mcp_tool_name_prefix;
256+
use codex_mcp::resolve_oauth_scopes;
257257
use codex_models_manager::collaboration_mode_presets::CollaborationModesConfig;
258258
use codex_protocol::ThreadId;
259259
use codex_protocol::config_types::CollaborationMode;
@@ -5175,7 +5175,7 @@ impl CodexMessageProcessor {
51755175
request_id: ConnectionRequestId,
51765176
params: ListMcpServerStatusParams,
51775177
config: Config,
5178-
mcp_config: codex_mcp::mcp::McpConfig,
5178+
mcp_config: codex_mcp::McpConfig,
51795179
auth: Option<CodexAuth>,
51805180
) {
51815181
let detail = match params.detail.unwrap_or(McpServerStatusDetail::Full) {

codex-rs/app-server/src/codex_message_processor/plugin_mcp_oauth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use codex_app_server_protocol::McpServerOauthLoginCompletedNotification;
55
use codex_app_server_protocol::ServerNotification;
66
use codex_config::types::McpServerConfig;
77
use codex_core::config::Config;
8-
use codex_mcp::mcp::auth::McpOAuthLoginSupport;
9-
use codex_mcp::mcp::auth::oauth_login_support;
10-
use codex_mcp::mcp::auth::resolve_oauth_scopes;
11-
use codex_mcp::mcp::auth::should_retry_without_scopes;
8+
use codex_mcp::McpOAuthLoginSupport;
9+
use codex_mcp::oauth_login_support;
10+
use codex_mcp::resolve_oauth_scopes;
11+
use codex_mcp::should_retry_without_scopes;
1212
use codex_rmcp_client::perform_oauth_login_silent;
1313
use tracing::warn;
1414

codex-rs/backend-client/src/client.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ impl Client {
503503
#[cfg(test)]
504504
mod tests {
505505
use super::*;
506+
use codex_backend_openapi_models::models::AdditionalRateLimitDetails;
506507
use pretty_assertions::assert_eq;
507508

508509
#[test]
@@ -536,7 +537,7 @@ mod tests {
536537
}))),
537538
..Default::default()
538539
}))),
539-
additional_rate_limits: Some(Some(vec![crate::types::AdditionalRateLimitDetails {
540+
additional_rate_limits: Some(Some(vec![AdditionalRateLimitDetails {
540541
limit_name: "codex_other".to_string(),
541542
metered_feature: "codex_other".to_string(),
542543
rate_limit: Some(Some(Box::new(crate::types::RateLimitStatusDetails {
@@ -596,7 +597,7 @@ mod tests {
596597
let payload = RateLimitStatusPayload {
597598
plan_type: crate::types::PlanType::Plus,
598599
rate_limit: None,
599-
additional_rate_limits: Some(Some(vec![crate::types::AdditionalRateLimitDetails {
600+
additional_rate_limits: Some(Some(vec![AdditionalRateLimitDetails {
600601
limit_name: "codex_other".to_string(),
601602
metered_feature: "codex_other".to_string(),
602603
rate_limit: None,

codex-rs/backend-client/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod client;
2-
pub mod types;
2+
pub(crate) mod types;
33

44
pub use client::Client;
55
pub use client::RequestError;

codex-rs/backend-client/src/types.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub use codex_backend_openapi_models::models::AdditionalRateLimitDetails;
21
pub use codex_backend_openapi_models::models::ConfigFileResponse;
32
pub use codex_backend_openapi_models::models::CreditStatusDetails;
43
pub use codex_backend_openapi_models::models::PaginatedListTaskListItem;

codex-rs/cli/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
pub mod debug_sandbox;
1+
pub(crate) mod debug_sandbox;
22
mod exit_status;
3-
pub mod login;
3+
pub(crate) mod login;
44

55
use clap::Parser;
66
use codex_utils_cli::CliConfigOverrides;
77

8+
pub use debug_sandbox::run_command_under_landlock;
9+
pub use debug_sandbox::run_command_under_seatbelt;
10+
pub use debug_sandbox::run_command_under_windows;
11+
pub use login::read_api_key_from_stdin;
12+
pub use login::run_login_status;
13+
pub use login::run_login_with_api_key;
14+
pub use login::run_login_with_chatgpt;
15+
pub use login::run_login_with_device_code;
16+
pub use login::run_login_with_device_code_fallback_to_browser;
17+
pub use login::run_logout;
18+
819
#[derive(Debug, Parser)]
920
pub struct SeatbeltCommand {
1021
/// Convenience alias for low-friction sandboxed automatic execution (network-disabled sandbox that can write to cwd and TMPDIR)

codex-rs/cli/src/main.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use codex_chatgpt::apply_command::run_apply_command;
1010
use codex_cli::LandlockCommand;
1111
use codex_cli::SeatbeltCommand;
1212
use codex_cli::WindowsCommand;
13-
use codex_cli::login::read_api_key_from_stdin;
14-
use codex_cli::login::run_login_status;
15-
use codex_cli::login::run_login_with_api_key;
16-
use codex_cli::login::run_login_with_chatgpt;
17-
use codex_cli::login::run_login_with_device_code;
18-
use codex_cli::login::run_logout;
13+
use codex_cli::read_api_key_from_stdin;
14+
use codex_cli::run_login_status;
15+
use codex_cli::run_login_with_api_key;
16+
use codex_cli::run_login_with_chatgpt;
17+
use codex_cli::run_login_with_device_code;
18+
use codex_cli::run_logout;
1919
use codex_cloud_tasks::Cli as CloudTasksCli;
2020
use codex_exec::Cli as ExecCli;
2121
use codex_exec::Command as ExecCommand;
@@ -27,7 +27,7 @@ use codex_state::state_db_path;
2727
use codex_tui::AppExitInfo;
2828
use codex_tui::Cli as TuiCli;
2929
use codex_tui::ExitReason;
30-
use codex_tui::update_action::UpdateAction;
30+
use codex_tui::UpdateAction;
3131
use codex_utils_cli::CliConfigOverrides;
3232
use owo_colors::OwoColorize;
3333
use std::io::IsTerminal;
@@ -883,7 +883,7 @@ async fn cli_main(arg0_paths: Arg0DispatchPaths) -> anyhow::Result<()> {
883883
&mut seatbelt_cli.config_overrides,
884884
root_config_overrides.clone(),
885885
);
886-
codex_cli::debug_sandbox::run_command_under_seatbelt(
886+
codex_cli::run_command_under_seatbelt(
887887
seatbelt_cli,
888888
arg0_paths.codex_linux_sandbox_exe.clone(),
889889
)
@@ -899,7 +899,7 @@ async fn cli_main(arg0_paths: Arg0DispatchPaths) -> anyhow::Result<()> {
899899
&mut landlock_cli.config_overrides,
900900
root_config_overrides.clone(),
901901
);
902-
codex_cli::debug_sandbox::run_command_under_landlock(
902+
codex_cli::run_command_under_landlock(
903903
landlock_cli,
904904
arg0_paths.codex_linux_sandbox_exe.clone(),
905905
)
@@ -915,7 +915,7 @@ async fn cli_main(arg0_paths: Arg0DispatchPaths) -> anyhow::Result<()> {
915915
&mut windows_cli.config_overrides,
916916
root_config_overrides.clone(),
917917
);
918-
codex_cli::debug_sandbox::run_command_under_windows(
918+
codex_cli::run_command_under_windows(
919919
windows_cli,
920920
arg0_paths.codex_linux_sandbox_exe.clone(),
921921
)
@@ -1173,7 +1173,7 @@ async fn run_debug_prompt_input_command(
11731173
});
11741174
}
11751175

1176-
let prompt_input = codex_core::prompt_debug::build_prompt_input(config, input).await?;
1176+
let prompt_input = codex_core::build_prompt_input(config, input).await?;
11771177
println!("{}", serde_json::to_string_pretty(&prompt_input)?);
11781178

11791179
Ok(())

codex-rs/cli/src/mcp_cmd.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ use anyhow::bail;
88
use clap::ArgGroup;
99
use codex_config::types::McpServerConfig;
1010
use codex_config::types::McpServerTransportConfig;
11+
use codex_core::McpManager;
1112
use codex_core::config::Config;
1213
use codex_core::config::edit::ConfigEditsBuilder;
1314
use codex_core::config::find_codex_home;
1415
use codex_core::config::load_global_mcp_servers;
15-
use codex_core::mcp::McpManager;
1616
use codex_core::plugins::PluginsManager;
17-
use codex_mcp::mcp::auth::McpOAuthLoginSupport;
18-
use codex_mcp::mcp::auth::ResolvedMcpOAuthScopes;
19-
use codex_mcp::mcp::auth::compute_auth_statuses;
20-
use codex_mcp::mcp::auth::discover_supported_scopes;
21-
use codex_mcp::mcp::auth::oauth_login_support;
22-
use codex_mcp::mcp::auth::resolve_oauth_scopes;
23-
use codex_mcp::mcp::auth::should_retry_without_scopes;
17+
use codex_mcp::McpOAuthLoginSupport;
18+
use codex_mcp::ResolvedMcpOAuthScopes;
19+
use codex_mcp::compute_auth_statuses;
20+
use codex_mcp::discover_supported_scopes;
21+
use codex_mcp::oauth_login_support;
22+
use codex_mcp::resolve_oauth_scopes;
23+
use codex_mcp::should_retry_without_scopes;
2424
use codex_protocol::protocol::McpAuthStatus;
2525
use codex_rmcp_client::delete_oauth_tokens;
2626
use codex_rmcp_client::perform_oauth_login;
2727
use codex_utils_cli::CliConfigOverrides;
28-
use codex_utils_cli::format_env_display::format_env_display;
28+
use codex_utils_cli::format_env_display;
2929

3030
/// Subcommands:
3131
/// - `list` — list configured servers (with `--json`)

codex-rs/cli/src/wsl_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::OsStr;
22

33
/// Returns true if the current process is running under WSL.
4-
pub use codex_utils_path::env::is_wsl;
4+
pub use codex_utils_path::is_wsl;
55

66
/// Convert a Windows absolute path (`C:\foo\bar` or `C:/foo/bar`) to a WSL mount path (`/mnt/c/foo/bar`).
77
/// Returns `None` if the input does not look like a Windows drive path.

0 commit comments

Comments
 (0)