Files
skills/orchestrator/kvb_orchestrator/revealing.py
T
Kevin Veen-BirkenbachandClaude Opus 5.5 af3555e88b feat(orchestrator): reveal withheld diff content under a passkey signature (019)
staged_diff masks only the secret rule hits and seals each masked file's clear patch apart; reviews and asks store the sealed patches next to their diff, delete them once the item leaves pending, and the hub sweeps orphans. POST /api/diffs/<kind>/<id>/reveal/sign and /reveal hand the clear patches to a signed request; page-diff.js offers Reveal per hidden file and Reveal all, keeps the clear text in the page only and forgets it once the item leaves the inbox. Requirement 019, unit, hub and e2e tests.

Accepted MEDUSA false positives (security.py accept after kvb-think-criticize, 2026-11-17): approval.py FTSCAN-231 WEB-SSRF RH005; permission_hook.py MM-SCAN-058 WEB-SSRF RH005; staged_diff.py SAST-ENV-001 AI-BACKDOOR-006 B603; hub.py MEX-SCAN-1167 INF-SCAN-589; page-load.js EXA002; hub_case.py TC001-TC009 INF-SCAN-2057/2206/2440/2457 EXA002 EXA006 PL002 B603 FTSC-SCAN-089.

🎯 Fix: 92 %
💥 Break: 4 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 88
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 19:04:35 +00:00

83 lines
3.9 KiB
Python

from __future__ import annotations
import time
from .asking import ask_state
from .diffs import SEALED_SUFFIX, sealed_file, stored_sealed
from .errors import Conflict, Missing, ToolError
from .fields import decode, expect
from .records import shown
TITLE_LIMIT = 200
PATHS_SHOWN = 2000
def reveal_item(kind_name: str, item_id: str, paths: list[str]) -> dict:
"""Returns:
The item a reveal signs: the sorted paths of one review or ask; its
hash equals no item an executor approves.
"""
return {"kind": "reveal", "target": kind_name, "id": item_id, "paths": paths}
class Revealing:
def sealed_status(self, kind_name: str, item_id: str, now: float) -> tuple[dict | None, str | None]:
record = self.reviews.get(item_id) if kind_name == "review" else self.asks.get(item_id)
if record is None:
return None, None
return record, record["status"] if kind_name == "review" else ask_state(record, now)["status"]
def open_record(self, kind_name: str, item_id: str) -> dict:
"""Returns:
The pending review or ask whose sealed patches a reveal reads.
Raises:
Missing for an unknown item; Conflict once it is decided or
expired, after its sealed file is deleted.
"""
record, status = self.sealed_status(kind_name, item_id, time.time())
if record is None:
raise Missing(item_id)
if status != "pending":
sealed_file(self.reviews.pages, kind_name, item_id).unlink(missing_ok=True)
raise Conflict({"kind": kind_name, "id": item_id, "status": status})
return record
def requested(self, kind_name: str, item_id: str, paths: object) -> tuple[dict, list[str], dict[str, str]]:
record = self.open_record(kind_name, item_id)
if not isinstance(paths, list) or not paths or not all(isinstance(path, str) for path in paths) or len(set(paths)) != len(paths):
raise ToolError("paths must name one or more distinct files")
sealed = stored_sealed(self.reviews.pages, kind_name, item_id)
unsealed = [path for path in paths if path not in sealed]
if unsealed:
raise ToolError(f"nothing sealed to reveal for {shown(unsealed[0])[:TITLE_LIMIT]}")
return record, sorted(paths), sealed
def sign_reveal(self, kind_name: str, item_id: str, body: bytes) -> dict:
payload = decode(body)
expect(payload, ("paths",))
_, paths, _ = self.requested(kind_name, item_id, payload["paths"])
return self.challenge_for([reveal_item(kind_name, item_id, paths)])
def reveal(self, kind_name: str, item_id: str, body: bytes) -> dict:
"""Returns:
The clear patches of exactly the requested paths, once a pinned
passkey signed their reveal_item unexpired and for the first
time; the approval stream records kind, id and paths, never a
patch.
"""
payload = decode(body)
expect(payload, ("paths", "proof"))
record, paths, sealed = self.requested(kind_name, item_id, payload["paths"])
self.operator_proven(payload["proof"], reveal_item(kind_name, item_id, paths))
title = record["title"] if kind_name == "review" else f"{record['tool']}: {record['command']}"
self.log.add({"kind": "approval", "title": f"Reveal {kind_name}: {shown(title)[:TITLE_LIMIT]}", "text": shown(", ".join(paths))[:PATHS_SHOWN], "ref": {"kind": kind_name, "id": item_id, "verb": "reveal", "paths": paths}})
return {"kind": kind_name, "id": item_id, "patches": {path: sealed[path] for path in paths}}
def sweep_sealed(self) -> None:
now = time.time()
for kind_name, suffix in SEALED_SUFFIX.items():
for file in self.reviews.pages.glob(f"*{suffix}"):
if self.sealed_status(kind_name, file.name.removesuffix(suffix), now)[1] != "pending":
file.unlink(missing_ok=True)