@rvdbreemen/adr-kit-opencode 0.52.0

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 (129) hide show
  1. package/.claude-plugin/plugin.json +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +850 -0
  4. package/bin/adr +1552 -0
  5. package/bin/adr-audit +454 -0
  6. package/bin/adr-context +584 -0
  7. package/bin/adr-discover +546 -0
  8. package/bin/adr-doctor +166 -0
  9. package/bin/adr-generate-scripts +421 -0
  10. package/bin/adr-grill-signal +131 -0
  11. package/bin/adr-guardian +1263 -0
  12. package/bin/adr-index +199 -0
  13. package/bin/adr-judge +2832 -0
  14. package/bin/adr-judge-precommit +87 -0
  15. package/bin/adr-lint +2087 -0
  16. package/bin/adr-mcp +1093 -0
  17. package/bin/adr-migrate +644 -0
  18. package/bin/adr-quality +275 -0
  19. package/bin/adr-readiness +211 -0
  20. package/bin/adr-readiness-ci +111 -0
  21. package/bin/adr-related +401 -0
  22. package/bin/adr-renumber +254 -0
  23. package/bin/adr-retire +467 -0
  24. package/bin/adr-settings +399 -0
  25. package/bin/adr-status +797 -0
  26. package/bin/adr-suggest +803 -0
  27. package/bin/adr-watch +674 -0
  28. package/bin/adr_catalog.py +536 -0
  29. package/bin/adr_config.py +280 -0
  30. package/bin/adr_doctor_checks.py +407 -0
  31. package/bin/adr_doctor_core.py +342 -0
  32. package/bin/adr_doctor_models.py +186 -0
  33. package/bin/adr_doctor_probes.py +216 -0
  34. package/bin/adr_format.py +786 -0
  35. package/bin/adr_grill_signal.py +123 -0
  36. package/bin/adr_guardian_queue.py +218 -0
  37. package/bin/adr_history_scan.py +278 -0
  38. package/bin/adr_index_core.py +443 -0
  39. package/bin/adr_llm.py +333 -0
  40. package/bin/adr_llm_judge_migration.py +314 -0
  41. package/bin/adr_quality_core.py +674 -0
  42. package/bin/adr_query.py +678 -0
  43. package/bin/adr_readiness.py +442 -0
  44. package/bin/adr_readiness_ci.py +123 -0
  45. package/bin/adr_regex.py +165 -0
  46. package/bin/adr_regex_worker.py +30 -0
  47. package/bin/adr_retrieval_health.py +385 -0
  48. package/bin/adr_schema.py +448 -0
  49. package/bin/adr_state.py +172 -0
  50. package/bin/bump-version +71 -0
  51. package/clients/workflows.json +229 -0
  52. package/hooks/__init__.py +1 -0
  53. package/hooks/adapters/__init__.py +13 -0
  54. package/hooks/adapters/claude.py +27 -0
  55. package/hooks/adapters/codex.py +26 -0
  56. package/hooks/adapters/copilot.py +11 -0
  57. package/hooks/adr-hook.py +128 -0
  58. package/hooks/adr_hook_core.py +843 -0
  59. package/hooks/adr_pr_guard.py +367 -0
  60. package/instructions/ADR-guide.md +48 -0
  61. package/instructions/adr.coding.md +82 -0
  62. package/instructions/adr.review.md +182 -0
  63. package/opencode/plugin.ts +451 -0
  64. package/package.json +41 -0
  65. package/schemas/adr-context-probes.schema.json +56 -0
  66. package/schemas/adr-enforcement.schema.json +57 -0
  67. package/schemas/adr-frontmatter.schema.json +144 -0
  68. package/schemas/adr-index.schema.json +276 -0
  69. package/schemas/adr-kit-config.schema.json +371 -0
  70. package/schemas/adr-readiness.schema.json +41 -0
  71. package/schemas/client-capabilities.schema.json +503 -0
  72. package/schemas/client-certification.schema.json +101 -0
  73. package/schemas/doctor-output.schema.json +92 -0
  74. package/schemas/marketplace.json.schema.json +70 -0
  75. package/schemas/plugin.json.schema.json +67 -0
  76. package/scripts/adr_settings.py +239 -0
  77. package/scripts/benchmark-adr-grilling.py +323 -0
  78. package/scripts/benchmark-client-generation.py +178 -0
  79. package/scripts/build-client-adapters.py +139 -0
  80. package/scripts/bump-version.py +304 -0
  81. package/scripts/check-branch-sync.py +243 -0
  82. package/scripts/check-release-version.py +81 -0
  83. package/scripts/client_certification.py +153 -0
  84. package/scripts/client_evidence.py +280 -0
  85. package/scripts/client_generation.py +288 -0
  86. package/scripts/client_generation_artifacts.py +351 -0
  87. package/scripts/client_generation_model.py +173 -0
  88. package/scripts/client_generation_state.py +260 -0
  89. package/scripts/client_support_matrix.py +360 -0
  90. package/scripts/install-agent-envs.py +300 -0
  91. package/scripts/probe-client-events.py +183 -0
  92. package/scripts/project_setup.py +379 -0
  93. package/scripts/refresh-otgw-corpus.py +219 -0
  94. package/scripts/settings.py +81 -0
  95. package/scripts/setup-project.py +205 -0
  96. package/scripts/sync-agent-plugins.py +17 -0
  97. package/scripts/version_sites.py +377 -0
  98. package/skills/adr/SKILL.md +780 -0
  99. package/skills/audit/SKILL.md +103 -0
  100. package/skills/context/SKILL.md +77 -0
  101. package/skills/grill/SKILL.md +84 -0
  102. package/skills/grill/agents/openai.yaml +4 -0
  103. package/skills/guardian/SKILL.md +316 -0
  104. package/skills/init/SKILL.md +499 -0
  105. package/skills/install-hooks/SKILL.md +154 -0
  106. package/skills/judge/SKILL.md +168 -0
  107. package/skills/lint/SKILL.md +321 -0
  108. package/skills/migrate/SKILL.md +313 -0
  109. package/skills/related/SKILL.md +62 -0
  110. package/skills/retire/SKILL.md +41 -0
  111. package/skills/review/SKILL.md +167 -0
  112. package/skills/settings/SKILL.md +73 -0
  113. package/skills/setup/SKILL.md +128 -0
  114. package/skills/supersede/SKILL.md +136 -0
  115. package/skills/upgrade/SKILL.md +273 -0
  116. package/templates/adr-kit-guide.md +354 -0
  117. package/templates/adr-template.canonical.md +115 -0
  118. package/templates/adr-template.madr.md +131 -0
  119. package/templates/adr-template.md +131 -0
  120. package/templates/adr-template.nygard.md +111 -0
  121. package/templates/cc-settings/guardian-hook-entry.json +9 -0
  122. package/templates/githooks/pre-commit +337 -0
  123. package/templates/github-workflows/adr-audit.yml +58 -0
  124. package/templates/github-workflows/adr-guardian-audit.yml +133 -0
  125. package/templates/github-workflows/adr-index-check.yml +30 -0
  126. package/templates/github-workflows/adr-judge.yml +31 -0
  127. package/templates/github-workflows/adr-readiness.yml +18 -0
  128. package/templates/validate_adr_template.py +38 -0
  129. package/templates/validate_adr_template.sh +74 -0
@@ -0,0 +1,153 @@
1
+ """Validate certification evidence.
2
+
3
+ Rendering the support document lives in `client_support_matrix.py`, which this
4
+ module re-exports `support_matrix` from so no caller had to change when the two
5
+ were split apart (ADR-010's support-module line budget).
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import datetime as dt
11
+ import re
12
+
13
+ CLIENTS = ("claude-code-cli", "codex-cli", "github-copilot-cli")
14
+ OUTCOMES = {
15
+ "workflow-discovery", "task-context", "edit-governance", "mcp",
16
+ "pre-commit", "lifecycle", "doctor",
17
+ }
18
+ FIXTURES = {"generator", "schema", "hook", "installer", "doctor", "package", "adr-lint", "adr-index", "regression"}
19
+ SMOKE = {
20
+ "install", "list", "workflow-discovery", "workflow-invocation", "instructions",
21
+ "hook-outcomes", "mcp-initialize", "mcp-list", "mcp-call", "second-install-noop",
22
+ "verified-update", "rollback", "doctor", "uninstall-preserves-user-state",
23
+ }
24
+ PRESERVATION = {
25
+ "unrelated-config", "instruction-bytes-outside-markers", "local-guide",
26
+ "previous-healthy-payload", "source-checkout",
27
+ }
28
+ NATIVE_OPTIMIZATION = {
29
+ "native-manifest-layout", "native-discovery-syntax", "client-skill-metadata",
30
+ "concise-prompt-behavior", "native-hook-shape", "no-deprecated-prompt-claim",
31
+ }
32
+
33
+ def _all_true(value: object, required: set[str], label: str, errors: list[str]) -> None:
34
+ if not isinstance(value, dict):
35
+ errors.append(f"{label}: expected object")
36
+ return
37
+ missing = sorted(required - {key for key, passed in value.items() if passed is True})
38
+ if missing:
39
+ errors.append(f"{label}: missing passing evidence: {', '.join(missing)}")
40
+
41
+
42
+ def validate(bundle: object, candidate: str, release_candidate: bool, max_age_days: int) -> list[str]:
43
+ errors: list[str] = []
44
+ if not isinstance(bundle, dict) or bundle.get("schema_version") != 1:
45
+ return ["bundle schema_version must be 1"]
46
+ if bundle.get("candidate_commit") != candidate:
47
+ errors.append("bundle candidate commit mismatch")
48
+ if release_candidate and not re.fullmatch(r"[0-9a-fA-F]{7,64}", candidate):
49
+ errors.append("release-candidate evidence must bind to a real commit hash")
50
+ try:
51
+ age = (dt.date.today() - dt.date.fromisoformat(bundle["contract_date"])).days
52
+ if age < 0 or age > max_age_days:
53
+ errors.append("bundle contract date is stale")
54
+ except (KeyError, TypeError, ValueError):
55
+ errors.append("bundle contract date is invalid")
56
+ records = bundle.get("records")
57
+ if not isinstance(records, list) or [record.get("client") for record in records] != list(CLIENTS):
58
+ return errors + ["records must contain exactly the three clients in canonical order"]
59
+ for record in records:
60
+ client = record["client"]
61
+ prefix = f"{client}"
62
+ if record.get("candidate_commit") != candidate:
63
+ errors.append(f"{prefix}: candidate commit mismatch")
64
+ if record.get("contract_date") != bundle.get("contract_date"):
65
+ errors.append(f"{prefix}: contract date mismatch")
66
+ for key in ("client_version", "adr_kit_version"):
67
+ if not record.get(key):
68
+ errors.append(f"{prefix}: {key} missing")
69
+ if record.get("surface") != "cli" or record.get("os") != "windows":
70
+ errors.append(f"{prefix}: only the Windows CLI identity is certifiable")
71
+ if release_candidate and record.get("evidence_mode") != "native":
72
+ errors.append(f"{prefix}: native release-candidate evidence missing")
73
+ if release_candidate and (
74
+ record.get("working_tree_clean") is not True
75
+ or not re.fullmatch(
76
+ r"[0-9a-f]{64}",
77
+ str(record.get("artifact_sha256", "")),
78
+ )
79
+ ):
80
+ errors.append(
81
+ f"{prefix}: clean commit-bound artifact hash missing"
82
+ )
83
+ if not record.get("environment_fingerprint") or not record.get("evidence_links"):
84
+ errors.append(f"{prefix}: retained redacted environment/log evidence missing")
85
+ _all_true(record.get("required_outcomes"), OUTCOMES, f"{prefix} outcomes", errors)
86
+ _all_true(record.get("fixtures"), FIXTURES, f"{prefix} fixtures", errors)
87
+ _all_true(record.get("native_smoke"), SMOKE, f"{prefix} native smoke", errors)
88
+ _all_true(record.get("lifecycle_preservation"), PRESERVATION, f"{prefix} preservation", errors)
89
+ _all_true(record.get("native_optimization"), NATIVE_OPTIMIZATION, f"{prefix} native optimization", errors)
90
+ if record.get("native_optimization", {}).get("deprecated-prompt-first-class") is True:
91
+ errors.append(f"{prefix}: deprecated prompt surface advertised")
92
+ platforms = record.get("platforms", {})
93
+ if platforms.get("windows", {}).get("status") != "pass":
94
+ errors.append(f"{prefix}: Windows evidence is not passing")
95
+ for platform in ("macos", "linux"):
96
+ status = platforms.get(platform, {}).get("status")
97
+ reason = platforms.get(platform, {}).get("reason")
98
+ if status not in {"pass", "fail", "not-run"} or (status == "not-run" and not reason):
99
+ errors.append(f"{prefix}: {platform} needs a result or not-run reason")
100
+ benchmarks = record.get("benchmarks", [])
101
+ states = {item.get("state"): item for item in benchmarks if isinstance(item, dict)}
102
+ for state, limits in {"cold": (1000, 2000, 5000), "warm": (150, 500, 1000)}.items():
103
+ item = states.get(state)
104
+ if not item:
105
+ errors.append(f"{prefix}: {state} benchmark missing")
106
+ continue
107
+ if item.get("samples", 0) < 5 or item.get("timed_out") is not False:
108
+ errors.append(f"{prefix}: {state} benchmark method/timeout failed")
109
+ if not item.get("method_id") or item.get("hard_timeout_ms") != limits[2]:
110
+ errors.append(f"{prefix}: {state} benchmark method/timeout failed")
111
+ if item.get("p50_ms", 1e99) > limits[0] or item.get("p95_ms", 1e99) > limits[1] or item.get("max_ms", 1e99) > limits[2]:
112
+ errors.append(f"{prefix}: {state} latency budget failed")
113
+ if item.get("p95_ms", 1e99) > item.get("baseline_p95_ms", 0) * 1.2:
114
+ errors.append(f"{prefix}: {state} p95 regressed more than 20%")
115
+ if state == "warm" and item.get("writes") != 0:
116
+ errors.append(f"{prefix}: unchanged generation rewrote output")
117
+ inventory = record.get("inventory", {})
118
+ if inventory.get("bin_baseline") != 27 or inventory.get("scripts_baseline") != 3:
119
+ errors.append(f"{prefix}: executable baseline missing")
120
+ if inventory.get("task_40_added", 99) > 4 and not inventory.get("exception"):
121
+ errors.append(f"{prefix}: executable budget exceeded")
122
+ dependencies = record.get("dependencies", {})
123
+ if dependencies.get("runtime") != [] or dependencies.get("development_in_runtime") is not False:
124
+ errors.append(f"{prefix}: runtime dependency policy failed")
125
+ for pin in dependencies.get("exact_pins", []):
126
+ required = {
127
+ "adr",
128
+ "compatibility_reason",
129
+ "review_after",
130
+ "update_mechanism",
131
+ "removal_test",
132
+ }
133
+ if not isinstance(pin, dict) or not required.issubset(pin):
134
+ errors.append(f"{prefix}: exact dependency pin lacks evidence")
135
+ if not record.get("source_links"):
136
+ errors.append(f"{prefix}: source links missing")
137
+ policy = record.get("release_policy", {})
138
+ if not policy.get("archive_allowlist_clean") or not policy.get("consolidated_candidate"):
139
+ errors.append(f"{prefix}: release archive/candidate policy failed")
140
+ if policy.get("stable_releases_today", 99) >= 1 and not all(
141
+ policy.get(key) for key in ("emergency_reason", "affected_versions", "rollback_proof", "changelog", "followup_review")
142
+ ):
143
+ errors.append(f"{prefix}: same-day stable release limit exceeded")
144
+ if policy.get("default_or_hook_reversal") and not policy.get("superseding_proposed_adr"):
145
+ errors.append(f"{prefix}: policy reversal lacks Proposed ADR")
146
+ return errors
147
+
148
+
149
+
150
+ # Rendering lives in its own module (ADR-010 line budget). Re-exported so
151
+ # `from client_certification import support_matrix, validate` keeps working:
152
+ # the seam is internal, and callers should not have to learn about it.
153
+ from client_support_matrix import support_matrix # noqa: E402,F401
@@ -0,0 +1,280 @@
1
+ """Assemble independent native observations into release-gate evidence."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import re
8
+ from pathlib import Path
9
+
10
+ from client_certification import (
11
+ FIXTURES,
12
+ NATIVE_OPTIMIZATION,
13
+ OUTCOMES,
14
+ PRESERVATION,
15
+ SMOKE,
16
+ _all_true,
17
+ validate,
18
+ )
19
+
20
+ NATIVE_EVIDENCE_PATHS = (
21
+ ("claude-code-cli", "claude/windows-native.json"),
22
+ ("codex-cli", "codex/windows-native.json"),
23
+ ("github-copilot-cli", "copilot/windows-native.json"),
24
+ )
25
+ NATIVE_LIFECYCLE = {
26
+ "claude-code-cli": {
27
+ "marketplace_add", "install", "list", "disable", "enable",
28
+ "no_op_update", "uninstall", "reinstall",
29
+ },
30
+ "codex-cli": {
31
+ "marketplace_add", "install", "list", "remove", "reinstall",
32
+ "verified_update_via_remove_add",
33
+ },
34
+ "github-copilot-cli": {
35
+ "marketplace_add", "install", "list", "no_op_update", "uninstall",
36
+ "reinstall",
37
+ },
38
+ }
39
+
40
+
41
+ class CertificationError(RuntimeError):
42
+ """Native evidence cannot form a release-candidate bundle."""
43
+
44
+
45
+ def _read_json(path: Path, label: str) -> dict:
46
+ try:
47
+ value = json.loads(path.read_text(encoding="utf-8"))
48
+ except (OSError, UnicodeError, json.JSONDecodeError) as exc:
49
+ raise CertificationError(f"{label} is unreadable: {path}: {exc}") from exc
50
+ if not isinstance(value, dict):
51
+ raise CertificationError(f"{label} must be a JSON object: {path}")
52
+ return value
53
+
54
+
55
+ def _generation_benchmarks(source_root: Path) -> list[dict]:
56
+ evidence = _read_json(
57
+ source_root / "packaging/client-generation-benchmark.json",
58
+ "generation benchmark evidence",
59
+ )
60
+ baseline = _read_json(
61
+ source_root / "packaging/client-generation-baseline.json",
62
+ "generation benchmark baseline",
63
+ )
64
+ if evidence.get("passed") is not True or evidence.get("platform", {}).get("os") != "nt":
65
+ raise CertificationError("passing Windows-native generation evidence is required")
66
+ result = []
67
+ for source_name, state in (("clean", "cold"), ("warm", "warm")):
68
+ source = evidence[source_name]
69
+ elapsed = source["elapsed_ms"]
70
+ result.append({
71
+ "method_id": "client-generation-v1",
72
+ "state": state,
73
+ "samples": source["sample_count"],
74
+ "p50_ms": elapsed["p50"],
75
+ "p95_ms": elapsed["p95"],
76
+ "max_ms": elapsed["max"],
77
+ "hard_timeout_ms": evidence["methodology"]["hard_timeouts_ms"][source_name],
78
+ "timed_out": False,
79
+ "baseline_p95_ms": baseline["p95_ms"][source_name],
80
+ "writes": source["files_written"],
81
+ })
82
+ return result
83
+
84
+
85
+ def _shared_inventory(source_root: Path) -> dict:
86
+ value = _read_json(
87
+ source_root / "packaging/executables.json",
88
+ "executable inventory",
89
+ )
90
+ return {
91
+ "bin_baseline": 27,
92
+ "scripts_baseline": 3,
93
+ "task_40_added": len(value.get("task_40_added_public_entrypoints", [])),
94
+ "exception": None,
95
+ }
96
+
97
+
98
+ def _shared_dependencies(source_root: Path) -> dict:
99
+ value = _read_json(
100
+ source_root / "packaging/dependencies.json",
101
+ "dependency evidence",
102
+ )
103
+ return {
104
+ "runtime": value.get("runtime"),
105
+ "development": [
106
+ item.get("name") for item in value.get("development", [])
107
+ ],
108
+ "licenses": value.get("licenses", []),
109
+ "development_in_runtime": False,
110
+ "exact_pins": [
111
+ item for item in value.get("development", [])
112
+ if item.get("exact_pin") is not None
113
+ ],
114
+ }
115
+
116
+
117
+ def _load_observation(path: Path, expected_client: str) -> dict:
118
+ value = _read_json(path, "native evidence")
119
+ if value.get("schema_version") != 1:
120
+ raise CertificationError(f"{path}: native evidence schema_version must be 1")
121
+ if value.get("client") != expected_client:
122
+ raise CertificationError(f"{path}: expected client {expected_client}")
123
+ return value
124
+
125
+
126
+ def _record(
127
+ observation: dict,
128
+ client: str,
129
+ candidate: str,
130
+ benchmarks: list[dict],
131
+ inventory: dict,
132
+ dependencies: dict,
133
+ ) -> dict:
134
+ prefix = client
135
+ if observation.get("source_commit") != candidate:
136
+ raise CertificationError(f"{prefix}: native observation commit mismatch")
137
+ if observation.get("working_tree_clean") is not True:
138
+ raise CertificationError(f"{prefix}: native observation was not captured clean")
139
+ if observation.get("release_eligible") is not True:
140
+ raise CertificationError(f"{prefix}: native observation is not release eligible")
141
+ for key in ("client_version", "adr_kit_version", "environment"):
142
+ if not observation.get(key):
143
+ raise CertificationError(f"{prefix}: {key} is missing")
144
+ detail_errors: list[str] = []
145
+ _all_true(
146
+ observation.get("native_lifecycle"),
147
+ NATIVE_LIFECYCLE[client],
148
+ f"{prefix} native lifecycle",
149
+ detail_errors,
150
+ )
151
+ if detail_errors:
152
+ raise CertificationError("; ".join(detail_errors))
153
+ if not observation.get("evidence_links"):
154
+ raise CertificationError(f"{prefix}: retained evidence links are missing")
155
+ official_url = observation.get("official_contract", {}).get("url")
156
+ if not isinstance(official_url, str) or not official_url.startswith("https://"):
157
+ raise CertificationError(f"{prefix}: official contract URL is missing")
158
+ artifact = str(observation.get("prepared_payload_sha256", ""))
159
+ if not re.fullmatch(r"[0-9a-f]{64}", artifact):
160
+ raise CertificationError(f"{prefix}: prepared payload hash is invalid")
161
+ certification = observation.get("certification")
162
+ if not isinstance(certification, dict):
163
+ raise CertificationError(f"{prefix}: certification outcome maps are missing")
164
+ required_maps = (
165
+ ("required_outcomes", OUTCOMES),
166
+ ("fixtures", FIXTURES),
167
+ ("native_smoke", SMOKE),
168
+ ("lifecycle_preservation", PRESERVATION),
169
+ ("native_optimization", NATIVE_OPTIMIZATION),
170
+ )
171
+ map_errors: list[str] = []
172
+ for key, required in required_maps:
173
+ _all_true(certification.get(key), required, f"{prefix} {key}", map_errors)
174
+ if map_errors:
175
+ raise CertificationError("; ".join(map_errors))
176
+ hook = observation.get("latency_evidence", {}).get("hooks", {})
177
+ if (
178
+ hook.get("method_id") != "adr-kit-hook-latency-v1"
179
+ or hook.get("samples", 0) < 30
180
+ or hook.get("all_targets_met") is not True
181
+ ):
182
+ raise CertificationError(f"{prefix}: release hook benchmark is incomplete")
183
+ policy = certification.get("release_policy")
184
+ if not isinstance(policy, dict):
185
+ raise CertificationError(f"{prefix}: release policy evidence is missing")
186
+ return {
187
+ "client": client,
188
+ "client_version": observation["client_version"],
189
+ "adr_kit_version": observation["adr_kit_version"],
190
+ "surface": "cli",
191
+ "os": "windows",
192
+ "candidate_commit": candidate,
193
+ "contract_date": observation.get("contract_date"),
194
+ "evidence_mode": "native",
195
+ "working_tree_clean": True,
196
+ "artifact_sha256": artifact,
197
+ "environment_fingerprint": observation["environment"],
198
+ "required_outcomes": certification["required_outcomes"],
199
+ "fixtures": certification["fixtures"],
200
+ "native_smoke": certification["native_smoke"],
201
+ "platforms": {
202
+ "windows": {
203
+ "status": observation.get("platforms", {}).get("windows", {}).get("status"),
204
+ "reason": "independent native Windows smoke passed",
205
+ },
206
+ "macos": observation.get("platforms", {}).get("macos"),
207
+ "linux": observation.get("platforms", {}).get("linux"),
208
+ },
209
+ "benchmarks": benchmarks,
210
+ "degradations": observation.get("degradations", []),
211
+ "lifecycle_preservation": certification["lifecycle_preservation"],
212
+ "native_optimization": certification["native_optimization"],
213
+ "inventory": inventory,
214
+ "dependencies": dependencies,
215
+ "release_policy": policy,
216
+ "source_links": [official_url],
217
+ "evidence_links": observation["evidence_links"],
218
+ }
219
+
220
+
221
+ def assemble_native_bundle(
222
+ evidence_root: Path,
223
+ source_root: Path,
224
+ candidate: str,
225
+ ) -> dict:
226
+ """Build one gate-compatible bundle from three independent observations."""
227
+ if not re.fullmatch(r"[0-9a-f]{40,64}", candidate):
228
+ raise CertificationError("native bundle candidate must be a full commit hash")
229
+ benchmarks = _generation_benchmarks(source_root)
230
+ inventory = _shared_inventory(source_root)
231
+ dependencies = _shared_dependencies(source_root)
232
+ records = [
233
+ _record(
234
+ _load_observation(evidence_root / relative, client),
235
+ client,
236
+ candidate,
237
+ benchmarks,
238
+ inventory,
239
+ dependencies,
240
+ )
241
+ for client, relative in NATIVE_EVIDENCE_PATHS
242
+ ]
243
+ if len({record["artifact_sha256"] for record in records}) != 1:
244
+ raise CertificationError("native observations do not identify one prepared payload")
245
+ dates = {record["contract_date"] for record in records}
246
+ if len(dates) != 1 or None in dates:
247
+ raise CertificationError("native observations do not share one contract date")
248
+ policies = {
249
+ json.dumps(record["release_policy"], sort_keys=True) for record in records
250
+ }
251
+ if len(policies) != 1:
252
+ raise CertificationError("native observations do not share one release policy")
253
+ bundle = {
254
+ "schema_version": 1,
255
+ "candidate_commit": candidate,
256
+ "contract_date": next(iter(dates)),
257
+ "records": records,
258
+ }
259
+ errors = validate(bundle, candidate, True, 30)
260
+ if errors:
261
+ raise CertificationError("; ".join(errors))
262
+ return bundle
263
+
264
+
265
+ def write_bundle(path: Path, bundle: dict, check: bool) -> bool:
266
+ """Write atomically, or report whether an existing output matches."""
267
+ payload = json.dumps(bundle, indent=2, sort_keys=True) + "\n"
268
+ if check:
269
+ return path.is_file() and path.read_text(encoding="utf-8") == payload
270
+ path.parent.mkdir(parents=True, exist_ok=True)
271
+ temporary = path.with_suffix(path.suffix + f".{os.getpid()}.tmp")
272
+ try:
273
+ temporary.write_text(payload, encoding="utf-8", newline="\n")
274
+ os.replace(temporary, path)
275
+ finally:
276
+ try:
277
+ temporary.unlink()
278
+ except FileNotFoundError:
279
+ pass
280
+ return True