Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ passing on its own is enough: a cherry-pick does not move the base.
| — | `wire_api = "chat"`: Chat Completions client restored for providers whose Responses path drops tool calls (grok via theclawbay/LiteLLM, WI-1139). New files only, plus one dispatch arm: `core/src/chat_request.rs` (request conversion; namespaced tools flattened to `ns__name`, freeform tools such as apply_patch exposed as a function taking one `input` string, calls restored by `ChatToolMap`), `codex-api/src/{endpoint,sse}/chat.rs` (client and SSE parser, fixture tests in `sse/chat_tests.rs`). Reasoning, web search and tool search are not sent over chat. Branch `fork/wi-1286-chat-wire`. | fork-only; upstream removed the chat client |
| — | Headless MCP startup (issue #26, WI-1514): `codex exec` defaults `mcp_optional_startup_grace_ms` to 0 unless set, so every enabled server's startup is awaited (each bounded by its `startup_timeout_sec`) before the first request; a failed or timed-out server is printed as a warning and the run continues. Tool dispatch resolves un-namespaced `mcp__<server>__<tool>` names and bare names unique across MCP servers, and answers a call to a server still handshaking with "MCP server `x` is still starting" instead of "unsupported call". `exec/src/lib.rs`, `core/src/tools/registry.rs`, `codex-mcp` `pending_startup_servers`. Branch `fix/issue-26-mcp-startup`. | fork-only |
| — | Auto-compaction loop guard (WI-2832): after a context-limit compaction (pre-turn or mid-turn), if the first request's prompt alone is still at or over `model_auto_compact_token_limit` (body after prefix for that scope) or the usable window, the turn ends with a warning and a `ContextWindowExceeded` error instead of compacting again. Before this, a fixed prefix (tool specs) over the limit looped compaction -> one tool call -> compaction (235 compactions in one turn). `core/src/session/turn.rs`; tests `turn_tests.rs` `prompt_over_limit_*`, `suite::compact::auto_compact_stops_when_compaction_cannot_get_below_limit`. Branch `wi-2832-compaction-thrash-guard`. | fork-only; upstream has the same loop |
| — | Auto-review audit trail (issue #34, WI-4410): `codex-rollout` `policy.rs` now persists terminal `GuardianAssessment` events (approved, denied, timed out, aborted) in the rollout; the in-progress marker stays transient. Before, no verdict was recorded in the parent rollout. Pinned by `policy_tests.rs::guardian_assessment_verdicts_are_persisted_but_in_progress_is_not`. Findings: the reviewer runs on the parent's own model provider (`guardian_session_inherits_parent_http_fallback` has a custom-provider case; not exercised against a live LiteLLM here). Under `approvals_reviewer=auto_review` an action is decided by the reviewer, not escalated as a user prompt: a denial reaches the model as a rejection and the client as a `GuardianAssessment` (Denied) event, and only `approvals_reviewer=user` raises `ExecApprovalRequest`. Branch `fix/issue-34-auto-review`. | fork-only |
| — | Per-session provider (issue #39, WI-4409): no code change. `-c model_provider=<id> -c model_context_window=<n> -c model_auto_compact_token_limit=<n>` already override the global `config.toml` for one session; pinned by `cli_overrides_select_session_provider_and_context_limits` in `core/src/config/config_loader_tests.rs`. Branch `fix/issue-39-session-provider`. | fork-only (test + note) |
| — | TUI mouse (issues #43, #44, WI-4408): wheel events scroll the transcript wherever the pointer is on screen (`tui/src/transcript_view/input.rs`; selection still respects the rect), and `tui.mouse_capture = false` (or `-c tui.mouse_capture=false`, or env `CODEX_TUI_MOUSE_CAPTURE=0`; env wins) stops the TUI requesting mouse reporting in the alternate screen so browser/mobile/multi-viewer front ends keep text selection while the fullscreen transcript stays. For append-only output use `tui.alternate_screen = "never"` / `--no-alt-screen`. `config/src/types.rs`, `tui/src/tui.rs` `MouseCapture::captures_mouse`. Branch `fix/wi-tui-43-44`. | fork-only |

## External adapters

Expand Down
5 changes: 5 additions & 0 deletions codex-rs/config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,11 @@ pub struct Tui {
#[schemars(schema_with = "crate::tui_mouse_scroll::schema")]
pub mouse_scroll_speed: Option<f64>,

/// Let the TUI capture mouse events in the alternate screen. Defaults to `true`.
/// Set `false` for browser, mobile or multi-viewer terminals whose front end owns text
/// selection. Overridden by the `CODEX_TUI_MOUSE_CAPTURE` environment variable.
pub mouse_capture: Option<bool>,

/// Copy selected transcript, footer, or composer text when the mouse button is released.
/// Defaults to `auto`: enabled except in direct terminals known to forward their native
/// copy shortcut (Ghostty 1.2+, Kitty on macOS, Windows Terminal, and VS Code on Windows).
Expand Down
4 changes: 4 additions & 0 deletions codex-rs/core/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5537,6 +5537,10 @@
"default": {},
"description": "Startup tooltip availability NUX state persisted by the TUI."
},
"mouse_capture": {
"description": "Let the TUI capture mouse events in the alternate screen. Defaults to `true`. Set `false` for browser, mobile or multi-viewer terminals whose front end owns text selection. Overridden by the `CODEX_TUI_MOUSE_CAPTURE` environment variable.",
"type": "boolean"
},
"mouse_scroll_speed": {
"default": null,
"description": "Mouse wheel speed multiplier for transcript scrolling, based on one row per event. Defaults to `1.0`. Positive fractional values slow scrolling; values above `1.0` speed it up.",
Expand Down
51 changes: 51 additions & 0 deletions codex-rs/core/src/config/config_loader_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4940,3 +4940,54 @@ async fn async_compaction_config() {
assert_eq!(actual, expected, "{settings}");
}
}

/// Fork issue #39: a session picks its provider and context limits with `-c`
/// overrides, without touching the global default in config.toml.
#[tokio::test]
async fn cli_overrides_select_session_provider_and_context_limits() {
let tmp = tempdir().expect("tempdir");
std::fs::write(
tmp.path().join(CONFIG_TOML_FILE),
r#"
model_provider = "global"
model_context_window = 850000
model_auto_compact_token_limit = 800000

[model_providers.global]
name = "global"
base_url = "http://localhost:1/v1"

[model_providers.session]
name = "session"
base_url = "http://localhost:2/v1"
"#,
)
.expect("write config");

let config = ConfigBuilder::default()
.codex_home(tmp.path().to_path_buf())
.fallback_cwd(Some(tmp.path().to_path_buf()))
.loader_overrides(LoaderOverrides::without_managed_config_for_tests())
.cli_overrides(vec![
(
"model_provider".to_string(),
TomlValue::String("session".to_string()),
),
(
"model_context_window".to_string(),
TomlValue::Integer(128000),
),
(
"model_auto_compact_token_limit".to_string(),
TomlValue::Integer(100000),
),
])
.build()
.await
.expect("config with provider override");

assert_eq!(config.model_provider_id, "session");
assert_eq!(config.model_provider.name, "session");
assert_eq!(config.model_context_window, Some(128000));
assert_eq!(config.model_auto_compact_token_limit, Some(100000));
}
2 changes: 2 additions & 0 deletions codex-rs/core/src/config/config_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,7 @@ fn config_toml_deserializes_model_availability_nux() {
collapse_turn_details: false,
sidebar_width_percent: None,
mouse_scroll_speed: None,
mouse_capture: None,
copy_on_select: Default::default(),
copy_on_select_clear_selection: false,
right_click_paste: Default::default(),
Expand Down Expand Up @@ -4778,6 +4779,7 @@ fn tui_config_missing_notifications_field_defaults_to_enabled() {
collapse_turn_details: false,
sidebar_width_percent: None,
mouse_scroll_speed: None,
mouse_capture: None,
copy_on_select: Default::default(),
copy_on_select_clear_selection: false,
right_click_paste: Default::default(),
Expand Down
4 changes: 4 additions & 0 deletions codex-rs/core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,9 @@ pub struct Config {
/// Mouse wheel speed multiplier for transcript scrolling; defaults to one row per event.
pub tui_mouse_scroll_speed: Option<f64>,

/// Whether the TUI may capture the mouse in the alternate screen (`tui.mouse_capture`).
pub tui_mouse_capture: Option<bool>,

/// Override the terminal default for copying transcript, footer, and composer selections.
pub tui_copy_on_select: codex_config::types::CopyOnSelect,

Expand Down Expand Up @@ -4896,6 +4899,7 @@ impl Config {
.is_none_or(|tui| tui.fullscreen_transcript),
tui_sidebar_width_percent: cfg.tui.as_ref().and_then(|tui| tui.sidebar_width_percent),
tui_mouse_scroll_speed: cfg.tui.as_ref().and_then(|tui| tui.mouse_scroll_speed),
tui_mouse_capture: cfg.tui.as_ref().and_then(|tui| tui.mouse_capture),
tui_copy_on_select: cfg
.tui
.as_ref()
Expand Down
8 changes: 7 additions & 1 deletion codex-rs/rollout/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,16 @@ fn persisted_event_msg(
&& event.kind != SubAgentActivityKind::Completed)
.then_some(Cow::Borrowed(ev)),

// Auto-review verdicts are the audit trail of what was auto-approved or
// denied (fork issue #34). Only the terminal status is durable; the
// in-progress marker is transient.
EventMsg::GuardianAssessment(event) => (event.status
!= codex_protocol::protocol::GuardianAssessmentStatus::InProgress)
.then_some(Cow::Borrowed(ev)),

// Transient, non-durable events.
EventMsg::Error(_)
| EventMsg::ThreadQueueChanged(_)
| EventMsg::GuardianAssessment(_)
| EventMsg::ExecCommandEnd(_)
| EventMsg::ViewImageToolCall(_)
| EventMsg::CollabAgentSpawnEnd(_)
Expand Down
46 changes: 46 additions & 0 deletions codex-rs/rollout/src/policy_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,49 @@ fn inline_image_generation_result_is_preserved() {
})
);
}

fn guardian_assessment(status: codex_protocol::protocol::GuardianAssessmentStatus) -> EventMsg {
EventMsg::GuardianAssessment(codex_protocol::protocol::GuardianAssessmentEvent {
review_reason: None,
model_context: None,
id: "review-1".into(),
target_item_id: None,
plugin_id: None,
script_path: None,
turn_id: "turn-1".into(),
started_at_ms: 1,
completed_at_ms: None,
status,
risk_level: None,
user_authorization: None,
rationale: None,
decision_source: None,
action: codex_protocol::protocol::GuardianAssessmentAction::Command {
source: codex_protocol::protocol::GuardianCommandSource::Shell,
command: "true".into(),
cwd: codex_utils_absolute_path::AbsolutePathBuf::current_dir()
.expect("current dir")
.into(),
},
})
}

/// Fork issue #34: auto-review verdicts must be auditable from the rollout.
#[test]
fn guardian_assessment_verdicts_are_persisted_but_in_progress_is_not() {
use codex_protocol::protocol::GuardianAssessmentStatus as S;
for status in [S::Approved, S::Denied, S::TimedOut, S::Aborted] {
let event = guardian_assessment(status);
assert!(
persisted_event_msg(&event, ThreadHistoryMode::Legacy).is_some(),
"{status:?} must be persisted"
);
}
assert!(
persisted_event_msg(
&guardian_assessment(S::InProgress),
ThreadHistoryMode::Legacy
)
.is_none()
);
}
1 change: 1 addition & 0 deletions codex-rs/thread-manager-sample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ async fn new_config(
tui_collapse_turn_details: false,
tui_sidebar_width_percent: None,
tui_mouse_scroll_speed: None,
tui_mouse_capture: None,
tui_copy_on_select: Default::default(),
tui_copy_on_select_clear_selection: false,
tui_right_click_paste: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions codex-rs/tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,7 @@ async fn run_ratatui_app(
);
}

crate::tui::configure_mouse_capture(config.tui_mouse_capture);
// Cloud configuration and session selection can change screen policy after first paint.
let use_alt_screen = determine_alt_screen_mode(
cli.no_alt_screen,
Expand Down
1 change: 1 addition & 0 deletions codex-rs/tui/src/local_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl LocalSettings {
collapse_turn_details: config.tui_collapse_turn_details,
sidebar_width_percent: config.tui_sidebar_width_percent,
mouse_scroll_speed: config.tui_mouse_scroll_speed,
mouse_capture: config.tui_mouse_capture,
copy_on_select: config.tui_copy_on_select,
copy_on_select_clear_selection: config.tui_copy_on_select_clear_selection,
right_click_paste: config.tui_right_click_paste,
Expand Down
8 changes: 7 additions & 1 deletion codex-rs/tui/src/transcript_view/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,13 @@ impl TranscriptView {
.selection
.as_ref()
.is_some_and(|selection| selection.dragging);
if !inside && !dragging {
// Wheel scrolling applies anywhere on screen: front ends that synthesize wheel reports
// (browser or mobile terminals) cannot be relied on to aim them at the transcript.
let wheel = matches!(
event.kind,
MouseEventKind::ScrollUp | MouseEventKind::ScrollDown
);
if !inside && !dragging && !wheel {
return None;
}
// Wheel navigation supersedes the last drag position. A real drag event can resume it.
Expand Down
18 changes: 18 additions & 0 deletions codex-rs/tui/src/transcript_view/input_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ fn fractional_mouse_scroll_does_not_pause_following_until_a_row_moves() {
assert!(!view.is_following());
}

#[test]
fn wheel_scrolls_transcript_when_pointer_is_outside_its_area() {
let (mut view, cells) = transcript(
"one\n\ntwo\n\nthree\n\nfour\n\nfive\n\nsix",
/*width*/ 12,
);
assert!(view.is_following());
view.handle_mouse(
mouse(
MouseEventKind::ScrollUp,
/*column*/ 60,
/*row*/ 40,
),
&cells,
);
assert!(!view.is_following());
}

fn transcript(markdown: &str, width: u16) -> (TranscriptView, Vec<Arc<dyn HistoryCell>>) {
let cells: Vec<Arc<dyn HistoryCell>> = vec![Arc::new(AgentMarkdownCell::new(
markdown.into(),
Expand Down
44 changes: 42 additions & 2 deletions codex-rs/tui/src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,31 @@ pub(crate) enum MouseCapture {
Disabled,
}

/// Process-wide veto from `tui.mouse_capture = false` or `CODEX_TUI_MOUSE_CAPTURE=0`.
static MOUSE_CAPTURE_VETOED: AtomicBool = AtomicBool::new(false);

/// Resolve the mouse-capture policy: the environment variable wins over the config value.
pub(crate) fn mouse_capture_allowed(config: Option<bool>, env: Option<&str>) -> bool {
match env.map(|value| value.trim().to_ascii_lowercase()) {
Some(value) if matches!(value.as_str(), "0" | "false" | "off" | "no" | "never") => false,
Some(value) if matches!(value.as_str(), "1" | "true" | "on" | "yes" | "always") => true,
_ => config.unwrap_or(true),
}
}

pub(crate) fn configure_mouse_capture(config: Option<bool>) {
let env = std::env::var("CODEX_TUI_MOUSE_CAPTURE").ok();
MOUSE_CAPTURE_VETOED.store(
!mouse_capture_allowed(config, env.as_deref()),
Ordering::Relaxed,
);
}

impl MouseCapture {
fn captures_mouse(self, owned_screen: bool) -> bool {
if MOUSE_CAPTURE_VETOED.load(Ordering::Relaxed) {
return false;
}
match self {
Self::Inherit => owned_screen,
Self::Enabled => true,
Expand Down Expand Up @@ -859,8 +882,10 @@ impl Tui {
let transition = if owned {
self.owned_screen = true;
if self.is_alt_screen_active() {
ALTERNATE_SCREEN
.configure_input(self.terminal.backend_mut(), /*capture_mouse*/ true)
ALTERNATE_SCREEN.configure_input(
self.terminal.backend_mut(),
MouseCapture::Enabled.captures_mouse(self.owned_screen),
)
} else {
self.enter_alt_screen()
}
Expand Down Expand Up @@ -1649,3 +1674,18 @@ fn ensure_virtual_terminal_processing() -> Result<()> {
fn ensure_virtual_terminal_processing() -> Result<()> {
Ok(())
}

#[cfg(test)]
mod mouse_capture_policy_tests {
use super::mouse_capture_allowed;

#[test]
fn config_and_env_resolve_mouse_capture() {
assert!(mouse_capture_allowed(None, None));
assert!(!mouse_capture_allowed(Some(false), None));
assert!(!mouse_capture_allowed(None, Some("0")));
assert!(!mouse_capture_allowed(Some(true), Some("off")));
assert!(mouse_capture_allowed(Some(false), Some("1")));
assert!(!mouse_capture_allowed(Some(false), Some("garbage")));
}
}
Loading