Download exporter.py from pharosproduction/production-ai-control-evidence: direct link, hf CLI and curl.
- Browser
- Download file 16 kB
-
https://huggingface.co/datasets/pharosproduction/production-ai-control-evidence/resolve/main/exporter.py
- Command line
-
hf download hf://datasets/pharosproduction/production-ai-control-evidence/exporter.py
-
curl -L -o exporter.py https://huggingface.co/datasets/pharosproduction/production-ai-control-evidence/resolve/main/exporter.py
16 kB
| """Reproducible private candidate export. Network-free after snapshot creation.""" | |
| from pathlib import Path | |
| import hashlib | |
| import json | |
| import shutil | |
| import subprocess | |
| import sys | |
| ROOT = Path(__file__).resolve().parents[1] | |
| REPOS = ROOT / 'repos' | |
| STAMP = '2026-09-17T06:17:24Z' | |
| SPECS = { | |
| 'security': ('pharos-agent-security-control-mapper', 'agent-security-control-mapper', 'data'), | |
| 'aibom': ('pharos-aibom-tools-compared', 'aibom-tools-compared', 'data'), | |
| 'drift': ('pharos-production-ai-drift-planner', 'production-ai-drift-planner', 'docs/data'), | |
| 'governance': ('pharos-ai-governance-readiness-map', 'ai-governance-readiness-map', 'docs/data'), | |
| 'rag': ('pharos-rag-vs-fine-tuning-matrix', 'rag-vs-fine-tuning-matrix', 'data'), | |
| 'build_buy': ('pharos-build-vs-buy-ai-agent-scorecard', 'build-vs-buy-ai-agent-scorecard', 'data'), | |
| 'framework': ('pharos-enterprise-ai-agent-frameworks', 'enterprise-ai-agent-frameworks', 'data'), | |
| } | |
| ENGINES = {'rag': 'decision-engine.js', 'build_buy': 'decision-scorecard.js', 'framework': 'framework-selector.js'} | |
| def h(data): | |
| return 'sha256:' + hashlib.sha256(data).hexdigest() | |
| def dump(path, obj): | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| path.write_text(json.dumps(obj, ensure_ascii=False, sort_keys=True, indent=2) + '\n') | |
| def freeze_sources(): | |
| path = ROOT / 'source-snapshot.json' | |
| if path.exists(): | |
| return json.loads(path.read_text()) | |
| sources = {} | |
| for config, (local, repo, folder) in SPECS.items(): | |
| base = Path('/Users/rudrafury/Projects') / local | |
| sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=base, text=True).strip() | |
| names = subprocess.check_output(['git', 'ls-tree', '-r', '--name-only', sha, folder], cwd=base, text=True).splitlines() | |
| names = [n for n in names if n.endswith('.json')] + ['LICENSE', 'README.md'] | |
| if config in ENGINES: | |
| names.append('docs/assets/' + ENGINES[config]) | |
| files = {} | |
| for name in sorted(names): | |
| raw = subprocess.check_output(['git', 'show', sha + ':' + name], cwd=base) | |
| files[name] = {'sha256': h(raw), 'content': raw.decode('utf-8'), | |
| 'url': f'https://github.com/PharosProduction/{repo}/blob/{sha}/{name}'} | |
| sources[config] = {'repo': f'https://github.com/PharosProduction/{repo}', 'commit': sha, | |
| 'pages': f'https://pharosproduction.github.io/{repo}/', 'files': files, | |
| 'snapshot_at': STAMP, 'independent_human_review': 'NOT_REVIEWED'} | |
| dump(path, sources) | |
| return sources | |
| def native(sources, config, file): | |
| folder = SPECS[config][2] | |
| return json.loads(sources[config]['files'][folder + '/' + file + '.json']['content']) | |
| def lineage(sources, config, file): | |
| source = sources[config] | |
| entry = source['files'][SPECS[config][2] + '/' + file + '.json'] | |
| return {'source_commit_sha': source['commit'], 'source_url': entry['url'], | |
| 'source_data_hash': entry['sha256'], 'review_status': 'NOT_REVIEWED', 'status': 'DRAFT', | |
| 'verified_at': None, 'snapshot_at': STAMP} | |
| def make_controls(sources, proposals): | |
| result = {key: [] for key in ('security', 'aibom', 'drift', 'governance')} | |
| for r in native(sources, 'security', 'controls')['controls']: | |
| p = proposals['security_layers'][r['layerId']] | |
| result['security'].append({ | |
| 'control_id': r['id'], 'name': r['name'], 'risk': p['risk'], | |
| 'system_boundary': 'Agent runtime, delegated identities and connected tools in the selected environment.', | |
| 'action': r['implementation'], 'verification': r['verification'], | |
| 'evidence_type': r['evidenceArtifacts'], 'owner_role': r['suggestedOwnerRole'], | |
| 'change_trigger': r['name'] + ': review on ' + p['trigger'], 'rollback': p['rollback'], | |
| 'source_native_id': r['id'], 'source_payload_json': json.dumps(r, sort_keys=True), | |
| 'field_origin': 'action/verification/evidence/owner: source; risk/boundary/trigger/rollback: engineering proposal', | |
| **lineage(sources, 'security', 'controls')}) | |
| for p in proposals['aibom_controls']: | |
| result['aibom'].append({**p, 'source_native_id': None, 'source_payload_json': 'null', | |
| 'field_origin': 'Original engineering proposal; the source compares tools and does not contain these controls.', | |
| **lineage(sources, 'aibom', 'tools')}) | |
| for r in native(sources, 'drift', 'metrics'): | |
| result['drift'].append({ | |
| 'control_id': 'DRIFT-' + r['id'].upper(), 'name': r['name'], | |
| 'risk': 'A change affecting ' + r['name'].lower() + ' goes undetected or receives an inappropriate response.', | |
| 'system_boundary': 'Selected production AI system, versioned evaluation cohort and monitoring window.', | |
| 'action': r['response'], 'verification': r['definition'], | |
| 'evidence_type': ['Versioned metric definition and baseline', 'Measured observations with sampling window and denominator', 'Response and recovery exercise record'], | |
| 'owner_role': 'Monitoring owner with the affected component owner', | |
| 'change_trigger': 'Review when the model, prompt, data, tools, traffic mix, metric definition or local error budget changes.', | |
| 'rollback': r['rollback'], 'source_native_id': r['id'], | |
| 'source_payload_json': json.dumps(r, sort_keys=True), | |
| 'field_origin': 'name/action/verification/rollback: source; risk/boundary/evidence/owner/trigger: engineering proposal', | |
| **lineage(sources, 'drift', 'metrics')}) | |
| for r in native(sources, 'governance', 'controls'): | |
| p = proposals['governance'][r['id']] | |
| result['governance'].append({ | |
| 'control_id': 'GOV-' + r['id'].upper(), 'name': r['title'], 'risk': p['risk'], | |
| 'system_boundary': 'The named AI system, intended use, affected people and operating organization.', | |
| 'action': r['purpose'], 'verification': 'Inspect the dated record, scope and named decision owner; exercise the documented procedure where applicable.', | |
| 'evidence_type': [r['evidence']], | |
| 'owner_role': r['suggestedResponsible'] + '; accountable role: ' + r['suggestedAccountable'], | |
| 'change_trigger': p['trigger'], 'rollback': p['rollback'], 'source_native_id': r['id'], | |
| 'source_payload_json': json.dumps(r, sort_keys=True), | |
| 'field_origin': 'name/action/evidence/roles: source; remaining normalized fields: engineering proposal', | |
| **lineage(sources, 'governance', 'controls')}) | |
| for config, rows in result.items(): | |
| for row in rows: | |
| row.update(config=config, decision_job='RELEASE_EVIDENCE', | |
| limitations=['Engineering draft; independent human review is pending.', | |
| 'A listed artifact or suggested role does not establish operating effectiveness or an actual assignment.', | |
| 'New normalized fields require canonical upstream adoption before public release.']) | |
| if config == 'drift': | |
| row['limitations'].append('Source thresholds are illustrative; calibrate locally. This catalog does not evaluate live telemetry.') | |
| return result | |
| def make_decisions(sources, proposals): | |
| registries = {} | |
| for config in ('rag', 'build_buy', 'framework'): | |
| registries[config] = {Path(p).stem: json.loads(v['content']) for p, v in sources[config]['files'].items() if p.endswith('.json')} | |
| registries['architecture'] = proposals['architecture'] | |
| sets = { | |
| 'rag': ('RULE', 'rules', registries['rag']['rules']['rules']), | |
| 'build_buy': ('WEIGHTED_CRITERION', 'criteria', registries['build_buy']['criteria']['criteria']), | |
| 'framework': ('FRAMEWORK_PROFILE', 'frameworks', registries['framework']['frameworks']['frameworks']), | |
| 'architecture': ('PATTERN_RULE_PROPOSAL', None, registries['architecture']['rules']), | |
| } | |
| rows = {} | |
| for config, (kind, file, records) in sets.items(): | |
| rows[config] = [] | |
| for r in records: | |
| origin = lineage(sources, config, file) if file else { | |
| 'source_commit_sha': None, 'source_url': None, | |
| 'source_data_hash': h(json.dumps(proposals['architecture'], sort_keys=True).encode()), | |
| 'review_status': 'NOT_REVIEWED', 'status': 'DRAFT', 'verified_at': None, 'snapshot_at': STAMP} | |
| rows[config].append({'record_id': r['id'], 'config': config, 'record_type': kind, | |
| 'decision_job': 'PATH_SELECTION', 'payload_json': json.dumps(r, ensure_ascii=False, sort_keys=True), | |
| 'limitations': ['Native method retained; numeric preference is not a probability or performance benchmark.', | |
| 'Architecture proposals have no published canonical source; framework facts retain their original cutoff.'], | |
| **origin}) | |
| return rows, registries | |
| def build(): | |
| sources = freeze_sources() | |
| proposals = json.loads((ROOT / 'source-proposals/proposals.json').read_text()) | |
| controls = make_controls(sources, proposals) | |
| decisions, registries = make_decisions(sources, proposals) | |
| for kind, rows in [('control-evidence', controls), ('decision-rules', decisions)]: | |
| repo = REPOS / ('production-ai-' + kind) | |
| for config, records in rows.items(): | |
| (repo / (config + '.jsonl')).write_text(''.join(json.dumps(r, ensure_ascii=False, sort_keys=True) + '\n' for r in records)) | |
| bundle = {'schema_version': '2.0.0-candidate.1', 'release_version': '0.1.0-candidate.1', | |
| 'review_status': 'NOT_REVIEWED', 'publish_eligible': False, | |
| 'mode': 'DRAFT_EXPLORATION', 'generated_at': STAMP, | |
| 'controls': controls} if kind == 'control-evidence' else { | |
| 'schema_version': '2.0.0-candidate.1', 'release_version': '0.1.0-candidate.1', | |
| 'review_status': 'NOT_REVIEWED', 'publish_eligible': False, | |
| 'mode': 'DRAFT_EXPLORATION', 'generated_at': STAMP, 'registries': registries} | |
| dump(repo / 'data.json', bundle) | |
| subset = {c: s for c, s in sources.items() if c in rows} | |
| dump(repo / 'source-snapshot.json', subset) | |
| dump(repo / 'source-proposals.json', proposals if kind == 'control-evidence' else {'architecture': proposals['architecture']}) | |
| manifest = {c: {k: v for k, v in s.items() if k != 'files'} | { | |
| 'files': {p: {k: v for k, v in f.items() if k != 'content'} for p, f in s['files'].items()}} | |
| for c, s in subset.items()} | |
| dump(repo / 'source-manifest.json', {'sources': manifest, 'original_proposals': { | |
| 'path': 'source-proposals.json', 'sha256': h((repo / 'source-proposals.json').read_bytes()), | |
| 'canonical_adoption': 'PENDING', 'human_review': 'NOT_REVIEWED'}}) | |
| dump(repo / 'release.json', {'version': '0.1.0-candidate.1', 'schema_version': '2.0.0-candidate.1', | |
| 'lifecycle': 'FUNCTIONAL_PRIVATE_CANDIDATE', 'publish_eligible': False, | |
| 'independent_human_review': 'NOT_REVIEWED', 'rights_decision': 'PENDING', | |
| 'upstream_proposal_adoption': 'PENDING', 'row_counts': {c: len(rs) for c, rs in rows.items()}, | |
| 'files': {c + '.jsonl': h((repo / (c + '.jsonl')).read_bytes()) for c in rows}, | |
| 'data_sha256': h((repo / 'data.json').read_bytes()), | |
| 'publication_authority': 'User authorized Control Evidence Dataset publication on 2026-09-17; review/rights evidence has not been supplied.'}) | |
| original = ROOT.parents[1] / 'HF-PP-2026-W02/repos' / repo.name / 'schema.json' | |
| shutil.copyfile(original, repo / 'release-schema-v1.json') | |
| # Public v1 is kept unchanged. Candidate rows cannot masquerade as REVIEWED. | |
| example = next(iter(rows.values()))[0] | |
| properties = {k: {'type': 'string', 'minLength': 1} for k in example} | |
| for key in ['limitations', 'evidence_type']: | |
| if key in properties: properties[key] = {'type': 'array', 'minItems': 1, 'items': {'type': 'string', 'minLength': 1}} | |
| properties.update(review_status={'const': 'NOT_REVIEWED'}, status={'const': 'DRAFT'}, | |
| verified_at={'type': 'null'}, source_data_hash={'type': 'string', 'pattern': '^sha256:[a-f0-9]{64}$'}, | |
| source_commit_sha={'type': ['string', 'null'], 'pattern': '^[a-f0-9]{40}$'}, | |
| source_url={'type': ['string', 'null'], 'pattern': '^https://'}, | |
| config={'enum': list(rows)}, decision_job={'const': 'RELEASE_EVIDENCE' if kind == 'control-evidence' else 'PATH_SELECTION'}) | |
| if 'source_native_id' in properties: properties['source_native_id'] = {'type': ['string', 'null']} | |
| common = {'type': 'object', 'additionalProperties': False, 'required': list(example), 'properties': properties} | |
| dump(repo / 'schema.json', {'$schema': 'https://json-schema.org/draft/2020-12/schema', 'title': kind + ' candidate 2.0.0-candidate.1', **common}) | |
| shutil.copyfile(Path(__file__), repo / 'exporter.py') | |
| for config, module in ENGINES.items(): | |
| raw = sources[config]['files']['docs/assets/' + module]['content'] | |
| (REPOS / 'production-ai-decision-lab' / module.replace('.js', '.mjs')).write_text(raw) | |
| for dataset, space in [('control-evidence', 'evidence-pack'), ('decision-rules', 'decision-lab')]: | |
| src, dst = REPOS / ('production-ai-' + dataset), REPOS / ('production-ai-' + space) | |
| shutil.copyfile(src / 'data.json', dst / 'data.json') | |
| lock_path = dst / 'dataset-lock.json' | |
| old = json.loads(lock_path.read_text()) if lock_path.exists() else {} | |
| digest = h((src / 'data.json').read_bytes()) | |
| dump(lock_path, { | |
| 'dataset_repo': 'pharosproduction/production-ai-' + dataset, | |
| 'revision': old.get('revision') if old.get('files', {}).get('data.json') == digest else None, | |
| 'lifecycle': 'FUNCTIONAL_PRIVATE_CANDIDATE', 'publish_eligible': False, | |
| 'mode': 'DRAFT_EXPLORATION', 'files': {'data.json': digest}}) | |
| dump(ROOT / 'audit/build-result.json', {'controls': {c: len(r) for c, r in controls.items()}, | |
| 'decisions': {c: len(r) for c, r in decisions.items()}, 'native_engines': 'BYTE_IDENTICAL', | |
| 'published_rows': 0, 'human_review': 'NOT_REVIEWED'}) | |
| print((ROOT / 'audit/build-result.json').read_text()) | |
| def reproduce_dataset(directory): | |
| directory = Path(directory) | |
| sources = json.loads((directory / 'source-snapshot.json').read_text()) | |
| proposals = json.loads((directory / 'source-proposals.json').read_text()) | |
| if 'security' in sources: | |
| rows = make_controls(sources, proposals) | |
| bundle = {'controls': rows} | |
| else: | |
| rows, registries = make_decisions(sources, proposals) | |
| bundle = {'registries': registries} | |
| bundle.update(schema_version='2.0.0-candidate.1', release_version='0.1.0-candidate.1', review_status='NOT_REVIEWED', | |
| publish_eligible=False, mode='DRAFT_EXPLORATION', generated_at=STAMP) | |
| expected = json.dumps(bundle, ensure_ascii=False, sort_keys=True, indent=2) + '\n' | |
| assert expected.encode() == (directory / 'data.json').read_bytes(), 'data.json differs from deterministic source export' | |
| for config, records in rows.items(): | |
| expected = ''.join(json.dumps(r, ensure_ascii=False, sort_keys=True) + '\n' for r in records) | |
| assert expected.encode() == (directory / (config + '.jsonl')).read_bytes(), config + ' rows differ' | |
| for source in sources.values(): | |
| for entry in source['files'].values(): assert h(entry['content'].encode()) == entry['sha256'] | |
| print('PASS: snapshot hashes and deterministic dataset export match.') | |
| if __name__ == '__main__': | |
| if len(sys.argv) == 3 and sys.argv[1] == '--verify-dataset': | |
| reproduce_dataset(sys.argv[2]) | |
| else: | |
| build() | |