File size: 7,929 Bytes
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""Separate basic scene usability from preserved native strict quality evidence.

This is a policy evaluator, not a geometry validator. Use acceptance_evidence to
bind disk artifacts and positively evaluate necessary 0.35 m whole-home access.
Unknown or missing mandatory evidence never becomes a pass.
"""
from __future__ import annotations
import copy

HARD_RULES = frozenset({
    'home_room_unreachable', 'home_door_unreachable', 'entrance_blocked',
    'rooms_not_connected', 'inside_room', 'door_swing_clear',
    'stove_on_counter', 'kitchen_sink_on_counter',
})
# Explicit quality policy: these do not prove a collision or failure of the
# separately tested 0.35 m body route. Authored required inventory remains hard.
SOFT_RULES = frozenset({
    'wardrobe_front_clear', 'wardrobe_back_on_wall', 'counter_front_clear',
    'counter_back_on_wall', 'range_front_clear', 'toilet_front_clear',
    'toilet_back_on_wall', 'bathroom_sink_front_clear', 'bathroom_sink_back_on_wall',
    'shower_front_clear', 'shower_on_wall', 'bed_side_access', 'bed_foot_clear',
    'bed_headboard_on_wall', 'nightstand_beside_bed', 'kitchen_completeness',
    'bathroom_completeness', 'room_content_required', 'room_content_forbidden',
    'duplicate_in_home', 'unreachable', 'door_entry_blocked', 'narrow_path',
    'home_carry_path_blocked', 'occupancy', 'oversized', 'room_sparse',
    'sofa_faces_tv', 'coffee_table_in_front_of_sofa', 'chair_at_table',
    'stove_fridge_separation', 'stove_not_at_counter_end', 'range_in_counter_run',
    'shower_in_corner', 'media_console_not_on_wall', 'television_faces_away',
    'yaw_not_axis_aligned', 'sliver_gap', 'back_sliver_gap', 'unbalanced',
    'window_floor_ratio_low', 'window_blocked_by_furniture', 'window_faces_cooktop',
    'window_missing', 'window_count_low', 'window_sill_height', 'window_ventilation_low',
    'window_sill_unprotected', 'window_glass_not_safety', 'bathroom_window_not_frosted',
})

def _gate(checks, present=True):
    bad = [name for name, value in checks.items() if value is not True]
    return dict(status=('not_evaluated' if not present else 'failed') if bad else 'passed',
                passed=not bad, reasons=bad)

def evaluate_evidence(bundle):
    """Consume explicit evidence; do not mutate native results or source inventory."""
    b=copy.deepcopy(bundle)
    g=b.get('generation') or {}; geo=b.get('geometry') or {}
    st=b.get('structure') or {}; metric=b.get('metric') or {}
    c=b.get('connectivity') or {}; v=b.get('validation') or {}
    rr=b.get('render_receipt') or {}; inv=b.get('inventory') or {}
    conv=b.get('conventions') or {}; bindings=b.get('bindings') or {}
    doors=b.get('door_degradation') or {}
    gates={}
    gates['evidence_integrity']=_gate(dict(no_evidence_errors=not b.get('evidence_errors')))
    gates['geometry']=_gate(dict(
        current_full_geometry=all(g.get(k) is True for k in (
            'geometry_passed','geometry_current','full_geometry_complete','full_geometry_passed',
            'output_contract_passed','inputs_unchanged')),
        native_full_proof=all(geo.get(k) is True for k in (
            'complete','geometry_passed','full_geometry_complete','full_geometry_passed','inputs_unchanged')),
        no_skipped_checks=(g.get('skipped_geometry_checks') == [] and
            geo.get('skipped_checks') == [] and geo.get('full_pending_fields') == [] and
            g.get('geometry_acceptance_scope',{}).get('excluded_contact_entity_ids') == [] and
            g.get('geometry_acceptance_scope',{}).get('excluded_support_pending_fields') == []),
        artifacts_bound=bindings.get('geometry') is True), bool(g and geo))
    gates['saved_structure']=_gate(dict(
        saved_reread_passed=st.get('passed') is True and st.get('failures') == [],
        structural_meshes_present=isinstance(st.get('structural_mesh_count'),int) and st['structural_mesh_count']>0,
        openings_reread=st.get('opening_geometry',{}).get('passed') is True,
        metric_reread=metric.get('passed') is True and metric.get('failures') == [],
        door_degradation_saved_reread=doors.get('passed') is True,
        artifacts_bound=bindings.get('structure') is True), bool(st and metric))
    gates['necessary_access']=_gate(dict(
        positively_evaluated=c.get('evaluated') is True,
        measured_saved_shell=c.get('saved_shell_used') is True,
        body_radius_unchanged=c.get('radius_m') == 0.175,
        entrance_found=c.get('entrance_found') is True,
        entrance_reachable=c.get('entrance_ok') is True,
        all_rooms_reachable=c.get('unreachable_rooms') == [] and c.get('reachable_room_fraction') == 1.0,
        all_doors_reachable=c.get('unreachable_doors') == [],
        room_door_inventory_checked=c.get('inventory_complete') is True,
        artifacts_bound=bindings.get('connectivity') is True), bool(c))
    gates['render_process']=_gate(dict(
        normal_exit=v.get('render_returncode') == 0 and type(v.get('render_returncode')) is int,
        native_completed=v.get('native_render_completed') is True and rr.get('render_completed') is True,
        scene_unchanged=v.get('native_source_unchanged') is True and rr.get('source_unchanged') is True,
        audited_inputs_unchanged=v.get('inputs_and_implementation_unchanged') is True,
        artifacts_bound=bindings.get('render') is True), bool(v and rr))
    gates['required_inventory']=_gate(dict(
        saved_inventory_accounted=inv.get('passed') is True,
        artifacts_bound=bindings.get('inventory') is True), bool(inv))
    findings=conv.get('findings',[])
    critical_missing={'bed','sofa','dining_table','toilet','shower','bathroom_sink','refrigerator','stove','kitchen_counter'}
    def hard_finding(r):
        return r.get('rule') in HARD_RULES or (
            r.get('rule') in {'room_content_required','bathroom_completeness','kitchen_completeness'}
            and r.get('measured',{}).get('missing') in critical_missing)
    hard=[r for r in findings if r.get('severity')=='fail' and hard_finding(r)]
    unknown=[r for r in findings if r.get('rule') not in HARD_RULES|SOFT_RULES or r.get('severity') not in {'fail','warn'}]
    gates['known_hard_layout']=_gate(dict(
        original_audit_bound=bindings.get('conventions') is True,
        no_hard_findings=not hard, all_findings_classified=not unknown), bool(conv) and not unknown)
    basic=all(row['passed'] for row in gates.values())
    return dict(schema='rhg.acceptance-layers.v1', policy='basic-saved-scene-v1',
        basic_success=basic, gates=gates,
        strict_quality=dict(passed=basic and v.get('passed') is True and inv.get('all_targets_fulfilled') is True
            and (b.get('visibility') or {}).get('passed') is True and conv.get('passed') is True
            and doors.get('all_original_doors_installed') is True,
            native_strict_passed=v.get('passed'), visibility_passed=(b.get('visibility') or {}).get('passed'),
            layout_conventions_passed=conv.get('passed'), all_original_targets_fulfilled=inv.get('all_targets_fulfilled'),
            all_original_doors_installed=doors.get('all_original_doors_installed'),
            original_audits_preserved=True),
        door_degradations=doors.get('door_degradations',[]),lost_capabilities=doors.get('lost_capabilities',[]),
        quality_findings=[r for r in findings if r.get('rule') in SOFT_RULES and r not in hard],
        hard_findings=hard, unclassified_findings=unknown, omissions=inv.get('unfilled',{}),
        evidence_errors=b.get('evidence_errors',[]), evidence_references=b.get('references',{}),
        limits=['Basic success is not strict visibility, complete furnishing, physical validation, or robot task success.',
                'Necessary access uses the existing 0.175 m body-radius polygon analysis, not robot motion simulation.',
                'Explicit requirements and unaccounted missing entities remain hard failures.'])