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(),
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![
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<Line<'static>> = 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() }