vibedgames 0.10.1 → 0.10.2
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/assets/rebuild-object/.cache/spec-search/core_3d.json +1 -0
- package/assets/rebuild-object/.cache/spec-search/cs2.json +1 -0
- package/assets/rebuild-object/LICENSE +201 -0
- package/assets/rebuild-object/NOTICE +7 -0
- package/assets/rebuild-object/docs/materials/material-reference.json +2324 -0
- package/assets/rebuild-object/docs/specs/render-profile.v2.example.json +63 -0
- package/assets/rebuild-object/docs/specs/render-profile.v2.schema.json +56 -0
- package/assets/rebuild-object/docs/specs/vocabulary/README.md +86 -0
- package/assets/rebuild-object/docs/specs/vocabulary/core_3d.jsonl +12 -0
- package/assets/rebuild-object/docs/specs/vocabulary/core_3d_reconstruction.jsonl +37 -0
- package/assets/rebuild-object/docs/specs/vocabulary/cs2.jsonl +8 -0
- package/assets/rebuild-object/docs/specs/vocabulary/cs2_reconstruction.jsonl +62 -0
- package/assets/rebuild-object/forge/_shared/artifact_cache.py +54 -0
- package/assets/rebuild-object/forge/_shared/chirality.py +272 -0
- package/assets/rebuild-object/forge/_shared/color_metrics.py +107 -0
- package/assets/rebuild-object/forge/_shared/feature_acceptance_policy.py +113 -0
- package/assets/rebuild-object/forge/_shared/image_hash.py +113 -0
- package/assets/rebuild-object/forge/_shared/jpeg.py +448 -0
- package/assets/rebuild-object/forge/_shared/material_physics.py +253 -0
- package/assets/rebuild-object/forge/_shared/pipeline_routing.py +177 -0
- package/assets/rebuild-object/forge/_shared/scalp_field.py +302 -0
- package/assets/rebuild-object/forge/_shared/sdf_primitives.py +172 -0
- package/assets/rebuild-object/forge/_shared/spec_search.py +1792 -0
- package/assets/rebuild-object/forge/_shared/spec_search_profiles.json +58 -0
- package/assets/rebuild-object/forge/_shared/status_banner.py +35 -0
- package/assets/rebuild-object/forge/_shared/subdivision.py +232 -0
- package/assets/rebuild-object/forge/_shared/vertex_paint.py +236 -0
- package/assets/rebuild-object/forge/_shared/workflow_state.py +406 -0
- package/assets/rebuild-object/forge/materials/__init__.py +17 -0
- package/assets/rebuild-object/forge/materials/compatibility.py +106 -0
- package/assets/rebuild-object/forge/materials/reference.py +240 -0
- package/assets/rebuild-object/forge/next.py +116 -0
- package/assets/rebuild-object/forge/report.py +38 -0
- package/assets/rebuild-object/forge/requirements.txt +6 -0
- package/assets/rebuild-object/forge/stage1_intake/analyze_texture.py +255 -0
- package/assets/rebuild-object/forge/stage1_intake/bind_detail_properties.py +99 -0
- package/assets/rebuild-object/forge/stage1_intake/build_detail_inventory.py +349 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_math.py +133 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_solver.py +197 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_types.py +291 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_image_helpers.py +133 -0
- package/assets/rebuild-object/forge/stage1_intake/check_intake_correctness.py +116 -0
- package/assets/rebuild-object/forge/stage1_intake/check_reference_admission.py +203 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_foundation.py +139 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_manifest.py +230 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_review_contract.py +42 -0
- package/assets/rebuild-object/forge/stage1_intake/delight_albedo.py +352 -0
- package/assets/rebuild-object/forge/stage1_intake/detect_cs2.py +276 -0
- package/assets/rebuild-object/forge/stage1_intake/detect_reference_effects.py +275 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_cs2_textures.py +126 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_gradient_stops.py +149 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_hair_evidence.py +385 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_landmarks.py +456 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_part_color_recipe.py +496 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_pbr_evidence.py +843 -0
- package/assets/rebuild-object/forge/stage1_intake/fetch_cs2_metadata.py +147 -0
- package/assets/rebuild-object/forge/stage1_intake/label_glb_nodes.py +318 -0
- package/assets/rebuild-object/forge/stage1_intake/locate_cs2_vpk.py +73 -0
- package/assets/rebuild-object/forge/stage1_intake/material_region_analysis.py +227 -0
- package/assets/rebuild-object/forge/stage1_intake/probe_glb.py +357 -0
- package/assets/rebuild-object/forge/stage1_intake/probe_image.py +168 -0
- package/assets/rebuild-object/forge/stage1_intake/run_vision_adapter.py +45 -0
- package/assets/rebuild-object/forge/stage1_intake/search_specs.py +258 -0
- package/assets/rebuild-object/forge/stage1_intake/semantic_decomposition.py +119 -0
- package/assets/rebuild-object/forge/stage1_intake/solve_camera_pose.py +254 -0
- package/assets/rebuild-object/forge/stage2_spec/apply_material_analysis.py +192 -0
- package/assets/rebuild-object/forge/stage2_spec/cs2_adapters.py +62 -0
- package/assets/rebuild-object/forge/stage2_spec/derive_geometry.py +118 -0
- package/assets/rebuild-object/forge/stage2_spec/hair_profile.py +306 -0
- package/assets/rebuild-object/forge/stage2_spec/humanoid_proportions.py +214 -0
- package/assets/rebuild-object/forge/stage2_spec/new_pre_spec_assessment.py +343 -0
- package/assets/rebuild-object/forge/stage2_spec/new_sculpt_spec.py +2396 -0
- package/assets/rebuild-object/forge/stage2_spec/validate_sculpt_spec.py +2871 -0
- package/assets/rebuild-object/forge/stage3_build/bake_projected_texture.py +181 -0
- package/assets/rebuild-object/forge/stage3_build/decimate.py +272 -0
- package/assets/rebuild-object/forge/stage3_build/generate_threejs_factory.py +4099 -0
- package/assets/rebuild-object/forge/stage3_build/module_cache.py +155 -0
- package/assets/rebuild-object/forge/stage3_build/morph_targets.py +178 -0
- package/assets/rebuild-object/forge/stage3_build/orchestrate_passes.py +653 -0
- package/assets/rebuild-object/forge/stage3_build/uv_unwrap.py +622 -0
- package/assets/rebuild-object/forge/stage3_build/visual_hull.py +357 -0
- package/assets/rebuild-object/forge/stage4_review/_fit_divine_eye.py +64 -0
- package/assets/rebuild-object/forge/stage4_review/append_review.py +453 -0
- package/assets/rebuild-object/forge/stage4_review/attachment_anchor.py +349 -0
- package/assets/rebuild-object/forge/stage4_review/calibrate_eye.py +131 -0
- package/assets/rebuild-object/forge/stage4_review/check_part_coverage.py +298 -0
- package/assets/rebuild-object/forge/stage4_review/compare_region_passes.py +169 -0
- package/assets/rebuild-object/forge/stage4_review/correction_loop.py +258 -0
- package/assets/rebuild-object/forge/stage4_review/cs2_review.py +224 -0
- package/assets/rebuild-object/forge/stage4_review/diagnose_render.py +356 -0
- package/assets/rebuild-object/forge/stage4_review/diagnose_render_multi_angle.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/divine_eye.py +461 -0
- package/assets/rebuild-object/forge/stage4_review/fit_params.py +381 -0
- package/assets/rebuild-object/forge/stage4_review/geometry_integrity.py +294 -0
- package/assets/rebuild-object/forge/stage4_review/hair_gate.py +216 -0
- package/assets/rebuild-object/forge/stage4_review/interior_difference.py +188 -0
- package/assets/rebuild-object/forge/stage4_review/joint_loops.py +209 -0
- package/assets/rebuild-object/forge/stage4_review/make_comparison_sheet.py +292 -0
- package/assets/rebuild-object/forge/stage4_review/material_comparator.py +181 -0
- package/assets/rebuild-object/forge/stage4_review/material_feedback.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/material_gate.py +126 -0
- package/assets/rebuild-object/forge/stage4_review/material_views.py +184 -0
- package/assets/rebuild-object/forge/stage4_review/mesh_reference_compare.py +362 -0
- package/assets/rebuild-object/forge/stage4_review/multi_pass.py +102 -0
- package/assets/rebuild-object/forge/stage4_review/objectness.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/pairwise_penetration.py +376 -0
- package/assets/rebuild-object/forge/stage4_review/per_feature.py +215 -0
- package/assets/rebuild-object/forge/stage4_review/render_bridge.py +556 -0
- package/assets/rebuild-object/forge/stage4_review/scalp_exposure.py +257 -0
- package/assets/rebuild-object/forge/stage4_review/self_intersection.py +592 -0
- package/assets/rebuild-object/forge/stage4_review/swept_arc_gate.py +336 -0
- package/assets/rebuild-object/forge/stage4_review/turntable_gate.py +415 -0
- package/assets/rebuild-object/forge/stage4_review/validate_render_profile.py +182 -0
- package/assets/rebuild-object/forge/stage4_review/vertex_region_gate.py +456 -0
- package/assets/rebuild-object/forge/stage4_review/vlm_gate.py +196 -0
- package/assets/rebuild-object/forge/stage5_rig/NOTES.md +149 -0
- package/assets/rebuild-object/forge/stage5_rig/__init__.py +6 -0
- package/assets/rebuild-object/forge/stage5_rig/emit_rig.py +420 -0
- package/assets/rebuild-object/forge/stage5_rig/geodesic_skinning.py +508 -0
- package/assets/rebuild-object/forge/stage5_rig/rig_spec.py +174 -0
- package/assets/rebuild-object/forge/stage5_rig/validate_rig_payload.py +195 -0
- package/assets/rebuild-object/forge/state.py +98 -0
- package/assets/rebuild-object/steps.json +381 -0
- package/dist/{chunk-FB3UDZAV.js → chunk-24TITAFS.js} +1 -1
- package/dist/{chunk-QNWCBPVO.js → chunk-2C5PG2QO.js} +1 -1
- package/dist/{chunk-4RYTTD4D.js → chunk-2DEVOKI7.js} +1 -1
- package/dist/{chunk-RRI23NK2.js → chunk-2GHPYT2P.js} +1 -1
- package/dist/{chunk-QEKVZ7BX.js → chunk-2HXGMXGC.js} +1 -1
- package/dist/{chunk-N2UHAQXC.js → chunk-36FORP7T.js} +0 -1
- package/dist/{chunk-DH6WPL3X.js → chunk-3IXRQTRF.js} +1 -1
- package/dist/{chunk-SXYQL4GK.js → chunk-4YHA32OE.js} +1 -1
- package/dist/{chunk-V5ADM3WC.js → chunk-4ZGQKPK5.js} +1 -1
- package/dist/{chunk-BJAN3RMY.js → chunk-6CLUPFQA.js} +1 -1
- package/dist/{chunk-52E6EKZV.js → chunk-7WTF2BA4.js} +1 -1
- package/dist/{chunk-P74GTK23.js → chunk-AAXZNK4Z.js} +1 -1
- package/dist/{chunk-F4J6XCHT.js → chunk-ALLBT4FB.js} +1 -1
- package/dist/{chunk-HRKVAXNN.js → chunk-BAZDPPIG.js} +5 -5
- package/dist/{chunk-RPJR3S5S.js → chunk-CYDENLZ4.js} +5 -8
- package/dist/{chunk-I5LELJSK.js → chunk-DKSUD44G.js} +1 -1
- package/dist/{chunk-43P4U7CB.js → chunk-DWWSJKTE.js} +1 -1
- package/dist/{chunk-6IUFHPMV.js → chunk-E72TFJZP.js} +1 -1
- package/dist/{chunk-E3FJUPLT.js → chunk-EUAAQMUA.js} +2 -0
- package/dist/{chunk-37LLKM73.js → chunk-F7LYJSZE.js} +1 -1
- package/dist/{chunk-MEAO33XW.js → chunk-FMON3C74.js} +8 -8
- package/dist/{chunk-YLUB6252.js → chunk-FPILHRLZ.js} +1 -1
- package/dist/{chunk-4UU622RK.js → chunk-GGO6ZYYI.js} +1 -3
- package/dist/{chunk-2ZKS7V72.js → chunk-GZCRYYS6.js} +5 -5
- package/dist/{chunk-E7NDOZ27.js → chunk-LE4GVTYI.js} +8 -8
- package/dist/{chunk-UTSSDFQL.js → chunk-NO6KPV64.js} +1 -1
- package/dist/{chunk-W2QPNAZ3.js → chunk-NXW3Z4Y4.js} +1 -1
- package/dist/{chunk-NG2X3SMF.js → chunk-OHOAZGO4.js} +1 -1
- package/dist/chunk-PYJNI5WD.js +83 -0
- package/dist/{chunk-VUV5U4J5.js → chunk-Q4XAGTFX.js} +1 -1
- package/dist/{chunk-3UGGMFJJ.js → chunk-QMZBSVKF.js} +1 -1
- package/dist/{chunk-ABTUEIRC.js → chunk-QO66UBOS.js} +2 -2
- package/dist/{chunk-LONQWRTR.js → chunk-S4KVGQQO.js} +8 -8
- package/dist/{chunk-FJXPMA63.js → chunk-T777EXAO.js} +1 -1
- package/dist/{chunk-YXOGRERG.js → chunk-TZZNRA3S.js} +1 -1
- package/dist/{chunk-CTY2WZQK.js → chunk-UC3QLWMQ.js} +1 -1
- package/dist/{chunk-MR5KIFI7.js → chunk-UDJH2RED.js} +3 -3
- package/dist/{chunk-FNJL6Z5C.js → chunk-UIKYK7KI.js} +1 -1
- package/dist/{chunk-PKM3JOKQ.js → chunk-UJRSQO2B.js} +1 -1
- package/dist/{chunk-ALPTHSUT.js → chunk-V7LEYVXB.js} +28 -24
- package/dist/{chunk-DPLFCKXP.js → chunk-WRMQEXUC.js} +1 -1
- package/dist/{chunk-HSMG6U7J.js → chunk-WXSBNC67.js} +3 -9
- package/dist/{chunk-HSCTPDEU.js → chunk-X4QIOXNQ.js} +1 -1
- package/dist/{chunk-72KHWZMN.js → chunk-Y6WHUK2O.js} +1 -1
- package/dist/{chunk-VZEJ2ZHE.js → chunk-Z3E7ORGQ.js} +5 -5
- package/dist/index.js +20 -20
- package/package.json +32 -22
- package/dist/{chunk-OFJIG4K3.js → chunk-4ENHS32B.js} +0 -0
- package/dist/{chunk-Q3XQPNF6.js → chunk-BN7TR6OR.js} +3 -3
- package/dist/{chunk-LORGE2NB.js → chunk-U2NCN5RO.js} +3 -3
- package/dist/{chunk-UPHB5HWO.js → chunk-VQTTSPA3.js} +3 -3
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Bounded stop-policy state machine for the Eye-driven correction loop.
|
|
3
|
+
|
|
4
|
+
Plan 1.3 Phase 4, §3.6 — bounded correction-loop stop policy.
|
|
5
|
+
|
|
6
|
+
This is a PURE-LOGIC module: no images, no repo imports, stdlib only. It decides,
|
|
7
|
+
after each iteration of an expensive VLM-driven correction loop, whether to stop
|
|
8
|
+
and what action the caller should take next.
|
|
9
|
+
|
|
10
|
+
TERMINATION GUARANTEE
|
|
11
|
+
---------------------
|
|
12
|
+
A caller that loops::
|
|
13
|
+
|
|
14
|
+
while not decide(history)["stop"]:
|
|
15
|
+
history.append(one_more_iteration())
|
|
16
|
+
|
|
17
|
+
can NEVER run more than ``max_iter`` iterations. The HARD_CEILING condition
|
|
18
|
+
(priority 8) fires purely on ``len(history) >= max_iter`` and cannot be bypassed
|
|
19
|
+
by any other state — not even a monotonically-improving-but-never-reaching-target
|
|
20
|
+
loop. This is the single most important property of this module; do not weaken it.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import json
|
|
27
|
+
import math
|
|
28
|
+
import sys
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def decide(history, target_fidelity=0.85, max_iter=6, min_delta=0.02):
|
|
32
|
+
"""Decide whether to stop the correction loop and what to do next.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
history: list of per-iteration dicts in chronological order, each
|
|
36
|
+
``{"fidelity": float in [0,1], "defectTags": list[str], "reverted": bool}``,
|
|
37
|
+
with optional Divine Eye ``hardGateFailures: list[str]`` and
|
|
38
|
+
``pendingReview: bool`` routing metadata.
|
|
39
|
+
``reverted`` means that iteration's correction lowered the score and
|
|
40
|
+
was auto-reverted.
|
|
41
|
+
target_fidelity: fidelity at/above which the model is considered good enough.
|
|
42
|
+
max_iter: non-bypassable ceiling on iterations — guarantees termination.
|
|
43
|
+
min_delta: minimum per-iteration fidelity gain below which progress has
|
|
44
|
+
plateaued.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
dict ``{"stop": bool, "action": str, "reason": str}``.
|
|
48
|
+
|
|
49
|
+
Stop conditions are evaluated in strict priority order; the first match wins.
|
|
50
|
+
"""
|
|
51
|
+
_validate_config(target_fidelity, max_iter, min_delta)
|
|
52
|
+
_validate_history(history)
|
|
53
|
+
|
|
54
|
+
# 1. EMPTY — nothing has happened yet.
|
|
55
|
+
if not history:
|
|
56
|
+
return {
|
|
57
|
+
"stop": False,
|
|
58
|
+
"action": "continue-iterating",
|
|
59
|
+
"reason": "no iterations yet",
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
last = history[-1]
|
|
63
|
+
prev = history[-2] if len(history) >= 2 else None
|
|
64
|
+
|
|
65
|
+
hard_gates, action, verdict, pending_review, fidelity = _routing_state(last)
|
|
66
|
+
|
|
67
|
+
# 2. HARD GATE — a Divine Eye hard failure needs code correction.
|
|
68
|
+
if hard_gates:
|
|
69
|
+
return {
|
|
70
|
+
"stop": True,
|
|
71
|
+
"action": "refine-code",
|
|
72
|
+
"reason": f"hard gate failure: {hard_gates[0]}",
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
# 3. PENDING REVIEW — preserve the Divine Eye evaluator's non-continue routing.
|
|
76
|
+
if pending_review:
|
|
77
|
+
route = action if action in ("refine-code", "refine-spec") else "request-input"
|
|
78
|
+
return {
|
|
79
|
+
"stop": True,
|
|
80
|
+
"action": route,
|
|
81
|
+
"reason": f"pending Divine Eye review: {action or verdict}",
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# 4. SUCCESS — target met and no open defects.
|
|
85
|
+
if fidelity >= target_fidelity and not last["defectTags"]:
|
|
86
|
+
return {
|
|
87
|
+
"stop": True,
|
|
88
|
+
"action": "continue",
|
|
89
|
+
"reason": "fidelity target met, no open defects",
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# 5. REPEATED_DEFECT — a defect tag survived two consecutive iterations.
|
|
93
|
+
if prev is not None:
|
|
94
|
+
shared = set(last["defectTags"]) & set(prev["defectTags"])
|
|
95
|
+
if shared:
|
|
96
|
+
tag = sorted(shared)[0]
|
|
97
|
+
return {
|
|
98
|
+
"stop": True,
|
|
99
|
+
"action": "refine-spec",
|
|
100
|
+
"reason": f"same defect survived 2 consecutive fixes: {tag}",
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# 6. OSCILLATION — two trailing reverted iterations.
|
|
104
|
+
reverts = 0
|
|
105
|
+
for entry in reversed(history):
|
|
106
|
+
if not entry.get("reverted"):
|
|
107
|
+
break
|
|
108
|
+
reverts += 1
|
|
109
|
+
oscillating = reverts >= 2
|
|
110
|
+
if oscillating:
|
|
111
|
+
return {
|
|
112
|
+
"stop": True,
|
|
113
|
+
"action": "refine-spec",
|
|
114
|
+
"reason": "oscillating/thrashing",
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
# 7. PLATEAU — progress stalled below target.
|
|
118
|
+
if (
|
|
119
|
+
prev is not None
|
|
120
|
+
and (fidelity - _routing_state(prev)[4]) < min_delta
|
|
121
|
+
and fidelity < target_fidelity
|
|
122
|
+
):
|
|
123
|
+
return {
|
|
124
|
+
"stop": True,
|
|
125
|
+
"action": "request-input",
|
|
126
|
+
"reason": "progress plateaued below target (Δ<min_delta)",
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
# 8. HARD_CEILING — non-bypassable termination guarantee.
|
|
130
|
+
if len(history) >= max_iter:
|
|
131
|
+
return {
|
|
132
|
+
"stop": True,
|
|
133
|
+
"action": "request-input",
|
|
134
|
+
"reason": "hit MAX_ITER ceiling",
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# 9. Otherwise — keep going.
|
|
138
|
+
return {
|
|
139
|
+
"stop": False,
|
|
140
|
+
"action": "continue-iterating",
|
|
141
|
+
"reason": "still improving toward target",
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def budget_exceeded(spent_tokens, budget):
|
|
146
|
+
"""§3.6 budget circuit-breaker.
|
|
147
|
+
|
|
148
|
+
Returns True when the token budget is spent. The caller uses this to
|
|
149
|
+
HALT-and-ask-the-user; it never silently continues.
|
|
150
|
+
"""
|
|
151
|
+
if not _is_finite_number(spent_tokens) or spent_tokens < 0:
|
|
152
|
+
raise ValueError("spent_tokens must be a finite non-negative number")
|
|
153
|
+
if isinstance(budget, bool) or not isinstance(budget, int) or budget < 0:
|
|
154
|
+
raise ValueError("budget must be a non-negative integer")
|
|
155
|
+
return spent_tokens >= budget
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _validate_history(history):
|
|
159
|
+
if not isinstance(history, list):
|
|
160
|
+
raise ValueError("history must be a JSON list")
|
|
161
|
+
for index, entry in enumerate(history):
|
|
162
|
+
if not isinstance(entry, dict):
|
|
163
|
+
raise ValueError(f"history[{index}] must be an object")
|
|
164
|
+
fidelity = entry.get("fidelity")
|
|
165
|
+
if isinstance(fidelity, bool) or not isinstance(fidelity, int | float) or not math.isfinite(fidelity) or not 0.0 <= fidelity <= 1.0:
|
|
166
|
+
raise ValueError(f"history[{index}].fidelity must be a finite number in [0, 1]")
|
|
167
|
+
_validate_tags(entry.get("defectTags"), f"history[{index}].defectTags")
|
|
168
|
+
_routing_state(entry, index)
|
|
169
|
+
if not isinstance(entry.get("reverted"), bool):
|
|
170
|
+
raise ValueError(f"history[{index}].reverted must be a boolean")
|
|
171
|
+
return history
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _validate_tags(tags, field):
|
|
175
|
+
if not isinstance(tags, list) or not all(isinstance(tag, str) for tag in tags):
|
|
176
|
+
raise ValueError(f"{field} must be a list of strings")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _routing_state(entry, index=None):
|
|
180
|
+
prefix = f"history[{index}]" if index is not None else "history entry"
|
|
181
|
+
if "pendingReview" in entry and not isinstance(entry["pendingReview"], bool):
|
|
182
|
+
raise ValueError(f"{prefix}.pendingReview must be a boolean")
|
|
183
|
+
provenance = entry.get("divineEye")
|
|
184
|
+
if provenance is not None and not isinstance(provenance, dict):
|
|
185
|
+
raise ValueError(f"{prefix}.divineEye must be an object")
|
|
186
|
+
source = provenance if provenance is not None else entry
|
|
187
|
+
fidelity = source.get("fidelity") if provenance is not None else entry.get("fidelity")
|
|
188
|
+
if isinstance(fidelity, bool) or not isinstance(fidelity, int | float) or not math.isfinite(fidelity) or not 0.0 <= fidelity <= 1.0:
|
|
189
|
+
raise ValueError(f"{prefix}.divineEye.fidelity must be a finite number in [0, 1]")
|
|
190
|
+
if provenance is not None and entry["fidelity"] != fidelity:
|
|
191
|
+
raise ValueError(f"{prefix}.fidelity conflicts with divineEye provenance")
|
|
192
|
+
hard_gates = source.get("hardGateFailures", [])
|
|
193
|
+
_validate_tags(hard_gates, f"{prefix}.hardGateFailures")
|
|
194
|
+
action = source.get("action") if provenance is not None else entry.get("divineEyeAction")
|
|
195
|
+
verdict = source.get("verdict") if provenance is not None else entry.get("divineEyeVerdict")
|
|
196
|
+
if action is not None and not isinstance(action, str):
|
|
197
|
+
raise ValueError(f"{prefix}.divineEyeAction must be a string")
|
|
198
|
+
if verdict is not None and not isinstance(verdict, str):
|
|
199
|
+
raise ValueError(f"{prefix}.divineEyeVerdict must be a string")
|
|
200
|
+
pending_review = bool(entry.get("pendingReview", False)) or action not in (None, "continue") or verdict not in (None, "pass") or bool(hard_gates)
|
|
201
|
+
if provenance is not None:
|
|
202
|
+
expected = {"hardGateFailures": hard_gates, "divineEyeAction": action, "divineEyeVerdict": verdict, "pendingReview": pending_review}
|
|
203
|
+
for key, value in expected.items():
|
|
204
|
+
if key in entry and entry[key] != value:
|
|
205
|
+
raise ValueError(f"{prefix}.{key} conflicts with divineEye provenance")
|
|
206
|
+
return hard_gates, action, verdict, pending_review, fidelity
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _validate_config(target_fidelity, max_iter, min_delta):
|
|
210
|
+
if not _is_finite_number(target_fidelity) or not 0.0 <= target_fidelity <= 1.0:
|
|
211
|
+
raise ValueError("target_fidelity must be a finite number in [0, 1]")
|
|
212
|
+
if isinstance(max_iter, bool) or not isinstance(max_iter, int) or max_iter <= 0:
|
|
213
|
+
raise ValueError("max_iter must be a positive integer")
|
|
214
|
+
if not _is_finite_number(min_delta) or min_delta < 0.0:
|
|
215
|
+
raise ValueError("min_delta must be finite and non-negative")
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _is_finite_number(value):
|
|
219
|
+
return not isinstance(value, bool) and isinstance(value, int | float) and math.isfinite(value)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def main(argv):
|
|
223
|
+
parser = argparse.ArgumentParser(
|
|
224
|
+
description="Bounded correction-loop stop policy (§3.6)."
|
|
225
|
+
)
|
|
226
|
+
parser.add_argument("--history", required=True, help="path to JSON list of iterations")
|
|
227
|
+
parser.add_argument("--target", type=float, default=0.85, help="target fidelity")
|
|
228
|
+
parser.add_argument("--max-iter", type=int, default=6, help="hard iteration ceiling")
|
|
229
|
+
parser.add_argument("--min-delta", type=float, default=0.02, help="plateau threshold")
|
|
230
|
+
parser.add_argument("--json", action="store_true", help="emit decision as JSON")
|
|
231
|
+
|
|
232
|
+
try:
|
|
233
|
+
args = parser.parse_args(argv)
|
|
234
|
+
with open(args.history, "r", encoding="utf-8") as fh:
|
|
235
|
+
history = json.load(fh)
|
|
236
|
+
|
|
237
|
+
decision = decide(
|
|
238
|
+
history,
|
|
239
|
+
target_fidelity=args.target,
|
|
240
|
+
max_iter=args.max_iter,
|
|
241
|
+
min_delta=args.min_delta,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
if args.json:
|
|
245
|
+
print(json.dumps(decision))
|
|
246
|
+
else:
|
|
247
|
+
print(
|
|
248
|
+
f"stop={decision['stop']} action={decision['action']} "
|
|
249
|
+
f"reason={decision['reason']}"
|
|
250
|
+
)
|
|
251
|
+
return 0 if not decision["stop"] else 1
|
|
252
|
+
except Exception as exc: # noqa: BLE001 - CLI boundary, surface any failure
|
|
253
|
+
print(f"error: {exc}")
|
|
254
|
+
return 2
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
if __name__ == "__main__":
|
|
258
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
REQUIRED_SCENE_KEYS = {
|
|
12
|
+
"version",
|
|
13
|
+
"fixtureId",
|
|
14
|
+
"reference",
|
|
15
|
+
"identity",
|
|
16
|
+
"camera",
|
|
17
|
+
"transform",
|
|
18
|
+
"environment",
|
|
19
|
+
"resolution",
|
|
20
|
+
"background",
|
|
21
|
+
"rendererVersion",
|
|
22
|
+
"calibration",
|
|
23
|
+
"thresholds",
|
|
24
|
+
}
|
|
25
|
+
REQUIRED_THRESHOLDS = {
|
|
26
|
+
"silhouetteIoU",
|
|
27
|
+
"aspectRatioDelta",
|
|
28
|
+
"scaleDelta",
|
|
29
|
+
"projectionCoverage",
|
|
30
|
+
"finishMaterialResponse",
|
|
31
|
+
"identityDetail",
|
|
32
|
+
"paintedRegion",
|
|
33
|
+
"maxOrbitCollapseRatio",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def load_review_scene(path: Path) -> dict[str, Any]:
|
|
38
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
39
|
+
if not isinstance(payload, dict):
|
|
40
|
+
raise ValueError("review scene must be a JSON object")
|
|
41
|
+
missing = REQUIRED_SCENE_KEYS - payload.keys()
|
|
42
|
+
if missing:
|
|
43
|
+
raise ValueError("review scene is missing: " + ", ".join(sorted(missing)))
|
|
44
|
+
thresholds = payload.get("thresholds")
|
|
45
|
+
if not isinstance(thresholds, dict) or not REQUIRED_THRESHOLDS.issubset(thresholds):
|
|
46
|
+
raise ValueError("review scene thresholds are incomplete")
|
|
47
|
+
if payload.get("version") != 1:
|
|
48
|
+
raise ValueError("unsupported review scene version")
|
|
49
|
+
return payload
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _number(value: Any) -> bool:
|
|
53
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _failed_threshold(metrics: dict[str, Any], key: str, threshold: float, *, maximum: bool) -> bool:
|
|
57
|
+
value = metrics.get(key)
|
|
58
|
+
if not _number(value):
|
|
59
|
+
return True
|
|
60
|
+
return float(value) > threshold if maximum else float(value) < threshold
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _region_results(inputs: dict[str, Any], threshold: float) -> tuple[list[dict[str, Any]], list[str]]:
|
|
64
|
+
raw = inputs.get("paintedRegions", [])
|
|
65
|
+
if not isinstance(raw, list):
|
|
66
|
+
return [], ["painted-regions-invalid"]
|
|
67
|
+
results: list[dict[str, Any]] = []
|
|
68
|
+
failures: list[str] = []
|
|
69
|
+
for region in raw:
|
|
70
|
+
if not isinstance(region, dict) or not isinstance(region.get("id"), str):
|
|
71
|
+
failures.append("painted-region-invalid")
|
|
72
|
+
continue
|
|
73
|
+
score = region.get("score")
|
|
74
|
+
confidence = region.get("confidence")
|
|
75
|
+
result = {"id": region["id"], "score": score, "confidence": confidence}
|
|
76
|
+
results.append(result)
|
|
77
|
+
if not _number(score) or float(score) < threshold:
|
|
78
|
+
failures.append(f"painted-region:{region['id']}")
|
|
79
|
+
if not _number(confidence):
|
|
80
|
+
failures.append(f"painted-region-confidence:{region['id']}")
|
|
81
|
+
return results, failures
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _critical_feature_failures(inputs: dict[str, Any], default_threshold: float) -> list[str]:
|
|
85
|
+
raw = inputs.get("criticalFeatures", [])
|
|
86
|
+
if not isinstance(raw, list):
|
|
87
|
+
return ["critical-features-invalid"]
|
|
88
|
+
failures: list[str] = []
|
|
89
|
+
for feature in raw:
|
|
90
|
+
if not isinstance(feature, dict) or not isinstance(feature.get("id"), str):
|
|
91
|
+
failures.append("critical-feature-invalid")
|
|
92
|
+
continue
|
|
93
|
+
threshold = feature.get("threshold", default_threshold)
|
|
94
|
+
if not _number(feature.get("score")) or not _number(threshold):
|
|
95
|
+
failures.append(f"critical-feature:{feature['id']}")
|
|
96
|
+
elif float(feature["score"]) < float(threshold):
|
|
97
|
+
failures.append(f"critical-feature:{feature['id']}")
|
|
98
|
+
return failures
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def evaluate_knife_review(
|
|
102
|
+
manifest: dict[str, Any],
|
|
103
|
+
inputs: dict[str, Any],
|
|
104
|
+
review_scene: dict[str, Any],
|
|
105
|
+
) -> dict[str, Any]:
|
|
106
|
+
thresholds = review_scene["thresholds"]
|
|
107
|
+
failed: list[str] = []
|
|
108
|
+
family = manifest.get("itemFamily")
|
|
109
|
+
if family != "knife":
|
|
110
|
+
failed.append(f"unsupported-family:{family or 'missing'}")
|
|
111
|
+
if manifest.get("componentAdapter") != "cs2-knife-v1":
|
|
112
|
+
failed.append("knife-adapter-missing")
|
|
113
|
+
if manifest.get("state") != "proceed":
|
|
114
|
+
failed.append(f"manifest-state:{manifest.get('state', 'missing')}")
|
|
115
|
+
|
|
116
|
+
for key in ("silhouetteIoU", "aspectRatioDelta", "scaleDelta"):
|
|
117
|
+
maximum = key != "silhouetteIoU"
|
|
118
|
+
if _failed_threshold(inputs, key, float(thresholds[key]), maximum=maximum):
|
|
119
|
+
failed.append(key)
|
|
120
|
+
for key in ("finishMaterialResponse", "identityDetail"):
|
|
121
|
+
if _failed_threshold(inputs, key, float(thresholds[key]), maximum=False):
|
|
122
|
+
failed.append(key)
|
|
123
|
+
|
|
124
|
+
region_results, region_failures = _region_results(inputs, float(thresholds["paintedRegion"]))
|
|
125
|
+
failed.extend(region_failures)
|
|
126
|
+
failed.extend(_critical_feature_failures(inputs, float(thresholds["identityDetail"])))
|
|
127
|
+
|
|
128
|
+
projection = inputs.get("projection")
|
|
129
|
+
if manifest.get("route") == "reference-projection":
|
|
130
|
+
if not isinstance(projection, dict) or projection.get("required") is not True:
|
|
131
|
+
failed.append("projection-evidence-missing")
|
|
132
|
+
elif _failed_threshold(projection, "coverage", float(thresholds["projectionCoverage"]), maximum=False):
|
|
133
|
+
failed.append("projection-coverage")
|
|
134
|
+
|
|
135
|
+
multi_angle = inputs.get("multiAngle")
|
|
136
|
+
if not isinstance(multi_angle, dict) or multi_angle.get("degenerate") is True:
|
|
137
|
+
failed.append("degenerate-orbit")
|
|
138
|
+
elif len(multi_angle.get("angles", [])) < 2:
|
|
139
|
+
failed.append("orbit-coverage-missing")
|
|
140
|
+
|
|
141
|
+
notes = manifest.get("approximationNotes", inputs.get("approximationNotes", []))
|
|
142
|
+
approximation_notes = [str(note) for note in notes] if isinstance(notes, list) else []
|
|
143
|
+
hidden_confidence = manifest.get("confidence", {}).get("hiddenRegions")
|
|
144
|
+
report = {
|
|
145
|
+
"verdict": "pass" if not failed else "reject",
|
|
146
|
+
"action": "continue" if not failed else ("request-input" if any(
|
|
147
|
+
item.startswith(("unsupported-family", "manifest-state", "projection-evidence", "orbit-coverage"))
|
|
148
|
+
for item in failed
|
|
149
|
+
) else "refine-code"),
|
|
150
|
+
"family": family,
|
|
151
|
+
"subtype": manifest.get("subtype"),
|
|
152
|
+
"exactnessTier": manifest.get("exactnessTier"),
|
|
153
|
+
"route": manifest.get("route"),
|
|
154
|
+
"reviewScene": {
|
|
155
|
+
"version": review_scene["version"],
|
|
156
|
+
"fixtureId": review_scene["fixtureId"],
|
|
157
|
+
"camera": review_scene["camera"],
|
|
158
|
+
"transform": review_scene["transform"],
|
|
159
|
+
"environment": review_scene["environment"],
|
|
160
|
+
"resolution": review_scene["resolution"],
|
|
161
|
+
"background": review_scene["background"],
|
|
162
|
+
"rendererVersion": review_scene["rendererVersion"],
|
|
163
|
+
"calibration": review_scene["calibration"],
|
|
164
|
+
},
|
|
165
|
+
"metrics": inputs,
|
|
166
|
+
"paintedRegions": region_results,
|
|
167
|
+
"perRegionConfidence": {region["id"]: region["confidence"] for region in region_results},
|
|
168
|
+
"hiddenRegionConfidence": hidden_confidence,
|
|
169
|
+
"approximationNotes": approximation_notes,
|
|
170
|
+
"failedGates": failed,
|
|
171
|
+
}
|
|
172
|
+
return report
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _load_object(path: Path, label: str) -> dict[str, Any]:
|
|
176
|
+
payload = json.loads(path.expanduser().read_text(encoding="utf-8"))
|
|
177
|
+
if not isinstance(payload, dict):
|
|
178
|
+
raise ValueError(f"{label} must be a JSON object")
|
|
179
|
+
return payload
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _write_json_atomic(path: Path, payload: dict[str, Any]) -> None:
|
|
183
|
+
target = path.expanduser().resolve()
|
|
184
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
185
|
+
handle, temporary = tempfile.mkstemp(prefix=f".{target.name}.", suffix=".tmp", dir=target.parent)
|
|
186
|
+
try:
|
|
187
|
+
with os.fdopen(handle, "w", encoding="utf-8") as stream:
|
|
188
|
+
json.dump(payload, stream, indent=2, ensure_ascii=False)
|
|
189
|
+
stream.write("\n")
|
|
190
|
+
stream.flush()
|
|
191
|
+
os.fsync(stream.fileno())
|
|
192
|
+
os.replace(temporary, target)
|
|
193
|
+
finally:
|
|
194
|
+
if os.path.exists(temporary):
|
|
195
|
+
os.unlink(temporary)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def main(argv: list[str] | None = None) -> int:
|
|
199
|
+
parser = argparse.ArgumentParser(description="Evaluate the blocking CS2 knife review contract")
|
|
200
|
+
parser.add_argument("--manifest", type=Path, required=True, help="validated cs2-intake.json")
|
|
201
|
+
parser.add_argument("--metrics", type=Path, required=True, help="render/review metrics JSON")
|
|
202
|
+
parser.add_argument(
|
|
203
|
+
"--scene",
|
|
204
|
+
type=Path,
|
|
205
|
+
default=Path("forge/tests/fixtures/knife_review_scene.json"),
|
|
206
|
+
help="versioned review scene fixture",
|
|
207
|
+
)
|
|
208
|
+
parser.add_argument("--out", type=Path, required=True, help="output review report JSON")
|
|
209
|
+
args = parser.parse_args(argv)
|
|
210
|
+
try:
|
|
211
|
+
manifest = _load_object(args.manifest, "manifest")
|
|
212
|
+
metrics = _load_object(args.metrics, "metrics")
|
|
213
|
+
scene = load_review_scene(args.scene.expanduser())
|
|
214
|
+
report = evaluate_knife_review(manifest, metrics, scene)
|
|
215
|
+
_write_json_atomic(args.out, report)
|
|
216
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
217
|
+
return 0 if report["verdict"] == "pass" else 1
|
|
218
|
+
except (OSError, ValueError, json.JSONDecodeError) as error:
|
|
219
|
+
print(f"error: {error}", file=sys.stderr)
|
|
220
|
+
return 2
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
if __name__ == "__main__":
|
|
224
|
+
raise SystemExit(main())
|