diff --git a/agents/_repo_paths.py b/agents/_repo_paths.py index 52e7e44d..93e4f47f 100644 --- a/agents/_repo_paths.py +++ b/agents/_repo_paths.py @@ -40,7 +40,7 @@ def manifest_paths(root: Path) -> dict[str, Path]: two/four-space mapping grammar, including quoted path scalars, and validate every explicit placement. Other metadata is deliberately not interpreted. """ - manifest = Path(root) / 'PyAutoMind' / 'repos.yaml' + manifest = bootstrap_repo_path(Path(root), 'PyAutoMind') / 'repos.yaml' if not manifest.is_file(): return {} paths: dict[str, Path] = {} @@ -92,6 +92,31 @@ def _families(root: Path): yield path +def bootstrap_repo_path(root: Path, name: str, required: bool = False) -> Path: + """Find an infrastructure checkout before its manifest can be loaded. + + Bounded discovery uses the same flat/one-family boundary as normal lookup, + without consulting Mind (which may itself be the repository being located). + """ + root = Path(root) + name = _name(name) + candidates = [root / name] + candidates.extend(family / name for family in _families(root) + if is_checkout(family / name) + or (not (root / name).is_dir() and name == 'PyAutoMind' + and (family / name / 'repos.yaml').is_file())) + existing = {} + for path in candidates: + if path.is_dir(): + existing.setdefault(path.resolve(), path) + if len(existing) > 1: + raise ValueError(f'{name}: ambiguous checkouts: ' + ', '.join(map(str, existing.values()))) + result = next(iter(existing.values()), root / name) + if required and not is_checkout(result): + raise FileNotFoundError(f'{name}: repository checkout missing at {result}') + return result + + def iter_checkouts(root: Path) -> list[Path]: """Actual flat or family checkouts, including symlinked bundle dependencies. @@ -126,7 +151,8 @@ def repo_path(root: Path, name: str, required: bool = False) -> Path: if len(declared.parts) > 1 and (root / declared.parts[0]).is_symlink(): raise ValueError(f'{name}: repository family must not be a symlink: {root / declared.parts[0]}') candidates = [root / name, root / declared] - candidates.extend(family / name for family in _families(root)) + candidates.extend(family / name for family in _families(root) + if is_checkout(family / name)) existing: dict[Path, Path] = {} for path in candidates: if path.is_dir(): @@ -148,7 +174,7 @@ def package_paths(root: Path) -> list[Path]: """Import roots for packages declared by the body map, in manifest order.""" root = Path(root) declared = manifest_paths(root) - manifest = root / 'PyAutoMind/repos.yaml' + manifest = bootstrap_repo_path(root, 'PyAutoMind') / 'repos.yaml' if not manifest.is_file(): return [] names = [] diff --git a/agents/conductors/batch/_integration.py b/agents/conductors/batch/_integration.py index 3bf3377d..6414e3a5 100644 --- a/agents/conductors/batch/_integration.py +++ b/agents/conductors/batch/_integration.py @@ -45,6 +45,7 @@ import sys sys.path.insert(0, str(Path(__file__).resolve().parents[2])) from _repo_paths import repo_path # noqa: E402 +from _pyauto_root import pyauto_root # noqa: E402 BRAIN = Path(__file__).resolve().parents[3] WORKTREE_SH = BRAIN / "bin" / "worktree.sh" @@ -82,7 +83,7 @@ def workspace_root() -> Path: operator's word and always wins; otherwise it is the parent of this Brain checkout, which is true in every environment the organism runs in. """ - return Path(os.environ.get("PYAUTO_ROOT") or BRAIN.parent) + return pyauto_root() def task_name(slot: str) -> str: @@ -182,9 +183,10 @@ def plan_jobs(members: list, order: list, notes: list) -> list: "want_sha": str(p.get("head_sha") or "")}) jobs = [] for g in groups.values(): - if not (workspace_root() / g["dir"] / ".git").exists(): + checkout = repo_path(workspace_root(), g["dir"]) + if not (checkout / ".git").exists(): notes.append(f"{g['repo']}: no checkout at " - f"{workspace_root() / g['dir']} — left out of the " + f"{checkout} — left out of the " f"integration root") continue jobs.append(g) diff --git a/agents/conductors/community/_community.py b/agents/conductors/community/_community.py index 258b62ff..90851812 100644 --- a/agents/conductors/community/_community.py +++ b/agents/conductors/community/_community.py @@ -47,6 +47,7 @@ # a non-existent tree in a remote session and reported empty rather than # failing. sys.path.insert(0, str(Path(__file__).resolve().parents[2])) +from _repo_paths import repo_path import _pyauto_root # noqa: E402 PYAUTO_ROOT = _pyauto_root.pyauto_root() @@ -104,7 +105,7 @@ def gh_json(args): def repo_homes(): """Every `github:` home in PyAutoMind/repos.yaml (regex, stdlib-only — no yaml dependency in the Brain).""" - body_map = PYAUTO_ROOT / "PyAutoMind" / "repos.yaml" + body_map = repo_path(PYAUTO_ROOT, "PyAutoMind") / "repos.yaml" if not body_map.is_file(): fail(4, f"body map not found: {body_map} (set PYAUTO_ROOT)") homes = re.findall( diff --git a/agents/conductors/cortex/_cortex.py b/agents/conductors/cortex/_cortex.py index 9178b301..3a967316 100644 --- a/agents/conductors/cortex/_cortex.py +++ b/agents/conductors/cortex/_cortex.py @@ -62,6 +62,7 @@ # The one workspace-root resolver (agents/_pyauto_root.py, mirrored by # bin/_pyauto_root.sh) — never a literal path. sys.path.insert(0, str(BRAIN_HOME / "agents")) +from _repo_paths import repo_path import _pyauto_root # noqa: E402 # The shared board theme: the one place that answers "what does a one-tap @@ -103,7 +104,7 @@ def resolve_root(explicit: str | None = None) -> Path: sibling = BRAIN_HOME.parent / CORTEX_REPO if sibling.is_dir(): return sibling - return _pyauto_root.pyauto_root() / CORTEX_REPO + return repo_path(_pyauto_root.pyauto_root(), CORTEX_REPO) _SCRIPTS: dict[str, object] = {} diff --git a/agents/conductors/hygiene/_hygiene_ci.py b/agents/conductors/hygiene/_hygiene_ci.py index 39574470..bc1a8e2b 100755 --- a/agents/conductors/hygiene/_hygiene_ci.py +++ b/agents/conductors/hygiene/_hygiene_ci.py @@ -73,6 +73,9 @@ HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) from _hygiene_repos import resolve_map # noqa: E402 +sys.path.insert(0, str(HERE.parents[2])) +from _repo_paths import repo_path # noqa: E402 +import _pyauto_root # noqa: E402 DEFAULT_HEART = "PyAuto" + "Heart" # an organ: framework identity, not an instance fact BOARD_FILENAME = "board.json" @@ -96,7 +99,7 @@ def pyauto_root() -> Path: if root: return Path(root) # ...//agents/conductors/hygiene/_hygiene_ci.py -> the repos' parent - return HERE.parents[3] + return _pyauto_root.pyauto_root() def candidate_sources(explicit: str | None, heart_repo: str) -> list[str]: @@ -110,7 +113,7 @@ def candidate_sources(explicit: str | None, heart_repo: str) -> list[str]: if org: out.append(f"https://{org.lower()}.github.io/{heart_repo}/{BOARD_FILENAME}") for rel in (Path("board") / BOARD_FILENAME, Path("docs") / BOARD_FILENAME, Path(BOARD_FILENAME)): - out.append(str(pyauto_root() / heart_repo / rel)) + out.append(str(repo_path(pyauto_root(), heart_repo) / rel)) return out @@ -255,7 +258,7 @@ def levers_from_text(text: str) -> list[dict]: def attach_levers(items: list[dict], scripts_root: Path) -> None: for item in items: - path = scripts_root / str(item.get("repo") or "") / str(item.get("entry") or "") + path = repo_path(scripts_root, str(item.get("repo") or "")) / str(item.get("entry") or "") try: text = path.read_text(encoding="utf-8", errors="replace") if path.is_file() else None except OSError: diff --git a/agents/conductors/hygiene/_hygiene_config.py b/agents/conductors/hygiene/_hygiene_config.py index 3c5f055e..c00f754d 100755 --- a/agents/conductors/hygiene/_hygiene_config.py +++ b/agents/conductors/hygiene/_hygiene_config.py @@ -52,6 +52,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname( os.path.dirname(os.path.abspath(__file__))))) import _pyauto_root # noqa: E402 +from _repo_paths import repo_path # noqa: E402 def _default_root() -> str: @@ -136,8 +137,10 @@ def diff_detail(root: str, pairs=PAIRS) -> list[tuple[str, str, list[str]]]: """ records: list[tuple[str, str, list[str]]] = [] for lib_rel, ws_rel in pairs: - lib_dir = os.path.join(root, lib_rel) - ws_dir = os.path.join(root, ws_rel) + lib_repo, _, lib_subdir = lib_rel.partition("/") + ws_repo, _, ws_subdir = ws_rel.partition("/") + lib_dir = str(repo_path(root, lib_repo) / lib_subdir) + ws_dir = str(repo_path(root, ws_repo) / ws_subdir) if not (os.path.isdir(lib_dir) and os.path.isdir(ws_dir)): continue repo = ws_rel.split("/")[0] @@ -173,7 +176,7 @@ def library_config_relpaths(root: str, libraries=LIBRARIES) -> set[str]: reachability reference the orphan check compares against.""" out: set[str] = set() for repo, pkg in libraries: - cfg = os.path.join(root, repo, pkg, "config") + cfg = str(repo_path(root, repo) / pkg / "config") if os.path.isdir(cfg): out |= _yaml_relpaths(cfg) return out diff --git a/agents/conductors/hygiene/_hygiene_extras.py b/agents/conductors/hygiene/_hygiene_extras.py index ae9819ce..08025a58 100644 --- a/agents/conductors/hygiene/_hygiene_extras.py +++ b/agents/conductors/hygiene/_hygiene_extras.py @@ -54,7 +54,7 @@ import sys sys.path.insert(0, str(Path(__file__).resolve().parents[2])) -from _repo_paths import iter_checkouts # noqa: E402 +from _repo_paths import iter_checkouts, repo_path # noqa: E402 # The extra mode=release installs for every library, and therefore the coverage # mode=smoke is expected to match. @@ -117,7 +117,7 @@ def install_roots( root: Path, step: re.Pattern[str] ) -> list[tuple[str, tuple[str, ...]]]: """Requirement roots the given install step passes to pip, in order.""" - workflow = root / WORKFLOW + workflow = repo_path(root, WORKFLOW.parts[0]) / Path(*WORKFLOW.parts[1:]) if not workflow.exists(): return [] @@ -210,7 +210,7 @@ def closure( def missing(root: Path) -> tuple[list[dict], str | None]: """Return (findings, skip-reason). A skip-reason means nothing was scannable.""" - if not (root / WORKFLOW).exists(): + if not (repo_path(root, WORKFLOW.parts[0]) / Path(*WORKFLOW.parts[1:])).exists(): return [], f"{WORKFLOW} is not present under the scan root" checkouts = libraries(root) diff --git a/agents/conductors/hygiene/_hygiene_repos.py b/agents/conductors/hygiene/_hygiene_repos.py index c725664d..0578a1af 100755 --- a/agents/conductors/hygiene/_hygiene_repos.py +++ b/agents/conductors/hygiene/_hygiene_repos.py @@ -42,6 +42,10 @@ import sys from pathlib import Path +sys.path.insert(0, str(Path(__file__).resolve().parents[2])) +from _repo_paths import bootstrap_repo_path # noqa: E402 +from _pyauto_root import pyauto_root # noqa: E402 + MAP_FILENAME = "repos.yaml" # The Mind is an organ, so its directory name is framework identity rather than @@ -66,10 +70,11 @@ def candidate_map_paths() -> list[Path]: if override and Path(override).is_dir(): return [Path(override)] candidates: list[Path] = [] - candidates.append(brain_parent / MIND_REPO) + candidates.append(bootstrap_repo_path(pyauto_root(), MIND_REPO)) root = os.environ.get("PYAUTO_ROOT") if root: - candidates.append(Path(root) / MIND_REPO) + candidates.append(bootstrap_repo_path(Path(root), MIND_REPO)) + candidates.append(brain_parent / MIND_REPO) home = Path.home() candidates += [home / MIND_REPO, home / "Code" / MIND_REPO] return candidates diff --git a/agents/conductors/intake/_intake.py b/agents/conductors/intake/_intake.py index 77d989a4..4ec286d6 100755 --- a/agents/conductors/intake/_intake.py +++ b/agents/conductors/intake/_intake.py @@ -53,6 +53,8 @@ # same ranking function the `/memory` verb prints — one recall implementation. sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "faculties" / "memory")) import _memory # noqa: E402 +sys.path.insert(0, str(Path(__file__).resolve().parents[2])) +from _repo_paths import repo_path # noqa: E402 # The shared board theme: the one place that answers "what does a one-tap board # look like". Presentation only — the stylesheet, the hero, the pills — so this @@ -559,7 +561,7 @@ def _next_action(proposed, confidence, work_type=None): def _memory_home(mind: Path) -> Path | None: """The PyAutoMemory checkout beside this Mind, or None when it is absent.""" override = os.environ.get("PYAUTO_MEMORY", "") - home = Path(override) if override else mind.parent / "PyAutoMemory" + home = Path(override) if override else repo_path(mind.parent, "PyAutoMemory") return home if home.is_dir() else None diff --git a/agents/faculties/review/_review.py b/agents/faculties/review/_review.py index dab0e7da..8a67c49c 100755 --- a/agents/faculties/review/_review.py +++ b/agents/faculties/review/_review.py @@ -135,7 +135,7 @@ def in_place_repos(task: str) -> list[Path]: entry lists its repos there and the checkouts live at the workspace root. """ pyauto_root = _pyauto_root.pyauto_root() - active = pyauto_root / "PyAutoMind" / "active.md" + active = repo_path(pyauto_root, "PyAutoMind") / "active.md" if not active.exists(): return [] repos: list[Path] = [] diff --git a/agents/faculties/sizing/_sizing.py b/agents/faculties/sizing/_sizing.py index 7f0c722b..1f95fd7d 100755 --- a/agents/faculties/sizing/_sizing.py +++ b/agents/faculties/sizing/_sizing.py @@ -43,6 +43,7 @@ import sys sys.path.insert(0, str(Path(__file__).resolve().parents[2])) +from _pyauto_root import pyauto_root from _repo_paths import repo_path # noqa: E402 # --- the PyAutoMind taxonomy (mirrors PyAutoMind/ROUTING.md) ----------------- @@ -92,7 +93,7 @@ def norm_work_type(value: str) -> str: BRAIN_HOME = Path(__file__).resolve().parents[3] POLICY_PATH = BRAIN_HOME / "config" / "policy.yaml" -BODY_MAP_PATH = repo_path(BRAIN_HOME.parent, "PyAutoMind") / "repos.yaml" +BODY_MAP_PATH = repo_path(pyauto_root(), "PyAutoMind") / "repos.yaml" _POLICY_CACHE: dict = {} diff --git a/bin/check_skill_line_counts.sh b/bin/check_skill_line_counts.sh index ec6041b7..50a5d4d2 100755 --- a/bin/check_skill_line_counts.sh +++ b/bin/check_skill_line_counts.sh @@ -16,7 +16,7 @@ set -euo pipefail LIMIT="${1:-200}" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -PYAUTO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +. "$SCRIPT_DIR/_pyauto_root.sh" . "$SCRIPT_DIR/_repo_paths.sh" for _repo in PyAutoMind PyAutoBrain PyAutoHeart PyAutoHands autolens_profiling; do pyauto_repo_path "$_repo" "$PYAUTO_ROOT" >/dev/null || exit $? diff --git a/bin/install.sh b/bin/install.sh index eeaaee5c..e12976f3 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -50,8 +50,7 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -DEFAULT_PYAUTO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" -PYAUTO_ROOT="${PYAUTO_ROOT:-$DEFAULT_PYAUTO_ROOT}" +. "$SCRIPT_DIR/_pyauto_root.sh" . "$SCRIPT_DIR/_repo_paths.sh" for _repo in PyAutoMind PyAutoBrain PyAutoMemory PyAutoHeart PyAutoHands autolens_profiling PyAutoFit; do pyauto_repo_path "$_repo" "$PYAUTO_ROOT" >/dev/null || exit $? diff --git a/bin/morning.sh b/bin/morning.sh index dbb28d8c..956c2b56 100755 --- a/bin/morning.sh +++ b/bin/morning.sh @@ -28,6 +28,7 @@ set -u HERE="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)" +. "$HERE/_pyauto_root.sh" . "$HERE/_repo_paths.sh" echo "== morning: sync every repo to main (ff-only; real work is skipped) ==" @@ -51,7 +52,7 @@ if [ "${1:-}" != "--no-publish" ]; then # saw (the observation expires after 48h). Publishing it here, beside the # Brain's, is what keeps those eight rows lit — they went grey because this # leg did not exist and the last hand-run was a week old. - heart_checkout="$(pyauto_repo_path PyAutoHeart "$HERE/../..")" || exit $? + heart_checkout="$(pyauto_repo_path PyAutoHeart "$PYAUTO_ROOT")" || exit $? heart="$heart_checkout/bin/pyauto-heart" if [ -x "$heart" ]; then echo diff --git a/bin/pyauto-brain b/bin/pyauto-brain index 377155b6..acb2909e 100755 --- a/bin/pyauto-brain +++ b/bin/pyauto-brain @@ -180,7 +180,9 @@ ensure_session_environment() { [[ "${CLAUDE_CODE_REMOTE:-}" == "true" ]] || return 0 [[ -z "${PYAUTO_SKIP_BOOTSTRAP:-}" ]] || return 0 local boot - boot="$PYAUTO_ROOT/PyAutoMind/scripts/session_bootstrap.sh" + local mind_checkout + mind_checkout="$(resolve_mind)" || return 0 + boot="$mind_checkout/scripts/session_bootstrap.sh" [[ -x "$boot" ]] || return 0 bash "$boot" >/dev/null 2>&1 || true } diff --git a/bin/regroup_workspace.py b/bin/regroup_workspace.py index df5daf32..0a50548f 100644 --- a/bin/regroup_workspace.py +++ b/bin/regroup_workspace.py @@ -102,6 +102,8 @@ def plan(root, state, bundles_root=None, manifest_root=None): records.append({'name': name, 'old': str(old), 'new': str(new), 'before': snapshot(old), 'worktrees': worktrees}) moves.append((str(old), str(new))) + if any(state.absolute().is_relative_to(Path(old)) for old, _ in moves): + raise ValueError('migration journal must be outside every checkout being moved') roots = [root] if bundles_root is not None and bundles_root.exists(): roots.append(bundles_root.absolute()) @@ -132,7 +134,8 @@ def plan(root, state, bundles_root=None, manifest_root=None): configs = [] # These are local, workspace-owned paths, not versioned source or shell RCs. config_paths = list((root / '.idea').glob('*.xml')) + list((root / '.idea').glob('*.iml')) - config_paths += [root / '.claude/settings.json'] + config_paths += [root / '.claude/settings.json', root / '.codex/hooks.json', + root / 'AGENTS.md', root / 'CLAUDE.md'] for path in config_paths: if not path.is_file() or path.is_symlink(): continue @@ -145,12 +148,14 @@ def plan(root, state, bundles_root=None, manifest_root=None): after = re.sub(re.escape(old) + r'(?=[/"\s:<]|$)', lambda _: new, after) for prefix in ('$PROJECT_DIR$/', '$MODULE_DIR$/', './', '${CLAUDE_PROJECT_DIR}/', '$CLAUDE_PROJECT_DIR/', '${PYAUTO_ROOT}/', '$PYAUTO_ROOT/'): after = re.sub(re.escape(prefix + name) + r'(?=[/"\s<]|$)', lambda _, p=prefix, r=relative: p+r, after) + if path.name in ('AGENTS.md', 'CLAUDE.md'): + after = re.sub(r'(?` branches. `worktree_check_conflict` fails closed when it cannot read the registry. A repo bullet beneath an active task's `repos:` is a claim; tasks touching the same repo serialize unless a human explicitly diff --git a/skills/board/board.md b/skills/board/board.md index f1b058b4..28d27dcf 100644 --- a/skills/board/board.md +++ b/skills/board/board.md @@ -39,7 +39,7 @@ nothing; every chip on it routes back through the real doors. human-gated job; closing issues stays `/issue_cleanup`'s; deletion stays `/repo_cleanup`'s. The board only names the door. 4. The local sync/clean leg is not yours to run from chat — it is the - terminal command `bash PyAutoBrain/bin/morning.sh` on the human's machine. + terminal command `bash "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/morning.sh"` on the human's machine. Publishing (`--apply`) is CI's job (`brain_board.yml`); run it manually only when asked to debug the render, writing under `_site/` or a scratch dir. diff --git a/skills/hygiene/hygiene.md b/skills/hygiene/hygiene.md index 170c6b39..70a7ec61 100644 --- a/skills/hygiene/hygiene.md +++ b/skills/hygiene/hygiene.md @@ -41,7 +41,7 @@ Shared routing context: `PyAutoBrain/skills/COMMANDS.md`. debris), `/cli_noise_clean`, `/dep_audit`, `/audit_docs` — for the full audit, or for `perf` route slow imports/functions to `/refactor` / `/bug` (JAX-adapt is a judgement call, never automatic). For `packaging`, preview with - `DRY_RUN=1 PyAutoBrain/bin/clean_slate.sh --packaging`, then run it without `DRY_RUN` to + `DRY_RUN=1 "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/clean_slate.sh" --packaging`, then run it without `DRY_RUN` to remove only the reported generated directories. For `docstrings`, `escapes` and `refs`, route the exact reported findings to `/refactor`; the Hygiene scan remains read-only. A `refs` finding is the reference **as written** — judge the intended target diff --git a/skills/intake/intake.md b/skills/intake/intake.md index 001ede16..408fa8b6 100644 --- a/skills/intake/intake.md +++ b/skills/intake/intake.md @@ -36,7 +36,7 @@ Shared routing context: `PyAutoBrain/skills/COMMANDS.md`. until the page that offers the task is rebuilt: ```bash - cd $PYAUTO_MAIN/PyAutoMind + cd "${PYAUTO_MIND:-$(test -d "$PYAUTO_MAIN/organs/PyAutoMind" && echo "$PYAUTO_MAIN/organs/PyAutoMind" || echo "$PYAUTO_MAIN/PyAutoMind")}" pyauto-brain intake --apply dashboard # writes dashboard.md + dashboard.html pyauto-brain intake dashboard --check # must print "…are current" source scripts/prompt_sync.sh && prompt_sync_push "intake: file " diff --git a/skills/prm/reference.md b/skills/prm/reference.md index 86306da7..5793863b 100644 --- a/skills/prm/reference.md +++ b/skills/prm/reference.md @@ -197,7 +197,7 @@ gh api -X PATCH repos///issues/ -f state=closed --jq .state # ### 3. Mind: active/ → complete/ ```bash -cd $PYAUTO_MAIN/PyAutoMind +cd "${PYAUTO_MIND:-$(test -d "$PYAUTO_MAIN/organs/PyAutoMind" && echo "$PYAUTO_MAIN/organs/PyAutoMind" || echo "$PYAUTO_MAIN/PyAutoMind")}" git rev-parse --abbrev-ref HEAD # must be main — check BEFORE writing python3 scripts/lifecycle.py record --date --from-file --prompt --apply ``` @@ -248,7 +248,7 @@ current. prompt: ```bash -cd $PYAUTO_MAIN/PyAutoMind +cd "${PYAUTO_MIND:-$(test -d "$PYAUTO_MAIN/organs/PyAutoMind" && echo "$PYAUTO_MAIN/organs/PyAutoMind" || echo "$PYAUTO_MAIN/PyAutoMind")}" grep -rn "\|" draft/ active/ epics.md \ active.md planned.md parked.md condemned.md ``` @@ -264,7 +264,7 @@ without asking. A folder is the handful this merge could plausibly have finished: ```bash -BRAIN=$PYAUTO_MAIN/PyAutoBrain/agents/conductors/intake/_intake.py +BRAIN="${PYAUTO_BRAIN:-$(test -d "$PYAUTO_MAIN/organs/PyAutoBrain" && echo "$PYAUTO_MAIN/organs/PyAutoBrain" || echo "$PYAUTO_MAIN/PyAutoBrain")}/agents/conductors/intake/_intake.py" python3 "$BRAIN" --mind . reconcile draft// ``` @@ -351,7 +351,7 @@ Then remove it properly — never `rm -rf`: ```bash export PYAUTO_MAIN=$HOME/Code/PyAutoLabs -source PyAutoBrain/bin/worktree.sh && worktree_remove +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" && worktree_remove ``` It **refuses** on a dirty repo, and on a merged task whose `active.md` claim is diff --git a/skills/repo_cleanup/SKILL.md b/skills/repo_cleanup/SKILL.md index 9b5d6961..ab49625d 100644 --- a/skills/repo_cleanup/SKILL.md +++ b/skills/repo_cleanup/SKILL.md @@ -83,7 +83,7 @@ environments". Branch buckets only; stashes and worktrees stay laptop-only. ### 1. Setup ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" ``` Provides `worktree_list_claimed`, `worktree_root_path`, `PYAUTO_LIBS`, diff --git a/skills/repo_cleanup/reference.md b/skills/repo_cleanup/reference.md index 66980ece..47b0b185 100644 --- a/skills/repo_cleanup/reference.md +++ b/skills/repo_cleanup/reference.md @@ -8,10 +8,11 @@ recap, and the execution-environment fallback. ## Audit canonical checkouts -For each in-scope repo at `$PYAUTO_MAIN/`: +For each in-scope repo resolved from `$PYAUTO_MAIN`: ```bash -repo_path="$PYAUTO_MAIN/" +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/_repo_paths.sh" +repo_path="$(pyauto_repo_path "" "$PYAUTO_MAIN")" [[ -d "$repo_path/.git" ]] || { echo "skip: $repo_path (not a git repo)"; continue; } current=$(git -C "$repo_path" branch --show-current) dirty=$(git -C "$repo_path" status --porcelain | head) @@ -29,7 +30,7 @@ any content not already in `origin/main`?** Use the blessed tool, never a hand-rolled ahead-count or `git cherry`/`merge-tree` one-off (those were wrong three times — docs/agent_failure_modes.md D1/D2): ```bash -source PyAutoBrain/bin/branch_contribution.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/branch_contribution.sh" branch_contribution "$repo_path" origin/main # MERGED/ABSORBED = safe; CONTRIBUTES = keep/inspect; UNKNOWN = never delete ``` An ahead-count alone over-reports (a squash-/cherry-merged branch is "ahead" yet diff --git a/skills/ship_library/reference.md b/skills/ship_library/reference.md index a85ac19c..53586228 100644 --- a/skills/ship_library/reference.md +++ b/skills/ship_library/reference.md @@ -102,7 +102,7 @@ Build/release step. Per repo, after the vitals faculty / Heart verdict is GREEN: (paste the drafted body verbatim via HEREDOC). Then **verify the label landed**: `gh pr view --json labels --jq '[.labels[].name]'`. If `pending-release` is absent, stop and report — usually the label doesn't - exist on the repo; fix with `bash PyAutoBrain/bin/ensure_workspace_labels.sh` + exist on the repo; fix with `bash "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/ensure_workspace_labels.sh"` then `gh pr edit --add-label pending-release`. If `gh pr create`/`gh pr edit` errors (SSH-URL origin, classic-Projects GraphQL failure), use the `gh api` fallbacks in `skills/OPERATIONS.md`. @@ -178,7 +178,7 @@ ledger (issues #71/#81): - **Write the record** — one step: it folds + removes the `active/` prompt, refreshes `complete/index.md`, and prunes the task's `active.md` section (all the state `lifecycle.py check` drift-checks): - `python3 PyAutoMind/scripts/lifecycle.py record --date --from-file --prompt --apply` + `python3 "${PYAUTO_MIND:-$(test -d organs/PyAutoMind && echo organs/PyAutoMind || echo PyAutoMind)}/scripts/lifecycle.py" record --date --from-file --prompt --apply` Then push Mind with `prompt_sync_push "prompt: ship (#) → complete"`. diff --git a/skills/ship_library/ship_library.md b/skills/ship_library/ship_library.md index 7841bb45..d854ef72 100644 --- a/skills/ship_library/ship_library.md +++ b/skills/ship_library/ship_library.md @@ -24,7 +24,7 @@ PR format, the execution contract, and the impact analysis are in Read `PyAutoMind/active.md` for the task's `worktree:` and `repos:` list. ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" WT_ROOT=~/Code/PyAutoLabs-wt/ source "$WT_ROOT/activate.sh" ``` diff --git a/skills/ship_workspace/reference.md b/skills/ship_workspace/reference.md index 0aaa3a97..98500a20 100644 --- a/skills/ship_workspace/reference.md +++ b/skills/ship_workspace/reference.md @@ -120,7 +120,7 @@ SHIP_EOF (all the state `lifecycle.py check` drift-checks): ```bash -python3 PyAutoMind/scripts/lifecycle.py record --date --from-file --prompt --apply +python3 "${PYAUTO_MIND:-$(test -d organs/PyAutoMind && echo organs/PyAutoMind || echo PyAutoMind)}/scripts/lifecycle.py" record --date --from-file --prompt --apply ``` Push Mind: `prompt_sync_push "prompt: ship (#) → complete"`. diff --git a/skills/ship_workspace/ship_workspace.md b/skills/ship_workspace/ship_workspace.md index e6066cb8..05b28aa4 100644 --- a/skills/ship_workspace/ship_workspace.md +++ b/skills/ship_workspace/ship_workspace.md @@ -24,7 +24,7 @@ and issue/Mind formats are in [`reference.md`](reference.md). Read `PyAutoMind/active.md` for the task's `worktree:` and `repos:` list. ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" WT_ROOT=~/Code/PyAutoLabs-wt/ source "$WT_ROOT/activate.sh" ``` diff --git a/skills/start_bundle/start_bundle.md b/skills/start_bundle/start_bundle.md index 25021a9c..03e67eb7 100644 --- a/skills/start_bundle/start_bundle.md +++ b/skills/start_bundle/start_bundle.md @@ -40,7 +40,7 @@ issue, and never open issues for members you have not planned. Create the worktree **once** for the whole bundle, not once per member: ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_create [repo2 ...] ``` diff --git a/skills/start_dev/reference.md b/skills/start_dev/reference.md index b7994301..1d95acf3 100644 --- a/skills/start_dev/reference.md +++ b/skills/start_dev/reference.md @@ -101,7 +101,7 @@ PyAutoMind. Shared organ boundary and the execution-environment model are in Source the worktree helper and list anything already claimed by another task: ```bash - source PyAutoBrain/bin/worktree.sh + source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_list_claimed ``` diff --git a/skills/start_dev/start_dev.md b/skills/start_dev/start_dev.md index f9530560..21559d44 100644 --- a/skills/start_dev/start_dev.md +++ b/skills/start_dev/start_dev.md @@ -75,7 +75,7 @@ Default runs without the flag are unchanged: present-and-wait. ### 0. Sync + resume check (Mind) ```bash -source PyAutoMind/scripts/prompt_sync.sh +source "${PYAUTO_MIND:-$(test -d organs/PyAutoMind && echo organs/PyAutoMind || echo PyAutoMind)}/scripts/prompt_sync.sh" prompt_sync_new_prompts # sweep up any new local prompt ideas (no-op if none) ``` @@ -143,7 +143,7 @@ routing decision. ### 6. Register in Mind + route ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_check_conflict [repo2 ...] ``` @@ -163,7 +163,7 @@ classification. registration (active.md / planned.md) added in step 6: ```bash -source PyAutoMind/scripts/prompt_sync.sh +source "${PYAUTO_MIND:-$(test -d organs/PyAutoMind && echo organs/PyAutoMind || echo PyAutoMind)}/scripts/prompt_sync.sh" prompt_sync_push "prompt: route (#) → " ``` diff --git a/skills/start_dev_for_user/start_dev_for_user.md b/skills/start_dev_for_user/start_dev_for_user.md index 5a4443e5..a6529b9f 100644 --- a/skills/start_dev_for_user/start_dev_for_user.md +++ b/skills/start_dev_for_user/start_dev_for_user.md @@ -81,7 +81,7 @@ developer review** — template in [`reference.md`](reference.md) → "Plan comm ### 6. Conflict check + register (Mind) ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_check_conflict [repo2 ...] ``` @@ -96,7 +96,7 @@ repo, branch, classification, plus the user-facing reminder ([`reference.md`](reference.md) → "Routing note"). Push Mind: ```bash -source PyAutoMind/scripts/prompt_sync.sh +source "${PYAUTO_MIND:-$(test -d organs/PyAutoMind && echo organs/PyAutoMind || echo PyAutoMind)}/scripts/prompt_sync.sh" prompt_sync_push "prompt: route (#) → [user-facing]" ``` diff --git a/skills/start_library/start_library.md b/skills/start_library/start_library.md index c12201af..c635dd17 100644 --- a/skills/start_library/start_library.md +++ b/skills/start_library/start_library.md @@ -16,7 +16,7 @@ the worktree helpers, the execution-environment model, and the registry paths. ### 1. Conflict guard ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_check_conflict [repo2 ...] ``` @@ -49,7 +49,7 @@ library work ships first (`/ship_library`), workspace follows. ### 4. Create the task worktree (feature-dev mechanics, local-dev) ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_create [repo2 ...] ``` @@ -93,7 +93,7 @@ The ` - ` bullets under `repos:` are the claim — they are what informational and may be omitted. Then: ```bash -source PyAutoMind/scripts/prompt_sync.sh +source "${PYAUTO_MIND:-$(test -d organs/PyAutoMind && echo organs/PyAutoMind || echo PyAutoMind)}/scripts/prompt_sync.sh" prompt_sync_push "prompt: register library repos in active.md" ``` diff --git a/skills/start_workspace/reference.md b/skills/start_workspace/reference.md index d0afbb0f..efef0fef 100644 --- a/skills/start_workspace/reference.md +++ b/skills/start_workspace/reference.md @@ -31,7 +31,7 @@ present as symlinks. Replace each affected workspace symlink with a real worktre on the same branch: ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_add_repo autofit_workspace # one call per affected workspace repo ``` @@ -42,7 +42,7 @@ runs happen inside `$WT_ROOT/`. ## Creating a worktree for a standalone workspace task ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_create [workspace_repo2 ...] ``` @@ -55,7 +55,7 @@ Before `/ship_workspace` runs, assert the canonical `pending-release` label so the later `gh pr create --label pending-release` cannot silently fail: ```bash -bash PyAutoBrain/bin/ensure_workspace_labels.sh +bash "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/ensure_workspace_labels.sh" ``` It is idempotent (no-op when nothing drifted) and bootstraps the label where diff --git a/skills/start_workspace/start_workspace.md b/skills/start_workspace/start_workspace.md index 2eea4b43..8225f8e9 100644 --- a/skills/start_workspace/start_workspace.md +++ b/skills/start_workspace/start_workspace.md @@ -18,7 +18,7 @@ helpers, execution-environment model, and registry paths. Verbose formats live i ### 1. Conflict guard ```bash -source PyAutoBrain/bin/worktree.sh +source "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/worktree.sh" worktree_check_conflict [workspace_repo2 ...] ``` diff --git a/skills/wake_up/SKILL.md b/skills/wake_up/SKILL.md index 90e2cf91..39053de2 100644 --- a/skills/wake_up/SKILL.md +++ b/skills/wake_up/SKILL.md @@ -7,6 +7,6 @@ description: Superseded morning door — the routine now lives on the Brain boar Follow [`wake_up.md`](wake_up.md) exactly. The morning routine is now the **Brain board** (`https://.github.io/PyAutoBrain/`) plus one terminal -command (`bash PyAutoBrain/bin/morning.sh`); this skill is the fallback that +command (`bash "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/morning.sh"`); this skill is the fallback that runs the same legs interactively. Auto-run only the non-destructive steps and surface everything destructive for approval. diff --git a/skills/wake_up/wake_up.md b/skills/wake_up/wake_up.md index 8d89a3ea..c7fb8851 100644 --- a/skills/wake_up/wake_up.md +++ b/skills/wake_up/wake_up.md @@ -2,7 +2,7 @@ **The morning routine no longer runs through this skill.** It is now: -1. **Terminal** (local, not a Claude chat): `bash PyAutoBrain/bin/morning.sh` — +1. **Terminal** (local, not a Claude chat): `bash "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/morning.sh"` — the sync + clean-slate leg (ff-only pull of every repo, git-aware cleanup of regenerable artifacts). `--digest` appends the board's markdown digest. 2. **The Brain board** — `https://.github.io/PyAutoBrain/` (rendered by @@ -23,7 +23,7 @@ the identical digest in a terminal when a page is not at hand. `/wake_up` stays a working door, for a stale board or a no-browser session: -1. **Local sync/clean** — run `bash PyAutoBrain/bin/morning.sh` (auto-run is +1. **Local sync/clean** — run `bash "${PYAUTO_BRAIN:-$(test -d organs/PyAutoBrain && echo organs/PyAutoBrain || echo PyAutoBrain)}/bin/morning.sh"` (auto-run is safe: both steps are the recoverable, git-aware ones — sync skips repos with real uncommitted work; clean-slate deletes only untracked regenerable artifacts and reports orphan datasets instead of removing them). Skip with diff --git a/tests/test_grouped_organ_consumers.py b/tests/test_grouped_organ_consumers.py new file mode 100644 index 00000000..4dd8128c --- /dev/null +++ b/tests/test_grouped_organ_consumers.py @@ -0,0 +1,63 @@ +"""Runtime callers use organ placement while the marker stays at the outer root.""" + +from __future__ import annotations + +import importlib.util +import sys +from pathlib import Path + + +BRAIN = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(BRAIN / "agents")) + + +def _load(name: str, relative: str): + spec = importlib.util.spec_from_file_location(name, BRAIN / relative) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def _grouped(tmp_path: Path) -> Path: + (tmp_path / ".pyauto-root").touch() + organs = tmp_path / "organs" + for name in ("PyAutoBrain", "PyAutoMind", "PyAutoMemory", "PyAutoHeart"): + (organs / name).mkdir(parents=True) + (organs / name / ".git").mkdir() + return organs + + +def test_intake_memory_finds_grouped_checkout(tmp_path, monkeypatch): + organs = _grouped(tmp_path) + (organs / "PyAutoMind" / "repos.yaml").write_text( + (BRAIN.parent / "PyAutoMind" / "repos.yaml").read_text()) + monkeypatch.setenv("PYAUTO_ROOT", str(tmp_path)) + intake = _load("grouped_intake", "agents/conductors/intake/_intake.py") + assert intake._memory_home(organs / "PyAutoMind") == organs / "PyAutoMemory" + + +def test_hygiene_map_and_heart_board_find_grouped_checkouts(tmp_path, monkeypatch): + organs = _grouped(tmp_path) + (organs / "PyAutoMind" / "repos.yaml").write_text("repos:\n") + monkeypatch.setenv("PYAUTO_ROOT", str(tmp_path)) + repos = _load("grouped_hygiene_repos", "agents/conductors/hygiene/_hygiene_repos.py") + assert repos.resolve_map() == organs / "PyAutoMind" / "repos.yaml" + ci = _load("grouped_hygiene_ci", "agents/conductors/hygiene/_hygiene_ci.py") + assert str(organs / "PyAutoHeart" / "board" / "board.json") in ci.candidate_sources(None, "PyAutoHeart") + + +def test_hygiene_config_reads_grouped_nerves(tmp_path): + organs = _grouped(tmp_path) + source = organs / "PyAutoNerves" / "autonerves" / "config" + source.mkdir(parents=True) + (organs / "PyAutoNerves" / ".git").mkdir() + (source / "general.yaml").write_text("test: true\n") + config = _load("grouped_hygiene_config", "agents/conductors/hygiene/_hygiene_config.py") + assert "general.yaml" in config.library_config_relpaths(str(tmp_path), [("PyAutoNerves", "autonerves")]) + + +def test_batch_root_uses_outer_marker(tmp_path, monkeypatch): + _grouped(tmp_path) + monkeypatch.setenv("PYAUTO_ROOT", str(tmp_path)) + batch = _load("grouped_integration", "agents/conductors/batch/_integration.py") + assert batch.workspace_root() == tmp_path diff --git a/tests/test_regroup_workspace.py b/tests/test_regroup_workspace.py index 88be63f9..321891ae 100644 --- a/tests/test_regroup_workspace.py +++ b/tests/test_regroup_workspace.py @@ -106,3 +106,27 @@ def test_journal_does_not_follow_preexisting_temp_link(tmp_path): migration.save(journal, {'stage': 'planned'}) assert important.read_text() == 'KEEP' assert 'planned' in journal.read_text() + + +def test_moving_manifest_checkout_keeps_journal_and_rollback_working(tmp_path): + import pytest + root, _, bundles, _ = fixture(tmp_path) + mind = root / 'PyAutoMind' + manifest = mind / 'repos.yaml' + manifest.write_text(manifest.read_text() + ' PyAutoMind:\n path: organs/PyAutoMind\n') + git(mind, 'init', '-q') + git(mind, 'config', 'user.email', 'test@example.org') + git(mind, 'config', 'user.name', 'Test') + git(mind, 'add', 'repos.yaml') + git(mind, 'commit', '-qm', 'manifest') + with pytest.raises(ValueError, match='journal must be outside'): + migration.plan(root, mind / 'journal.json', bundles) + journal = tmp_path / 'journal.json' + data = migration.plan(root, journal, bundles) + migration.apply(journal, data) + assert migration.manifest_paths(root)['Demo'] == Path('science/Demo') + assert not mind.exists() + assert journal.exists() + migration.verify(data) + migration.rollback(journal, data) + assert manifest.exists() diff --git a/tests/test_repo_paths.py b/tests/test_repo_paths.py index 53179b45..1105dc83 100644 --- a/tests/test_repo_paths.py +++ b/tests/test_repo_paths.py @@ -109,3 +109,19 @@ def test_pythonpath_follows_manifest_package_order(tmp_path): first = checkout(tmp_path / 'science/Demo') second = checkout(tmp_path / 'Other') assert paths.package_paths(tmp_path) == [first, second] + + +def test_grouped_mind_bootstraps_its_own_manifest(tmp_path): + bootstrap_repo_path = paths.bootstrap_repo_path + manifest_paths = paths.manifest_paths + package_paths = paths.package_paths + mind = tmp_path / 'organs/PyAutoMind' + mind.mkdir(parents=True) + (mind / '.git').mkdir() + (mind / 'repos.yaml').write_text('repos:\n PyAutoMind:\n path: organs/PyAutoMind\n Demo:\n path: science/Demo\n package: demo\n') + assert bootstrap_repo_path(tmp_path, 'PyAutoMind', required=True) == mind + assert manifest_paths(tmp_path)['Demo'] == Path('science/Demo') + assert package_paths(tmp_path) == [tmp_path / 'science/Demo'] + (tmp_path / 'PyAutoMind').mkdir() + with pytest.raises(ValueError, match='ambiguous'): + manifest_paths(tmp_path)