motionloom 2.2.0 → 2.4.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.
- package/CHANGELOG.md +48 -1
- package/README.md +123 -17
- package/ROADMAP.md +8 -3
- package/SKILL.md +34 -3
- package/agent-card.json +48 -5
- package/agent-surfaces.json +8 -1
- package/artifact-adapter-registry.json +53 -0
- package/bin/motionloom.mjs +41 -4
- package/docs/AGENT-INTEGRATION.md +15 -2
- package/docs/CHECKLIST.md +21 -0
- package/docs/STATUS.md +2 -2
- package/docs/audits/data/deep-stress-latest.json +65 -65
- package/docs/releases/2.3.0.md +33 -0
- package/docs/releases/2.4.0.md +31 -0
- package/docs/releases/npm-publish-from-workstation.md +19 -8
- package/docs/research/agent-skill-ecosystem-notes.md +47 -0
- package/docs/research/ai-animation-tools-2026-notes.md +81 -0
- package/docs/research/ai-animation-tools-2026-report.md +168 -0
- package/docs/research/ai-pilot-ingest-notes.md +29 -0
- package/examples/agent-consumer/ai-generated-pilot/hero-male.json +10 -0
- package/examples/agent-consumer/ai-generated-pilot-provenance.json +55 -0
- package/examples/agent-consumer/ai-pilot-scout/CHATGPT-HANDOFF.md +70 -0
- package/examples/agent-consumer/ai-pilot-scout/CODEX-HANDOFF.md +80 -0
- package/examples/agent-consumer/ai-pilot-scout/README.md +39 -0
- package/examples/agent-consumer/ai-pilot-scout/chatgpt-geometry-correction-prompt.md +55 -0
- package/examples/agent-consumer/ai-pilot-scout/chatgpt-pose-generation-prompt.md +78 -0
- package/examples/agent-consumer/ai-pilot-scout/partial-handoff.json +73 -0
- package/examples/agent-consumer/artifact-intake/hero-motion-controls.json +15 -0
- package/examples/agent-consumer/artifact-intake/hero-motion-export.json +14 -0
- package/examples/agent-consumer/artifact-intake/hero-motion-provenance.json +20 -0
- package/examples/agent-consumer/artifact-intake/hero-motion-receipt.json +16 -0
- package/examples/agent-consumer/asset-consistency/assets/forest-back.png +0 -0
- package/examples/agent-consumer/asset-consistency/assets/forest-front.png +0 -0
- package/examples/agent-consumer/asset-consistency/assets/forest-mid.png +0 -0
- package/examples/agent-consumer/asset-consistency/assets/hero-atlas.png +0 -0
- package/examples/agent-consumer/asset-consistency/assets/hero-frame-00.png +0 -0
- package/examples/agent-consumer/asset-consistency/assets/hero-frame-01.png +0 -0
- package/examples/agent-consumer/asset-consistency/assets/hero-frame-02.png +0 -0
- package/examples/agent-consumer/asset-consistency/assets/hero-frame-03.png +0 -0
- package/examples/agent-consumer/asset-consistency/forest-layered-map.json +53 -0
- package/examples/agent-consumer/asset-consistency/hero-atlas-contract.json +24 -0
- package/examples/agent-consumer/asset-consistency/hero-identity.json +51 -0
- package/examples/agent-consumer/asset-consistency/hero-walk-action-set.json +27 -0
- package/examples/agent-consumer/asset-consistency/hero-walk-frame-geometry.json +63 -0
- package/examples/agent-consumer/rig-compatibility/hero-walk-fixture-rig.json +13 -0
- package/examples/agent-consumer/rive-package-gate/README.md +20 -0
- package/examples/agent-consumer/runtime-candidate/hero-walk-candidate.json +18 -0
- package/examples/agent-consumer/runtime-pilot/action-set.json +19 -0
- package/examples/agent-consumer/runtime-pilot/asset-identity.json +44 -0
- package/examples/agent-consumer/runtime-pilot/candidate.json +21 -0
- package/examples/agent-consumer/runtime-pilot/controls.json +35 -0
- package/examples/agent-consumer/runtime-pilot/export.json +17 -0
- package/examples/agent-consumer/runtime-pilot/provenance.json +38 -0
- package/examples/agent-consumer/runtime-pilot/receipt.json +30 -0
- package/package.json +65 -4
- package/references/agent-interoperability.md +11 -0
- package/references/browser-review-contract.md +7 -1
- package/references/intelligence-core.md +29 -2
- package/rig-adapter-registry.json +39 -0
- package/schemas/action-set.schema.json +42 -0
- package/schemas/agent-surfaces.schema.json +1 -1
- package/schemas/artifact-adapter-registry.schema.json +16 -0
- package/schemas/asset-identity.schema.json +117 -0
- package/schemas/asset-provenance.schema.json +183 -0
- package/schemas/atlas-contract.schema.json +48 -0
- package/schemas/control-track.schema.json +18 -0
- package/schemas/export-manifest.schema.json +19 -0
- package/schemas/frame-geometry.schema.json +79 -0
- package/schemas/generation-receipt.schema.json +20 -0
- package/schemas/layered-map.schema.json +75 -0
- package/schemas/rig-adapter-registry.schema.json +14 -0
- package/schemas/rig-compatibility.schema.json +53 -0
- package/schemas/rive-package-manifest.schema.json +43 -0
- package/schemas/runtime-candidate.schema.json +48 -0
- package/schemas/scene-manifest.schema.json +19 -0
- package/scripts/artifact-intake.py +408 -0
- package/scripts/asset-consistency.py +517 -0
- package/scripts/asset-provenance.py +395 -0
- package/scripts/build-ai-pilot.py +504 -0
- package/scripts/docs-audit.py +14 -2
- package/scripts/isolate-alpha-background.py +147 -0
- package/scripts/pr.py +2 -0
- package/scripts/quality-gate.py +127 -3
- package/scripts/report.py +135 -0
- package/scripts/resolve-task-bundle.py +84 -0
- package/scripts/review-hook.py +26 -4
- package/scripts/rig-compatibility.py +251 -0
- package/scripts/rive-package-gate.py +245 -0
- package/scripts/runtime-candidate.py +301 -0
- package/scripts/setup.mjs +500 -0
- package/scripts/skill-doctor.py +2 -1
- package/src/output/browser-review-smoke/asset-provenance.json +77 -0
- package/src/output/browser-review-smoke/manifest.json +1 -0
- package/src/output/browser-review-smoke/visual-truth.json +3 -3
- package/src/output/runtime-pilot-framer/asset-provenance.json +38 -0
- package/src/output/runtime-pilot-framer/browser-review.json +20 -0
- package/src/output/runtime-pilot-framer/framer-motion/runtime-telemetry.json +103 -0
- package/src/output/runtime-pilot-framer/manifest.json +31 -0
- package/src/output/runtime-pilot-framer/motion-spec.json +25 -0
- package/src/output/runtime-pilot-framer/runtime-evidence.json +96 -0
- package/src/output/runtime-pilot-framer/runtime-telemetry.json +100 -0
- package/src/output/runtime-pilot-framer/scene.jsx +52 -0
- package/src/output/runtime-pilot-framer/snapshot/.render-meta.json +9 -0
- package/src/output/runtime-pilot-framer/snapshot/frame-00.png +0 -0
- package/src/output/runtime-pilot-framer/snapshot/frame-100.png +0 -0
- package/src/output/runtime-pilot-framer/snapshot/frame-50.png +0 -0
- package/tests/scripts/run_tests.py +131 -0
- package/tests/scripts/test_ai_pilot_builder.py +128 -0
- package/tests/scripts/test_alpha_isolation.py +60 -0
- package/tests/scripts/test_artifact_intake.py +146 -0
- package/tests/scripts/test_asset_consistency.py +199 -0
- package/tests/scripts/test_rig_compatibility.py +105 -0
- package/tests/scripts/test_rive_package_gate.py +101 -0
- package/tests/scripts/test_runtime_candidate.py +95 -0
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
"""Validate and classify asset-level provenance without granting approval.
|
|
2
|
+
|
|
3
|
+
The contract is intentionally fail-closed. An Agent may declare how an asset
|
|
4
|
+
was produced and may prove runtime readiness, but it cannot manufacture human
|
|
5
|
+
authority or production approval. The script uses pathlib and JSON only so
|
|
6
|
+
the same entrypoint works on Ubuntu, macOS and Windows.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import hashlib
|
|
13
|
+
import json
|
|
14
|
+
import re
|
|
15
|
+
import sys
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
22
|
+
SCHEMA_VERSION = "1.0"
|
|
23
|
+
AUTHORITIES = {
|
|
24
|
+
"ai_generated",
|
|
25
|
+
"ai_assisted",
|
|
26
|
+
"ai_assisted_human_reviewed",
|
|
27
|
+
"artist_authored",
|
|
28
|
+
"code_authored",
|
|
29
|
+
"unknown",
|
|
30
|
+
}
|
|
31
|
+
READINESS = {
|
|
32
|
+
"blocked",
|
|
33
|
+
"runtime_ready",
|
|
34
|
+
"review_required",
|
|
35
|
+
"production_eligible",
|
|
36
|
+
"production_approved",
|
|
37
|
+
}
|
|
38
|
+
SAFE_RELATIVE = re.compile(r"^(?!/)(?!.*(?:^|/)\.\.(?:/|$)).+")
|
|
39
|
+
SHA256 = re.compile(r"^[a-f0-9]{64}$")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def read_json(path: Path) -> dict[str, Any]:
|
|
43
|
+
try:
|
|
44
|
+
value = json.loads(path.read_text(encoding="utf-8"))
|
|
45
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
46
|
+
raise ValueError(f"{path}: {exc}") from exc
|
|
47
|
+
if not isinstance(value, dict):
|
|
48
|
+
raise ValueError(f"{path}: provenance document must be a JSON object")
|
|
49
|
+
return value
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def is_datetime(value: Any) -> bool:
|
|
53
|
+
if not isinstance(value, str) or not value.strip():
|
|
54
|
+
return False
|
|
55
|
+
try:
|
|
56
|
+
datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
57
|
+
except ValueError:
|
|
58
|
+
return False
|
|
59
|
+
return True
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def is_relative_path(value: Any) -> bool:
|
|
63
|
+
return isinstance(value, str) and bool(SAFE_RELATIVE.fullmatch(value))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def is_sha256(value: Any) -> bool:
|
|
67
|
+
return isinstance(value, str) and bool(SHA256.fullmatch(value))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _required(data: dict[str, Any], keys: tuple[str, ...], prefix: str, errors: list[str]) -> None:
|
|
71
|
+
for key in keys:
|
|
72
|
+
if key not in data:
|
|
73
|
+
errors.append(f"{prefix}.{key} is required")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _check_text(data: dict[str, Any], key: str, prefix: str, errors: list[str]) -> None:
|
|
77
|
+
if key in data and (not isinstance(data[key], str) or not data[key].strip()):
|
|
78
|
+
errors.append(f"{prefix}.{key} must be a non-empty string")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _check_human_review(data: dict[str, Any], errors: list[str]) -> None:
|
|
82
|
+
review = data.get("human_review")
|
|
83
|
+
if not isinstance(review, dict):
|
|
84
|
+
errors.append("human_review is required for human-reviewed readiness")
|
|
85
|
+
return
|
|
86
|
+
_required(review, ("reviewer", "decision", "scope", "reviewed_at", "user_confirmed"), "human_review", errors)
|
|
87
|
+
_check_text(review, "reviewer", "human_review", errors)
|
|
88
|
+
if review.get("decision") not in {"approved", "rejected", "changes_requested"}:
|
|
89
|
+
errors.append("human_review.decision must be approved, rejected or changes_requested")
|
|
90
|
+
if not is_datetime(review.get("reviewed_at")):
|
|
91
|
+
errors.append("human_review.reviewed_at must be an ISO-8601 timestamp")
|
|
92
|
+
if review.get("user_confirmed") is not True:
|
|
93
|
+
errors.append("human_review.user_confirmed must be true; Agent-only review is not sufficient")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _check_human_attestation(data: dict[str, Any], errors: list[str]) -> None:
|
|
97
|
+
attestation = data.get("human_attestation")
|
|
98
|
+
if not isinstance(attestation, dict):
|
|
99
|
+
errors.append("artist_authored requires human_attestation")
|
|
100
|
+
return
|
|
101
|
+
_required(attestation, ("attestor", "attestor_type", "decision", "attested_at", "user_confirmed"), "human_attestation", errors)
|
|
102
|
+
_check_text(attestation, "attestor", "human_attestation", errors)
|
|
103
|
+
if attestation.get("attestor_type") not in {"artist", "user"}:
|
|
104
|
+
errors.append("human_attestation.attestor_type must be artist or user")
|
|
105
|
+
if attestation.get("decision") != "artist_authored":
|
|
106
|
+
errors.append("human_attestation.decision must be artist_authored")
|
|
107
|
+
if not is_datetime(attestation.get("attested_at")):
|
|
108
|
+
errors.append("human_attestation.attested_at must be an ISO-8601 timestamp")
|
|
109
|
+
if attestation.get("user_confirmed") is not True:
|
|
110
|
+
errors.append("human_attestation.user_confirmed must be true; Agent-only authority is rejected")
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _check_generator(data: dict[str, Any], errors: list[str]) -> None:
|
|
114
|
+
generator = data.get("generator")
|
|
115
|
+
if not isinstance(generator, dict):
|
|
116
|
+
errors.append("AI-origin authority requires generator metadata")
|
|
117
|
+
return
|
|
118
|
+
_required(generator, ("model", "task_id", "source", "generated_at"), "generator", errors)
|
|
119
|
+
for key in ("model", "task_id", "source"):
|
|
120
|
+
_check_text(generator, key, "generator", errors)
|
|
121
|
+
if not is_datetime(generator.get("generated_at")):
|
|
122
|
+
errors.append("generator.generated_at must be an ISO-8601 timestamp")
|
|
123
|
+
if "prompt_hash" in generator and not is_sha256(generator.get("prompt_hash")):
|
|
124
|
+
errors.append("generator.prompt_hash must be a lowercase SHA-256")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _check_files(data: dict[str, Any], errors: list[str]) -> None:
|
|
128
|
+
files = data.get("files")
|
|
129
|
+
if not isinstance(files, list) or not files:
|
|
130
|
+
errors.append("files must contain at least one asset file")
|
|
131
|
+
return
|
|
132
|
+
for index, item in enumerate(files):
|
|
133
|
+
prefix = f"files[{index}]"
|
|
134
|
+
if not isinstance(item, dict):
|
|
135
|
+
errors.append(f"{prefix} must be an object")
|
|
136
|
+
continue
|
|
137
|
+
_required(item, ("path", "role", "sha256"), prefix, errors)
|
|
138
|
+
if not is_relative_path(item.get("path")):
|
|
139
|
+
errors.append(f"{prefix}.path must be a safe relative path")
|
|
140
|
+
_check_text(item, "role", prefix, errors)
|
|
141
|
+
if not is_sha256(item.get("sha256")):
|
|
142
|
+
errors.append(f"{prefix}.sha256 must be a lowercase SHA-256")
|
|
143
|
+
if "bytes" in item and (not isinstance(item["bytes"], int) or item["bytes"] < 0):
|
|
144
|
+
errors.append(f"{prefix}.bytes must be a non-negative integer")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _check_chain(data: dict[str, Any], errors: list[str]) -> None:
|
|
148
|
+
chain = data.get("provenance_chain")
|
|
149
|
+
if not isinstance(chain, list) or not chain:
|
|
150
|
+
errors.append("provenance_chain must contain at least one step")
|
|
151
|
+
return
|
|
152
|
+
for index, item in enumerate(chain):
|
|
153
|
+
prefix = f"provenance_chain[{index}]"
|
|
154
|
+
if not isinstance(item, dict):
|
|
155
|
+
errors.append(f"{prefix} must be an object")
|
|
156
|
+
continue
|
|
157
|
+
_required(item, ("step", "actor", "source", "timestamp"), prefix, errors)
|
|
158
|
+
for key in ("step", "actor", "source"):
|
|
159
|
+
_check_text(item, key, prefix, errors)
|
|
160
|
+
if not is_datetime(item.get("timestamp")):
|
|
161
|
+
errors.append(f"{prefix}.timestamp must be an ISO-8601 timestamp")
|
|
162
|
+
if "sha256" in item and not is_sha256(item.get("sha256")):
|
|
163
|
+
errors.append(f"{prefix}.sha256 must be a lowercase SHA-256")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def validate_document(data: dict[str, Any]) -> list[str]:
|
|
167
|
+
errors: list[str] = []
|
|
168
|
+
_required(data, ("schema_version", "provenance_id", "asset", "authority", "readiness", "files", "license", "provenance_chain", "created_at"), "provenance", errors)
|
|
169
|
+
if data.get("schema_version") != SCHEMA_VERSION:
|
|
170
|
+
errors.append(f"schema_version must be {SCHEMA_VERSION}")
|
|
171
|
+
_check_text(data, "provenance_id", "provenance", errors)
|
|
172
|
+
if not is_datetime(data.get("created_at")):
|
|
173
|
+
errors.append("created_at must be an ISO-8601 timestamp")
|
|
174
|
+
|
|
175
|
+
asset = data.get("asset")
|
|
176
|
+
if not isinstance(asset, dict):
|
|
177
|
+
errors.append("asset must be an object")
|
|
178
|
+
else:
|
|
179
|
+
_required(asset, ("id", "path", "type", "framework"), "asset", errors)
|
|
180
|
+
_check_text(asset, "id", "asset", errors)
|
|
181
|
+
if not is_relative_path(asset.get("path")):
|
|
182
|
+
errors.append("asset.path must be a safe relative path")
|
|
183
|
+
for key in ("type", "framework"):
|
|
184
|
+
_check_text(asset, key, "asset", errors)
|
|
185
|
+
|
|
186
|
+
authority = data.get("authority")
|
|
187
|
+
readiness = data.get("readiness")
|
|
188
|
+
if authority not in AUTHORITIES:
|
|
189
|
+
errors.append(f"authority must be one of {sorted(AUTHORITIES)}")
|
|
190
|
+
if readiness not in READINESS:
|
|
191
|
+
errors.append(f"readiness must be one of {sorted(READINESS)}")
|
|
192
|
+
|
|
193
|
+
license_data = data.get("license")
|
|
194
|
+
if not isinstance(license_data, dict):
|
|
195
|
+
errors.append("license must be an object")
|
|
196
|
+
else:
|
|
197
|
+
_required(license_data, ("spdx", "source", "attribution"), "license", errors)
|
|
198
|
+
for key in ("spdx", "source", "attribution"):
|
|
199
|
+
_check_text(license_data, key, "license", errors)
|
|
200
|
+
|
|
201
|
+
_check_files(data, errors)
|
|
202
|
+
_check_chain(data, errors)
|
|
203
|
+
if authority in {"ai_generated", "ai_assisted", "ai_assisted_human_reviewed"}:
|
|
204
|
+
_check_generator(data, errors)
|
|
205
|
+
if authority == "artist_authored":
|
|
206
|
+
_check_human_attestation(data, errors)
|
|
207
|
+
|
|
208
|
+
if authority == "unknown" and readiness != "blocked":
|
|
209
|
+
errors.append("unknown authority is always blocked")
|
|
210
|
+
if authority == "ai_generated" and readiness != "runtime_ready":
|
|
211
|
+
errors.append("ai_generated assets may be runtime_ready only; they are never production eligible")
|
|
212
|
+
if authority == "code_authored" and readiness not in {"runtime_ready", "review_required"}:
|
|
213
|
+
errors.append("code_authored runtime scenes may be runtime_ready or review_required only; production eligibility remains a separate human-governed release lane")
|
|
214
|
+
if authority == "ai_assisted_human_reviewed" and readiness not in {"review_required", "production_eligible"}:
|
|
215
|
+
errors.append("ai_assisted_human_reviewed assets must remain review_required or pass a later production gate")
|
|
216
|
+
if authority == "ai_assisted_human_reviewed":
|
|
217
|
+
_check_human_review(data, errors)
|
|
218
|
+
if authority == "ai_assisted" and readiness not in {"runtime_ready", "review_required", "production_eligible"}:
|
|
219
|
+
errors.append("ai_assisted assets must be runtime_ready, review_required or production_eligible")
|
|
220
|
+
if authority == "ai_assisted" and readiness == "production_eligible":
|
|
221
|
+
_check_human_review(data, errors)
|
|
222
|
+
if readiness in {"production_eligible", "production_approved"}:
|
|
223
|
+
runtime = data.get("runtime_evidence")
|
|
224
|
+
if not isinstance(runtime, dict) or runtime.get("status") != "pass":
|
|
225
|
+
errors.append("production eligibility requires runtime_evidence.status=pass")
|
|
226
|
+
full_gate = data.get("full_gate")
|
|
227
|
+
if not isinstance(full_gate, dict):
|
|
228
|
+
errors.append("production eligibility requires full_gate evidence")
|
|
229
|
+
else:
|
|
230
|
+
_required(full_gate, ("status", "quality_gate", "visual_truth", "license", "checked_at"), "full_gate", errors)
|
|
231
|
+
if full_gate.get("status") != "pass" or full_gate.get("quality_gate") != "pass" or full_gate.get("visual_truth") != "pass" or full_gate.get("license") != "pass":
|
|
232
|
+
errors.append("full_gate must have pass for status, quality_gate, visual_truth and license")
|
|
233
|
+
if not is_datetime(full_gate.get("checked_at")):
|
|
234
|
+
errors.append("full_gate.checked_at must be an ISO-8601 timestamp")
|
|
235
|
+
if authority in {"ai_assisted", "ai_assisted_human_reviewed"}:
|
|
236
|
+
_check_human_review(data, errors)
|
|
237
|
+
if authority in {"unknown", "ai_generated", "code_authored"}:
|
|
238
|
+
errors.append(f"{authority} cannot be production eligible")
|
|
239
|
+
if readiness == "production_approved":
|
|
240
|
+
approval = data.get("human_approval")
|
|
241
|
+
if not isinstance(approval, dict):
|
|
242
|
+
errors.append("production_approved requires human_approval")
|
|
243
|
+
else:
|
|
244
|
+
_required(approval, ("issued_by", "decision", "approved_at", "user_confirmed"), "human_approval", errors)
|
|
245
|
+
issuer = approval.get("issued_by")
|
|
246
|
+
if not isinstance(issuer, dict) or issuer.get("type") not in {"user", "artist"} or not str(issuer.get("id") or "").strip():
|
|
247
|
+
errors.append("human_approval.issued_by must be a non-empty user or artist identity")
|
|
248
|
+
if approval.get("decision") != "approved":
|
|
249
|
+
errors.append("human_approval.decision must be approved")
|
|
250
|
+
if not is_datetime(approval.get("approved_at")):
|
|
251
|
+
errors.append("human_approval.approved_at must be an ISO-8601 timestamp")
|
|
252
|
+
if approval.get("user_confirmed") is not True:
|
|
253
|
+
errors.append("human_approval.user_confirmed must be true")
|
|
254
|
+
if authority in {"unknown", "ai_generated", "code_authored"}:
|
|
255
|
+
errors.append("unknown, ai_generated and code_authored assets can never be production_approved")
|
|
256
|
+
if "human_approval" in data and readiness != "production_approved":
|
|
257
|
+
errors.append("human_approval is only valid when readiness is production_approved")
|
|
258
|
+
return errors
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _resolve_inside(base: Path, relative: str) -> Path | None:
|
|
262
|
+
if not is_relative_path(relative):
|
|
263
|
+
return None
|
|
264
|
+
resolved = (base / relative).resolve()
|
|
265
|
+
try:
|
|
266
|
+
resolved.relative_to(base.resolve())
|
|
267
|
+
except ValueError:
|
|
268
|
+
return None
|
|
269
|
+
return resolved
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def validate_files(data: dict[str, Any], base: Path) -> list[str]:
|
|
273
|
+
errors: list[str] = []
|
|
274
|
+
for item in data.get("files", []):
|
|
275
|
+
path = _resolve_inside(base, str(item.get("path", "")))
|
|
276
|
+
if path is None or not path.is_file():
|
|
277
|
+
errors.append(f"asset file is missing: {item.get('path', '<unknown>')}")
|
|
278
|
+
continue
|
|
279
|
+
digest = hashlib.sha256(path.read_bytes()).hexdigest()
|
|
280
|
+
if digest != item.get("sha256"):
|
|
281
|
+
errors.append(f"asset file SHA-256 mismatch: {item.get('path', '<unknown>')}")
|
|
282
|
+
if "bytes" in item and path.stat().st_size != item.get("bytes"):
|
|
283
|
+
errors.append(f"asset file byte count mismatch: {item.get('path', '<unknown>')}")
|
|
284
|
+
asset_path = _resolve_inside(base, str((data.get("asset") or {}).get("path", "")))
|
|
285
|
+
if asset_path is None or not asset_path.is_file():
|
|
286
|
+
errors.append(f"asset.path is missing: {(data.get('asset') or {}).get('path', '<unknown>')}")
|
|
287
|
+
return errors
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def classify(data: dict[str, Any], errors: list[str] | None = None) -> dict[str, Any]:
|
|
291
|
+
errors = errors or []
|
|
292
|
+
authority = data.get("authority", "unknown")
|
|
293
|
+
readiness = data.get("readiness", "blocked")
|
|
294
|
+
effective = "blocked" if errors or authority == "unknown" else "runtime_ready"
|
|
295
|
+
if not errors:
|
|
296
|
+
if authority == "ai_generated":
|
|
297
|
+
effective = "runtime_ready"
|
|
298
|
+
elif authority == "code_authored":
|
|
299
|
+
effective = "review_required" if readiness == "review_required" else "runtime_ready"
|
|
300
|
+
elif authority in {"ai_assisted", "ai_assisted_human_reviewed"}:
|
|
301
|
+
review = data.get("human_review") or {}
|
|
302
|
+
if data.get("full_gate", {}).get("status") == "pass" and review.get("decision") == "approved" and review.get("user_confirmed") is True:
|
|
303
|
+
effective = "production_eligible"
|
|
304
|
+
elif authority == "ai_assisted_human_reviewed" or readiness == "review_required":
|
|
305
|
+
effective = "review_required"
|
|
306
|
+
else:
|
|
307
|
+
effective = "runtime_ready"
|
|
308
|
+
elif authority == "artist_authored":
|
|
309
|
+
effective = "production_eligible" if data.get("full_gate", {}).get("status") == "pass" else "runtime_ready"
|
|
310
|
+
if readiness == "production_approved" and data.get("human_approval", {}).get("user_confirmed") is True:
|
|
311
|
+
effective = "production_approved"
|
|
312
|
+
return {
|
|
313
|
+
"authority": authority,
|
|
314
|
+
"declared_readiness": readiness,
|
|
315
|
+
"effective_readiness": effective,
|
|
316
|
+
"production_eligible": effective in {"production_eligible", "production_approved"},
|
|
317
|
+
"production_approved": effective == "production_approved",
|
|
318
|
+
"errors": errors,
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def evaluate(path: Path, *, base: Path | None = None, mode: str = "contract", manifest: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
323
|
+
try:
|
|
324
|
+
data = read_json(path)
|
|
325
|
+
except ValueError as exc:
|
|
326
|
+
return {"status": "fail", "provenance_path": str(path), "errors": [str(exc)]}
|
|
327
|
+
errors = validate_document(data)
|
|
328
|
+
if manifest is not None:
|
|
329
|
+
manifest_file = manifest.get("file")
|
|
330
|
+
asset_path = (data.get("asset") or {}).get("path")
|
|
331
|
+
if manifest_file and asset_path != manifest_file:
|
|
332
|
+
errors.append("asset.path must match scene manifest.file")
|
|
333
|
+
provenance_ref = manifest.get("asset_provenance")
|
|
334
|
+
if provenance_ref and provenance_ref != path.name and provenance_ref != path.as_posix():
|
|
335
|
+
errors.append("scene manifest asset_provenance does not match the loaded provenance file")
|
|
336
|
+
if mode in {"runtime", "production"}:
|
|
337
|
+
if base is None:
|
|
338
|
+
errors.append(f"{mode} check requires --root for asset file hash verification")
|
|
339
|
+
else:
|
|
340
|
+
errors.extend(validate_files(data, base))
|
|
341
|
+
runtime = data.get("runtime_evidence") or {}
|
|
342
|
+
if runtime.get("status") != "pass":
|
|
343
|
+
errors.append("runtime check requires runtime_evidence.status=pass")
|
|
344
|
+
if mode == "production":
|
|
345
|
+
summary = classify(data, errors)
|
|
346
|
+
if summary["effective_readiness"] != "production_eligible":
|
|
347
|
+
errors.append("production check requires effective_readiness=production_eligible; production_approved remains a human-only state")
|
|
348
|
+
summary = classify(data, errors)
|
|
349
|
+
return {
|
|
350
|
+
"status": "pass" if not errors else "fail",
|
|
351
|
+
"mode": mode,
|
|
352
|
+
"provenance_path": str(path),
|
|
353
|
+
"summary": summary,
|
|
354
|
+
"errors": errors,
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def print_result(result: dict[str, Any], as_json: bool = True) -> None:
|
|
359
|
+
if as_json:
|
|
360
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
361
|
+
return
|
|
362
|
+
print(f"Asset provenance: {result.get('status', 'fail').upper()}")
|
|
363
|
+
summary = result.get("summary") or {}
|
|
364
|
+
print(f"Authority: {summary.get('authority', 'unknown')}")
|
|
365
|
+
print(f"Declared readiness: {summary.get('declared_readiness', 'blocked')}")
|
|
366
|
+
print(f"Effective readiness: {summary.get('effective_readiness', 'blocked')}")
|
|
367
|
+
for error in result.get("errors", []):
|
|
368
|
+
print(f"- {error}")
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def main() -> int:
|
|
372
|
+
parser = argparse.ArgumentParser(description="Validate, classify and report MotionLoom asset provenance")
|
|
373
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
374
|
+
for name in ("validate", "classify", "check", "report"):
|
|
375
|
+
command = sub.add_parser(name)
|
|
376
|
+
command.add_argument("--input", required=True, help="Asset provenance JSON path")
|
|
377
|
+
command.add_argument("--root", help="Directory used to resolve and hash asset files")
|
|
378
|
+
command.add_argument("--mode", choices=("contract", "runtime", "production"), default="contract")
|
|
379
|
+
command.add_argument("--manifest", help="Optional scene manifest used for binding checks")
|
|
380
|
+
command.add_argument("--json", action="store_true", help="Emit JSON output")
|
|
381
|
+
args = parser.parse_args()
|
|
382
|
+
path = Path(args.input).expanduser().resolve()
|
|
383
|
+
base = Path(args.root).expanduser().resolve() if args.root else None
|
|
384
|
+
manifest = read_json(Path(args.manifest).expanduser().resolve()) if args.manifest else None
|
|
385
|
+
result = evaluate(path, base=base, mode=args.mode, manifest=manifest)
|
|
386
|
+
if args.command == "classify" and result.get("summary"):
|
|
387
|
+
result = {"status": result.get("status"), "provenance_path": str(path), "summary": result["summary"], "errors": result.get("errors", [])}
|
|
388
|
+
if args.command == "validate":
|
|
389
|
+
result["mode"] = "contract"
|
|
390
|
+
print_result(result, as_json=args.json or args.command != "report")
|
|
391
|
+
return 0 if result.get("status") == "pass" else 1
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
if __name__ == "__main__":
|
|
395
|
+
raise SystemExit(main())
|