Files
codex/codex-rs/agent-roles/src/discovery.rs
T
rhan-oai fb9311db5c Extract agent role loading into a dedicated crate (#40487)
## What changed

- Add `codex-agent-roles` for agent role configuration types, parsing,
  discovery, validation, and layered loading.
- Update `codex-core` to consume the new crate's public role configuration and
  parsing APIs.

GitOrigin-RevId: 5a963a219a581b2848dae6fd071aa31a0b5ff22c
2026-08-24 22:40:35 +00:00

41 lines
1.2 KiB
Rust

use codex_file_system::ExecutorFileSystem;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use std::io;
use std::io::ErrorKind;
pub(crate) async fn collect_agent_role_files(
fs: &dyn ExecutorFileSystem,
dir: &AbsolutePathBuf,
) -> io::Result<Vec<AbsolutePathBuf>> {
let mut files = Vec::new();
let mut dirs = vec![dir.clone()];
while let Some(dir) = dirs.pop() {
let dir_uri = PathUri::from_abs_path(&dir);
let entries = match fs.read_directory(&dir_uri, /*sandbox*/ None).await {
Ok(entries) => entries,
Err(err) if err.kind() == ErrorKind::NotFound => continue,
Err(err) => return Err(err),
};
for entry in entries {
let path = dir.join(entry.file_name);
if entry.is_directory {
dirs.push(path);
continue;
}
if entry.is_file
&& path
.as_path()
.extension()
.is_some_and(|extension| extension == "toml")
{
files.push(path);
}
}
}
files.sort();
Ok(files)
}