9ea5eb31c1
Keep the avatar mounted while all connection, permission, privacy and diagnostic controls live in a settings sheet. Save the tested continuous-body renderer, safe transition driver and foreground HELLO/permission workflow from this session. Pin runtime03 for the code14 UI-only candidate; mouth deformation remains unresolved. Add source UI contracts, an optional sensor-free device probe, exact asset import and candidate packaging checks. Portrait binaries and diagnostics remain private and untracked.
78 lines
3.4 KiB
Python
78 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Import an exact coordinator-reviewed neutral graph; runtime SHA allowlist is independent."""
|
|
from pathlib import Path
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import re
|
|
import os
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PACK = 'a01-neutral-graph-v1'
|
|
|
|
def sha(data):
|
|
return hashlib.sha256(data).hexdigest()
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('source', type=Path)
|
|
parser.add_argument('--approved-manifest-sha', required=True)
|
|
parser.add_argument('--verify-only', action='store_true')
|
|
args = parser.parse_args()
|
|
source = args.source.resolve(strict=True)
|
|
raw = (source/'manifest.json').read_bytes()
|
|
assert len(raw) <= 256_000
|
|
assert re.fullmatch('[0-9a-f]{64}', args.approved_manifest_sha)
|
|
assert sha(raw) == args.approved_manifest_sha, 'Manifest bytes differ from reviewed hash'
|
|
manifest = json.loads(raw)
|
|
assert manifest['schemaVersion'] == 1 and manifest['packId'] == PACK and manifest['identityId'] == 'a01'
|
|
graph = manifest['safeTransitions']
|
|
assert graph['version'] == 1 and graph['reviewStatus'] == 'approved'
|
|
assert len(graph['clips']) == 5
|
|
assert len(manifest['assets']) == 5
|
|
files = {'manifest.json': raw}
|
|
|
|
def read(name, expected, maximum, pattern):
|
|
assert re.fullmatch(pattern, name), f'Invalid delivery path: {name}'
|
|
path = (source/name).resolve(strict=True)
|
|
assert path.is_relative_to(source), 'Path escaped source pack'
|
|
assert path.stat().st_size <= maximum
|
|
data = path.read_bytes()
|
|
assert sha(data) == expected, f'Asset hash mismatch: {name}'
|
|
assert name not in files
|
|
files[name] = data
|
|
|
|
ids = set()
|
|
for row in manifest['assets']:
|
|
assert row['id'] not in ids
|
|
ids.add(row['id'])
|
|
assert row['emotion'] == 'neutral' and row['intensity'] == 0 and row['hasAudio'] is False
|
|
read(row['path'], row['sha256'], 16_000_000, r'(videos|delivery)/[A-Za-z0-9_.-]+\.mp4')
|
|
assert {row['assetId'] for row in graph['clips']} == ids
|
|
assert sum(map(len, files.values())) <= 128_000_000
|
|
read(manifest['staticFallbackPath'], manifest['staticFallbackSha256'], 8_000_000, r'frames/[A-Za-z0-9_.-]+\.png')
|
|
target = ROOT/'app/src/main/assets/avatar'/PACK
|
|
# Preflight every existing byte before writing anything. Never erase another pack.
|
|
for name, data in files.items():
|
|
dest = target/name
|
|
assert not dest.exists() or sha(dest.read_bytes()) == sha(data), f'Unknown existing file: {dest}'
|
|
if not args.verify_only:
|
|
for name, data in files.items():
|
|
dest = target/name
|
|
dest.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
fd, temporary = tempfile.mkstemp(prefix='.import-', dir=dest.parent)
|
|
try:
|
|
with os.fdopen(fd, 'wb') as stream:
|
|
stream.write(data)
|
|
os.chmod(temporary, 0o600)
|
|
os.replace(temporary, dest)
|
|
finally:
|
|
if os.path.exists(temporary): os.unlink(temporary)
|
|
print(json.dumps({'pack': PACK, 'manifestSha256': sha(raw), 'imported': not args.verify_only,
|
|
'runtimeActivation': 'requires exact SHA allowlist plus complete approved graph validation',
|
|
'rightsStatus': manifest.get('rightsStatus', 'unverified')}, indent=2))
|
|
|
|
if __name__ == '__main__':
|
|
main()
|