Collapse home paths in AGENTS.md status summaries (#40502)

## What changed

- Render AGENTS.md paths under the home directory with `~` in `/status`.
- Preserve project-relative paths for instruction files inside or above the current working directory.

## Testing

- Add coverage for home-relative, parent, current-directory, and nested AGENTS.md paths.

GitOrigin-RevId: 6dd1ddf481d95dda9d16f7c03a7431d1297f87ec
This commit is contained in:
Eric Traut
2026-08-25 00:29:28 +00:00
committed by copyberry
parent 5918c743f3
commit ebe18fc982

View File

@@ -11,7 +11,7 @@ use codex_utils_path_uri::PathUri;
use std::path::Path;
fn normalize_agents_display_path(path: &Path) -> String {
dunce::simplified(path).display().to_string()
format_directory_display(dunce::simplified(path), /*max_width*/ None)
}
pub(crate) fn compose_model_display(
@@ -276,6 +276,32 @@ mod tests {
);
}
#[tokio::test]
async fn compose_agents_summary_collapses_home_and_preserves_project_relative_paths() {
let Some(home) = dirs::home_dir() else {
return;
};
let codex_home = TempDir::new().expect("temp codex home");
let cwd = TempDir::new().expect("temp cwd");
let mut config = test_config(&codex_home, &cwd).await;
config.cwd = home.join("workspace").join("project").abs();
let paths = [
home.join(".codex").join("AGENTS.md"),
home.join("workspace").join("AGENTS.md"),
config.cwd.join("AGENTS.md").to_path_buf(),
config.cwd.join("nested").join("AGENTS.md").to_path_buf(),
]
.map(|path| PathUri::from_abs_path(&path.abs()));
let summary = compose_agents_summary(&config, &paths);
insta::assert_snapshot!(
summary.replace('\\', "/"),
@"~/.codex/AGENTS.md, ../AGENTS.md, AGENTS.md, nested/AGENTS.md"
);
}
#[tokio::test]
async fn compose_agents_summary_names_global_agents_override() {
let codex_home = TempDir::new().expect("temp codex home");