#!/usr/bin/env python3 """install_mimo_tools.py — canonical MiMo tool installer (TTY-repair tranche). Canonical sources: config/mimo-tools/{bash.ts,await-operation.ts} Targets: ~/.mimocode/tools/{bash.ts,await-operation.ts} Verifies hashes after install; detects drift in both directions (the parity test reads these hashes). """ import hashlib import shutil import sys from pathlib import Path REPO = Path(__file__).resolve().parent.parent TOOLS = ["bash.ts", "await-operation.ts"] def sha256(p: Path) -> str: return hashlib.sha256(p.read_bytes()).hexdigest() def main() -> int: rc = 0 for name in TOOLS: canon = REPO / "config" / "mimo-tools" / name target = Path.home() / ".mimocode" / "tools" / name if not canon.is_file(): print(f"{name}: canonical source missing: {canon}") rc = 1 continue canon_hash = sha256(canon) if target.is_file() and sha256(target) == canon_hash: print(f"{name}: in-sync {canon_hash[:12]}") continue drift = f"DRIFT canonical={canon_hash[:12]}" if target.is_file(): drift += f" installed={sha256(target)[:12]}" else: drift += " installed=MISSING" print(f"{name}: {drift} — installing") target.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(canon, target) if sha256(target) != canon_hash: print(f"{name}: INSTALL FAILED (hash mismatch after copy)") rc = 1 else: print(f"{name}: installed {canon_hash[:12]}") return rc if __name__ == "__main__": sys.exit(main())