Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions agents/_repo_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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():
Expand All @@ -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 = []
Expand Down
8 changes: 5 additions & 3 deletions agents/conductors/batch/_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion agents/conductors/community/_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion agents/conductors/cortex/_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] = {}
Expand Down
9 changes: 6 additions & 3 deletions agents/conductors/hygiene/_hygiene_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -96,7 +99,7 @@ def pyauto_root() -> Path:
if root:
return Path(root)
# .../<checkout>/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]:
Expand All @@ -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


Expand Down Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions agents/conductors/hygiene/_hygiene_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions agents/conductors/hygiene/_hygiene_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 []

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions agents/conductors/hygiene/_hygiene_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion agents/conductors/intake/_intake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion agents/faculties/review/_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down
3 changes: 2 additions & 1 deletion agents/faculties/sizing/_sizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) -----------------
Expand Down Expand Up @@ -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 = {}

Expand Down
2 changes: 1 addition & 1 deletion bin/check_skill_line_counts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
Expand Down
3 changes: 1 addition & 2 deletions bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
Expand Down
3 changes: 2 additions & 1 deletion bin/morning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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) =="
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion bin/pyauto-brain
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
26 changes: 20 additions & 6 deletions bin/regroup_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -145,29 +148,40 @@ 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'(?<![\w/])' + re.escape(name) + r'(?=/)', lambda _, r=relative: r, after)
if path == root / '.claude/settings.json':
settings = json.loads(after)
import_roots = [str(remap(p, moves)) for p in package_paths(root)]
if import_roots:
if (root / 'PyAutoHeart').is_dir():
import_roots.append(str(root / 'PyAutoHeart'))
if repo_path(root, 'PyAutoHeart').is_dir():
import_roots.append(str(remap(repo_path(root, 'PyAutoHeart'), moves)))
environment = settings.setdefault('env', {})
previous = environment.get('PYTHONPATH', '')
environment['PYTHONPATH'] = os.pathsep.join(import_roots + ([previous] if previous else []))
after = json.dumps(settings, indent=2) + '\n'
if before != after:
configs.append({'path': str(path), 'old': before, 'new': after})
activation = root / 'activate.sh'
brain_relative = str(remap(repo_path(root, 'PyAutoBrain'), moves).relative_to(root))
heart_relative = str(remap(repo_path(root, 'PyAutoHeart'), moves).relative_to(root))
mind_relative = str(remap(repo_path(root, 'PyAutoMind'), moves).relative_to(root))
hands_relative = str(remap(repo_path(root, 'PyAutoHands'), moves).relative_to(root))
activate_text = '''# Source this file after opening a shell in the grouped workspace.
_pyauto_activation_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
export PYAUTO_ROOT="$_pyauto_activation_root"
_pyauto_import_paths="$(python3 "$PYAUTO_ROOT/PyAutoBrain/agents/_repo_paths.py" pythonpath --root "$PYAUTO_ROOT")" || return
export PYTHONPATH="$_pyauto_import_paths:$PYAUTO_ROOT/PyAutoHeart${PYTHONPATH:+:$PYTHONPATH}"
export PYAUTO_BRAIN="$PYAUTO_ROOT/@BRAIN@"
export PYAUTO_MIND="$PYAUTO_ROOT/@MIND@"
export PYAUTO_HEART="$PYAUTO_ROOT/@HEART@"
export PYAUTO_HANDS="$PYAUTO_ROOT/@HANDS@"
export PATH="$PYAUTO_BRAIN/bin:$PYAUTO_HEART/bin:$PYAUTO_HANDS/bin:$PATH"
_pyauto_import_paths="$(python3 "$PYAUTO_ROOT/@BRAIN@/agents/_repo_paths.py" pythonpath --root "$PYAUTO_ROOT")" || return
export PYTHONPATH="$_pyauto_import_paths:$PYAUTO_ROOT/@HEART@${PYTHONPATH:+:$PYTHONPATH}"
export NUMBA_CACHE_DIR="${NUMBA_CACHE_DIR:-/tmp/numba_cache}"
export MPLCONFIGDIR="${MPLCONFIGDIR:-/tmp/matplotlib}"
mkdir -p "$NUMBA_CACHE_DIR" "$MPLCONFIGDIR"
unset _pyauto_activation_root _pyauto_import_paths _pyauto_import_repo _pyauto_import_dir
'''
'''.replace('@BRAIN@', brain_relative).replace('@HEART@', heart_relative).replace('@MIND@', mind_relative).replace('@HANDS@', hands_relative)
configs.append({'path': str(activation), 'old': activation.read_text() if activation.exists() else None,
'new': activate_text})
data = {'root': str(root), 'stage': 'planned', 'repos': records,
Expand Down
Loading
Loading