tui: hide '/init' suggestion when AGENTS.md exists (#3038)

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`.
This commit is contained in:
Jeremy Rose
2025-09-02 12:04:32 -07:00
committed by GitHub
parent eb40fe3451
commit fcb62a0fa5

View File

@@ -657,68 +657,40 @@ pub(crate) fn new_session_info(
Some(_) => "~".to_string(), Some(_) => "~".to_string(),
None => config.cwd.display().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<Line<'static>> = vec![ let mut lines: Vec<Line<'static>> = Vec::new();
Line::from(vec![ lines.push(Line::from(vec![
Span::raw(">_ ").dim(), ">_ ".dim(),
Span::styled( "You are using OpenAI Codex in".bold(),
"You are using OpenAI Codex in", format!(" {cwd_str}").dim(),
Style::default().add_modifier(Modifier::BOLD), ]));
), lines.push(Line::from("".dim()));
Span::raw(format!(" {cwd_str}")).dim(), lines.push(Line::from(
]), " To get started, describe a task or try one of these commands:".dim(),
Line::from("".dim()), ));
Line::from(" To get started, describe a task or try one of these commands:".dim()), lines.push(Line::from("".dim()));
Line::from("".dim()), if !has_agents_md {
Line::from(vec![ lines.push(Line::from(vec![
Span::styled( " /init".bold(),
" /init", format!(" - {}", SlashCommand::Init.description()).dim(),
Style::default() ]));
.add_modifier(Modifier::BOLD) }
.fg(Color::White), lines.push(Line::from(vec![
), " /status".bold(),
Span::styled( format!(" - {}", SlashCommand::Status.description()).dim(),
format!(" - {}", SlashCommand::Init.description()), ]));
Style::default().dim(), lines.push(Line::from(vec![
), " /approvals".bold(),
]), format!(" - {}", SlashCommand::Approvals.description()).dim(),
Line::from(vec![ ]));
Span::styled( lines.push(Line::from(vec![
" /status", " /model".bold(),
Style::default() format!(" - {}", SlashCommand::Model.description()).dim(),
.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(),
),
]),
];
PlainHistoryCell { lines } PlainHistoryCell { lines }
} else if config.model == model { } else if config.model == model {
PlainHistoryCell { lines: Vec::new() } PlainHistoryCell { lines: Vec::new() }