Skip to main content

project_root_for

Function project_root_for 

Source
pub fn project_root_for(cwd: &Path, markers: &[String]) -> Option<PathBuf>
Expand description

BP-9 (§3.1 core.project_root_markers, catalog:232 “Project-root detection markers”, cx§6, oc§6): the project root for cwd — the NEAREST ancestor (starting at cwd itself) that directly contains any entry named by markers. None when no ancestor carries a marker, or when markers is empty (an empty marker list is an explicit “don’t do root detection”, not an invitation to walk to /).

This is the ONE walk every marker consumer shares — the git-status probe in env_context, the CLI’s .supercode.toml discovery, and prompt assembly’s instruction walk. Sharing it is the point: “where does the project stop?” must have exactly one answer per config, or the same project_root_markers value would mean three different things.

A marker matches whether it is a file or a directory (.git is a directory in a normal checkout and a FILE in a worktree/submodule — both are the root). Symlinks are followed by exists(), and the walk is purely lexical on cwd as given: no canonicalization, so a caller that wants symlink-resolved semantics canonicalizes before calling.