hotdocs 0.1.0a1__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.
- hotdocs/__init__.py +3 -0
- hotdocs/__main__.py +5 -0
- hotdocs/_entry.py +46 -0
- hotdocs/_tool/AUTHORING.md +185 -0
- hotdocs/_tool/QUICKSTART.md +308 -0
- hotdocs/_tool/SPEC_GUIDELINES.md +815 -0
- hotdocs/_tool/agent-skills/README.md +10 -0
- hotdocs/_tool/agent-skills/hotdocs-asset-kind/SKILL.md +121 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/acceptance/AC-SLUG-001.md +14 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/acceptance/AC-SLUG-002.md +14 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/acceptance/AC-SLUG-003.md +10 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/acceptance/AC-SLUG-004.md +18 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/component.md +51 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/constraints.md +3 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/interface/library.md +10 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/requirements/R-SLUG-001.md +5 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/requirements/R-SLUG-002.md +7 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/requirements/R-SLUG-003.md +5 -0
- hotdocs/_tool/examples/slugify/specs/components/slugify/requirements/R-SLUG-004.md +6 -0
- hotdocs/_tool/examples/slugify/specs/product/slugs.md +22 -0
- hotdocs/_tool/gen/README.md +24 -0
- hotdocs/_tool/gen/agentic-generator/.provenance.json +379 -0
- hotdocs/_tool/gen/agentic-generator/agentic_generator.py +427 -0
- hotdocs/_tool/gen/cache-manager/.provenance.json +458 -0
- hotdocs/_tool/gen/cache-manager/cache_manager.py +254 -0
- hotdocs/_tool/gen/capability-scenario-verifier/.provenance.json +469 -0
- hotdocs/_tool/gen/capability-scenario-verifier/capability_scenario_verifier.py +534 -0
- hotdocs/_tool/gen/citation-checker/.provenance.json +370 -0
- hotdocs/_tool/gen/citation-checker/citation_checker.py +219 -0
- hotdocs/_tool/gen/component-gate-runner/.provenance.json +375 -0
- hotdocs/_tool/gen/component-gate-runner/component_gate_runner.py +556 -0
- hotdocs/_tool/gen/corpus-graph-builder/.provenance.json +381 -0
- hotdocs/_tool/gen/corpus-graph-builder/corpus_graph_builder/__init__.py +192 -0
- hotdocs/_tool/gen/corpus-graph-builder/corpus_graph_builder/cli.py +51 -0
- hotdocs/_tool/gen/corpus-loader/.provenance.json +331 -0
- hotdocs/_tool/gen/corpus-loader/corpus_loader.py +249 -0
- hotdocs/_tool/gen/decision-drift-detector/.provenance.json +382 -0
- hotdocs/_tool/gen/decision-drift-detector/decision_drift_detector.py +338 -0
- hotdocs/_tool/gen/docs-site-renderer/.provenance.json +381 -0
- hotdocs/_tool/gen/docs-site-renderer/docs_site_renderer/__init__.py +188 -0
- hotdocs/_tool/gen/docs-site-renderer/docs_site_renderer/cli.py +69 -0
- hotdocs/_tool/gen/docs-site-renderer/static/app.js +111 -0
- hotdocs/_tool/gen/generation-loop/.provenance.json +341 -0
- hotdocs/_tool/gen/generation-loop/generation_loop.py +287 -0
- hotdocs/_tool/gen/generator/.provenance.json +600 -0
- hotdocs/_tool/gen/generator/generator.py +469 -0
- hotdocs/_tool/gen/graph-query-engine/.provenance.json +385 -0
- hotdocs/_tool/gen/graph-query-engine/graph_query_engine.py +230 -0
- hotdocs/_tool/gen/hotdocs-cli/.provenance.json +371 -0
- hotdocs/_tool/gen/hotdocs-cli/hotdocs_cli.py +339 -0
- hotdocs/_tool/gen/hotdocs-init/.provenance.json +342 -0
- hotdocs/_tool/gen/hotdocs-init/hotdocs_init.py +463 -0
- hotdocs/_tool/gen/impact-analyzer/.provenance.json +418 -0
- hotdocs/_tool/gen/impact-analyzer/impact_analyzer.py +350 -0
- hotdocs/_tool/gen/kind-javascript/.provenance.json +482 -0
- hotdocs/_tool/gen/kind-javascript/kind_javascript.py +371 -0
- hotdocs/_tool/gen/kind-python/.provenance.json +433 -0
- hotdocs/_tool/gen/kind-python/kind_python.py +371 -0
- hotdocs/_tool/gen/license-scanner/.provenance.json +508 -0
- hotdocs/_tool/gen/license-scanner/license_scanner.py +388 -0
- hotdocs/_tool/gen/llm-endpoint/.provenance.json +494 -0
- hotdocs/_tool/gen/llm-endpoint/llm_endpoint.py +638 -0
- hotdocs/_tool/gen/llm-tool-endpoint/.provenance.json +409 -0
- hotdocs/_tool/gen/llm-tool-endpoint/llm_tool_endpoint.py +465 -0
- hotdocs/_tool/gen/provenance-checker/.provenance.json +495 -0
- hotdocs/_tool/gen/provenance-checker/provenance_checker.py +492 -0
- hotdocs/_tool/gen/provenance-tracker/.provenance.json +354 -0
- hotdocs/_tool/gen/provenance-tracker/provenance_tracker.py +423 -0
- hotdocs/_tool/gen/provenance-tracker-ui/.provenance.json +376 -0
- hotdocs/_tool/gen/provenance-tracker-ui/provenance_tracker_ui.py +309 -0
- hotdocs/_tool/gen/provenance-tracker-ui/static/app.js +23 -0
- hotdocs/_tool/gen/provenance-writer/.provenance.json +602 -0
- hotdocs/_tool/gen/provenance-writer/provenance_writer.py +315 -0
- hotdocs/_tool/gen/review-packet-builder/.provenance.json +378 -0
- hotdocs/_tool/gen/review-packet-builder/review_packet_builder.py +299 -0
- hotdocs/_tool/gen/secret-scanner/.provenance.json +558 -0
- hotdocs/_tool/gen/secret-scanner/secret_scanner.py +553 -0
- hotdocs/_tool/gen/size-checker/.provenance.json +393 -0
- hotdocs/_tool/gen/size-checker/size_checker.py +248 -0
- hotdocs/_tool/gen/spec-bundle-assembler/.provenance.json +573 -0
- hotdocs/_tool/gen/spec-bundle-assembler/spec_bundle_assembler.py +472 -0
- hotdocs/_tool/gen/spec-completeness-assistant/.provenance.json +357 -0
- hotdocs/_tool/gen/spec-completeness-assistant/spec_completeness_assistant.py +412 -0
- hotdocs/_tool/gen/spec-linter/.provenance.json +741 -0
- hotdocs/_tool/gen/spec-linter/spec_linter.py +894 -0
- hotdocs/_tool/gen/spec-reviewer/.provenance.json +342 -0
- hotdocs/_tool/gen/spec-reviewer/spec_reviewer.py +527 -0
- hotdocs/_tool/gen/spec-scaffolder/.provenance.json +397 -0
- hotdocs/_tool/gen/spec-scaffolder/spec_scaffolder.py +535 -0
- hotdocs/_tool/gen/surface-checker/.provenance.json +334 -0
- hotdocs/_tool/gen/surface-checker/surface_checker.py +322 -0
- hotdocs/_tool/gen/test-author/.provenance.json +506 -0
- hotdocs/_tool/gen/test-author/test_author.py +465 -0
- hotdocs/_tool/gen/test-probe/.provenance.json +379 -0
- hotdocs/_tool/gen/test-probe/test_probe.py +424 -0
- hotdocs/_tool/gen/verifier-orchestrator/.provenance.json +655 -0
- hotdocs/_tool/gen/verifier-orchestrator/verifier_orchestrator.py +878 -0
- hotdocs/_tool/pipeline/README.md +26 -0
- hotdocs/_tool/pipeline/criterion-compiler/.sealed-provenance.json +17 -0
- hotdocs/_tool/pipeline/criterion-compiler/criterion_compiler.py +529 -0
- hotdocs/_tool/pyproject.toml +38 -0
- hotdocs/_tool/requirements.txt +6 -0
- hotdocs/_tool/specs/architecture/asset-kind-javascript.md +106 -0
- hotdocs/_tool/specs/architecture/asset-kind-python.md +115 -0
- hotdocs/_tool/specs/architecture/asset-kinds.md +240 -0
- hotdocs/_tool/specs/architecture/cli-conventions.md +47 -0
- hotdocs/_tool/specs/architecture/step-phrase-grammar.md +84 -0
- hotdocs-0.1.0a1.dist-info/METADATA +140 -0
- hotdocs-0.1.0a1.dist-info/RECORD +113 -0
- hotdocs-0.1.0a1.dist-info/WHEEL +5 -0
- hotdocs-0.1.0a1.dist-info/entry_points.txt +2 -0
- hotdocs-0.1.0a1.dist-info/licenses/LICENSE +190 -0
- hotdocs-0.1.0a1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
"""Provenance checker: decides whether a committed provenance manifest proves
|
|
2
|
+
a component was already verified against the current spec state."""
|
|
3
|
+
|
|
4
|
+
import contextlib
|
|
5
|
+
import hashlib
|
|
6
|
+
import importlib.util
|
|
7
|
+
import itertools
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import re
|
|
11
|
+
import sys
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
USAGE = (
|
|
16
|
+
"usage: hotdocs provenance check <component-id> --spec-bundle-hash=<h> "
|
|
17
|
+
"--gate-versions=<json> [--repo-root=<dir>] [--format=json|text]"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
_FLAGS = ("--spec-bundle-hash", "--gate-versions", "--repo-root", "--format")
|
|
21
|
+
_COMPONENT_ID_RE = r"(comp-)?[a-z0-9]+(-[a-z0-9]+)*"
|
|
22
|
+
_HASH_RE = r"sha256:[0-9a-f]+"
|
|
23
|
+
_OWNER_RE = r"[a-z0-9]+(-[a-z0-9]+)*"
|
|
24
|
+
_SOURCE_PATH_RE = r"[A-Za-z0-9_][A-Za-z0-9_.-]*(/[A-Za-z0-9_][A-Za-z0-9_.-]*)*/?"
|
|
25
|
+
_SEALED_KEYS = {
|
|
26
|
+
"kind", "version", "component_id", "owners", "source_path",
|
|
27
|
+
"source_hash", "verifier_version", "characterization", "written_at",
|
|
28
|
+
}
|
|
29
|
+
_CHAR_KEYS = {"overall", "criteria_passed", "criteria_total"}
|
|
30
|
+
|
|
31
|
+
_adapter_counter = itertools.count()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class ProvenanceKey:
|
|
36
|
+
spec_bundle_hash: str
|
|
37
|
+
gate_versions: dict = field(default_factory=dict)
|
|
38
|
+
assets: list = field(default_factory=list)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass
|
|
42
|
+
class SealedKey:
|
|
43
|
+
owners: list
|
|
44
|
+
source_path: str
|
|
45
|
+
source_hash: str
|
|
46
|
+
verifier_version: str
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ProvenanceCheckResult(dict):
|
|
50
|
+
"""A dict that also exposes its keys as attributes."""
|
|
51
|
+
|
|
52
|
+
def __getattr__(self, name):
|
|
53
|
+
try:
|
|
54
|
+
return self[name]
|
|
55
|
+
except KeyError:
|
|
56
|
+
raise AttributeError(name) from None
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class _UsageError(Exception):
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# --------------------------------------------------------------------------
|
|
64
|
+
# helpers
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _get(obj, key, default=None):
|
|
68
|
+
if isinstance(obj, dict):
|
|
69
|
+
return obj.get(key, default)
|
|
70
|
+
return getattr(obj, key, default)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _slug(component_id):
|
|
74
|
+
return component_id.removeprefix("comp-")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _tool_root():
|
|
78
|
+
here = Path(__file__).resolve()
|
|
79
|
+
return next(p.parent for p in here.parents if p.name == "gen")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@contextlib.contextmanager
|
|
83
|
+
def _no_bytecode():
|
|
84
|
+
saved = sys.dont_write_bytecode
|
|
85
|
+
sys.dont_write_bytecode = True
|
|
86
|
+
try:
|
|
87
|
+
yield
|
|
88
|
+
finally:
|
|
89
|
+
sys.dont_write_bytecode = saved
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _exec_module(name, path, search=None):
|
|
93
|
+
spec = importlib.util.spec_from_file_location(
|
|
94
|
+
name, path, submodule_search_locations=search
|
|
95
|
+
)
|
|
96
|
+
module = importlib.util.module_from_spec(spec)
|
|
97
|
+
sys.modules[name] = module
|
|
98
|
+
with _no_bytecode():
|
|
99
|
+
spec.loader.exec_module(module)
|
|
100
|
+
return module
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _load_dep(rel_dir, module, repo_root):
|
|
104
|
+
directory = Path(repo_root) / rel_dir
|
|
105
|
+
if not directory.exists():
|
|
106
|
+
directory = _tool_root() / rel_dir
|
|
107
|
+
path = directory / f"{module}.py"
|
|
108
|
+
search = None
|
|
109
|
+
if not path.is_file():
|
|
110
|
+
path = directory / module / "__init__.py"
|
|
111
|
+
search = [str(path.parent)]
|
|
112
|
+
return _exec_module(module, path, search)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _file_sha(path):
|
|
116
|
+
return "sha256:" + hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _frontmatter(repo_root, slug):
|
|
120
|
+
path = Path(repo_root) / "specs" / "components" / slug / "component.md"
|
|
121
|
+
if not path.is_file():
|
|
122
|
+
return []
|
|
123
|
+
lines = []
|
|
124
|
+
for line in path.read_text(encoding="utf-8").splitlines()[1:]:
|
|
125
|
+
if line.strip() == "---":
|
|
126
|
+
break
|
|
127
|
+
lines.append(line)
|
|
128
|
+
return lines
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _is_sealed(lines):
|
|
132
|
+
return any(line.strip() == "sealed: true" for line in lines)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _declared_assets(lines):
|
|
136
|
+
for line in lines:
|
|
137
|
+
if line.startswith("assets:"):
|
|
138
|
+
inner = line[line.index("[") + 1:line.index("]")]
|
|
139
|
+
items = [item.strip() for item in inner.split(",")]
|
|
140
|
+
return [tuple(item.split(":", 1)) for item in items if item]
|
|
141
|
+
return []
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _adapter_path(kind, repo_root):
|
|
145
|
+
rel = Path("gen") / f"kind-{kind}" / f"kind_{kind.replace('-', '_')}.py"
|
|
146
|
+
for root in (Path(repo_root), _tool_root()):
|
|
147
|
+
if (root / rel).is_file():
|
|
148
|
+
return root / rel
|
|
149
|
+
return None
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _kind_info(kind, repo_root):
|
|
153
|
+
definition = Path(repo_root) / "specs" / "architecture" / f"asset-kind-{kind}.md"
|
|
154
|
+
info = {
|
|
155
|
+
"definition_sha256": _file_sha(definition) if definition.is_file() else None,
|
|
156
|
+
"adapter_sha256": None,
|
|
157
|
+
"provision": None,
|
|
158
|
+
}
|
|
159
|
+
adapter = _adapter_path(kind, repo_root)
|
|
160
|
+
if adapter is not None:
|
|
161
|
+
info["adapter_sha256"] = _file_sha(adapter)
|
|
162
|
+
name = f"_provenance_checker_kind_{kind.replace('-', '_')}_{next(_adapter_counter)}"
|
|
163
|
+
module = _exec_module(name, adapter)
|
|
164
|
+
info["provision"] = module.provision(Path(repo_root))
|
|
165
|
+
return info
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _current_assets(component_id, repo_root, stop):
|
|
169
|
+
"""Return (assets, miss_reason). With ``stop``, the first kind with no
|
|
170
|
+
adapter or a failed provision ends the computation with a reason."""
|
|
171
|
+
lines = _frontmatter(repo_root, _slug(component_id))
|
|
172
|
+
if _is_sealed(lines):
|
|
173
|
+
return [], None
|
|
174
|
+
infos = {}
|
|
175
|
+
assets = []
|
|
176
|
+
for kind, path in [("python", ".")] + _declared_assets(lines):
|
|
177
|
+
if kind not in infos:
|
|
178
|
+
infos[kind] = _kind_info(kind, repo_root)
|
|
179
|
+
info = infos[kind]
|
|
180
|
+
prov = info["provision"]
|
|
181
|
+
if stop:
|
|
182
|
+
if prov is None:
|
|
183
|
+
return None, f"unknown asset kind: {kind}"
|
|
184
|
+
if not _get(prov, "ok"):
|
|
185
|
+
return None, _get(prov, "reason")
|
|
186
|
+
assets.append({
|
|
187
|
+
"kind": kind,
|
|
188
|
+
"path": path,
|
|
189
|
+
"definition_sha256": info["definition_sha256"],
|
|
190
|
+
"adapter_sha256": info["adapter_sha256"],
|
|
191
|
+
"versions": {} if prov is None else _get(prov, "versions"),
|
|
192
|
+
"lockfile_sha256": None if prov is None else _get(prov, "lockfile_sha256"),
|
|
193
|
+
})
|
|
194
|
+
return assets, None
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _only_environment_differs(old, current):
|
|
198
|
+
return (
|
|
199
|
+
isinstance(old, list)
|
|
200
|
+
and len(old) == len(current)
|
|
201
|
+
and all(
|
|
202
|
+
isinstance(o, dict)
|
|
203
|
+
and set(o) == set(c)
|
|
204
|
+
and all(o[k] == c[k] for k in ("kind", "path", "definition_sha256", "adapter_sha256"))
|
|
205
|
+
for o, c in zip(old, current)
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _trust_judge():
|
|
211
|
+
return os.environ.get("VAR_TRUST_JUDGE_PROVENANCE", "").strip().lower() != "false"
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _matches(pattern, value):
|
|
215
|
+
return isinstance(value, str) and re.fullmatch(pattern, value) is not None
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _valid_owners(owners):
|
|
219
|
+
return (
|
|
220
|
+
isinstance(owners, list)
|
|
221
|
+
and len(owners) > 0
|
|
222
|
+
and all(_matches(_OWNER_RE, o) for o in owners)
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _valid_source_path(source_path):
|
|
227
|
+
return _matches(_SOURCE_PATH_RE, source_path) and source_path.split("/")[0] != "gen"
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _is_int(value):
|
|
231
|
+
return type(value) is int
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _valid_sealed_manifest(doc):
|
|
235
|
+
if not isinstance(doc, dict) or set(doc) != _SEALED_KEYS:
|
|
236
|
+
return False
|
|
237
|
+
char = doc["characterization"]
|
|
238
|
+
if not isinstance(char, dict) or set(char) != _CHAR_KEYS:
|
|
239
|
+
return False
|
|
240
|
+
passed = char["criteria_passed"]
|
|
241
|
+
total = char["criteria_total"]
|
|
242
|
+
if not (_is_int(passed) and _is_int(total) and 0 <= passed <= total):
|
|
243
|
+
return False
|
|
244
|
+
if char["overall"] == "pass":
|
|
245
|
+
counts_ok = total >= 1 and passed == total
|
|
246
|
+
else:
|
|
247
|
+
counts_ok = char["overall"] == "fail"
|
|
248
|
+
return (
|
|
249
|
+
counts_ok
|
|
250
|
+
and doc["kind"] == "sealed-provenance"
|
|
251
|
+
and _is_int(doc["version"])
|
|
252
|
+
and doc["version"] == 1
|
|
253
|
+
and _matches(r"comp-[a-z0-9]+(-[a-z0-9]+)*", doc["component_id"])
|
|
254
|
+
and _valid_owners(doc["owners"])
|
|
255
|
+
and _valid_source_path(doc["source_path"])
|
|
256
|
+
and _matches(r"sha256:[0-9a-f]{64}", doc["source_hash"])
|
|
257
|
+
and _matches(r"verifier-orchestrator@[0-9]+\.[0-9]+\.[0-9]+", doc["verifier_version"])
|
|
258
|
+
and _matches(r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z", doc["written_at"])
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _source_hash(base):
|
|
263
|
+
files = []
|
|
264
|
+
for dirpath, dirnames, filenames in os.walk(base):
|
|
265
|
+
dirnames[:] = [d for d in dirnames if d != "__pycache__"]
|
|
266
|
+
for name in filenames:
|
|
267
|
+
if name != ".sealed-provenance.json":
|
|
268
|
+
full = Path(dirpath) / name
|
|
269
|
+
files.append((full.relative_to(base).as_posix(), full))
|
|
270
|
+
digest = hashlib.sha256()
|
|
271
|
+
for rel, full in sorted(files, key=lambda item: item[0]):
|
|
272
|
+
digest.update(rel.encode("utf-8"))
|
|
273
|
+
digest.update(b"\0")
|
|
274
|
+
digest.update(full.read_bytes())
|
|
275
|
+
digest.update(b"\0")
|
|
276
|
+
return "sha256:" + digest.hexdigest()
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
# --------------------------------------------------------------------------
|
|
280
|
+
# library
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _miss(reason):
|
|
284
|
+
return ProvenanceCheckResult(
|
|
285
|
+
hit=False, reason=reason, verification_report=None,
|
|
286
|
+
license_scan=None, secret_scan=None,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def check_provenance(component_id, spec_bundle_hash, gate_versions, repo_root):
|
|
291
|
+
repo_root = Path(repo_root)
|
|
292
|
+
path = repo_root / "gen" / _slug(component_id) / ".provenance.json"
|
|
293
|
+
if not path.is_file():
|
|
294
|
+
return _miss("no manifest")
|
|
295
|
+
manifest = json.loads(path.read_text(encoding="utf-8"))
|
|
296
|
+
if manifest.get("spec_bundle_hash") != spec_bundle_hash:
|
|
297
|
+
return _miss("spec_bundle_hash differs")
|
|
298
|
+
if manifest.get("gate_versions") != dict(gate_versions):
|
|
299
|
+
return _miss("gate_versions differ")
|
|
300
|
+
current, reason = _current_assets(component_id, repo_root, stop=True)
|
|
301
|
+
if reason is not None:
|
|
302
|
+
return _miss(reason)
|
|
303
|
+
old = manifest.get("assets") or []
|
|
304
|
+
if old != current:
|
|
305
|
+
if _only_environment_differs(old, current):
|
|
306
|
+
return _miss("environment differs")
|
|
307
|
+
return _miss("assets differ")
|
|
308
|
+
report = manifest.get("verification_report")
|
|
309
|
+
criteria = _get(report, "criteria") or []
|
|
310
|
+
if not _trust_judge() and any(_get(c, "kind") == "llm-judge" for c in criteria):
|
|
311
|
+
return _miss("llm-judge results not trusted")
|
|
312
|
+
return ProvenanceCheckResult(
|
|
313
|
+
hit=True,
|
|
314
|
+
reason=None,
|
|
315
|
+
verification_report=report,
|
|
316
|
+
license_scan=manifest.get("license_scan"),
|
|
317
|
+
secret_scan=manifest.get("secret_scan"),
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def current_provenance_key(component_id, repo_root):
|
|
322
|
+
repo_root = Path(repo_root)
|
|
323
|
+
with _no_bytecode():
|
|
324
|
+
assembler = _load_dep("gen/spec-bundle-assembler", "spec_bundle_assembler", repo_root)
|
|
325
|
+
bundle = assembler.assemble(component_id, repo_root=repo_root, mode="cold")
|
|
326
|
+
spec_bundle_hash = _get(bundle, "spec_bundle_hash")
|
|
327
|
+
compiler = _load_dep("pipeline/criterion-compiler", "criterion_compiler", repo_root)
|
|
328
|
+
compiler_version = compiler.GATE_VERSION
|
|
329
|
+
author = _load_dep("gen/test-author", "test_author", repo_root)
|
|
330
|
+
author_version = author.GATE_VERSION
|
|
331
|
+
verifier = _load_dep("gen/verifier-orchestrator", "verifier_orchestrator", repo_root)
|
|
332
|
+
verifier_version = verifier.GATE_VERSION
|
|
333
|
+
license_mod = _load_dep("gen/license-scanner", "license_scanner", repo_root)
|
|
334
|
+
license_version = license_mod.gate_version(repo_root)
|
|
335
|
+
secret_mod = _load_dep("gen/secret-scanner", "secret_scanner", repo_root)
|
|
336
|
+
secret_version = secret_mod.gate_version(repo_root)
|
|
337
|
+
generator = _load_dep("gen/generator", "generator", repo_root)
|
|
338
|
+
generator_version = f"{generator.GATE_VERSION}+{generator.PROMPT_VERSION}"
|
|
339
|
+
assets, _ = _current_assets(component_id, repo_root, stop=False)
|
|
340
|
+
return ProvenanceKey(
|
|
341
|
+
spec_bundle_hash=spec_bundle_hash,
|
|
342
|
+
gate_versions={
|
|
343
|
+
"compiler": compiler_version,
|
|
344
|
+
"generated_test": author_version,
|
|
345
|
+
"verifier": verifier_version,
|
|
346
|
+
"license_scanner": license_version,
|
|
347
|
+
"secret_scanner": secret_version,
|
|
348
|
+
"generator": generator_version,
|
|
349
|
+
},
|
|
350
|
+
assets=assets,
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def current_sealed_key(component_id, repo_root):
|
|
355
|
+
repo_root = Path(repo_root)
|
|
356
|
+
lines = _frontmatter(repo_root, _slug(component_id))
|
|
357
|
+
if not _is_sealed(lines):
|
|
358
|
+
return None
|
|
359
|
+
owners = None
|
|
360
|
+
source_path = None
|
|
361
|
+
for line in lines:
|
|
362
|
+
if line.startswith("owners:"):
|
|
363
|
+
m = re.fullmatch(r"\[(.*)\]", line[len("owners:"):].strip())
|
|
364
|
+
if m is None:
|
|
365
|
+
raise ValueError("owners must be a one-line list: owners: [a, b]")
|
|
366
|
+
owners = [item.strip() for item in m.group(1).split(",")]
|
|
367
|
+
elif line.startswith("source_path:"):
|
|
368
|
+
source_path = line[len("source_path:"):].strip()
|
|
369
|
+
if not _valid_owners(owners):
|
|
370
|
+
raise ValueError(f"invalid or missing owners: {owners!r}")
|
|
371
|
+
if not _valid_source_path(source_path):
|
|
372
|
+
raise ValueError(f"invalid or missing source_path: {source_path!r}")
|
|
373
|
+
source_hash = _source_hash(repo_root / source_path)
|
|
374
|
+
with _no_bytecode():
|
|
375
|
+
verifier = _load_dep("gen/verifier-orchestrator", "verifier_orchestrator", repo_root)
|
|
376
|
+
verifier_version = verifier.GATE_VERSION
|
|
377
|
+
return SealedKey(
|
|
378
|
+
owners=owners,
|
|
379
|
+
source_path=source_path,
|
|
380
|
+
source_hash=source_hash,
|
|
381
|
+
verifier_version=verifier_version,
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def _sealed_result(reason, sealed=True, manifest=None):
|
|
386
|
+
hit = reason is None
|
|
387
|
+
return {
|
|
388
|
+
"hit": hit,
|
|
389
|
+
"sealed": sealed,
|
|
390
|
+
"reason": reason,
|
|
391
|
+
"verification_report": {"overall": manifest["characterization"]["overall"]} if hit else None,
|
|
392
|
+
"license_scan": None,
|
|
393
|
+
"secret_scan": None,
|
|
394
|
+
"owners": manifest["owners"] if hit else None,
|
|
395
|
+
"source_hash": manifest["source_hash"] if hit else None,
|
|
396
|
+
"written_at": manifest["written_at"] if hit else None,
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def check_sealed_provenance(component_id, repo_root):
|
|
401
|
+
repo_root = Path(repo_root)
|
|
402
|
+
key = current_sealed_key(component_id, repo_root)
|
|
403
|
+
if key is None:
|
|
404
|
+
return _sealed_result("not_sealed", sealed=False)
|
|
405
|
+
path = repo_root / key.source_path / ".sealed-provenance.json"
|
|
406
|
+
if not path.exists():
|
|
407
|
+
return _sealed_result("manifest_missing")
|
|
408
|
+
try:
|
|
409
|
+
doc = json.loads(path.read_text(encoding="utf-8"))
|
|
410
|
+
except (OSError, ValueError):
|
|
411
|
+
return _sealed_result("manifest_invalid")
|
|
412
|
+
if not _valid_sealed_manifest(doc):
|
|
413
|
+
return _sealed_result("manifest_invalid")
|
|
414
|
+
if doc["component_id"] != "comp-" + _slug(component_id) or doc["source_path"] != key.source_path:
|
|
415
|
+
return _sealed_result("component_mismatch")
|
|
416
|
+
if doc["source_hash"] != key.source_hash:
|
|
417
|
+
return _sealed_result("source_changed")
|
|
418
|
+
if doc["owners"] != key.owners:
|
|
419
|
+
return _sealed_result("owners_changed")
|
|
420
|
+
if doc["verifier_version"] != key.verifier_version:
|
|
421
|
+
return _sealed_result("verifier_changed")
|
|
422
|
+
if doc["characterization"]["overall"] != "pass":
|
|
423
|
+
return _sealed_result("characterization_failed")
|
|
424
|
+
return _sealed_result(None, manifest=doc)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
# --------------------------------------------------------------------------
|
|
428
|
+
# CLI
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def _parse(argv):
|
|
432
|
+
if not argv or argv[0] != "check":
|
|
433
|
+
raise _UsageError("expected subcommand 'check'")
|
|
434
|
+
values = {}
|
|
435
|
+
component_id = None
|
|
436
|
+
i = 1
|
|
437
|
+
while i < len(argv):
|
|
438
|
+
token = argv[i]
|
|
439
|
+
name, eq, value = token.partition("=")
|
|
440
|
+
if name in _FLAGS:
|
|
441
|
+
if not eq:
|
|
442
|
+
if i + 1 >= len(argv):
|
|
443
|
+
raise _UsageError(f"{name} requires a value")
|
|
444
|
+
i += 1
|
|
445
|
+
value = argv[i]
|
|
446
|
+
values[name] = value
|
|
447
|
+
elif token.startswith("--") or component_id is not None:
|
|
448
|
+
raise _UsageError(f"unknown argument: {token}")
|
|
449
|
+
else:
|
|
450
|
+
component_id = token
|
|
451
|
+
i += 1
|
|
452
|
+
if component_id is None:
|
|
453
|
+
raise _UsageError("missing <component-id>")
|
|
454
|
+
if not re.fullmatch(_COMPONENT_ID_RE, component_id):
|
|
455
|
+
raise _UsageError(f"invalid component id: {component_id}")
|
|
456
|
+
if "--spec-bundle-hash" not in values:
|
|
457
|
+
raise _UsageError("missing --spec-bundle-hash")
|
|
458
|
+
spec_bundle_hash = values["--spec-bundle-hash"]
|
|
459
|
+
if not re.fullmatch(_HASH_RE, spec_bundle_hash):
|
|
460
|
+
raise _UsageError(f"invalid --spec-bundle-hash: {spec_bundle_hash}")
|
|
461
|
+
if "--gate-versions" not in values:
|
|
462
|
+
raise _UsageError("missing --gate-versions")
|
|
463
|
+
try:
|
|
464
|
+
gate_versions = json.loads(values["--gate-versions"])
|
|
465
|
+
except ValueError:
|
|
466
|
+
raise _UsageError("--gate-versions is not valid JSON") from None
|
|
467
|
+
if not isinstance(gate_versions, dict) or not all(
|
|
468
|
+
isinstance(v, str) for v in gate_versions.values()
|
|
469
|
+
):
|
|
470
|
+
raise _UsageError("--gate-versions must be a JSON object of strings")
|
|
471
|
+
fmt = values.get("--format", "text")
|
|
472
|
+
if fmt not in ("json", "text"):
|
|
473
|
+
raise _UsageError(f"invalid --format: {fmt}")
|
|
474
|
+
repo_root = Path(values.get("--repo-root", os.getcwd()))
|
|
475
|
+
return component_id, spec_bundle_hash, gate_versions, repo_root, fmt
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def main(argv=None):
|
|
479
|
+
if argv is None:
|
|
480
|
+
argv = sys.argv[1:]
|
|
481
|
+
try:
|
|
482
|
+
component_id, spec_bundle_hash, gate_versions, repo_root, fmt = _parse(list(argv))
|
|
483
|
+
except _UsageError as exc:
|
|
484
|
+
print(f"usage error: {exc}", file=sys.stderr)
|
|
485
|
+
print(USAGE, file=sys.stderr)
|
|
486
|
+
return 2
|
|
487
|
+
result = check_provenance(component_id, spec_bundle_hash, gate_versions, repo_root)
|
|
488
|
+
if fmt == "json":
|
|
489
|
+
print(json.dumps(dict(result), sort_keys=True))
|
|
490
|
+
else:
|
|
491
|
+
print(f"{'hit' if result['hit'] else 'miss'} {component_id}")
|
|
492
|
+
return 0
|