@babylonjs-toolkit/agent 1.2.16 → 1.2.21
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.
- package/README.md +3 -2
- package/package.json +1 -1
- package/skills/bt-blender/SKILL.md +448 -0
- package/skills/bt-blender/THIRD_PARTY_NOTICES.md +141 -0
- package/skills/bt-blender/references/art-style-and-genre.md +173 -0
- package/skills/bt-blender/references/characters-and-creatures.md +644 -0
- package/skills/bt-blender/references/environments.md +478 -0
- package/skills/bt-blender/references/game-engine-export.md +284 -0
- package/skills/bt-blender/references/geometry-nodes.md +447 -0
- package/skills/bt-blender/references/hard-surface.md +724 -0
- package/skills/bt-blender/references/procedural-generation.md +358 -0
- package/skills/bt-blender/references/rigging-and-animation.md +1080 -0
- package/skills/bt-blender/references/sculpting-and-retopology.md +544 -0
- package/skills/bt-blender/references/uv-and-pbr-materials.md +381 -0
- package/skills/bt-blender/references/vehicles.md +637 -0
- package/skills/bt-blender/scripts/blender/__pycache__/construction_kit.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/geometry_nodes_builders.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/image_measure.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/reference_traces.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/assembly_check.py +420 -0
- package/skills/bt-blender/scripts/blender/blueprint.py +293 -0
- package/skills/bt-blender/scripts/blender/character_blockout.py +462 -0
- package/skills/bt-blender/scripts/blender/construction_kit.py +1770 -0
- package/skills/bt-blender/scripts/blender/coverage_check.py +221 -0
- package/skills/bt-blender/scripts/blender/environment_kit.py +525 -0
- package/skills/bt-blender/scripts/blender/evidence_sheet.py +243 -0
- package/skills/bt-blender/scripts/blender/export_asset.py +623 -0
- package/skills/bt-blender/scripts/blender/geometry_nodes_builders.py +575 -0
- package/skills/bt-blender/scripts/blender/hard_surface_panels.py +374 -0
- package/skills/bt-blender/scripts/blender/hard_surface_trims.py +200 -0
- package/skills/bt-blender/scripts/blender/image_measure.py +917 -0
- package/skills/bt-blender/scripts/blender/materials_pbr.py +439 -0
- package/skills/bt-blender/scripts/blender/measure_stations.py +496 -0
- package/skills/bt-blender/scripts/blender/ortho_views.py +309 -0
- package/skills/bt-blender/scripts/blender/overlay_sheet.py +238 -0
- package/skills/bt-blender/scripts/blender/procedural_game_ready.py +258 -0
- package/skills/bt-blender/scripts/blender/procedural_generators.py +842 -0
- package/skills/bt-blender/scripts/blender/qa_check.py +729 -0
- package/skills/bt-blender/scripts/blender/reference_traces.py +344 -0
- package/skills/bt-blender/scripts/blender/retopology_tools.py +781 -0
- package/skills/bt-blender/scripts/blender/review_render.py +358 -0
- package/skills/bt-blender/scripts/blender/rigging_tools.py +1170 -0
- package/skills/bt-blender/scripts/blender/style_palette.py +190 -0
- package/skills/bt-blender/scripts/blender/tool_common.py +289 -0
- package/skills/bt-blender/scripts/blender/trace.py +283 -0
- package/skills/bt-blender/scripts/blender/uv_layout.py +555 -0
- package/skills/bt-blender/scripts/blender/vehicle_parts.py +370 -0
- package/skills/bt-blender/scripts/blender/view_consistency.py +133 -0
- package/skills/bt-blender/scripts/blender/world_gate.py +231 -0
- package/skills/bt-blender/scripts/bt-blender.mjs +333 -0
- package/skills/bt-blender/scripts/validate_gltf.mjs +204 -0
- package/skills/bt-execute/SKILL.md +2 -1
- package/skills/bt-gauntlet/SKILL.md +30 -20
- package/skills/bt-gauntlet/references/critic-rubrics.md +106 -7
- package/skills/bt-gauntlet/references/loop-templates.md +23 -3
- package/skills/bt-gauntlet/references/spec-composition.md +20 -1
- package/skills/bt-gauntlet/references/target-images.md +27 -0
- package/skills/bt-gauntlet/references/unity-pipeline.md +41 -4
- package/skills/bt-gauntlet/references/workspace.md +90 -6
- package/skills/bt-unwrap/scripts/blender/__pycache__/bt_unwrap.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/image_utils.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/mesh_tools.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/model_io.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/previews.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/rasterizer.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/reference_views.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/reference_warp.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/texture_bake.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/texture_compose.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/uv_layout.cpython-313.pyc +0 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Traced reference outlines and design curves for bt-blender build scripts, and the stamp that proves a part
|
|
3
|
+
was built on them.
|
|
4
|
+
|
|
5
|
+
The `trace` tool writes traces.json: per reference view the subject's outline in image pixels and in world
|
|
6
|
+
metres on the view's plane, plus named design curves as world points. A build script reads it with
|
|
7
|
+
`construction_kit.load_traces(path)` (a TraceSet, which records every curve and view the build reads), lays its
|
|
8
|
+
blockout, sections, cage lines and loft rails on those curves, and stamps every part it built with
|
|
9
|
+
`construction_kit.stamp_traces(objects, path, curves_used=traces.accessed_curves)`. The stamp holds the traces
|
|
10
|
+
file's SHA-256 and the curves and views the build read (its provenance). A spec with "require_traces" makes
|
|
11
|
+
`world-gate` and `measure-stations` run the trace gate: the stamp must be current, and the geometry must follow
|
|
12
|
+
the traces (the `trace_adherence` module), so "built on the traced curves" is measured, not attested.
|
|
13
|
+
|
|
14
|
+
Pure Python and numpy: no bpy import (objects are only read and written through their custom properties).
|
|
15
|
+
"""
|
|
16
|
+
import hashlib
|
|
17
|
+
import json
|
|
18
|
+
import os
|
|
19
|
+
from collections.abc import Mapping
|
|
20
|
+
|
|
21
|
+
import numpy as np
|
|
22
|
+
|
|
23
|
+
import image_measure
|
|
24
|
+
|
|
25
|
+
# Custom property holding the SHA-256 of the traces file a part was built on.
|
|
26
|
+
TRACES_PROPERTY = "bt_traces"
|
|
27
|
+
|
|
28
|
+
# Custom property holding the stamp's provenance: JSON {"curves": [...], "views": [...]} the build read.
|
|
29
|
+
PROVENANCE_PROPERTY = "bt_traces_provenance"
|
|
30
|
+
|
|
31
|
+
# Spec key naming the traces file (relative to the spec) every measured part must be stamped with.
|
|
32
|
+
REQUIRE_TRACES_KEY = "require_traces"
|
|
33
|
+
|
|
34
|
+
# Spec key listing, per object, the named design curves its surface must follow: {"Shell": ["side_top"]}.
|
|
35
|
+
TRACE_ADHERENCE_KEY = "trace_adherence"
|
|
36
|
+
|
|
37
|
+
# Side names accepted by the boundary lookups: the largest or smallest crossing.
|
|
38
|
+
SIDE_ALIASES = {"max": "max", "upper": "max", "min": "min", "lower": "min"}
|
|
39
|
+
|
|
40
|
+
AXIS_ORDER = ("x", "y", "z")
|
|
41
|
+
|
|
42
|
+
# Bytes read per step while hashing a file.
|
|
43
|
+
HASH_CHUNK_BYTES = 1 << 20
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def file_sha256(path: str) -> str:
|
|
47
|
+
"""
|
|
48
|
+
The SHA-256 of a file's bytes.
|
|
49
|
+
|
|
50
|
+
:param path: File path.
|
|
51
|
+
:returns: Lower-case hex digest.
|
|
52
|
+
:raises FileNotFoundError: when the file does not exist.
|
|
53
|
+
"""
|
|
54
|
+
digest = hashlib.sha256()
|
|
55
|
+
with open(path, "rb") as handle:
|
|
56
|
+
for chunk in iter(lambda: handle.read(HASH_CHUNK_BYTES), b""):
|
|
57
|
+
digest.update(chunk)
|
|
58
|
+
return digest.hexdigest()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class AccessRecordingCurves(Mapping):
|
|
62
|
+
"""
|
|
63
|
+
The named design curves of a TraceSet as a read-only mapping that records every curve read through it, so
|
|
64
|
+
`TraceSet.accessed_curves` lists what a build really used however it reached the curves.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(self, curves: dict, accessed: list):
|
|
68
|
+
"""
|
|
69
|
+
:param curves: {name: (N, 3) world points}.
|
|
70
|
+
:param accessed: The list the names read are appended to (shared with the TraceSet).
|
|
71
|
+
"""
|
|
72
|
+
self._curves = curves
|
|
73
|
+
self._accessed = accessed
|
|
74
|
+
|
|
75
|
+
def __getitem__(self, name: str) -> np.ndarray:
|
|
76
|
+
"""One curve's world points (a copy); records the read."""
|
|
77
|
+
if name not in self._curves:
|
|
78
|
+
raise KeyError(f"no traced curve '{name}'; curves: {sorted(self._curves)}")
|
|
79
|
+
if name not in self._accessed:
|
|
80
|
+
self._accessed.append(name)
|
|
81
|
+
return self._curves[name].copy()
|
|
82
|
+
|
|
83
|
+
def __iter__(self):
|
|
84
|
+
"""Curve names, in file order; iterating alone reads no curve."""
|
|
85
|
+
return iter(self._curves)
|
|
86
|
+
|
|
87
|
+
def __len__(self) -> int:
|
|
88
|
+
"""Number of curves."""
|
|
89
|
+
return len(self._curves)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class TraceSet:
|
|
93
|
+
"""
|
|
94
|
+
A loaded traces.json: per-view outlines on the view plane and named world curves.
|
|
95
|
+
|
|
96
|
+
Plane coordinates are in the order of the view's `plane_axes` (image right axis first, then image up),
|
|
97
|
+
e.g. ("y", "z") for a side view. World points are (x, y, z) in metres. Every curve and view the build
|
|
98
|
+
reads is recorded (`accessed_curves`, `accessed_views`) for the stamp's provenance.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
def __init__(self, data: dict, path: str = None, sha256: str = None):
|
|
102
|
+
"""
|
|
103
|
+
:param data: The parsed traces.json.
|
|
104
|
+
:param path: The file it came from, if any.
|
|
105
|
+
:param sha256: That file's SHA-256, if any.
|
|
106
|
+
"""
|
|
107
|
+
self.data = data
|
|
108
|
+
self.path = path
|
|
109
|
+
self.sha256 = sha256
|
|
110
|
+
self.views = data.get("views") or {}
|
|
111
|
+
self._accessed_curves = []
|
|
112
|
+
self._accessed_views = []
|
|
113
|
+
self.curves = AccessRecordingCurves(
|
|
114
|
+
{name: np.array(curve["points_world"], dtype=np.float64).reshape(-1, 3)
|
|
115
|
+
for name, curve in (data.get("curves") or {}).items()}, self._accessed_curves)
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def accessed_curves(self) -> list:
|
|
119
|
+
"""Names of the design curves read so far, in first-read order: pass to `stamp_traces(curves_used=...)`."""
|
|
120
|
+
return list(self._accessed_curves)
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def accessed_views(self) -> list:
|
|
124
|
+
"""Names of the traced views whose outlines were read so far, in first-read order."""
|
|
125
|
+
return list(self._accessed_views)
|
|
126
|
+
|
|
127
|
+
def _view(self, view: str) -> dict:
|
|
128
|
+
"""The record of one traced view, by its spec name; records the read."""
|
|
129
|
+
if view not in self.views:
|
|
130
|
+
raise KeyError(f"no traced view '{view}'; traced views: {sorted(self.views)}")
|
|
131
|
+
if view not in self._accessed_views:
|
|
132
|
+
self._accessed_views.append(view)
|
|
133
|
+
return self.views[view]
|
|
134
|
+
|
|
135
|
+
def curve(self, name: str) -> np.ndarray:
|
|
136
|
+
"""
|
|
137
|
+
A named design curve.
|
|
138
|
+
|
|
139
|
+
:param name: Curve name from curves.json.
|
|
140
|
+
:returns: (N, 3) world points in metres.
|
|
141
|
+
:raises KeyError: for an unknown curve.
|
|
142
|
+
"""
|
|
143
|
+
return self.curves[name]
|
|
144
|
+
|
|
145
|
+
def plane_axes(self, view: str) -> tuple:
|
|
146
|
+
"""The view's two plane axes, image right first: e.g. ("y", "z")."""
|
|
147
|
+
return tuple(self._view(view)["plane_axes"])
|
|
148
|
+
|
|
149
|
+
def depth_axis(self, view: str) -> str:
|
|
150
|
+
"""The world axis the view looks along (the one it cannot measure)."""
|
|
151
|
+
return self._view(view)["depth_axis"]
|
|
152
|
+
|
|
153
|
+
def outline(self, view: str) -> np.ndarray:
|
|
154
|
+
"""
|
|
155
|
+
The subject's traced outer outline on the view plane.
|
|
156
|
+
|
|
157
|
+
:param view: Spec view name.
|
|
158
|
+
:returns: (N, 2) plane coordinates in metres, a closed loop (last point joins the first).
|
|
159
|
+
"""
|
|
160
|
+
return np.array(self._view(view)["outline_world"], dtype=np.float64).reshape(-1, 2)
|
|
161
|
+
|
|
162
|
+
def outline_points(self, view: str, depth: float = 0.0) -> np.ndarray:
|
|
163
|
+
"""
|
|
164
|
+
The traced outline as world points, lying in the plane depth_axis = depth.
|
|
165
|
+
|
|
166
|
+
:param view: Spec view name.
|
|
167
|
+
:param depth: Coordinate along the view's depth axis, metres.
|
|
168
|
+
:returns: (N, 3) world points.
|
|
169
|
+
"""
|
|
170
|
+
plane = self.outline(view)
|
|
171
|
+
points = np.full((len(plane), 3), float(depth))
|
|
172
|
+
for column, axis in enumerate(self.plane_axes(view)):
|
|
173
|
+
points[:, AXIS_ORDER.index(axis)] = plane[:, column]
|
|
174
|
+
return points
|
|
175
|
+
|
|
176
|
+
def extent(self, view: str) -> dict:
|
|
177
|
+
"""The outline's world interval on each plane axis: {axis: [minimum, maximum]} in metres."""
|
|
178
|
+
return dict(self._view(view)["extent_m"])
|
|
179
|
+
|
|
180
|
+
def outline_extent(self, view: str, axis: str, value: float):
|
|
181
|
+
"""
|
|
182
|
+
The outline's extent across one station line.
|
|
183
|
+
|
|
184
|
+
:param view: Spec view name.
|
|
185
|
+
:param axis: The station axis, one of the view's plane axes (e.g. "y" in a side view).
|
|
186
|
+
:param value: The station's world coordinate on that axis, metres.
|
|
187
|
+
:returns: (minimum, maximum) of the other plane axis where the outline crosses the station, or None
|
|
188
|
+
when the station misses the outline.
|
|
189
|
+
:raises ValueError: when the axis is not on the view's plane.
|
|
190
|
+
"""
|
|
191
|
+
axes = self.plane_axes(view)
|
|
192
|
+
if axis not in axes:
|
|
193
|
+
raise ValueError(f"view '{view}' shows {axes}, not '{axis}'")
|
|
194
|
+
return image_measure.polyline_boundary(self.outline(view), axes.index(axis), float(value))
|
|
195
|
+
|
|
196
|
+
def outline_boundary(self, view: str, axis: str, value: float, side: str = "max"):
|
|
197
|
+
"""
|
|
198
|
+
One side of the outline at a station: e.g. the top line of a side view at a length station
|
|
199
|
+
(`outline_boundary("left", "y", 0.4, "max")` gives z), or the half-width of a top view
|
|
200
|
+
(`outline_boundary("top", "y", 0.4, "max")` gives x).
|
|
201
|
+
|
|
202
|
+
:param view: Spec view name.
|
|
203
|
+
:param axis: The station axis, one of the view's plane axes.
|
|
204
|
+
:param value: The station's world coordinate, metres.
|
|
205
|
+
:param side: "max" / "upper" or "min" / "lower" along the other plane axis.
|
|
206
|
+
:returns: The boundary coordinate in metres, or None when the station misses the outline.
|
|
207
|
+
"""
|
|
208
|
+
if side not in SIDE_ALIASES:
|
|
209
|
+
raise ValueError(f"side must be one of {sorted(SIDE_ALIASES)}")
|
|
210
|
+
crossing = self.outline_extent(view, axis, value)
|
|
211
|
+
if crossing is None:
|
|
212
|
+
return None
|
|
213
|
+
return crossing[1] if SIDE_ALIASES[side] == "max" else crossing[0]
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def load_traces(path: str) -> TraceSet:
|
|
217
|
+
"""
|
|
218
|
+
Reads a traces.json written by the `trace` tool.
|
|
219
|
+
|
|
220
|
+
:param path: The file.
|
|
221
|
+
:returns: The TraceSet, carrying the file's SHA-256.
|
|
222
|
+
:raises FileNotFoundError: when the file does not exist.
|
|
223
|
+
"""
|
|
224
|
+
absolute = os.path.abspath(path)
|
|
225
|
+
if not os.path.isfile(absolute):
|
|
226
|
+
raise FileNotFoundError(f"traces not found: {absolute} (run the trace tool first)")
|
|
227
|
+
with open(absolute, "r", encoding="utf-8") as handle:
|
|
228
|
+
data = json.load(handle)
|
|
229
|
+
return TraceSet(data, absolute, file_sha256(absolute))
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _views_of_curves(traces: TraceSet, curve_names: list) -> list:
|
|
233
|
+
"""The traced views a set of curves was picked in or paired with, in first-use order."""
|
|
234
|
+
views = []
|
|
235
|
+
for name in curve_names:
|
|
236
|
+
record = traces.data["curves"][name]
|
|
237
|
+
for view in (record.get("view"), record.get("pair_view")):
|
|
238
|
+
if view and view not in views:
|
|
239
|
+
views.append(view)
|
|
240
|
+
return views
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _checked_names(names, known, kind: str) -> list:
|
|
244
|
+
"""The given names without repeats, in order, after checking each one exists."""
|
|
245
|
+
unique = list(dict.fromkeys(names or []))
|
|
246
|
+
unknown = [name for name in unique if name not in known]
|
|
247
|
+
if unknown:
|
|
248
|
+
raise KeyError(f"unknown traced {kind}(s) {unknown}; the traces file has {sorted(known)}")
|
|
249
|
+
return unique
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def stamp_objects(objects, path: str, curves_used=None, views_used=None) -> str:
|
|
253
|
+
"""
|
|
254
|
+
Records on every object that it was built on this traces file, and from which curves and views.
|
|
255
|
+
|
|
256
|
+
:param objects: Blender objects (anything with item assignment for custom properties).
|
|
257
|
+
:param path: The traces file.
|
|
258
|
+
:param curves_used: Names of the design curves the build read (e.g. `TraceSet.accessed_curves`). Without
|
|
259
|
+
them the stamp is an attestation only, which the gate fails when the spec lists `trace_adherence`.
|
|
260
|
+
:param views_used: Names of the traced views whose outlines the build read (e.g. `TraceSet.accessed_views`);
|
|
261
|
+
default: the views the used curves were picked in or paired with.
|
|
262
|
+
:returns: The SHA-256 written to each object's `bt_traces` property.
|
|
263
|
+
:raises KeyError: for a curve or view name the traces file does not have.
|
|
264
|
+
"""
|
|
265
|
+
traces = load_traces(path)
|
|
266
|
+
curves = _checked_names(curves_used, traces.curves, "curve")
|
|
267
|
+
views = _checked_names(views_used, traces.views, "view") if views_used else _views_of_curves(traces, curves)
|
|
268
|
+
provenance = json.dumps({"curves": curves, "views": views})
|
|
269
|
+
for obj in objects:
|
|
270
|
+
obj[TRACES_PROPERTY] = traces.sha256
|
|
271
|
+
obj[PROVENANCE_PROPERTY] = provenance
|
|
272
|
+
return traces.sha256
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def stamp_provenance(obj) -> dict:
|
|
276
|
+
"""
|
|
277
|
+
The curves and views an object's stamp says its build read.
|
|
278
|
+
|
|
279
|
+
:param obj: A Blender object.
|
|
280
|
+
:returns: {"curves": [...], "views": [...]}; both empty for a stamp without provenance.
|
|
281
|
+
"""
|
|
282
|
+
try:
|
|
283
|
+
recorded = json.loads(obj.get(PROVENANCE_PROPERTY) or "{}")
|
|
284
|
+
except (TypeError, ValueError):
|
|
285
|
+
recorded = {}
|
|
286
|
+
return {"curves": list(recorded.get("curves") or []), "views": list(recorded.get("views") or [])}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def check_stamps(objects, traces_path: str, required_curves: dict = None, require_provenance: bool = False) -> dict:
|
|
290
|
+
"""
|
|
291
|
+
Checks the stamps of the measured objects: every one carries the current traces file's SHA-256, and (when
|
|
292
|
+
asked) records the curves its build read, including every curve the spec says it must follow.
|
|
293
|
+
|
|
294
|
+
:param objects: The measured Blender objects.
|
|
295
|
+
:param traces_path: The required traces file.
|
|
296
|
+
:param required_curves: {object name: [curve names]} from the spec's `trace_adherence`.
|
|
297
|
+
:param require_provenance: Fail objects stamped without recorded curves ("attestation only").
|
|
298
|
+
:returns: {"pass", "traces", "sha256", "unstamped", "stale", "attestation_only", "missing_objects",
|
|
299
|
+
"unknown_curves", "unrecorded_curves", "provenance", "message"}.
|
|
300
|
+
"""
|
|
301
|
+
absolute = os.path.abspath(traces_path)
|
|
302
|
+
required_curves = required_curves or {}
|
|
303
|
+
if not os.path.isfile(absolute):
|
|
304
|
+
return {"pass": False, "traces": absolute, "sha256": None, "unstamped": [obj.name for obj in objects],
|
|
305
|
+
"stale": [], "attestation_only": [], "missing_objects": [], "unknown_curves": {},
|
|
306
|
+
"unrecorded_curves": {}, "provenance": {},
|
|
307
|
+
"message": f"required traces file not found: {absolute}. Run the trace tool, build on its curves, "
|
|
308
|
+
"and stamp the parts from the build with construction_kit.stamp_traces."}
|
|
309
|
+
traces = load_traces(absolute)
|
|
310
|
+
names = [obj.name for obj in objects]
|
|
311
|
+
unstamped = [obj.name for obj in objects if not obj.get(TRACES_PROPERTY)]
|
|
312
|
+
stale = [obj.name for obj in objects if obj.get(TRACES_PROPERTY) and obj.get(TRACES_PROPERTY) != traces.sha256]
|
|
313
|
+
provenance = {obj.name: stamp_provenance(obj) for obj in objects if obj.get(TRACES_PROPERTY) == traces.sha256}
|
|
314
|
+
attestation_only = [name for name, record in provenance.items() if not record["curves"]]
|
|
315
|
+
missing_objects = [name for name in required_curves if name not in names]
|
|
316
|
+
unknown_curves = {name: [curve for curve in curves if curve not in traces.curves]
|
|
317
|
+
for name, curves in required_curves.items()}
|
|
318
|
+
unknown_curves = {name: curves for name, curves in unknown_curves.items() if curves}
|
|
319
|
+
unrecorded_curves = {name: [curve for curve in curves if curve not in provenance[name]["curves"]]
|
|
320
|
+
for name, curves in required_curves.items() if name in provenance}
|
|
321
|
+
unrecorded_curves = {name: curves for name, curves in unrecorded_curves.items() if curves}
|
|
322
|
+
problems = []
|
|
323
|
+
if unstamped:
|
|
324
|
+
problems.append(f"not built on the traces (no '{TRACES_PROPERTY}' stamp): {', '.join(unstamped)}")
|
|
325
|
+
if stale:
|
|
326
|
+
problems.append(f"stamped with an older traces file: {', '.join(stale)}")
|
|
327
|
+
if attestation_only and require_provenance:
|
|
328
|
+
problems.append(f"stamped without the curves the build read (attestation only): {', '.join(attestation_only)}")
|
|
329
|
+
if missing_objects:
|
|
330
|
+
problems.append(f"trace_adherence names objects that are not measured: {', '.join(missing_objects)}")
|
|
331
|
+
if unknown_curves:
|
|
332
|
+
problems.append(f"trace_adherence names curves the traces file lacks: {unknown_curves}")
|
|
333
|
+
if unrecorded_curves:
|
|
334
|
+
problems.append(f"the stamp does not record curves the part must follow: {unrecorded_curves}")
|
|
335
|
+
passed = not problems
|
|
336
|
+
message = ("every measured part is stamped with the current traces" if passed else
|
|
337
|
+
"trace gate failed: " + "; ".join(problems) + f". Build these parts on the curves in {absolute} "
|
|
338
|
+
"(construction_kit.load_traces) and stamp them from that build with the curves it read "
|
|
339
|
+
"(construction_kit.stamp_traces(parts, path, curves_used=traces.accessed_curves)); re-stamp after "
|
|
340
|
+
"re-tracing. Never answer a refusal by stamping: fix the build.")
|
|
341
|
+
return {"pass": passed, "traces": absolute, "sha256": traces.sha256, "unstamped": unstamped, "stale": stale,
|
|
342
|
+
"attestation_only": attestation_only, "missing_objects": missing_objects,
|
|
343
|
+
"unknown_curves": unknown_curves, "unrecorded_curves": unrecorded_curves, "provenance": provenance,
|
|
344
|
+
"message": message}
|