Files
myagents/bin/project_root.py
T
Zhengshou Lai ab597d1d02 refactor: rename source dir to bin, reorganize templates, remove personal info
- Rename myclaude/ source directory → bin/
- Update all Python imports (myclaude.* → bin.*) and mock patch paths
- Update pyproject.toml: entry point and packages config
- Move workspace_template/ → templates/workspace/ for future extensibility
- Migrate .claude/skills/ to global ~/.claude/skills/ and remove local copies
- Remove SessionStart hook (sync-global.sh) from settings.local.json
- Remove unrelated script rename_funcs_to_snake.py
- Remove personal info (name, org, paths) from CLAUDE.md, README.md, settings
- Update .gitignore with standard Python/runtime exclusions
- Clean .DS_Store, __pycache__, .mypy_cache, .pytest_cache, .ruff_cache,
  .playwright-mcp runtime files
2026-04-26 09:37:13 +08:00

79 lines
2.1 KiB
Python

"""Resolve myclaude repository and workspace roots."""
import os
from pathlib import Path
def _pyproject_names_myclaude(path: Path) -> bool:
try:
text = path.read_text(encoding="utf-8", errors="ignore")
except OSError:
return False
return 'name = "myclaude"' in text or "name = 'myclaude'" in text
def _walk_up_for_pyproject(start: Path) -> Path | None:
p = start.resolve()
for _ in range(16):
candidate = p / "pyproject.toml"
if candidate.is_file() and _pyproject_names_myclaude(candidate):
return p
parent = p.parent
if parent == p:
break
p = parent
return None
def get_myclaude_project_root() -> Path:
"""
Root of the myclaude repo (contains Makefile + pyproject).
Order: MYCLAUDE_PROJECT_ROOT > walk from cwd > package source tree > ~/.myclaude
"""
env_root = os.environ.get("MYCLAUDE_PROJECT_ROOT")
if env_root:
return Path(env_root).resolve()
try:
cwd = Path.cwd()
except (OSError, PermissionError):
cwd = None
if cwd is not None:
found = _walk_up_for_pyproject(cwd)
if found is not None:
return found
here = Path(__file__).resolve().parent
for _ in range(8):
pyproject = here / "pyproject.toml"
if pyproject.is_file() and _pyproject_names_myclaude(pyproject):
return here
if here.parent == here:
break
here = here.parent
return Path.home() / ".myclaude"
def get_workspace_root() -> Path:
"""
Root of the myclaude workspace directory.
Order: MYCLAUDE_WORKSPACE_ROOT > project_root/workspace/ > ~/workspace
Creates the directory if it does not exist.
"""
env_root = os.environ.get("MYCLAUDE_WORKSPACE_ROOT")
if env_root:
root = Path(env_root).expanduser().resolve()
else:
project_root = get_myclaude_project_root()
project_workspace = project_root / "workspace"
if project_workspace.is_dir():
root = project_workspace
else:
root = Path.home() / "workspace"
root.mkdir(parents=True, exist_ok=True)
return root