|
| 1 | +#!/usr/bin/env python |
| 2 | +"""Assert every tracked file in a reference assistant falls on one side of the |
| 3 | +template boundary. |
| 4 | +
|
| 5 | +`_clone.py`'s partition already refuses to birth a newborn while any reference |
| 6 | +file is unclassified — deliberate pressure that keeps the boundary notes |
| 7 | +complete. But that pressure only lands when someone tries to give birth, which |
| 8 | +is rare, and by then the person blocked is not the person who added the file: |
| 9 | +they must go and classify someone else's work in a repo they may not know. |
| 10 | +
|
| 11 | +This runs the same check at PR time in the reference's own CI, so the author who |
| 12 | +adds a file classifies it while they still remember whether it is framework or |
| 13 | +science. Three features (the euclid mode, the JOSS paper, the results-inspector |
| 14 | +MCP wiring) each landed unclassified and silently blocked every future birth |
| 15 | +before this existed. |
| 16 | +
|
| 17 | +Usage: |
| 18 | + python check_boundary.py <reference-checkout> [--reference <name>] |
| 19 | +
|
| 20 | +`--reference` defaults to the checkout's directory name, which is how the |
| 21 | +profiles are keyed. A checkout with no profile is not a clone reference and has |
| 22 | +no boundary to grade, so it *skips* — this matters because a newborn inherits |
| 23 | +this check in its `.github/` and is not itself a reference until someone adds a |
| 24 | +profile for it. An explicitly-passed `--reference` that has no profile is still |
| 25 | +an error, so a typo cannot pass silently. |
| 26 | +
|
| 27 | +Exit codes: `0` boundary complete (or not a reference) · `1` unclassified |
| 28 | +files · `4` bad inputs. |
| 29 | +""" |
| 30 | + |
| 31 | +import argparse |
| 32 | +import importlib.util |
| 33 | +import sys |
| 34 | +from pathlib import Path |
| 35 | + |
| 36 | + |
| 37 | +def _load_clone(): |
| 38 | + spec = importlib.util.spec_from_file_location( |
| 39 | + "_clone_boundary", Path(__file__).resolve().parent / "_clone.py" |
| 40 | + ) |
| 41 | + mod = importlib.util.module_from_spec(spec) |
| 42 | + spec.loader.exec_module(mod) |
| 43 | + return mod |
| 44 | + |
| 45 | + |
| 46 | +def main(): |
| 47 | + parser = argparse.ArgumentParser(description=__doc__) |
| 48 | + parser.add_argument("checkout", help="path to the reference assistant checkout") |
| 49 | + parser.add_argument( |
| 50 | + "--reference", |
| 51 | + default=None, |
| 52 | + help="profile name to grade against (default: the checkout's dir name)", |
| 53 | + ) |
| 54 | + args = parser.parse_args() |
| 55 | + |
| 56 | + root = Path(args.checkout).resolve() |
| 57 | + if not (root / ".git").exists(): |
| 58 | + print(f"check_boundary: not a git checkout: {root}", file=sys.stderr) |
| 59 | + return 4 |
| 60 | + |
| 61 | + clone = _load_clone() |
| 62 | + name = args.reference or root.name |
| 63 | + profile = clone.REFERENCE_PROFILES.get(name) |
| 64 | + if profile is None: |
| 65 | + if args.reference is not None: |
| 66 | + # Explicitly named: a typo must not pass silently. |
| 67 | + print( |
| 68 | + f"check_boundary: no clone profile for '{name}' — supported: " |
| 69 | + f"{', '.join(sorted(clone.REFERENCE_PROFILES))}", |
| 70 | + file=sys.stderr, |
| 71 | + ) |
| 72 | + return 4 |
| 73 | + # Inferred: this repo is not a clone reference, so it has no boundary to |
| 74 | + # grade. A newborn inherits this check and lands here until (and unless) |
| 75 | + # it is promoted to a reference with a profile of its own. |
| 76 | + print(f"check_boundary: {name} is not a clone reference — nothing to grade") |
| 77 | + return 0 |
| 78 | + |
| 79 | + sets = clone.partition(root, profile) |
| 80 | + unclassified = sets["unclassified"] |
| 81 | + if not unclassified: |
| 82 | + print( |
| 83 | + f"check_boundary: {name} boundary complete — " |
| 84 | + f"generic {len(sets['generic'])} · domain {len(sets['domain'])} · " |
| 85 | + f"mixed {len(sets['mixed'])}" |
| 86 | + ) |
| 87 | + return 0 |
| 88 | + |
| 89 | + print( |
| 90 | + f"check_boundary: {len(unclassified)} file(s) in {name} fall on neither " |
| 91 | + f"side of the template boundary:\n", |
| 92 | + file=sys.stderr, |
| 93 | + ) |
| 94 | + for path in unclassified: |
| 95 | + print(f" ✗ {path}", file=sys.stderr) |
| 96 | + print( |
| 97 | + "\nEvery tracked file must be classified, because the Clone Agent " |
| 98 | + "refuses to birth a\nnewborn while any is unclassified — leaving these " |
| 99 | + "blocks every future assistant birth.\nDecide what each file is, then " |
| 100 | + "record it in BOTH places, which must agree:\n\n" |
| 101 | + " 1. modes/maintainer.md, '## Assistant-as-template' — the prose that " |
| 102 | + "OWNS the boundary\n" |
| 103 | + " 2. PyAutoBrain agents/conductors/clone/_clone.py — REFERENCE_PROFILES" |
| 104 | + f"['{name}']\n\n" |
| 105 | + " generic — framework that clones to any domain near-verbatim\n" |
| 106 | + " domain — this field's science; a newborn regrows its own\n" |
| 107 | + " mixed — generic structure, domain-specific values\n", |
| 108 | + file=sys.stderr, |
| 109 | + ) |
| 110 | + return 1 |
| 111 | + |
| 112 | + |
| 113 | +if __name__ == "__main__": |
| 114 | + sys.exit(main()) |
0 commit comments