#!/usr/bin/env python3 """User-authorized metadata-only derivative of the exact expressions-r02 delivery. Preserves owner input and all media bytes. Does not import, build, approve or register. """ import argparse import importlib.util import json from pathlib import Path import shutil ROOT = Path(__file__).resolve().parents[1] SOURCE_PIN = '0758672dd2ca8686f32c5e1062bca0d4bbf19063b036a42db71c1050ecb08d08' def derive(source, output): spec = importlib.util.spec_from_file_location('expression_media_gate', ROOT/'scripts/package-avatar-emotion.py') gate = importlib.util.module_from_spec(spec);spec.loader.exec_module(gate) source = Path(source).resolve(strict=True);output = Path(output).absolute() gate.require(gate.file_sha(source/'manifest.json') == SOURCE_PIN, 'exact source pin required') gate.require(not output.exists() and not output.is_symlink() and not output.resolve().is_relative_to(source), 'new derivative outside owner input required') gate.require(not any(p.is_symlink() for p in source.rglob('*')), 'source symlink') original = gate.read_json(source/'manifest.json') index = json.loads(json.dumps(original)) action = next(a for a in index['actions'] if a['id'] == 'asset_02') clip = gate.locate(source,action['clip']['path']) gate.require(gate.file_sha(clip)==action['clip']['sha256'], 'action clip drift') measured = gate.probe_music_clip(clip) gate.require(action['audioEndUs']==8_000_000 and measured['audioEndUs']==7_940_998, 'unexpected audio endpoint; re-audit required') action['audioEndUs'] = measured['audioEndUs'] restored = json.loads(json.dumps(index)) next(a for a in restored['actions'] if a['id']=='asset_02')['audioEndUs'] = 8_000_000 gate.require(restored==original, 'derivative changes more than audioEndUs') for row in original['files']: p=gate.locate(source,row['path']) gate.require(p.stat().st_size==row['bytes'] and gate.file_sha(p)==row['sha256'], 'source inventory drift') shutil.copytree(source,output) raw=(json.dumps(index,indent=2,ensure_ascii=False)+'\n').encode() (output/'manifest.json').write_bytes(raw) pin=gate.sha(raw) (output/'manifest.sha256').write_text(pin+' manifest.json\n') for row in index['files']: p=gate.locate(output,row['path']) gate.require(p.stat().st_size==row['bytes'] and gate.file_sha(p)==row['sha256'], 'derivative media/inventory drift') gate.require(gate.file_sha(source/'manifest.json')==SOURCE_PIN, 'owner source changed') return {'authorization':'user_requested_deterministic_self_correction', 'sourceIndexSha256':SOURCE_PIN, 'derivedIndexSha256':pin,'changedField':'actions[asset_02].audioEndUs','before':8_000_000,'after':7_940_998, 'mediaFilesChanged':0,'runtimeManifestsChanged':0,'runtimeReady':'unchanged_false', 'independentPiApproval':False,'gatewayChanged':False,'output':str(output)} if __name__=='__main__': parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--source',type=Path,required=True);parser.add_argument('--output',type=Path,required=True) args=parser.parse_args();print(json.dumps(derive(args.source,args.output),indent=2)+'\n')