Expand description
Issue #88: project-root detection and palace-slug enforcement.
Why: prevents unbounded palace creation by anchoring palace names to the
canonical slug of the project directory that contains the CWD, or to the
personal sentinel for non-project contexts.
What: exports find_project_root, project_slug_at, project_slug,
validate_palace_name, PERSONAL_PALACE, and PROJECT_MARKERS.
Test: see unit tests inside this module.
Project-root detection and palace-slug derivation (issue #88).
Why: unbounded palace creation leads to orphaned namespaces that no longer
correspond to any project on disk. Anchoring palace names to a stable,
filesystem-derived slug ensures each project gets exactly one palace and
makes “which palace am I in?” predictable from the working directory alone.
The personal palace is the single sanctioned exception for non-project
contexts (global notes, one-off sessions).
What: project_slug() walks upward from CWD looking for canonical project
markers (.git, Cargo.toml, pyproject.toml, package.json) and
returns the slugified basename of the first ancestor that contains one.
Returns None when no project root is found (all ancestors have been
exhausted). The slug is deterministic, lowercase, filesystem-safe, and
under 64 chars.
Test: project_slug_finds_git_root, project_slug_returns_none_without_markers,
project_slug_uses_first_ancestor_marker,
project_slug_personal_always_allowed.
Constants§
- PERSONAL_
PALACE - Sentinel palace name that is always valid regardless of project context.
- PROJECT_
MARKERS - File names that mark a directory as a project root.
Functions§
- find_
project_ root - Walk upward from
startand return the first ancestor directory (inclusive) that contains at least one project marker. - project_
slug - Derive a palace slug for the current working directory.
- project_
slug_ at - Derive a palace slug from the project root found at or above
start. - validate_
palace_ name - Validate a proposed palace name against project-slug enforcement rules.