feat(match): merge and commit-tree previews, Match motion and Home tile
The host runner computes a merge preview for each operator row that merges or commits and posts it to the runner-only /api/runner/previews, and an ask of git commit ships the staged commit tree; Match cards show what the merge brings in onto HEAD, or why no preview exists. Cards fly off with their verdict stamp unless reduced motion is set, Match gets its own button in Tasks and a Home tile that keeps the live stack, and the 3D graph and the faces fix land with it. 🎯 Fix: 85 % 💥 Break: 10 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 77 🚦 Gate: ⛔ fix 85 % < 90, break 10 % > 5 Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
96d4d2933c
commit
78f2fec339
19 files changed
+692
-90
No files matched your search
@@ -27,6 +27,7 @@ ENTRY = re.compile(r"/api/stream/([0-9]{1,12})")
|
||||
BOARD = re.compile(r"/api/board/([a-z-]{1,32})")
|
||||
UPLOADS = "/api/uploads"
|
||||
MATCH_ROUTE = "/api/match"
|
||||
PREVIEWS_ROUTE = "/api/runner/previews"
|
||||
MATCH_POSTS = {"/api/match/stale": "match_stale", "/api/match/snapshot": "match_snapshot"}
|
||||
POSTS = ("/api/asks", UPLOADS, "/api/messages", *MATCH_POSTS)
|
||||
STORED = {
|
||||
@@ -147,9 +148,9 @@ class Handler(Exchange):
|
||||
self.answer(hub.view_store.get, HTTPStatus.OK)
|
||||
elif path == "/api/subagents":
|
||||
self.answer(lambda: hub.subagents(self.query()), HTTPStatus.OK)
|
||||
elif path == "/api/runner/jobs":
|
||||
elif path in ("/api/runner/jobs", PREVIEWS_ROUTE):
|
||||
if self.client():
|
||||
self.answer(hub.runner_jobs, HTTPStatus.OK)
|
||||
self.answer(hub.runner_jobs if path == "/api/runner/jobs" else hub.preview_rows, HTTPStatus.OK)
|
||||
else:
|
||||
self.send_text(HTTPStatus.FORBIDDEN, "forbidden: the runner calls with the X-Kvb-Orchestrator header and no origin only")
|
||||
elif entry:
|
||||
@@ -266,7 +267,9 @@ class Handler(Exchange):
|
||||
def runner(self, path: str, body: bytes) -> None:
|
||||
hub = self.server.hub
|
||||
route = RUNNER_ROUTE.fullmatch(path)
|
||||
if route.group(2) == "claim":
|
||||
if route is None:
|
||||
self.answer(lambda: hub.record_preview(body), HTTPStatus.OK)
|
||||
elif route.group(2) == "claim":
|
||||
self.answer(lambda: hub.claim(route.group(1)), HTTPStatus.OK)
|
||||
else:
|
||||
self.answer(lambda: hub.report(route.group(1), body), HTTPStatus.OK)
|
||||
@@ -285,7 +288,7 @@ class Handler(Exchange):
|
||||
return lambda body: self.answer(lambda: receive(body), HTTPStatus.OK if path in MATCH_POSTS else HTTPStatus.CREATED)
|
||||
self.send_text(HTTPStatus.FORBIDDEN, "forbidden: local POST with the X-Kvb-Orchestrator header and no foreign origin only")
|
||||
return None
|
||||
if RUNNER_ROUTE.fullmatch(path):
|
||||
if RUNNER_ROUTE.fullmatch(path) or path == PREVIEWS_ROUTE:
|
||||
if self.client():
|
||||
return lambda body: self.runner(path, body)
|
||||
self.send_text(HTTPStatus.FORBIDDEN, "forbidden: the runner calls with the X-Kvb-Orchestrator header and no origin only")
|
||||
@@ -303,7 +306,7 @@ class Handler(Exchange):
|
||||
|
||||
def do_POST(self) -> None:
|
||||
path = urlsplit(self.path).path
|
||||
length = self.body_length({UPLOADS: UPLOAD_LIMIT, STT_ROUTE: INPUT_LIMIT, VOICE_ROUTE: STT_LIMIT, "/mcp": DIFF_BODY_LIMIT, "/api/asks": DIFF_BODY_LIMIT}.get(path, BODY_LIMIT))
|
||||
length = self.body_length({UPLOADS: UPLOAD_LIMIT, STT_ROUTE: INPUT_LIMIT, VOICE_ROUTE: STT_LIMIT, "/mcp": DIFF_BODY_LIMIT, "/api/asks": DIFF_BODY_LIMIT, PREVIEWS_ROUTE: DIFF_BODY_LIMIT}.get(path, BODY_LIMIT))
|
||||
if length is None:
|
||||
return
|
||||
host = self.host()
|
||||
|
||||
@@ -35,6 +35,7 @@ from .messaging import Messaging
|
||||
from .names import Names
|
||||
from .offices import Offices
|
||||
from .presence import SNAPSHOT
|
||||
from .previewing import Previewing
|
||||
from .queue_order import QUEUE_SCRIPT, QueueOrder
|
||||
from .receipts import (
|
||||
NAMES,
|
||||
@@ -88,7 +89,7 @@ def environment(templates: Path) -> jinja2.Environment:
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Hub(Mcp, Reviewing, Revealing, Asking, Messaging, Choosing, Approving, Denying, Requesting, Cleaning, Offices, Tasking, Gating, Firewall, Inbox, Matching, Rules, Jobs, Sources, Timeline, View, Language):
|
||||
class Hub(Mcp, Reviewing, Revealing, Asking, Messaging, Choosing, Approving, Denying, Requesting, Cleaning, Offices, Tasking, Gating, Firewall, Inbox, Matching, Previewing, Rules, Jobs, Sources, Timeline, View, Language):
|
||||
council: Path
|
||||
pages: Path
|
||||
public_port: int
|
||||
@@ -136,6 +137,7 @@ class Hub(Mcp, Reviewing, Revealing, Asking, Messaging, Choosing, Approving, Den
|
||||
queue_order: QueueOrder
|
||||
view_store: ViewStore
|
||||
match_snapshots: Ledger
|
||||
merge_previews: Ledger
|
||||
live_state: LiveState
|
||||
|
||||
def hosts(self) -> tuple[str, str]:
|
||||
@@ -206,6 +208,7 @@ def open_hub(council: Path, pages: Path, public_port: int, state: Path, host_sta
|
||||
replay=state / "replay" / "messages.json",
|
||||
view_store=ViewStore(state / "view.json"),
|
||||
match_snapshots=Ledger(state / "match.json"),
|
||||
merge_previews=Ledger(state / "previews.json"),
|
||||
live_state=LiveState(live_ttl),
|
||||
rules=Ledger(state / "rules.json"),
|
||||
offers=Offers(),
|
||||
|
||||
@@ -19,12 +19,14 @@ USAGE = 2
|
||||
|
||||
def runner_job(job: dict) -> dict:
|
||||
"""Returns:
|
||||
What the runner claims: an operator command, or a task or gate change
|
||||
with kind and argv; a runner that predates such changes verifies them
|
||||
as an operator command and refuses them.
|
||||
What the runner claims: an operator command, with head when a Match
|
||||
release bound it to a merge preview of that HEAD, or a task or gate
|
||||
change with kind and argv; a runner that predates such changes
|
||||
verifies them as an operator command and refuses them.
|
||||
"""
|
||||
change = {"kind": job["kind"], "argv": job["argv"]} if job.get("kind") in CHANGES else {}
|
||||
return {**{key: job[key] for key in ("id", "task", "command", "directory", "sha256")}, **change, "proof": job.get("proof")}
|
||||
head = {"head": job["head"]} if job.get("head") else {}
|
||||
return {**{key: job[key] for key in ("id", "task", "command", "directory", "sha256")}, **change, **head, "proof": job.get("proof")}
|
||||
|
||||
|
||||
def console_of(job: dict | None) -> dict | None:
|
||||
@@ -60,7 +62,8 @@ class Jobs:
|
||||
return "refused: the row changed since the grant"
|
||||
if item["id"] in self.open_jobs():
|
||||
return "already running"
|
||||
job = {"task": row["task"], "command": row["command"], "directory": row["directory"], "sha256": item["sha256"], "status": "queued", "proof": proof}
|
||||
head = self.previewed_head(row["task"], row["command"]) if item.get("bound") else ""
|
||||
job = {"task": row["task"], "command": row["command"], "directory": row["directory"], "sha256": item["sha256"], "status": "queued", "proof": proof, "head": head}
|
||||
self.jobs.add({**job, "code": None, "output": "", "created_ts": time.time(), "started": None, "finished": None, "dismissed": False})
|
||||
return "handed to the runner"
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from .diffs import stored_diff
|
||||
from .errors import Conflict, Missing, ToolError
|
||||
from .fields import decode, expect, field
|
||||
from .payloads import denied_roots, payload_files, payload_hash
|
||||
from .previewing import merge_hash
|
||||
from .records import digest, iso_epoch
|
||||
from .register import REGISTER, adder, operator_rows, read_register
|
||||
from .scores import metric_chips, score_labels
|
||||
@@ -58,9 +59,10 @@ class Matching:
|
||||
agent = adder(tasks[row["task"]])
|
||||
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:
|
||||
self.match_snapshots.remove(snapshot["id"])
|
||||
for store in (self.match_snapshots, self.merge_previews):
|
||||
for snapshot in store.listed():
|
||||
if snapshot["id"] not in listed:
|
||||
store.remove(snapshot["id"])
|
||||
return {"now": now, "cards": cards}
|
||||
|
||||
def commit_card(self, review: dict, reviews: list[dict], born: float | None, labels: dict | None) -> dict:
|
||||
@@ -79,26 +81,38 @@ class Matching:
|
||||
"stale": bool(reason), "stale_reason": reason, "files": files, "command": "", "directory": review["worktree"], "reason": "",
|
||||
}
|
||||
|
||||
def card_payload(self, row: dict, roots: list[str] | None) -> tuple[list[dict], str, dict | None]:
|
||||
"""Returns:
|
||||
What a command card shows and is bound to: the runner's merge
|
||||
preview diff and merge_hash() for a git merge it previewed, else
|
||||
the named payload files and payload_hash(); and the preview.
|
||||
"""
|
||||
preview = self.preview_of(row)
|
||||
if preview is not None:
|
||||
return preview.get("diff", []), merge_hash(row, preview), preview
|
||||
files = payload_files(row["command"], row["directory"], roots)
|
||||
return files, payload_hash(row["command"], row["directory"], files), None
|
||||
|
||||
def command_card(self, row: dict, agent: str, born: float | None, roots: list[str] | None, scan: dict) -> dict:
|
||||
card_id = f"operator:{row['task']}"
|
||||
files = payload_files(row["command"], row["directory"], roots)
|
||||
live = payload_hash(row["command"], row["directory"], files)
|
||||
files, live, preview = self.card_payload(row, roots)
|
||||
snapshot = self.match_snapshots.get(card_id)
|
||||
if snapshot is None or snapshot["command_sha256"] != digest(row["command"]):
|
||||
if snapshot is None or snapshot["command_sha256"] != digest(row["command"]) or (preview is not None and not snapshot.get("previewed")):
|
||||
self.match_snapshots.remove(card_id)
|
||||
snapshot = self.match_snapshots.insert(card_id, {"command_sha256": digest(row["command"]), "hash": live, "files": files, "taken": time.time()})
|
||||
snapshot = self.match_snapshots.insert(card_id, {"command_sha256": digest(row["command"]), "hash": live, "files": files, "previewed": preview is not None, "taken": time.time()})
|
||||
stale = snapshot["hash"] != live
|
||||
moved = "HEAD or the merge base moved since it was added" if preview is not None else "a payload file changed since it was added"
|
||||
merge = None if preview is None else {key: preview.get(key, "") for key in ("head", "base", "target", "error")}
|
||||
repo, branch, worktree = place_of(row["directory"], scan)
|
||||
return {
|
||||
"id": card_id, "kind": "command", "ref": row["task"], "agent": agent, "born": born, "created_ts": snapshot["taken"], "repo": repo, "branch": branch, "worktree": worktree,
|
||||
"title": row["command"], "score": "", "metrics": [], "gate": "", "hash": snapshot["hash"], "live_hash": live, "stale": stale,
|
||||
"stale_reason": "a payload file changed since it was added" if stale else "", "files": snapshot["files"], "command": row["command"], "directory": row["directory"],
|
||||
"reason": row["why"], "sha256": digest(row["command"]),
|
||||
"stale_reason": moved if stale else "", "files": snapshot["files"], "command": row["command"], "directory": row["directory"],
|
||||
"reason": row["why"], "sha256": digest(row["command"]), "merge": merge,
|
||||
}
|
||||
|
||||
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)
|
||||
return self.card_payload(row, denied_roots(self.settings_files()[0]))[1]
|
||||
|
||||
def payload_bound(self, row: dict, shown: object) -> list[dict]:
|
||||
"""Args:
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
|
||||
from .diffs import valid_diff
|
||||
from .errors import Conflict, Missing, ToolError
|
||||
from .fields import bounded, decode, expect
|
||||
from .records import digest
|
||||
from .register import OPERATOR, REGISTER, operator_rows, read_register
|
||||
from .signed import signing
|
||||
|
||||
OBJECT_ID = re.compile(r"[0-9a-f]{40}|[0-9a-f]{64}")
|
||||
ERROR_LIMIT = 500
|
||||
SHOWN = ("task", "command", "head", "base", "target", "diff")
|
||||
FAILED = ("task", "command", "head", "error")
|
||||
|
||||
|
||||
def card_id(task: str) -> str:
|
||||
return f"operator:{task}"
|
||||
|
||||
|
||||
def object_id(payload: dict, name: str, empty: bool) -> str:
|
||||
value = payload[name]
|
||||
if not isinstance(value, str) or not (OBJECT_ID.fullmatch(value) or (empty and value == "")):
|
||||
raise ToolError(f"{name} must be a full git object id")
|
||||
return value
|
||||
|
||||
|
||||
def merge_hash(row: dict, preview: dict) -> str:
|
||||
"""Returns:
|
||||
The sha256 a merge card is bound to: its command, directory, the
|
||||
HEAD, merge base and target the runner previewed and the digest of
|
||||
the diff or the error it sent.
|
||||
"""
|
||||
shown = {key: preview.get(key, "") for key in ("head", "base", "target", "error")}
|
||||
return signing.item_hash({"kind": "merge", "command": row["command"], "directory": row["directory"], **shown, "diff": digest(json.dumps(preview.get("diff", []), sort_keys=True))})
|
||||
|
||||
|
||||
class Previewing:
|
||||
def open_rows(self) -> list[dict]:
|
||||
held = self.open_jobs()
|
||||
return [row for row in operator_rows(read_register(self.council / REGISTER)) if row["check"] != "decision" and row["task"] not in held]
|
||||
|
||||
def preview_of(self, row: dict) -> dict | None:
|
||||
"""Returns:
|
||||
The runner's merge preview of the row's command, None when it
|
||||
sent none for this command.
|
||||
"""
|
||||
found = self.merge_previews.get(card_id(row["task"]))
|
||||
return found if found is not None and found["command"] == row["command"] else None
|
||||
|
||||
def preview_rows(self) -> dict:
|
||||
"""Returns:
|
||||
{"rows"}: every open operator row in an absolute directory with
|
||||
the HEAD of the preview the hub holds, None for none, for the
|
||||
runner to preview the git merges among them.
|
||||
"""
|
||||
rows = [row for row in self.open_rows() if row["directory"].startswith("/")]
|
||||
return {"rows": [{"task": row["task"], "command": row["command"], "directory": row["directory"], "head": (self.preview_of(row) or {}).get("head")} for row in rows]}
|
||||
|
||||
def record_preview(self, body: bytes) -> dict:
|
||||
"""Args:
|
||||
body: from the runner, {task, command, head, base, target, diff}
|
||||
for a git merge row, or {task, command, head, error} when it
|
||||
could not preview it; head is empty when HEAD is unreadable.
|
||||
"""
|
||||
payload = decode(body)
|
||||
expect(payload, FAILED if "error" in payload else SHOWN)
|
||||
task = payload["task"]
|
||||
if not isinstance(task, str) or not task.startswith(OPERATOR) or not signing.TASK.fullmatch(task):
|
||||
raise ToolError("task must be an operator row")
|
||||
row = next((row for row in self.open_rows() if row["task"] == task), None)
|
||||
if row is None:
|
||||
raise Missing(task)
|
||||
if payload["command"] != row["command"]:
|
||||
raise Conflict({"id": task, "status": "changed"})
|
||||
record = {"command": row["command"], "head": object_id(payload, "head", "error" in payload), "taken": time.time()}
|
||||
if "error" in payload:
|
||||
record["error"] = bounded(payload, "error", ERROR_LIMIT)
|
||||
else:
|
||||
record.update(base=object_id(payload, "base", False), target=object_id(payload, "target", False), diff=valid_diff(payload["diff"]))
|
||||
self.merge_previews.remove(card_id(task))
|
||||
self.merge_previews.insert(card_id(task), record)
|
||||
return {"id": card_id(task), "head": record["head"]}
|
||||
|
||||
def previewed_head(self, task: str, command: str) -> str:
|
||||
found = self.merge_previews.get(card_id(task))
|
||||
return found["head"] if found is not None and found["command"] == command and "diff" in found else ""
|
||||
Reference in new issue
Block a user