Files
myagents/mybot/project_root.py
T
Zhengshou Lai b98d35c387 feat: add mybot CLI with update, chat, and Claude project config
- Click entrypoint: mybot update (make install / pip -e), mybot chat (claude in repo)
- Optional --dangerously-skip-permissions for Claude Code
- Makefile install; hatchling package layout
- .gitignore: venv, build artifacts, workspace (local symlinks)

Made-with: Cursor
2026-04-06 13:11:10 +08:00

57 lines
1.5 KiB
Python

"""Resolve mybot repository root for make / editable install flows."""
import os
from pathlib import Path
def _pyproject_names_mybot(path: Path) -> bool:
try:
text = path.read_text(encoding="utf-8", errors="ignore")
except OSError:
return False
return 'name = "mybot"' in text or "name = 'mybot'" 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_mybot(candidate):
return p
parent = p.parent
if parent == p:
break
p = parent
return None
def get_mybot_project_root() -> Path:
"""
Root of the mybot repo (contains Makefile + pyproject).
Order: MYBOT_PROJECT_ROOT > walk from cwd > package source tree > ~/.mybot
"""
env_root = os.environ.get("MYBOT_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_mybot(pyproject):
return here
if here.parent == here:
break
here = here.parent
return Path.home() / ".mybot"