#!/usr/bin/env python3
from pathlib import Path
import re,sys,json
R=['SKILL.md','references/identity2-shot-roundtable.md','references/screenplay-to-storyboard-compiler.md','references/storyboard-format-contract.md','references/coverage-editing-continuity-contract.md','references/performance-sound-ai-interface.md','references/failure-gates-and-validation.md','references/beat-clustering-shot-decision-contract.md','references/production-expansion-boundary-contract.md','references/pov-information-density-energy-contract.md','references/creative-cut-safety-coverage-setup-contract.md','references/rollback-paired-learning-contract.md','references/three-authority-upstream-handoff.md','scripts/validate_storyboard_package.py','scripts/validate_rendered_storyboard.py','scripts/audit_legacy_storyboard.py','scripts/run_self_tests.py','fixtures/storyboard-package-test-fixture.json','fixtures/rendered-storyboard-test-fixture.md','fixtures/three-authority-upstream-handoff-test-fixture.json','scripts/validate_three_authority_handoff.py','scripts/run_three_authority_handoff_tests.py']
r=Path(sys.argv[1] if len(sys.argv)>1 else '.');e=[f'missing {x}' for x in R if not (r/x).is_file()];s=(r/'SKILL.md').read_text(encoding='utf-8') if (r/'SKILL.md').exists() else ''
if not re.match(r'^---\nname:\s*\S+',s):e.append('invalid frontmatter')
for x in re.findall(r'\]\((references/[^)]+)\)',s):
 if not (r/x).exists():e.append('broken '+x)
for term in ['N_MIN','N_COVERAGE','N_EDIT','N_SETUP','beat-clustering-shot-decision-contract.md','production-expansion-boundary-contract.md','three-authority-upstream-handoff.md']:
 if term not in s:e.append('SKILL missing governance term '+term)
print(json.dumps({'status':'PASS' if not e else 'FAIL','errors':e},ensure_ascii=False,indent=2));raise SystemExit(0 if not e else 1)
