367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
109 lines
6.5 KiB
Python
109 lines
6.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Prepare additive private class bits in isolated runtime evidence only."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import warrior_cooldown_modifier as flat
|
|
import warrior_cooldown_private_bits as private
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def sha(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def prepare(args):
|
|
output = args.output.resolve()
|
|
if not output.is_relative_to(ROOT / 'runtime') or output.exists():
|
|
raise ValueError('fresh isolated runtime output required')
|
|
report_path = args.candidate / 'report.json'
|
|
if sha(report_path) != args.candidate_report_sha256:
|
|
raise ValueError('candidate report digest differs')
|
|
baseline = json.loads(report_path.read_text())
|
|
for name, digest in baseline['output_sha256'].items():
|
|
if Path(name).name != name or sha(args.candidate / name) != digest:
|
|
raise ValueError('candidate inventory artifact differs')
|
|
for name, digest in baseline['input_sha256'].items():
|
|
path = Path(name).resolve()
|
|
if not path.is_relative_to(ROOT) or sha(path) != digest:
|
|
raise ValueError('original candidate input differs')
|
|
source = json.loads((args.candidate / 'source-class-inventory.json').read_text())
|
|
target = json.loads((args.candidate / 'native-class4-inventory.json').read_text())
|
|
profile = json.loads((args.candidate / 'mapping-profile.json').read_text())
|
|
flat.validate_profile(profile, source, target)
|
|
if sha(args.source_manifest) != baseline['input_sha256'].get(str(args.source_manifest)):
|
|
raise ValueError('source manifest outside original candidate provenance')
|
|
if sha(args.package) != baseline['input_sha256'].get(str(args.package)):
|
|
raise ValueError('package outside original candidate provenance')
|
|
manifest = json.loads(args.source_manifest.read_text())
|
|
records = {}
|
|
for chunk in manifest['chunks']:
|
|
name = chunk['path']
|
|
if Path(name).name != name:
|
|
raise ValueError('source chunk path escape')
|
|
path = args.source_manifest.parent / name
|
|
raw = path.read_bytes()
|
|
if hashlib.sha256(raw).hexdigest() != chunk['sha256']:
|
|
raise ValueError('source chunk changed')
|
|
for row in json.loads(raw):
|
|
ident = row['entry']
|
|
if ident in records:
|
|
raise ValueError('duplicate source identity')
|
|
records[ident] = row
|
|
inventory = [{'id': row['entry'], 'family': row['spellFamilyName'], 'mask': row['spellFamilyFlags']}
|
|
for row in records.values()]
|
|
if inventory != source:
|
|
raise ValueError('source complete class inventory differs')
|
|
package = json.loads(args.package.read_text())
|
|
native_tables, pins = {}, {}
|
|
for table in private.TABLES:
|
|
path = args.native_directory / (table + '.json')
|
|
native_tables[table] = json.loads(path.read_text())
|
|
pins[str(path)] = sha(path)
|
|
desired = sorted({ident for row in profile['held'] for ident in row['spell_ids']})
|
|
closure = private.definition_closure(records, native_tables, package['rows'], desired)
|
|
allocation = private.allocate(source, target, closure, profile['source_bits'])
|
|
private.validate_allocation(allocation, source, target, closure, profile['source_bits'])
|
|
output.mkdir(parents=True)
|
|
for name, value in [('definition-closure.json', closure), ('allocation-candidate.json', allocation),
|
|
('native-class4-inventory.json', allocation['native_inventory']),
|
|
('mapping-profile.json', allocation['mapping_profile']),
|
|
('record-replacements.json', allocation['record_replacements'])]:
|
|
(output / name).write_text(json.dumps(value, sort_keys=True, separators=(',', ':')) + '\n')
|
|
audit_families = json.loads((args.candidate / 'cooldown-talent-families.json').read_text())
|
|
admitted = {row['source_bit'] for row in allocation['mapping_profile']['admitted']}
|
|
for row in audit_families:
|
|
row['status'] = 'complete-bit-mapping' if set(row['source_bits']) <= admitted else 'held-bit-mapping'
|
|
(output / 'cooldown-talent-families.json').write_text(json.dumps(audit_families, indent=2) + '\n')
|
|
for path in [report_path, args.source_manifest, args.package, Path(flat.__file__), Path(private.__file__), Path(__file__)]:
|
|
pins[str(path)] = sha(path)
|
|
report = {'kind': allocation['policy'], 'baseline_unused_bits': len(allocation['baseline_unused_native_bits']),
|
|
'allocated_bits': len(allocation['allocations']), 'source_bits': profile['source_bits'],
|
|
'admitted_bits_before': len(profile['admitted']),
|
|
'admitted_bits_after': len(allocation['mapping_profile']['admitted']),
|
|
'held_bits_after': len(allocation['mapping_profile']['held']),
|
|
'changed_native_class_rows': len(allocation['record_replacements']),
|
|
'complete_audited_effects': sum(row['status'] == 'complete-bit-mapping' for row in audit_families),
|
|
'new_spell_definitions': 0, 'base_registry_rows': baseline['package_rows'],
|
|
'all_existing_fields_and_bits_preserved': True,
|
|
'input_sha256': pins, 'output_sha256': {p.name: sha(p) for p in output.glob('*.json')},
|
|
'installable_package': False, 'canonical_metadata_changed': False,
|
|
'native_runtime_integrated': False, 'live_acceptance': False,
|
|
'limits': ['No missing parent/spell/effect definitions authored; they remain held until complete composer closure.',
|
|
'Private bits unused in every current effective class4 row; final composition must recompute against merged inventory.',
|
|
'Existing parent/name/default-effect-slot presence is proved, not new gameplay/visual or asset semantics.',
|
|
'Record replacements preserve the complete baseline row and every original mask bit. They are not installable hotfix rows.']}
|
|
(output / 'report.json').write_text(json.dumps(report, indent=2) + '\n')
|
|
return report
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
for name in ['candidate', 'source-manifest', 'package', 'native-directory', 'output']:
|
|
parser.add_argument('--' + name, type=Path, required=True)
|
|
parser.add_argument('--candidate-report-sha256', required=True)
|
|
result = prepare(parser.parse_args())
|
|
print(json.dumps({key: result[key] for key in ['baseline_unused_bits', 'allocated_bits', 'admitted_bits_after', 'changed_native_class_rows', 'complete_audited_effects']}, sort_keys=True))
|