From 40f38ddb4e51c071a662865421cf1f05abe717a1 Mon Sep 17 00:00:00 2001 From: "kh.ai" Date: Mon, 3 Nov 2025 10:30:20 -0800 Subject: [PATCH] tui: fix auto-scope detection + confirmation - Default include=true when omitted in auto-scope JSON - Run folder detection + confirmation only for options 3 & 4 - Lock auto-scope model to fast gpt-5-codex - Use exact confirmed paths for collection/specs - Add unit test for missing include flag Also ran fmt, clippy (tui), and tests (tui). --- codex-rs/tui/src/chatwidget.rs | 12 +++++------- codex-rs/tui/src/security_review.rs | 27 +++++++++++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 8ddcd9ada7..1288991aed 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -2872,13 +2872,11 @@ impl ChatWidget { progress_percent: Some(0), }); - let annotated_scope_prompt = if matches!(mode, SecurityReviewMode::Bugs) { - scope_prompt - .as_ref() - .map(|prompt| annotate_scope_prompt(prompt.as_str())) - } else { - None - }; + // Enable auto-scope when a scope prompt is provided (options 3 and 4). + // We annotate the prompt for both Full and Bugs modes. + let annotated_scope_prompt = scope_prompt + .as_ref() + .map(|prompt| annotate_scope_prompt(prompt.as_str())); let request = SecurityReviewRequest { repo_path, diff --git a/codex-rs/tui/src/security_review.rs b/codex-rs/tui/src/security_review.rs index f1ae92ebc7..88621012b8 100644 --- a/codex-rs/tui/src/security_review.rs +++ b/codex-rs/tui/src/security_review.rs @@ -1429,8 +1429,7 @@ pub(crate) async fn run_security_review( let mut include_paths = request.include_paths.clone(); let git_link_info = build_git_link_info(&repo_path).await; - if matches!(request.mode, SecurityReviewMode::Bugs) - && include_paths.is_empty() + if include_paths.is_empty() && let Some(prompt) = request.auto_scope_prompt.as_ref().and_then(|value| { let trimmed = value.trim(); if trimmed.is_empty() { @@ -1440,11 +1439,8 @@ pub(crate) async fn run_security_review( } }) { - let auto_scope_model = if request.triage_model.trim().is_empty() { - AUTO_SCOPE_MODEL - } else { - request.triage_model.as_str() - }; + // Always use the fast model for auto-scope regardless of triage_model. + let auto_scope_model = AUTO_SCOPE_MODEL; record(format!( "Auto-detecting review scope from user prompt: {prompt}" @@ -3168,10 +3164,13 @@ fn parse_include_flag(value: &Value) -> Option { } fn parse_raw_auto_scope_selection(map: &Map) -> Option { + // Be tolerant: default to include=true when the model omits the flag. + // Older prompts mandated an explicit include flag, but newer responses + // often omit it when the intent is clearly to include the path. let include = map .get("include") .and_then(parse_include_flag) - .unwrap_or(false); + .unwrap_or(true); if !include { return None; } @@ -3862,6 +3861,18 @@ ALL let result = parse_paths(input).expect("expected selections"); assert_eq!(result, vec![("backend".to_string(), None)],); } + + #[test] + fn defaults_to_include_when_flag_missing() { + // Model may omit `include`; treat as include=true. + let input = r#" +{"path": "api"} +{"path": "docs", "include": false} +"#; + + let result = parse_paths(input).expect("expected selections"); + assert_eq!(result, vec![("api".to_string(), None)],); + } } #[cfg(test)]