atomadic-forge 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. atomadic_forge/__init__.py +12 -0
  2. atomadic_forge/__main__.py +5 -0
  3. atomadic_forge/a0_qk_constants/__init__.py +1 -0
  4. atomadic_forge/a0_qk_constants/agent_plan_schema.py +120 -0
  5. atomadic_forge/a0_qk_constants/commandsmith_types.py +49 -0
  6. atomadic_forge/a0_qk_constants/config_defaults.py +38 -0
  7. atomadic_forge/a0_qk_constants/emergent_types.py +77 -0
  8. atomadic_forge/a0_qk_constants/error_codes.py +296 -0
  9. atomadic_forge/a0_qk_constants/forge_types.py +89 -0
  10. atomadic_forge/a0_qk_constants/gen_language.py +116 -0
  11. atomadic_forge/a0_qk_constants/lang_extensions.py +150 -0
  12. atomadic_forge/a0_qk_constants/policy_schema.py +48 -0
  13. atomadic_forge/a0_qk_constants/receipt_schema.py +311 -0
  14. atomadic_forge/a0_qk_constants/roi_constants.py +96 -0
  15. atomadic_forge/a0_qk_constants/semantic_types.py +61 -0
  16. atomadic_forge/a0_qk_constants/sidecar_schema.py +81 -0
  17. atomadic_forge/a0_qk_constants/synergy_types.py +62 -0
  18. atomadic_forge/a0_qk_constants/tier_names.py +47 -0
  19. atomadic_forge/a1_at_functions/__init__.py +1 -0
  20. atomadic_forge/a1_at_functions/agent_context_pack.py +193 -0
  21. atomadic_forge/a1_at_functions/agent_memory.py +139 -0
  22. atomadic_forge/a1_at_functions/agent_plan_emitter.py +324 -0
  23. atomadic_forge/a1_at_functions/agent_summary.py +277 -0
  24. atomadic_forge/a1_at_functions/body_extractor.py +306 -0
  25. atomadic_forge/a1_at_functions/card_renderer.py +210 -0
  26. atomadic_forge/a1_at_functions/certify_checks.py +445 -0
  27. atomadic_forge/a1_at_functions/chat_context.py +170 -0
  28. atomadic_forge/a1_at_functions/cherry_pick.py +71 -0
  29. atomadic_forge/a1_at_functions/classify_tier.py +115 -0
  30. atomadic_forge/a1_at_functions/commandsmith_discover.py +167 -0
  31. atomadic_forge/a1_at_functions/commandsmith_render.py +267 -0
  32. atomadic_forge/a1_at_functions/compiler_feedback.py +94 -0
  33. atomadic_forge/a1_at_functions/compliance_checker.py +228 -0
  34. atomadic_forge/a1_at_functions/config_io.py +68 -0
  35. atomadic_forge/a1_at_functions/cs1_renderer.py +588 -0
  36. atomadic_forge/a1_at_functions/doc_synthesizer.py +205 -0
  37. atomadic_forge/a1_at_functions/emergent_compose.py +192 -0
  38. atomadic_forge/a1_at_functions/emergent_rank.py +116 -0
  39. atomadic_forge/a1_at_functions/emergent_signature_extract.py +242 -0
  40. atomadic_forge/a1_at_functions/emergent_synthesize.py +88 -0
  41. atomadic_forge/a1_at_functions/enforce_planner.py +208 -0
  42. atomadic_forge/a1_at_functions/error_hints.py +105 -0
  43. atomadic_forge/a1_at_functions/evolution_log.py +94 -0
  44. atomadic_forge/a1_at_functions/forge_feedback.py +433 -0
  45. atomadic_forge/a1_at_functions/generation_quality.py +322 -0
  46. atomadic_forge/a1_at_functions/import_repair.py +211 -0
  47. atomadic_forge/a1_at_functions/import_smoke.py +102 -0
  48. atomadic_forge/a1_at_functions/js_parser.py +539 -0
  49. atomadic_forge/a1_at_functions/lineage_chain.py +144 -0
  50. atomadic_forge/a1_at_functions/lineage_reader.py +107 -0
  51. atomadic_forge/a1_at_functions/llm_client.py +554 -0
  52. atomadic_forge/a1_at_functions/local_signer.py +134 -0
  53. atomadic_forge/a1_at_functions/lsp_protocol.py +379 -0
  54. atomadic_forge/a1_at_functions/manifest_diff.py +314 -0
  55. atomadic_forge/a1_at_functions/mcp_protocol.py +1066 -0
  56. atomadic_forge/a1_at_functions/patch_scorer.py +267 -0
  57. atomadic_forge/a1_at_functions/plan_adapter.py +75 -0
  58. atomadic_forge/a1_at_functions/policy_loader.py +107 -0
  59. atomadic_forge/a1_at_functions/preflight_change.py +227 -0
  60. atomadic_forge/a1_at_functions/progress_reporter.py +81 -0
  61. atomadic_forge/a1_at_functions/provider_detect.py +157 -0
  62. atomadic_forge/a1_at_functions/provider_resolver.py +48 -0
  63. atomadic_forge/a1_at_functions/receipt_emitter.py +291 -0
  64. atomadic_forge/a1_at_functions/recipes.py +186 -0
  65. atomadic_forge/a1_at_functions/repo_explainer.py +124 -0
  66. atomadic_forge/a1_at_functions/roi_calculator.py +265 -0
  67. atomadic_forge/a1_at_functions/rollback_planner.py +147 -0
  68. atomadic_forge/a1_at_functions/sbom_emitter.py +155 -0
  69. atomadic_forge/a1_at_functions/scaffold_js.py +55 -0
  70. atomadic_forge/a1_at_functions/scaffold_pyproject.py +62 -0
  71. atomadic_forge/a1_at_functions/scaffold_starter.py +94 -0
  72. atomadic_forge/a1_at_functions/scout_walk.py +309 -0
  73. atomadic_forge/a1_at_functions/sidecar_parser.py +161 -0
  74. atomadic_forge/a1_at_functions/sidecar_validator.py +202 -0
  75. atomadic_forge/a1_at_functions/stub_detector.py +158 -0
  76. atomadic_forge/a1_at_functions/synergy_detect.py +166 -0
  77. atomadic_forge/a1_at_functions/synergy_render.py +252 -0
  78. atomadic_forge/a1_at_functions/synergy_surface_extract.py +163 -0
  79. atomadic_forge/a1_at_functions/test_runner.py +196 -0
  80. atomadic_forge/a1_at_functions/test_selector.py +122 -0
  81. atomadic_forge/a1_at_functions/tier_init_rebuild.py +122 -0
  82. atomadic_forge/a1_at_functions/tool_composer.py +130 -0
  83. atomadic_forge/a1_at_functions/transcript_log.py +70 -0
  84. atomadic_forge/a1_at_functions/wire_check.py +260 -0
  85. atomadic_forge/a2_mo_composites/__init__.py +1 -0
  86. atomadic_forge/a2_mo_composites/lineage_chain_store.py +122 -0
  87. atomadic_forge/a2_mo_composites/manifest_store.py +46 -0
  88. atomadic_forge/a2_mo_composites/plan_store.py +164 -0
  89. atomadic_forge/a2_mo_composites/receipt_signer.py +231 -0
  90. atomadic_forge/a3_og_features/__init__.py +1 -0
  91. atomadic_forge/a3_og_features/commandsmith_feature.py +267 -0
  92. atomadic_forge/a3_og_features/demo_packages/mixed_py_js/src/mixed_pkg/__init__.py +3 -0
  93. atomadic_forge/a3_og_features/demo_packages/mixed_py_js/src/mixed_pkg/a0_qk_constants/__init__.py +4 -0
  94. atomadic_forge/a3_og_features/demo_packages/mixed_py_js/src/mixed_pkg/a1_at_functions/__init__.py +14 -0
  95. atomadic_forge/a3_og_features/demo_packages/mixed_py_js/tests/conftest.py +10 -0
  96. atomadic_forge/a3_og_features/demo_packages/mixed_py_js/tests/test_mixed.py +18 -0
  97. atomadic_forge/a3_og_features/demo_runner.py +502 -0
  98. atomadic_forge/a3_og_features/emergent_feature.py +95 -0
  99. atomadic_forge/a3_og_features/emergent_pipeline_integration.py +154 -0
  100. atomadic_forge/a3_og_features/forge_enforce.py +107 -0
  101. atomadic_forge/a3_og_features/forge_evolve.py +176 -0
  102. atomadic_forge/a3_og_features/forge_loop.py +528 -0
  103. atomadic_forge/a3_og_features/forge_pipeline.py +295 -0
  104. atomadic_forge/a3_og_features/forge_plan_apply.py +222 -0
  105. atomadic_forge/a3_og_features/lsp_server.py +98 -0
  106. atomadic_forge/a3_og_features/mcp_server.py +160 -0
  107. atomadic_forge/a3_og_features/setup_wizard.py +337 -0
  108. atomadic_forge/a3_og_features/synergy_feature.py +65 -0
  109. atomadic_forge/a4_sy_orchestration/__init__.py +1 -0
  110. atomadic_forge/a4_sy_orchestration/cli.py +1284 -0
  111. atomadic_forge/commands/__init__.py +1 -0
  112. atomadic_forge/commands/_registry.py +36 -0
  113. atomadic_forge/commands/audit.py +142 -0
  114. atomadic_forge/commands/chat.py +133 -0
  115. atomadic_forge/commands/commandsmith.py +178 -0
  116. atomadic_forge/commands/config_cmd.py +145 -0
  117. atomadic_forge/commands/demo.py +142 -0
  118. atomadic_forge/commands/emergent.py +124 -0
  119. atomadic_forge/commands/emergent_then_synergy.py +70 -0
  120. atomadic_forge/commands/evolve.py +122 -0
  121. atomadic_forge/commands/evolve_then_iterate.py +70 -0
  122. atomadic_forge/commands/feature_then_emergent.py +111 -0
  123. atomadic_forge/commands/iterate.py +140 -0
  124. atomadic_forge/commands/synergy.py +96 -0
  125. atomadic_forge/commands/synergy_then_emergent.py +70 -0
  126. atomadic_forge-0.3.2.dist-info/METADATA +471 -0
  127. atomadic_forge-0.3.2.dist-info/RECORD +131 -0
  128. atomadic_forge-0.3.2.dist-info/WHEEL +5 -0
  129. atomadic_forge-0.3.2.dist-info/entry_points.txt +3 -0
  130. atomadic_forge-0.3.2.dist-info/licenses/LICENSE +15 -0
  131. atomadic_forge-0.3.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,588 @@
1
+ """Tier a1 -- pure Forge Conformity Statement CS-1 renderer.
2
+
3
+ Golden Path Lane F W1.
4
+
5
+ Composes a ForgeReceiptV1 dict (already validated by receipt_emitter)
6
+ into a ``ForgeCS1V1`` dict (schema ``atomadic-forge.cs1/v1``) and then
7
+ renders it to regulator-friendly Markdown. Pure: no I/O, stdlib only.
8
+
9
+ CS-1 is the Atomadic Forge Conformity Statement -- a single artifact
10
+ that bundles EU AI Act Annex IV, Federal Reserve SR 11-7, FDA PCCP,
11
+ and DoD CMMC-AI compliance evidence into one signed-or-signable doc.
12
+
13
+ Compliance framework citations
14
+ EU AI Act -- Regulation (EU) 2024/1689, Annex IV
15
+ SR 11-7 -- Federal Reserve SR Letter 11-7 (2011) + FAQ (2021)
16
+ FDA PCCP -- FDA Guidance: AI/ML-Based SaMD Action Plan 2021;
17
+ Predetermined Change Control Plan (PCCP) Draft 2023
18
+ CMMC-AI -- CMMC 2.0 (32 CFR Part 170) + NIST AI RMF 1.0 (2023)
19
+ """
20
+ from __future__ import annotations
21
+
22
+ import datetime as _dt
23
+ import hashlib
24
+ import json
25
+ from typing import Any
26
+
27
+ CS1_SCHEMA_VERSION = "atomadic-forge.cs1/v1"
28
+
29
+ _REQUIRED_RECEIPT_FIELDS = (
30
+ "schema_version",
31
+ "generated_at_utc",
32
+ "verdict",
33
+ "project",
34
+ "certify",
35
+ "wire",
36
+ "scout",
37
+ )
38
+
39
+ # ---------------------------------------------------------------------------
40
+ # Compliance claim templates
41
+ # ---------------------------------------------------------------------------
42
+
43
+ _EU_AI_ACT_CLAIMS: list[dict[str, str]] = [
44
+ {
45
+ "framework": "EU AI Act",
46
+ "ref": "Annex IV §1",
47
+ "title": "General description of the AI system",
48
+ "citation": "Regulation (EU) 2024/1689, Annex IV, paragraph 1",
49
+ "receipt_field": "project.name + project.language + scout.symbol_count",
50
+ "evidence": (
51
+ "The project block (Receipt field: ``project``) records the "
52
+ "system name, primary programming language, and per-language "
53
+ "file counts. The scout block records total symbol count and "
54
+ "tier distribution, providing the structural description "
55
+ "required by Annex IV §1."
56
+ ),
57
+ },
58
+ {
59
+ "framework": "EU AI Act",
60
+ "ref": "Annex IV §2(a)",
61
+ "title": "Training, validation and testing data",
62
+ "citation": "Regulation (EU) 2024/1689, Annex IV, paragraph 2(a)",
63
+ "receipt_field": "lean4_attestation.corpora",
64
+ "evidence": (
65
+ "Lean4 corpora cited in ``lean4_attestation`` enumerate the "
66
+ "machine-checked theorem corpora used to validate the system's "
67
+ "structural invariants. Each corpus entry records name, "
68
+ "repo_url, ref_sha, theorem_count, sorry_count (MUST be 0), "
69
+ "and axiom_count, satisfying the data-documentation obligation "
70
+ "under Annex IV §2(a)."
71
+ ),
72
+ },
73
+ {
74
+ "framework": "EU AI Act",
75
+ "ref": "Annex IV §2(b)",
76
+ "title": "Data governance and data management practices",
77
+ "citation": "Regulation (EU) 2024/1689, Annex IV, paragraph 2(b)",
78
+ "receipt_field": "lineage.lineage_path + lineage.chain_depth",
79
+ "evidence": (
80
+ "The Vanguard lineage chain (``lineage.lineage_path``, "
81
+ "``lineage.chain_depth``, ``lineage.parent_receipt_hash``) "
82
+ "provides a tamper-evident audit log of every structural "
83
+ "change, satisfying the data-governance traceability "
84
+ "requirement of Annex IV §2(b)."
85
+ ),
86
+ },
87
+ {
88
+ "framework": "EU AI Act",
89
+ "ref": "Annex IV §3",
90
+ "title": "Description of the monitoring, functioning and control",
91
+ "citation": "Regulation (EU) 2024/1689, Annex IV, paragraph 3",
92
+ "receipt_field": "wire.verdict + wire.violation_count + certify.axes",
93
+ "evidence": (
94
+ "The wire scan verdict (``wire.verdict``) and violation count "
95
+ "(``wire.violation_count``) document the outcome of automated "
96
+ "architectural monitoring. The certify axes block "
97
+ "(``certify.axes``) records the four structural control checks "
98
+ "(documentation_complete, tests_present, tier_layout_present, "
99
+ "no_upward_imports), satisfying Annex IV §3."
100
+ ),
101
+ },
102
+ {
103
+ "framework": "EU AI Act",
104
+ "ref": "Annex IV §4",
105
+ "title": "Description of the changes to the AI system and its performance",
106
+ "citation": "Regulation (EU) 2024/1689, Annex IV, paragraph 4",
107
+ "receipt_field": "lineage.parent_receipt_hash + lineage.chain_depth",
108
+ "evidence": (
109
+ "Each Receipt records ``lineage.parent_receipt_hash`` (SHA-256 "
110
+ "of the immediately prior Receipt) and ``lineage.chain_depth`` "
111
+ "(monotonically increasing integer). Together they provide the "
112
+ "change-description log required by Annex IV §4; the full "
113
+ "diff is recoverable via Vanguard ``/v1/forge/lineage``."
114
+ ),
115
+ },
116
+ {
117
+ "framework": "EU AI Act",
118
+ "ref": "Annex IV §5",
119
+ "title": "Post-market monitoring plan",
120
+ "citation": "Regulation (EU) 2024/1689, Annex IV, paragraph 5",
121
+ "receipt_field": "signatures.sigstore + signatures.aaaa_nexus",
122
+ "evidence": (
123
+ "Sigstore Rekor entry (``signatures.sigstore.rekor_uuid``, "
124
+ "``signatures.sigstore.log_index``) and AAAA-Nexus signature "
125
+ "(``signatures.aaaa_nexus``) provide the post-market "
126
+ "attestation chain required by Annex IV §5. Each Receipt "
127
+ "emission produces a new Rekor entry, enabling continuous "
128
+ "monitoring of structural compliance."
129
+ ),
130
+ },
131
+ ]
132
+
133
+ _SR_11_7_CLAIMS: list[dict[str, str]] = [
134
+ {
135
+ "framework": "SR 11-7",
136
+ "ref": "§III.A",
137
+ "title": "Model development and implementation",
138
+ "citation": "Federal Reserve SR Letter 11-7 (2011), Section III.A",
139
+ "receipt_field": "certify.score + certify.axes",
140
+ "evidence": (
141
+ "The certify score (``certify.score``) and per-axis flags "
142
+ "(``certify.axes``) document that the model has been developed "
143
+ "and implemented against the four Atomadic structural axes "
144
+ "(documentation, tests, tier layout, import discipline), "
145
+ "satisfying the development-documentation obligation of SR 11-7 "
146
+ "§III.A."
147
+ ),
148
+ },
149
+ {
150
+ "framework": "SR 11-7",
151
+ "ref": "§IV",
152
+ "title": "Validation",
153
+ "citation": "Federal Reserve SR Letter 11-7 (2011), Section IV",
154
+ "receipt_field": "lean4_attestation + wire.verdict",
155
+ "evidence": (
156
+ "Machine-checked Lean4 proofs (``lean4_attestation``) provide "
157
+ "formal validation of the system's mathematical invariants. "
158
+ "The wire scan PASS verdict (``wire.verdict``) provides "
159
+ "automated structural validation. Together they satisfy the "
160
+ "independent validation requirement of SR 11-7 §IV."
161
+ ),
162
+ },
163
+ {
164
+ "framework": "SR 11-7",
165
+ "ref": "§IV.A",
166
+ "title": "Evaluating conceptual soundness",
167
+ "citation": "Federal Reserve SR Letter 11-7 (2011), Section IV.A",
168
+ "receipt_field": "lean4_attestation.corpora[*].sorry_count",
169
+ "evidence": (
170
+ "Every Lean4 corpus cited in ``lean4_attestation.corpora`` "
171
+ "MUST record ``sorry_count = 0`` (no admitted but unproven "
172
+ "theorems). This zero-sorry constraint is the machine-checked "
173
+ "evidence of conceptual soundness required by SR 11-7 §IV.A."
174
+ ),
175
+ },
176
+ {
177
+ "framework": "SR 11-7",
178
+ "ref": "§V.A",
179
+ "title": "Ongoing monitoring",
180
+ "citation": "Federal Reserve SR Letter 11-7 (2011), Section V.A",
181
+ "receipt_field": "lineage.chain_depth + generated_at_utc",
182
+ "evidence": (
183
+ "The Receipt emission timestamp (``generated_at_utc``) and "
184
+ "lineage chain depth (``lineage.chain_depth``) together "
185
+ "constitute the ongoing monitoring record required by SR 11-7 "
186
+ "§V.A. Each ``forge auto`` run produces a new Receipt and "
187
+ "increments the chain depth, creating a time-stamped audit trail."
188
+ ),
189
+ },
190
+ ]
191
+
192
+ _FDA_PCCP_CLAIMS: list[dict[str, str]] = [
193
+ {
194
+ "framework": "FDA PCCP",
195
+ "ref": "§II.A",
196
+ "title": "Description of modifications",
197
+ "citation": (
198
+ "FDA Guidance: Predetermined Change Control Plan for "
199
+ "Machine Learning-Enabled Medical Devices (Draft, 2023), "
200
+ "Section II.A"
201
+ ),
202
+ "receipt_field": "lineage.parent_receipt_hash + lineage.chain_depth",
203
+ "evidence": (
204
+ "The lineage block (``lineage.parent_receipt_hash``, "
205
+ "``lineage.chain_depth``) provides the modification log "
206
+ "required under FDA PCCP §II.A. Each Receipt captures the "
207
+ "structural state at a point in time; the parent hash chain "
208
+ "links successive modifications into an auditable sequence."
209
+ ),
210
+ },
211
+ {
212
+ "framework": "FDA PCCP",
213
+ "ref": "§II.B",
214
+ "title": "Methodology for implementing and validating modifications",
215
+ "citation": (
216
+ "FDA Guidance: Predetermined Change Control Plan for "
217
+ "Machine Learning-Enabled Medical Devices (Draft, 2023), "
218
+ "Section II.B"
219
+ ),
220
+ "receipt_field": "lean4_attestation + certify.axes",
221
+ "evidence": (
222
+ "The Lean4 attestation block documents the formal validation "
223
+ "methodology (machine-checked proofs, 0 sorry). The certify "
224
+ "axes provide the structural validation checklist (tests_present, "
225
+ "documentation_complete, tier_layout_present, no_upward_imports). "
226
+ "Together they satisfy the methodology-documentation obligation "
227
+ "of FDA PCCP §II.B."
228
+ ),
229
+ },
230
+ {
231
+ "framework": "FDA PCCP",
232
+ "ref": "§II.C",
233
+ "title": "Performance monitoring plan",
234
+ "citation": (
235
+ "FDA Guidance: Predetermined Change Control Plan for "
236
+ "Machine Learning-Enabled Medical Devices (Draft, 2023), "
237
+ "Section II.C"
238
+ ),
239
+ "receipt_field": "signatures.sigstore + generated_at_utc",
240
+ "evidence": (
241
+ "The Sigstore Rekor entry (``signatures.sigstore``) and "
242
+ "AAAA-Nexus signature (``signatures.aaaa_nexus``) provide "
243
+ "the timestamped, immutable performance-monitoring record "
244
+ "required by FDA PCCP §II.C. The ``generated_at_utc`` field "
245
+ "pins the monitoring event to a specific UTC instant."
246
+ ),
247
+ },
248
+ ]
249
+
250
+ _CMMC_AI_CLAIMS: list[dict[str, str]] = [
251
+ {
252
+ "framework": "CMMC-AI",
253
+ "ref": "GOVERN 1.1",
254
+ "title": "AI risk management policy",
255
+ "citation": "NIST AI RMF 1.0 (2023), GOVERN 1.1",
256
+ "receipt_field": "certify.axes + wire.verdict",
257
+ "evidence": (
258
+ "The certify axes and wire verdict demonstrate that an "
259
+ "AI risk management policy (Atomadic UEP v20 Monadic "
260
+ "Development Standard) is implemented and enforced via "
261
+ "automated gate checks on every Receipt emission."
262
+ ),
263
+ },
264
+ {
265
+ "framework": "CMMC-AI",
266
+ "ref": "MAP 1.5",
267
+ "title": "Organizational risk tolerances",
268
+ "citation": "NIST AI RMF 1.0 (2023), MAP 1.5",
269
+ "receipt_field": "verdict + certify.score",
270
+ "evidence": (
271
+ "The Receipt verdict (PASS / FAIL / REFINE / QUARANTINE) "
272
+ "and certify score (0..100) encode the organization's "
273
+ "risk tolerance thresholds. PASS requires wire PASS AND "
274
+ "certify.score >= threshold (default 100.0), satisfying "
275
+ "the risk-tolerance documentation obligation of MAP 1.5."
276
+ ),
277
+ },
278
+ {
279
+ "framework": "CMMC-AI",
280
+ "ref": "MEASURE 2.5",
281
+ "title": "AI system to be evaluated for trustworthiness characteristics",
282
+ "citation": "NIST AI RMF 1.0 (2023), MEASURE 2.5",
283
+ "receipt_field": "lean4_attestation + certify.axes",
284
+ "evidence": (
285
+ "Trustworthiness characteristics are evaluated via Lean4 "
286
+ "machine-checked proofs (mathematical correctness) and the "
287
+ "four certify axes (documentation, tests, tier layout, "
288
+ "import discipline). Results are recorded in the Receipt "
289
+ "and versioned in the Vanguard lineage chain."
290
+ ),
291
+ },
292
+ {
293
+ "framework": "CMMC-AI",
294
+ "ref": "MANAGE 1.3",
295
+ "title": "Responses to identified AI risks are prioritized",
296
+ "citation": "NIST AI RMF 1.0 (2023), MANAGE 1.3",
297
+ "receipt_field": "wire.violation_count + wire.auto_fixable + certify.issues",
298
+ "evidence": (
299
+ "Wire violation count (``wire.violation_count``), auto-fixable "
300
+ "count (``wire.auto_fixable``), and certify issue list "
301
+ "(``certify.issues``) enumerate identified risks in priority "
302
+ "order. Auto-fixable items are addressed first by ``forge wire "
303
+ "--apply``; remaining items are surfaced in the receipt for "
304
+ "human review, satisfying MANAGE 1.3."
305
+ ),
306
+ },
307
+ ]
308
+
309
+ _REGULATOR_QUESTIONS: list[dict[str, str]] = [
310
+ {
311
+ "id": "RQ-1",
312
+ "question": "What is the AI system and what does it do?",
313
+ "answer_fields": "project.name, project.language, scout.symbol_count, scout.tier_distribution",
314
+ "framework_refs": "EU AI Act Annex IV §1; SR 11-7 §III.A",
315
+ },
316
+ {
317
+ "id": "RQ-2",
318
+ "question": "How was the system validated and what formal proofs exist?",
319
+ "answer_fields": "lean4_attestation.corpora, lean4_attestation.total_theorems, certify.axes",
320
+ "framework_refs": "EU AI Act Annex IV §2(a); SR 11-7 §IV, §IV.A; FDA PCCP §II.B",
321
+ },
322
+ {
323
+ "id": "RQ-3",
324
+ "question": "What structural controls are in place?",
325
+ "answer_fields": "wire.verdict, wire.violation_count, certify.score, certify.axes",
326
+ "framework_refs": "EU AI Act Annex IV §3; SR 11-7 §III.A; CMMC-AI GOVERN 1.1, MAP 1.5",
327
+ },
328
+ {
329
+ "id": "RQ-4",
330
+ "question": "How are changes tracked and what is the audit trail?",
331
+ "answer_fields": "lineage.lineage_path, lineage.parent_receipt_hash, lineage.chain_depth",
332
+ "framework_refs": "EU AI Act Annex IV §2(b), §4; SR 11-7 §V.A; FDA PCCP §II.A",
333
+ },
334
+ {
335
+ "id": "RQ-5",
336
+ "question": "Is this statement signed and independently attested?",
337
+ "answer_fields": "signatures.sigstore, signatures.aaaa_nexus, signatures.local_sign",
338
+ "framework_refs": "EU AI Act Annex IV §5; FDA PCCP §II.C; CMMC-AI MEASURE 2.5",
339
+ },
340
+ ]
341
+
342
+
343
+ # ---------------------------------------------------------------------------
344
+ # Internal helpers
345
+ # ---------------------------------------------------------------------------
346
+
347
+ def _signatures_status(receipt: dict[str, Any]) -> str:
348
+ """Return 'SIGNED', 'PARTIAL', or 'UNSIGNED'."""
349
+ sigs = receipt.get("signatures") or {}
350
+ has_sigstore = bool((sigs.get("sigstore") or {}).get("rekor_uuid"))
351
+ has_nexus = bool((sigs.get("aaaa_nexus") or {}).get("signature"))
352
+ has_local = bool((sigs.get("local_sign") or {}).get("signature"))
353
+ if has_sigstore and has_nexus:
354
+ return "SIGNED"
355
+ if has_sigstore or has_nexus or has_local:
356
+ return "PARTIAL"
357
+ return "UNSIGNED"
358
+
359
+
360
+ def _lineage_digest(receipt: dict[str, Any]) -> str | None:
361
+ """Return sha256 of the canonical lineage block, or None."""
362
+ lineage = receipt.get("lineage")
363
+ if not lineage:
364
+ return None
365
+ canonical = json.dumps(lineage, sort_keys=True, separators=(",", ":"))
366
+ return hashlib.sha256(canonical.encode()).hexdigest()
367
+
368
+
369
+ def _receipt_summary(receipt: dict[str, Any]) -> dict[str, Any]:
370
+ project = receipt.get("project") or {}
371
+ certify = receipt.get("certify") or {}
372
+ wire = receipt.get("wire") or {}
373
+ scout = receipt.get("scout") or {}
374
+ return {
375
+ "schema_version": receipt.get("schema_version", ""),
376
+ "generated_at_utc": receipt.get("generated_at_utc", ""),
377
+ "forge_version": receipt.get("forge_version", ""),
378
+ "verdict": receipt.get("verdict", "FAIL"),
379
+ "project_name": project.get("name", ""),
380
+ "project_language": project.get("language", "python"),
381
+ "certify_score": float(certify.get("score", 0.0)),
382
+ "wire_verdict": wire.get("verdict", "FAIL"),
383
+ "wire_violation_count": int(wire.get("violation_count", 0)),
384
+ "symbol_count": int(scout.get("symbol_count", 0)),
385
+ }
386
+
387
+
388
+ def _attestation_block(receipt: dict[str, Any]) -> dict[str, Any]:
389
+ lean4 = receipt.get("lean4_attestation") or {}
390
+ corpora = lean4.get("corpora") or []
391
+ return {
392
+ "total_theorems": int(lean4.get("total_theorems", 0)),
393
+ "total_sorry": sum(int(c.get("sorry_count", 0)) for c in corpora),
394
+ "corpora_count": len(corpora),
395
+ "summary": lean4.get("summary", "no attestation"),
396
+ "corpora": [
397
+ {
398
+ "name": c.get("name", ""),
399
+ "ref_sha": c.get("ref_sha", ""),
400
+ "theorem_count": int(c.get("theorem_count", 0)),
401
+ "sorry_count": int(c.get("sorry_count", 0)),
402
+ }
403
+ for c in corpora
404
+ ],
405
+ }
406
+
407
+
408
+ # ---------------------------------------------------------------------------
409
+ # Public API
410
+ # ---------------------------------------------------------------------------
411
+
412
+ def render_cs1(receipt: dict[str, Any]) -> dict[str, Any]:
413
+ """Build a CS-1 dict from a ForgeReceiptV1.
414
+
415
+ Raises ValueError if required Receipt fields are missing.
416
+ Returns a JSON-serializable dict with schema_version
417
+ ``atomadic-forge.cs1/v1``.
418
+ """
419
+ for field in _REQUIRED_RECEIPT_FIELDS:
420
+ if field not in receipt:
421
+ raise ValueError(f"Receipt missing required field: {field!r}")
422
+
423
+ return {
424
+ "schema_version": CS1_SCHEMA_VERSION,
425
+ "generated_at_utc": _dt.datetime.now(_dt.timezone.utc).strftime(
426
+ "%Y-%m-%dT%H:%M:%SZ"
427
+ ),
428
+ "receipt_schema_version": receipt.get("schema_version", ""),
429
+ "receipt_generated_at_utc": receipt.get("generated_at_utc", ""),
430
+ "project": dict(receipt.get("project") or {}),
431
+ "receipt_summary": _receipt_summary(receipt),
432
+ "attestation": _attestation_block(receipt),
433
+ "compliance_claims": (
434
+ _EU_AI_ACT_CLAIMS
435
+ + _SR_11_7_CLAIMS
436
+ + _FDA_PCCP_CLAIMS
437
+ + _CMMC_AI_CLAIMS
438
+ ),
439
+ "regulator_questions": _REGULATOR_QUESTIONS,
440
+ "lineage_chain_digest": _lineage_digest(receipt),
441
+ "signatures_status": _signatures_status(receipt),
442
+ "notes": list(receipt.get("notes") or []),
443
+ }
444
+
445
+
446
+ def render_cs1_markdown(cs1: dict[str, Any]) -> str:
447
+ """Render a CS-1 dict to a regulator-friendly Markdown string.
448
+
449
+ Pure: no I/O, stdlib only. The output is structured Markdown
450
+ that regulators can read directly or convert to PDF via pandoc.
451
+ """
452
+ lines: list[str] = []
453
+ a = lines.append
454
+
455
+ rs = cs1.get("receipt_summary") or {}
456
+ proj = cs1.get("project") or {}
457
+ att = cs1.get("attestation") or {}
458
+ sig_status = cs1.get("signatures_status", "UNSIGNED")
459
+ lineage_digest = cs1.get("lineage_chain_digest")
460
+
461
+ a("# Atomadic Forge Conformity Statement CS-1")
462
+ a("")
463
+ a(f"**Schema version:** `{cs1.get('schema_version', '')}` ")
464
+ a(f"**Generated:** {cs1.get('generated_at_utc', '')} ")
465
+ a(f"**Receipt schema:** `{cs1.get('receipt_schema_version', '')}` ")
466
+ a(f"**Receipt timestamp:** {cs1.get('receipt_generated_at_utc', '')} ")
467
+ a(f"**Signature status:** {sig_status} ")
468
+ a("")
469
+ a("---")
470
+ a("")
471
+
472
+ # Project
473
+ a("## Project")
474
+ a("")
475
+ a("| Field | Value |")
476
+ a("|-------|-------|")
477
+ a(f"| Name | `{rs.get('project_name', '')}` |")
478
+ a(f"| Primary language | {rs.get('project_language', 'python')} |")
479
+ if proj.get("languages"):
480
+ langs = ", ".join(
481
+ f"{k}: {v}" for k, v in sorted(proj["languages"].items())
482
+ )
483
+ a(f"| Languages | {langs} |")
484
+ if proj.get("vcs"):
485
+ vcs = proj["vcs"]
486
+ branch = vcs.get("branch", "")
487
+ sha = vcs.get("short_sha", "")
488
+ dirty = " (dirty)" if vcs.get("dirty") else ""
489
+ a(f"| VCS | {branch}@{sha}{dirty} |")
490
+ a("")
491
+
492
+ # Verdict summary
493
+ a("## Verdict Summary")
494
+ a("")
495
+ verdict = rs.get("verdict", "FAIL")
496
+ glyph = {"PASS": "✓", "FAIL": "✗", "REFINE": "↻", "QUARANTINE": "⏸"}.get(
497
+ verdict, "?"
498
+ )
499
+ a(f"**{glyph} {verdict}**")
500
+ a("")
501
+ a("| Check | Result |")
502
+ a("|-------|--------|")
503
+ a(f"| Wire scan | {rs.get('wire_verdict', 'FAIL')} ({rs.get('wire_violation_count', 0)} violations) |")
504
+ a(f"| Certify score | {rs.get('certify_score', 0.0):.1f} / 100 |")
505
+ a(f"| Symbol count | {rs.get('symbol_count', 0)} |")
506
+ a("")
507
+
508
+ # Lean4 attestation
509
+ a("## Lean4 Attestation")
510
+ a("")
511
+ if att.get("corpora_count", 0) == 0:
512
+ a("_No Lean4 attestation attached to this Receipt._")
513
+ else:
514
+ a(f"**{att.get('total_theorems', 0)} theorems** across "
515
+ f"**{att.get('corpora_count', 0)} corpus/corpora** — "
516
+ f"**{att.get('total_sorry', 0)} sorry**")
517
+ a("")
518
+ a("| Corpus | Ref SHA | Theorems | Sorry |")
519
+ a("|--------|---------|----------|-------|")
520
+ for c in att.get("corpora") or []:
521
+ sha = (c.get("ref_sha") or "")[:12]
522
+ a(f"| {c.get('name', '')} | `{sha}` | "
523
+ f"{c.get('theorem_count', 0)} | {c.get('sorry_count', 0)} |")
524
+ a("")
525
+
526
+ # Lineage
527
+ a("## Vanguard Lineage Chain")
528
+ a("")
529
+ if lineage_digest:
530
+ a(f"Lineage block SHA-256: `{lineage_digest}`")
531
+ else:
532
+ a("_No lineage block attached to this Receipt._")
533
+ a("")
534
+
535
+ # Regulator questions
536
+ a("## Regulator Questions and Answers")
537
+ a("")
538
+ for rq in cs1.get("regulator_questions") or []:
539
+ a(f"### {rq.get('id', '')} — {rq.get('question', '')}")
540
+ a("")
541
+ a(f"**Receipt fields:** `{rq.get('answer_fields', '')}` ")
542
+ a(f"**Framework refs:** {rq.get('framework_refs', '')} ")
543
+ a("")
544
+
545
+ # Compliance claims by framework
546
+ claims = cs1.get("compliance_claims") or []
547
+ frameworks_seen: list[str] = []
548
+ frameworks_order: list[str] = []
549
+ for c in claims:
550
+ fw = c.get("framework", "")
551
+ if fw not in frameworks_seen:
552
+ frameworks_seen.append(fw)
553
+ frameworks_order.append(fw)
554
+
555
+ a("## Compliance Claims")
556
+ a("")
557
+ for fw in frameworks_order:
558
+ a(f"### {fw}")
559
+ a("")
560
+ fw_claims = [c for c in claims if c.get("framework") == fw]
561
+ for claim in fw_claims:
562
+ a(f"#### {claim.get('ref', '')} — {claim.get('title', '')}")
563
+ a("")
564
+ a(f"**Citation:** {claim.get('citation', '')} ")
565
+ a(f"**Receipt field(s):** `{claim.get('receipt_field', '')}` ")
566
+ a("")
567
+ a(claim.get("evidence", ""))
568
+ a("")
569
+
570
+ # Mapping doc references
571
+ a("## Mapping Document References")
572
+ a("")
573
+ a("| Document | Path |")
574
+ a("|----------|------|")
575
+ a("| EU AI Act Annex IV Mapping | `docs/compliance/EU_AI_ACT_ANNEX_IV.md` |")
576
+ a("| SR 11-7 Mapping | `docs/compliance/SR_11-7_MAPPING.md` |")
577
+ a("| FDA PCCP Mapping | `docs/compliance/FDA_PCCP_MAPPING.md` |")
578
+ a("| CMMC-AI Mapping | `docs/compliance/CMMC_AI_MAPPING.md` |")
579
+ a("")
580
+
581
+ # Footer
582
+ a("---")
583
+ a("")
584
+ a(f"_Generated by Atomadic Forge CS-1 renderer — "
585
+ f"`{cs1.get('schema_version', '')}`_")
586
+ a("")
587
+
588
+ return "\n".join(lines)