"""Read-only checks; full schema validation optional and explicitly reported.""" from pathlib import Path import argparse, json, re from urllib.parse import unquote from build_content_index import make_index, validate_index, read_json def validate(root,schemas=True): root=Path(root).resolve(); manifest=read_json(root/'repository.json'); variables=read_json(root/'repository-variables.json'); index=read_json(root/'content-index.json') for p in root.rglob('*.json'): if 'receipts' not in p.parts: read_json(p) validate_index(root,index) if index!=make_index(root): raise ValueError('Stale content index; rebuild required') version=(root/'VERSION').read_text().strip() if manifest['version']!=version: raise ValueError('Repository version mismatch') citation=(root/'CITATION.cff').read_text(); author=(root/'AUTHOR.md').read_text() if not re.search(r'^version: '+re.escape(version)+r'$',citation,re.M): raise ValueError('Citation version mismatch') if '## '+version+' ' not in (root/'CHANGELOG.md').read_text(): raise ValueError('Missing version changelog') for key,value in variables['repository'].items(): if manifest.get(key)!=value: raise ValueError('Repository identity mismatch: '+key) if variables['identity']['authors']!=manifest['authors'] or variables['identity']['publisher']!=manifest['publisher']: raise ValueError('Attribution mismatch') if variables['identity']['maintainer']['name']!=manifest['maintenance']['maintainer']: raise ValueError('Maintainer mismatch') for key,value in variables['rights'].items(): if manifest['rights'][key]!=value: raise ValueError('Rights mismatch') if 'Eddie Soehnel' not in author or manifest['canonical_url'] not in author or 'family-names: Soehnel' not in citation or 'MIT License' not in (root/'LICENSE').read_text(): raise ValueError('Human attribution/license mismatch') paths=list(manifest['entrypoints'].values())+[i['path'] for i in manifest['contents']]+manifest['ai_retrieval']['read_first']+manifest['ai_retrieval']['retrieve_as_needed'] for path in paths: if path and not (root/path).exists(): raise ValueError('Missing declared path: '+path) for path in ['README.md','AUTHOR.md','AGENTS.md','skills.md','CONTRIBUTING.md','SECURITY.md','examples/README.md','scripts/README.md','skills/seo-geo-research/SKILL.md']: p=root/path for dest in re.findall(r'\[[^\]]*\]\(([^)]+)\)',p.read_text()): dest=dest.strip('<>').split('#')[0] if not dest or re.match(r'[a-zA-Z]+:',dest): continue if not (p.parent/unquote(dest)).resolve().exists(): raise ValueError('Broken relative link in '+path+': '+dest) for p in [root/'README.md',root/'AUTHOR.md',root/'repository.json',root/'repository-variables.json']: if re.search(r'(?:ghp_[A-Za-z0-9]{20,}|sk-[A-Za-z0-9]{20,}|BEGIN (?:RSA |OPENSSH )?PRIVATE KEY)',p.read_text()): raise ValueError('Possible secret in '+p.name) schema_result='not requested' if schemas: try: import jsonschema except ImportError: schema_result='UNAVAILABLE: jsonschema is not installed; core checks passed' else: for name,data in [('repository',manifest),('repository-variables',variables),('content-index',index)]: schema=read_json(root/f'schemas/{name}.schema.json'); jsonschema.Draft202012Validator(schema,format_checker=jsonschema.FormatChecker()).validate(data) schema_result='PASS: all three template JSON Schemas' return {'status':'PASS','documents':len(index['items']),'schemas':schema_result,'checks':['JSON','attribution','version alignment','declared paths','index freshness','unique IDs and paths','relationships','changed-entrypoint relative links','obvious-secret patterns']} if __name__=='__main__': parser=argparse.ArgumentParser(); parser.add_argument('--root',default=str(Path(__file__).resolve().parents[1])); args=parser.parse_args(); print(json.dumps(validate(args.root),indent=2))