Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- app.py +57 -28
- frontend/index.html +13 -0
app.py
CHANGED
|
@@ -632,25 +632,41 @@ async def ws_stream(ws: WebSocket):
|
|
| 632 |
|
| 633 |
force = bool(msg.get("force", False))
|
| 634 |
if force or (qvd > state.qvd_threshold and novelty > 0.1):
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
state.
|
| 638 |
-
state
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
print(f"[WS] Patch generated: session={state.session_id} hash={result['patch_hash'][:16]} qvd={round(qvd,3)}", flush=True)
|
| 644 |
-
|
| 645 |
await ws.send_json({
|
| 646 |
-
"type": "
|
| 647 |
-
"
|
| 648 |
-
"
|
| 649 |
-
"
|
| 650 |
"qvd": round(qvd, 4),
|
| 651 |
})
|
| 652 |
-
|
| 653 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
|
| 655 |
# Send QVD update
|
| 656 |
await ws.send_json({
|
|
@@ -692,19 +708,32 @@ async def ws_stream(ws: WebSocket):
|
|
| 692 |
state.observer_state = observation
|
| 693 |
state.last_observer_ts = time.time()
|
| 694 |
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
|
| 709 |
elif msg_type == "state":
|
| 710 |
await ws.send_json({
|
|
|
|
| 632 |
|
| 633 |
force = bool(msg.get("force", False))
|
| 634 |
if force or (qvd > state.qvd_threshold and novelty > 0.1):
|
| 635 |
+
# βββ Evidence Gate: check if sufficient intent exists βββ
|
| 636 |
+
ev_result = evidence_gate(
|
| 637 |
+
(state.observer_state or {}).get("observer_output", ""),
|
| 638 |
+
compress_state(state),
|
| 639 |
+
)
|
| 640 |
+
log_gate_decision("evidence_gate", ev_result, patch_hash="")
|
| 641 |
+
if not ev_result.passed:
|
| 642 |
+
print(f"[WS] Evidence Gate blocked: session={state.session_id} reason={ev_result.reason[:60]}", flush=True)
|
|
|
|
|
|
|
| 643 |
await ws.send_json({
|
| 644 |
+
"type": "gate_block",
|
| 645 |
+
"gate": "evidence_gate",
|
| 646 |
+
"reason": ev_result.reason,
|
| 647 |
+
"evidence_type": ev_result.evidence_type,
|
| 648 |
"qvd": round(qvd, 4),
|
| 649 |
})
|
| 650 |
+
else:
|
| 651 |
+
try:
|
| 652 |
+
result = build(state, state.observer_state or {})
|
| 653 |
+
state.current_artifact = result["patch_output"]
|
| 654 |
+
state.last_patch_hash = result["patch_hash"]
|
| 655 |
+
state.last_builder_ts = time.time()
|
| 656 |
+
state.receipt_count += 1
|
| 657 |
+
|
| 658 |
+
save_receipt(result["receipt"])
|
| 659 |
+
print(f"[WS] Patch generated: session={state.session_id} hash={result['patch_hash'][:16]} qvd={round(qvd,3)}", flush=True)
|
| 660 |
+
|
| 661 |
+
await ws.send_json({
|
| 662 |
+
"type": "patch",
|
| 663 |
+
"output": result["patch_output"],
|
| 664 |
+
"patch_hash": result["patch_hash"],
|
| 665 |
+
"receipt": result["receipt"],
|
| 666 |
+
"qvd": round(qvd, 4),
|
| 667 |
+
})
|
| 668 |
+
except Exception as e:
|
| 669 |
+
await ws.send_json({"type": "error", "stage": "builder", "message": str(e)})
|
| 670 |
|
| 671 |
# Send QVD update
|
| 672 |
await ws.send_json({
|
|
|
|
| 708 |
state.observer_state = observation
|
| 709 |
state.last_observer_ts = time.time()
|
| 710 |
|
| 711 |
+
# βββ Evidence Gate: check if sufficient intent exists βββ
|
| 712 |
+
ev_result = evidence_gate(observation.get("observer_output", ""), compact)
|
| 713 |
+
log_gate_decision("evidence_gate", ev_result, patch_hash="")
|
| 714 |
+
if not ev_result.passed:
|
| 715 |
+
print(f"[WS] Evidence Gate blocked (synthesize): session={state.session_id} reason={ev_result.reason[:60]}", flush=True)
|
| 716 |
+
await ws.send_json({
|
| 717 |
+
"type": "gate_block",
|
| 718 |
+
"gate": "evidence_gate",
|
| 719 |
+
"reason": ev_result.reason,
|
| 720 |
+
"evidence_type": ev_result.evidence_type,
|
| 721 |
+
})
|
| 722 |
+
else:
|
| 723 |
+
result = build(state, observation)
|
| 724 |
+
state.current_artifact = result["patch_output"]
|
| 725 |
+
state.last_patch_hash = result["patch_hash"]
|
| 726 |
+
state.last_builder_ts = time.time()
|
| 727 |
+
state.receipt_count += 1
|
| 728 |
+
save_receipt(result["receipt"])
|
| 729 |
+
print(f"[WS] Patch generated (synthesize): session={state.session_id} hash={result['patch_hash'][:16]}", flush=True)
|
| 730 |
|
| 731 |
+
await ws.send_json({
|
| 732 |
+
"type": "patch",
|
| 733 |
+
"output": result["patch_output"],
|
| 734 |
+
"patch_hash": result["patch_hash"],
|
| 735 |
+
"receipt": result["receipt"],
|
| 736 |
+
})
|
| 737 |
|
| 738 |
elif msg_type == "state":
|
| 739 |
await ws.send_json({
|
frontend/index.html
CHANGED
|
@@ -1464,6 +1464,19 @@
|
|
| 1464 |
patchStream.innerHTML = '<div class="empty-state" style="color:var(--red)">' + escapeHtml(msg.message) + '</div>';
|
| 1465 |
}
|
| 1466 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1467 |
case "state":
|
| 1468 |
updateSpeakerLedger(msg.state);
|
| 1469 |
break;
|
|
|
|
| 1464 |
patchStream.innerHTML = '<div class="empty-state" style="color:var(--red)">' + escapeHtml(msg.message) + '</div>';
|
| 1465 |
}
|
| 1466 |
break;
|
| 1467 |
+
case "gate_block":
|
| 1468 |
+
const gateDiv = document.createElement("div");
|
| 1469 |
+
gateDiv.className = "patch-entry";
|
| 1470 |
+
gateDiv.style.borderColor = "var(--amber)";
|
| 1471 |
+
gateDiv.innerHTML = '<div class="patch-header" style="color:var(--amber)">\u26d4 Evidence Gate Blocked</div>' +
|
| 1472 |
+
'<div style="padding:12px 16px;font-size:13px;color:var(--text2);line-height:1.6">' +
|
| 1473 |
+
'<strong>Reason:</strong> ' + escapeHtml(msg.reason) + '<br>' +
|
| 1474 |
+
'<strong>Evidence type:</strong> ' + escapeHtml(msg.evidence_type) + '<br>' +
|
| 1475 |
+
'<em style="color:var(--gray);margin-top:8px;display:block">Speak to the camera or show a screen with code to trigger code generation.</em>' +
|
| 1476 |
+
'</div>';
|
| 1477 |
+
patchStream.prepend(gateDiv);
|
| 1478 |
+
setStatus("Evidence Gate: " + msg.evidence_type, "dot-idle");
|
| 1479 |
+
break;
|
| 1480 |
case "state":
|
| 1481 |
updateSpeakerLedger(msg.state);
|
| 1482 |
break;
|