fd2482e3e6
Only .git, botignore.toml, and .botignore.toml define project boundaries. A bare .botignore is a policy file, not a root marker. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
28 lines
876 B
Rust
28 lines
876 B
Rust
use std::path::{Path, PathBuf};
|
|
|
|
/// Markers checked in priority order when walking up from a target path.
|
|
const MARKERS: &[&str] = &["botignore.toml", ".botignore.toml", ".git"];
|
|
|
|
/// Walk upward from `target` (or its parent if `target` is a file) looking
|
|
/// for the nearest project root. Roots are identified by the presence of
|
|
/// any marker in `MARKERS`. Walks from the **target file's location**, not
|
|
/// from cwd, because agents `cd` around.
|
|
pub fn find_project_root(target: &Path) -> Option<PathBuf> {
|
|
let start = if target.is_file() {
|
|
target.parent()?
|
|
} else {
|
|
target
|
|
};
|
|
|
|
let mut current = Some(start);
|
|
while let Some(dir) = current {
|
|
for marker in MARKERS {
|
|
if dir.join(marker).exists() {
|
|
return Some(dir.to_path_buf());
|
|
}
|
|
}
|
|
current = dir.parent();
|
|
}
|
|
None
|
|
}
|