Spaces:
Running
chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)
Browse filesAutomated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): (none)
Deleted (gone from the repo + Dockerfile COPY set): docs/anatomy-linkedin/make_docx.py, kipu_qillqaq/__init__.py, kipu_qillqaq/cell.py, kipu_qillqaq/coding.py, kipu_qillqaq/events.py, kipu_qillqaq/genome.py, kipu_qillqaq/handlers.py, kipu_qillqaq/pool.py, kipu_qillqaq/transcribe.py, packages/inference/__init__.py, packages/inference/src/__init__.py, packages/inference/src/voters/__init__.py, packages/inference/src/voters/base_voter.py, packages/inference/src/voters/deepseek_r1.py, packages/inference/src/voters/glm_4_6.py, packages/inference/src/voters/hermes_4_405b.py, packages/inference/src/voters/hf_inference_voter.py, packages/inference/src/voters/kimi_k2.py, packages/inference/src/voters/minimax_m2.py, packages/inference/src/voters/nemotron_super_49b.py, packages/inference/src/voters/nomos_1.py, packages/inference/src/voters/qwen_local.py, packages/inference/src/voters/step_3_7_flash.py, packages/inference/src/voters/xiaomi_mimo.py, resilience/status_feed.py, resilience/szl_breaker.py, resilience/szl_exporter.py, scripts/audit_github_access_permissions.py, scripts/audit_huggingface_ecosystem.py, scripts/build_ecosystem_readiness.py, scripts/build_ecosystem_stage_matrix.py, scripts/build_operational_payload.py, scripts/ecosystem_audit.py, scripts/payload_manifest.py, scripts/prepare_huggingface_payload.py, scripts/publish_huggingface_payload.py, scripts/validate_action_contract_manifest.py, scripts/validate_anatomy_formula_runtime_map.py, scripts/validate_benchmark_map.py, scripts/validate_controls_evidence_map.py, scripts/validate_cross_repo_handoff_manifest.py, scripts/validate_github_access_checklist.py, scripts/validate_hf_test_results_manifest.py, scripts/validate_phase_completion_manifest.py, scripts/validate_public_pattern_manifest.py, scripts/validate_theorem_runtime_manifest.py, tests/__init__.py, tests/test_be_hardening.py, tests/test_conduction_aphasia.py, tests/test_dsse_real_signing.py, tests/test_formulas/__init__.py, tests/test_formulas/test_bloom_filter.py, tests/test_formulas/test_bls_aggregate.py, tests/test_formulas/test_byzantine_quorum.py, tests/test_formulas/test_hnsw_retrieval.py, tests/test_formulas/test_holevo_bound.py, tests/test_formulas/test_kalman.py, tests/test_formulas/test_pac_bayes.py, tests/test_formulas/test_reidemeister.py, tests/test_formulas/test_welford.py, tests/test_hickok_ingest.py, tests/test_parity_gaps.py, tests/test_v4_agent_voters.py, tests/test_zero_cdn_guard.py, tools/freeze_manifest.py, vsp_otel/__init__.py, vsp_otel/middleware.py
Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend, new endpoints don't 404 there, and orphaned modules
removed from the repo don't linger in the Space tree.
- docs/anatomy-linkedin/make_docx.py +0 -238
- kipu_qillqaq/__init__.py +0 -40
- kipu_qillqaq/cell.py +0 -83
- kipu_qillqaq/coding.py +0 -185
- kipu_qillqaq/events.py +0 -45
- kipu_qillqaq/genome.py +0 -110
- kipu_qillqaq/handlers.py +0 -31
- kipu_qillqaq/pool.py +0 -137
- kipu_qillqaq/transcribe.py +0 -123
- packages/inference/__init__.py +0 -0
- packages/inference/src/__init__.py +0 -0
- packages/inference/src/voters/__init__.py +0 -117
- packages/inference/src/voters/base_voter.py +0 -187
- packages/inference/src/voters/deepseek_r1.py +0 -80
- packages/inference/src/voters/glm_4_6.py +0 -76
- packages/inference/src/voters/hermes_4_405b.py +0 -79
- packages/inference/src/voters/hf_inference_voter.py +0 -82
- packages/inference/src/voters/kimi_k2.py +0 -77
- packages/inference/src/voters/minimax_m2.py +0 -76
- packages/inference/src/voters/nemotron_super_49b.py +0 -64
- packages/inference/src/voters/nomos_1.py +0 -75
- packages/inference/src/voters/qwen_local.py +0 -73
- packages/inference/src/voters/step_3_7_flash.py +0 -76
- packages/inference/src/voters/xiaomi_mimo.py +0 -76
- resilience/status_feed.py +0 -88
- resilience/szl_breaker.py +0 -129
- resilience/szl_exporter.py +0 -93
- scripts/audit_github_access_permissions.py +0 -210
- scripts/audit_huggingface_ecosystem.py +0 -158
- scripts/build_ecosystem_readiness.py +0 -304
- scripts/build_ecosystem_stage_matrix.py +0 -179
- scripts/build_operational_payload.py +0 -227
- scripts/ecosystem_audit.py +0 -80
- scripts/payload_manifest.py +0 -89
- scripts/prepare_huggingface_payload.py +0 -155
- scripts/publish_huggingface_payload.py +0 -74
- scripts/validate_action_contract_manifest.py +0 -114
- scripts/validate_anatomy_formula_runtime_map.py +0 -145
- scripts/validate_benchmark_map.py +0 -92
- scripts/validate_controls_evidence_map.py +0 -124
- scripts/validate_cross_repo_handoff_manifest.py +0 -140
- scripts/validate_github_access_checklist.py +0 -88
- scripts/validate_hf_test_results_manifest.py +0 -91
- scripts/validate_phase_completion_manifest.py +0 -84
- scripts/validate_public_pattern_manifest.py +0 -141
- scripts/validate_theorem_runtime_manifest.py +0 -86
- tests/__init__.py +0 -0
- tests/test_be_hardening.py +0 -163
- tests/test_conduction_aphasia.py +0 -319
- tests/test_dsse_real_signing.py +0 -160
|
@@ -1,238 +0,0 @@
|
|
| 1 |
-
from docx import Document
|
| 2 |
-
from docx.shared import Pt, RGBColor
|
| 3 |
-
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
| 4 |
-
|
| 5 |
-
# ---------- CONTENT BLOCKS (each one is copy-paste-ready, character-counted) ----------
|
| 6 |
-
|
| 7 |
-
HOOK_140 = (
|
| 8 |
-
"We shipped an AI-governance page that recomputes a SHA-256 over the "
|
| 9 |
-
"published thesis bundle on every load. Drifts → red banner."
|
| 10 |
-
) # target ≤ 140 (desktop preview)
|
| 11 |
-
|
| 12 |
-
HOOK_210 = (
|
| 13 |
-
"Most \"AI governance\" pages are decoration. Ours recomputes a SHA-256 "
|
| 14 |
-
"over the entire upstream-published anatomy bundle on every page load. "
|
| 15 |
-
"One byte drifts, the banner flips red. No trust-us path."
|
| 16 |
-
) # target ≤ 210 (mobile fold)
|
| 17 |
-
|
| 18 |
-
POST_FULL = """Most "AI governance" pages in production are decoration: a Notion link, a PDF on a shared drive, a screenshot of a SOC 2 badge. We just shipped the opposite.
|
| 19 |
-
|
| 20 |
-
A11oy → /anatomy is a read-only viewer that vendors the entire upstream Ouroboros thesis anatomy bundle (CC-BY-4.0, github.com/szl-holdings/ouroboros-thesis) and proves byte-level parity with the published thesis on every page load. If one byte drifts, the banner flips from green to red and the page refuses to claim parity. There is no "trust us" code path.
|
| 21 |
-
|
| 22 |
-
WHAT'S IN THE BUNDLE
|
| 23 |
-
|
| 24 |
-
• 8 canonical figures (brain, wires, full-body, heart, blood/immune, skeleton, nervous, body-graph) as both vector PDF and 300dpi PNG — the operational schematic of a governed agent: AMARU cortex with a 9-axis conjunctive doctrine gate, YUYAY v3 13-axis AND gate (no averaging, sacred axes ≥ 0.95), YAWAR append-only ledger, HUKLLA T01–T10 tripwires, OTel/VSP nervous system, CHAKANA 21-edge M=0 lattice.
|
| 25 |
-
|
| 26 |
-
• 7-chakra activation spine (root → crown) with per-chakra leader.md + result.md prose pulled verbatim from upstream — the actual kernel notes (tinygrad → KALLPA dispatch, DSPy → YACHAY retrieval, vLLM → RIMAY sampling), not marketing copy.
|
| 27 |
-
|
| 28 |
-
• Real DOIs on every section: concept DOI 10.5281/zenodo.19944926 (always resolves to latest), v13 release 10.5281/zenodo.20195368.
|
| 29 |
-
|
| 30 |
-
THE INTEGRITY MECHANISM (the part CTOs care about)
|
| 31 |
-
|
| 32 |
-
In the browser, on every load:
|
| 33 |
-
|
| 34 |
-
1. Fetch VENDOR.json::expected_files (canonical 14-file manifest).
|
| 35 |
-
2. For each filename in sorted order, fetch the bytes and concat sha256( filename || NUL || bytes || NUL ).
|
| 36 |
-
3. Compare the digest to VENDOR.json::upstream_sha. Match → green. Mismatch → red DRIFT banner with both hashes side-by-side. No SubtleCrypto → sentinel that never matches a real sha256. Fails closed, never silently green.
|
| 37 |
-
|
| 38 |
-
Same construction as Sigstore cosign verify or Subresource Integrity, applied to a documentation bundle.
|
| 39 |
-
|
| 40 |
-
WHY THIS MATTERS OPERATIONALLY
|
| 41 |
-
|
| 42 |
-
• Auditors re-run the hash and get bit-for-bit reproducibility against the publication.
|
| 43 |
-
• CI can fail the build the moment someone "fixes a typo" in a vendored binary.
|
| 44 |
-
• Citations are stable — every chakra section deep-links to a resolvable Zenodo DOI, not a Notion page that 404s in six months.
|
| 45 |
-
• If you're claiming "auditable AI," these eight figures are the load-bearing primitives. Run a hash against your own published claims and see what happens.
|
| 46 |
-
|
| 47 |
-
STACK
|
| 48 |
-
|
| 49 |
-
React + Vite + TypeScript. PDF via <object> with PNG fallback (CSP-aware). crypto.subtle.digest("SHA-256", …). No third-party hash libs — the proof is ~30 lines and inspectable in DevTools.
|
| 50 |
-
|
| 51 |
-
Upstream thesis: github.com/szl-holdings/ouroboros-thesis"""
|
| 52 |
-
|
| 53 |
-
POST_SHORT = """Most "AI governance" pages are decoration. Ours isn't.
|
| 54 |
-
|
| 55 |
-
A11oy → /anatomy vendors the entire upstream Ouroboros thesis anatomy bundle (CC-BY-4.0) and recomputes a SHA-256 over the published binaries in the browser on every page load. One byte drifts, the banner flips red. No "trust us" path.
|
| 56 |
-
|
| 57 |
-
In the bundle:
|
| 58 |
-
• 8 canonical figures (brain, wires, full-body, heart, blood/immune, skeleton, nervous, body-graph) — the operational schematic of a governed agent: AMARU cortex (9-axis doctrine gate), YUYAY v3 (13-axis AND gate, no averaging), YAWAR append-only ledger, HUKLLA tripwires, OTel/VSP nervous system.
|
| 59 |
-
• 7-chakra activation spine with per-kernel prose pulled verbatim from upstream.
|
| 60 |
-
• Real DOIs (concept 10.5281/zenodo.19944926, v13 10.5281/zenodo.20195368).
|
| 61 |
-
|
| 62 |
-
The integrity proof is ~30 lines of crypto.subtle and inspectable in DevTools. Same construction as Sigstore cosign verify, applied to a documentation bundle. Auditors re-run the hash; CI fails the build the moment a vendored byte changes.
|
| 63 |
-
|
| 64 |
-
If your governance claim can't survive a hash check, it's a brochure.
|
| 65 |
-
|
| 66 |
-
Upstream: github.com/szl-holdings/ouroboros-thesis"""
|
| 67 |
-
|
| 68 |
-
HASHTAGS = "#AIGovernance #AuditableAI #DecisionIntelligence #ReproducibleResearch #PlatformEngineering #SoftwareReceipts #SRE #OuroborosThesis #SZLHoldings"
|
| 69 |
-
|
| 70 |
-
WARHACKER_BODY = """TO: Defense Unicorns — Warhacker (defenseunicorns.com/warhacker)
|
| 71 |
-
RE: Fixing the drones — accountable autonomy on small UAS
|
| 72 |
-
FROM: SZL Holdings · CC-BY-4.0 · DOI 10.5281/zenodo.19944926
|
| 73 |
-
|
| 74 |
-
PITCH
|
| 75 |
-
|
| 76 |
-
Small-UAS autonomy isn't an airframe problem — it's an accountable-software problem. Closed binaries, no provenance, models that can't be re-run bit-for-bit after an engagement, "AI" decisions with no receipt. We built the substrate that fixes that — CC-BY-4.0, permanent DOI, drops into UDS / Big Bang, running live now. A JAG-defensible flight-data recorder for every kernel decision a drone makes.
|
| 77 |
-
|
| 78 |
-
WHAT WE JUST SHIPPED
|
| 79 |
-
|
| 80 |
-
/anatomy now embeds a live ops panel polling our amaru sidecar over a read-only proxy: chakras registered, receipts counter, scheduler ticks, bus publishes/failures, HUKLLA T01–T10 with pass/warn/trip dots, R0513 invariants + live kernel/brain hashes, chakana 21-edge lattice with the ouroboros edge in gold. Nothing is mocked — counters increment, tripwires flip, the cycle is visibly the only cycle. Same proxy + allowlist exposes drone-side state to a UDS dashboard with zero new auth. We also pulled the decorative AI hero images. Page shows only what we can prove.
|
| 81 |
-
|
| 82 |
-
HOW IT FIXES THE DRONES
|
| 83 |
-
|
| 84 |
-
1. Supply-chain integrity. SHA-256 recomputed over every vendored binary on load; one drifted byte and the banner flips red. Sigstore-class proof on the doctrine bundle. Ports as-is into Big Bang / UDS.
|
| 85 |
-
|
| 86 |
-
2. Doctrine gate (YUYAY v3). 13-axis conjunctive AND — sacred axes (moralGrounding, measurabilityHonesty, ontologicalGrounding) ≥0.95, rest ≥0.90. No averaging. Technical implementation of DoD 3000.09 human-judgment.
|
| 87 |
-
|
| 88 |
-
3. YAWAR receipts. Every evaluation appends a hash-chained receipt (seq, prev_hash, self_hash, params, result). Flight-data recorder for autonomy — replay the exact (input, model, doctrine) after any engagement.
|
| 89 |
-
|
| 90 |
-
4. HUKLLA tripwires. T01–T10 cover registration, chain integrity, scheduler progress, wiring acyclicity, bus health, doctrine load, envelope size, proof freshness. Trip → halt. Stops the fleet on a quiet model swap or stale pin.
|
| 91 |
-
|
| 92 |
-
5. R0513 OVERWATCH. Six invariants over the live receipt chain (KL drift, joint margin, mid-exec regate, M=0 rigidity, hash integrity, reserved). Read-only — halt stays with HUKLLA, so OVERWATCH is never an SPoF.
|
| 93 |
-
|
| 94 |
-
6. Byte-identical replay. Each kernel is ≤10 lines and ships a 5× byte-identical replay SHA-256. After-action review is `python3 test_replay.py` and a hash compare.
|
| 95 |
-
|
| 96 |
-
7. Minimization. Kernels are tiny (3.45% absorbed source, 50× reduction). Reviewable code, small SBOM, real audit pre-flight.
|
| 97 |
-
|
| 98 |
-
WHAT TO DO WITH IT
|
| 99 |
-
|
| 100 |
-
Vendor the bundle into your UDS / Big Bang package (hash self-check ports as-is). Put YUYAY v3 in front of any model emitting an action recommendation. Pipe autonomy decisions through YAWAR. Wire HUKLLA as CI gates AND runtime kill-switches — same definition both places. Adopt byte-identical replay for every kernel in an effects loop. If it can't replay, it can't fly.
|
| 101 |
-
|
| 102 |
-
Nothing here is a slide."""
|
| 103 |
-
|
| 104 |
-
FIRST_COMMENT = """Direct links if anyone wants to dig in:
|
| 105 |
-
|
| 106 |
-
• Upstream thesis (source of truth): github.com/szl-holdings/ouroboros-thesis
|
| 107 |
-
• Concept DOI (always latest): doi.org/10.5281/zenodo.19944926
|
| 108 |
-
• v13 release DOI: doi.org/10.5281/zenodo.20195368
|
| 109 |
-
• Anatomy bundle index (per-figure metadata + sha256 list): docs/anatomy/INDEX.md and docs/anatomy/figures.sha256 in the repo above
|
| 110 |
-
|
| 111 |
-
Happy to walk through the in-browser integrity check construction if anyone wants the 30-line walkthrough."""
|
| 112 |
-
|
| 113 |
-
# ---------- DOC ----------
|
| 114 |
-
|
| 115 |
-
doc = Document()
|
| 116 |
-
style = doc.styles['Normal']
|
| 117 |
-
style.font.name = 'Calibri'
|
| 118 |
-
style.font.size = Pt(11)
|
| 119 |
-
|
| 120 |
-
def heading(text, level=1):
|
| 121 |
-
h = doc.add_heading(text, level=level)
|
| 122 |
-
for r in h.runs:
|
| 123 |
-
r.font.color.rgb = RGBColor(0x1A, 0x1A, 0x1A)
|
| 124 |
-
|
| 125 |
-
def para(text, bold=False, italic=False, mono=False, size=11):
|
| 126 |
-
p = doc.add_paragraph()
|
| 127 |
-
r = p.add_run(text)
|
| 128 |
-
r.bold = bold
|
| 129 |
-
r.italic = italic
|
| 130 |
-
r.font.size = Pt(size)
|
| 131 |
-
if mono:
|
| 132 |
-
r.font.name = 'Consolas'
|
| 133 |
-
return p
|
| 134 |
-
|
| 135 |
-
def block(text, label, limit_label):
|
| 136 |
-
n = len(text)
|
| 137 |
-
heading(f"{label} — {n} chars {limit_label}", level=2)
|
| 138 |
-
p = doc.add_paragraph()
|
| 139 |
-
r = p.add_run(text)
|
| 140 |
-
r.font.name = 'Consolas'
|
| 141 |
-
r.font.size = Pt(10)
|
| 142 |
-
doc.add_paragraph() # spacer
|
| 143 |
-
|
| 144 |
-
title = doc.add_heading('LinkedIn post — A11oy /anatomy (CTO-facing, copy-paste pack)', level=0)
|
| 145 |
-
for r in title.runs:
|
| 146 |
-
r.font.color.rgb = RGBColor(0x1A, 0x1A, 0x1A)
|
| 147 |
-
|
| 148 |
-
para(
|
| 149 |
-
'Each block below is plain text, ready to copy directly into LinkedIn. '
|
| 150 |
-
'LinkedIn rules of thumb: ~140 chars visible in the desktop feed preview, '
|
| 151 |
-
'~210 chars on mobile before the "see more" cut, 3,000 chars hard limit '
|
| 152 |
-
'on a post, and the first comment is the place to drop links so the '
|
| 153 |
-
'post body stays clean. Character counts are shown in each section heading.',
|
| 154 |
-
italic=True,
|
| 155 |
-
)
|
| 156 |
-
|
| 157 |
-
heading('1. Above-the-fold hook (desktop preview, ≤140 chars)', 1)
|
| 158 |
-
para(
|
| 159 |
-
'Use this as the opening line of the post so what appears before "see more" '
|
| 160 |
-
'in the desktop feed is the kill-shot. Then paste the FULL POST body below it.',
|
| 161 |
-
italic=True,
|
| 162 |
-
)
|
| 163 |
-
block(HOOK_140, 'HOOK — desktop preview', '(target ≤ 140)')
|
| 164 |
-
|
| 165 |
-
heading('2. Above-the-fold hook (mobile, ≤210 chars)', 1)
|
| 166 |
-
para(
|
| 167 |
-
'Slightly longer alternative if you care more about the mobile feed than '
|
| 168 |
-
'the desktop feed.',
|
| 169 |
-
italic=True,
|
| 170 |
-
)
|
| 171 |
-
block(HOOK_210, 'HOOK — mobile fold', '(target ≤ 210)')
|
| 172 |
-
|
| 173 |
-
heading('3. FULL POST BODY (≤3,000 chars — LinkedIn hard limit)', 1)
|
| 174 |
-
para(
|
| 175 |
-
'This is the main, technical, CTO-facing post. Plain text, no markdown — '
|
| 176 |
-
'LinkedIn does not render Markdown. Bullet glyphs (•) and arrows (→) '
|
| 177 |
-
'render fine. Triple-click the block below to select, then copy.',
|
| 178 |
-
italic=True,
|
| 179 |
-
)
|
| 180 |
-
block(POST_FULL, 'FULL POST', '(LinkedIn limit 3,000)')
|
| 181 |
-
|
| 182 |
-
heading('4. SHORT POST (≤1,300 chars — higher reach variant)', 1)
|
| 183 |
-
para(
|
| 184 |
-
'Use this if you want maximum dwell time / completion rate rather than '
|
| 185 |
-
'depth. LinkedIn\'s algorithm tends to reward posts read all the way through, '
|
| 186 |
-
'and shorter posts complete more often.',
|
| 187 |
-
italic=True,
|
| 188 |
-
)
|
| 189 |
-
block(POST_SHORT, 'SHORT POST', '(target ≤ 1,300)')
|
| 190 |
-
|
| 191 |
-
doc.add_page_break()
|
| 192 |
-
heading('5. WARHACKER appendix — how this fixes the drones', 1)
|
| 193 |
-
para(
|
| 194 |
-
'Long-form, CTO/PM-facing explanation of how the anatomy bundle maps onto '
|
| 195 |
-
'Defense Unicorns\' Warhacker push for accountable software on small UAS. '
|
| 196 |
-
'Plain text, copy-paste-ready into a LinkedIn article, a UDS / Big Bang '
|
| 197 |
-
'design doc, or an email to a program manager. References real Warhacker '
|
| 198 |
-
'context (defenseunicorns.com/warhacker) and concrete bundle primitives.',
|
| 199 |
-
italic=True,
|
| 200 |
-
)
|
| 201 |
-
block(WARHACKER_BODY, 'WARHACKER APPENDIX', '(article-length, no LinkedIn 3,000 limit)')
|
| 202 |
-
doc.add_page_break()
|
| 203 |
-
|
| 204 |
-
heading('6. Hashtag block (paste at end of post or as first comment)', 1)
|
| 205 |
-
block(HASHTAGS, 'HASHTAGS', '')
|
| 206 |
-
|
| 207 |
-
heading('7. First comment (link drop — keeps body clean)', 1)
|
| 208 |
-
para(
|
| 209 |
-
'LinkedIn deprioritizes posts with external links in the body. Standard '
|
| 210 |
-
'practice: omit the GitHub/Zenodo URLs from the body and drop them as the '
|
| 211 |
-
'first comment within ~60 seconds of posting.',
|
| 212 |
-
italic=True,
|
| 213 |
-
)
|
| 214 |
-
block(FIRST_COMMENT, 'FIRST COMMENT', '')
|
| 215 |
-
|
| 216 |
-
doc.add_page_break()
|
| 217 |
-
|
| 218 |
-
heading('Suggested image stack (carousel order)', 1)
|
| 219 |
-
para('1. screenshots/a11oy_anatomy_top.jpg — green "Bundle integrity verified" banner. This is the kill-shot.')
|
| 220 |
-
para('2. agent-anatomy/anatomy_brain.png — AMARU cortex / 9-axis doctrine gate.')
|
| 221 |
-
para('3. agent-anatomy/anatomy_heart.png — YUYAY v3 13-axis conjunctive AND gate.')
|
| 222 |
-
para('4. agent-anatomy/anatomy_skeleton.png — 12-repo service topology.')
|
| 223 |
-
para('5. agent-anatomy/anatomy_nervous.png — OTel/VSP span propagation.')
|
| 224 |
-
para('6. agent-anatomy/anatomy_body_graph.png — master overlay (the "this is the system" hero).')
|
| 225 |
-
|
| 226 |
-
heading('Posting tips', 1)
|
| 227 |
-
para('• Post Tue/Wed/Thu between 8–10am in your audience\'s timezone for engineering audiences.')
|
| 228 |
-
para('• First 60 seconds matter: drop the first comment with links, like your own post once, share to a relevant company page.')
|
| 229 |
-
para('• Reply to every comment in the first 2 hours — LinkedIn\'s algorithm treats comments as a stronger signal than likes.')
|
| 230 |
-
para('• If you cross-post: HN title can be sharper — "We made our AI-governance page verify itself with SHA-256 on every load." Lobste.rs: tag as `practices` and `crypto`.')
|
| 231 |
-
para('• Do NOT edit the post within the first hour; edits suppress reach.')
|
| 232 |
-
|
| 233 |
-
# Print char counts so they show up in the run log too
|
| 234 |
-
for lbl, txt in [('HOOK_140', HOOK_140), ('HOOK_210', HOOK_210), ('POST_FULL', POST_FULL), ('POST_SHORT', POST_SHORT), ('FIRST_COMMENT', FIRST_COMMENT), ('HASHTAGS', HASHTAGS)]:
|
| 235 |
-
print(f"{lbl}: {len(txt)} chars")
|
| 236 |
-
|
| 237 |
-
doc.save('exports/a11oy_anatomy_linkedin_post.docx')
|
| 238 |
-
print('wrote exports/a11oy_anatomy_linkedin_post.docx')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
"""kipu_qillqaq — KIPU receipt-cell substrate + QILLQAQ genome (config + module loading) engine.
|
| 2 |
-
|
| 3 |
-
HONEST NAMING (no mysticism):
|
| 4 |
-
* KIPU is a content-addressed receipt-cell pool with LMDB (or JSON-file fallback)
|
| 5 |
-
persistence, an in-process pub/sub event bus, and Reed-Solomon erasure coding for
|
| 6 |
-
durability. It is NOT "holographic QEC". Reed-Solomon is the well-understood MDS
|
| 7 |
-
erasure code used by RAID-6, CD/DVD, QR codes, and Backblaze. See coding.py.
|
| 8 |
-
* QILLQAQ is a declarative engine: it reads organ `genome.toml` files (parsed with the
|
| 9 |
-
stdlib `tomllib`), validates them against a schema, and boots `OrganAgent` instances.
|
| 10 |
-
"DNA" here is shorthand for *config*; "boot from DNA" means *parse config + load a
|
| 11 |
-
module/handler*. There is no biology and no magic.
|
| 12 |
-
|
| 13 |
-
Author: Yachay (SZL Holdings). License: Apache-2.0.
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
__version__ = "0.1.0"
|
| 17 |
-
|
| 18 |
-
from .cell import ReceiptCell, content_address
|
| 19 |
-
from .coding import ReedSolomonCoder, decode_shards, encode_cell
|
| 20 |
-
from .events import EventBus
|
| 21 |
-
from .genome import Genome, GenomeError, load_genome, validate_genome
|
| 22 |
-
from .pool import KipuPool
|
| 23 |
-
from .transcribe import OrganAgent, QillqaqEngine
|
| 24 |
-
|
| 25 |
-
__all__ = [
|
| 26 |
-
"__version__",
|
| 27 |
-
"ReceiptCell",
|
| 28 |
-
"content_address",
|
| 29 |
-
"KipuPool",
|
| 30 |
-
"EventBus",
|
| 31 |
-
"ReedSolomonCoder",
|
| 32 |
-
"encode_cell",
|
| 33 |
-
"decode_shards",
|
| 34 |
-
"Genome",
|
| 35 |
-
"GenomeError",
|
| 36 |
-
"load_genome",
|
| 37 |
-
"validate_genome",
|
| 38 |
-
"OrganAgent",
|
| 39 |
-
"QillqaqEngine",
|
| 40 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,83 +0,0 @@
|
|
| 1 |
-
"""ReceiptCell — a content-addressed receipt (a "knot" in the KIPU).
|
| 2 |
-
|
| 3 |
-
A ReceiptCell is an immutable record of one act: who wrote it, what organ, what kind of
|
| 4 |
-
receipt, the payload, the timestamp, and an optional pointer to parent cells (forming a
|
| 5 |
-
content-addressed DAG like git/IPLD). The content address is the SHA-256 of the canonical
|
| 6 |
-
JSON of the cell's *content* fields (everything except the address itself).
|
| 7 |
-
"""
|
| 8 |
-
|
| 9 |
-
from __future__ import annotations
|
| 10 |
-
|
| 11 |
-
import hashlib
|
| 12 |
-
import json
|
| 13 |
-
import time
|
| 14 |
-
from dataclasses import asdict, dataclass, field
|
| 15 |
-
from typing import Any
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def _canonical(obj: Any) -> bytes:
|
| 19 |
-
"""Deterministic JSON encoding for hashing (sorted keys, no whitespace drift)."""
|
| 20 |
-
return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def content_address(content: dict) -> str:
|
| 24 |
-
"""SHA-256 hex content address of a cell's content dict. Pure function."""
|
| 25 |
-
return hashlib.sha256(_canonical(content)).hexdigest()
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
@dataclass(frozen=True)
|
| 29 |
-
class ReceiptCell:
|
| 30 |
-
"""An immutable, content-addressed receipt cell.
|
| 31 |
-
|
| 32 |
-
`cid` is derived from the content fields and is the cell's identity in the pool.
|
| 33 |
-
"""
|
| 34 |
-
|
| 35 |
-
organ: str
|
| 36 |
-
kind: str
|
| 37 |
-
payload: dict
|
| 38 |
-
author: str = "Yachay"
|
| 39 |
-
ts: float = field(default_factory=lambda: time.time())
|
| 40 |
-
parents: tuple = () # tuple of parent CIDs -> DAG edges
|
| 41 |
-
cid: str = "" # filled in __post_init__
|
| 42 |
-
|
| 43 |
-
def __post_init__(self):
|
| 44 |
-
if not self.cid:
|
| 45 |
-
object.__setattr__(self, "cid", content_address(self._content()))
|
| 46 |
-
|
| 47 |
-
def _content(self) -> dict:
|
| 48 |
-
return {
|
| 49 |
-
"organ": self.organ,
|
| 50 |
-
"kind": self.kind,
|
| 51 |
-
"payload": self.payload,
|
| 52 |
-
"author": self.author,
|
| 53 |
-
"ts": self.ts,
|
| 54 |
-
"parents": list(self.parents),
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
def verify(self) -> bool:
|
| 58 |
-
"""Chain-verify: recompute the content address and compare. True iff intact."""
|
| 59 |
-
return self.cid == content_address(self._content())
|
| 60 |
-
|
| 61 |
-
def to_dict(self) -> dict:
|
| 62 |
-
d = asdict(self)
|
| 63 |
-
d["parents"] = list(self.parents)
|
| 64 |
-
return d
|
| 65 |
-
|
| 66 |
-
@classmethod
|
| 67 |
-
def from_dict(cls, d: dict) -> "ReceiptCell":
|
| 68 |
-
return cls(
|
| 69 |
-
organ=d["organ"],
|
| 70 |
-
kind=d["kind"],
|
| 71 |
-
payload=d["payload"],
|
| 72 |
-
author=d.get("author", "Yachay"),
|
| 73 |
-
ts=d["ts"],
|
| 74 |
-
parents=tuple(d.get("parents", ())),
|
| 75 |
-
cid=d.get("cid", ""),
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
def to_bytes(self) -> bytes:
|
| 79 |
-
return _canonical(self.to_dict())
|
| 80 |
-
|
| 81 |
-
@classmethod
|
| 82 |
-
def from_bytes(cls, b: bytes) -> "ReceiptCell":
|
| 83 |
-
return cls.from_dict(json.loads(b.decode("utf-8")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,185 +0,0 @@
|
|
| 1 |
-
"""Reed-Solomon erasure coding for KIPU receipt-cell durability.
|
| 2 |
-
|
| 3 |
-
HONEST NAMING: this is Reed-Solomon (Reed & Solomon, 1960) — the same MDS erasure code
|
| 4 |
-
used by RAID-6, CD/DVD/Blu-ray, QR codes, and Backblaze's storage pods. It is NOT
|
| 5 |
-
"holographic quantum error correction". An (n, k) RS code splits data into k data shards
|
| 6 |
-
plus (n-k) parity shards; ANY k of the n shards reconstruct the original. We default to
|
| 7 |
-
RS(10, 6): 6 data + 4 parity, surviving loss of any 4 of 10 shards (40% loss tolerance).
|
| 8 |
-
|
| 9 |
-
Implementation strategy (open-source only, graceful):
|
| 10 |
-
* If the `reedsolo` package is installed, use it (battle-tested GF(2^8) RS).
|
| 11 |
-
* Otherwise use a self-contained pure-Python RS over GF(2^8) implemented here so the
|
| 12 |
-
package works with zero non-stdlib deps. Same (n, k) semantics either way.
|
| 13 |
-
"""
|
| 14 |
-
|
| 15 |
-
from __future__ import annotations
|
| 16 |
-
|
| 17 |
-
from typing import Optional
|
| 18 |
-
|
| 19 |
-
# ---------------------------------------------------------------------------
|
| 20 |
-
# GF(2^8) arithmetic (pure-python fallback), primitive polynomial 0x11d.
|
| 21 |
-
# ---------------------------------------------------------------------------
|
| 22 |
-
_EXP = [0] * 512
|
| 23 |
-
_LOG = [0] * 256
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
def _init_tables() -> None:
|
| 27 |
-
x = 1
|
| 28 |
-
for i in range(255):
|
| 29 |
-
_EXP[i] = x
|
| 30 |
-
_LOG[x] = i
|
| 31 |
-
x <<= 1
|
| 32 |
-
if x & 0x100:
|
| 33 |
-
x ^= 0x11D
|
| 34 |
-
for i in range(255, 512):
|
| 35 |
-
_EXP[i] = _EXP[i - 255]
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
_init_tables()
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def _gf_mul(a: int, b: int) -> int:
|
| 42 |
-
if a == 0 or b == 0:
|
| 43 |
-
return 0
|
| 44 |
-
return _EXP[_LOG[a] + _LOG[b]]
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def _gf_div(a: int, b: int) -> int:
|
| 48 |
-
if b == 0:
|
| 49 |
-
raise ZeroDivisionError("GF division by zero")
|
| 50 |
-
if a == 0:
|
| 51 |
-
return 0
|
| 52 |
-
return _EXP[(_LOG[a] - _LOG[b]) % 255]
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
class _PureRS:
|
| 56 |
-
"""Minimal systematic RS(n,k) over GF(2^8) using a Vandermonde parity matrix.
|
| 57 |
-
|
| 58 |
-
Encodes per-byte across k data shards into (n-k) parity shards. Decodes by solving the
|
| 59 |
-
linear system over GF(2^8) for any k available shards (data or parity). MDS: any k of n
|
| 60 |
-
suffice. This is a clean, dependency-free reference implementation.
|
| 61 |
-
"""
|
| 62 |
-
|
| 63 |
-
def __init__(self, n: int, k: int):
|
| 64 |
-
if not (0 < k < n <= 255):
|
| 65 |
-
raise ValueError("require 0 < k < n <= 255")
|
| 66 |
-
self.n, self.k = n, k
|
| 67 |
-
# Vandermonde matrix V[i][j] = (i+1)^j for i in [0, n), j in [0, k).
|
| 68 |
-
# Rows 0..k-1 used as-is is NOT identity, so we keep full Vandermonde and solve
|
| 69 |
-
# generally on decode (no systematic assumption needed for correctness).
|
| 70 |
-
self.V = [[_gf_pow(i + 1, j) for j in range(k)] for i in range(n)]
|
| 71 |
-
|
| 72 |
-
def encode(self, data_shards: list[bytes]) -> list[bytes]:
|
| 73 |
-
assert len(data_shards) == self.k
|
| 74 |
-
length = len(data_shards[0])
|
| 75 |
-
assert all(len(s) == length for s in data_shards)
|
| 76 |
-
out = [bytearray(length) for _ in range(self.n)]
|
| 77 |
-
for pos in range(length):
|
| 78 |
-
col = [data_shards[j][pos] for j in range(self.k)]
|
| 79 |
-
for i in range(self.n):
|
| 80 |
-
acc = 0
|
| 81 |
-
row = self.V[i]
|
| 82 |
-
for j in range(self.k):
|
| 83 |
-
acc ^= _gf_mul(row[j], col[j])
|
| 84 |
-
out[i][pos] = acc
|
| 85 |
-
return [bytes(b) for b in out]
|
| 86 |
-
|
| 87 |
-
def decode(self, shards: list[Optional[bytes]]) -> list[bytes]:
|
| 88 |
-
"""shards: list of length n; None = lost. Returns reconstructed k data shards."""
|
| 89 |
-
present = [(i, s) for i, s in enumerate(shards) if s is not None]
|
| 90 |
-
if len(present) < self.k:
|
| 91 |
-
raise ValueError(f"need >= {self.k} shards, have {len(present)}")
|
| 92 |
-
idx = [i for i, _ in present[: self.k]]
|
| 93 |
-
sub = [self.V[i][:] for i in idx]
|
| 94 |
-
length = len(present[0][1])
|
| 95 |
-
recovered = [bytearray(length) for _ in range(self.k)]
|
| 96 |
-
for pos in range(length):
|
| 97 |
-
vec = [present[t][1][pos] for t in range(self.k)]
|
| 98 |
-
sol = _solve_gf(sub, vec)
|
| 99 |
-
for j in range(self.k):
|
| 100 |
-
recovered[j][pos] = sol[j]
|
| 101 |
-
return [bytes(b) for b in recovered]
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
def _gf_pow(a: int, p: int) -> int:
|
| 105 |
-
r = 1
|
| 106 |
-
for _ in range(p):
|
| 107 |
-
r = _gf_mul(r, a)
|
| 108 |
-
return r
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
def _solve_gf(matrix: list[list[int]], vec: list[int]) -> list[int]:
|
| 112 |
-
"""Gaussian elimination over GF(2^8). matrix is k x k, vec length k."""
|
| 113 |
-
k = len(vec)
|
| 114 |
-
m = [row[:] + [vec[i]] for i, row in enumerate(matrix)]
|
| 115 |
-
for col in range(k):
|
| 116 |
-
piv = next((r for r in range(col, k) if m[r][col] != 0), None)
|
| 117 |
-
if piv is None:
|
| 118 |
-
raise ValueError("singular matrix")
|
| 119 |
-
m[col], m[piv] = m[piv], m[col]
|
| 120 |
-
inv = _gf_div(1, m[col][col])
|
| 121 |
-
m[col] = [_gf_mul(x, inv) for x in m[col]]
|
| 122 |
-
for r in range(k):
|
| 123 |
-
if r != col and m[r][col] != 0:
|
| 124 |
-
f = m[r][col]
|
| 125 |
-
m[r] = [a ^ _gf_mul(f, b) for a, b in zip(m[r], m[col])]
|
| 126 |
-
return [m[i][k] for i in range(k)]
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class ReedSolomonCoder:
|
| 130 |
-
"""(n, k) Reed-Solomon erasure coder. Default RS(10, 6) -> tolerate 4/10 lost."""
|
| 131 |
-
|
| 132 |
-
def __init__(self, n: int = 10, k: int = 6):
|
| 133 |
-
self.n, self.k = n, k
|
| 134 |
-
self._backend = "pure"
|
| 135 |
-
self._impl = _PureRS(n, k)
|
| 136 |
-
try:
|
| 137 |
-
import reedsolo # type: ignore # noqa: F401
|
| 138 |
-
|
| 139 |
-
self._backend = "reedsolo"
|
| 140 |
-
except Exception:
|
| 141 |
-
pass
|
| 142 |
-
|
| 143 |
-
@property
|
| 144 |
-
def backend(self) -> str:
|
| 145 |
-
return self._backend
|
| 146 |
-
|
| 147 |
-
def _split(self, data: bytes) -> tuple[list[bytes], int]:
|
| 148 |
-
orig_len = len(data)
|
| 149 |
-
shard_len = (orig_len + self.k - 1) // self.k
|
| 150 |
-
padded = data + b"\x00" * (shard_len * self.k - orig_len)
|
| 151 |
-
shards = [padded[i * shard_len : (i + 1) * shard_len] for i in range(self.k)]
|
| 152 |
-
return shards, orig_len
|
| 153 |
-
|
| 154 |
-
def encode(self, data: bytes) -> tuple[list[bytes], int]:
|
| 155 |
-
"""Return (n shards, original_length). Reconstruct from any k shards."""
|
| 156 |
-
data_shards, orig_len = self._split(data)
|
| 157 |
-
all_shards = self._impl.encode(data_shards)
|
| 158 |
-
return all_shards, orig_len
|
| 159 |
-
|
| 160 |
-
def decode(self, shards: list[Optional[bytes]], orig_len: int) -> bytes:
|
| 161 |
-
data_shards = self._impl.decode(shards)
|
| 162 |
-
return b"".join(data_shards)[:orig_len]
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
def encode_cell(cell_bytes: bytes, n: int = 10, k: int = 6) -> dict:
|
| 166 |
-
"""Encode a serialized cell into RS shards. Returns a portable shard manifest."""
|
| 167 |
-
coder = ReedSolomonCoder(n, k)
|
| 168 |
-
shards, orig_len = coder.encode(cell_bytes)
|
| 169 |
-
return {
|
| 170 |
-
"code": f"RS({n},{k})",
|
| 171 |
-
"backend": coder.backend,
|
| 172 |
-
"orig_len": orig_len,
|
| 173 |
-
"n": n,
|
| 174 |
-
"k": k,
|
| 175 |
-
"loss_tolerance": (n - k) / n,
|
| 176 |
-
"shards": [s.hex() for s in shards],
|
| 177 |
-
}
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
def decode_shards(manifest: dict) -> bytes:
|
| 181 |
-
"""Reconstruct original cell bytes from a shard manifest with up to (n-k) losses."""
|
| 182 |
-
n, k = manifest["n"], manifest["k"]
|
| 183 |
-
coder = ReedSolomonCoder(n, k)
|
| 184 |
-
shards = [bytes.fromhex(s) if s is not None else None for s in manifest["shards"]]
|
| 185 |
-
return coder.decode(shards, manifest["orig_len"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
"""EventBus — a minimal in-process publish/subscribe event bus.
|
| 2 |
-
|
| 3 |
-
No external broker. Subscribers register a callback for a topic (or "*" for all). When the
|
| 4 |
-
pool commits a cell it publishes a ("write", cell) event; reads publish ("read", cid).
|
| 5 |
-
This is the pub/sub layer of the KIPU substrate — organs subscribe to react to each
|
| 6 |
-
other's receipts without polling.
|
| 7 |
-
"""
|
| 8 |
-
|
| 9 |
-
from __future__ import annotations
|
| 10 |
-
|
| 11 |
-
import threading
|
| 12 |
-
from collections import defaultdict
|
| 13 |
-
from typing import Any, Callable
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
class EventBus:
|
| 17 |
-
def __init__(self) -> None:
|
| 18 |
-
self._subs: dict[str, list[Callable[[str, Any], None]]] = defaultdict(list)
|
| 19 |
-
self._lock = threading.RLock()
|
| 20 |
-
|
| 21 |
-
def subscribe(self, topic: str, callback: Callable[[str, Any], None]) -> Callable[[], None]:
|
| 22 |
-
"""Register `callback(topic, payload)`. Returns an unsubscribe function."""
|
| 23 |
-
with self._lock:
|
| 24 |
-
self._subs[topic].append(callback)
|
| 25 |
-
|
| 26 |
-
def _unsub() -> None:
|
| 27 |
-
with self._lock:
|
| 28 |
-
if callback in self._subs[topic]:
|
| 29 |
-
self._subs[topic].remove(callback)
|
| 30 |
-
|
| 31 |
-
return _unsub
|
| 32 |
-
|
| 33 |
-
def publish(self, topic: str, payload: Any) -> int:
|
| 34 |
-
"""Deliver to subscribers of `topic` and of "*". Returns count delivered."""
|
| 35 |
-
with self._lock:
|
| 36 |
-
targets = list(self._subs.get(topic, [])) + list(self._subs.get("*", []))
|
| 37 |
-
n = 0
|
| 38 |
-
for cb in targets:
|
| 39 |
-
try:
|
| 40 |
-
cb(topic, payload)
|
| 41 |
-
n += 1
|
| 42 |
-
except Exception:
|
| 43 |
-
# A misbehaving subscriber must not break the bus.
|
| 44 |
-
pass
|
| 45 |
-
return n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,110 +0,0 @@
|
|
| 1 |
-
"""QILLQAQ genome — declarative organ config parsed with stdlib `tomllib`.
|
| 2 |
-
|
| 3 |
-
HONEST NAMING: a "genome" here is a TOML config file describing an organ's identity, the
|
| 4 |
-
receipt KINDS it is allowed to read/write on the KIPU substrate, and which Python handler
|
| 5 |
-
(module:callable) implements its loop. "Boot from DNA" = parse TOML + import a module.
|
| 6 |
-
No biology, no magic. tomllib is the Python 3.11+ standard library TOML parser.
|
| 7 |
-
|
| 8 |
-
Schema (validated below):
|
| 9 |
-
[organ] name (str, required), quechua (str), function (str, required)
|
| 10 |
-
[role] loop (str, required) -- human description of the organ's loop
|
| 11 |
-
[reads] kinds (list[str], required) -- receipt KINDS this organ may read
|
| 12 |
-
[writes] kinds (list[str], required) -- receipt KINDS this organ may write
|
| 13 |
-
[boot] handler (str "module:callable", required), enabled (bool, default true)
|
| 14 |
-
[meta] any free-form table (optional)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
from __future__ import annotations
|
| 18 |
-
|
| 19 |
-
from dataclasses import dataclass, field
|
| 20 |
-
from pathlib import Path
|
| 21 |
-
from typing import Any
|
| 22 |
-
|
| 23 |
-
import tomllib
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
class GenomeError(ValueError):
|
| 27 |
-
"""Raised when a genome.toml fails schema validation."""
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
@dataclass
|
| 31 |
-
class Genome:
|
| 32 |
-
name: str
|
| 33 |
-
quechua: str
|
| 34 |
-
function: str
|
| 35 |
-
loop: str
|
| 36 |
-
reads: list[str]
|
| 37 |
-
writes: list[str]
|
| 38 |
-
handler: str # "module:callable"
|
| 39 |
-
enabled: bool = True
|
| 40 |
-
meta: dict = field(default_factory=dict)
|
| 41 |
-
raw: dict = field(default_factory=dict)
|
| 42 |
-
|
| 43 |
-
def may_write(self, kind: str) -> bool:
|
| 44 |
-
return kind in self.writes
|
| 45 |
-
|
| 46 |
-
def may_read(self, kind: str) -> bool:
|
| 47 |
-
return kind in self.reads
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
def _require(table: dict, key: str, typ: type, where: str) -> Any:
|
| 51 |
-
if key not in table:
|
| 52 |
-
raise GenomeError(f"[{where}] missing required key '{key}'")
|
| 53 |
-
val = table[key]
|
| 54 |
-
if not isinstance(val, typ):
|
| 55 |
-
raise GenomeError(f"[{where}] key '{key}' must be {typ.__name__}, got {type(val).__name__}")
|
| 56 |
-
return val
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
def validate_genome(data: dict) -> Genome:
|
| 60 |
-
"""Validate a parsed TOML dict against the genome schema. Returns a Genome or raises."""
|
| 61 |
-
if "organ" not in data:
|
| 62 |
-
raise GenomeError("missing [organ] table")
|
| 63 |
-
organ = data["organ"]
|
| 64 |
-
name = _require(organ, "name", str, "organ")
|
| 65 |
-
function = _require(organ, "function", str, "organ")
|
| 66 |
-
quechua = organ.get("quechua", "")
|
| 67 |
-
|
| 68 |
-
if "role" not in data:
|
| 69 |
-
raise GenomeError("missing [role] table")
|
| 70 |
-
loop = _require(data["role"], "loop", str, "role")
|
| 71 |
-
|
| 72 |
-
if "reads" not in data:
|
| 73 |
-
raise GenomeError("missing [reads] table")
|
| 74 |
-
reads = _require(data["reads"], "kinds", list, "reads")
|
| 75 |
-
if not all(isinstance(x, str) for x in reads):
|
| 76 |
-
raise GenomeError("[reads] kinds must be a list of strings")
|
| 77 |
-
|
| 78 |
-
if "writes" not in data:
|
| 79 |
-
raise GenomeError("missing [writes] table")
|
| 80 |
-
writes = _require(data["writes"], "kinds", list, "writes")
|
| 81 |
-
if not all(isinstance(x, str) for x in writes):
|
| 82 |
-
raise GenomeError("[writes] kinds must be a list of strings")
|
| 83 |
-
|
| 84 |
-
if "boot" not in data:
|
| 85 |
-
raise GenomeError("missing [boot] table")
|
| 86 |
-
handler = _require(data["boot"], "handler", str, "boot")
|
| 87 |
-
if ":" not in handler:
|
| 88 |
-
raise GenomeError("[boot] handler must be 'module:callable'")
|
| 89 |
-
enabled = bool(data["boot"].get("enabled", True))
|
| 90 |
-
|
| 91 |
-
return Genome(
|
| 92 |
-
name=name,
|
| 93 |
-
quechua=quechua,
|
| 94 |
-
function=function,
|
| 95 |
-
loop=loop,
|
| 96 |
-
reads=reads,
|
| 97 |
-
writes=writes,
|
| 98 |
-
handler=handler,
|
| 99 |
-
enabled=enabled,
|
| 100 |
-
meta=data.get("meta", {}),
|
| 101 |
-
raw=data,
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
def load_genome(path: str | Path) -> Genome:
|
| 106 |
-
"""Parse a genome.toml file with tomllib and validate it. Returns a Genome."""
|
| 107 |
-
p = Path(path)
|
| 108 |
-
with open(p, "rb") as f:
|
| 109 |
-
data = tomllib.load(f)
|
| 110 |
-
return validate_genome(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
"""Default reference handlers for OrganAgents.
|
| 2 |
-
|
| 3 |
-
A genome's [boot] handler points at "module:callable". For organs whose real runtime code
|
| 4 |
-
lives elsewhere (amaru/, rosie/, sentra/ repos), the genome can point at one of these
|
| 5 |
-
generic reference handlers so the agent has a working, gated step() out of the box.
|
| 6 |
-
|
| 7 |
-
Each handler receives the bound OrganAgent and returns a dict summary of what it did. They
|
| 8 |
-
only ever write receipt KINDS the genome authorizes (the OrganAgent.write() gate enforces
|
| 9 |
-
this), so a handler cannot exceed its declared role.
|
| 10 |
-
"""
|
| 11 |
-
|
| 12 |
-
from __future__ import annotations
|
| 13 |
-
|
| 14 |
-
import time
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def echo(agent, message: str = "alive") -> dict:
|
| 18 |
-
"""Write a single heartbeat receipt of the organ's first authorized write-kind."""
|
| 19 |
-
kind = agent.genome.writes[0]
|
| 20 |
-
cid = agent.write(kind, {"message": message, "ts": time.time()})
|
| 21 |
-
return {"organ": agent.genome.name, "wrote_kind": kind, "cid": cid}
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def reconcile(agent) -> dict:
|
| 25 |
-
"""No-op reconcile: report current authorization surface. Writes nothing."""
|
| 26 |
-
return {
|
| 27 |
-
"organ": agent.genome.name,
|
| 28 |
-
"reads": agent.genome.reads,
|
| 29 |
-
"writes": agent.genome.writes,
|
| 30 |
-
"reconciled": True,
|
| 31 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,137 +0,0 @@
|
|
| 1 |
-
"""KipuPool — the shared, content-addressed receipt-cell substrate.
|
| 2 |
-
|
| 3 |
-
Every organ reads/writes ReceiptCells here. Each write:
|
| 4 |
-
1. computes/verifies the content address (cid),
|
| 5 |
-
2. persists the cell (LMDB if available, else a JSON-file store — same API),
|
| 6 |
-
3. optionally stores a Reed-Solomon shard manifest for durability,
|
| 7 |
-
4. publishes a ("write", cell) event on the in-process EventBus.
|
| 8 |
-
|
| 9 |
-
Each read publishes a ("read", cid) event and emits a read-receipt cell, so there is no
|
| 10 |
-
silent access. This is a Linda-style tuple space + event sourcing + content addressing.
|
| 11 |
-
HONEST: durability is Reed-Solomon erasure coding, not "holographic QEC".
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
from __future__ import annotations
|
| 15 |
-
|
| 16 |
-
import json
|
| 17 |
-
import os
|
| 18 |
-
import threading
|
| 19 |
-
from pathlib import Path
|
| 20 |
-
from typing import Iterable, Optional
|
| 21 |
-
|
| 22 |
-
from .cell import ReceiptCell
|
| 23 |
-
from .coding import decode_shards, encode_cell
|
| 24 |
-
from .events import EventBus
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
class _Store:
|
| 28 |
-
"""Key-value persistence: LMDB backend if installed, else JSON-file fallback."""
|
| 29 |
-
|
| 30 |
-
def __init__(self, path: str):
|
| 31 |
-
self.path = path
|
| 32 |
-
self.backend = "json"
|
| 33 |
-
self._lmdb = None
|
| 34 |
-
self._lock = threading.RLock()
|
| 35 |
-
try:
|
| 36 |
-
import lmdb # type: ignore
|
| 37 |
-
|
| 38 |
-
os.makedirs(path, exist_ok=True)
|
| 39 |
-
self._lmdb = lmdb.open(path, map_size=256 * 1024 * 1024)
|
| 40 |
-
self.backend = "lmdb"
|
| 41 |
-
except Exception:
|
| 42 |
-
self._file = Path(path)
|
| 43 |
-
self._file.parent.mkdir(parents=True, exist_ok=True)
|
| 44 |
-
if not self._file.exists():
|
| 45 |
-
self._file.write_text("{}")
|
| 46 |
-
|
| 47 |
-
def put(self, key: str, value: bytes) -> None:
|
| 48 |
-
with self._lock:
|
| 49 |
-
if self.backend == "lmdb":
|
| 50 |
-
with self._lmdb.begin(write=True) as txn:
|
| 51 |
-
txn.put(key.encode(), value)
|
| 52 |
-
else:
|
| 53 |
-
d = json.loads(self._file.read_text())
|
| 54 |
-
d[key] = value.decode("utf-8")
|
| 55 |
-
self._file.write_text(json.dumps(d))
|
| 56 |
-
|
| 57 |
-
def get(self, key: str) -> Optional[bytes]:
|
| 58 |
-
with self._lock:
|
| 59 |
-
if self.backend == "lmdb":
|
| 60 |
-
with self._lmdb.begin() as txn:
|
| 61 |
-
v = txn.get(key.encode())
|
| 62 |
-
return bytes(v) if v is not None else None
|
| 63 |
-
d = json.loads(self._file.read_text())
|
| 64 |
-
v = d.get(key)
|
| 65 |
-
return v.encode("utf-8") if v is not None else None
|
| 66 |
-
|
| 67 |
-
def keys(self) -> Iterable[str]:
|
| 68 |
-
with self._lock:
|
| 69 |
-
if self.backend == "lmdb":
|
| 70 |
-
with self._lmdb.begin() as txn:
|
| 71 |
-
return [k.decode() for k, _ in txn.cursor()]
|
| 72 |
-
return list(json.loads(self._file.read_text()).keys())
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
class KipuPool:
|
| 76 |
-
"""The shared receipt-cell substrate."""
|
| 77 |
-
|
| 78 |
-
def __init__(self, path: str = "/tmp/kipu", durability: bool = True,
|
| 79 |
-
rs_n: int = 10, rs_k: int = 6):
|
| 80 |
-
self.bus = EventBus()
|
| 81 |
-
self._cells = _Store(os.path.join(path, "cells"))
|
| 82 |
-
self._shards = _Store(os.path.join(path, "shards"))
|
| 83 |
-
self.durability = durability
|
| 84 |
-
self.rs_n, self.rs_k = rs_n, rs_k
|
| 85 |
-
|
| 86 |
-
@property
|
| 87 |
-
def store_backend(self) -> str:
|
| 88 |
-
return self._cells.backend
|
| 89 |
-
|
| 90 |
-
def write(self, cell: ReceiptCell) -> str:
|
| 91 |
-
"""Persist a cell, optionally RS-encode it, publish a write event. Returns cid."""
|
| 92 |
-
if not cell.verify():
|
| 93 |
-
raise ValueError("ReceiptCell failed content-address verification")
|
| 94 |
-
cb = cell.to_bytes()
|
| 95 |
-
self._cells.put(cell.cid, cb)
|
| 96 |
-
if self.durability:
|
| 97 |
-
manifest = encode_cell(cb, self.rs_n, self.rs_k)
|
| 98 |
-
self._shards.put(cell.cid, json.dumps(manifest).encode())
|
| 99 |
-
self.bus.publish("write", cell)
|
| 100 |
-
self.bus.publish(f"organ:{cell.organ}", cell)
|
| 101 |
-
return cell.cid
|
| 102 |
-
|
| 103 |
-
def read(self, cid: str, reader: str = "anon", emit_receipt: bool = True) -> Optional[ReceiptCell]:
|
| 104 |
-
"""Read a cell by cid. Publishes a read event and (optionally) a read-receipt."""
|
| 105 |
-
raw = self._cells.get(cid)
|
| 106 |
-
cell = ReceiptCell.from_bytes(raw) if raw is not None else None
|
| 107 |
-
self.bus.publish("read", {"cid": cid, "reader": reader, "hit": cell is not None})
|
| 108 |
-
if emit_receipt and cell is not None:
|
| 109 |
-
rr = ReceiptCell(organ=reader, kind="read_receipt",
|
| 110 |
-
payload={"read_cid": cid}, parents=(cid,))
|
| 111 |
-
self._cells.put(rr.cid, rr.to_bytes())
|
| 112 |
-
return cell
|
| 113 |
-
|
| 114 |
-
def recover(self, cid: str, drop: Optional[list[int]] = None) -> Optional[ReceiptCell]:
|
| 115 |
-
"""Recover a cell from its Reed-Solomon shards, optionally simulating lost shards."""
|
| 116 |
-
raw = self._shards.get(cid)
|
| 117 |
-
if raw is None:
|
| 118 |
-
return None
|
| 119 |
-
manifest = json.loads(raw.decode())
|
| 120 |
-
if drop:
|
| 121 |
-
shards = list(manifest["shards"])
|
| 122 |
-
for i in drop:
|
| 123 |
-
shards[i] = None
|
| 124 |
-
manifest = {**manifest, "shards": shards}
|
| 125 |
-
cb = decode_shards(manifest)
|
| 126 |
-
return ReceiptCell.from_bytes(cb)
|
| 127 |
-
|
| 128 |
-
def all_cids(self) -> list[str]:
|
| 129 |
-
return list(self._cells.keys())
|
| 130 |
-
|
| 131 |
-
def stats(self) -> dict:
|
| 132 |
-
return {
|
| 133 |
-
"store_backend": self._cells.backend,
|
| 134 |
-
"cells": len(list(self._cells.keys())),
|
| 135 |
-
"durability": self.durability,
|
| 136 |
-
"rs_code": f"RS({self.rs_n},{self.rs_k})",
|
| 137 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,123 +0,0 @@
|
|
| 1 |
-
"""QILLQAQ transcription engine — boot OrganAgents from declarative genome.toml files.
|
| 2 |
-
|
| 3 |
-
HONEST NAMING: "transcription" = read TOML config, import a handler module, instantiate an
|
| 4 |
-
agent. "boot from DNA" = config-driven module loading (like a plugin registry or a
|
| 5 |
-
Kubernetes operator reconciling a CRD). No biology.
|
| 6 |
-
|
| 7 |
-
An OrganAgent:
|
| 8 |
-
* holds its Genome (the validated config),
|
| 9 |
-
* is bound to a shared KipuPool,
|
| 10 |
-
* exposes write()/read() that are GATED by the genome's allowed receipt kinds,
|
| 11 |
-
* runs its handler (a module:callable) when stepped, if one resolves.
|
| 12 |
-
|
| 13 |
-
If a handler module cannot be imported (e.g. the organ's real code isn't present), the
|
| 14 |
-
agent still boots in "declared" mode: it can read/write receipts but has no step logic.
|
| 15 |
-
This keeps the engine usable as pure substrate wiring without every organ's code on path.
|
| 16 |
-
"""
|
| 17 |
-
|
| 18 |
-
from __future__ import annotations
|
| 19 |
-
|
| 20 |
-
import importlib
|
| 21 |
-
from pathlib import Path
|
| 22 |
-
from typing import Callable, Optional
|
| 23 |
-
|
| 24 |
-
from .cell import ReceiptCell
|
| 25 |
-
from .genome import Genome, GenomeError, load_genome
|
| 26 |
-
from .pool import KipuPool
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
class OrganAgent:
|
| 30 |
-
def __init__(self, genome: Genome, pool: KipuPool):
|
| 31 |
-
self.genome = genome
|
| 32 |
-
self.pool = pool
|
| 33 |
-
self.handler: Optional[Callable] = None
|
| 34 |
-
self.handler_status = "unbound"
|
| 35 |
-
self._resolve_handler()
|
| 36 |
-
|
| 37 |
-
def _resolve_handler(self) -> None:
|
| 38 |
-
mod_name, _, attr = self.genome.handler.partition(":")
|
| 39 |
-
try:
|
| 40 |
-
mod = importlib.import_module(mod_name)
|
| 41 |
-
self.handler = getattr(mod, attr)
|
| 42 |
-
self.handler_status = "bound"
|
| 43 |
-
except Exception as e:
|
| 44 |
-
self.handler = None
|
| 45 |
-
self.handler_status = f"declared (handler import failed: {type(e).__name__})"
|
| 46 |
-
|
| 47 |
-
def write(self, kind: str, payload: dict, parents: tuple = ()) -> str:
|
| 48 |
-
if not self.genome.may_write(kind):
|
| 49 |
-
raise PermissionError(
|
| 50 |
-
f"organ '{self.genome.name}' genome does not authorize writing kind '{kind}' "
|
| 51 |
-
f"(allowed: {self.genome.writes})"
|
| 52 |
-
)
|
| 53 |
-
cell = ReceiptCell(organ=self.genome.name, kind=kind, payload=payload, parents=parents)
|
| 54 |
-
return self.pool.write(cell)
|
| 55 |
-
|
| 56 |
-
def read(self, cid: str) -> Optional[ReceiptCell]:
|
| 57 |
-
cell = self.pool.read(cid, reader=self.genome.name)
|
| 58 |
-
if cell is not None and not self.genome.may_read(cell.kind):
|
| 59 |
-
raise PermissionError(
|
| 60 |
-
f"organ '{self.genome.name}' genome does not authorize reading kind '{cell.kind}' "
|
| 61 |
-
f"(allowed: {self.genome.reads})"
|
| 62 |
-
)
|
| 63 |
-
return cell
|
| 64 |
-
|
| 65 |
-
def step(self, *args, **kwargs):
|
| 66 |
-
"""Invoke the bound handler if present. Handler signature: handler(agent, *a, **k)."""
|
| 67 |
-
if self.handler is None:
|
| 68 |
-
return None
|
| 69 |
-
return self.handler(self, *args, **kwargs)
|
| 70 |
-
|
| 71 |
-
def info(self) -> dict:
|
| 72 |
-
return {
|
| 73 |
-
"name": self.genome.name,
|
| 74 |
-
"quechua": self.genome.quechua,
|
| 75 |
-
"function": self.genome.function,
|
| 76 |
-
"reads": self.genome.reads,
|
| 77 |
-
"writes": self.genome.writes,
|
| 78 |
-
"handler": self.genome.handler,
|
| 79 |
-
"handler_status": self.handler_status,
|
| 80 |
-
"enabled": self.genome.enabled,
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
class QillqaqEngine:
|
| 85 |
-
"""Reads a directory of genome.toml files and boots an OrganAgent for each."""
|
| 86 |
-
|
| 87 |
-
def __init__(self, pool: Optional[KipuPool] = None):
|
| 88 |
-
self.pool = pool or KipuPool()
|
| 89 |
-
self.agents: dict[str, OrganAgent] = {}
|
| 90 |
-
self.errors: dict[str, str] = {}
|
| 91 |
-
|
| 92 |
-
def boot_file(self, path: str | Path) -> Optional[OrganAgent]:
|
| 93 |
-
try:
|
| 94 |
-
genome = load_genome(path)
|
| 95 |
-
except GenomeError as e:
|
| 96 |
-
self.errors[str(path)] = str(e)
|
| 97 |
-
return None
|
| 98 |
-
if not genome.enabled:
|
| 99 |
-
return None
|
| 100 |
-
agent = OrganAgent(genome, self.pool)
|
| 101 |
-
self.agents[genome.name] = agent
|
| 102 |
-
return agent
|
| 103 |
-
|
| 104 |
-
def boot_dir(self, directory: str | Path, pattern: str = "*.toml") -> dict[str, OrganAgent]:
|
| 105 |
-
"""Boot every genome file in a directory. Returns {organ_name: agent}."""
|
| 106 |
-
d = Path(directory)
|
| 107 |
-
for f in sorted(d.glob(pattern)):
|
| 108 |
-
self.boot_file(f)
|
| 109 |
-
return self.agents
|
| 110 |
-
|
| 111 |
-
def boot_packaged(self) -> dict[str, OrganAgent]:
|
| 112 |
-
"""Boot the genome.toml files bundled inside the installed package."""
|
| 113 |
-
here = Path(__file__).parent / "genomes"
|
| 114 |
-
return self.boot_dir(here)
|
| 115 |
-
|
| 116 |
-
def manifest(self) -> dict:
|
| 117 |
-
return {
|
| 118 |
-
"engine": "QILLQAQ",
|
| 119 |
-
"pool": self.pool.stats(),
|
| 120 |
-
"organs": {name: a.info() for name, a in self.agents.items()},
|
| 121 |
-
"errors": self.errors,
|
| 122 |
-
"count": len(self.agents),
|
| 123 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File without changes
|
|
File without changes
|
|
@@ -1,117 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
voters/__init__.py — Registry of all 13 a11oy v4 ensemble voters.
|
| 8 |
-
|
| 9 |
-
Sovereign-default: qwen-local is ALWAYS first and never removed.
|
| 10 |
-
Cloud voters: off by default, activate via env var + explicit voters list.
|
| 11 |
-
"""
|
| 12 |
-
from __future__ import annotations
|
| 13 |
-
|
| 14 |
-
from typing import Dict, List
|
| 15 |
-
|
| 16 |
-
from .base_voter import BaseVoter, VOTER_INPUT_SCHEMA, VOTER_OUTPUT_SCHEMA
|
| 17 |
-
|
| 18 |
-
# ── Existing 4 voters ─────────────────────────────────────────────────────────
|
| 19 |
-
from .qwen_local import QwenLocalVoter
|
| 20 |
-
from .hf_inference_voter import (
|
| 21 |
-
HFInferenceLlamaVoter,
|
| 22 |
-
HFInferenceMistralVoter,
|
| 23 |
-
HFInferenceQwenVoter,
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
# ── 9 new voters (feat/llm-roster-expansion-9-voters) ────────────────────────
|
| 27 |
-
from .deepseek_r1 import DeepSeekR1Voter
|
| 28 |
-
from .kimi_k2 import KimiK2Voter
|
| 29 |
-
from .glm_4_6 import GLM46Voter
|
| 30 |
-
from .hermes_4_405b import Hermes4405BVoter
|
| 31 |
-
from .minimax_m2 import MiniMaxM2Voter
|
| 32 |
-
from .step_3_7_flash import Step37FlashVoter
|
| 33 |
-
from .nomos_1 import Nomos1Voter
|
| 34 |
-
from .nemotron_super_49b import NemotronSuper49BVoter
|
| 35 |
-
from .xiaomi_mimo import XiaomiMiMoVoter
|
| 36 |
-
|
| 37 |
-
# Ordered: sovereign-default first, then existing HF voters, then 9 new voters
|
| 38 |
-
_ALL_VOTER_INSTANCES: List[BaseVoter] = [
|
| 39 |
-
QwenLocalVoter(), # sovereign-default: always in pool
|
| 40 |
-
HFInferenceLlamaVoter(),
|
| 41 |
-
HFInferenceMistralVoter(),
|
| 42 |
-
HFInferenceQwenVoter(),
|
| 43 |
-
# --- 9 new voters ---
|
| 44 |
-
DeepSeekR1Voter(),
|
| 45 |
-
KimiK2Voter(),
|
| 46 |
-
GLM46Voter(),
|
| 47 |
-
Hermes4405BVoter(),
|
| 48 |
-
MiniMaxM2Voter(),
|
| 49 |
-
Step37FlashVoter(),
|
| 50 |
-
Nomos1Voter(),
|
| 51 |
-
NemotronSuper49BVoter(),
|
| 52 |
-
XiaomiMiMoVoter(),
|
| 53 |
-
]
|
| 54 |
-
|
| 55 |
-
_VOTER_MAP: Dict[str, BaseVoter] = {v.VOTER_ID: v for v in _ALL_VOTER_INSTANCES}
|
| 56 |
-
|
| 57 |
-
VOTER_COUNT = len(_ALL_VOTER_INSTANCES) # 13
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
def get_all_voters() -> List[BaseVoter]:
|
| 61 |
-
"""Return all 13 registered voter instances."""
|
| 62 |
-
return list(_ALL_VOTER_INSTANCES)
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
def get_voter(voter_id: str) -> BaseVoter | None:
|
| 66 |
-
"""Look up a voter by ID."""
|
| 67 |
-
return _VOTER_MAP.get(voter_id)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
def resolve_voters(requested: List[str] | None) -> List[BaseVoter]:
|
| 71 |
-
"""Return voters to run for a given request.
|
| 72 |
-
|
| 73 |
-
If `requested` is None/empty → only qwen-local (sovereign-default).
|
| 74 |
-
Otherwise → intersection of requested IDs with the registry, preserving order.
|
| 75 |
-
qwen-local is always prepended as the sovereign floor.
|
| 76 |
-
"""
|
| 77 |
-
sovereign = _VOTER_MAP["qwen-local"]
|
| 78 |
-
if not requested:
|
| 79 |
-
return [sovereign]
|
| 80 |
-
out: List[BaseVoter] = []
|
| 81 |
-
seen = set()
|
| 82 |
-
# sovereign-default always first
|
| 83 |
-
out.append(sovereign)
|
| 84 |
-
seen.add("qwen-local")
|
| 85 |
-
for vid in requested:
|
| 86 |
-
if vid in seen:
|
| 87 |
-
continue
|
| 88 |
-
voter = _VOTER_MAP.get(vid)
|
| 89 |
-
if voter is not None:
|
| 90 |
-
out.append(voter)
|
| 91 |
-
seen.add(vid)
|
| 92 |
-
return out
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
__all__ = [
|
| 96 |
-
"BaseVoter",
|
| 97 |
-
"VOTER_INPUT_SCHEMA",
|
| 98 |
-
"VOTER_OUTPUT_SCHEMA",
|
| 99 |
-
"VOTER_COUNT",
|
| 100 |
-
"get_all_voters",
|
| 101 |
-
"get_voter",
|
| 102 |
-
"resolve_voters",
|
| 103 |
-
# Individual voter classes
|
| 104 |
-
"QwenLocalVoter",
|
| 105 |
-
"HFInferenceLlamaVoter",
|
| 106 |
-
"HFInferenceMistralVoter",
|
| 107 |
-
"HFInferenceQwenVoter",
|
| 108 |
-
"DeepSeekR1Voter",
|
| 109 |
-
"KimiK2Voter",
|
| 110 |
-
"GLM46Voter",
|
| 111 |
-
"Hermes4405BVoter",
|
| 112 |
-
"MiniMaxM2Voter",
|
| 113 |
-
"Step37FlashVoter",
|
| 114 |
-
"Nomos1Voter",
|
| 115 |
-
"NemotronSuper49BVoter",
|
| 116 |
-
"XiaomiMiMoVoter",
|
| 117 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,187 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Λ = Conjecture 1 (NOT a theorem; 163 sorries).
|
| 4 |
-
# Authored by Yachay (CTO). DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
base_voter.py — Abstract base class for all a11oy v4 multi-LLM ensemble voters.
|
| 8 |
-
|
| 9 |
-
Every voter MUST:
|
| 10 |
-
- Declare a VOTER_ID (str), ENV_VARS (list[str]), LICENSE, PROVIDER, CONTEXT_WINDOW
|
| 11 |
-
- Implement _call(prompt, **kwargs) -> str (raw model text completion)
|
| 12 |
-
- Never fabricate a response when unavailable; return {status: "unavailable"} instead.
|
| 13 |
-
|
| 14 |
-
Voter is OFF by default. Only activates when:
|
| 15 |
-
1. Caller explicitly lists it in the `voters` field of /agent/ask
|
| 16 |
-
2. At least one of its ENV_VARS is present in os.environ
|
| 17 |
-
|
| 18 |
-
Λ-aggregator: untouched (Conjecture 1, 163 sorries). Provenance entries appended.
|
| 19 |
-
"""
|
| 20 |
-
from __future__ import annotations
|
| 21 |
-
|
| 22 |
-
import abc
|
| 23 |
-
import asyncio
|
| 24 |
-
import os
|
| 25 |
-
import time
|
| 26 |
-
from typing import Any, Dict, List, Optional
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# ---------------------------------------------------------------------------
|
| 30 |
-
# JSON Schema for voter input/output (additionalProperties: false)
|
| 31 |
-
# ---------------------------------------------------------------------------
|
| 32 |
-
|
| 33 |
-
VOTER_INPUT_SCHEMA: Dict[str, Any] = {
|
| 34 |
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 35 |
-
"type": "object",
|
| 36 |
-
"title": "VoterInput",
|
| 37 |
-
"required": ["prompt"],
|
| 38 |
-
"additionalProperties": False,
|
| 39 |
-
"properties": {
|
| 40 |
-
"prompt": {"type": "string", "description": "The user prompt to route to this voter."},
|
| 41 |
-
"system": {"type": "string", "description": "Optional system prompt override."},
|
| 42 |
-
"max_tokens": {"type": "integer", "default": 512, "minimum": 1, "maximum": 8192},
|
| 43 |
-
"temperature": {"type": "number", "default": 0.7, "minimum": 0.0, "maximum": 2.0},
|
| 44 |
-
},
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
VOTER_OUTPUT_SCHEMA: Dict[str, Any] = {
|
| 48 |
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 49 |
-
"type": "object",
|
| 50 |
-
"title": "VoterOutput",
|
| 51 |
-
"additionalProperties": False,
|
| 52 |
-
"properties": {
|
| 53 |
-
"voter_id": {"type": "string"},
|
| 54 |
-
"status": {"type": "string", "enum": ["ok", "unavailable", "error"]},
|
| 55 |
-
"text": {"type": ["string", "null"]},
|
| 56 |
-
"reason": {"type": ["string", "null"]},
|
| 57 |
-
"latency_ms": {"type": ["number", "null"]},
|
| 58 |
-
"provenance": {
|
| 59 |
-
"type": "object",
|
| 60 |
-
"additionalProperties": False,
|
| 61 |
-
"properties": {
|
| 62 |
-
"provider": {"type": "string"},
|
| 63 |
-
"model_id": {"type": "string"},
|
| 64 |
-
"license": {"type": "string"},
|
| 65 |
-
"env_var_used": {"type": ["string", "null"]},
|
| 66 |
-
"timestamp_utc": {"type": "string"},
|
| 67 |
-
},
|
| 68 |
-
},
|
| 69 |
-
},
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
class BaseVoter(abc.ABC):
|
| 74 |
-
"""Abstract base voter for the a11oy v4 multi-LLM ensemble."""
|
| 75 |
-
|
| 76 |
-
# Subclasses MUST override:
|
| 77 |
-
VOTER_ID: str = ""
|
| 78 |
-
ENV_VARS: List[str] = [] # First present one is used
|
| 79 |
-
LICENSE: str = ""
|
| 80 |
-
PROVIDER: str = ""
|
| 81 |
-
CONTEXT_WINDOW: int = 4096
|
| 82 |
-
MODEL_ID: str = ""
|
| 83 |
-
BFCL_SCORE: Optional[str] = None # e.g. "#1" or None
|
| 84 |
-
|
| 85 |
-
def is_available(self) -> bool:
|
| 86 |
-
"""True iff at least one required env var is present."""
|
| 87 |
-
return any(os.environ.get(v) for v in self.ENV_VARS)
|
| 88 |
-
|
| 89 |
-
def _active_env_var(self) -> Optional[str]:
|
| 90 |
-
"""Return the first present env var name (not the value)."""
|
| 91 |
-
for v in self.ENV_VARS:
|
| 92 |
-
if os.environ.get(v):
|
| 93 |
-
return v
|
| 94 |
-
return None
|
| 95 |
-
|
| 96 |
-
@abc.abstractmethod
|
| 97 |
-
async def _call(
|
| 98 |
-
self,
|
| 99 |
-
prompt: str,
|
| 100 |
-
system: Optional[str] = None,
|
| 101 |
-
max_tokens: int = 512,
|
| 102 |
-
temperature: float = 0.7,
|
| 103 |
-
**kwargs: Any,
|
| 104 |
-
) -> str:
|
| 105 |
-
"""Perform the actual LLM call. Must return a non-empty string.
|
| 106 |
-
Raise any exception on failure; the wrapper handles it.
|
| 107 |
-
"""
|
| 108 |
-
...
|
| 109 |
-
|
| 110 |
-
async def vote(
|
| 111 |
-
self,
|
| 112 |
-
prompt: str,
|
| 113 |
-
system: Optional[str] = None,
|
| 114 |
-
max_tokens: int = 512,
|
| 115 |
-
temperature: float = 0.7,
|
| 116 |
-
**kwargs: Any,
|
| 117 |
-
) -> Dict[str, Any]:
|
| 118 |
-
"""Entry point called by the aggregator. Never raises.
|
| 119 |
-
|
| 120 |
-
If the env var is missing → returns {status: "unavailable"}.
|
| 121 |
-
If the call fails → returns {status: "error"}.
|
| 122 |
-
If success → returns {status: "ok", text: <str>}.
|
| 123 |
-
"""
|
| 124 |
-
import datetime
|
| 125 |
-
|
| 126 |
-
env_var_used = self._active_env_var()
|
| 127 |
-
provenance = {
|
| 128 |
-
"provider": self.PROVIDER,
|
| 129 |
-
"model_id": self.MODEL_ID,
|
| 130 |
-
"license": self.LICENSE,
|
| 131 |
-
"env_var_used": env_var_used,
|
| 132 |
-
"timestamp_utc": datetime.datetime.now(datetime.timezone.utc).isoformat().replace("+00:00", "Z"),
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
if not self.is_available():
|
| 136 |
-
return {
|
| 137 |
-
"voter_id": self.VOTER_ID,
|
| 138 |
-
"status": "unavailable",
|
| 139 |
-
"text": None,
|
| 140 |
-
"reason": (
|
| 141 |
-
f"token_not_present — none of {self.ENV_VARS} found in runtime env; "
|
| 142 |
-
"set the env var to activate this voter."
|
| 143 |
-
),
|
| 144 |
-
"latency_ms": None,
|
| 145 |
-
"provenance": provenance,
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
t0 = time.monotonic()
|
| 149 |
-
try:
|
| 150 |
-
text = await self._call(
|
| 151 |
-
prompt=prompt,
|
| 152 |
-
system=system,
|
| 153 |
-
max_tokens=max_tokens,
|
| 154 |
-
temperature=temperature,
|
| 155 |
-
**kwargs,
|
| 156 |
-
)
|
| 157 |
-
return {
|
| 158 |
-
"voter_id": self.VOTER_ID,
|
| 159 |
-
"status": "ok",
|
| 160 |
-
"text": text,
|
| 161 |
-
"reason": None,
|
| 162 |
-
"latency_ms": round((time.monotonic() - t0) * 1000, 1),
|
| 163 |
-
"provenance": provenance,
|
| 164 |
-
}
|
| 165 |
-
except Exception as exc:
|
| 166 |
-
return {
|
| 167 |
-
"voter_id": self.VOTER_ID,
|
| 168 |
-
"status": "error",
|
| 169 |
-
"text": None,
|
| 170 |
-
"reason": f"{type(exc).__name__}: {exc}",
|
| 171 |
-
"latency_ms": round((time.monotonic() - t0) * 1000, 1),
|
| 172 |
-
"provenance": provenance,
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
def metadata(self) -> Dict[str, Any]:
|
| 176 |
-
"""Return voter metadata for /agent/voters endpoint."""
|
| 177 |
-
avail = self.is_available()
|
| 178 |
-
return {
|
| 179 |
-
"voter_id": self.VOTER_ID,
|
| 180 |
-
"status": "available" if avail else "token_required",
|
| 181 |
-
"provider": self.PROVIDER,
|
| 182 |
-
"license": self.LICENSE,
|
| 183 |
-
"context_window": self.CONTEXT_WINDOW,
|
| 184 |
-
"bfcl_score": self.BFCL_SCORE,
|
| 185 |
-
"env_vars": self.ENV_VARS,
|
| 186 |
-
"model_id": self.MODEL_ID,
|
| 187 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,80 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
deepseek_r1.py — DeepSeek-R1 voter.
|
| 8 |
-
|
| 9 |
-
Backend: DeepSeek API (primary) or HF Inference (secondary).
|
| 10 |
-
Env vars: DEEPSEEK_API_KEY or HF_TOKEN.
|
| 11 |
-
Off by default — activate by listing "deepseek-r1" in voters and having the env var.
|
| 12 |
-
"""
|
| 13 |
-
from __future__ import annotations
|
| 14 |
-
|
| 15 |
-
import os
|
| 16 |
-
from typing import Any, Optional
|
| 17 |
-
|
| 18 |
-
import httpx
|
| 19 |
-
|
| 20 |
-
from .base_voter import BaseVoter
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
class DeepSeekR1Voter(BaseVoter):
|
| 24 |
-
VOTER_ID = "deepseek-r1"
|
| 25 |
-
ENV_VARS = ["DEEPSEEK_API_KEY", "HF_TOKEN"]
|
| 26 |
-
LICENSE = "MIT (open weights)"
|
| 27 |
-
PROVIDER = "DeepSeek API / HuggingFace Inference"
|
| 28 |
-
CONTEXT_WINDOW = 65536
|
| 29 |
-
MODEL_ID = "deepseek-ai/DeepSeek-R1"
|
| 30 |
-
BFCL_SCORE = None
|
| 31 |
-
|
| 32 |
-
async def _call(
|
| 33 |
-
self,
|
| 34 |
-
prompt: str,
|
| 35 |
-
system: Optional[str] = None,
|
| 36 |
-
max_tokens: int = 512,
|
| 37 |
-
temperature: float = 0.7,
|
| 38 |
-
**kwargs: Any,
|
| 39 |
-
) -> str:
|
| 40 |
-
messages = []
|
| 41 |
-
if system:
|
| 42 |
-
messages.append({"role": "system", "content": system})
|
| 43 |
-
messages.append({"role": "user", "content": prompt})
|
| 44 |
-
|
| 45 |
-
deepseek_key = os.environ.get("DEEPSEEK_API_KEY")
|
| 46 |
-
if deepseek_key:
|
| 47 |
-
# DeepSeek API (OpenAI-compat)
|
| 48 |
-
url = "https://api.deepseek.com/v1/chat/completions"
|
| 49 |
-
headers = {
|
| 50 |
-
"Authorization": f"Bearer {deepseek_key}",
|
| 51 |
-
"Content-Type": "application/json",
|
| 52 |
-
}
|
| 53 |
-
payload = {
|
| 54 |
-
"model": "deepseek-reasoner",
|
| 55 |
-
"messages": messages,
|
| 56 |
-
"max_tokens": max_tokens,
|
| 57 |
-
"temperature": temperature,
|
| 58 |
-
}
|
| 59 |
-
else:
|
| 60 |
-
# Fallback: HF Inference API
|
| 61 |
-
hf_token = os.environ.get("HF_TOKEN", "")
|
| 62 |
-
url = "https://api-inference.huggingface.co/v1/chat/completions"
|
| 63 |
-
headers = {
|
| 64 |
-
"Authorization": f"Bearer {hf_token}",
|
| 65 |
-
"Content-Type": "application/json",
|
| 66 |
-
}
|
| 67 |
-
payload = {
|
| 68 |
-
"model": self.MODEL_ID,
|
| 69 |
-
"messages": messages,
|
| 70 |
-
"max_tokens": max_tokens,
|
| 71 |
-
"temperature": temperature,
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 75 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 76 |
-
resp.raise_for_status()
|
| 77 |
-
data = resp.json()
|
| 78 |
-
# Strip <think>...</think> blocks from reasoning output if present
|
| 79 |
-
text = data["choices"][0]["message"]["content"]
|
| 80 |
-
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,76 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
glm_4_6.py — GLM-4.6 voter (Zhipu AI / z.ai).
|
| 8 |
-
|
| 9 |
-
Backend: z.ai (primary) or OpenRouter (secondary).
|
| 10 |
-
Env vars: ZAI_API_KEY or OPENROUTER_API_KEY.
|
| 11 |
-
BFCL #1 function caller. Off by default.
|
| 12 |
-
"""
|
| 13 |
-
from __future__ import annotations
|
| 14 |
-
|
| 15 |
-
import os
|
| 16 |
-
from typing import Any, Optional
|
| 17 |
-
|
| 18 |
-
import httpx
|
| 19 |
-
|
| 20 |
-
from .base_voter import BaseVoter
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
class GLM46Voter(BaseVoter):
|
| 24 |
-
VOTER_ID = "glm-4.6"
|
| 25 |
-
ENV_VARS = ["ZAI_API_KEY", "OPENROUTER_API_KEY"]
|
| 26 |
-
LICENSE = "Open weights"
|
| 27 |
-
PROVIDER = "Zhipu AI (z.ai) / OpenRouter"
|
| 28 |
-
CONTEXT_WINDOW = 131072
|
| 29 |
-
MODEL_ID = "THUDM/GLM-4.6-9B-Chat"
|
| 30 |
-
BFCL_SCORE = "#1"
|
| 31 |
-
|
| 32 |
-
async def _call(
|
| 33 |
-
self,
|
| 34 |
-
prompt: str,
|
| 35 |
-
system: Optional[str] = None,
|
| 36 |
-
max_tokens: int = 512,
|
| 37 |
-
temperature: float = 0.7,
|
| 38 |
-
**kwargs: Any,
|
| 39 |
-
) -> str:
|
| 40 |
-
messages = []
|
| 41 |
-
if system:
|
| 42 |
-
messages.append({"role": "system", "content": system})
|
| 43 |
-
messages.append({"role": "user", "content": prompt})
|
| 44 |
-
|
| 45 |
-
zai_key = os.environ.get("ZAI_API_KEY")
|
| 46 |
-
openrouter_key = os.environ.get("OPENROUTER_API_KEY")
|
| 47 |
-
|
| 48 |
-
if zai_key:
|
| 49 |
-
url = "https://open.bigmodel.cn/api/paas/v4/chat/completions"
|
| 50 |
-
headers = {
|
| 51 |
-
"Authorization": f"Bearer {zai_key}",
|
| 52 |
-
"Content-Type": "application/json",
|
| 53 |
-
}
|
| 54 |
-
model = "glm-4"
|
| 55 |
-
else:
|
| 56 |
-
url = "https://openrouter.ai/api/v1/chat/completions"
|
| 57 |
-
headers = {
|
| 58 |
-
"Authorization": f"Bearer {openrouter_key}",
|
| 59 |
-
"Content-Type": "application/json",
|
| 60 |
-
"HTTP-Referer": "https://szlholdings.com",
|
| 61 |
-
"X-Title": "a11oy-ensemble",
|
| 62 |
-
}
|
| 63 |
-
model = "thudm/glm-4.6-9b"
|
| 64 |
-
|
| 65 |
-
payload = {
|
| 66 |
-
"model": model,
|
| 67 |
-
"messages": messages,
|
| 68 |
-
"max_tokens": max_tokens,
|
| 69 |
-
"temperature": temperature,
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 73 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 74 |
-
resp.raise_for_status()
|
| 75 |
-
data = resp.json()
|
| 76 |
-
return data["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,79 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
hermes_4_405b.py — Hermes-4-405B voter (Nous Research).
|
| 8 |
-
|
| 9 |
-
Backend: Nous Research Portal (primary), OpenRouter (secondary), HF (tertiary).
|
| 10 |
-
Env vars: NOUS_API_KEY or HF_TOKEN.
|
| 11 |
-
Hybrid <think> reasoning + ChatML. Off by default.
|
| 12 |
-
"""
|
| 13 |
-
from __future__ import annotations
|
| 14 |
-
|
| 15 |
-
import os
|
| 16 |
-
import re
|
| 17 |
-
from typing import Any, Optional
|
| 18 |
-
|
| 19 |
-
import httpx
|
| 20 |
-
|
| 21 |
-
from .base_voter import BaseVoter
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
class Hermes4405BVoter(BaseVoter):
|
| 25 |
-
VOTER_ID = "hermes-4-405b"
|
| 26 |
-
ENV_VARS = ["NOUS_API_KEY", "HF_TOKEN"]
|
| 27 |
-
LICENSE = "Open weights (Llama 3.1 base)"
|
| 28 |
-
PROVIDER = "Nous Research / OpenRouter / HuggingFace"
|
| 29 |
-
CONTEXT_WINDOW = 131072
|
| 30 |
-
MODEL_ID = "NousResearch/Hermes-4-405B"
|
| 31 |
-
BFCL_SCORE = None
|
| 32 |
-
|
| 33 |
-
async def _call(
|
| 34 |
-
self,
|
| 35 |
-
prompt: str,
|
| 36 |
-
system: Optional[str] = None,
|
| 37 |
-
max_tokens: int = 512,
|
| 38 |
-
temperature: float = 0.7,
|
| 39 |
-
**kwargs: Any,
|
| 40 |
-
) -> str:
|
| 41 |
-
messages = []
|
| 42 |
-
if system:
|
| 43 |
-
messages.append({"role": "system", "content": system})
|
| 44 |
-
messages.append({"role": "user", "content": prompt})
|
| 45 |
-
|
| 46 |
-
nous_key = os.environ.get("NOUS_API_KEY")
|
| 47 |
-
hf_token = os.environ.get("HF_TOKEN")
|
| 48 |
-
|
| 49 |
-
if nous_key:
|
| 50 |
-
url = "https://inference.nous.systems/v1/chat/completions"
|
| 51 |
-
headers = {
|
| 52 |
-
"Authorization": f"Bearer {nous_key}",
|
| 53 |
-
"Content-Type": "application/json",
|
| 54 |
-
}
|
| 55 |
-
model = "hermes-4-405b"
|
| 56 |
-
else:
|
| 57 |
-
# HF Inference fallback
|
| 58 |
-
url = "https://api-inference.huggingface.co/v1/chat/completions"
|
| 59 |
-
headers = {
|
| 60 |
-
"Authorization": f"Bearer {hf_token}",
|
| 61 |
-
"Content-Type": "application/json",
|
| 62 |
-
}
|
| 63 |
-
model = self.MODEL_ID
|
| 64 |
-
|
| 65 |
-
payload = {
|
| 66 |
-
"model": model,
|
| 67 |
-
"messages": messages,
|
| 68 |
-
"max_tokens": max_tokens,
|
| 69 |
-
"temperature": temperature,
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 73 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 74 |
-
resp.raise_for_status()
|
| 75 |
-
data = resp.json()
|
| 76 |
-
text = data["choices"][0]["message"]["content"]
|
| 77 |
-
# Strip <think>...</think> blocks from hybrid reasoning output
|
| 78 |
-
text = re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL).strip()
|
| 79 |
-
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,82 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
hf_inference_voter.py — Three HF Inference free-tier voters:
|
| 8 |
-
- hf-inference-llama (Meta-Llama-3.1-70B-Instruct)
|
| 9 |
-
- hf-inference-mistral (Mistral-7B-Instruct-v0.3)
|
| 10 |
-
- hf-inference-qwen (Qwen2.5-72B-Instruct via HF)
|
| 11 |
-
|
| 12 |
-
All three use HF_TOKEN. Off by default; activate by including voter_id in
|
| 13 |
-
the `voters` list AND having HF_TOKEN in the env.
|
| 14 |
-
"""
|
| 15 |
-
from __future__ import annotations
|
| 16 |
-
|
| 17 |
-
import os
|
| 18 |
-
from typing import Any, Optional
|
| 19 |
-
|
| 20 |
-
import httpx
|
| 21 |
-
|
| 22 |
-
from .base_voter import BaseVoter
|
| 23 |
-
|
| 24 |
-
HF_INFERENCE_BASE = "https://api-inference.huggingface.co/models"
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
class _HFInferenceBaseVoter(BaseVoter):
|
| 28 |
-
ENV_VARS = ["HF_TOKEN"]
|
| 29 |
-
LICENSE = "various-open"
|
| 30 |
-
PROVIDER = "HuggingFace Inference API"
|
| 31 |
-
BFCL_SCORE = None
|
| 32 |
-
|
| 33 |
-
async def _call(
|
| 34 |
-
self,
|
| 35 |
-
prompt: str,
|
| 36 |
-
system: Optional[str] = None,
|
| 37 |
-
max_tokens: int = 512,
|
| 38 |
-
temperature: float = 0.7,
|
| 39 |
-
**kwargs: Any,
|
| 40 |
-
) -> str:
|
| 41 |
-
token = os.environ.get("HF_TOKEN", "")
|
| 42 |
-
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
| 43 |
-
messages = []
|
| 44 |
-
if system:
|
| 45 |
-
messages.append({"role": "system", "content": system})
|
| 46 |
-
messages.append({"role": "user", "content": prompt})
|
| 47 |
-
payload = {
|
| 48 |
-
"model": self.MODEL_ID,
|
| 49 |
-
"messages": messages,
|
| 50 |
-
"max_tokens": max_tokens,
|
| 51 |
-
"temperature": temperature,
|
| 52 |
-
}
|
| 53 |
-
url = "https://api-inference.huggingface.co/v1/chat/completions"
|
| 54 |
-
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 55 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 56 |
-
resp.raise_for_status()
|
| 57 |
-
data = resp.json()
|
| 58 |
-
return data["choices"][0]["message"]["content"]
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
class HFInferenceLlamaVoter(_HFInferenceBaseVoter):
|
| 62 |
-
VOTER_ID = "hf-inference-llama"
|
| 63 |
-
LICENSE = "Llama 3 Community"
|
| 64 |
-
PROVIDER = "HuggingFace Inference API (Meta-Llama)"
|
| 65 |
-
CONTEXT_WINDOW = 131072
|
| 66 |
-
MODEL_ID = "meta-llama/Meta-Llama-3.1-70B-Instruct"
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
class HFInferenceMistralVoter(_HFInferenceBaseVoter):
|
| 70 |
-
VOTER_ID = "hf-inference-mistral"
|
| 71 |
-
LICENSE = "Apache-2.0"
|
| 72 |
-
PROVIDER = "HuggingFace Inference API (Mistral)"
|
| 73 |
-
CONTEXT_WINDOW = 32768
|
| 74 |
-
MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.3"
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
class HFInferenceQwenVoter(_HFInferenceBaseVoter):
|
| 78 |
-
VOTER_ID = "hf-inference-qwen"
|
| 79 |
-
LICENSE = "Apache-2.0"
|
| 80 |
-
PROVIDER = "HuggingFace Inference API (Qwen)"
|
| 81 |
-
CONTEXT_WINDOW = 131072
|
| 82 |
-
MODEL_ID = "Qwen/Qwen2.5-72B-Instruct"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,77 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
kimi_k2.py — Kimi K2 voter (Moonshot AI).
|
| 8 |
-
|
| 9 |
-
Backend: Moonshot API (primary) or OpenRouter (secondary).
|
| 10 |
-
Env vars: MOONSHOT_API_KEY or OPENROUTER_API_KEY.
|
| 11 |
-
200k+ context window, top-tier tool calling.
|
| 12 |
-
Off by default — activate by listing "kimi-k2" in voters.
|
| 13 |
-
"""
|
| 14 |
-
from __future__ import annotations
|
| 15 |
-
|
| 16 |
-
import os
|
| 17 |
-
from typing import Any, Optional
|
| 18 |
-
|
| 19 |
-
import httpx
|
| 20 |
-
|
| 21 |
-
from .base_voter import BaseVoter
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
class KimiK2Voter(BaseVoter):
|
| 25 |
-
VOTER_ID = "kimi-k2"
|
| 26 |
-
ENV_VARS = ["MOONSHOT_API_KEY", "OPENROUTER_API_KEY"]
|
| 27 |
-
LICENSE = "Open weights"
|
| 28 |
-
PROVIDER = "Moonshot AI / OpenRouter"
|
| 29 |
-
CONTEXT_WINDOW = 200000
|
| 30 |
-
MODEL_ID = "moonshot-ai/kimi-k2"
|
| 31 |
-
BFCL_SCORE = None
|
| 32 |
-
|
| 33 |
-
async def _call(
|
| 34 |
-
self,
|
| 35 |
-
prompt: str,
|
| 36 |
-
system: Optional[str] = None,
|
| 37 |
-
max_tokens: int = 512,
|
| 38 |
-
temperature: float = 0.7,
|
| 39 |
-
**kwargs: Any,
|
| 40 |
-
) -> str:
|
| 41 |
-
messages = []
|
| 42 |
-
if system:
|
| 43 |
-
messages.append({"role": "system", "content": system})
|
| 44 |
-
messages.append({"role": "user", "content": prompt})
|
| 45 |
-
|
| 46 |
-
moonshot_key = os.environ.get("MOONSHOT_API_KEY")
|
| 47 |
-
openrouter_key = os.environ.get("OPENROUTER_API_KEY")
|
| 48 |
-
|
| 49 |
-
if moonshot_key:
|
| 50 |
-
url = "https://api.moonshot.cn/v1/chat/completions"
|
| 51 |
-
headers = {
|
| 52 |
-
"Authorization": f"Bearer {moonshot_key}",
|
| 53 |
-
"Content-Type": "application/json",
|
| 54 |
-
}
|
| 55 |
-
model = "kimi-k2-0711-preview"
|
| 56 |
-
else:
|
| 57 |
-
url = "https://openrouter.ai/api/v1/chat/completions"
|
| 58 |
-
headers = {
|
| 59 |
-
"Authorization": f"Bearer {openrouter_key}",
|
| 60 |
-
"Content-Type": "application/json",
|
| 61 |
-
"HTTP-Referer": "https://szlholdings.com",
|
| 62 |
-
"X-Title": "a11oy-ensemble",
|
| 63 |
-
}
|
| 64 |
-
model = "moonshotai/kimi-k2"
|
| 65 |
-
|
| 66 |
-
payload = {
|
| 67 |
-
"model": model,
|
| 68 |
-
"messages": messages,
|
| 69 |
-
"max_tokens": max_tokens,
|
| 70 |
-
"temperature": temperature,
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 74 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 75 |
-
resp.raise_for_status()
|
| 76 |
-
data = resp.json()
|
| 77 |
-
return data["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,76 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
minimax_m2.py — MiniMax-M2 voter.
|
| 8 |
-
|
| 9 |
-
Backend: MiniMax API (primary) or OpenRouter (secondary).
|
| 10 |
-
Env vars: MINIMAX_API_KEY or OPENROUTER_API_KEY.
|
| 11 |
-
1M context window. Off by default.
|
| 12 |
-
"""
|
| 13 |
-
from __future__ import annotations
|
| 14 |
-
|
| 15 |
-
import os
|
| 16 |
-
from typing import Any, Optional
|
| 17 |
-
|
| 18 |
-
import httpx
|
| 19 |
-
|
| 20 |
-
from .base_voter import BaseVoter
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
class MiniMaxM2Voter(BaseVoter):
|
| 24 |
-
VOTER_ID = "minimax-m2"
|
| 25 |
-
ENV_VARS = ["MINIMAX_API_KEY", "OPENROUTER_API_KEY"]
|
| 26 |
-
LICENSE = "Open weights"
|
| 27 |
-
PROVIDER = "MiniMax / OpenRouter"
|
| 28 |
-
CONTEXT_WINDOW = 1000000
|
| 29 |
-
MODEL_ID = "MiniMaxAI/MiniMax-M2"
|
| 30 |
-
BFCL_SCORE = None
|
| 31 |
-
|
| 32 |
-
async def _call(
|
| 33 |
-
self,
|
| 34 |
-
prompt: str,
|
| 35 |
-
system: Optional[str] = None,
|
| 36 |
-
max_tokens: int = 512,
|
| 37 |
-
temperature: float = 0.7,
|
| 38 |
-
**kwargs: Any,
|
| 39 |
-
) -> str:
|
| 40 |
-
messages = []
|
| 41 |
-
if system:
|
| 42 |
-
messages.append({"role": "system", "content": system})
|
| 43 |
-
messages.append({"role": "user", "content": prompt})
|
| 44 |
-
|
| 45 |
-
minimax_key = os.environ.get("MINIMAX_API_KEY")
|
| 46 |
-
openrouter_key = os.environ.get("OPENROUTER_API_KEY")
|
| 47 |
-
|
| 48 |
-
if minimax_key:
|
| 49 |
-
url = "https://api.minimax.chat/v1/text/chatcompletion_v2"
|
| 50 |
-
headers = {
|
| 51 |
-
"Authorization": f"Bearer {minimax_key}",
|
| 52 |
-
"Content-Type": "application/json",
|
| 53 |
-
}
|
| 54 |
-
model = "MiniMax-M2"
|
| 55 |
-
else:
|
| 56 |
-
url = "https://openrouter.ai/api/v1/chat/completions"
|
| 57 |
-
headers = {
|
| 58 |
-
"Authorization": f"Bearer {openrouter_key}",
|
| 59 |
-
"Content-Type": "application/json",
|
| 60 |
-
"HTTP-Referer": "https://szlholdings.com",
|
| 61 |
-
"X-Title": "a11oy-ensemble",
|
| 62 |
-
}
|
| 63 |
-
model = "minimax/minimax-m2"
|
| 64 |
-
|
| 65 |
-
payload = {
|
| 66 |
-
"model": model,
|
| 67 |
-
"messages": messages,
|
| 68 |
-
"max_tokens": max_tokens,
|
| 69 |
-
"temperature": temperature,
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 73 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 74 |
-
resp.raise_for_status()
|
| 75 |
-
data = resp.json()
|
| 76 |
-
return data["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,64 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
nemotron_super_49b.py — Nemotron-Super-49B voter (NVIDIA NIM).
|
| 8 |
-
|
| 9 |
-
Backend: NVIDIA NIM API exclusively.
|
| 10 |
-
Env var: NVIDIA_API_KEY.
|
| 11 |
-
NVIDIA-optimized, "Palantir-class" reasoning. Off by default.
|
| 12 |
-
"""
|
| 13 |
-
from __future__ import annotations
|
| 14 |
-
|
| 15 |
-
import os
|
| 16 |
-
from typing import Any, Optional
|
| 17 |
-
|
| 18 |
-
import httpx
|
| 19 |
-
|
| 20 |
-
from .base_voter import BaseVoter
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
class NemotronSuper49BVoter(BaseVoter):
|
| 24 |
-
VOTER_ID = "nemotron-super-49b"
|
| 25 |
-
ENV_VARS = ["NVIDIA_API_KEY"]
|
| 26 |
-
LICENSE = "NVIDIA Open Model License"
|
| 27 |
-
PROVIDER = "NVIDIA NIM"
|
| 28 |
-
CONTEXT_WINDOW = 131072
|
| 29 |
-
MODEL_ID = "nvidia/llama-3.3-nemotron-super-49b-v1"
|
| 30 |
-
BFCL_SCORE = None
|
| 31 |
-
|
| 32 |
-
async def _call(
|
| 33 |
-
self,
|
| 34 |
-
prompt: str,
|
| 35 |
-
system: Optional[str] = None,
|
| 36 |
-
max_tokens: int = 512,
|
| 37 |
-
temperature: float = 0.7,
|
| 38 |
-
**kwargs: Any,
|
| 39 |
-
) -> str:
|
| 40 |
-
messages = []
|
| 41 |
-
if system:
|
| 42 |
-
messages.append({"role": "system", "content": system})
|
| 43 |
-
messages.append({"role": "user", "content": prompt})
|
| 44 |
-
|
| 45 |
-
nvidia_key = os.environ.get("NVIDIA_API_KEY", "")
|
| 46 |
-
|
| 47 |
-
url = "https://integrate.api.nvidia.com/v1/chat/completions"
|
| 48 |
-
headers = {
|
| 49 |
-
"Authorization": f"Bearer {nvidia_key}",
|
| 50 |
-
"Content-Type": "application/json",
|
| 51 |
-
}
|
| 52 |
-
payload = {
|
| 53 |
-
"model": self.MODEL_ID,
|
| 54 |
-
"messages": messages,
|
| 55 |
-
"max_tokens": max_tokens,
|
| 56 |
-
"temperature": temperature,
|
| 57 |
-
"stream": False,
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 61 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 62 |
-
resp.raise_for_status()
|
| 63 |
-
data = resp.json()
|
| 64 |
-
return data["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
nomos_1.py — Nomos-1 voter (Nous Research).
|
| 8 |
-
|
| 9 |
-
Backend: Nous Research Portal (primary) or HF Inference (secondary).
|
| 10 |
-
Env vars: NOUS_API_KEY or HF_TOKEN.
|
| 11 |
-
30B SOTA mathematician — critical for Lean kernel work.
|
| 12 |
-
Off by default.
|
| 13 |
-
"""
|
| 14 |
-
from __future__ import annotations
|
| 15 |
-
|
| 16 |
-
import os
|
| 17 |
-
from typing import Any, Optional
|
| 18 |
-
|
| 19 |
-
import httpx
|
| 20 |
-
|
| 21 |
-
from .base_voter import BaseVoter
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
class Nomos1Voter(BaseVoter):
|
| 25 |
-
VOTER_ID = "nomos-1"
|
| 26 |
-
ENV_VARS = ["NOUS_API_KEY", "HF_TOKEN"]
|
| 27 |
-
LICENSE = "Open weights"
|
| 28 |
-
PROVIDER = "Nous Research / HuggingFace"
|
| 29 |
-
CONTEXT_WINDOW = 32768
|
| 30 |
-
MODEL_ID = "NousResearch/Nomos-1-30B"
|
| 31 |
-
BFCL_SCORE = None
|
| 32 |
-
|
| 33 |
-
async def _call(
|
| 34 |
-
self,
|
| 35 |
-
prompt: str,
|
| 36 |
-
system: Optional[str] = None,
|
| 37 |
-
max_tokens: int = 512,
|
| 38 |
-
temperature: float = 0.7,
|
| 39 |
-
**kwargs: Any,
|
| 40 |
-
) -> str:
|
| 41 |
-
messages = []
|
| 42 |
-
if system:
|
| 43 |
-
messages.append({"role": "system", "content": system})
|
| 44 |
-
messages.append({"role": "user", "content": prompt})
|
| 45 |
-
|
| 46 |
-
nous_key = os.environ.get("NOUS_API_KEY")
|
| 47 |
-
hf_token = os.environ.get("HF_TOKEN")
|
| 48 |
-
|
| 49 |
-
if nous_key:
|
| 50 |
-
url = "https://inference.nous.systems/v1/chat/completions"
|
| 51 |
-
headers = {
|
| 52 |
-
"Authorization": f"Bearer {nous_key}",
|
| 53 |
-
"Content-Type": "application/json",
|
| 54 |
-
}
|
| 55 |
-
model = "nomos-1"
|
| 56 |
-
else:
|
| 57 |
-
url = "https://api-inference.huggingface.co/v1/chat/completions"
|
| 58 |
-
headers = {
|
| 59 |
-
"Authorization": f"Bearer {hf_token}",
|
| 60 |
-
"Content-Type": "application/json",
|
| 61 |
-
}
|
| 62 |
-
model = self.MODEL_ID
|
| 63 |
-
|
| 64 |
-
payload = {
|
| 65 |
-
"model": model,
|
| 66 |
-
"messages": messages,
|
| 67 |
-
"max_tokens": max_tokens,
|
| 68 |
-
"temperature": temperature,
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 72 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 73 |
-
resp.raise_for_status()
|
| 74 |
-
data = resp.json()
|
| 75 |
-
return data["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,73 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
qwen_local.py — SOVEREIGN DEFAULT voter.
|
| 8 |
-
|
| 9 |
-
Qwen-local is the floor: it ALWAYS participates regardless of any env var.
|
| 10 |
-
When the local vLLM endpoint is unreachable it degrades to a clearly-labelled
|
| 11 |
-
deterministic stub — never a hallucinated completion.
|
| 12 |
-
|
| 13 |
-
Sovereign-default: qwen-local is ALWAYS in the voter pool. The aggregator may
|
| 14 |
-
receive a stub response, but it never gets silence from the sovereign floor.
|
| 15 |
-
"""
|
| 16 |
-
from __future__ import annotations
|
| 17 |
-
|
| 18 |
-
import os
|
| 19 |
-
from typing import Any, Optional
|
| 20 |
-
|
| 21 |
-
import httpx
|
| 22 |
-
|
| 23 |
-
from .base_voter import BaseVoter
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
class QwenLocalVoter(BaseVoter):
|
| 27 |
-
VOTER_ID = "qwen-local"
|
| 28 |
-
ENV_VARS = [] # No env var required — sovereign default
|
| 29 |
-
LICENSE = "Apache-2.0"
|
| 30 |
-
PROVIDER = "local-vLLM"
|
| 31 |
-
CONTEXT_WINDOW = 32768
|
| 32 |
-
MODEL_ID = "Qwen/Qwen2.5-72B-Instruct"
|
| 33 |
-
BFCL_SCORE = None
|
| 34 |
-
|
| 35 |
-
# Sovereign-default: always available
|
| 36 |
-
def is_available(self) -> bool:
|
| 37 |
-
return True
|
| 38 |
-
|
| 39 |
-
def _active_env_var(self):
|
| 40 |
-
return None # No env var needed
|
| 41 |
-
|
| 42 |
-
async def _call(
|
| 43 |
-
self,
|
| 44 |
-
prompt: str,
|
| 45 |
-
system: Optional[str] = None,
|
| 46 |
-
max_tokens: int = 512,
|
| 47 |
-
temperature: float = 0.7,
|
| 48 |
-
**kwargs: Any,
|
| 49 |
-
) -> str:
|
| 50 |
-
vllm_url = os.environ.get("QWEN_LOCAL_URL", "http://127.0.0.1:8000/v1/chat/completions")
|
| 51 |
-
messages = []
|
| 52 |
-
if system:
|
| 53 |
-
messages.append({"role": "system", "content": system})
|
| 54 |
-
messages.append({"role": "user", "content": prompt})
|
| 55 |
-
payload = {
|
| 56 |
-
"model": self.MODEL_ID,
|
| 57 |
-
"messages": messages,
|
| 58 |
-
"max_tokens": max_tokens,
|
| 59 |
-
"temperature": temperature,
|
| 60 |
-
}
|
| 61 |
-
try:
|
| 62 |
-
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 63 |
-
resp = await client.post(vllm_url, json=payload)
|
| 64 |
-
resp.raise_for_status()
|
| 65 |
-
data = resp.json()
|
| 66 |
-
return data["choices"][0]["message"]["content"]
|
| 67 |
-
except Exception:
|
| 68 |
-
# Sovereign-default stub — clearly labelled, never fabricated
|
| 69 |
-
return (
|
| 70 |
-
f"[qwen-local · STUB · local vLLM unreachable] "
|
| 71 |
-
f"Deterministic stub response for: {prompt[:80]!r}. "
|
| 72 |
-
f"Deploy a local vLLM serving {self.MODEL_ID} at QWEN_LOCAL_URL to enable real inference."
|
| 73 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,76 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
step_3_7_flash.py — Step-3.7-Flash voter (StepFun / 阶跃星辰).
|
| 8 |
-
|
| 9 |
-
Backend: StepFun API (primary) or OpenRouter (secondary).
|
| 10 |
-
Env vars: STEPFUN_API_KEY or OPENROUTER_API_KEY.
|
| 11 |
-
198B MoE vision-language model. Off by default.
|
| 12 |
-
"""
|
| 13 |
-
from __future__ import annotations
|
| 14 |
-
|
| 15 |
-
import os
|
| 16 |
-
from typing import Any, Optional
|
| 17 |
-
|
| 18 |
-
import httpx
|
| 19 |
-
|
| 20 |
-
from .base_voter import BaseVoter
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
class Step37FlashVoter(BaseVoter):
|
| 24 |
-
VOTER_ID = "step-3.7-flash"
|
| 25 |
-
ENV_VARS = ["STEPFUN_API_KEY", "OPENROUTER_API_KEY"]
|
| 26 |
-
LICENSE = "Open weights"
|
| 27 |
-
PROVIDER = "StepFun / OpenRouter"
|
| 28 |
-
CONTEXT_WINDOW = 32768
|
| 29 |
-
MODEL_ID = "stepfun-ai/step-3.7-flash"
|
| 30 |
-
BFCL_SCORE = None
|
| 31 |
-
|
| 32 |
-
async def _call(
|
| 33 |
-
self,
|
| 34 |
-
prompt: str,
|
| 35 |
-
system: Optional[str] = None,
|
| 36 |
-
max_tokens: int = 512,
|
| 37 |
-
temperature: float = 0.7,
|
| 38 |
-
**kwargs: Any,
|
| 39 |
-
) -> str:
|
| 40 |
-
messages = []
|
| 41 |
-
if system:
|
| 42 |
-
messages.append({"role": "system", "content": system})
|
| 43 |
-
messages.append({"role": "user", "content": prompt})
|
| 44 |
-
|
| 45 |
-
stepfun_key = os.environ.get("STEPFUN_API_KEY")
|
| 46 |
-
openrouter_key = os.environ.get("OPENROUTER_API_KEY")
|
| 47 |
-
|
| 48 |
-
if stepfun_key:
|
| 49 |
-
url = "https://api.stepfun.com/v1/chat/completions"
|
| 50 |
-
headers = {
|
| 51 |
-
"Authorization": f"Bearer {stepfun_key}",
|
| 52 |
-
"Content-Type": "application/json",
|
| 53 |
-
}
|
| 54 |
-
model = "step-3-7b-flash"
|
| 55 |
-
else:
|
| 56 |
-
url = "https://openrouter.ai/api/v1/chat/completions"
|
| 57 |
-
headers = {
|
| 58 |
-
"Authorization": f"Bearer {openrouter_key}",
|
| 59 |
-
"Content-Type": "application/json",
|
| 60 |
-
"HTTP-Referer": "https://szlholdings.com",
|
| 61 |
-
"X-Title": "a11oy-ensemble",
|
| 62 |
-
}
|
| 63 |
-
model = "stepfun-ai/step-3-7b-flash"
|
| 64 |
-
|
| 65 |
-
payload = {
|
| 66 |
-
"model": model,
|
| 67 |
-
"messages": messages,
|
| 68 |
-
"max_tokens": max_tokens,
|
| 69 |
-
"temperature": temperature,
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 73 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 74 |
-
resp.raise_for_status()
|
| 75 |
-
data = resp.json()
|
| 76 |
-
return data["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,76 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO).
|
| 4 |
-
# DCO: Signed-off-by: Yachay <yachay@szlholdings.dev>
|
| 5 |
-
# Co-Authored-By: Perplexity Computer Agent
|
| 6 |
-
"""
|
| 7 |
-
xiaomi_mimo.py — Xiaomi MiMo voter.
|
| 8 |
-
|
| 9 |
-
Backend: Nous Research Portal (primary) or direct Xiaomi endpoint (secondary).
|
| 10 |
-
Env vars: XIAOMI_API_KEY or NOUS_API_KEY.
|
| 11 |
-
Strong Chinese model. Off by default.
|
| 12 |
-
"""
|
| 13 |
-
from __future__ import annotations
|
| 14 |
-
|
| 15 |
-
import os
|
| 16 |
-
from typing import Any, Optional
|
| 17 |
-
|
| 18 |
-
import httpx
|
| 19 |
-
|
| 20 |
-
from .base_voter import BaseVoter
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
class XiaomiMiMoVoter(BaseVoter):
|
| 24 |
-
VOTER_ID = "xiaomi-mimo"
|
| 25 |
-
ENV_VARS = ["XIAOMI_API_KEY", "NOUS_API_KEY"]
|
| 26 |
-
LICENSE = "Open weights (Apache-2.0)"
|
| 27 |
-
PROVIDER = "Nous Research / Xiaomi direct"
|
| 28 |
-
CONTEXT_WINDOW = 131072
|
| 29 |
-
MODEL_ID = "XiaomiMiMo/MiMo-7B-RL"
|
| 30 |
-
BFCL_SCORE = None
|
| 31 |
-
|
| 32 |
-
async def _call(
|
| 33 |
-
self,
|
| 34 |
-
prompt: str,
|
| 35 |
-
system: Optional[str] = None,
|
| 36 |
-
max_tokens: int = 512,
|
| 37 |
-
temperature: float = 0.7,
|
| 38 |
-
**kwargs: Any,
|
| 39 |
-
) -> str:
|
| 40 |
-
messages = []
|
| 41 |
-
if system:
|
| 42 |
-
messages.append({"role": "system", "content": system})
|
| 43 |
-
messages.append({"role": "user", "content": prompt})
|
| 44 |
-
|
| 45 |
-
xiaomi_key = os.environ.get("XIAOMI_API_KEY")
|
| 46 |
-
nous_key = os.environ.get("NOUS_API_KEY")
|
| 47 |
-
|
| 48 |
-
if xiaomi_key:
|
| 49 |
-
# Xiaomi direct API (OpenAI-compat)
|
| 50 |
-
url = "https://api.xiaomi-mimo.com/v1/chat/completions"
|
| 51 |
-
headers = {
|
| 52 |
-
"Authorization": f"Bearer {xiaomi_key}",
|
| 53 |
-
"Content-Type": "application/json",
|
| 54 |
-
}
|
| 55 |
-
model = "mimo-7b-rl"
|
| 56 |
-
else:
|
| 57 |
-
# Nous Portal fallback
|
| 58 |
-
url = "https://inference.nous.systems/v1/chat/completions"
|
| 59 |
-
headers = {
|
| 60 |
-
"Authorization": f"Bearer {nous_key}",
|
| 61 |
-
"Content-Type": "application/json",
|
| 62 |
-
}
|
| 63 |
-
model = "xiaomi-mimo-7b"
|
| 64 |
-
|
| 65 |
-
payload = {
|
| 66 |
-
"model": model,
|
| 67 |
-
"messages": messages,
|
| 68 |
-
"max_tokens": max_tokens,
|
| 69 |
-
"temperature": temperature,
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 73 |
-
resp = await client.post(url, json=payload, headers=headers)
|
| 74 |
-
resp.raise_for_status()
|
| 75 |
-
data = resp.json()
|
| 76 |
-
return data["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,88 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0 · Doctrine v12 (additive). Yachay.
|
| 2 |
-
"""
|
| 3 |
-
status_feed — internal health -> public status_feed.json (fail-closed allow-list).
|
| 4 |
-
Reads Prometheus + active Alertmanager alerts + degradation receipts; emits ONLY the
|
| 5 |
-
szl.status_feed/v1 schema. Anything not explicitly mapped is dropped (never leaked).
|
| 6 |
-
|
| 7 |
-
Honest anti-cover-up: driven by the SAME Prometheus signals as the internal dashboard,
|
| 8 |
-
so the public page can never claim green while internally red. v11 LOCKED untouched.
|
| 9 |
-
"""
|
| 10 |
-
from datetime import datetime, timezone
|
| 11 |
-
|
| 12 |
-
# allow-list: internal flagship -> public component
|
| 13 |
-
PUBLIC_COMPONENT = {
|
| 14 |
-
"a11oy": "Governance & Brand", "amaru": "Memory / Cortex",
|
| 15 |
-
"sentra": "Immune / Policy", "vessels": "Maritime & Receipts",
|
| 16 |
-
"rosie": "Companion", "killinchu": "Drone Ops",
|
| 17 |
-
"lean-kernel": "Proof Kernel",
|
| 18 |
-
}
|
| 19 |
-
# Keys that MUST NEVER appear in the public feed (defense in depth; allow-list already
|
| 20 |
-
# drops them). We match on KEY NAMES (not a substring of the whole blob) so legitimate
|
| 21 |
-
# component copy like "Receipts"/"Companion" is never falsely flagged.
|
| 22 |
-
_NEVER_PUBLISH_KEYS = frozenset({
|
| 23 |
-
"provider", "model", "tripwire", "khipu_node", "digest",
|
| 24 |
-
"hostname", "ip", "secret", "token", "breaker", "circuit",
|
| 25 |
-
})
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def _coarse_status(up: bool, degraded: bool, partial: bool) -> str:
|
| 29 |
-
if not up: return "major_outage"
|
| 30 |
-
if partial: return "partial_outage"
|
| 31 |
-
if degraded: return "degraded"
|
| 32 |
-
return "operational"
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
def build_feed(metrics: dict, alerts: list[dict]) -> dict:
|
| 36 |
-
components = []
|
| 37 |
-
for fl, comp in PUBLIC_COMPONENT.items():
|
| 38 |
-
up = metrics.get(f"szl_up::{fl}", 0) == 1
|
| 39 |
-
degraded = any(a for a in alerts
|
| 40 |
-
if a.get("flagship") == fl and a.get("impact") == "degraded")
|
| 41 |
-
components.append({
|
| 42 |
-
"name": comp,
|
| 43 |
-
"status": _coarse_status(up, degraded, partial=False),
|
| 44 |
-
"uptime_30d": round(metrics.get(f"szl_uptime_30d::{fl}", 0.0), 2),
|
| 45 |
-
})
|
| 46 |
-
# AI Responses component derived from router tiers (impact only, no provider names)
|
| 47 |
-
router_degraded = (metrics.get("szl_router_tier::T0_cache", 0)
|
| 48 |
-
+ metrics.get("szl_router_tier::T1_small", 0)) > 0
|
| 49 |
-
components.append({"name": "AI Responses",
|
| 50 |
-
"status": "degraded" if router_degraded else "operational",
|
| 51 |
-
"note": "Responses may be slower than usual." if router_degraded else None})
|
| 52 |
-
|
| 53 |
-
overall = "operational"
|
| 54 |
-
if any(c["status"] == "major_outage" for c in components): overall = "major_outage"
|
| 55 |
-
elif any(c["status"] == "partial_outage" for c in components): overall = "partial_outage"
|
| 56 |
-
elif any(c["status"] == "degraded" for c in components): overall = "degraded"
|
| 57 |
-
|
| 58 |
-
feed = {"schema": "szl.status_feed/v1",
|
| 59 |
-
"generated_at": datetime.now(timezone.utc).isoformat(),
|
| 60 |
-
"overall": overall, "components": components,
|
| 61 |
-
"active_incidents": _public_incidents(alerts),
|
| 62 |
-
"scheduled_maintenance": []}
|
| 63 |
-
_assert_no_leak(feed) # fail-closed: refuse to emit if any banned key present
|
| 64 |
-
return feed
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
def _public_incidents(alerts):
|
| 68 |
-
out = []
|
| 69 |
-
for a in alerts:
|
| 70 |
-
if not a.get("customer_impacting"): # only customer-impacting alerts go public
|
| 71 |
-
continue
|
| 72 |
-
out.append({"id": a["incident_id"], "title": a["public_title"], # pre-sanitized
|
| 73 |
-
"impact": a["impact"], "started_at": a["started_at"],
|
| 74 |
-
"latest_update": a["public_update"]})
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
def _assert_no_leak(node) -> None:
|
| 79 |
-
"""Recursively assert no banned KEY appears anywhere in the feed (fail-closed)."""
|
| 80 |
-
if isinstance(node, dict):
|
| 81 |
-
for k, v in node.items():
|
| 82 |
-
if str(k).lower() in _NEVER_PUBLISH_KEYS:
|
| 83 |
-
raise RuntimeError(
|
| 84 |
-
f"status_feed leak guard tripped on key '{k}' — refusing to publish")
|
| 85 |
-
_assert_no_leak(v)
|
| 86 |
-
elif isinstance(node, (list, tuple)):
|
| 87 |
-
for item in node:
|
| 88 |
-
_assert_no_leak(item)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,129 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 SZL Holdings · Doctrine v12 (additive over v11 LOCKED). Yachay.
|
| 3 |
-
"""
|
| 4 |
-
szl_breaker — Hystrix-style circuit breakers for every external SZL call.
|
| 5 |
-
|
| 6 |
-
pybreaker = state machine (CLOSED/OPEN/HALF-OPEN).
|
| 7 |
-
tenacity = bounded retry w/ exponential backoff + full jitter.
|
| 8 |
-
We add: per-call timeout, named fallback, and a Khipu degradation receipt
|
| 9 |
-
on every OPEN transition and every fallback execution.
|
| 10 |
-
|
| 11 |
-
ADDITIVE only: this wraps calls; it never alters the 13-axis Yuyay gate, the
|
| 12 |
-
Lambda aggregator, or any LOCKED number (749/14/163, replay-hash bacf5443…631fc5).
|
| 13 |
-
|
| 14 |
-
HONEST: receipt signature is DSSE PLACEHOLDER (Sigstore CI not wired, v11 §9).
|
| 15 |
-
Khipu DAG ingest reuses szl_wire.ingest_receipt (in-memory ring + S3 mirror).
|
| 16 |
-
"""
|
| 17 |
-
from __future__ import annotations
|
| 18 |
-
|
| 19 |
-
import functools
|
| 20 |
-
from concurrent.futures import ThreadPoolExecutor
|
| 21 |
-
from concurrent.futures import TimeoutError as FutureTimeout
|
| 22 |
-
from datetime import datetime, timezone
|
| 23 |
-
from typing import Any, Callable
|
| 24 |
-
|
| 25 |
-
import pybreaker
|
| 26 |
-
from tenacity import (
|
| 27 |
-
retry,
|
| 28 |
-
retry_if_exception_type,
|
| 29 |
-
stop_after_attempt,
|
| 30 |
-
wait_exponential_jitter,
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
try:
|
| 34 |
-
from szl_wire import SIGNATURE_PLACEHOLDER, ingest_receipt # reuse the live DAG
|
| 35 |
-
except Exception: # edge / standalone import
|
| 36 |
-
SIGNATURE_PLACEHOLDER = "PLACEHOLDER — Sigstore CI not wired (Doctrine v12)"
|
| 37 |
-
def ingest_receipt(receipt: dict) -> dict: # local fallback writer
|
| 38 |
-
return {"receipt": receipt, "note": "local-only ingest (no szl_wire)"}
|
| 39 |
-
|
| 40 |
-
_POOL = ThreadPoolExecutor(max_workers=16)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
def _emit_degradation(breaker_name: str, flagship: str, failure_mode: str,
|
| 44 |
-
fallback_tier: str, state: str, traceparent: str | None) -> None:
|
| 45 |
-
"""Append a szl.degradation.receipt/v1 to the canonical Khipu DAG (RUWAY-only path)."""
|
| 46 |
-
ingest_receipt({
|
| 47 |
-
"schema": "szl.degradation.receipt/v1",
|
| 48 |
-
"event_id": f"deg-{datetime.now(timezone.utc).isoformat()}-{flagship}-{breaker_name}",
|
| 49 |
-
"flagship": flagship,
|
| 50 |
-
"failure_mode": failure_mode,
|
| 51 |
-
"circuit": breaker_name,
|
| 52 |
-
"breaker_state": state,
|
| 53 |
-
"fallback_tier_served": fallback_tier,
|
| 54 |
-
"detected_at": datetime.now(timezone.utc).isoformat(),
|
| 55 |
-
"user_visible": True,
|
| 56 |
-
"traceparent": traceparent,
|
| 57 |
-
"doctrine": "v12",
|
| 58 |
-
"dsse": {"sig": SIGNATURE_PLACEHOLDER, "keyid": "PENDING"},
|
| 59 |
-
})
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
class KhipuListener(pybreaker.CircuitBreakerListener):
|
| 63 |
-
"""Emit a Khipu receipt on every breaker state transition (honest audit trail)."""
|
| 64 |
-
def __init__(self, name: str, flagship: str, failure_mode: str, fallback_tier: str):
|
| 65 |
-
self.name, self.flagship = name, flagship
|
| 66 |
-
self.failure_mode, self.fallback_tier = failure_mode, fallback_tier
|
| 67 |
-
def state_change(self, cb, old, new):
|
| 68 |
-
_emit_degradation(self.name, self.flagship, self.failure_mode,
|
| 69 |
-
self.fallback_tier, str(new.name).upper(), None)
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
def make_breaker(name: str, flagship: str, failure_mode: str, fallback_tier: str,
|
| 73 |
-
fail_max: int = 5, reset_timeout_s: int = 15) -> pybreaker.CircuitBreaker:
|
| 74 |
-
return pybreaker.CircuitBreaker(
|
| 75 |
-
fail_max=fail_max,
|
| 76 |
-
reset_timeout=reset_timeout_s,
|
| 77 |
-
listeners=[KhipuListener(name, flagship, failure_mode, fallback_tier)],
|
| 78 |
-
name=name,
|
| 79 |
-
)
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
def guarded_call(breaker: pybreaker.CircuitBreaker, *, flagship: str, failure_mode: str,
|
| 83 |
-
fallback_tier: str, timeout_s: float, retry_budget: int,
|
| 84 |
-
fallback: Callable[[], Any], traceparent: str | None = None):
|
| 85 |
-
"""
|
| 86 |
-
Decorator: wraps an external call with breaker + timeout + bounded retry + fallback.
|
| 87 |
-
On OPEN (short-circuit) or exhausted retries, runs `fallback` and emits a Khipu receipt.
|
| 88 |
-
"""
|
| 89 |
-
def deco(fn: Callable[..., Any]) -> Callable[..., Any]:
|
| 90 |
-
@retry(stop=stop_after_attempt(max(1, retry_budget + 1)),
|
| 91 |
-
wait=wait_exponential_jitter(initial=1, max=300),
|
| 92 |
-
retry=retry_if_exception_type(Exception), reraise=True)
|
| 93 |
-
def _attempt(*a, **k):
|
| 94 |
-
fut = _POOL.submit(fn, *a, **k)
|
| 95 |
-
try:
|
| 96 |
-
return fut.result(timeout=timeout_s) # per-call hard timeout
|
| 97 |
-
except FutureTimeout:
|
| 98 |
-
raise TimeoutError(f"{breaker.name} exceeded {timeout_s}s")
|
| 99 |
-
|
| 100 |
-
@functools.wraps(fn)
|
| 101 |
-
def wrapper(*a, **k):
|
| 102 |
-
try:
|
| 103 |
-
return breaker.call(_attempt, *a, **k) # breaker tracks success/fail
|
| 104 |
-
except pybreaker.CircuitBreakerError: # OPEN → short-circuit
|
| 105 |
-
_emit_degradation(breaker.name, flagship, failure_mode,
|
| 106 |
-
fallback_tier, "OPEN", traceparent)
|
| 107 |
-
return fallback()
|
| 108 |
-
except Exception: # retries exhausted
|
| 109 |
-
_emit_degradation(breaker.name, flagship, failure_mode,
|
| 110 |
-
fallback_tier, "FALLBACK", traceparent)
|
| 111 |
-
return fallback()
|
| 112 |
-
return wrapper
|
| 113 |
-
return deco
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
# Breaker registry helper (names match OBSERVABILITY_DASHBOARD §3 + CIRCUIT_BREAKER_LAYER §1)
|
| 117 |
-
REGISTRY = {}
|
| 118 |
-
|
| 119 |
-
def register(name: str, flagship: str, failure_mode: str, fallback_tier: str,
|
| 120 |
-
fail_max: int = 5, reset_timeout_s: int = 15) -> pybreaker.CircuitBreaker:
|
| 121 |
-
b = make_breaker(name, flagship, failure_mode, fallback_tier, fail_max, reset_timeout_s)
|
| 122 |
-
REGISTRY[name] = b
|
| 123 |
-
return b
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
def breaker_states() -> dict[str, int]:
|
| 127 |
-
"""For /healthz: 0=CLOSED, 1=HALF_OPEN, 2=OPEN per registered breaker."""
|
| 128 |
-
m = {"closed": 0, "half-open": 1, "open": 2}
|
| 129 |
-
return {n: m.get(str(b.current_state).lower(), -1) for n, b in REGISTRY.items()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,93 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 SZL Holdings · Doctrine v12 (additive). Yachay.
|
| 3 |
-
"""
|
| 4 |
-
szl_exporter — scrapes each Space's honest in-process state and re-exposes it as
|
| 5 |
-
Prometheus metrics for the single-pane Grafana dashboard (OBSERVABILITY_DASHBOARD.md).
|
| 6 |
-
|
| 7 |
-
Reads /api/<space>/healthz, /v1/mesh/state, /v1/brain/sockets, vessels ledger,
|
| 8 |
-
lean-kernel /api/lean/theorems.
|
| 9 |
-
|
| 10 |
-
HONEST: it reports what the Spaces actually expose. Where a Space has no metric yet
|
| 11 |
-
(e.g. a static Space has no latency histogram), the series is simply absent, not faked.
|
| 12 |
-
The in-process buses + Khipu DAG are in-memory ring buffers (per szl_wire.py); the
|
| 13 |
-
durable record is the S3 mirror (BACKUP_AND_RECOVERY.md). v11 LOCKED numbers untouched.
|
| 14 |
-
"""
|
| 15 |
-
import time
|
| 16 |
-
|
| 17 |
-
import httpx
|
| 18 |
-
from prometheus_client import Gauge, start_http_server
|
| 19 |
-
|
| 20 |
-
SPACES = {
|
| 21 |
-
"a11oy": "https://szlholdings-a11oy.hf.space",
|
| 22 |
-
"amaru": "https://szlholdings-amaru.hf.space",
|
| 23 |
-
"sentra": "https://szlholdings-sentra.hf.space",
|
| 24 |
-
"vessels": "https://szlholdings-vessels.hf.space",
|
| 25 |
-
"rosie": "https://szlholdings-rosie.hf.space",
|
| 26 |
-
"killinchu": "https://szlholdings-killinchu.hf.space",
|
| 27 |
-
"lean-kernel": "https://szlholdings-lean-kernel.hf.space",
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
up = Gauge("szl_up", "flagship up (1) or down (0)", ["flagship"])
|
| 31 |
-
dag_depth = Gauge("szl_khipu_dag_depth", "Khipu DAG depth (ring buffer)", ["chain"])
|
| 32 |
-
integ = Gauge("szl_khipu_integrity_ok", "Khipu integrity (1 ok / 0 mismatch)", ["chain"])
|
| 33 |
-
lean_dec = Gauge("szl_lean_declarations", "lean-kernel total declarations (live build)")
|
| 34 |
-
lean_sry = Gauge("szl_lean_sorry", "lean-kernel sorry count (live build)")
|
| 35 |
-
lean_axi = Gauge("szl_lean_axiom", "lean-kernel axiom count (live build)")
|
| 36 |
-
|
| 37 |
-
# LOCKED reference (Doctrine v11/v12) — surfaced alongside the live build, never edited.
|
| 38 |
-
LOCKED = Gauge("szl_lean_locked_reference", "Doctrine LOCKED reference numbers", ["kind"])
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def _recompute_integrity(nodes: list[dict]) -> int:
|
| 42 |
-
"""Honest hash-chain check: digest must equal sha256(receipt sorted-json || parents)."""
|
| 43 |
-
import hashlib
|
| 44 |
-
import json
|
| 45 |
-
prev = None
|
| 46 |
-
for n in nodes:
|
| 47 |
-
h = hashlib.sha256()
|
| 48 |
-
h.update(json.dumps(n.get("receipt", {}), sort_keys=True).encode())
|
| 49 |
-
for p in n.get("parents", []):
|
| 50 |
-
h.update(p.encode())
|
| 51 |
-
if n.get("digest") and n["digest"] != h.hexdigest():
|
| 52 |
-
return 0
|
| 53 |
-
prev = n.get("digest")
|
| 54 |
-
return 1
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def scrape_once():
|
| 58 |
-
for name, base in SPACES.items():
|
| 59 |
-
try:
|
| 60 |
-
h = httpx.get(f"{base}/api/{name}/healthz", timeout=10)
|
| 61 |
-
up.labels(name).set(1 if h.status_code == 200 else 0)
|
| 62 |
-
except Exception:
|
| 63 |
-
up.labels(name).set(0) # honest: probe failed -> down
|
| 64 |
-
|
| 65 |
-
# Khipu DAG depth + integrity from vessels ledger read-view
|
| 66 |
-
try:
|
| 67 |
-
led = httpx.get(f"{SPACES['vessels']}/api/vessels/v1/receipts/ledger", timeout=10).json()
|
| 68 |
-
nodes = led.get("nodes", [])
|
| 69 |
-
dag_depth.labels("canonical").set(len(nodes))
|
| 70 |
-
integ.labels("canonical").set(_recompute_integrity(nodes))
|
| 71 |
-
except Exception:
|
| 72 |
-
integ.labels("canonical").set(0)
|
| 73 |
-
|
| 74 |
-
# Lean-kernel live build numbers (surfaced next to LOCKED reference)
|
| 75 |
-
try:
|
| 76 |
-
th = httpx.get(f"{SPACES['lean-kernel']}/api/lean/theorems", timeout=15).json()["summary"]
|
| 77 |
-
lean_dec.set(th.get("total_declarations", 0))
|
| 78 |
-
lean_sry.set(th.get("sorry", 0))
|
| 79 |
-
lean_axi.set(th.get("axiom", 0))
|
| 80 |
-
except Exception:
|
| 81 |
-
pass
|
| 82 |
-
|
| 83 |
-
# LOCKED reference (never edited): 749 declarations / 14 unique axioms / 163 sorries
|
| 84 |
-
LOCKED.labels("declarations").set(749)
|
| 85 |
-
LOCKED.labels("unique_axioms").set(14)
|
| 86 |
-
LOCKED.labels("sorries").set(163)
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
if __name__ == "__main__":
|
| 90 |
-
start_http_server(9100) # Prometheus scrapes :9100/metrics
|
| 91 |
-
while True:
|
| 92 |
-
scrape_once()
|
| 93 |
-
time.sleep(15)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,210 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Read-only GitHub access audit for cross-repo execution readiness.
|
| 3 |
-
|
| 4 |
-
This script observes the current gh authentication context and target-repo
|
| 5 |
-
viewer permissions from docs/github-enterprise-access-checklist.json. It never
|
| 6 |
-
pushes, opens pull requests, edits repos, mutates teams, or calls write-method
|
| 7 |
-
GitHub APIs.
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
-
from __future__ import annotations
|
| 11 |
-
|
| 12 |
-
import argparse
|
| 13 |
-
import json
|
| 14 |
-
import subprocess
|
| 15 |
-
import sys
|
| 16 |
-
from datetime import datetime, timezone
|
| 17 |
-
from pathlib import Path
|
| 18 |
-
from typing import Any
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 22 |
-
CHECKLIST = REPO_ROOT / "docs" / "github-enterprise-access-checklist.json"
|
| 23 |
-
PERMISSION_RANK = {
|
| 24 |
-
"": 0,
|
| 25 |
-
"NONE": 0,
|
| 26 |
-
"READ": 1,
|
| 27 |
-
"TRIAGE": 1,
|
| 28 |
-
"WRITE": 2,
|
| 29 |
-
"MAINTAIN": 3,
|
| 30 |
-
"ADMIN": 4,
|
| 31 |
-
}
|
| 32 |
-
WRITE_READY = {"WRITE", "MAINTAIN", "ADMIN"}
|
| 33 |
-
ALLOWED_STATUSES = {"write-ready", "read-only", "unavailable", "error"}
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def run_gh(args: list[str]) -> tuple[int, str, str]:
|
| 37 |
-
command = ["gh", *args]
|
| 38 |
-
completed = subprocess.run(
|
| 39 |
-
command,
|
| 40 |
-
cwd=REPO_ROOT,
|
| 41 |
-
text=True,
|
| 42 |
-
stdout=subprocess.PIPE,
|
| 43 |
-
stderr=subprocess.PIPE,
|
| 44 |
-
check=False,
|
| 45 |
-
)
|
| 46 |
-
return completed.returncode, completed.stdout.strip(), completed.stderr.strip()
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
def sanitize_error(value: str) -> str:
|
| 50 |
-
return value.replace("\n", " ")[:500]
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
def permission_meets_minimum(viewer_permission: str, minimum: str) -> bool:
|
| 54 |
-
minimum = minimum.upper()
|
| 55 |
-
viewer = viewer_permission.upper()
|
| 56 |
-
if minimum == "WRITE":
|
| 57 |
-
return viewer in WRITE_READY
|
| 58 |
-
return PERMISSION_RANK.get(viewer, 0) >= PERMISSION_RANK.get(minimum, 0)
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
def repo_status(viewer_permission: str, exit_code: int) -> str:
|
| 62 |
-
if exit_code != 0:
|
| 63 |
-
return "unavailable"
|
| 64 |
-
permission = viewer_permission.upper()
|
| 65 |
-
if permission in WRITE_READY:
|
| 66 |
-
return "write-ready"
|
| 67 |
-
return "read-only"
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
def audit(checklist_path: Path) -> dict[str, Any]:
|
| 71 |
-
checklist = json.loads(checklist_path.read_text(encoding="utf-8"))
|
| 72 |
-
|
| 73 |
-
auth_code, auth_stdout, auth_stderr = run_gh(["auth", "status"])
|
| 74 |
-
user_code, user_stdout, user_stderr = run_gh(["api", "user", "-q", ".login"])
|
| 75 |
-
viewer = {
|
| 76 |
-
"login": user_stdout if user_code == 0 else None,
|
| 77 |
-
"source": "gh api user -q .login",
|
| 78 |
-
"error": sanitize_error(user_stderr) if user_code != 0 else None,
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
repos = []
|
| 82 |
-
for target in checklist.get("targetRepos", []):
|
| 83 |
-
repo = target["repo"]
|
| 84 |
-
command_args = [
|
| 85 |
-
"repo",
|
| 86 |
-
"view",
|
| 87 |
-
repo,
|
| 88 |
-
"--json",
|
| 89 |
-
"viewerPermission,nameWithOwner,isPrivate,defaultBranchRef",
|
| 90 |
-
]
|
| 91 |
-
code, stdout, stderr = run_gh(command_args)
|
| 92 |
-
viewer_permission = ""
|
| 93 |
-
raw: dict[str, Any] | None = None
|
| 94 |
-
if code == 0 and stdout:
|
| 95 |
-
try:
|
| 96 |
-
raw = json.loads(stdout)
|
| 97 |
-
viewer_permission = str(raw.get("viewerPermission") or "")
|
| 98 |
-
except json.JSONDecodeError:
|
| 99 |
-
code = 1
|
| 100 |
-
stderr = "gh returned non-JSON output"
|
| 101 |
-
|
| 102 |
-
minimum = target.get("minimumPermission", "write")
|
| 103 |
-
meets = permission_meets_minimum(viewer_permission, minimum)
|
| 104 |
-
repos.append(
|
| 105 |
-
{
|
| 106 |
-
"repo": repo,
|
| 107 |
-
"minimumPermission": minimum,
|
| 108 |
-
"viewerPermission": viewer_permission or None,
|
| 109 |
-
"meetsMinimumPermission": meets,
|
| 110 |
-
"phaseUnlocked": target.get("phaseUnlocked"),
|
| 111 |
-
"currentFallback": target.get("currentFallback"),
|
| 112 |
-
"ghCommand": "gh " + " ".join(command_args),
|
| 113 |
-
"status": repo_status(viewer_permission, code) if code == 0 else "unavailable",
|
| 114 |
-
"error": sanitize_error(stderr) if code != 0 else None,
|
| 115 |
-
"isPrivate": raw.get("isPrivate") if raw else None,
|
| 116 |
-
"defaultBranch": raw.get("defaultBranchRef", {}).get("name") if raw and raw.get("defaultBranchRef") else None,
|
| 117 |
-
}
|
| 118 |
-
)
|
| 119 |
-
|
| 120 |
-
summary = {
|
| 121 |
-
"total": len(repos),
|
| 122 |
-
"writeReady": sum(1 for repo in repos if repo["status"] == "write-ready"),
|
| 123 |
-
"readOnly": sum(1 for repo in repos if repo["status"] == "read-only"),
|
| 124 |
-
"unavailable": sum(1 for repo in repos if repo["status"] == "unavailable"),
|
| 125 |
-
"errors": sum(1 for repo in repos if repo["status"] == "error"),
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
return {
|
| 129 |
-
"schemaVersion": 1,
|
| 130 |
-
"generatedAt": datetime.now(timezone.utc).isoformat(),
|
| 131 |
-
"checklistPath": str(checklist_path.relative_to(REPO_ROOT)),
|
| 132 |
-
"viewer": viewer,
|
| 133 |
-
"auth": {
|
| 134 |
-
"ghAuthStatusExitCode": auth_code,
|
| 135 |
-
"authenticated": auth_code == 0,
|
| 136 |
-
"stdout": auth_stdout,
|
| 137 |
-
"error": sanitize_error(auth_stderr) if auth_code != 0 else None,
|
| 138 |
-
},
|
| 139 |
-
"repos": repos,
|
| 140 |
-
"summary": summary,
|
| 141 |
-
"failureBoundaries": checklist.get("doctrineBoundaries", []),
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
def validate_output(data: dict[str, Any]) -> list[str]:
|
| 146 |
-
errors: list[str] = []
|
| 147 |
-
required_top = {"schemaVersion", "generatedAt", "checklistPath", "viewer", "auth", "repos", "summary", "failureBoundaries"}
|
| 148 |
-
missing = sorted(required_top - data.keys())
|
| 149 |
-
if missing:
|
| 150 |
-
errors.append(f"missing top-level fields: {', '.join(missing)}")
|
| 151 |
-
|
| 152 |
-
repos = data.get("repos", [])
|
| 153 |
-
if not isinstance(repos, list) or not repos:
|
| 154 |
-
errors.append("repos must be a non-empty list")
|
| 155 |
-
repos = []
|
| 156 |
-
|
| 157 |
-
for repo in repos:
|
| 158 |
-
status = repo.get("status")
|
| 159 |
-
if status not in ALLOWED_STATUSES:
|
| 160 |
-
errors.append(f"{repo.get('repo', '<unknown>')}: unknown status {status!r}")
|
| 161 |
-
if repo.get("minimumPermission") == "write":
|
| 162 |
-
permission = str(repo.get("viewerPermission") or "").upper()
|
| 163 |
-
expected = permission in WRITE_READY
|
| 164 |
-
if bool(repo.get("meetsMinimumPermission")) != expected:
|
| 165 |
-
errors.append(f"{repo.get('repo', '<unknown>')}: meetsMinimumPermission does not match viewerPermission")
|
| 166 |
-
command = str(repo.get("ghCommand") or "")
|
| 167 |
-
if not command.startswith("gh repo view "):
|
| 168 |
-
errors.append(f"{repo.get('repo', '<unknown>')}: ghCommand must be read-only repo view")
|
| 169 |
-
|
| 170 |
-
return errors
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
def main() -> int:
|
| 174 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 175 |
-
parser.add_argument("--checklist", default=str(CHECKLIST), help="Path to access checklist JSON")
|
| 176 |
-
parser.add_argument("--output", required=True, help="Where to write audit JSON")
|
| 177 |
-
parser.add_argument("--validate", action="store_true", help="Validate the emitted output shape")
|
| 178 |
-
args = parser.parse_args()
|
| 179 |
-
|
| 180 |
-
checklist_path = Path(args.checklist)
|
| 181 |
-
if not checklist_path.is_absolute():
|
| 182 |
-
checklist_path = REPO_ROOT / checklist_path
|
| 183 |
-
output_path = Path(args.output)
|
| 184 |
-
if not output_path.is_absolute():
|
| 185 |
-
output_path = REPO_ROOT / output_path
|
| 186 |
-
|
| 187 |
-
data = audit(checklist_path)
|
| 188 |
-
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 189 |
-
output_path.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
|
| 190 |
-
|
| 191 |
-
if args.validate:
|
| 192 |
-
errors = validate_output(data)
|
| 193 |
-
if errors:
|
| 194 |
-
print("GitHub access live audit output validation failed:")
|
| 195 |
-
for error in errors:
|
| 196 |
-
print(f" - {error}")
|
| 197 |
-
return 1
|
| 198 |
-
|
| 199 |
-
print(f"Wrote GitHub access audit: {output_path}")
|
| 200 |
-
print(
|
| 201 |
-
"Summary: "
|
| 202 |
-
f"{data['summary']['writeReady']} write-ready, "
|
| 203 |
-
f"{data['summary']['readOnly']} read-only, "
|
| 204 |
-
f"{data['summary']['unavailable']} unavailable"
|
| 205 |
-
)
|
| 206 |
-
return 0
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
if __name__ == "__main__":
|
| 210 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,158 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Generate a GitHub-backed Hugging Face ecosystem manifest for SZLHOLDINGS."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import argparse
|
| 7 |
-
import json
|
| 8 |
-
import urllib.request
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
from typing import Any
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
REPO_ROOT = Path.cwd()
|
| 14 |
-
DEFAULT_OUTPUT = REPO_ROOT / "docs" / "huggingface-ecosystem-manifest.json"
|
| 15 |
-
ORG = "SZLHOLDINGS"
|
| 16 |
-
OBSERVED_AT = "2026-05-30T03:43:04Z"
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def fetch_json(url: str) -> Any:
|
| 20 |
-
with urllib.request.urlopen(url, timeout=30) as response:
|
| 21 |
-
return json.load(response)
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def api_items(kind: str) -> list[dict[str, Any]]:
|
| 25 |
-
data = fetch_json(f"https://huggingface.co/api/{kind}?author={ORG}&limit=100")
|
| 26 |
-
if not isinstance(data, list):
|
| 27 |
-
raise TypeError(f"Expected list from Hugging Face {kind} API")
|
| 28 |
-
return sorted(data, key=lambda item: item.get("id", ""))
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def item_summary(item: dict[str, Any], repo_type: str) -> dict[str, Any]:
|
| 32 |
-
item_id = item.get("id") or item.get("modelId")
|
| 33 |
-
tags = item.get("tags") or []
|
| 34 |
-
card = item.get("cardData") or {}
|
| 35 |
-
return {
|
| 36 |
-
"id": item_id,
|
| 37 |
-
"repoType": repo_type,
|
| 38 |
-
"private": bool(item.get("private", False)),
|
| 39 |
-
"gated": bool(item.get("gated", False)),
|
| 40 |
-
"disabled": bool(item.get("disabled", False)),
|
| 41 |
-
"sdk": item.get("sdk"),
|
| 42 |
-
"license": card.get("license") or next((tag.removeprefix("license:") for tag in tags if isinstance(tag, str) and tag.startswith("license:")), None),
|
| 43 |
-
"sha": item.get("sha"),
|
| 44 |
-
"lastModified": item.get("lastModified"),
|
| 45 |
-
"createdAt": item.get("createdAt"),
|
| 46 |
-
"tags": tags,
|
| 47 |
-
"claimStatus": "generated-mirror" if item_id == "SZLHOLDINGS/a11oy-v19-substrate" else "inventory",
|
| 48 |
-
"evidenceUrls": [
|
| 49 |
-
f"https://huggingface.co/{item_id}",
|
| 50 |
-
],
|
| 51 |
-
"unsafeFlags": unsafe_flags(str(item_id), repo_type, tags, card),
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
def unsafe_flags(item_id: str, repo_type: str, tags: list[Any], card: dict[str, Any]) -> list[str]:
|
| 56 |
-
flags: list[str] = []
|
| 57 |
-
text = json.dumps({"id": item_id, "tags": tags, "card": card}, sort_keys=True).lower()
|
| 58 |
-
if any(name in text for name in ["kora", "lumina", "paragon", "lyte"]):
|
| 59 |
-
flags.append("stale-product-name-review")
|
| 60 |
-
if item_id in {
|
| 61 |
-
"SZLHOLDINGS/counsel-source",
|
| 62 |
-
"SZLHOLDINGS/terra-source",
|
| 63 |
-
"SZLHOLDINGS/carlota-jo-source",
|
| 64 |
-
}:
|
| 65 |
-
flags.append("funded-roadmap-scaffold-not-active-demo")
|
| 66 |
-
if item_id == "SZLHOLDINGS/SZLHOLDINGS":
|
| 67 |
-
flags.append("org-profile-duplicate-review")
|
| 68 |
-
if repo_type == "space" and any(fragment in item_id for fragment in ["deep-dive", "platform"]):
|
| 69 |
-
flags.append("space-card-should-link-github-commit")
|
| 70 |
-
return flags
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
def build_manifest() -> dict[str, Any]:
|
| 74 |
-
models = [item_summary(item, "model") for item in api_items("models")]
|
| 75 |
-
datasets = [item_summary(item, "dataset") for item in api_items("datasets")]
|
| 76 |
-
spaces = [item_summary(item, "space") for item in api_items("spaces")]
|
| 77 |
-
counts = {
|
| 78 |
-
"models": len(models),
|
| 79 |
-
"datasets": len(datasets),
|
| 80 |
-
"spaces": len(spaces),
|
| 81 |
-
}
|
| 82 |
-
return {
|
| 83 |
-
"schemaVersion": 1,
|
| 84 |
-
"generatedBy": "scripts/audit_huggingface_ecosystem.py",
|
| 85 |
-
"observedAt": OBSERVED_AT,
|
| 86 |
-
"org": ORG,
|
| 87 |
-
"canonicalGitHubRepo": "https://github.com/szl-holdings/a11oy",
|
| 88 |
-
"canonicalRule": "GitHub releases, CI, manifests, checksums, and DOI records are canonical; Hugging Face is a generated discovery and diligence mirror.",
|
| 89 |
-
"publicApiEndpoints": [
|
| 90 |
-
f"https://huggingface.co/api/models?author={ORG}&limit=100",
|
| 91 |
-
f"https://huggingface.co/api/datasets?author={ORG}&limit=100",
|
| 92 |
-
f"https://huggingface.co/api/spaces?author={ORG}&limit=100",
|
| 93 |
-
],
|
| 94 |
-
"counts": counts,
|
| 95 |
-
"canonicalNumbers": {
|
| 96 |
-
"hfSpaces": counts["spaces"],
|
| 97 |
-
"hfDatasets": counts["datasets"],
|
| 98 |
-
"hfModels": counts["models"],
|
| 99 |
-
"githubPublicRepos": 19,
|
| 100 |
-
"leanDeclarations": 217,
|
| 101 |
-
"leanAxioms": 12,
|
| 102 |
-
"leanSorries": 7,
|
| 103 |
-
"anchorFormulaGates": "35/35",
|
| 104 |
-
"benchmarkBaseline": "8.3% (1/12)",
|
| 105 |
-
},
|
| 106 |
-
"guardrails": [
|
| 107 |
-
"Do not present Counsel, Terra, or Carlota Jo as active demo surfaces.",
|
| 108 |
-
"Do not use KORA, LUMINA, PARAGON, or active Lyte framing.",
|
| 109 |
-
"Do not claim zero-sorry or all-green Lean proof status without current machine-readable proof evidence.",
|
| 110 |
-
"Do not claim signed UDS release assets exist unless tarball, signature, sha256, and public key assets are present and verify.",
|
| 111 |
-
],
|
| 112 |
-
"inventory": {
|
| 113 |
-
"models": models,
|
| 114 |
-
"datasets": datasets,
|
| 115 |
-
"spaces": spaces,
|
| 116 |
-
},
|
| 117 |
-
"recommendedActions": [
|
| 118 |
-
{
|
| 119 |
-
"target": "SZLHOLDINGS/a11oy-v19-substrate",
|
| 120 |
-
"action": "Republish from dist/huggingface/a11oy after every GitHub canonical-source change.",
|
| 121 |
-
},
|
| 122 |
-
{
|
| 123 |
-
"target": "SZLHOLDINGS/SZLHOLDINGS",
|
| 124 |
-
"action": "Replace duplicate org-profile model/dataset copy with generated counts and GitHub source links, or deprecate.",
|
| 125 |
-
},
|
| 126 |
-
{
|
| 127 |
-
"target": "source mirrors",
|
| 128 |
-
"action": "Add generated card section: GitHub repo, exact commit, release/CI, DOI, claim status, limitations.",
|
| 129 |
-
},
|
| 130 |
-
{
|
| 131 |
-
"target": "counsel-source/terra-source/carlota-jo-source",
|
| 132 |
-
"action": "Mark funded-roadmap scaffold and remove from active-demo collections until funded.",
|
| 133 |
-
},
|
| 134 |
-
],
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
def main() -> int:
|
| 139 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 140 |
-
parser.add_argument("--output", default=str(DEFAULT_OUTPUT))
|
| 141 |
-
parser.add_argument("--check", action="store_true")
|
| 142 |
-
args = parser.parse_args()
|
| 143 |
-
output = Path(args.output)
|
| 144 |
-
rendered = json.dumps(build_manifest(), indent=2, sort_keys=False) + "\n"
|
| 145 |
-
if args.check:
|
| 146 |
-
if not output.exists() or output.read_text(encoding="utf-8") != rendered:
|
| 147 |
-
print(f"Hugging Face ecosystem manifest is stale: {output}")
|
| 148 |
-
return 1
|
| 149 |
-
print(f"Hugging Face ecosystem manifest is current: {output.relative_to(REPO_ROOT)}")
|
| 150 |
-
return 0
|
| 151 |
-
output.parent.mkdir(parents=True, exist_ok=True)
|
| 152 |
-
output.write_text(rendered, encoding="utf-8")
|
| 153 |
-
print(f"Wrote Hugging Face ecosystem manifest: {output.relative_to(REPO_ROOT)}")
|
| 154 |
-
return 0
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
if __name__ == "__main__":
|
| 158 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,304 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Build the deterministic SZL ecosystem readiness report.
|
| 3 |
-
|
| 4 |
-
The report is intentionally offline by default. It converts the curated
|
| 5 |
-
ecosystem registry into a reviewable investor/UDS readiness packet and adds the
|
| 6 |
-
current claim guardrails observed during the GitHub deep dive. Live GitHub
|
| 7 |
-
status is useful for operators, but reproducible CI should not depend on network
|
| 8 |
-
calls.
|
| 9 |
-
"""
|
| 10 |
-
|
| 11 |
-
from __future__ import annotations
|
| 12 |
-
|
| 13 |
-
import argparse
|
| 14 |
-
import json
|
| 15 |
-
from pathlib import Path
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
REPO_ROOT = Path.cwd()
|
| 19 |
-
REGISTRY_PATH = REPO_ROOT / "docs" / "ecosystem-registry.json"
|
| 20 |
-
DEFAULT_OUTPUT = REPO_ROOT / "docs" / "ecosystem-readiness-report.json"
|
| 21 |
-
OBSERVED_AT = "2026-05-30"
|
| 22 |
-
LIVE_AUDIT_NOTES = {
|
| 23 |
-
"a11oy": [
|
| 24 |
-
"Live main has seven policy gate files under packages/policy/src/gates and ten theorem-runtime manifest entries; larger gate counts require merged PR evidence.",
|
| 25 |
-
"uds-v0.3.0 release currently carries SBOM assets only, not signed binary payload assets.",
|
| 26 |
-
],
|
| 27 |
-
"vessels": [
|
| 28 |
-
"uds-v0.3.0 release was observed with zero release assets; use uds-v0.2.0 for signed-asset demonstration until v0.3.x assets land.",
|
| 29 |
-
"GHCR manifest checks returned an authentication challenge in this environment; package availability needs owner-side push or visibility confirmation.",
|
| 30 |
-
],
|
| 31 |
-
"lutar-lean": [
|
| 32 |
-
"Competition-math benchmark public language must stay raw-score and reproducible; cite only what an upstream proof report verifies.",
|
| 33 |
-
],
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
ACTIVE_DEMO_REPOS = {
|
| 38 |
-
"a11oy",
|
| 39 |
-
"amaru",
|
| 40 |
-
"sentra",
|
| 41 |
-
"rosie",
|
| 42 |
-
"ouroboros",
|
| 43 |
-
"lutar-lean",
|
| 44 |
-
"ouroboros-thesis",
|
| 45 |
-
"uds-mesh",
|
| 46 |
-
"vsp-otel",
|
| 47 |
-
"vessels",
|
| 48 |
-
"agi-forecast",
|
| 49 |
-
"szl-trust",
|
| 50 |
-
"szl-brand",
|
| 51 |
-
"szl-cookbook",
|
| 52 |
-
".github",
|
| 53 |
-
"platform",
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
EXCLUDED_UNTIL_FUNDED = {"counsel", "terra", "carlota-jo"}
|
| 57 |
-
|
| 58 |
-
FUNCTIONAL_STATUS = {
|
| 59 |
-
"a11oy": "demo-ready",
|
| 60 |
-
"vessels": "demo-ready",
|
| 61 |
-
"amaru": "supporting",
|
| 62 |
-
"sentra": "supporting",
|
| 63 |
-
"rosie": "supporting",
|
| 64 |
-
"ouroboros": "supporting",
|
| 65 |
-
"uds-mesh": "supporting",
|
| 66 |
-
"vsp-otel": "supporting",
|
| 67 |
-
"agi-forecast": "supporting",
|
| 68 |
-
"szl-trust": "supporting",
|
| 69 |
-
"szl-brand": "supporting",
|
| 70 |
-
"szl-cookbook": "supporting",
|
| 71 |
-
".github": "supporting",
|
| 72 |
-
"platform": "supporting",
|
| 73 |
-
"lutar-lean": "needs-upstream-fix",
|
| 74 |
-
"ouroboros-thesis": "needs-upstream-fix",
|
| 75 |
-
"counsel": "scaffold-excluded",
|
| 76 |
-
"terra": "scaffold-excluded",
|
| 77 |
-
"carlota-jo": "scaffold-excluded",
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
SHOWCASE_LABELS = {
|
| 81 |
-
"a11oy": "Operational hub and UDS/Zarf-compatible payload publisher",
|
| 82 |
-
"platform": "Canonical product integration monorepo and runtime evidence surface",
|
| 83 |
-
"ouroboros": "Bounded-loop runtime and governance receipt spine",
|
| 84 |
-
"lutar-lean": "Lean 4 proof substrate; cite exact closed modules and current CI",
|
| 85 |
-
"ouroboros-thesis": "DOI-pinned thesis and public claim taxonomy",
|
| 86 |
-
"rosie": "Khipu receipt DAG and CSS-ingress orchestration",
|
| 87 |
-
"amaru": "Receipt minting, append-only provenance, and anchoring component",
|
| 88 |
-
"sentra": "Telemetry, posture drift, and incident-command evidence component",
|
| 89 |
-
"uds-mesh": "UDS/Zarf mesh pointer manifest and bundle topology",
|
| 90 |
-
"vsp-otel": "OpenTelemetry exporter for Lambda-axis spans and receipt hashes",
|
| 91 |
-
"szl-cookbook": "Operator recipes and governed-AI development patterns",
|
| 92 |
-
"agi-forecast": "Governance trajectory forecast scenarios",
|
| 93 |
-
"vessels": "Maritime vertical demo wedge with governed alert trails",
|
| 94 |
-
"szl-trust": "Public trust and replay artifact ledger",
|
| 95 |
-
"szl-brand": "Brand, anatomy, social previews, and visual doctrine",
|
| 96 |
-
".github": "Organization profile, reusable workflows, templates, and checks",
|
| 97 |
-
"counsel": "Funded-roadmap legal vertical scaffold",
|
| 98 |
-
"terra": "Funded-roadmap real-estate vertical scaffold",
|
| 99 |
-
"carlota-jo": "Funded-roadmap advisory services scaffold",
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
EVIDENCE = {
|
| 103 |
-
"a11oy": [
|
| 104 |
-
"README.md",
|
| 105 |
-
"docs/PROVENANCE.md",
|
| 106 |
-
"docs/INVESTOR_DEMO.md",
|
| 107 |
-
"artifacts/a11oy-uds/README.md",
|
| 108 |
-
"deploy/MANIFEST.json",
|
| 109 |
-
".github/workflows/doctrine.yml",
|
| 110 |
-
".github/workflows/operational.yml",
|
| 111 |
-
".github/workflows/huggingface.yml",
|
| 112 |
-
"https://github.com/szl-holdings/a11oy/releases/tag/v1.0.1",
|
| 113 |
-
"https://github.com/szl-holdings/a11oy/releases/tag/uds-v0.2.0",
|
| 114 |
-
],
|
| 115 |
-
"platform": [
|
| 116 |
-
"https://github.com/szl-holdings/platform",
|
| 117 |
-
"https://github.com/szl-holdings/platform/releases/tag/v1.0.0-codex-kernel",
|
| 118 |
-
],
|
| 119 |
-
"ouroboros": [
|
| 120 |
-
"https://github.com/szl-holdings/ouroboros",
|
| 121 |
-
"https://github.com/szl-holdings/ouroboros/releases/tag/v6.3.0",
|
| 122 |
-
],
|
| 123 |
-
"lutar-lean": [
|
| 124 |
-
"https://github.com/szl-holdings/lutar-lean",
|
| 125 |
-
"https://github.com/szl-holdings/lutar-lean/releases/tag/lutar-v18.0.0",
|
| 126 |
-
"https://doi.org/10.5281/zenodo.20434308",
|
| 127 |
-
],
|
| 128 |
-
"ouroboros-thesis": [
|
| 129 |
-
"https://github.com/szl-holdings/ouroboros-thesis",
|
| 130 |
-
"https://doi.org/10.5281/zenodo.20434276",
|
| 131 |
-
"https://doi.org/10.5281/zenodo.19944926",
|
| 132 |
-
],
|
| 133 |
-
"rosie": [
|
| 134 |
-
"https://github.com/szl-holdings/rosie",
|
| 135 |
-
"https://github.com/szl-holdings/rosie/releases/tag/v1.0.1",
|
| 136 |
-
"https://github.com/szl-holdings/rosie/releases/tag/uds-v0.2.0",
|
| 137 |
-
],
|
| 138 |
-
"amaru": [
|
| 139 |
-
"https://github.com/szl-holdings/amaru",
|
| 140 |
-
"https://github.com/szl-holdings/amaru/releases/tag/uds-v0.2.0",
|
| 141 |
-
],
|
| 142 |
-
"sentra": [
|
| 143 |
-
"https://github.com/szl-holdings/sentra",
|
| 144 |
-
"https://github.com/szl-holdings/sentra/releases/tag/uds-v0.2.0",
|
| 145 |
-
],
|
| 146 |
-
"uds-mesh": [
|
| 147 |
-
"https://github.com/szl-holdings/uds-mesh",
|
| 148 |
-
"https://github.com/szl-holdings/uds-mesh/releases/tag/uds-v0.2.0",
|
| 149 |
-
],
|
| 150 |
-
"vsp-otel": [
|
| 151 |
-
"https://github.com/szl-holdings/vsp-otel",
|
| 152 |
-
"https://github.com/szl-holdings/vsp-otel/releases/tag/v0.1.0",
|
| 153 |
-
],
|
| 154 |
-
"szl-cookbook": [
|
| 155 |
-
"https://github.com/szl-holdings/szl-cookbook",
|
| 156 |
-
"https://github.com/szl-holdings/szl-cookbook/releases/tag/v0.1.0",
|
| 157 |
-
],
|
| 158 |
-
"agi-forecast": [
|
| 159 |
-
"https://github.com/szl-holdings/agi-forecast",
|
| 160 |
-
"https://github.com/szl-holdings/agi-forecast/releases/tag/v0.1.0",
|
| 161 |
-
],
|
| 162 |
-
"vessels": [
|
| 163 |
-
"https://github.com/szl-holdings/vessels",
|
| 164 |
-
"https://github.com/szl-holdings/vessels/releases/tag/uds-v0.2.0",
|
| 165 |
-
],
|
| 166 |
-
"szl-trust": [
|
| 167 |
-
"https://github.com/szl-holdings/szl-trust",
|
| 168 |
-
],
|
| 169 |
-
"szl-brand": [
|
| 170 |
-
"https://github.com/szl-holdings/szl-brand",
|
| 171 |
-
"https://github.com/szl-holdings/szl-brand/releases/tag/v0.1.0",
|
| 172 |
-
],
|
| 173 |
-
".github": [
|
| 174 |
-
"https://github.com/szl-holdings/.github",
|
| 175 |
-
],
|
| 176 |
-
"counsel": ["https://github.com/szl-holdings/counsel"],
|
| 177 |
-
"terra": ["https://github.com/szl-holdings/terra"],
|
| 178 |
-
"carlota-jo": ["https://github.com/szl-holdings/carlota-jo"],
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
CAVEATS = {
|
| 182 |
-
"lutar-lean": [
|
| 183 |
-
"Latest observed Lean kernel CI needs upstream repair before broad 'all green' or 'zero sorry' copy is repeated.",
|
| 184 |
-
"Use exact theorem/module references for formal claims.",
|
| 185 |
-
],
|
| 186 |
-
"ouroboros-thesis": [
|
| 187 |
-
"Thesis v18.0 DOI is the current citation anchor; GitHub release list reconciliation remains an upstream action.",
|
| 188 |
-
"Treat the thesis as the claim taxonomy, not blanket runtime proof.",
|
| 189 |
-
],
|
| 190 |
-
"platform": [
|
| 191 |
-
"Use as canonical integration evidence; keep production-readiness claims scoped to current CI and release artifacts.",
|
| 192 |
-
],
|
| 193 |
-
"vessels": [
|
| 194 |
-
"Use as the active vertical demo wedge; avoid implying every vertical scaffold is funded or production-ready.",
|
| 195 |
-
],
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
def repo_entry(repo: dict[str, object]) -> dict[str, object]:
|
| 200 |
-
name = str(repo["name"])
|
| 201 |
-
status = FUNCTIONAL_STATUS.get(name, "roadmap")
|
| 202 |
-
active = name in ACTIVE_DEMO_REPOS and name not in EXCLUDED_UNTIL_FUNDED
|
| 203 |
-
return {
|
| 204 |
-
"name": name,
|
| 205 |
-
"tier": repo.get("tier"),
|
| 206 |
-
"readiness": repo.get("readiness"),
|
| 207 |
-
"functionalDemoStatus": status,
|
| 208 |
-
"activeShowcase": active,
|
| 209 |
-
"showcaseLabel": SHOWCASE_LABELS.get(name, repo.get("role", "")),
|
| 210 |
-
"role": repo.get("role"),
|
| 211 |
-
"github": repo.get("github"),
|
| 212 |
-
"defaultBranch": repo.get("defaultBranch"),
|
| 213 |
-
"evidence": EVIDENCE.get(name, [repo.get("github")]),
|
| 214 |
-
"guardrails": CAVEATS.get(name, []),
|
| 215 |
-
"liveAuditNotes": LIVE_AUDIT_NOTES.get(name, []),
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
def build_report() -> dict[str, object]:
|
| 220 |
-
registry = json.loads(REGISTRY_PATH.read_text(encoding="utf-8"))
|
| 221 |
-
repos = [repo_entry(repo) for repo in registry["repos"]]
|
| 222 |
-
status_counts: dict[str, int] = {}
|
| 223 |
-
for repo in repos:
|
| 224 |
-
status = str(repo["functionalDemoStatus"])
|
| 225 |
-
status_counts[status] = status_counts.get(status, 0) + 1
|
| 226 |
-
|
| 227 |
-
return {
|
| 228 |
-
"schemaVersion": 1,
|
| 229 |
-
"generatedBy": "scripts/build_ecosystem_readiness.py",
|
| 230 |
-
"observedAt": OBSERVED_AT,
|
| 231 |
-
"canonicalHub": registry["canonicalHub"],
|
| 232 |
-
"huggingFaceTarget": registry["huggingFaceTarget"],
|
| 233 |
-
"thesis": registry["thesis"],
|
| 234 |
-
"namingPolicy": {
|
| 235 |
-
"activeProductNames": [
|
| 236 |
-
"a11oy",
|
| 237 |
-
"amaru",
|
| 238 |
-
"sentra",
|
| 239 |
-
"rosie",
|
| 240 |
-
"ouroboros",
|
| 241 |
-
"lutar-lean",
|
| 242 |
-
"ouroboros-thesis",
|
| 243 |
-
"uds-mesh",
|
| 244 |
-
"vsp-otel",
|
| 245 |
-
"vessels",
|
| 246 |
-
"agi-forecast",
|
| 247 |
-
"szl-trust",
|
| 248 |
-
"szl-brand",
|
| 249 |
-
"szl-cookbook",
|
| 250 |
-
"platform",
|
| 251 |
-
],
|
| 252 |
-
"excludedUntilFunded": sorted(EXCLUDED_UNTIL_FUNDED),
|
| 253 |
-
"retiredOrDisallowedInShowcase": ["KORA", "LUMINA", "PARAGON", "Lyte"],
|
| 254 |
-
},
|
| 255 |
-
"claimGuardrails": [
|
| 256 |
-
"GitHub releases, workflows, manifests, checksums, and DOI records are canonical.",
|
| 257 |
-
"Hugging Face is a generated diligence mirror, not the source of release truth.",
|
| 258 |
-
"Counsel, Terra, and Carlota Jo are intentionally excluded from active-demo scope until funded.",
|
| 259 |
-
"Do not repeat broad all-green or zero-sorry proof claims without a current machine-readable proof report.",
|
| 260 |
-
"Do not repeat inflated benchmark closure claims; keep public language raw-score and reproducible, citing only what upstream proof reports verify.",
|
| 261 |
-
"Do not describe SBOM-only or empty UDS v0.3.0 releases as signed binary payload releases.",
|
| 262 |
-
"Do not describe unmerged G36-G40 or broader gate totals as live A11oy main runtime gates.",
|
| 263 |
-
"Use Defense Unicorns UDS/Zarf-compatible phrasing; do not imply Defense Unicorns endorsement or catalog acceptance.",
|
| 264 |
-
],
|
| 265 |
-
"runtimeManifestSummary": {
|
| 266 |
-
"path": "docs/theorem-runtime-manifest.json",
|
| 267 |
-
"trackedEntries": 10,
|
| 268 |
-
"verifiedRuntimeEntries": 8,
|
| 269 |
-
"stagedOrRoadmapEntries": 2,
|
| 270 |
-
},
|
| 271 |
-
"statusCounts": status_counts,
|
| 272 |
-
"repos": repos,
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
def main() -> int:
|
| 277 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 278 |
-
parser.add_argument("--output", default=str(DEFAULT_OUTPUT))
|
| 279 |
-
parser.add_argument("--check", action="store_true", help="fail if output is stale")
|
| 280 |
-
args = parser.parse_args()
|
| 281 |
-
|
| 282 |
-
output = Path(args.output)
|
| 283 |
-
report = build_report()
|
| 284 |
-
rendered = json.dumps(report, indent=2, sort_keys=False) + "\n"
|
| 285 |
-
|
| 286 |
-
if args.check:
|
| 287 |
-
if not output.exists():
|
| 288 |
-
print(f"Missing readiness report: {output}")
|
| 289 |
-
return 1
|
| 290 |
-
current = output.read_text(encoding="utf-8")
|
| 291 |
-
if current != rendered:
|
| 292 |
-
print(f"Readiness report is stale: {output}")
|
| 293 |
-
return 1
|
| 294 |
-
print(f"Readiness report is current: {output.relative_to(REPO_ROOT)}")
|
| 295 |
-
return 0
|
| 296 |
-
|
| 297 |
-
output.parent.mkdir(parents=True, exist_ok=True)
|
| 298 |
-
output.write_text(rendered, encoding="utf-8")
|
| 299 |
-
print(f"Wrote ecosystem readiness report: {output.relative_to(REPO_ROOT)}")
|
| 300 |
-
return 0
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
if __name__ == "__main__":
|
| 304 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Build the SZL ecosystem stage matrix.
|
| 3 |
-
|
| 4 |
-
The matrix is intentionally conservative: it records what is operational,
|
| 5 |
-
verified, staged, blocked, or excluded without turning roadmap items into
|
| 6 |
-
shipping claims.
|
| 7 |
-
"""
|
| 8 |
-
|
| 9 |
-
from __future__ import annotations
|
| 10 |
-
|
| 11 |
-
import argparse
|
| 12 |
-
import json
|
| 13 |
-
from pathlib import Path
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
REPO_ROOT = Path.cwd()
|
| 17 |
-
READINESS = REPO_ROOT / "docs" / "ecosystem-readiness-report.json"
|
| 18 |
-
THEOREMS = REPO_ROOT / "docs" / "theorem-runtime-manifest.json"
|
| 19 |
-
HF = REPO_ROOT / "docs" / "huggingface-ecosystem-manifest.json"
|
| 20 |
-
DEFAULT_OUTPUT = REPO_ROOT / "docs" / "ecosystem-stage-matrix.json"
|
| 21 |
-
OBSERVED_AT = "2026-05-30"
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def load_json(path: Path) -> dict:
|
| 25 |
-
return json.loads(path.read_text(encoding="utf-8"))
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def stage_for_repo(repo: dict) -> str:
|
| 29 |
-
status = repo["functionalDemoStatus"]
|
| 30 |
-
if status == "demo-ready":
|
| 31 |
-
return "operational"
|
| 32 |
-
if status == "supporting":
|
| 33 |
-
return "supporting-operational"
|
| 34 |
-
if status == "needs-upstream-fix":
|
| 35 |
-
return "blocked-upstream"
|
| 36 |
-
if status == "scaffold-excluded":
|
| 37 |
-
return "excluded-until-funded"
|
| 38 |
-
return "roadmap"
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def build_matrix() -> dict:
|
| 42 |
-
readiness = load_json(READINESS)
|
| 43 |
-
theorem_manifest = load_json(THEOREMS)
|
| 44 |
-
hf = load_json(HF)
|
| 45 |
-
|
| 46 |
-
repos = []
|
| 47 |
-
for repo in readiness["repos"]:
|
| 48 |
-
repos.append({
|
| 49 |
-
"name": repo["name"],
|
| 50 |
-
"stage": stage_for_repo(repo),
|
| 51 |
-
"tier": repo["tier"],
|
| 52 |
-
"github": repo["github"],
|
| 53 |
-
"activeShowcase": repo["activeShowcase"],
|
| 54 |
-
"evidence": repo["evidence"],
|
| 55 |
-
"guardrails": repo["guardrails"],
|
| 56 |
-
"nextAction": next_action_for_repo(repo),
|
| 57 |
-
})
|
| 58 |
-
|
| 59 |
-
formulas = []
|
| 60 |
-
for entry in theorem_manifest["entries"]:
|
| 61 |
-
formulas.append({
|
| 62 |
-
"id": entry["id"],
|
| 63 |
-
"formula": entry["formula"],
|
| 64 |
-
"stage": formula_stage(entry["claimStatus"]),
|
| 65 |
-
"claimStatus": entry["claimStatus"],
|
| 66 |
-
"runtimeFile": entry["runtimeFile"],
|
| 67 |
-
"testFile": entry["testFile"],
|
| 68 |
-
"validationCommand": entry["validationCommand"],
|
| 69 |
-
"caveat": entry["caveat"],
|
| 70 |
-
})
|
| 71 |
-
|
| 72 |
-
hf_items = []
|
| 73 |
-
for repo_type, items in hf["inventory"].items():
|
| 74 |
-
for item in items:
|
| 75 |
-
hf_items.append({
|
| 76 |
-
"id": item["id"],
|
| 77 |
-
"repoType": repo_type[:-1] if repo_type.endswith("s") else repo_type,
|
| 78 |
-
"stage": "generated-mirror" if item["id"] == "SZLHOLDINGS/a11oy-v19-substrate" else "inventory",
|
| 79 |
-
"private": item["private"],
|
| 80 |
-
"unsafeFlags": item["unsafeFlags"],
|
| 81 |
-
"evidenceUrls": item["evidenceUrls"],
|
| 82 |
-
})
|
| 83 |
-
|
| 84 |
-
return {
|
| 85 |
-
"schemaVersion": 1,
|
| 86 |
-
"generatedBy": "scripts/build_ecosystem_stage_matrix.py",
|
| 87 |
-
"observedAt": OBSERVED_AT,
|
| 88 |
-
"doctrine": {
|
| 89 |
-
"noFakeGreen": True,
|
| 90 |
-
"noFakeSignedAssets": True,
|
| 91 |
-
"githubCanonical": True,
|
| 92 |
-
"hfGeneratedMirror": True,
|
| 93 |
-
"excludedUntilFunded": ["carlota-jo", "counsel", "terra"],
|
| 94 |
-
},
|
| 95 |
-
"stageDefinitions": {
|
| 96 |
-
"operational": "Code/tests/docs support an active demo path in GitHub.",
|
| 97 |
-
"supporting-operational": "Supports the demo as library, proof, receipt, telemetry, brand, trust, or workflow infrastructure.",
|
| 98 |
-
"blocked-upstream": "Requires upstream proof/CI/release correction before broad claims.",
|
| 99 |
-
"proxy-ready": "Patch/artifact exists but target repo write or owner action is required.",
|
| 100 |
-
"release-payload": "Included in checksummed/signed or generated payload artifacts.",
|
| 101 |
-
"generated-mirror": "Published/generated Hugging Face mirror of GitHub-backed content.",
|
| 102 |
-
"staged": "Prepared but not public/verified/live enough for active claims.",
|
| 103 |
-
"excluded-until-funded": "Visible scaffold, intentionally outside active-demo scope.",
|
| 104 |
-
},
|
| 105 |
-
"canonicalNumbers": {
|
| 106 |
-
"githubPublicRepos": len(readiness["repos"]),
|
| 107 |
-
"hfModels": hf["counts"]["models"],
|
| 108 |
-
"hfDatasets": hf["counts"]["datasets"],
|
| 109 |
-
"hfSpaces": hf["counts"]["spaces"],
|
| 110 |
-
"theoremRuntimeEntries": len(theorem_manifest["entries"]),
|
| 111 |
-
},
|
| 112 |
-
"repositories": repos,
|
| 113 |
-
"formulas": formulas,
|
| 114 |
-
"huggingFace": hf_items,
|
| 115 |
-
"uds": {
|
| 116 |
-
"stage": "operator-proof-point",
|
| 117 |
-
"evidence": [
|
| 118 |
-
"artifacts/a11oy-uds/README.md",
|
| 119 |
-
"artifacts/a11oy-uds/docs/OPERATOR-QUICKSTART.md",
|
| 120 |
-
"docs/UDS_FRONTIER_GAP_MAP.md",
|
| 121 |
-
"deploy/MANIFEST.json"
|
| 122 |
-
],
|
| 123 |
-
"blockedForCatalogGrade": [
|
| 124 |
-
"Signed tar.zst/signature/sha256/pubkey assets must exist and verify for each v0.3.x release.",
|
| 125 |
-
"UDS Package CR / Helm / monitor / network policy integration is not complete for A11oy catalog-grade packaging.",
|
| 126 |
-
"Multi-repo mesh capstone requires real a11oy/amaru/sentra/rosie/vessels assets."
|
| 127 |
-
]
|
| 128 |
-
}
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
def formula_stage(status: str) -> str:
|
| 133 |
-
if status == "verified-runtime":
|
| 134 |
-
return "operational"
|
| 135 |
-
if status.startswith("lean-backed"):
|
| 136 |
-
return "blocked-upstream" if "needs" in status else "supporting-operational"
|
| 137 |
-
if status == "historical-roadmap":
|
| 138 |
-
return "roadmap"
|
| 139 |
-
return "staged"
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
def next_action_for_repo(repo: dict) -> str:
|
| 143 |
-
name = repo["name"]
|
| 144 |
-
status = repo["functionalDemoStatus"]
|
| 145 |
-
if name == "a11oy":
|
| 146 |
-
return "Merge/proxy runtime hardening branches and republish HF payload from GitHub."
|
| 147 |
-
if name == "lutar-lean":
|
| 148 |
-
return "Apply kernel-green proxy patch in Lean-enabled runner; keep 7 sorries honest."
|
| 149 |
-
if name == "agi-forecast":
|
| 150 |
-
return "Merge FG-S1-S4 pipeline and competition-math v2 harness; preserve the recorded raw-score baseline unless a rerun proves improvement."
|
| 151 |
-
if name in {"amaru", "rosie", "sentra", "uds-mesh", "vessels"}:
|
| 152 |
-
return "Land repo-specific receipt/formula/UDS patches via proxy; do not fake signed assets."
|
| 153 |
-
if status == "scaffold-excluded":
|
| 154 |
-
return "Keep excluded until funded; do not market as active demo."
|
| 155 |
-
return "Keep GitHub evidence current and link from generated HF surfaces."
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
def main() -> int:
|
| 159 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 160 |
-
parser.add_argument("--output", default=str(DEFAULT_OUTPUT))
|
| 161 |
-
parser.add_argument("--check", action="store_true")
|
| 162 |
-
args = parser.parse_args()
|
| 163 |
-
|
| 164 |
-
rendered = json.dumps(build_matrix(), indent=2) + "\n"
|
| 165 |
-
output = Path(args.output)
|
| 166 |
-
if args.check:
|
| 167 |
-
if not output.exists() or output.read_text(encoding="utf-8") != rendered:
|
| 168 |
-
print(f"Ecosystem stage matrix is stale: {output}")
|
| 169 |
-
return 1
|
| 170 |
-
print(f"Ecosystem stage matrix is current: {output.relative_to(REPO_ROOT)}")
|
| 171 |
-
return 0
|
| 172 |
-
output.parent.mkdir(parents=True, exist_ok=True)
|
| 173 |
-
output.write_text(rendered, encoding="utf-8")
|
| 174 |
-
print(f"Wrote ecosystem stage matrix: {output.relative_to(REPO_ROOT)}")
|
| 175 |
-
return 0
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
if __name__ == "__main__":
|
| 179 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,227 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Build or verify the A11oy operational payload tarball."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import argparse
|
| 7 |
-
import gzip
|
| 8 |
-
import hashlib
|
| 9 |
-
import io
|
| 10 |
-
import json
|
| 11 |
-
import shutil
|
| 12 |
-
import tarfile
|
| 13 |
-
from pathlib import Path
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
REPO_ROOT = Path.cwd()
|
| 17 |
-
DIST_DIR = REPO_ROOT / "dist" / "payload"
|
| 18 |
-
STAGE_DIR = DIST_DIR / "stage" / "a11oy-operational-payload"
|
| 19 |
-
ARCHIVE = DIST_DIR / "a11oy-operational-payload.tar.gz"
|
| 20 |
-
SHA256 = DIST_DIR / "a11oy-operational-payload.tar.gz.sha256"
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def sha256_file(path: Path) -> str:
|
| 24 |
-
digest = hashlib.sha256()
|
| 25 |
-
with path.open("rb") as handle:
|
| 26 |
-
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
| 27 |
-
digest.update(chunk)
|
| 28 |
-
return digest.hexdigest()
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def copy_file(source: str, target: str) -> None:
|
| 32 |
-
destination = STAGE_DIR / target
|
| 33 |
-
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 34 |
-
shutil.copy2(REPO_ROOT / source, destination)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
def copy_tree(source: str, target: str) -> None:
|
| 38 |
-
destination = STAGE_DIR / target
|
| 39 |
-
if destination.exists():
|
| 40 |
-
shutil.rmtree(destination)
|
| 41 |
-
shutil.copytree(REPO_ROOT / source, destination)
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
def collect_stage_files() -> list[Path]:
|
| 45 |
-
return sorted(path for path in STAGE_DIR.rglob("*") if path.is_file())
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
def write_stage_manifest() -> None:
|
| 49 |
-
files = []
|
| 50 |
-
for path in collect_stage_files():
|
| 51 |
-
rel = path.relative_to(STAGE_DIR).as_posix()
|
| 52 |
-
if rel == "PAYLOAD-MANIFEST.json":
|
| 53 |
-
continue
|
| 54 |
-
files.append(
|
| 55 |
-
{
|
| 56 |
-
"path": rel,
|
| 57 |
-
"size": path.stat().st_size,
|
| 58 |
-
"sha256": sha256_file(path),
|
| 59 |
-
}
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
aggregate_input = "\n".join(
|
| 63 |
-
f"{entry['path']}\0{entry['size']}\0{entry['sha256']}" for entry in files
|
| 64 |
-
).encode("utf-8")
|
| 65 |
-
|
| 66 |
-
manifest = {
|
| 67 |
-
"manifestVersion": 1,
|
| 68 |
-
"name": "a11oy-operational-payload",
|
| 69 |
-
"sourceRepository": "https://github.com/szl-holdings/a11oy",
|
| 70 |
-
"fileCount": len(files),
|
| 71 |
-
"aggregateSha256": hashlib.sha256(aggregate_input).hexdigest(),
|
| 72 |
-
"files": files,
|
| 73 |
-
"verification": {
|
| 74 |
-
"doctrine": [
|
| 75 |
-
"pnpm test:doctrine",
|
| 76 |
-
"pnpm typecheck:doctrine",
|
| 77 |
-
"pnpm build:doctrine",
|
| 78 |
-
"pnpm ecosystem:audit",
|
| 79 |
-
"pnpm ecosystem:os:audit",
|
| 80 |
-
],
|
| 81 |
-
"payload": [
|
| 82 |
-
"pnpm payload:verify",
|
| 83 |
-
"pnpm payload:bundle:verify",
|
| 84 |
-
],
|
| 85 |
-
},
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
(STAGE_DIR / "PAYLOAD-MANIFEST.json").write_text(
|
| 89 |
-
json.dumps(manifest, indent=2) + "\n",
|
| 90 |
-
encoding="utf-8",
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
def stage_payload() -> None:
|
| 95 |
-
if STAGE_DIR.exists():
|
| 96 |
-
shutil.rmtree(STAGE_DIR)
|
| 97 |
-
STAGE_DIR.mkdir(parents=True)
|
| 98 |
-
|
| 99 |
-
for source in [
|
| 100 |
-
"README.md",
|
| 101 |
-
"ROADMAP.md",
|
| 102 |
-
"CHANGELOG.md",
|
| 103 |
-
"LICENSE",
|
| 104 |
-
"CITATION.cff",
|
| 105 |
-
"package.json",
|
| 106 |
-
"pnpm-lock.yaml",
|
| 107 |
-
"pnpm-workspace.yaml",
|
| 108 |
-
"tsconfig.base.json",
|
| 109 |
-
]:
|
| 110 |
-
copy_file(source, source)
|
| 111 |
-
|
| 112 |
-
if (REPO_ROOT / "NOTICE").exists():
|
| 113 |
-
copy_file("NOTICE", "NOTICE")
|
| 114 |
-
|
| 115 |
-
for source in [
|
| 116 |
-
"docs/org-repo-map.md",
|
| 117 |
-
"docs/ECOSYSTEM.md",
|
| 118 |
-
"docs/PROVENANCE.md",
|
| 119 |
-
"docs/SERIES_A_DILIGENCE.md",
|
| 120 |
-
"docs/SERIES_A_MARKET_EVIDENCE.md",
|
| 121 |
-
"docs/SUBSTRATE_REALITY_MAP.md",
|
| 122 |
-
"docs/INVESTOR_DEMO.md",
|
| 123 |
-
"docs/WARHACKER_UDS_PROOF_POINT.md",
|
| 124 |
-
"docs/PERPLEXITY_BRIEF.md",
|
| 125 |
-
"docs/ecosystem-registry.json",
|
| 126 |
-
"docs/ecosystem-readiness-report.json",
|
| 127 |
-
"docs/huggingface.md",
|
| 128 |
-
"docs/regulatory_to_lambda.md",
|
| 129 |
-
"benchmarks",
|
| 130 |
-
".github/workflows/doctrine.yml",
|
| 131 |
-
".github/workflows/huggingface.yml",
|
| 132 |
-
"scripts",
|
| 133 |
-
"deploy",
|
| 134 |
-
"huggingface",
|
| 135 |
-
"dist/huggingface/a11oy",
|
| 136 |
-
"web/packages/a11oy-core/package.json",
|
| 137 |
-
"web/packages/a11oy-core/tsconfig.json",
|
| 138 |
-
"web/packages/a11oy-core/src",
|
| 139 |
-
"web/packages/a11oy-core/dist",
|
| 140 |
-
"web/packages/a11oy-connection/package.json",
|
| 141 |
-
"web/packages/a11oy-connection/tsconfig.json",
|
| 142 |
-
"web/packages/a11oy-connection/src",
|
| 143 |
-
"web/packages/a11oy-connection/dist",
|
| 144 |
-
]:
|
| 145 |
-
target = source
|
| 146 |
-
if source == "dist/huggingface/a11oy":
|
| 147 |
-
target = "publish/huggingface/a11oy"
|
| 148 |
-
if (REPO_ROOT / source).is_dir():
|
| 149 |
-
copy_tree(source, target)
|
| 150 |
-
else:
|
| 151 |
-
copy_file(source, target)
|
| 152 |
-
|
| 153 |
-
write_stage_manifest()
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
def deterministic_tar() -> None:
|
| 157 |
-
DIST_DIR.mkdir(parents=True, exist_ok=True)
|
| 158 |
-
with ARCHIVE.open("wb") as raw:
|
| 159 |
-
with gzip.GzipFile(fileobj=raw, mode="wb", filename="", mtime=0) as gz:
|
| 160 |
-
with tarfile.open(fileobj=gz, mode="w", format=tarfile.PAX_FORMAT) as tar:
|
| 161 |
-
for path in collect_stage_files():
|
| 162 |
-
rel = path.relative_to(STAGE_DIR.parent).as_posix()
|
| 163 |
-
data = path.read_bytes()
|
| 164 |
-
info = tarfile.TarInfo(rel)
|
| 165 |
-
info.size = len(data)
|
| 166 |
-
info.mtime = 0
|
| 167 |
-
info.uid = 0
|
| 168 |
-
info.gid = 0
|
| 169 |
-
info.uname = ""
|
| 170 |
-
info.gname = ""
|
| 171 |
-
info.mode = 0o644
|
| 172 |
-
tar.addfile(info, io.BytesIO(data))
|
| 173 |
-
|
| 174 |
-
digest = sha256_file(ARCHIVE)
|
| 175 |
-
SHA256.write_text(f"{digest} {ARCHIVE.name}\n", encoding="utf-8")
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
def verify_bundle() -> int:
|
| 179 |
-
if not ARCHIVE.exists() or not SHA256.exists():
|
| 180 |
-
print("Operational payload bundle is missing. Run: pnpm payload:bundle")
|
| 181 |
-
return 1
|
| 182 |
-
|
| 183 |
-
expected = SHA256.read_text(encoding="utf-8").split()[0]
|
| 184 |
-
actual = sha256_file(ARCHIVE)
|
| 185 |
-
if expected != actual:
|
| 186 |
-
print(f"Bundle checksum mismatch: expected {expected}, got {actual}")
|
| 187 |
-
return 1
|
| 188 |
-
|
| 189 |
-
required = {
|
| 190 |
-
"a11oy-operational-payload/PAYLOAD-MANIFEST.json",
|
| 191 |
-
"a11oy-operational-payload/deploy/MANIFEST.json",
|
| 192 |
-
"a11oy-operational-payload/publish/huggingface/a11oy/README.md",
|
| 193 |
-
"a11oy-operational-payload/publish/huggingface/a11oy/DEMO_RECEIPT_SAMPLE.jsonl",
|
| 194 |
-
"a11oy-operational-payload/web/packages/a11oy-core/dist/index.js",
|
| 195 |
-
"a11oy-operational-payload/web/packages/a11oy-connection/dist/index.js",
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
with tarfile.open(ARCHIVE, mode="r:gz") as tar:
|
| 199 |
-
names = set(tar.getnames())
|
| 200 |
-
missing = sorted(required - names)
|
| 201 |
-
if missing:
|
| 202 |
-
print("Bundle is missing required files:")
|
| 203 |
-
for name in missing:
|
| 204 |
-
print(f" - {name}")
|
| 205 |
-
return 1
|
| 206 |
-
|
| 207 |
-
print(f"Verified operational payload bundle: {ARCHIVE.relative_to(REPO_ROOT)}")
|
| 208 |
-
return 0
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
def main() -> int:
|
| 212 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 213 |
-
parser.add_argument("--verify", action="store_true")
|
| 214 |
-
args = parser.parse_args()
|
| 215 |
-
|
| 216 |
-
if args.verify:
|
| 217 |
-
return verify_bundle()
|
| 218 |
-
|
| 219 |
-
stage_payload()
|
| 220 |
-
deterministic_tar()
|
| 221 |
-
print(f"Built operational payload bundle: {ARCHIVE.relative_to(REPO_ROOT)}")
|
| 222 |
-
print(f"Wrote checksum sidecar: {SHA256.relative_to(REPO_ROOT)}")
|
| 223 |
-
return 0
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
if __name__ == "__main__":
|
| 227 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,80 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the tracked SZL ecosystem registry and optional local checkouts."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import argparse
|
| 7 |
-
import json
|
| 8 |
-
import subprocess
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
REPO_ROOT = Path.cwd()
|
| 13 |
-
REGISTRY_PATH = REPO_ROOT / "docs" / "ecosystem-registry.json"
|
| 14 |
-
LOCAL_ROOT = REPO_ROOT / ".repos" / "szl-holdings"
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def git_head(path: Path) -> str | None:
|
| 18 |
-
try:
|
| 19 |
-
return subprocess.check_output(
|
| 20 |
-
["git", "-C", str(path), "rev-parse", "--short=12", "HEAD"],
|
| 21 |
-
text=True,
|
| 22 |
-
stderr=subprocess.DEVNULL,
|
| 23 |
-
).strip()
|
| 24 |
-
except (subprocess.CalledProcessError, FileNotFoundError):
|
| 25 |
-
return None
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def main() -> int:
|
| 29 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 30 |
-
parser.add_argument("--require-local", action="store_true")
|
| 31 |
-
args = parser.parse_args()
|
| 32 |
-
|
| 33 |
-
registry = json.loads(REGISTRY_PATH.read_text(encoding="utf-8"))
|
| 34 |
-
repos = registry.get("repos", [])
|
| 35 |
-
names = [repo["name"] for repo in repos]
|
| 36 |
-
|
| 37 |
-
errors: list[str] = []
|
| 38 |
-
if registry.get("canonicalHub") != "a11oy":
|
| 39 |
-
errors.append("canonicalHub must be a11oy")
|
| 40 |
-
if len(names) != len(set(names)):
|
| 41 |
-
errors.append("repo names must be unique")
|
| 42 |
-
if len(repos) < 19:
|
| 43 |
-
errors.append("registry should cover all 19 visible public org repos")
|
| 44 |
-
|
| 45 |
-
for repo in repos:
|
| 46 |
-
for field in ["name", "tier", "readiness", "role", "github", "defaultBranch"]:
|
| 47 |
-
if not repo.get(field):
|
| 48 |
-
errors.append(f"{repo.get('name', '<unknown>')} missing {field}")
|
| 49 |
-
if not str(repo.get("github", "")).startswith("https://github.com/szl-holdings/"):
|
| 50 |
-
errors.append(f"{repo.get('name')} has non-SZL GitHub URL")
|
| 51 |
-
|
| 52 |
-
local_name = repo["name"]
|
| 53 |
-
local_path = LOCAL_ROOT / local_name
|
| 54 |
-
if local_name == ".github":
|
| 55 |
-
local_path = LOCAL_ROOT / ".github"
|
| 56 |
-
if args.require_local and not (local_path / ".git").exists():
|
| 57 |
-
errors.append(f"missing local checkout: {local_path}")
|
| 58 |
-
|
| 59 |
-
if errors:
|
| 60 |
-
print("Ecosystem audit failed:")
|
| 61 |
-
for error in errors:
|
| 62 |
-
print(f" - {error}")
|
| 63 |
-
return 1
|
| 64 |
-
|
| 65 |
-
print(f"Ecosystem audit passed: {len(repos)} repos tracked")
|
| 66 |
-
if LOCAL_ROOT.exists():
|
| 67 |
-
present = 0
|
| 68 |
-
for repo in repos:
|
| 69 |
-
local_path = LOCAL_ROOT / repo["name"]
|
| 70 |
-
if repo["name"] == ".github":
|
| 71 |
-
local_path = LOCAL_ROOT / ".github"
|
| 72 |
-
head = git_head(local_path)
|
| 73 |
-
if head:
|
| 74 |
-
present += 1
|
| 75 |
-
print(f"Local checkouts present: {present}/{len(repos)} under {LOCAL_ROOT}")
|
| 76 |
-
return 0
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
if __name__ == "__main__":
|
| 80 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,89 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Build or verify deterministic SHA-256 manifests for payload directories."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import argparse
|
| 7 |
-
import hashlib
|
| 8 |
-
import json
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def sha256_file(path: Path) -> str:
|
| 13 |
-
digest = hashlib.sha256()
|
| 14 |
-
with path.open("rb") as handle:
|
| 15 |
-
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
| 16 |
-
digest.update(chunk)
|
| 17 |
-
return digest.hexdigest()
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def collect_files(root: Path, output: Path) -> list[dict[str, object]]:
|
| 21 |
-
files: list[dict[str, object]] = []
|
| 22 |
-
output = output.resolve()
|
| 23 |
-
|
| 24 |
-
for path in sorted(root.rglob("*")):
|
| 25 |
-
if not path.is_file():
|
| 26 |
-
continue
|
| 27 |
-
if path.resolve() == output:
|
| 28 |
-
continue
|
| 29 |
-
|
| 30 |
-
rel = path.relative_to(root).as_posix()
|
| 31 |
-
files.append(
|
| 32 |
-
{
|
| 33 |
-
"path": rel,
|
| 34 |
-
"size": path.stat().st_size,
|
| 35 |
-
"sha256": sha256_file(path),
|
| 36 |
-
}
|
| 37 |
-
)
|
| 38 |
-
|
| 39 |
-
return files
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def build_manifest(root: Path, output: Path) -> dict[str, object]:
|
| 43 |
-
files = collect_files(root, output)
|
| 44 |
-
aggregate_input = "\n".join(
|
| 45 |
-
f"{entry['path']}\0{entry['size']}\0{entry['sha256']}" for entry in files
|
| 46 |
-
).encode("utf-8")
|
| 47 |
-
|
| 48 |
-
return {
|
| 49 |
-
"manifestVersion": 1,
|
| 50 |
-
"payloadRoot": root.name,
|
| 51 |
-
"generator": "scripts/payload_manifest.py",
|
| 52 |
-
"fileCount": len(files),
|
| 53 |
-
"aggregateSha256": hashlib.sha256(aggregate_input).hexdigest(),
|
| 54 |
-
"files": files,
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
def main() -> int:
|
| 59 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 60 |
-
parser.add_argument("payload_dir", type=Path)
|
| 61 |
-
parser.add_argument("--output", required=True, type=Path)
|
| 62 |
-
parser.add_argument("--verify", action="store_true")
|
| 63 |
-
args = parser.parse_args()
|
| 64 |
-
|
| 65 |
-
root = args.payload_dir.resolve()
|
| 66 |
-
output = args.output.resolve()
|
| 67 |
-
manifest = build_manifest(root, output)
|
| 68 |
-
serialized = json.dumps(manifest, indent=2, sort_keys=False) + "\n"
|
| 69 |
-
|
| 70 |
-
if args.verify:
|
| 71 |
-
existing = output.read_text(encoding="utf-8")
|
| 72 |
-
if existing != serialized:
|
| 73 |
-
rel_output = output.relative_to(Path.cwd()) if output.is_relative_to(Path.cwd()) else output
|
| 74 |
-
print(f"Payload manifest is stale: {rel_output}")
|
| 75 |
-
print(
|
| 76 |
-
"Run: python3 scripts/payload_manifest.py "
|
| 77 |
-
f"{args.payload_dir} --output {args.output}"
|
| 78 |
-
)
|
| 79 |
-
return 1
|
| 80 |
-
print(f"Verified payload manifest: {output.relative_to(Path.cwd())}")
|
| 81 |
-
return 0
|
| 82 |
-
|
| 83 |
-
output.write_text(serialized, encoding="utf-8")
|
| 84 |
-
print(f"Wrote payload manifest: {output.relative_to(Path.cwd())}")
|
| 85 |
-
return 0
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
if __name__ == "__main__":
|
| 89 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,155 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Prepare the Hugging Face payload directory from tracked source files."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import shutil
|
| 8 |
-
import subprocess
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
REPO_ROOT = Path.cwd()
|
| 13 |
-
OUT_DIR = REPO_ROOT / "dist" / "huggingface" / "a11oy"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def git_value(*args: str, fallback: str = "unknown") -> str:
|
| 17 |
-
try:
|
| 18 |
-
return subprocess.check_output(
|
| 19 |
-
["git", *args],
|
| 20 |
-
cwd=REPO_ROOT,
|
| 21 |
-
text=True,
|
| 22 |
-
stderr=subprocess.DEVNULL,
|
| 23 |
-
).strip()
|
| 24 |
-
except (subprocess.CalledProcessError, FileNotFoundError):
|
| 25 |
-
return fallback
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def copy_text(source: str, target: str) -> None:
|
| 29 |
-
destination = OUT_DIR / target
|
| 30 |
-
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 31 |
-
destination.write_text((REPO_ROOT / source).read_text(encoding="utf-8"), encoding="utf-8")
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def copy_tree(source: str, target: str) -> None:
|
| 35 |
-
destination = OUT_DIR / target
|
| 36 |
-
if destination.exists():
|
| 37 |
-
shutil.rmtree(destination)
|
| 38 |
-
shutil.copytree(REPO_ROOT / source, destination)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def main() -> int:
|
| 42 |
-
if OUT_DIR.exists():
|
| 43 |
-
shutil.rmtree(OUT_DIR)
|
| 44 |
-
OUT_DIR.mkdir(parents=True)
|
| 45 |
-
|
| 46 |
-
files = [
|
| 47 |
-
("huggingface/README.md", "README.md"),
|
| 48 |
-
("huggingface/SHOWCASE.md", "SHOWCASE.md"),
|
| 49 |
-
("huggingface/INVESTOR_BRIEF.md", "INVESTOR_BRIEF.md"),
|
| 50 |
-
("huggingface/VERIFICATION.md", "VERIFICATION.md"),
|
| 51 |
-
("huggingface/INNOVATIONS_DEEP_DIVE.md", "INNOVATIONS_DEEP_DIVE.md"),
|
| 52 |
-
("huggingface/INTEGRATION_QUICKSTART.md", "INTEGRATION_QUICKSTART.md"),
|
| 53 |
-
("huggingface/DEMO_RECEIPT_SAMPLE.jsonl", "DEMO_RECEIPT_SAMPLE.jsonl"),
|
| 54 |
-
("LICENSE", "LICENSE"),
|
| 55 |
-
("CITATION.cff", "CITATION.cff"),
|
| 56 |
-
("README.md", "source/README.md"),
|
| 57 |
-
("ROADMAP.md", "source/ROADMAP.md"),
|
| 58 |
-
("CHANGELOG.md", "source/CHANGELOG.md"),
|
| 59 |
-
("docs/org-repo-map.md", "source/docs/org-repo-map.md"),
|
| 60 |
-
("docs/regulatory_to_lambda.md", "source/docs/regulatory_to_lambda.md"),
|
| 61 |
-
("docs/huggingface.md", "source/docs/huggingface.md"),
|
| 62 |
-
("docs/huggingface-ecosystem-manifest.json", "source/docs/huggingface-ecosystem-manifest.json"),
|
| 63 |
-
("docs/huggingface-ecosystem-manifest.schema.json", "source/docs/huggingface-ecosystem-manifest.schema.json"),
|
| 64 |
-
("docs/ecosystem-registry.json", "source/docs/ecosystem-registry.json"),
|
| 65 |
-
("docs/PROVENANCE.md", "source/docs/PROVENANCE.md"),
|
| 66 |
-
("docs/SERIES_A_DILIGENCE.md", "source/docs/SERIES_A_DILIGENCE.md"),
|
| 67 |
-
("docs/SERIES_A_MARKET_EVIDENCE.md", "source/docs/SERIES_A_MARKET_EVIDENCE.md"),
|
| 68 |
-
("docs/SUBSTRATE_REALITY_MAP.md", "source/docs/SUBSTRATE_REALITY_MAP.md"),
|
| 69 |
-
("docs/INVESTOR_DEMO.md", "source/docs/INVESTOR_DEMO.md"),
|
| 70 |
-
("docs/WARHACKER_UDS_PROOF_POINT.md", "source/docs/WARHACKER_UDS_PROOF_POINT.md"),
|
| 71 |
-
("docs/PERPLEXITY_BRIEF.md", "source/docs/PERPLEXITY_BRIEF.md"),
|
| 72 |
-
("docs/ECOSYSTEM.md", "source/docs/ECOSYSTEM.md"),
|
| 73 |
-
("docs/ecosystem-readiness-report.json", "source/docs/ecosystem-readiness-report.json"),
|
| 74 |
-
("deploy/MANIFEST.json", "payloads/deploy/MANIFEST.json"),
|
| 75 |
-
("deploy/zarf.yaml", "payloads/deploy/zarf.yaml"),
|
| 76 |
-
("deploy/attestations.jsonl", "payloads/deploy/attestations.jsonl"),
|
| 77 |
-
("docs/huggingface-ecosystem-manifest.json", "HF_ECOSYSTEM_MANIFEST.json"),
|
| 78 |
-
("package.json", "build/package.json"),
|
| 79 |
-
("pnpm-lock.yaml", "build/pnpm-lock.yaml"),
|
| 80 |
-
("pnpm-workspace.yaml", "build/pnpm-workspace.yaml"),
|
| 81 |
-
("tsconfig.base.json", "build/tsconfig.base.json"),
|
| 82 |
-
]
|
| 83 |
-
|
| 84 |
-
for source, target in files:
|
| 85 |
-
copy_text(source, target)
|
| 86 |
-
|
| 87 |
-
if (REPO_ROOT / "NOTICE").exists():
|
| 88 |
-
copy_text("NOTICE", "NOTICE")
|
| 89 |
-
|
| 90 |
-
copy_tree("deploy/manifests", "payloads/deploy/manifests")
|
| 91 |
-
copy_tree("huggingface/test-results", "test-results")
|
| 92 |
-
|
| 93 |
-
metadata = {
|
| 94 |
-
"name": "a11oy",
|
| 95 |
-
"owner": "szl-holdings",
|
| 96 |
-
"sourceRepository": "https://github.com/szl-holdings/a11oy",
|
| 97 |
-
"sourceCommit": git_value("rev-parse", "HEAD"),
|
| 98 |
-
"sourceBranch": git_value("rev-parse", "--abbrev-ref", "HEAD"),
|
| 99 |
-
"doctrineCommands": [
|
| 100 |
-
"pnpm test:doctrine",
|
| 101 |
-
"pnpm typecheck:doctrine",
|
| 102 |
-
"pnpm build:doctrine",
|
| 103 |
-
"pnpm ecosystem:audit",
|
| 104 |
-
"pnpm ecosystem:readiness",
|
| 105 |
-
"pnpm hf:ecosystem:audit",
|
| 106 |
-
"pnpm payload:verify",
|
| 107 |
-
"pnpm payload:huggingface",
|
| 108 |
-
"pnpm payload:bundle",
|
| 109 |
-
"pnpm payload:bundle:verify",
|
| 110 |
-
],
|
| 111 |
-
"activeShowcaseRepos": [
|
| 112 |
-
"a11oy",
|
| 113 |
-
"amaru",
|
| 114 |
-
"sentra",
|
| 115 |
-
"rosie",
|
| 116 |
-
"ouroboros",
|
| 117 |
-
"lutar-lean",
|
| 118 |
-
"ouroboros-thesis",
|
| 119 |
-
"uds-mesh",
|
| 120 |
-
"vsp-otel",
|
| 121 |
-
"vessels",
|
| 122 |
-
"agi-forecast",
|
| 123 |
-
"szl-trust",
|
| 124 |
-
"szl-brand",
|
| 125 |
-
"szl-cookbook",
|
| 126 |
-
".github",
|
| 127 |
-
"platform",
|
| 128 |
-
],
|
| 129 |
-
"excludedUntilFunded": ["carlota-jo", "counsel", "terra"],
|
| 130 |
-
"retiredOrDisallowedNames": ["KORA", "LUMINA", "PARAGON", "Lyte"],
|
| 131 |
-
"payloads": [
|
| 132 |
-
{
|
| 133 |
-
"name": "deploy",
|
| 134 |
-
"manifest": "payloads/deploy/MANIFEST.json",
|
| 135 |
-
"zarf": "payloads/deploy/zarf.yaml",
|
| 136 |
-
"kubernetesManifests": "payloads/deploy/manifests/",
|
| 137 |
-
}
|
| 138 |
-
],
|
| 139 |
-
"demoReceiptSample": "DEMO_RECEIPT_SAMPLE.jsonl",
|
| 140 |
-
"publishHygiene": {
|
| 141 |
-
"deleteStaleRemoteFiles": True,
|
| 142 |
-
"staleLegacyFiles": ["EVAL_TRACE_SAMPLE.jsonl"],
|
| 143 |
-
},
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
(OUT_DIR / "a11oy-metadata.json").write_text(
|
| 147 |
-
json.dumps(metadata, indent=2) + "\n",
|
| 148 |
-
encoding="utf-8",
|
| 149 |
-
)
|
| 150 |
-
print(f"Prepared Hugging Face payload at {OUT_DIR.relative_to(REPO_ROOT)}")
|
| 151 |
-
return 0
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
if __name__ == "__main__":
|
| 155 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,74 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Publish the prepared A11oy Hugging Face payload.
|
| 3 |
-
|
| 4 |
-
Requires HF_TOKEN in the environment. The token is never printed.
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
from __future__ import annotations
|
| 8 |
-
|
| 9 |
-
import argparse
|
| 10 |
-
import os
|
| 11 |
-
from pathlib import Path
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def main() -> int:
|
| 15 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 16 |
-
parser.add_argument("--repo-id", default="SZLHOLDINGS/a11oy-v19-substrate")
|
| 17 |
-
parser.add_argument("--repo-type", default="model")
|
| 18 |
-
parser.add_argument("--folder", default="dist/huggingface/a11oy")
|
| 19 |
-
parser.add_argument(
|
| 20 |
-
"--no-delete-stale",
|
| 21 |
-
action="store_true",
|
| 22 |
-
help="upload without pruning remote files absent from the generated payload",
|
| 23 |
-
)
|
| 24 |
-
args = parser.parse_args()
|
| 25 |
-
|
| 26 |
-
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
|
| 27 |
-
if not token:
|
| 28 |
-
print("Missing HF_TOKEN. Add it as a GitHub Actions secret or export it locally.")
|
| 29 |
-
return 2
|
| 30 |
-
|
| 31 |
-
folder = Path(args.folder)
|
| 32 |
-
if not folder.exists():
|
| 33 |
-
print(f"Missing payload folder: {folder}. Run `pnpm payload:huggingface` first.")
|
| 34 |
-
return 1
|
| 35 |
-
|
| 36 |
-
try:
|
| 37 |
-
from huggingface_hub import CommitOperationDelete, HfApi
|
| 38 |
-
except ImportError:
|
| 39 |
-
print("Missing huggingface_hub. Install with: python -m pip install --upgrade huggingface_hub")
|
| 40 |
-
return 2
|
| 41 |
-
|
| 42 |
-
api = HfApi(token=token)
|
| 43 |
-
api.create_repo(repo_id=args.repo_id, repo_type=args.repo_type, exist_ok=True)
|
| 44 |
-
|
| 45 |
-
if not args.no_delete_stale:
|
| 46 |
-
local_files = {
|
| 47 |
-
path.relative_to(folder).as_posix()
|
| 48 |
-
for path in folder.rglob("*")
|
| 49 |
-
if path.is_file()
|
| 50 |
-
}
|
| 51 |
-
remote_files = set(api.list_repo_files(repo_id=args.repo_id, repo_type=args.repo_type))
|
| 52 |
-
stale_files = sorted(remote_files - local_files)
|
| 53 |
-
if stale_files:
|
| 54 |
-
operations = [CommitOperationDelete(path_in_repo=path) for path in stale_files]
|
| 55 |
-
api.create_commit(
|
| 56 |
-
repo_id=args.repo_id,
|
| 57 |
-
repo_type=args.repo_type,
|
| 58 |
-
operations=operations,
|
| 59 |
-
commit_message="prune stale a11oy payload files",
|
| 60 |
-
)
|
| 61 |
-
print(f"Pruned {len(stale_files)} stale Hugging Face files")
|
| 62 |
-
|
| 63 |
-
api.upload_folder(
|
| 64 |
-
repo_id=args.repo_id,
|
| 65 |
-
repo_type=args.repo_type,
|
| 66 |
-
folder_path=str(folder),
|
| 67 |
-
commit_message="publish a11oy operational payload",
|
| 68 |
-
)
|
| 69 |
-
print(f"Published Hugging Face payload to {args.repo_type}:{args.repo_id}")
|
| 70 |
-
return 0
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
if __name__ == "__main__":
|
| 74 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,114 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the original A11oy action-contract manifest."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import sys
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
-
CONTRACT_PATH = REPO_ROOT / "docs" / "action-contract-manifest.json"
|
| 13 |
-
PATTERNS_PATH = REPO_ROOT / "docs" / "public-pattern-source-manifest.json"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def load_json(path: Path) -> dict:
|
| 17 |
-
return json.loads(path.read_text(encoding="utf-8"))
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def main() -> int:
|
| 21 |
-
errors: list[str] = []
|
| 22 |
-
contract = load_json(CONTRACT_PATH)
|
| 23 |
-
patterns = load_json(PATTERNS_PATH)
|
| 24 |
-
pattern_ids = {pattern["id"] for pattern in patterns.get("patterns", [])}
|
| 25 |
-
|
| 26 |
-
if contract.get("schemaVersion") != "a11oy.action-contract.v0.1":
|
| 27 |
-
errors.append("schemaVersion must be a11oy.action-contract.v0.1")
|
| 28 |
-
|
| 29 |
-
if contract.get("claimStatus") not in {"roadmap", "verified-runtime", "release-payload"}:
|
| 30 |
-
errors.append("claimStatus must be roadmap, verified-runtime, or release-payload")
|
| 31 |
-
|
| 32 |
-
clean_room = contract.get("cleanRoom", {})
|
| 33 |
-
if clean_room.get("copyingRule") != "pattern-only":
|
| 34 |
-
errors.append("cleanRoom.copyingRule must be pattern-only")
|
| 35 |
-
if "endorsement" not in clean_room.get("endorsementBoundary", "").lower():
|
| 36 |
-
errors.append("cleanRoom.endorsementBoundary must reject implied endorsement")
|
| 37 |
-
for pattern_id in clean_room.get("sourcePatternIds", []):
|
| 38 |
-
if pattern_id not in pattern_ids:
|
| 39 |
-
errors.append(f"unknown source pattern ID: {pattern_id}")
|
| 40 |
-
|
| 41 |
-
identity = contract.get("identity", {})
|
| 42 |
-
for field in ["actorId", "actorKind", "sessionId", "signerVerifier"]:
|
| 43 |
-
if not identity.get(field):
|
| 44 |
-
errors.append(f"identity.{field} is required")
|
| 45 |
-
|
| 46 |
-
policy = contract.get("policy", {})
|
| 47 |
-
for field in ["policyDocumentRef", "policyHash", "mandatoryAxes", "minimumLambdaCoverage", "approvalGate"]:
|
| 48 |
-
if field not in policy:
|
| 49 |
-
errors.append(f"policy.{field} is required")
|
| 50 |
-
policy_ref = policy.get("policyDocumentRef")
|
| 51 |
-
if policy_ref and not (REPO_ROOT / policy_ref).exists():
|
| 52 |
-
errors.append(f"policyDocumentRef does not exist: {policy_ref}")
|
| 53 |
-
if not isinstance(policy.get("mandatoryAxes", []), list) or not policy.get("mandatoryAxes"):
|
| 54 |
-
errors.append("policy.mandatoryAxes must be a non-empty list")
|
| 55 |
-
if float(policy.get("minimumLambdaCoverage", 0)) < 0.0:
|
| 56 |
-
errors.append("policy.minimumLambdaCoverage must be non-negative")
|
| 57 |
-
|
| 58 |
-
evidence = contract.get("evidence", {})
|
| 59 |
-
for collection in ["manifestRefs", "attestationRefs", "testCommands", "localEvidenceRefs", "claimRefs"]:
|
| 60 |
-
if not isinstance(evidence.get(collection), list):
|
| 61 |
-
errors.append(f"evidence.{collection} must be a list")
|
| 62 |
-
for collection in ["manifestRefs", "attestationRefs", "localEvidenceRefs", "claimRefs"]:
|
| 63 |
-
for ref in evidence.get(collection, []):
|
| 64 |
-
if not (REPO_ROOT / ref).exists():
|
| 65 |
-
errors.append(f"evidence ref does not exist: {ref}")
|
| 66 |
-
|
| 67 |
-
receipt_sinks = contract.get("receiptSinks", {})
|
| 68 |
-
if receipt_sinks.get("chainMode") != "hash-chain":
|
| 69 |
-
errors.append("receiptSinks.chainMode must be hash-chain")
|
| 70 |
-
if int(receipt_sinks.get("retentionDays", 0)) < 365:
|
| 71 |
-
errors.append("receiptSinks.retentionDays must be at least 365")
|
| 72 |
-
for field in ["primaryJsonl", "payloadBundlePath", "udsManifestRef"]:
|
| 73 |
-
if not receipt_sinks.get(field):
|
| 74 |
-
errors.append(f"receiptSinks.{field} is required")
|
| 75 |
-
|
| 76 |
-
replay = contract.get("replayBounds", {})
|
| 77 |
-
if not replay.get("idempotencyKey"):
|
| 78 |
-
errors.append("replayBounds.idempotencyKey is required")
|
| 79 |
-
if int(replay.get("maxReplays", 0)) < 1:
|
| 80 |
-
errors.append("replayBounds.maxReplays must be >= 1")
|
| 81 |
-
if int(replay.get("replayWindowSeconds", 0)) < 1:
|
| 82 |
-
errors.append("replayBounds.replayWindowSeconds must be >= 1")
|
| 83 |
-
for ref in replay.get("deterministicInputs", []):
|
| 84 |
-
if not (REPO_ROOT / ref).exists():
|
| 85 |
-
errors.append(f"deterministic input does not exist: {ref}")
|
| 86 |
-
|
| 87 |
-
egress = contract.get("egressLimits", {})
|
| 88 |
-
if egress.get("defaultDeny") is not True:
|
| 89 |
-
errors.append("egressLimits.defaultDeny must be true")
|
| 90 |
-
denied = set(egress.get("deniedCapabilities", []))
|
| 91 |
-
for capability in ["secret-export", "private-repo-ingestion", "self-approval"]:
|
| 92 |
-
if capability not in denied:
|
| 93 |
-
errors.append(f"egressLimits.deniedCapabilities missing {capability}")
|
| 94 |
-
|
| 95 |
-
uds = contract.get("udsProofPoint", {})
|
| 96 |
-
forbidden_text = " ".join(uds.get("forbiddenClaims", [])).lower()
|
| 97 |
-
for phrase in ["endorsed", "catalog accepted", "deploys to every uds"]:
|
| 98 |
-
if phrase not in forbidden_text:
|
| 99 |
-
errors.append(f"udsProofPoint.forbiddenClaims missing boundary phrase: {phrase}")
|
| 100 |
-
if "proof point" not in uds.get("wording", "").lower():
|
| 101 |
-
errors.append("udsProofPoint.wording must use proof point language")
|
| 102 |
-
|
| 103 |
-
if errors:
|
| 104 |
-
print("Action contract manifest validation failed:")
|
| 105 |
-
for error in errors:
|
| 106 |
-
print(f" - {error}")
|
| 107 |
-
return 1
|
| 108 |
-
|
| 109 |
-
print(f"Validated {CONTRACT_PATH.relative_to(REPO_ROOT)}")
|
| 110 |
-
return 0
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
if __name__ == "__main__":
|
| 114 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,145 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the anatomy/formula/runtime map.
|
| 3 |
-
|
| 4 |
-
The validator is intentionally lightweight and offline. It verifies that the
|
| 5 |
-
map has the expected structure, that referenced theorem-runtime IDs exist, and
|
| 6 |
-
that active local runtime/test paths are present in this checkout.
|
| 7 |
-
"""
|
| 8 |
-
|
| 9 |
-
from __future__ import annotations
|
| 10 |
-
|
| 11 |
-
import json
|
| 12 |
-
import sys
|
| 13 |
-
from pathlib import Path
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 17 |
-
MAP_PATH = REPO_ROOT / "docs" / "anatomy-formula-runtime-map.json"
|
| 18 |
-
THEOREM_MANIFEST_PATH = REPO_ROOT / "docs" / "theorem-runtime-manifest.json"
|
| 19 |
-
|
| 20 |
-
ALLOWED_CLAIM_STATUSES = {
|
| 21 |
-
"verified-runtime",
|
| 22 |
-
"release-payload",
|
| 23 |
-
"lean-backed-current-green",
|
| 24 |
-
"lean-backed-needs-upstream-ci",
|
| 25 |
-
"lean-backed-needs-runtime",
|
| 26 |
-
"thesis-anchor",
|
| 27 |
-
"historical",
|
| 28 |
-
"historical-roadmap",
|
| 29 |
-
"roadmap",
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def load_json(path: Path) -> dict:
|
| 34 |
-
return json.loads(path.read_text(encoding="utf-8"))
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
def main() -> int:
|
| 38 |
-
errors: list[str] = []
|
| 39 |
-
data = load_json(MAP_PATH)
|
| 40 |
-
theorem_manifest = load_json(THEOREM_MANIFEST_PATH)
|
| 41 |
-
theorem_ids = {entry["id"] for entry in theorem_manifest.get("entries", [])}
|
| 42 |
-
|
| 43 |
-
required_top = {
|
| 44 |
-
"schemaVersion",
|
| 45 |
-
"generatedBy",
|
| 46 |
-
"observedAt",
|
| 47 |
-
"canonicalHub",
|
| 48 |
-
"canonicalRule",
|
| 49 |
-
"autonomousLearningDoctrine",
|
| 50 |
-
"organs",
|
| 51 |
-
}
|
| 52 |
-
missing_top = sorted(required_top - data.keys())
|
| 53 |
-
if missing_top:
|
| 54 |
-
errors.append(f"missing top-level fields: {', '.join(missing_top)}")
|
| 55 |
-
|
| 56 |
-
if data.get("canonicalHub") != "a11oy":
|
| 57 |
-
errors.append("canonicalHub must be a11oy")
|
| 58 |
-
|
| 59 |
-
doctrine = data.get("autonomousLearningDoctrine", {})
|
| 60 |
-
if doctrine.get("promotionModel") != "human_promotion_required":
|
| 61 |
-
errors.append("autonomousLearningDoctrine.promotionModel must require human promotion")
|
| 62 |
-
forbidden_modes = set(doctrine.get("forbiddenModes", []))
|
| 63 |
-
for mode in ["self_approve", "self_promote", "deploy", "publish"]:
|
| 64 |
-
if mode not in forbidden_modes:
|
| 65 |
-
errors.append(f"autonomousLearningDoctrine.forbiddenModes missing {mode}")
|
| 66 |
-
|
| 67 |
-
organs = data.get("organs", [])
|
| 68 |
-
if not isinstance(organs, list) or not organs:
|
| 69 |
-
errors.append("organs must be a non-empty list")
|
| 70 |
-
|
| 71 |
-
repos = set()
|
| 72 |
-
required_organ = {
|
| 73 |
-
"repo",
|
| 74 |
-
"anatomyRole",
|
| 75 |
-
"formulaRuntime",
|
| 76 |
-
"theoremAnchors",
|
| 77 |
-
"receiptSurface",
|
| 78 |
-
"testEvidence",
|
| 79 |
-
"udsStage",
|
| 80 |
-
"hfStage",
|
| 81 |
-
"claimStatus",
|
| 82 |
-
"autonomousLearningRole",
|
| 83 |
-
"gaps",
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
for organ in organs:
|
| 87 |
-
repo = organ.get("repo", "<missing>")
|
| 88 |
-
if repo in repos:
|
| 89 |
-
errors.append(f"duplicate organ repo: {repo}")
|
| 90 |
-
repos.add(repo)
|
| 91 |
-
|
| 92 |
-
missing = sorted(required_organ - organ.keys())
|
| 93 |
-
if missing:
|
| 94 |
-
errors.append(f"{repo}: missing fields: {', '.join(missing)}")
|
| 95 |
-
|
| 96 |
-
status = organ.get("claimStatus")
|
| 97 |
-
if status not in ALLOWED_CLAIM_STATUSES:
|
| 98 |
-
errors.append(f"{repo}: unsupported claimStatus {status!r}")
|
| 99 |
-
|
| 100 |
-
for collection_name in [
|
| 101 |
-
"formulaRuntime",
|
| 102 |
-
"theoremAnchors",
|
| 103 |
-
"receiptSurface",
|
| 104 |
-
"testEvidence",
|
| 105 |
-
"gaps",
|
| 106 |
-
]:
|
| 107 |
-
if not isinstance(organ.get(collection_name), list):
|
| 108 |
-
errors.append(f"{repo}: {collection_name} must be a list")
|
| 109 |
-
|
| 110 |
-
for formula in organ.get("formulaRuntime", []):
|
| 111 |
-
formula_status = formula.get("claimStatus")
|
| 112 |
-
if formula_status not in ALLOWED_CLAIM_STATUSES:
|
| 113 |
-
errors.append(
|
| 114 |
-
f"{repo}/{formula.get('formula', '<formula>')}: unsupported claimStatus {formula_status!r}"
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
manifest_id = formula.get("theoremRuntimeManifestId")
|
| 118 |
-
if manifest_id is not None and manifest_id not in theorem_ids:
|
| 119 |
-
errors.append(
|
| 120 |
-
f"{repo}/{formula.get('formula', '<formula>')}: unknown theoremRuntimeManifestId {manifest_id}"
|
| 121 |
-
)
|
| 122 |
-
|
| 123 |
-
runtime_file = formula.get("runtimeFile")
|
| 124 |
-
if runtime_file and not (REPO_ROOT / runtime_file).exists():
|
| 125 |
-
errors.append(
|
| 126 |
-
f"{repo}/{formula.get('formula', '<formula>')}: runtimeFile does not exist: {runtime_file}"
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
required_repos = {"a11oy", "lutar-lean", "ouroboros-thesis", "agi-forecast"}
|
| 130 |
-
missing_repos = sorted(required_repos - repos)
|
| 131 |
-
if missing_repos:
|
| 132 |
-
errors.append(f"missing required organ repos: {', '.join(missing_repos)}")
|
| 133 |
-
|
| 134 |
-
if errors:
|
| 135 |
-
print("Anatomy/formula/runtime map validation failed:")
|
| 136 |
-
for error in errors:
|
| 137 |
-
print(f" - {error}")
|
| 138 |
-
return 1
|
| 139 |
-
|
| 140 |
-
print(f"Validated {MAP_PATH.relative_to(REPO_ROOT)} ({len(organs)} organs)")
|
| 141 |
-
return 0
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
if __name__ == "__main__":
|
| 145 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,92 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the doctrine-safe benchmark map."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import sys
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
-
BENCHMARK_MAP = REPO_ROOT / "benchmarks" / "benchmark-map.json"
|
| 13 |
-
THEOREM_MANIFEST = REPO_ROOT / "docs" / "theorem-runtime-manifest.json"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def load_json(path: Path) -> dict:
|
| 17 |
-
return json.loads(path.read_text(encoding="utf-8"))
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def main() -> int:
|
| 21 |
-
errors: list[str] = []
|
| 22 |
-
data = load_json(BENCHMARK_MAP)
|
| 23 |
-
theorem_manifest = load_json(THEOREM_MANIFEST)
|
| 24 |
-
theorem_ids = {entry["id"] for entry in theorem_manifest.get("entries", [])}
|
| 25 |
-
|
| 26 |
-
if data.get("publication", {}).get("publishMode") != "mirror-not-canonical":
|
| 27 |
-
errors.append("publication.publishMode must be mirror-not-canonical")
|
| 28 |
-
|
| 29 |
-
entries = data.get("entries")
|
| 30 |
-
if not isinstance(entries, list) or not entries:
|
| 31 |
-
errors.append("entries must be a non-empty list")
|
| 32 |
-
entries = []
|
| 33 |
-
|
| 34 |
-
for entry in entries:
|
| 35 |
-
entry_id = entry.get("id", "<missing>")
|
| 36 |
-
if "mathcomp" in entry_id.lower():
|
| 37 |
-
scoring = entry.get("scoring", {})
|
| 38 |
-
if scoring.get("scoreType") != "raw_points":
|
| 39 |
-
errors.append(f"{entry_id}: competition-math benchmark entries must use raw_points")
|
| 40 |
-
|
| 41 |
-
honesty = entry.get("honesty", {})
|
| 42 |
-
disallowed = set(honesty.get("disallowedClaims", []))
|
| 43 |
-
for phrase in ["solved the benchmark", "beat the benchmark", "AGI proven"]:
|
| 44 |
-
if phrase not in disallowed:
|
| 45 |
-
errors.append(f"{entry_id}: disallowedClaims missing {phrase!r}")
|
| 46 |
-
|
| 47 |
-
allowed_claim = honesty.get("allowedClaim", "").lower()
|
| 48 |
-
if "cracked" in allowed_claim or "solved" in allowed_claim:
|
| 49 |
-
errors.append(f"{entry_id}: allowedClaim contains unsupported benchmark language")
|
| 50 |
-
|
| 51 |
-
corpus = entry.get("corpus", {})
|
| 52 |
-
if corpus.get("sealed") and corpus.get("digestStatus") != "sealed":
|
| 53 |
-
errors.append(f"{entry_id}: sealed corpus must have digestStatus=sealed")
|
| 54 |
-
|
| 55 |
-
judges = entry.get("judges", [])
|
| 56 |
-
judge_ids = {judge.get("id") for judge in judges}
|
| 57 |
-
for required_judge in ["raw_grader", "proof_judge", "provenance_judge"]:
|
| 58 |
-
if required_judge not in judge_ids:
|
| 59 |
-
errors.append(f"{entry_id}: missing judge {required_judge}")
|
| 60 |
-
|
| 61 |
-
receipts = entry.get("receipts", {})
|
| 62 |
-
if receipts.get("required") is not True:
|
| 63 |
-
errors.append(f"{entry_id}: receipts.required must be true")
|
| 64 |
-
if receipts.get("chain") != "hash_chain":
|
| 65 |
-
errors.append(f"{entry_id}: receipts.chain must be hash_chain")
|
| 66 |
-
|
| 67 |
-
for route in entry.get("formulaRoutes", []):
|
| 68 |
-
manifest_id = route.get("theoremRuntimeManifestId")
|
| 69 |
-
if manifest_id not in theorem_ids:
|
| 70 |
-
errors.append(f"{entry_id}: unknown formula route manifest ID {manifest_id}")
|
| 71 |
-
|
| 72 |
-
gates = set(entry.get("ciGates", []))
|
| 73 |
-
for gate in [
|
| 74 |
-
"validate-benchmark-map",
|
| 75 |
-
"verify-formula-routes",
|
| 76 |
-
"reject-unsupported-benchmark-claims",
|
| 77 |
-
]:
|
| 78 |
-
if gate not in gates:
|
| 79 |
-
errors.append(f"{entry_id}: missing CI gate {gate}")
|
| 80 |
-
|
| 81 |
-
if errors:
|
| 82 |
-
print("Benchmark map validation failed:")
|
| 83 |
-
for error in errors:
|
| 84 |
-
print(f" - {error}")
|
| 85 |
-
return 1
|
| 86 |
-
|
| 87 |
-
print(f"Validated {BENCHMARK_MAP.relative_to(REPO_ROOT)} ({len(entries)} entries)")
|
| 88 |
-
return 0
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
if __name__ == "__main__":
|
| 92 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,124 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the original A11oy controls evidence map."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import re
|
| 8 |
-
import sys
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 13 |
-
MAP_PATH = REPO_ROOT / "docs" / "controls-evidence-map.json"
|
| 14 |
-
|
| 15 |
-
ALLOWED_STATUSES = {
|
| 16 |
-
"verified-runtime",
|
| 17 |
-
"release-payload",
|
| 18 |
-
"lean-backed-current-green",
|
| 19 |
-
"lean-backed-needs-upstream-ci",
|
| 20 |
-
"thesis-anchor",
|
| 21 |
-
"historical",
|
| 22 |
-
"roadmap",
|
| 23 |
-
}
|
| 24 |
-
CONTROL_ID = re.compile(r"^A11OY-CE-\d{3}$")
|
| 25 |
-
FORBIDDEN_HF = {"canonical", "source-of-truth"}
|
| 26 |
-
FORBIDDEN_UDS = {"catalog-grade", "catalog-accepted", "endorsed"}
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def load_json(path: Path) -> dict:
|
| 30 |
-
return json.loads(path.read_text(encoding="utf-8"))
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def main() -> int:
|
| 34 |
-
errors: list[str] = []
|
| 35 |
-
data = load_json(MAP_PATH)
|
| 36 |
-
|
| 37 |
-
if "no external control catalog" not in data.get("cleanRoomRule", "").lower():
|
| 38 |
-
errors.append("cleanRoomRule must reject copied external control catalogs")
|
| 39 |
-
|
| 40 |
-
controls = data.get("controls", [])
|
| 41 |
-
if not isinstance(controls, list) or len(controls) < 5:
|
| 42 |
-
errors.append("controls must contain at least five controls")
|
| 43 |
-
controls = []
|
| 44 |
-
|
| 45 |
-
seen: set[str] = set()
|
| 46 |
-
required_fields = {
|
| 47 |
-
"controlId",
|
| 48 |
-
"title",
|
| 49 |
-
"description",
|
| 50 |
-
"claimStatus",
|
| 51 |
-
"evidencePaths",
|
| 52 |
-
"validationCommands",
|
| 53 |
-
"receiptHook",
|
| 54 |
-
"hfExposure",
|
| 55 |
-
"udsExposure",
|
| 56 |
-
"invariants",
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
for control in controls:
|
| 60 |
-
control_id = control.get("controlId", "<missing>")
|
| 61 |
-
if control_id in seen:
|
| 62 |
-
errors.append(f"duplicate controlId: {control_id}")
|
| 63 |
-
seen.add(control_id)
|
| 64 |
-
|
| 65 |
-
if not CONTROL_ID.match(control_id):
|
| 66 |
-
errors.append(f"{control_id}: controlId must match A11OY-CE-###")
|
| 67 |
-
|
| 68 |
-
missing = sorted(required_fields - control.keys())
|
| 69 |
-
if missing:
|
| 70 |
-
errors.append(f"{control_id}: missing fields: {', '.join(missing)}")
|
| 71 |
-
|
| 72 |
-
status = control.get("claimStatus")
|
| 73 |
-
if status not in ALLOWED_STATUSES:
|
| 74 |
-
errors.append(f"{control_id}: unsupported claimStatus {status!r}")
|
| 75 |
-
|
| 76 |
-
evidence_paths = control.get("evidencePaths", [])
|
| 77 |
-
if not isinstance(evidence_paths, list) or not evidence_paths:
|
| 78 |
-
errors.append(f"{control_id}: evidencePaths must be a non-empty list")
|
| 79 |
-
for evidence in evidence_paths:
|
| 80 |
-
if not (REPO_ROOT / evidence).exists():
|
| 81 |
-
errors.append(f"{control_id}: evidence path does not exist: {evidence}")
|
| 82 |
-
|
| 83 |
-
commands = control.get("validationCommands", [])
|
| 84 |
-
if not isinstance(commands, list) or not commands:
|
| 85 |
-
errors.append(f"{control_id}: validationCommands must be a non-empty list")
|
| 86 |
-
|
| 87 |
-
receipt_hook = control.get("receiptHook", {})
|
| 88 |
-
if not receipt_hook.get("eventType") or not receipt_hook.get("status"):
|
| 89 |
-
errors.append(f"{control_id}: receiptHook requires eventType and status")
|
| 90 |
-
if receipt_hook.get("status") not in {"runtime-available", "roadmap", "staged"}:
|
| 91 |
-
errors.append(f"{control_id}: unsupported receiptHook.status {receipt_hook.get('status')!r}")
|
| 92 |
-
|
| 93 |
-
if status == "verified-runtime" and receipt_hook.get("status") != "runtime-available":
|
| 94 |
-
errors.append(f"{control_id}: verified-runtime controls need runtime-available receipt hook")
|
| 95 |
-
|
| 96 |
-
hf_exposure = control.get("hfExposure", "").lower()
|
| 97 |
-
if hf_exposure in FORBIDDEN_HF:
|
| 98 |
-
errors.append(f"{control_id}: hfExposure cannot be canonical/source-of-truth")
|
| 99 |
-
|
| 100 |
-
uds_exposure = control.get("udsExposure", "").lower()
|
| 101 |
-
if uds_exposure in FORBIDDEN_UDS:
|
| 102 |
-
errors.append(f"{control_id}: udsExposure cannot imply catalog/endorsement")
|
| 103 |
-
|
| 104 |
-
invariants = control.get("invariants", [])
|
| 105 |
-
if not isinstance(invariants, list) or not invariants:
|
| 106 |
-
errors.append(f"{control_id}: invariants must be a non-empty list")
|
| 107 |
-
|
| 108 |
-
required = {"A11OY-CE-001", "A11OY-CE-002", "A11OY-CE-005", "A11OY-CE-008"}
|
| 109 |
-
missing_required = sorted(required - seen)
|
| 110 |
-
if missing_required:
|
| 111 |
-
errors.append(f"missing required controls: {', '.join(missing_required)}")
|
| 112 |
-
|
| 113 |
-
if errors:
|
| 114 |
-
print("Controls evidence map validation failed:")
|
| 115 |
-
for error in errors:
|
| 116 |
-
print(f" - {error}")
|
| 117 |
-
return 1
|
| 118 |
-
|
| 119 |
-
print(f"Validated {MAP_PATH.relative_to(REPO_ROOT)} ({len(controls)} controls)")
|
| 120 |
-
return 0
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
if __name__ == "__main__":
|
| 124 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,140 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the cross-repo handoff manifest."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import hashlib
|
| 7 |
-
import json
|
| 8 |
-
import sys
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 13 |
-
MANIFEST = REPO_ROOT / "docs" / "cross-repo-handoff-manifest.json"
|
| 14 |
-
ACCESS = REPO_ROOT / "docs" / "github-enterprise-access-checklist.json"
|
| 15 |
-
|
| 16 |
-
ALLOWED_ACCESS_STATES = {"blocked-by-access", "write-ready"}
|
| 17 |
-
ALLOWED_HANDOFF_STATES = {
|
| 18 |
-
"ready-for-owner-apply",
|
| 19 |
-
"needs-target-runner",
|
| 20 |
-
"blocked-by-access",
|
| 21 |
-
"complete",
|
| 22 |
-
}
|
| 23 |
-
ALLOWED_CLAIM_STATUSES = {
|
| 24 |
-
"verified-runtime",
|
| 25 |
-
"release-payload",
|
| 26 |
-
"lean-backed-needs-upstream-ci",
|
| 27 |
-
"roadmap",
|
| 28 |
-
}
|
| 29 |
-
FORBIDDEN_COMPLETE_PHRASES = [
|
| 30 |
-
"production-ready",
|
| 31 |
-
"all green",
|
| 32 |
-
"zero sorry",
|
| 33 |
-
"catalog accepted",
|
| 34 |
-
"endorsed",
|
| 35 |
-
"deployed to target repo",
|
| 36 |
-
]
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def sha256_file(path: Path) -> str:
|
| 40 |
-
digest = hashlib.sha256()
|
| 41 |
-
with path.open("rb") as handle:
|
| 42 |
-
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
| 43 |
-
digest.update(chunk)
|
| 44 |
-
return digest.hexdigest()
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def main() -> int:
|
| 48 |
-
errors: list[str] = []
|
| 49 |
-
manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
|
| 50 |
-
access = json.loads(ACCESS.read_text(encoding="utf-8"))
|
| 51 |
-
target_repos = {entry["repo"] for entry in access.get("targetRepos", [])}
|
| 52 |
-
|
| 53 |
-
rule = manifest.get("canonicalRule", "").lower()
|
| 54 |
-
if "not complete until" not in rule or "target repo" not in rule:
|
| 55 |
-
errors.append("canonicalRule must say handoffs are not complete until target repo evidence exists")
|
| 56 |
-
|
| 57 |
-
forbidden_claims = {claim.lower() for claim in manifest.get("forbiddenClaims", [])}
|
| 58 |
-
for phrase in FORBIDDEN_COMPLETE_PHRASES:
|
| 59 |
-
if phrase not in forbidden_claims:
|
| 60 |
-
errors.append(f"forbiddenClaims missing {phrase!r}")
|
| 61 |
-
|
| 62 |
-
handoffs = manifest.get("handoffs", [])
|
| 63 |
-
if not isinstance(handoffs, list) or not handoffs:
|
| 64 |
-
errors.append("handoffs must be a non-empty list")
|
| 65 |
-
handoffs = []
|
| 66 |
-
|
| 67 |
-
seen: set[str] = set()
|
| 68 |
-
required_fields = {
|
| 69 |
-
"handoffId",
|
| 70 |
-
"targetRepo",
|
| 71 |
-
"targetBranch",
|
| 72 |
-
"patchPath",
|
| 73 |
-
"statusPath",
|
| 74 |
-
"patchSha256",
|
| 75 |
-
"accessState",
|
| 76 |
-
"handoffState",
|
| 77 |
-
"localValidation",
|
| 78 |
-
"targetValidationRequired",
|
| 79 |
-
"completionRequires",
|
| 80 |
-
"claimStatus",
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
for handoff in handoffs:
|
| 84 |
-
handoff_id = handoff.get("handoffId", "<missing>")
|
| 85 |
-
if handoff_id in seen:
|
| 86 |
-
errors.append(f"duplicate handoffId: {handoff_id}")
|
| 87 |
-
seen.add(handoff_id)
|
| 88 |
-
|
| 89 |
-
missing = sorted(required_fields - handoff.keys())
|
| 90 |
-
if missing:
|
| 91 |
-
errors.append(f"{handoff_id}: missing fields: {', '.join(missing)}")
|
| 92 |
-
|
| 93 |
-
target_repo = handoff.get("targetRepo")
|
| 94 |
-
if target_repo not in target_repos:
|
| 95 |
-
errors.append(f"{handoff_id}: targetRepo not in access checklist: {target_repo}")
|
| 96 |
-
|
| 97 |
-
if handoff.get("accessState") not in ALLOWED_ACCESS_STATES:
|
| 98 |
-
errors.append(f"{handoff_id}: unsupported accessState {handoff.get('accessState')!r}")
|
| 99 |
-
if handoff.get("handoffState") not in ALLOWED_HANDOFF_STATES:
|
| 100 |
-
errors.append(f"{handoff_id}: unsupported handoffState {handoff.get('handoffState')!r}")
|
| 101 |
-
if handoff.get("claimStatus") not in ALLOWED_CLAIM_STATUSES:
|
| 102 |
-
errors.append(f"{handoff_id}: unsupported claimStatus {handoff.get('claimStatus')!r}")
|
| 103 |
-
|
| 104 |
-
patch_path = REPO_ROOT / str(handoff.get("patchPath", ""))
|
| 105 |
-
status_path = REPO_ROOT / str(handoff.get("statusPath", ""))
|
| 106 |
-
if not patch_path.exists():
|
| 107 |
-
errors.append(f"{handoff_id}: patchPath does not exist: {handoff.get('patchPath')}")
|
| 108 |
-
else:
|
| 109 |
-
actual = sha256_file(patch_path)
|
| 110 |
-
if actual != handoff.get("patchSha256"):
|
| 111 |
-
errors.append(f"{handoff_id}: patchSha256 mismatch: expected {handoff.get('patchSha256')}, got {actual}")
|
| 112 |
-
if not status_path.exists():
|
| 113 |
-
errors.append(f"{handoff_id}: statusPath does not exist: {handoff.get('statusPath')}")
|
| 114 |
-
|
| 115 |
-
for list_field in ["localValidation", "targetValidationRequired", "completionRequires"]:
|
| 116 |
-
if not isinstance(handoff.get(list_field), list) or not handoff.get(list_field):
|
| 117 |
-
errors.append(f"{handoff_id}: {list_field} must be a non-empty list")
|
| 118 |
-
|
| 119 |
-
if handoff.get("handoffState") == "complete":
|
| 120 |
-
completion = " ".join(handoff.get("completionRequires", [])).lower()
|
| 121 |
-
if "target ci green" not in completion or "target pr" not in completion:
|
| 122 |
-
errors.append(f"{handoff_id}: complete handoff requires target PR and target CI evidence")
|
| 123 |
-
|
| 124 |
-
if target_repo == "szl-holdings/lutar-lean":
|
| 125 |
-
target_validation = " ".join(handoff.get("targetValidationRequired", [])).lower()
|
| 126 |
-
if "lake build" not in target_validation:
|
| 127 |
-
errors.append(f"{handoff_id}: lutar-lean handoff must require lake build")
|
| 128 |
-
|
| 129 |
-
if errors:
|
| 130 |
-
print("Cross-repo handoff manifest validation failed:")
|
| 131 |
-
for error in errors:
|
| 132 |
-
print(f" - {error}")
|
| 133 |
-
return 1
|
| 134 |
-
|
| 135 |
-
print(f"Validated {MANIFEST.relative_to(REPO_ROOT)} ({len(handoffs)} handoffs)")
|
| 136 |
-
return 0
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
if __name__ == "__main__":
|
| 140 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,88 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the GitHub Enterprise access checklist."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import sys
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
-
CHECKLIST = REPO_ROOT / "docs" / "github-enterprise-access-checklist.json"
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def main() -> int:
|
| 16 |
-
errors: list[str] = []
|
| 17 |
-
data = json.loads(CHECKLIST.read_text(encoding="utf-8"))
|
| 18 |
-
|
| 19 |
-
if data.get("seatsAloneGrantWriteAccess") is not False:
|
| 20 |
-
errors.append("seatsAloneGrantWriteAccess must be false")
|
| 21 |
-
|
| 22 |
-
if data.get("currentKnownWritableRepo") != "szl-holdings/a11oy":
|
| 23 |
-
errors.append("currentKnownWritableRepo must be szl-holdings/a11oy")
|
| 24 |
-
|
| 25 |
-
rule = data.get("canonicalRule", "").lower()
|
| 26 |
-
for phrase in ["accepted org membership", "repo/team write permission", "token or github app scope"]:
|
| 27 |
-
if phrase not in rule:
|
| 28 |
-
errors.append(f"canonicalRule must mention {phrase!r}")
|
| 29 |
-
|
| 30 |
-
scopes = " ".join(data.get("requiredTokenScopes", [])).lower()
|
| 31 |
-
for required in ["contents: read and write", "sso authorization"]:
|
| 32 |
-
if required not in scopes:
|
| 33 |
-
errors.append(f"requiredTokenScopes must mention {required!r}")
|
| 34 |
-
|
| 35 |
-
checks = data.get("readOnlyChecks", [])
|
| 36 |
-
if not isinstance(checks, list) or not checks:
|
| 37 |
-
errors.append("readOnlyChecks must be a non-empty list")
|
| 38 |
-
for command in checks:
|
| 39 |
-
if not isinstance(command, str) or not command.startswith("gh "):
|
| 40 |
-
errors.append(f"readOnlyChecks must use gh read-only commands, got {command!r}")
|
| 41 |
-
forbidden = [" pr create", " pr merge", " issue create", " repo edit", " api -X PATCH", " api -X POST", " api -X PUT", " api -X DELETE"]
|
| 42 |
-
if any(token in command for token in forbidden):
|
| 43 |
-
errors.append(f"readOnlyChecks contains write-like command: {command}")
|
| 44 |
-
|
| 45 |
-
targets = data.get("targetRepos", [])
|
| 46 |
-
if not isinstance(targets, list) or len(targets) < 8:
|
| 47 |
-
errors.append("targetRepos must include the sibling repos needed for cross-repo phases")
|
| 48 |
-
targets = []
|
| 49 |
-
|
| 50 |
-
repos = set()
|
| 51 |
-
for target in targets:
|
| 52 |
-
repo = target.get("repo")
|
| 53 |
-
if repo in repos:
|
| 54 |
-
errors.append(f"duplicate target repo: {repo}")
|
| 55 |
-
repos.add(repo)
|
| 56 |
-
if target.get("minimumPermission") != "write":
|
| 57 |
-
errors.append(f"{repo}: minimumPermission must be write")
|
| 58 |
-
for field in ["phaseUnlocked", "currentFallback"]:
|
| 59 |
-
if not target.get(field):
|
| 60 |
-
errors.append(f"{repo}: missing {field}")
|
| 61 |
-
|
| 62 |
-
for required_repo in [
|
| 63 |
-
"szl-holdings/.github",
|
| 64 |
-
"szl-holdings/lutar-lean",
|
| 65 |
-
"szl-holdings/agi-forecast",
|
| 66 |
-
"szl-holdings/uds-mesh",
|
| 67 |
-
"szl-holdings/vessels",
|
| 68 |
-
]:
|
| 69 |
-
if required_repo not in repos:
|
| 70 |
-
errors.append(f"missing target repo: {required_repo}")
|
| 71 |
-
|
| 72 |
-
boundaries = " ".join(data.get("doctrineBoundaries", [])).lower()
|
| 73 |
-
for phrase in ["do not commit tokens", "do not claim all lean green", "do not claim defense unicorns endorsement"]:
|
| 74 |
-
if phrase not in boundaries:
|
| 75 |
-
errors.append(f"doctrineBoundaries must include {phrase!r}")
|
| 76 |
-
|
| 77 |
-
if errors:
|
| 78 |
-
print("GitHub access checklist validation failed:")
|
| 79 |
-
for error in errors:
|
| 80 |
-
print(f" - {error}")
|
| 81 |
-
return 1
|
| 82 |
-
|
| 83 |
-
print(f"Validated {CHECKLIST.relative_to(REPO_ROOT)} ({len(targets)} target repos)")
|
| 84 |
-
return 0
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
if __name__ == "__main__":
|
| 88 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,91 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the staged Hugging Face test-results manifest."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import sys
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
-
MANIFEST_PATH = REPO_ROOT / "huggingface" / "test-results" / "MANIFEST.json"
|
| 13 |
-
BENCHMARK_MAP = REPO_ROOT / "benchmarks" / "benchmark-map.json"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def load_json(path: Path) -> dict:
|
| 17 |
-
return json.loads(path.read_text(encoding="utf-8"))
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def main() -> int:
|
| 21 |
-
errors: list[str] = []
|
| 22 |
-
manifest = load_json(MANIFEST_PATH)
|
| 23 |
-
benchmark_map = load_json(BENCHMARK_MAP)
|
| 24 |
-
|
| 25 |
-
publication = manifest.get("publication", {})
|
| 26 |
-
if publication.get("repo_type") != "dataset":
|
| 27 |
-
errors.append("publication.repo_type must be dataset")
|
| 28 |
-
if publication.get("publish_mode") != "mirror-not-canonical":
|
| 29 |
-
errors.append("publication.publish_mode must be mirror-not-canonical")
|
| 30 |
-
if publication.get("canonical_source") != "https://github.com/szl-holdings/a11oy":
|
| 31 |
-
errors.append("publication.canonical_source must point to a11oy GitHub")
|
| 32 |
-
|
| 33 |
-
if manifest.get("claim_status") != "staged-no-live-score":
|
| 34 |
-
errors.append("claim_status must remain staged-no-live-score until sealed results exist")
|
| 35 |
-
|
| 36 |
-
disallowed = {claim.lower() for claim in manifest.get("disallowed_claims", [])}
|
| 37 |
-
for phrase in ["solved the benchmark", "beat the benchmark", "agi proven", "hf is canonical"]:
|
| 38 |
-
if phrase not in disallowed:
|
| 39 |
-
errors.append(f"disallowed_claims missing {phrase!r}")
|
| 40 |
-
|
| 41 |
-
allowed_text = " ".join(manifest.get("allowed_public_wording", [])).lower()
|
| 42 |
-
for forbidden in ["cracked", "solved", "leaderboard"]:
|
| 43 |
-
if forbidden in allowed_text:
|
| 44 |
-
errors.append(f"allowed_public_wording contains unsupported word {forbidden!r}")
|
| 45 |
-
|
| 46 |
-
benchmark_ref = manifest.get("benchmark_map", {})
|
| 47 |
-
if benchmark_ref.get("path") != "benchmarks/benchmark-map.json":
|
| 48 |
-
errors.append("benchmark_map.path must be benchmarks/benchmark-map.json")
|
| 49 |
-
entry_id = benchmark_ref.get("entry_id")
|
| 50 |
-
map_entry_ids = {entry.get("id") for entry in benchmark_map.get("entries", [])}
|
| 51 |
-
if entry_id not in map_entry_ids:
|
| 52 |
-
errors.append(f"benchmark_map.entry_id not found in benchmark map: {entry_id}")
|
| 53 |
-
|
| 54 |
-
corpus = manifest.get("corpus", {})
|
| 55 |
-
if corpus.get("sealed") is not False:
|
| 56 |
-
errors.append("corpus.sealed must be false in staged manifest")
|
| 57 |
-
if corpus.get("problem_text_included") is not False:
|
| 58 |
-
errors.append("corpus.problem_text_included must be false")
|
| 59 |
-
if int(corpus.get("problem_count", -1)) != 0:
|
| 60 |
-
errors.append("corpus.problem_count must be 0 until corpus is sealed")
|
| 61 |
-
|
| 62 |
-
runs = manifest.get("runs", [])
|
| 63 |
-
if runs:
|
| 64 |
-
errors.append("runs must be empty until a sealed receipt-backed run exists")
|
| 65 |
-
|
| 66 |
-
# Guard against accidentally adding live-looking result/receipt files before
|
| 67 |
-
# the benchmark doctrine gates are implemented.
|
| 68 |
-
for forbidden_dir in [
|
| 69 |
-
REPO_ROOT / "huggingface" / "test-results" / "results",
|
| 70 |
-
REPO_ROOT / "huggingface" / "test-results" / "receipts",
|
| 71 |
-
]:
|
| 72 |
-
if forbidden_dir.exists() and any(forbidden_dir.rglob("*")):
|
| 73 |
-
errors.append(f"{forbidden_dir.relative_to(REPO_ROOT)} must remain empty in staged manifest")
|
| 74 |
-
|
| 75 |
-
commands = manifest.get("validation", {}).get("commands", [])
|
| 76 |
-
for command in ["npm run hf:test-results:audit", "npm run benchmark:audit"]:
|
| 77 |
-
if command not in commands:
|
| 78 |
-
errors.append(f"validation.commands missing {command}")
|
| 79 |
-
|
| 80 |
-
if errors:
|
| 81 |
-
print("HF test-results manifest validation failed:")
|
| 82 |
-
for error in errors:
|
| 83 |
-
print(f" - {error}")
|
| 84 |
-
return 1
|
| 85 |
-
|
| 86 |
-
print(f"Validated {MANIFEST_PATH.relative_to(REPO_ROOT)}")
|
| 87 |
-
return 0
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
if __name__ == "__main__":
|
| 91 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate A11oy phase completion manifest."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import sys
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
-
MANIFEST = REPO_ROOT / "docs" / "phase-completion-manifest.json"
|
| 13 |
-
REPORT = REPO_ROOT / "docs" / "PHASE_COMPLETION_REPORT.md"
|
| 14 |
-
|
| 15 |
-
ALLOWED_STATUSES = {
|
| 16 |
-
"complete-for-current-branch",
|
| 17 |
-
"runtime-helper-complete",
|
| 18 |
-
"runtime-helper-complete-harness-staged",
|
| 19 |
-
"schema-complete-no-live-score",
|
| 20 |
-
"access-pending-handoff-queued",
|
| 21 |
-
"generated-payload-ready",
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def main() -> int:
|
| 26 |
-
errors: list[str] = []
|
| 27 |
-
data = json.loads(MANIFEST.read_text(encoding="utf-8"))
|
| 28 |
-
|
| 29 |
-
if not REPORT.exists():
|
| 30 |
-
errors.append("PHASE_COMPLETION_REPORT.md is missing")
|
| 31 |
-
|
| 32 |
-
rule = data.get("canonicalRule", "").lower()
|
| 33 |
-
if "sibling repo phases remain access-pending" not in rule:
|
| 34 |
-
errors.append("canonicalRule must keep sibling repo phases access-pending")
|
| 35 |
-
if data.get("a11oyLocalStatus") != "complete-for-current-branch":
|
| 36 |
-
errors.append("a11oyLocalStatus must be complete-for-current-branch")
|
| 37 |
-
if data.get("crossRepoStatus") != "access-pending-handoff-queued":
|
| 38 |
-
errors.append("crossRepoStatus must be access-pending-handoff-queued")
|
| 39 |
-
|
| 40 |
-
forbidden = " ".join(data.get("forbiddenClaims", [])).lower()
|
| 41 |
-
for phrase in ["zero sorry", "solved the benchmark", "uds catalog accepted", "hf is canonical"]:
|
| 42 |
-
if phrase not in forbidden:
|
| 43 |
-
errors.append(f"forbiddenClaims missing {phrase!r}")
|
| 44 |
-
|
| 45 |
-
phases = data.get("phases", [])
|
| 46 |
-
if not isinstance(phases, list) or len(phases) < 7:
|
| 47 |
-
errors.append("phases must contain at least seven phase entries")
|
| 48 |
-
phases = []
|
| 49 |
-
|
| 50 |
-
seen: set[str] = set()
|
| 51 |
-
for phase in phases:
|
| 52 |
-
phase_id = phase.get("id", "<missing>")
|
| 53 |
-
if phase_id in seen:
|
| 54 |
-
errors.append(f"duplicate phase id: {phase_id}")
|
| 55 |
-
seen.add(phase_id)
|
| 56 |
-
if phase.get("status") not in ALLOWED_STATUSES:
|
| 57 |
-
errors.append(f"{phase_id}: unsupported status {phase.get('status')!r}")
|
| 58 |
-
artifacts = phase.get("artifacts", [])
|
| 59 |
-
if not isinstance(artifacts, list) or not artifacts:
|
| 60 |
-
errors.append(f"{phase_id}: artifacts must be non-empty")
|
| 61 |
-
for artifact in artifacts:
|
| 62 |
-
if not (REPO_ROOT / artifact).exists():
|
| 63 |
-
errors.append(f"{phase_id}: artifact does not exist: {artifact}")
|
| 64 |
-
commands = phase.get("validationCommands", [])
|
| 65 |
-
if not isinstance(commands, list) or not commands:
|
| 66 |
-
errors.append(f"{phase_id}: validationCommands must be non-empty")
|
| 67 |
-
|
| 68 |
-
requires = " ".join(data.get("completionRequiresForSiblingRepos", [])).lower()
|
| 69 |
-
for phrase in ["target repo write-ready access", "target ci green"]:
|
| 70 |
-
if phrase not in requires:
|
| 71 |
-
errors.append(f"completionRequiresForSiblingRepos missing {phrase!r}")
|
| 72 |
-
|
| 73 |
-
if errors:
|
| 74 |
-
print("Phase completion manifest validation failed:")
|
| 75 |
-
for error in errors:
|
| 76 |
-
print(f" - {error}")
|
| 77 |
-
return 1
|
| 78 |
-
|
| 79 |
-
print(f"Validated {MANIFEST.relative_to(REPO_ROOT)} ({len(phases)} phases)")
|
| 80 |
-
return 0
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
if __name__ == "__main__":
|
| 84 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,141 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the public-pattern synthesis manifest.
|
| 3 |
-
|
| 4 |
-
The manifest is a clean-room guardrail: public sources can inspire original
|
| 5 |
-
SZL/A11oy work, but private/unlicensed copying is not allowed.
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
-
from __future__ import annotations
|
| 9 |
-
|
| 10 |
-
import json
|
| 11 |
-
import sys
|
| 12 |
-
from pathlib import Path
|
| 13 |
-
from urllib.parse import urlparse
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 17 |
-
MANIFEST_PATH = REPO_ROOT / "docs" / "public-pattern-source-manifest.json"
|
| 18 |
-
|
| 19 |
-
ALLOWED_STATUSES = {
|
| 20 |
-
"verified-runtime",
|
| 21 |
-
"release-payload",
|
| 22 |
-
"lean-backed-current-green",
|
| 23 |
-
"lean-backed-needs-upstream-ci",
|
| 24 |
-
"thesis-anchor",
|
| 25 |
-
"historical",
|
| 26 |
-
"roadmap",
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
def load_json(path: Path) -> dict:
|
| 31 |
-
return json.loads(path.read_text(encoding="utf-8"))
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def is_public_url(value: str) -> bool:
|
| 35 |
-
parsed = urlparse(value)
|
| 36 |
-
return parsed.scheme in {"https", "http"} and bool(parsed.netloc)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def main() -> int:
|
| 40 |
-
errors: list[str] = []
|
| 41 |
-
manifest = load_json(MANIFEST_PATH)
|
| 42 |
-
|
| 43 |
-
if manifest.get("privateIngestionAllowed") is not False:
|
| 44 |
-
errors.append("privateIngestionAllowed must be false")
|
| 45 |
-
|
| 46 |
-
copying_rule = manifest.get("copyingRule", "").lower()
|
| 47 |
-
for required in ["pattern-only", "no upstream code", "private material"]:
|
| 48 |
-
if required not in copying_rule:
|
| 49 |
-
errors.append(f"copyingRule must include {required!r}")
|
| 50 |
-
|
| 51 |
-
if "endorsement" not in manifest.get("endorsementBoundary", "").lower():
|
| 52 |
-
errors.append("endorsementBoundary must explicitly reject implied endorsement")
|
| 53 |
-
|
| 54 |
-
queues = manifest.get("sourceQueues", [])
|
| 55 |
-
if not isinstance(queues, list) or not queues:
|
| 56 |
-
errors.append("sourceQueues must be a non-empty list")
|
| 57 |
-
queues = []
|
| 58 |
-
|
| 59 |
-
queue_ids: set[str] = set()
|
| 60 |
-
for queue in queues:
|
| 61 |
-
queue_id = queue.get("id", "<missing>")
|
| 62 |
-
if queue_id in queue_ids:
|
| 63 |
-
errors.append(f"duplicate source queue id: {queue_id}")
|
| 64 |
-
queue_ids.add(queue_id)
|
| 65 |
-
|
| 66 |
-
public_url = queue.get("publicUrl")
|
| 67 |
-
if not isinstance(public_url, str) or not is_public_url(public_url):
|
| 68 |
-
errors.append(f"{queue_id}: publicUrl must be an http(s) URL")
|
| 69 |
-
|
| 70 |
-
audit_mode = queue.get("auditMode", "")
|
| 71 |
-
if "public" not in audit_mode and "authorized" not in audit_mode:
|
| 72 |
-
errors.append(f"{queue_id}: auditMode must be public/authorized scoped")
|
| 73 |
-
|
| 74 |
-
patterns = manifest.get("patterns", [])
|
| 75 |
-
if not isinstance(patterns, list) or not patterns:
|
| 76 |
-
errors.append("patterns must be a non-empty list")
|
| 77 |
-
patterns = []
|
| 78 |
-
|
| 79 |
-
pattern_ids: set[str] = set()
|
| 80 |
-
required_pattern_fields = {
|
| 81 |
-
"id",
|
| 82 |
-
"name",
|
| 83 |
-
"sourceQueueIds",
|
| 84 |
-
"publicSourceCategories",
|
| 85 |
-
"licenseCaveat",
|
| 86 |
-
"a11oyTransform",
|
| 87 |
-
"localEvidence",
|
| 88 |
-
"validationCommands",
|
| 89 |
-
"claimStatus",
|
| 90 |
-
}
|
| 91 |
-
for pattern in patterns:
|
| 92 |
-
pattern_id = pattern.get("id", "<missing>")
|
| 93 |
-
if pattern_id in pattern_ids:
|
| 94 |
-
errors.append(f"duplicate pattern id: {pattern_id}")
|
| 95 |
-
pattern_ids.add(pattern_id)
|
| 96 |
-
|
| 97 |
-
missing = sorted(required_pattern_fields - pattern.keys())
|
| 98 |
-
if missing:
|
| 99 |
-
errors.append(f"{pattern_id}: missing fields: {', '.join(missing)}")
|
| 100 |
-
|
| 101 |
-
if pattern.get("claimStatus") not in ALLOWED_STATUSES:
|
| 102 |
-
errors.append(f"{pattern_id}: unsupported claimStatus {pattern.get('claimStatus')!r}")
|
| 103 |
-
|
| 104 |
-
for queue_id in pattern.get("sourceQueueIds", []):
|
| 105 |
-
if queue_id not in queue_ids:
|
| 106 |
-
errors.append(f"{pattern_id}: unknown sourceQueueId {queue_id}")
|
| 107 |
-
|
| 108 |
-
license_caveat = pattern.get("licenseCaveat", "").lower()
|
| 109 |
-
if not any(token in license_caveat for token in ["copy", "license", "redistribute"]):
|
| 110 |
-
errors.append(f"{pattern_id}: licenseCaveat must state copying/license boundary")
|
| 111 |
-
|
| 112 |
-
transform = pattern.get("a11oyTransform", "").lower()
|
| 113 |
-
if "a11oy" not in transform and "szl" not in transform:
|
| 114 |
-
errors.append(f"{pattern_id}: a11oyTransform must describe original SZL/A11oy work")
|
| 115 |
-
|
| 116 |
-
local_evidence = pattern.get("localEvidence", [])
|
| 117 |
-
if not isinstance(local_evidence, list) or not local_evidence:
|
| 118 |
-
errors.append(f"{pattern_id}: localEvidence must be a non-empty list")
|
| 119 |
-
for evidence in local_evidence:
|
| 120 |
-
# URLs are allowed as evidence, but local paths should exist when
|
| 121 |
-
# they are part of this checkout.
|
| 122 |
-
if isinstance(evidence, str) and not is_public_url(evidence):
|
| 123 |
-
if not (REPO_ROOT / evidence).exists():
|
| 124 |
-
errors.append(f"{pattern_id}: local evidence path does not exist: {evidence}")
|
| 125 |
-
|
| 126 |
-
commands = pattern.get("validationCommands", [])
|
| 127 |
-
if not isinstance(commands, list) or not commands:
|
| 128 |
-
errors.append(f"{pattern_id}: validationCommands must be a non-empty list")
|
| 129 |
-
|
| 130 |
-
if errors:
|
| 131 |
-
print("Public pattern manifest validation failed:")
|
| 132 |
-
for error in errors:
|
| 133 |
-
print(f" - {error}")
|
| 134 |
-
return 1
|
| 135 |
-
|
| 136 |
-
print(f"Validated {MANIFEST_PATH.relative_to(REPO_ROOT)} ({len(patterns)} patterns)")
|
| 137 |
-
return 0
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
if __name__ == "__main__":
|
| 141 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,86 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Validate the A11oy theorem-to-runtime manifest."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import argparse
|
| 7 |
-
import json
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
REPO_ROOT = Path.cwd()
|
| 12 |
-
MANIFEST = REPO_ROOT / "docs" / "theorem-runtime-manifest.json"
|
| 13 |
-
VALID_STATUSES = {
|
| 14 |
-
"verified-runtime",
|
| 15 |
-
"lean-backed-current-green",
|
| 16 |
-
"lean-backed-needs-upstream-ci",
|
| 17 |
-
"lean-backed-needs-runtime",
|
| 18 |
-
"historical-roadmap",
|
| 19 |
-
"roadmap",
|
| 20 |
-
# staged-advisory: honest, NOT-proven status (SZL Doctrine v11). The gate
|
| 21 |
-
# ships enforced:false/severity:warning while its Lean proof is pending, so
|
| 22 |
-
# it must never be counted as proven. Honesty semantics enforced below.
|
| 23 |
-
"staged-advisory",
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
def main() -> int:
|
| 28 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 29 |
-
parser.add_argument("--manifest", default=str(MANIFEST))
|
| 30 |
-
args = parser.parse_args()
|
| 31 |
-
path = Path(args.manifest)
|
| 32 |
-
data = json.loads(path.read_text(encoding="utf-8"))
|
| 33 |
-
errors: list[str] = []
|
| 34 |
-
|
| 35 |
-
seen = set()
|
| 36 |
-
for entry in data.get("entries", []):
|
| 37 |
-
entry_id = entry.get("id")
|
| 38 |
-
if not entry_id:
|
| 39 |
-
errors.append("entry missing id")
|
| 40 |
-
continue
|
| 41 |
-
if entry_id in seen:
|
| 42 |
-
errors.append(f"duplicate entry id: {entry_id}")
|
| 43 |
-
seen.add(entry_id)
|
| 44 |
-
|
| 45 |
-
status = entry.get("claimStatus")
|
| 46 |
-
if status not in VALID_STATUSES:
|
| 47 |
-
errors.append(f"{entry_id}: invalid claimStatus {status}")
|
| 48 |
-
|
| 49 |
-
for field in ["runtimeFile", "exportFile", "testFile"]:
|
| 50 |
-
value = entry.get(field)
|
| 51 |
-
if value and not (REPO_ROOT / value).exists():
|
| 52 |
-
errors.append(f"{entry_id}: missing {field} path {value}")
|
| 53 |
-
|
| 54 |
-
if status == "verified-runtime" and not entry.get("validationCommand"):
|
| 55 |
-
errors.append(f"{entry_id}: verified-runtime requires validationCommand")
|
| 56 |
-
|
| 57 |
-
if status == "staged-advisory":
|
| 58 |
-
# Honesty guard (SZL Doctrine v11): staged-advisory entries are NOT
|
| 59 |
-
# proven. They must self-identify as advisory and carry a caveat so
|
| 60 |
-
# they can never be silently promoted into a proven claim.
|
| 61 |
-
if entry.get("stagedAdvisory") is not True:
|
| 62 |
-
errors.append(
|
| 63 |
-
f"{entry_id}: staged-advisory requires stagedAdvisory: true"
|
| 64 |
-
)
|
| 65 |
-
if not entry.get("caveat"):
|
| 66 |
-
errors.append(
|
| 67 |
-
f"{entry_id}: staged-advisory requires a caveat"
|
| 68 |
-
)
|
| 69 |
-
if entry.get("leanStatus") in {"proven", "verified", "lean-proven"}:
|
| 70 |
-
errors.append(
|
| 71 |
-
f"{entry_id}: staged-advisory cannot have leanStatus "
|
| 72 |
-
f"{entry.get('leanStatus')!r} (not yet proven)"
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
if errors:
|
| 76 |
-
print("Theorem runtime manifest failed:")
|
| 77 |
-
for error in errors:
|
| 78 |
-
print(f" - {error}")
|
| 79 |
-
return 1
|
| 80 |
-
|
| 81 |
-
print(f"Theorem runtime manifest OK: {len(seen)} entries")
|
| 82 |
-
return 0
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
if __name__ == "__main__":
|
| 86 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File without changes
|
|
@@ -1,163 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 3 |
-
# Doctrine v11 LOCKED 749/14/163 @ c7c0ba17 · Λ = Conjecture 1.
|
| 4 |
-
"""
|
| 5 |
-
test_be_hardening.py — real HTTP tests for the backend hardening surface.
|
| 6 |
-
|
| 7 |
-
Uses FastAPI's TestClient against a freshly hardened app. NO mocks: the Khipu
|
| 8 |
-
store writes to a real temp SQLite DB, the rate limiter counts real requests,
|
| 9 |
-
and OpenAPI is the real auto-generated schema. Restart durability is proven by
|
| 10 |
-
constructing a second DurableKhipu over the same on-disk path.
|
| 11 |
-
|
| 12 |
-
Run: pytest -q test_be_hardening.py
|
| 13 |
-
"""
|
| 14 |
-
from __future__ import annotations
|
| 15 |
-
|
| 16 |
-
import os
|
| 17 |
-
import tempfile
|
| 18 |
-
|
| 19 |
-
import pytest
|
| 20 |
-
from fastapi import FastAPI
|
| 21 |
-
from fastapi.testclient import TestClient
|
| 22 |
-
|
| 23 |
-
import szl_be_hardening as H
|
| 24 |
-
|
| 25 |
-
ORGAN = "testorgan"
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
@pytest.fixture()
|
| 29 |
-
def client(tmp_path):
|
| 30 |
-
app = FastAPI(title="hardening-test", version="0.0.0")
|
| 31 |
-
db_path = os.path.join(tmp_path, "khipu_test.sqlite3")
|
| 32 |
-
report = H.harden(app, organ=ORGAN, khipu_path=db_path)
|
| 33 |
-
assert report.get("ok") is True
|
| 34 |
-
c = TestClient(app)
|
| 35 |
-
c._db_path = db_path # type: ignore[attr-defined]
|
| 36 |
-
return c
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
# ---- 4: health probes ------------------------------------------------------
|
| 40 |
-
def test_healthz_liveness(client):
|
| 41 |
-
r = client.get("/healthz")
|
| 42 |
-
assert r.status_code == 200
|
| 43 |
-
body = r.json()
|
| 44 |
-
assert body["status"] == "ok"
|
| 45 |
-
assert body["doctrine"] == "v11"
|
| 46 |
-
assert body["lock"] == "749/14/163"
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
def test_readyz_checks_chain(client):
|
| 50 |
-
r = client.get(f"/api/{ORGAN}/v1/readyz")
|
| 51 |
-
assert r.status_code == 200
|
| 52 |
-
body = r.json()
|
| 53 |
-
assert body["status"] == "ready"
|
| 54 |
-
assert body["khipu_chain_ok"] is True
|
| 55 |
-
assert body["khipu_durable"] is True
|
| 56 |
-
assert body["khipu_backend"] == "sqlite"
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# ---- 1: real input validation (pydantic) -----------------------------------
|
| 60 |
-
def test_echo_valid(client):
|
| 61 |
-
r = client.post(f"/api/{ORGAN}/v1/be/echo", json={"message": "hi"})
|
| 62 |
-
assert r.status_code == 200
|
| 63 |
-
assert r.json()["echo"] == "hi"
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
def test_echo_rejects_raw_dict_extra_fields(client):
|
| 67 |
-
r = client.post(f"/api/{ORGAN}/v1/be/echo", json={"message": "hi", "evil": 1})
|
| 68 |
-
assert r.status_code == 422
|
| 69 |
-
assert r.json()["error"]["code"] == "validation_error"
|
| 70 |
-
assert r.json()["error"]["doctrine"] == "v11"
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
def test_echo_rejects_missing_field(client):
|
| 74 |
-
r = client.post(f"/api/{ORGAN}/v1/be/echo", json={})
|
| 75 |
-
assert r.status_code == 422
|
| 76 |
-
assert r.json()["error"]["doctrine"] == "v11"
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
# ---- 6: error envelopes ----------------------------------------------------
|
| 80 |
-
def test_error_envelope_on_404(client):
|
| 81 |
-
r = client.get("/api/nope/v1/does-not-exist")
|
| 82 |
-
assert r.status_code == 404
|
| 83 |
-
err = r.json()["error"]
|
| 84 |
-
assert set(err.keys()) >= {"code", "message", "trace_id", "doctrine"}
|
| 85 |
-
assert err["doctrine"] == "v11"
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
def test_trace_headers_present(client):
|
| 89 |
-
r = client.get("/healthz")
|
| 90 |
-
assert r.headers.get("X-Trace-Id")
|
| 91 |
-
assert r.headers.get("X-Span-Id")
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
# ---- 3: real OpenAPI -------------------------------------------------------
|
| 95 |
-
def test_openapi_served_at_organ_path(client):
|
| 96 |
-
r = client.get(f"/api/{ORGAN}/openapi.json")
|
| 97 |
-
assert r.status_code == 200
|
| 98 |
-
spec = r.json()
|
| 99 |
-
assert spec["openapi"].startswith("3.")
|
| 100 |
-
# real generated paths include our hardening endpoints
|
| 101 |
-
assert any("/khipu/verify" in p for p in spec["paths"])
|
| 102 |
-
assert any("/echo" in p for p in spec["paths"])
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
# ---- 7: durable persistence (survives restart) -----------------------------
|
| 106 |
-
def test_khipu_append_and_verify(client):
|
| 107 |
-
r = client.post(f"/api/{ORGAN}/v1/be/khipu/append",
|
| 108 |
-
json={"action": "test.action", "payload": {"k": 1}})
|
| 109 |
-
assert r.status_code == 200
|
| 110 |
-
assert r.json()["ok"] is True
|
| 111 |
-
v = client.get(f"/api/{ORGAN}/v1/be/khipu/verify").json()
|
| 112 |
-
assert v["ok"] is True
|
| 113 |
-
assert v["depth"] >= 1
|
| 114 |
-
assert v["durable"] is True
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
def test_khipu_survives_restart(client):
|
| 118 |
-
# append two receipts via the live API
|
| 119 |
-
for i in range(2):
|
| 120 |
-
client.post(f"/api/{ORGAN}/v1/be/khipu/append",
|
| 121 |
-
json={"action": f"a{i}", "payload": {"i": i}})
|
| 122 |
-
depth_before = client.get(f"/api/{ORGAN}/v1/be/khipu/verify").json()["depth"]
|
| 123 |
-
assert depth_before >= 2
|
| 124 |
-
# simulate a process restart: brand-new store over the SAME on-disk path
|
| 125 |
-
reopened = H.DurableKhipu(ORGAN, path=client._db_path)
|
| 126 |
-
ok, depth, brk = reopened.verify()
|
| 127 |
-
assert ok is True
|
| 128 |
-
assert depth == depth_before # receipts survived
|
| 129 |
-
assert brk == -1
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
def test_khipu_append_rejects_bad_body(client):
|
| 133 |
-
r = client.post(f"/api/{ORGAN}/v1/be/khipu/append", json={"payload": {}})
|
| 134 |
-
assert r.status_code == 422 # missing required 'action'
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
# ---- 9: honest footer matches the exact v11 lock ---------------------------
|
| 138 |
-
def test_honest_footer_exact_lock(client):
|
| 139 |
-
body = client.get("/honest").json()
|
| 140 |
-
lock = body["doctrine_lock"]
|
| 141 |
-
assert lock["doctrine"] == "v11"
|
| 142 |
-
assert lock["state"] == "LOCKED"
|
| 143 |
-
assert (lock["declarations"], lock["axioms"], lock["sorries"]) == (749, 14, 163)
|
| 144 |
-
assert lock["commit"] == "c7c0ba17"
|
| 145 |
-
assert lock["lambda"] == "Conjecture 1"
|
| 146 |
-
assert body["footer"] == "Doctrine v11 LOCKED 749/14/163 @ c7c0ba17 · Λ = Conjecture 1"
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
# ---- 2: rate limiting (60/min/IP) ------------------------------------------
|
| 150 |
-
def test_rate_limit_enforced():
|
| 151 |
-
# isolated app/client so other tests' requests don't pollute the window
|
| 152 |
-
app = FastAPI()
|
| 153 |
-
with tempfile.TemporaryDirectory() as d:
|
| 154 |
-
H.harden(app, organ="rl", khipu_path=os.path.join(d, "k.sqlite3"))
|
| 155 |
-
c = TestClient(app)
|
| 156 |
-
statuses = [c.get("/healthz").status_code for _ in range(H.RATE_LIMIT_PER_MIN + 5)]
|
| 157 |
-
assert 429 in statuses, "expected at least one 429 after exceeding 60/min"
|
| 158 |
-
assert statuses[:H.RATE_LIMIT_PER_MIN] == [200] * H.RATE_LIMIT_PER_MIN
|
| 159 |
-
# the 429 body is the uniform error envelope
|
| 160 |
-
last = c.get("/healthz")
|
| 161 |
-
assert last.status_code == 429
|
| 162 |
-
assert last.json()["error"]["code"] == "rate_limited"
|
| 163 |
-
assert last.json()["error"]["doctrine"] == "v11"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,319 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 3 |
-
# Authored by Yachay (CTO). Co-Authored-By: Perplexity Computer Agent.
|
| 4 |
-
# Doctrine v11 LOCKED 749/14/163 · Λ Conjecture 1 · SLSA L1 honest
|
| 5 |
-
"""
|
| 6 |
-
tests/test_conduction_aphasia.py — pytest suite for the Conduction-Aphasia Detector.
|
| 7 |
-
|
| 8 |
-
Three core tests (per task spec):
|
| 9 |
-
1. Single observation below threshold -> no alert
|
| 10 |
-
2. N consecutive observations above threshold -> alert fires
|
| 11 |
-
3. Receipt is signed and has all required fields (lutar_anchor, neuro_citation, etc.)
|
| 12 |
-
|
| 13 |
-
Hickok citation: Hickok, Houde, Rong 2011, Neuron 69:407-422.
|
| 14 |
-
DOI 10.1016/j.neuron.2011.01.019
|
| 15 |
-
"""
|
| 16 |
-
from __future__ import annotations
|
| 17 |
-
|
| 18 |
-
import sys
|
| 19 |
-
import types
|
| 20 |
-
import os
|
| 21 |
-
|
| 22 |
-
import pytest
|
| 23 |
-
|
| 24 |
-
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 25 |
-
if REPO_ROOT not in sys.path:
|
| 26 |
-
sys.path.insert(0, REPO_ROOT)
|
| 27 |
-
|
| 28 |
-
# Stub szl_dsse if not present
|
| 29 |
-
for _mod in ("szl_dsse",):
|
| 30 |
-
if _mod not in sys.modules:
|
| 31 |
-
stub = types.ModuleType(_mod)
|
| 32 |
-
stub.sign_payload = lambda x, **kw: {"signed": False, "signatures": [], "honesty": "UNSIGNED stub"}
|
| 33 |
-
stub.signing_available = lambda: False
|
| 34 |
-
sys.modules[_mod] = stub
|
| 35 |
-
|
| 36 |
-
import conduction_aphasia as ca
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def fresh_state(tau: float = 0.30, window: int = 3) -> ca._ConductionState:
|
| 40 |
-
return ca._ConductionState(tau=tau, window=window)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# ---------------------------------------------------------------------------
|
| 44 |
-
# Test 1 — Single observation below threshold -> no alert
|
| 45 |
-
# ---------------------------------------------------------------------------
|
| 46 |
-
|
| 47 |
-
class TestBelowThreshold:
|
| 48 |
-
"""A single observation with delta <= tau must not breach or raise an alert."""
|
| 49 |
-
|
| 50 |
-
def test_cosine_identical_inputs_no_breach(self):
|
| 51 |
-
state = fresh_state(tau=0.30, window=3)
|
| 52 |
-
receipt = state.observe("t1", [1.0, 0.5, 0.2], [1.0, 0.5, 0.2], metric="cosine")
|
| 53 |
-
assert receipt["breach"] is False
|
| 54 |
-
assert receipt["delta"] == pytest.approx(0.0, abs=1e-9)
|
| 55 |
-
assert receipt["alert_level"] == ca.ALERT_NORMAL
|
| 56 |
-
assert receipt["consecutive_breaches"] == 0
|
| 57 |
-
|
| 58 |
-
def test_l2_small_perturbation_no_breach(self):
|
| 59 |
-
state = fresh_state(tau=0.30, window=3)
|
| 60 |
-
receipt = state.observe("t2", [0.8, 0.6, 0.0], [0.81, 0.59, 0.01], metric="l2")
|
| 61 |
-
assert receipt["breach"] is False
|
| 62 |
-
assert receipt["delta"] < 0.30
|
| 63 |
-
assert receipt["alert_level"] == ca.ALERT_NORMAL
|
| 64 |
-
|
| 65 |
-
def test_hash_hamming_identical_no_breach(self):
|
| 66 |
-
state = fresh_state(tau=0.30, window=3)
|
| 67 |
-
receipt = state.observe("t3", "hello world", "hello world", metric="hash_hamming")
|
| 68 |
-
assert receipt["breach"] is False
|
| 69 |
-
assert receipt["delta"] == pytest.approx(0.0, abs=1e-9)
|
| 70 |
-
|
| 71 |
-
def test_status_shows_normal_after_clean(self):
|
| 72 |
-
state = fresh_state()
|
| 73 |
-
state.observe("t_clean", [1.0], [1.0], metric="cosine")
|
| 74 |
-
status = state.status()
|
| 75 |
-
assert status["current_alert_level"] == ca.ALERT_NORMAL
|
| 76 |
-
assert status["consecutive_breaches"] == 0
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
# ---------------------------------------------------------------------------
|
| 80 |
-
# Test 2 — N consecutive observations above threshold -> alert fires
|
| 81 |
-
# ---------------------------------------------------------------------------
|
| 82 |
-
|
| 83 |
-
class TestConsecutiveBreachesFireAlert:
|
| 84 |
-
|
| 85 |
-
def _high_pair(self):
|
| 86 |
-
return [1.0, 0.0, 0.0], [0.0, 0.0, 1.0] # orthogonal -> cosine dist = 1.0
|
| 87 |
-
|
| 88 |
-
def test_n_consecutive_fire_conduction_alert(self):
|
| 89 |
-
state = fresh_state(tau=0.30, window=3)
|
| 90 |
-
p, a = self._high_pair()
|
| 91 |
-
receipts = [state.observe(f"tick_{i}", p, a, metric="cosine") for i in range(3)]
|
| 92 |
-
assert receipts[0]["alert_level"] == ca.ALERT_WATCHING
|
| 93 |
-
assert receipts[1]["alert_level"] == ca.ALERT_WATCHING
|
| 94 |
-
assert receipts[2]["alert_level"] == ca.ALERT_CONDUCTION
|
| 95 |
-
assert receipts[2]["breach"] is True
|
| 96 |
-
assert receipts[2]["consecutive_breaches"] == 3
|
| 97 |
-
|
| 98 |
-
def test_status_after_n_breaches_is_alert(self):
|
| 99 |
-
state = fresh_state(tau=0.30, window=3)
|
| 100 |
-
p, a = self._high_pair()
|
| 101 |
-
for i in range(3):
|
| 102 |
-
state.observe(f"tick_s_{i}", p, a, metric="cosine")
|
| 103 |
-
status = state.status()
|
| 104 |
-
assert status["current_alert_level"] == ca.ALERT_CONDUCTION
|
| 105 |
-
assert status["last_alert_at"] is not None
|
| 106 |
-
|
| 107 |
-
def test_streak_resets_on_clean(self):
|
| 108 |
-
state = fresh_state(tau=0.30, window=3)
|
| 109 |
-
p, a = self._high_pair()
|
| 110 |
-
for i in range(2):
|
| 111 |
-
state.observe(f"breach_{i}", p, a, metric="cosine")
|
| 112 |
-
state.observe("clean", [1.0], [1.0], metric="cosine")
|
| 113 |
-
assert state._breach_streak == 0
|
| 114 |
-
|
| 115 |
-
def test_n_minus_one_only_watching(self):
|
| 116 |
-
state = fresh_state(tau=0.30, window=3)
|
| 117 |
-
p, a = self._high_pair()
|
| 118 |
-
for i in range(2):
|
| 119 |
-
state.observe(f"tick_{i}", p, a, metric="cosine")
|
| 120 |
-
assert state.status()["current_alert_level"] == ca.ALERT_WATCHING
|
| 121 |
-
|
| 122 |
-
def test_window_of_1_fires_immediately(self):
|
| 123 |
-
state = fresh_state(tau=0.05, window=1)
|
| 124 |
-
p, a = self._high_pair()
|
| 125 |
-
r = state.observe("immediate", p, a, metric="cosine")
|
| 126 |
-
assert r["alert_level"] == ca.ALERT_CONDUCTION
|
| 127 |
-
|
| 128 |
-
def test_breach_with_l2_metric(self):
|
| 129 |
-
state = fresh_state(tau=0.10, window=3)
|
| 130 |
-
p = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
| 131 |
-
a = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
|
| 132 |
-
for i in range(3):
|
| 133 |
-
state.observe(f"l2_{i}", p, a, metric="l2")
|
| 134 |
-
assert state._current_alert == ca.ALERT_CONDUCTION
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
# ---------------------------------------------------------------------------
|
| 138 |
-
# Test 3 — Receipt has all required fields, lutar_anchor, neuro_citation
|
| 139 |
-
# ---------------------------------------------------------------------------
|
| 140 |
-
|
| 141 |
-
class TestReceiptSchema:
|
| 142 |
-
REQUIRED_FIELDS = [
|
| 143 |
-
"receipt_id", "kind", "tick_id", "predicted_hash", "actual_hash",
|
| 144 |
-
"delta", "metric", "threshold_tau", "breach", "alert_level",
|
| 145 |
-
"consecutive_breaches", "doctrine_v", "neuro_citation",
|
| 146 |
-
"lutar_anchor", "signed_by", "sig", "ts",
|
| 147 |
-
]
|
| 148 |
-
|
| 149 |
-
def _get_receipt(self, **kw):
|
| 150 |
-
state = fresh_state()
|
| 151 |
-
return state.observe(
|
| 152 |
-
tick_id=kw.get("tick_id", "schema_test"),
|
| 153 |
-
predicted_sensory=kw.get("predicted_sensory", [0.5, 0.5]),
|
| 154 |
-
actual_sensory=kw.get("actual_sensory", [0.5, 0.5]),
|
| 155 |
-
metric=kw.get("metric", "cosine"),
|
| 156 |
-
)
|
| 157 |
-
|
| 158 |
-
def test_all_required_fields_present(self):
|
| 159 |
-
r = self._get_receipt()
|
| 160 |
-
for field in self.REQUIRED_FIELDS:
|
| 161 |
-
assert field in r, f"Missing required field: {field}"
|
| 162 |
-
|
| 163 |
-
def test_lutar_anchor_value(self):
|
| 164 |
-
r = self._get_receipt()
|
| 165 |
-
assert r["lutar_anchor"] == "A37_InternalFeedbackIntegrity"
|
| 166 |
-
|
| 167 |
-
def test_neuro_citation_has_hickok_doi(self):
|
| 168 |
-
r = self._get_receipt()
|
| 169 |
-
nc = r["neuro_citation"]
|
| 170 |
-
assert isinstance(nc, dict)
|
| 171 |
-
assert nc.get("doi") == "10.1016/j.neuron.2011.01.019"
|
| 172 |
-
|
| 173 |
-
def test_neuro_citation_has_label(self):
|
| 174 |
-
r = self._get_receipt()
|
| 175 |
-
nc = r["neuro_citation"]
|
| 176 |
-
assert "Hickok" in nc.get("label", "")
|
| 177 |
-
assert "2011" in nc.get("label", "")
|
| 178 |
-
|
| 179 |
-
def test_kind_is_conduction_observation(self):
|
| 180 |
-
assert self._get_receipt()["kind"] == "conduction_observation"
|
| 181 |
-
|
| 182 |
-
def test_doctrine_v_is_11(self):
|
| 183 |
-
assert self._get_receipt()["doctrine_v"] == "11"
|
| 184 |
-
|
| 185 |
-
def test_signed_by_is_yachay(self):
|
| 186 |
-
assert self._get_receipt()["signed_by"] == "yachay"
|
| 187 |
-
|
| 188 |
-
def test_predicted_hash_format(self):
|
| 189 |
-
r = self._get_receipt(predicted_sensory=[0.1, 0.2])
|
| 190 |
-
assert r["predicted_hash"].startswith("sha256:")
|
| 191 |
-
|
| 192 |
-
def test_actual_hash_format(self):
|
| 193 |
-
r = self._get_receipt(actual_sensory=[0.4, 0.5])
|
| 194 |
-
assert r["actual_hash"].startswith("sha256:")
|
| 195 |
-
|
| 196 |
-
def test_receipt_ids_unique(self):
|
| 197 |
-
state = fresh_state()
|
| 198 |
-
r1 = state.observe("t_a", [1.0], [1.0], "cosine")
|
| 199 |
-
r2 = state.observe("t_b", [1.0], [1.0], "cosine")
|
| 200 |
-
assert r1["receipt_id"] != r2["receipt_id"]
|
| 201 |
-
|
| 202 |
-
def test_receipts_ring_newest_first(self):
|
| 203 |
-
state = fresh_state()
|
| 204 |
-
for i in range(3):
|
| 205 |
-
state.observe(f"order_{i}", [float(i)], [float(i)], "cosine")
|
| 206 |
-
receipts = state.receipts()
|
| 207 |
-
assert receipts[0]["tick_id"] == "order_2"
|
| 208 |
-
assert receipts[2]["tick_id"] == "order_0"
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
# ---------------------------------------------------------------------------
|
| 212 |
-
# Test 4 — Metric math
|
| 213 |
-
# ---------------------------------------------------------------------------
|
| 214 |
-
|
| 215 |
-
class TestMetricComputation:
|
| 216 |
-
def test_cosine_identical_zero(self):
|
| 217 |
-
assert ca._cosine_delta([1.0, 0.5], [1.0, 0.5]) == pytest.approx(0.0, abs=1e-9)
|
| 218 |
-
|
| 219 |
-
def test_cosine_orthogonal_one(self):
|
| 220 |
-
assert ca._cosine_delta([1.0, 0.0], [0.0, 1.0]) == pytest.approx(1.0, abs=1e-9)
|
| 221 |
-
|
| 222 |
-
def test_l2_identical_zero(self):
|
| 223 |
-
assert ca._l2_delta([3.0, 4.0], [3.0, 4.0]) == pytest.approx(0.0, abs=1e-9)
|
| 224 |
-
|
| 225 |
-
def test_l2_pythagorean(self):
|
| 226 |
-
assert ca._l2_delta([0.0, 0.0], [3.0, 4.0]) == pytest.approx(5.0, abs=1e-9)
|
| 227 |
-
|
| 228 |
-
def test_hamming_identical_zero(self):
|
| 229 |
-
assert ca._hash_hamming_delta("abc", "abc") == pytest.approx(0.0, abs=1e-9)
|
| 230 |
-
|
| 231 |
-
def test_hamming_different_positive(self):
|
| 232 |
-
d = ca._hash_hamming_delta("abc", "xyz")
|
| 233 |
-
assert 0.0 < d <= 1.0
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
# ---------------------------------------------------------------------------
|
| 237 |
-
# Test 5 — FastAPI HTTP contract
|
| 238 |
-
# ---------------------------------------------------------------------------
|
| 239 |
-
|
| 240 |
-
class TestFastAPIEndpoints:
|
| 241 |
-
@pytest.fixture(autouse=True)
|
| 242 |
-
def _setup(self):
|
| 243 |
-
try:
|
| 244 |
-
from fastapi import FastAPI
|
| 245 |
-
from fastapi.testclient import TestClient
|
| 246 |
-
except ImportError:
|
| 247 |
-
pytest.skip("FastAPI / httpx not installed")
|
| 248 |
-
ca.reset_state(tau=0.30, window=3)
|
| 249 |
-
app = FastAPI()
|
| 250 |
-
ca.register(app, ns="a11oy")
|
| 251 |
-
self.client = TestClient(app)
|
| 252 |
-
yield
|
| 253 |
-
|
| 254 |
-
def test_status_200_doctrine_v(self):
|
| 255 |
-
r = self.client.get("/api/a11oy/v4/conduction/status")
|
| 256 |
-
assert r.status_code == 200
|
| 257 |
-
d = r.json()
|
| 258 |
-
assert d["doctrine_v"] == "11"
|
| 259 |
-
assert "threshold_tau" in d
|
| 260 |
-
|
| 261 |
-
def test_observe_below_no_breach(self):
|
| 262 |
-
r = self.client.post("/api/a11oy/v4/conduction/observe", json={
|
| 263 |
-
"tick_id": "http_t1", "predicted_sensory": [1.0, 1.0],
|
| 264 |
-
"actual_sensory": [1.0, 1.0], "metric": "cosine"})
|
| 265 |
-
assert r.status_code == 200
|
| 266 |
-
d = r.json()
|
| 267 |
-
assert d["breach"] is False
|
| 268 |
-
assert d["alert_level"] == "normal"
|
| 269 |
-
|
| 270 |
-
def test_observe_high_delta_breach(self):
|
| 271 |
-
r = self.client.post("/api/a11oy/v4/conduction/observe", json={
|
| 272 |
-
"tick_id": "http_breach", "predicted_sensory": [1.0, 0.0, 0.0],
|
| 273 |
-
"actual_sensory": [0.0, 0.0, 1.0], "metric": "cosine"})
|
| 274 |
-
assert r.status_code == 200
|
| 275 |
-
assert r.json()["breach"] is True
|
| 276 |
-
|
| 277 |
-
def test_n_consecutive_fires_conduction_alert(self):
|
| 278 |
-
for i in range(3):
|
| 279 |
-
self.client.post("/api/a11oy/v4/conduction/observe", json={
|
| 280 |
-
"tick_id": f"alert_{i}", "predicted_sensory": [1.0, 0.0, 0.0],
|
| 281 |
-
"actual_sensory": [0.0, 0.0, 1.0], "metric": "cosine"})
|
| 282 |
-
status = self.client.get("/api/a11oy/v4/conduction/status").json()
|
| 283 |
-
assert status["current_alert_level"] == "conduction_alert"
|
| 284 |
-
|
| 285 |
-
def test_receipts_returns_list(self):
|
| 286 |
-
self.client.post("/api/a11oy/v4/conduction/observe", json={
|
| 287 |
-
"tick_id": "rec_1", "predicted_sensory": [0.5],
|
| 288 |
-
"actual_sensory": [0.5], "metric": "cosine"})
|
| 289 |
-
r = self.client.get("/api/a11oy/v4/conduction/receipts?limit=5")
|
| 290 |
-
assert r.status_code == 200
|
| 291 |
-
d = r.json()
|
| 292 |
-
assert isinstance(d["receipts"], list)
|
| 293 |
-
assert len(d["receipts"]) >= 1
|
| 294 |
-
|
| 295 |
-
def test_receipt_has_lutar_anchor_and_doi(self):
|
| 296 |
-
self.client.post("/api/a11oy/v4/conduction/observe", json={
|
| 297 |
-
"tick_id": "schema_http", "predicted_sensory": [1.0],
|
| 298 |
-
"actual_sensory": [1.0], "metric": "cosine"})
|
| 299 |
-
d = self.client.get("/api/a11oy/v4/conduction/receipts?limit=1").json()
|
| 300 |
-
rec = d["receipts"][0]
|
| 301 |
-
assert rec["lutar_anchor"] == "A37_InternalFeedbackIntegrity"
|
| 302 |
-
assert rec["neuro_citation"]["doi"] == "10.1016/j.neuron.2011.01.019"
|
| 303 |
-
|
| 304 |
-
def test_demo_endpoint_injects_high_delta(self):
|
| 305 |
-
r = self.client.post("/api/a11oy/v4/conduction/demo")
|
| 306 |
-
assert r.status_code == 200
|
| 307 |
-
d = r.json()
|
| 308 |
-
assert d.get("demo") is True
|
| 309 |
-
assert d["delta"] > 0.0
|
| 310 |
-
|
| 311 |
-
def test_conduction_html_has_doi(self):
|
| 312 |
-
r = self.client.get("/conduction")
|
| 313 |
-
assert r.status_code == 200
|
| 314 |
-
assert "10.1016/j.neuron.2011.01.019" in r.text
|
| 315 |
-
assert "A37" in r.text
|
| 316 |
-
|
| 317 |
-
def test_status_has_neuro_citation(self):
|
| 318 |
-
d = self.client.get("/api/a11oy/v4/conduction/status").json()
|
| 319 |
-
assert d["neuro_citation"]["doi"] == "10.1016/j.neuron.2011.01.019"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1,160 +0,0 @@
|
|
| 1 |
-
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
-
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 3 |
-
# Authored by Yachay (CTO). Co-Authored-By: Perplexity Computer Agent.
|
| 4 |
-
# Doctrine v11 LOCKED 749/14/163 · Λ Conjecture 1 · SLSA L1+L2
|
| 5 |
-
"""
|
| 6 |
-
tests/test_dsse_real_signing.py — proves the DSSE signer flips from
|
| 7 |
-
`signatures: []` (honest UNSIGNED) to a REAL ECDSA-P256-SHA256 signature
|
| 8 |
-
the moment the SZL_COSIGN_PRIVATE_KEY_PEM secret is present, and that the
|
| 9 |
-
resulting signature verifies against the matching public key.
|
| 10 |
-
|
| 11 |
-
HONESTY / SAFETY
|
| 12 |
-
- No real org private key is ever required, embedded, or baked into CI.
|
| 13 |
-
- The "present-secret" test GENERATES its own ephemeral P-256 key at runtime,
|
| 14 |
-
sets the env var to it, signs, and verifies against THAT key's public half.
|
| 15 |
-
- The real-org-secret round-trip is `skipif`-guarded: it runs ONLY if a real
|
| 16 |
-
SZL_COSIGN_PRIVATE_KEY_PEM / SZL_COSIGN_PRIVATE_PEM is already in the env
|
| 17 |
-
(e.g. a developer's local shell). It is never satisfied by CI defaults.
|
| 18 |
-
"""
|
| 19 |
-
from __future__ import annotations
|
| 20 |
-
|
| 21 |
-
import base64
|
| 22 |
-
import importlib
|
| 23 |
-
import os
|
| 24 |
-
import sys
|
| 25 |
-
|
| 26 |
-
import pytest
|
| 27 |
-
|
| 28 |
-
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 29 |
-
if REPO_ROOT not in sys.path:
|
| 30 |
-
sys.path.insert(0, REPO_ROOT)
|
| 31 |
-
|
| 32 |
-
cryptography = pytest.importorskip("cryptography")
|
| 33 |
-
from cryptography.hazmat.primitives import serialization
|
| 34 |
-
from cryptography.hazmat.primitives.asymmetric import ec
|
| 35 |
-
from cryptography.hazmat.primitives import hashes
|
| 36 |
-
from cryptography.exceptions import InvalidSignature
|
| 37 |
-
|
| 38 |
-
import szl_dsse
|
| 39 |
-
|
| 40 |
-
_PRIV_ENV = "SZL_COSIGN_PRIVATE_KEY_PEM"
|
| 41 |
-
_LEGACY_ENV = "SZL_COSIGN_PRIVATE_PEM"
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
def _gen_ephemeral_keypair():
|
| 45 |
-
"""Generate a fresh, test-only ECDSA P-256 keypair (plain PKCS#8 PEM)."""
|
| 46 |
-
priv = ec.generate_private_key(ec.SECP256R1())
|
| 47 |
-
priv_pem = priv.private_bytes(
|
| 48 |
-
encoding=serialization.Encoding.PEM,
|
| 49 |
-
format=serialization.PrivateFormat.PKCS8,
|
| 50 |
-
encryption_algorithm=serialization.NoEncryption(),
|
| 51 |
-
).decode("utf-8")
|
| 52 |
-
pub_pem = priv.public_key().public_bytes(
|
| 53 |
-
encoding=serialization.Encoding.PEM,
|
| 54 |
-
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
| 55 |
-
).decode("utf-8")
|
| 56 |
-
return priv_pem, pub_pem
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
@pytest.fixture(autouse=True)
|
| 60 |
-
def _clean_env(monkeypatch):
|
| 61 |
-
"""Ensure no ambient secret leaks between tests unless a test sets one."""
|
| 62 |
-
yield
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
def test_unsigned_fallback_when_secret_absent(monkeypatch):
|
| 66 |
-
"""No secret -> signatures:[] + honesty:UNSIGNED, never fabricated."""
|
| 67 |
-
monkeypatch.delenv(_PRIV_ENV, raising=False)
|
| 68 |
-
monkeypatch.delenv(_LEGACY_ENV, raising=False)
|
| 69 |
-
importlib.reload(szl_dsse)
|
| 70 |
-
env = szl_dsse.sign_payload({"hello": "world"})
|
| 71 |
-
assert env["signatures"] == []
|
| 72 |
-
assert env["signed"] is False
|
| 73 |
-
assert "UNSIGNED" in env["honesty"]
|
| 74 |
-
assert szl_dsse.signing_available() is False
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
def test_real_signature_with_ephemeral_key_verifies(monkeypatch):
|
| 78 |
-
"""Secret present (ephemeral test key) -> REAL signature that verifies
|
| 79 |
-
against the matching public key via raw cryptography AND via the module's
|
| 80 |
-
own verify path when the embedded public key is swapped to the test key."""
|
| 81 |
-
priv_pem, pub_pem = _gen_ephemeral_keypair()
|
| 82 |
-
monkeypatch.delenv(_LEGACY_ENV, raising=False)
|
| 83 |
-
monkeypatch.setenv(_PRIV_ENV, priv_pem)
|
| 84 |
-
importlib.reload(szl_dsse)
|
| 85 |
-
|
| 86 |
-
assert szl_dsse.signing_available() is True
|
| 87 |
-
env = szl_dsse.sign_payload({"hello": "world", "n": 42})
|
| 88 |
-
|
| 89 |
-
# Flipped from [] to a real signature
|
| 90 |
-
assert env["signed"] is True
|
| 91 |
-
assert len(env["signatures"]) == 1
|
| 92 |
-
sig_entry = env["signatures"][0]
|
| 93 |
-
assert sig_entry["keyid"] == szl_dsse.KEYID
|
| 94 |
-
assert "REAL" in env["honesty"]
|
| 95 |
-
|
| 96 |
-
# 1) Verify the signature against the test public key with raw cryptography,
|
| 97 |
-
# reconstructing the exact DSSE PAE bytes the signer used.
|
| 98 |
-
body = base64.b64decode(env["payload"])
|
| 99 |
-
msg = szl_dsse.pae(env["payloadType"], body)
|
| 100 |
-
pub = serialization.load_pem_public_key(pub_pem.encode("utf-8"))
|
| 101 |
-
sig = base64.b64decode(sig_entry["sig"])
|
| 102 |
-
pub.verify(sig, msg, ec.ECDSA(hashes.SHA256())) # raises InvalidSignature on failure
|
| 103 |
-
|
| 104 |
-
# 2) Module verify path: point the embedded public key at the test public
|
| 105 |
-
# key and confirm verify_envelope() validates the just-made signature.
|
| 106 |
-
monkeypatch.setattr(szl_dsse, "COSIGN_PUBLIC_PEM", pub_pem, raising=True)
|
| 107 |
-
verdict = szl_dsse.verify_envelope(env)
|
| 108 |
-
assert verdict["verified"] is True
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
def test_tampered_payload_fails_verification(monkeypatch):
|
| 112 |
-
"""A tampered payload must NOT verify (signature binds the payload)."""
|
| 113 |
-
priv_pem, pub_pem = _gen_ephemeral_keypair()
|
| 114 |
-
monkeypatch.delenv(_LEGACY_ENV, raising=False)
|
| 115 |
-
monkeypatch.setenv(_PRIV_ENV, priv_pem)
|
| 116 |
-
importlib.reload(szl_dsse)
|
| 117 |
-
|
| 118 |
-
env = szl_dsse.sign_payload({"amount": 1})
|
| 119 |
-
body = szl_dsse.canonical_json({"amount": 1000000}) # tamper
|
| 120 |
-
msg = szl_dsse.pae(env["payloadType"], body)
|
| 121 |
-
pub = serialization.load_pem_public_key(pub_pem.encode("utf-8"))
|
| 122 |
-
sig = base64.b64decode(env["signatures"][0]["sig"])
|
| 123 |
-
with pytest.raises(InvalidSignature):
|
| 124 |
-
pub.verify(sig, msg, ec.ECDSA(hashes.SHA256()))
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
def test_legacy_env_var_still_works(monkeypatch):
|
| 128 |
-
"""Backward-compat: the legacy SZL_COSIGN_PRIVATE_PEM name still signs."""
|
| 129 |
-
priv_pem, _pub_pem = _gen_ephemeral_keypair()
|
| 130 |
-
monkeypatch.delenv(_PRIV_ENV, raising=False)
|
| 131 |
-
monkeypatch.setenv(_LEGACY_ENV, priv_pem)
|
| 132 |
-
importlib.reload(szl_dsse)
|
| 133 |
-
env = szl_dsse.sign_payload({"compat": True})
|
| 134 |
-
assert env["signed"] is True
|
| 135 |
-
assert len(env["signatures"]) == 1
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
@pytest.mark.skipif(
|
| 139 |
-
not (os.environ.get(_PRIV_ENV) or os.environ.get(_LEGACY_ENV)),
|
| 140 |
-
reason="real cosign private key not present in env; skip real-key round-trip "
|
| 141 |
-
"(the private key is never baked into CI)",
|
| 142 |
-
)
|
| 143 |
-
def test_real_org_key_roundtrip_if_present():
|
| 144 |
-
"""OPT-IN: if a real org private key is in the env, the produced signature
|
| 145 |
-
must verify against the module's embedded (published) public key."""
|
| 146 |
-
importlib.reload(szl_dsse)
|
| 147 |
-
assert szl_dsse.signing_available() is True
|
| 148 |
-
env = szl_dsse.sign_payload({"real": "org-key-roundtrip"})
|
| 149 |
-
assert env["signed"] is True
|
| 150 |
-
verdict = szl_dsse.verify_envelope(env)
|
| 151 |
-
assert verdict["verified"] is True, verdict
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
@pytest.fixture(autouse=True)
|
| 155 |
-
def _restore_module():
|
| 156 |
-
yield
|
| 157 |
-
# Restore a clean module state for any downstream tests
|
| 158 |
-
for _n in (_PRIV_ENV, _LEGACY_ENV):
|
| 159 |
-
os.environ.pop(_n, None)
|
| 160 |
-
importlib.reload(szl_dsse)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|