Files
rune/scripts/admit_wave_worktree_isolation.py
Nick 3432f6d3ba feat(factory): worktree isolation enforcement — per-wave git worktrees, landing gate judges the merged result
factory_worktree.py: create (git worktree add rune-wave-<hash>),
enter, land (merge inside throwaway rune-merge worktree, run
unified_check.py + check_landing.py against the MERGED tree, green =
CLEARED TO LAND), cleanup. No subcommand writes files or moves refs
in the main tree (update-ref ref-surgery rejected — phantom-dirty +
silent no-op, probe-proven). 8 frozen tests red-first. Landing gate
catches breakage at merge: unbuildable Go module, RED manifest,
missing manifest. Main-session verify: own runs green.
2026-10-18 00:38:39 +01:00

126 lines
5.0 KiB
Python

"""Admission dispatch for wave worktree-isolation (2026-10-17).
classify + activate + admit (the headless scaffolding entry law,
scripts/admit_wave_shared_build_integrity.py pattern): the factory
worktree-isolation law as runtime machinery on the existing rune
project, owner directive dispatched after 30 waves on one shared tree
caused repeated boot-implodes, file sweeps and compile races.
DECLARED EXEMPTION: the touched surface is factory/gate machinery
itself (scripts/factory_worktree.py + frozen tests), approved as this
wave's own scope by the owner dispatch (approval_ref below), not an
ungoverned edit.
"""
import json
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from rune import construction_activation as cact # noqa: E402
from rune import construction_admission as cadm # noqa: E402
from rune import construction_mode as cmode # noqa: E402
from rune import scaffold as sc # noqa: E402
ROOT = os.path.join(os.path.dirname(__file__), "..")
OBJECTIVE = (
"enforce the factory worktree-isolation law mechanically (owner "
"directive, 2026-10-17: 30 waves on ONE shared tree caused repeated "
"boot-implodes — a sibling's syntax error in the shared rune-entry "
"module shipped into the user's boot — plus git add -A file sweeps "
"and compile races): (1) scripts/factory_worktree.py create/enter/"
"land/cleanup gives every wave an ISOLATED git worktree "
"(git worktree add rune-wave-<hash>, a SIBLING of the repo, on a "
"wave/<name> branch — duplicate wave names refused per the "
"duplicate-spawn law); (2) land merges the wave inside a throwaway "
"rune-merge-<hash> worktree and runs the unified runner (the merged "
"tree's own scripts/unified_check.py — evidence) and then the "
"LANDING GATE — the owner's scripts/check_landing.py, the protected "
"class the factory cannot modify — against that MERGED result, "
"never the mid-flight tree; (3) the main tree stays bootable "
"ALWAYS: no subcommand writes a file or moves a ref in the main "
"checkout — update-ref surgery was tried and leaves the main "
"checkout phantom-dirty with a no-op ff-only forever after, so "
"land instead CLEARS the wave (verified merged tree sha printed) "
"and the MAIN SESSION applies the gate-proven same-parents merge "
"serially; a target that moved mid-land refuses with re-land; "
"(4) cleanup removes the wave worktree and branches"
)
AFFECTED = [
"scripts/factory_worktree.py",
"tests/test_factory_worktree.py",
]
def main() -> int:
store = os.path.join(ROOT, "store", "scaffold")
scaffold = sc.Scaffold(store, "rune")
md = cmode.classify_mode(
OBJECTIVE,
target_project="rune",
project_exists=True,
affected_surface=AFFECTED,
)
print("classified mode:", md.mode)
need = {
"need_id": "need-wave-worktree-isolation",
"objective": OBJECTIVE,
"origin": "worker",
"project": "rune",
"task_ref": "wave-worktree-isolation",
"affected_surface": AFFECTED,
"evidence_refs": [
"scripts/factory_worktree.py",
"scripts/check_landing.py",
"scripts/unified_check.py",
"AGENTS.md",
],
}
act = cact.activate(md, need=need, scaffold=scaffold,
builder="wave-worktree-isolation")
print("activated:", act.get("activated"), act.get("mode"))
env = cadm.admit(
act,
objective=OBJECTIVE,
builder="wave-worktree-isolation",
affected_surface=AFFECTED,
evidence_refs=need["evidence_refs"],
origin="worker",
task_ref="wave-worktree-isolation",
expected_new_entities=[
"scripts/factory_worktree.py (create/enter/land/cleanup "
"per-wave isolated worktrees)",
],
expected_runtime_effects=[
"waves work in sibling rune-wave-<hash> worktrees on "
"wave/<name> branches; the main tree is never written",
"land gates the MERGED result (runner evidence + the "
"owner's check_landing.py) and clears serial landing; "
"breakage at merge is refused with nothing landed",
],
verification_obligations=[
"red-first: all 8 frozen tests in "
"tests/test_factory_worktree.py RED before the tool "
"existed, GREEN after (create/land/cleanup round-trip; "
"main tree untouched during wave and land; gate catches "
"unbuildable merged tree / RED manifest / missing "
"manifest)",
"own run: pytest tests/test_factory_worktree.py 8/8 "
"green; adjacent tests/test_check_landing.py unchanged "
"and green",
],
approval_ref="user:wave-worktree-isolation dispatch",
contract_id="ADMIT-wave-worktree-isolation",
project_store=store,
project_id="rune",
)
print(json.dumps(env, indent=2, default=str)[:2400])
return 0 if env.get("success") else 1
if __name__ == "__main__":
sys.exit(main())