Skip to main content

Module project_root

Module project_root 

Source
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, palace-slug derivation, and .trusty-tools/ pin file management (issue #88 + Phase 1 of the .trusty-tools/ convention).

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).

Sub-modules:

  • detection: find_project_root, PROJECT_MARKERS, TRUSTY_TOOLS_DIR, PERSONAL_PALACE, is_unsafe_pin_location.
  • pin_file: ProjectPin, PIN_SCHEMA_VERSION, PIN_FILE_REL, read_project_pin, write_project_pin, project_slug_at, project_slug_at_readonly, project_slug, project_slug_from_basename.
  • validation: validate_palace_name.

Test: project_slug_finds_git_root, project_slug_returns_none_without_markers, project_slug_uses_first_ancestor_marker, project_slug_personal_always_allowed, pin_file_read_when_present, absent_pin_writes_computed_slug, renamed_dir_with_pin_resolves_to_original_slug, trusty_tools_dir_is_project_marker, lazy_write_non_fatal_on_readonly_dir.

Structs§

ProjectPin
Serialisable schema for .trusty-tools/trusty-memory.yaml.

Constants§

PERSONAL_PALACE
Sentinel palace name that is always valid regardless of project context.
PIN_FILE_REL
Relative path of the pin file within a project root.
PIN_SCHEMA_VERSION
Schema version for .trusty-tools/trusty-memory.yaml.
PROJECT_MARKERS
File names that mark a directory as a project root.
TRUSTY_TOOLS_DIR
The .trusty-tools/ directory name (used as a project marker).

Functions§

find_project_root
Walk upward from start and return the first ancestor directory (inclusive) that contains at least one project marker.
pinned_slug_at
Return the pinned palace slug for the project at or above start, and ONLY when a committed pin file exists — never the basename fallback.
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.
project_slug_at_readonly
Derive a palace slug from the project root found at or above start, WITHOUT the lazy-write side-effect.
project_slug_from_basename
Compute the palace slug purely from the directory basename (the pre-Phase-1 logic, now extracted for composability).
read_project_pin
Read the palace pin from .trusty-tools/trusty-memory.yaml at root.
validate_palace_name
Validate a proposed palace name against project-slug enforcement rules.
write_project_pin
Write a palace pin to .trusty-tools/trusty-memory.yaml at root.