From fcb62a0fa5e81beb46483f64bea06a68dde5476b Mon Sep 17 00:00:00 2001 From: Jeremy Rose <172423086+nornagon-openai@users.noreply.github.com> Date: Tue, 2 Sep 2025 12:04:32 -0700 Subject: [PATCH] tui: hide '/init' suggestion when AGENTS.md exists (#3038) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hide the “/init” suggestion in the new-session banner when an `AGENTS.md` exists anywhere from the repo root down to the current working directory. Changes - Conditional suggestion: use `discover_project_doc_paths(config)` to suppress `/init` when agents docs are present. - TUI style cleanup: switch banner construction to `Stylize` helpers (`.bold()`, `.dim()`, `.into()`), avoiding `Span::styled`/`Span::raw`. - Fixture update: remove `/init` line in `tui/tests/fixtures/ideal-binary-response.txt` to match the new banner. Validation - Ran formatting and scoped lint fixes: `just fmt` and `just fix -p codex-tui`. - Tests: `cargo test -p codex-tui` passed (`176 passed, 0 failed`). Notes - No change to the `/init` command itself; only the welcome banner now adapts based on presence of `AGENTS.md`. --- codex-rs/tui/src/history_cell.rs | 94 +++++++++++--------------------- 1 file changed, 33 insertions(+), 61 deletions(-) diff --git a/codex-rs/tui/src/history_cell.rs b/codex-rs/tui/src/history_cell.rs index 185767be..db4609ca 100644 --- a/codex-rs/tui/src/history_cell.rs +++ b/codex-rs/tui/src/history_cell.rs @@ -657,68 +657,40 @@ pub(crate) fn new_session_info( Some(_) => "~".to_string(), None => config.cwd.display().to_string(), }; + // Discover AGENTS.md files to decide whether to suggest `/init`. + let has_agents_md = discover_project_doc_paths(config) + .map(|v| !v.is_empty()) + .unwrap_or(false); - let lines: Vec> = vec![ - Line::from(vec![ - Span::raw(">_ ").dim(), - Span::styled( - "You are using OpenAI Codex in", - Style::default().add_modifier(Modifier::BOLD), - ), - Span::raw(format!(" {cwd_str}")).dim(), - ]), - Line::from("".dim()), - Line::from(" To get started, describe a task or try one of these commands:".dim()), - Line::from("".dim()), - Line::from(vec![ - Span::styled( - " /init", - Style::default() - .add_modifier(Modifier::BOLD) - .fg(Color::White), - ), - Span::styled( - format!(" - {}", SlashCommand::Init.description()), - Style::default().dim(), - ), - ]), - Line::from(vec![ - Span::styled( - " /status", - Style::default() - .add_modifier(Modifier::BOLD) - .fg(Color::White), - ), - Span::styled( - format!(" - {}", SlashCommand::Status.description()), - Style::default().dim(), - ), - ]), - Line::from(vec![ - Span::styled( - " /approvals", - Style::default() - .add_modifier(Modifier::BOLD) - .fg(Color::White), - ), - Span::styled( - format!(" - {}", SlashCommand::Approvals.description()), - Style::default().dim(), - ), - ]), - Line::from(vec![ - Span::styled( - " /model", - Style::default() - .add_modifier(Modifier::BOLD) - .fg(Color::White), - ), - Span::styled( - format!(" - {}", SlashCommand::Model.description()), - Style::default().dim(), - ), - ]), - ]; + let mut lines: Vec> = Vec::new(); + lines.push(Line::from(vec![ + ">_ ".dim(), + "You are using OpenAI Codex in".bold(), + format!(" {cwd_str}").dim(), + ])); + lines.push(Line::from("".dim())); + lines.push(Line::from( + " To get started, describe a task or try one of these commands:".dim(), + )); + lines.push(Line::from("".dim())); + if !has_agents_md { + lines.push(Line::from(vec![ + " /init".bold(), + format!(" - {}", SlashCommand::Init.description()).dim(), + ])); + } + lines.push(Line::from(vec![ + " /status".bold(), + format!(" - {}", SlashCommand::Status.description()).dim(), + ])); + lines.push(Line::from(vec![ + " /approvals".bold(), + format!(" - {}", SlashCommand::Approvals.description()).dim(), + ])); + lines.push(Line::from(vec![ + " /model".bold(), + format!(" - {}", SlashCommand::Model.description()).dim(), + ])); PlainHistoryCell { lines } } else if config.model == model { PlainHistoryCell { lines: Vec::new() }