Skip to content

Projects

projects

Project tracking for Crux — register, list, and prune tracked projects.

Tracked projects are stored in ~/.crux/projects.json with the schema::

{"projects": [{"path": "...", "name": "...", "registered_at": "..."}]}

register_project

register_project(project_path, name, *, projects_file=None)

Register a project path. No-op if already registered.

Source code in src/crux_cli/projects.py
def register_project(project_path: Path, name: str, *, projects_file: Path | None = None) -> None:
    """Register a project path. No-op if already registered."""
    data = _load_projects_file(projects_file)
    abs_path = str(project_path.resolve())

    for entry in data["projects"]:
        if entry["path"] == abs_path:
            return

    data["projects"].append({
        "path": abs_path,
        "name": name,
        "registered_at": datetime.now(tz=UTC).isoformat(),
    })
    _save_projects_file(data, projects_file)

list_projects

list_projects(*, projects_file=None)

Return all tracked projects.

Source code in src/crux_cli/projects.py
def list_projects(*, projects_file: Path | None = None) -> list[dict[str, Any]]:
    """Return all tracked projects."""
    data = _load_projects_file(projects_file)
    return data["projects"]

detect_stale_projects

detect_stale_projects(*, projects_file=None)

Return tracked projects whose paths no longer exist on disk.

Source code in src/crux_cli/projects.py
def detect_stale_projects(*, projects_file: Path | None = None) -> list[dict[str, Any]]:
    """Return tracked projects whose paths no longer exist on disk."""
    projects = list_projects(projects_file=projects_file)
    return [p for p in projects if not Path(p["path"]).exists()]

remove_stale_projects

remove_stale_projects(*, projects_file=None)

Remove all stale projects and return the removed entries.

Source code in src/crux_cli/projects.py
def remove_stale_projects(*, projects_file: Path | None = None) -> list[dict[str, Any]]:
    """Remove all stale projects and return the removed entries."""
    data = _load_projects_file(projects_file)
    stale = [p for p in data["projects"] if not Path(p["path"]).exists()]
    if stale:
        stale_paths = {p["path"] for p in stale}
        data["projects"] = [p for p in data["projects"] if p["path"] not in stale_paths]
        _save_projects_file(data, projects_file)
    return stale