feat(orchestrator): release Match decisions with one passkey, bound to what each card showed
Phase C of 012: the Match overview lists every decided card with flip, edit and back, and one passkey signature releases them all through the inbox. An approved operator command is bound to the payload hash its card showed (match_item in the signed set): the hub refuses a stale snapshot or a changed payload file at release and again before it queues the job. A rejected commit review carries its feedback as a radio call to the card's agent, which the hub verifies and records as the review's rejection. Reject feedback shows line by line, an empty one as such; the arrow keys are in the help; 012 counts every waiting inbox entry in the Tasks badge. Accepted MEDUSA false positives (kvb-think-criticize 2026-11-17): MEDUSA-MM-SCAN-058 signing.py:335 and :337 (pla of plan), EXA010 page-match.js:409 (passkey in a title), EXA006 matching.py:49 (agent then requester_of), STG002 page-constants.js:79 (U+2212 minus as a label). 🎯 Fix: 92 % 💥 Break: 4 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % (style-match.css not covered by MEDUSA, reviewed by hand) 🏆 Score: 88 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e9cd1aeda5
commit
5e00a79fdc
11 files changed
+673
-28
No files matched your search
@@ -6,7 +6,14 @@ import time
|
||||
from .asking import ask_state
|
||||
from .choosing import answer_signed
|
||||
from .cleanup import cleanup_request
|
||||
from .denying import DENIABLE, DENY_KEYS, denial_note, request_status, request_words
|
||||
from .denying import (
|
||||
DENIABLE,
|
||||
DENY_KEYS,
|
||||
NOTED,
|
||||
denial_note,
|
||||
request_status,
|
||||
request_words,
|
||||
)
|
||||
from .errors import Conflict, Missing, ToolError
|
||||
from .fields import decode, expect, field, visible
|
||||
from .firewall import settings_request
|
||||
@@ -46,12 +53,20 @@ def inbox_item(raw: dict, label: str, title: str, gate: str, subject: dict | Non
|
||||
The batch item. A denial of a deniable kind signs its own item and
|
||||
carries the note that tells the requesting agent.
|
||||
"""
|
||||
note = denial_note(raw, requester) if raw["verb"] == "reject" and raw["kind"] in DENIABLE else None
|
||||
note = denial_note(raw, requester) if raw["verb"] == "reject" and "channel" in raw else None
|
||||
signed = subject if raw["verb"] == "approve" else None if note is None else signing.denial_item(subject, note["channel"], note["reason"], note["to"])
|
||||
sha256 = raw["sha256"] if raw["kind"] == "operator" else ""
|
||||
return {"kind": raw["kind"], "id": raw["id"], "verb": raw["verb"], "label": label, "sha256": sha256, "title": shown(title)[:200], "gate": gate, "signed": signed, "note": note}
|
||||
|
||||
|
||||
def signed_of(items: list[dict]) -> list[dict]:
|
||||
"""Returns:
|
||||
Every item the approval of items must list: each item's own signed
|
||||
item and the payload bindings of operator commands.
|
||||
"""
|
||||
return [entry for item in items for entry in ([item["signed"]] if item["signed"] is not None else []) + item.get("bound", [])]
|
||||
|
||||
|
||||
class Approving:
|
||||
def keys(self) -> list[dict]:
|
||||
try:
|
||||
@@ -164,6 +179,8 @@ class Approving:
|
||||
if item["note"] is not None:
|
||||
return self.deny(item, proof)
|
||||
if item["kind"] == "operator":
|
||||
if not all(self.payload_holds(bound) for bound in item.get("bound", [])):
|
||||
return "refused: a payload file changed since the release"
|
||||
return self.queue_job(item, proof)
|
||||
if item["kind"] == "ask":
|
||||
record = self.asks.get(item["id"])
|
||||
@@ -188,7 +205,7 @@ class Approving:
|
||||
Conflict when it is no longer the one the inbox showed the
|
||||
operator, sent back as raw["to"].
|
||||
"""
|
||||
if raw["verb"] != "reject" or raw["kind"] not in DENIABLE:
|
||||
if raw["verb"] != "reject" or "channel" not in raw:
|
||||
return ""
|
||||
name = self.addressee(who)[0]
|
||||
if raw["to"] != name:
|
||||
@@ -214,13 +231,16 @@ class Approving:
|
||||
raise Conflict({"id": row["task"], "status": "changed"})
|
||||
if row["task"] in self.open_jobs():
|
||||
raise Conflict({"id": row["task"], "status": "queued"})
|
||||
return inbox_item(raw, "", row["command"], "", operator_signed(row), self.requester(raw, adder(tasks[row["task"]])))
|
||||
bound = self.payload_bound(row, raw["payload"]) if "payload" in raw else []
|
||||
return {**inbox_item(raw, "", row["command"], "", operator_signed(row), self.requester(raw, adder(tasks[row["task"]]))), "bound": bound}
|
||||
|
||||
def item_of(self, raw: object, tasks: dict[str, dict]) -> dict:
|
||||
if not isinstance(raw, dict):
|
||||
raise ToolError("every item must be an object with kind, id, verb, label and sha256, and a denial also channel, reason and to")
|
||||
kind_name, verb = raw.get("kind"), raw.get("verb")
|
||||
expect(raw, (*ITEM_KEYS, *DENY_KEYS) if verb == "reject" and kind_name in DENIABLE else ITEM_KEYS)
|
||||
noted = verb == "reject" and (kind_name in DENIABLE or kind_name in NOTED and "channel" in raw)
|
||||
shown = ("payload",) if kind_name == "operator" and verb == "approve" and "payload" in raw else ()
|
||||
expect(raw, (*ITEM_KEYS, *DENY_KEYS) if noted else (*ITEM_KEYS, *shown))
|
||||
if kind_name not in INBOX_KINDS or verb not in VERBS or not isinstance(raw["label"], str) or not isinstance(raw["sha256"], str):
|
||||
raise ToolError(f"kind must be one of {', '.join(INBOX_KINDS)}, verb approve or reject, label and sha256 text")
|
||||
if kind_name == "operator":
|
||||
@@ -243,7 +263,7 @@ class Approving:
|
||||
return inbox_item(raw, "", f"Rule {request_words(record)}", "", request_signed(record), self.requester(raw, record["agent"]))
|
||||
title = {"review": record.get("title"), "ask": f"{record.get('tool')} {record.get('command')}", "decision": record.get("question")}[kind_name]
|
||||
subject = {"review": review_signed, "ask": ask_signed}[kind_name](record) if kind_name != "decision" else answer_signed(record, label)
|
||||
return inbox_item(raw, label, title, record.get("gate", ""), subject, self.requester(raw, record["session"] if kind_name == "ask" else ""))
|
||||
return inbox_item(raw, label, title, record.get("gate", ""), subject, self.requester(raw, record["session"] if kind_name == "ask" else record.get("agent", "")))
|
||||
|
||||
def checked(self, raw: object) -> list[dict]:
|
||||
if not isinstance(raw, list) or not 1 <= len(raw) <= BATCH_LIMIT:
|
||||
@@ -277,14 +297,14 @@ class Approving:
|
||||
signed = self.enable_items(raw)
|
||||
return {**self.challenge_for(signed), "enables": signed[0]["rule"]}
|
||||
else:
|
||||
signed = [item["signed"] for item in self.checked(raw) if item["signed"] is not None]
|
||||
signed = signed_of(self.checked(raw))
|
||||
return self.challenge_for(signed)
|
||||
|
||||
def approve(self, body: bytes) -> dict:
|
||||
payload = decode(body)
|
||||
expect(payload, ("items", "proof"))
|
||||
items = self.checked(payload["items"])
|
||||
proof = self.covered(payload["proof"], [item["signed"] for item in items if item["signed"] is not None], time.time())
|
||||
proof = self.covered(payload["proof"], signed_of(items), time.time())
|
||||
return self.batches.add(items, "operator", proof, self.apply)
|
||||
|
||||
def undo(self, batch_id: str) -> dict:
|
||||
|
||||
@@ -11,6 +11,7 @@ from .signed import operator_signed, signing
|
||||
from .skill_scripts import RASCI
|
||||
|
||||
DENIABLE = ("ask", "operator", "rule")
|
||||
NOTED = ("review",)
|
||||
DENY_KEYS = ("channel", "reason", "to")
|
||||
DENY_CHANNELS = {**DIRECT, **{name: words for name, words in TO_ALL.items() if name != "mayday"}}
|
||||
REASON_LIMIT = 2000
|
||||
@@ -84,6 +85,14 @@ class Denying:
|
||||
return f"failed: {run['command']} → {run['code']}"
|
||||
command, directory = row["command"][:200], row["directory"]
|
||||
return f"stopped · {self.tell(item, proof, adder(tasks[item['id']]), f'operator command {command} in {directory}')}"
|
||||
if item["kind"] == "review":
|
||||
record, changed = self.reviews.decide(item["id"], {"status": "rejected", "proof": proof, **note})
|
||||
if record is None:
|
||||
return "unknown"
|
||||
if not changed:
|
||||
return f"already {record['status']}"
|
||||
title, branch = record["title"][:200], record["branch"]
|
||||
return f"rejected · {self.tell(item, proof, record.get('agent', ''), f'commit {title} on {branch}')}"
|
||||
ledger = self.asks if item["kind"] == "ask" else self.rule_requests
|
||||
record = ledger.get(item["id"])
|
||||
if record is None:
|
||||
|
||||
@@ -3,8 +3,9 @@ from __future__ import annotations
|
||||
import time
|
||||
|
||||
from .council import read_claims
|
||||
from .denying import requester_of
|
||||
from .diffs import stored_diff
|
||||
from .errors import Missing, ToolError
|
||||
from .errors import Conflict, Missing, ToolError
|
||||
from .fields import decode, expect, field
|
||||
from .payloads import denied_roots, payload_files, payload_hash
|
||||
from .records import digest, iso_epoch
|
||||
@@ -45,7 +46,7 @@ class Matching:
|
||||
claims = read_claims(self.council)
|
||||
names = self.names.listed()
|
||||
reviews = self.reviews.pending()
|
||||
cards = [self.commit_card(review, reviews, born_of(review.get("agent", ""), names, claims)) for review in reviews]
|
||||
cards = [{**self.commit_card(review, reviews, born_of(review.get("agent", ""), names, claims)), "to": requester_of(claims, review.get("agent", ""))[0]} for review in reviews]
|
||||
tasks = read_register(self.council / REGISTER)
|
||||
held = self.open_jobs()
|
||||
rows = [row for row in operator_rows(tasks) if row["check"] != "decision" and row["task"] not in held]
|
||||
@@ -53,7 +54,7 @@ class Matching:
|
||||
scan = self.tree.get()
|
||||
for row in rows:
|
||||
agent = adder(tasks[row["task"]])
|
||||
cards.append(self.command_card(row, agent, born_of(agent, names, claims), roots, scan))
|
||||
cards.append({**self.command_card(row, agent, born_of(agent, names, claims), roots, scan), "to": requester_of(claims, agent)[0]})
|
||||
listed = {card["id"] for card in cards}
|
||||
for snapshot in self.match_snapshots.listed():
|
||||
if snapshot["id"] not in listed:
|
||||
@@ -92,6 +93,35 @@ class Matching:
|
||||
"reason": row["why"], "sha256": digest(row["command"]),
|
||||
}
|
||||
|
||||
def live_payload(self, row: dict) -> str:
|
||||
files = payload_files(row["command"], row["directory"], denied_roots(self.settings_files()[0]))
|
||||
return payload_hash(row["command"], row["directory"], files)
|
||||
|
||||
def payload_bound(self, row: dict, shown: object) -> list[dict]:
|
||||
"""Args:
|
||||
row: the open operator row a Match release approves.
|
||||
shown: the payload hash its card showed the operator.
|
||||
|
||||
Returns:
|
||||
The match item binding the approval to that hash.
|
||||
|
||||
Raises:
|
||||
ToolError for a hash that is no hex digest; Conflict when the
|
||||
card's snapshot is gone or retaken, or a payload file changed
|
||||
since the card showed it.
|
||||
"""
|
||||
if not isinstance(shown, str) or not signing.HASH.fullmatch(shown):
|
||||
raise ToolError("payload must be the hash the card showed")
|
||||
snapshot = self.match_snapshots.get(f"operator:{row['task']}")
|
||||
if snapshot is None or snapshot["command_sha256"] != digest(row["command"]) or snapshot["hash"] != shown or self.live_payload(row) != shown:
|
||||
raise Conflict({"id": row["task"], "status": "stale"})
|
||||
return [signing.match_item(f"operator:{row['task']}", shown)]
|
||||
|
||||
def payload_holds(self, bound: dict) -> bool:
|
||||
task = bound["id"].removeprefix("operator:")
|
||||
row = next((row for row in operator_rows(read_register(self.council / REGISTER)) if row["task"] == task), None)
|
||||
return row is not None and self.live_payload(row) == bound["hash"]
|
||||
|
||||
def match_stale(self, body: bytes) -> dict:
|
||||
"""Args:
|
||||
body: {"id", "tree"}: a pending review and the tree git
|
||||
|
||||
Reference in new issue
Block a user