Files
skills/orchestrator/kvb_orchestrator/register.py
T
Kevin Veen-BirkenbachandClaude Opus 5.5 0fad1bfae3 feat: hub and skills requirements 032 to 063
Hub: send in the field (032), coherent speak box (033), stream head band (034), Match at full width with its pile (035, 036), Home without the outer box (037), badge to Match (038), rejects that survive a changed or withdrawn card (039), the release card (040), code marks in the review diff (041), why Deny is off (042), the undo window clock (043), widgets without inner boxes (044), the Artifacts head on one line (045), accepting a red gate's risk (046), one code box (047), done rows greyed and folded (048), one control height (049), menus that stay open (050), radio settings in the Device card (051), bubbles beside the modes (052), agent settings on every face and name (053), pin only by menu (054), WASD in Match (055), the flowing card edge (056), Schedules in Controls (057) and the hub poll cost (059).

Skills: the coach leaves for its own repository kevinveenbirkenbach/coach (058; test_install pins its four skills in skills-lock.json and stays red until that repository is published and pinned), hooks and timers start fewer processes (060), council files on hot paths stay bounded and mirror by marker instead of mtime (061), scripts and hooks hand agents less output (062), and block.py builds the commit table and message block in one run (063). Requirement documents 032 to 063 with their implementation amendments.

MEDUSA false positives accepted after kvb-think-criticize (36 lines): MM-SCAN-058 (pla inside replace or plan), JB-SCAN-616/641 (the local clip helper), CODEGEN-SCAN-001 (drop-in paths), CGS-SCAN-029 (systemctl argv from constants), CGS-SCAN-040 (runner poll loop), FLA-SCAN-055 (feedback), WM-SCAN-354, AI-BACKDOOR-006, GENAI-SCAN-1270, B604 (runner shell path for passkey-verified commands), TC004, EXA002, EXA006, EXA010 and WEB-SSRF.

🎯 Fix: 92 %
💥 Break: 8 %
💸 Tokens: 89 %
⏱️ Velocity: –
🛡️ Security: ~100 %
🏆 Score: 95
🚦 Gate: ⛔ break 8 % > 5

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 08:44:15 +00:00

182 lines
6.4 KiB
Python

from __future__ import annotations
import os
import threading
from pathlib import Path
from .council import HUMAN, agent, ordered
from .fields import DESCRIPTION_LIMIT, OPTION_LIMIT, ORDER_NAME
from .records import read_json, shown
LABEL_LIMIT = 80
REGISTER = "rasci.json"
AGENT_ORDER = "agent-order.json"
OPERATOR = "operator/"
ENDED = ("done", "stopped")
PARSED_KEPT = 8
parsed: dict[Path, tuple[tuple[int, int, int], dict[str, dict]]] = {}
parsed_lock = threading.Lock()
def read_register(path: Path) -> dict[str, dict]:
"""Returns:
The task rows of the register, parsed again only when its inode, size
or mtime changed; a fresh top-level dict per call whose rows are
shared between callers and read only.
"""
try:
info = os.lstat(path)
except OSError:
return {}
stamp = (info.st_ino, info.st_size, info.st_mtime_ns)
with parsed_lock:
found = parsed.get(path)
if found is not None and found[0] == stamp:
return dict(found[1])
data = read_json(path)
rows = {task: row for task, row in data.items() if isinstance(row, dict)} if isinstance(data, dict) else {}
with parsed_lock:
parsed.pop(path, None)
parsed[path] = (stamp, rows)
while len(parsed) > PARSED_KEPT:
parsed.pop(next(iter(parsed)))
return dict(rows)
def status_of(row: dict) -> str:
if "status" not in row:
return "queued"
return str(row["status"])
def holders(row: dict, letter: str) -> str:
roles = row.get("roles")
if not isinstance(roles, dict):
return "-"
names = sorted((str(p) for p, v in roles.items() if isinstance(v, str) and letter in v), key=str.lower)
return shown(", ".join(names))
def parties(row: dict) -> dict[str, str]:
roles = row.get("roles")
if not isinstance(roles, dict):
return {}
found: dict[str, str] = {}
for party, letters in roles.items():
name = agent(party)
if name and isinstance(letters, str):
found[name] = found.get(name, "") + letters
return found
def adder(row: dict) -> str:
return next((name for name, letters in parties(row).items() if "A" in letters and name != HUMAN), "")
def is_open(task: str, row: dict, operator: bool) -> bool:
return task.startswith(OPERATOR) == operator and status_of(row) not in ENDED
def row_options(row: dict) -> list[dict]:
"""Args:
row: an operator row of the register, which agents write.
Returns:
A decision row's options as {"label", "description"}, at most
OPTION_LIMIT, each label one non-empty line of at most LABEL_LIMIT
characters and unique; [] for any other row or malformed options.
"""
raw = row.get("options")
if row.get("check") != "decision" or not isinstance(raw, list):
return []
options = []
for option in raw[:OPTION_LIMIT]:
label = option.get("label") if isinstance(option, dict) else None
description = option.get("description", "") if isinstance(option, dict) else None
if isinstance(label, str) and isinstance(description, str) and label.strip() and label.isprintable() and len(label) <= LABEL_LIMIT:
options.append({"label": label.strip(), "description": " ".join(description.split())[:DESCRIPTION_LIMIT]})
labels = [option["label"] for option in options]
return options if len(set(labels)) == len(labels) else []
def operator_rows(tasks: dict[str, dict]) -> list[dict]:
rows = []
for task, row in sorted(tasks.items()):
if not is_open(task, row, True):
continue
options = row_options(row)
recommended = row.get("recommended")
rows.append({
"task": task,
"command": shown(row.get("title")),
"directory": shown(row.get("workdir")),
"why": shown(row.get("description")),
"check": shown(row.get("check")),
"status": status_of(row),
"options": options,
"recommended": recommended if recommended in [option["label"] for option in options] else "",
})
return rows
def runnable(row: dict) -> bool:
return row["command"] != "-" and row["directory"].startswith("/") and row["check"] != "decision"
def pinned(item: tuple[str, dict]) -> tuple[bool, int, str]:
task, row = item
prio = row.get("prio")
if isinstance(prio, int) and not isinstance(prio, bool):
return False, prio, task
return True, 0, task
def register_row(task: str, row: dict) -> dict:
results = row.get("key_results")
if not isinstance(results, list):
results = []
return {
"task": task,
"title": shown(row.get("title")),
"status": status_of(row),
"worker": shown(row.get("worker")),
"responsible": holders(row, "R"),
"accountable": holders(row, "A"),
"objective": shown(row.get("objective")),
"branch": shown(row.get("branch")),
"workdir": shown(row.get("workdir")),
"met": sum(1 for kr in results if isinstance(kr, dict) and kr.get("met") is True),
"total": len(results),
}
def stored_order(path: Path) -> list[str]:
data = read_json(path)
names = data.get("agents") if isinstance(data, dict) else None
if not isinstance(names, list) or not all(isinstance(name, str) for name in names):
return []
return names
def agent_order(tasks: dict[str, dict], claims: list[dict], stored: list[str]) -> list[str]:
"""Args:
tasks: the register.
claims: every office claim; its holder is an agent too.
stored: the operator's agent order, as `rasci.py agents order` wrote it.
Returns:
The agents `rasci.py agents order` accepts: the stored ones it still
knows first, in their order, then the workers of open tasks by pin,
then the remaining office holders by name.
"""
names: list[str] = []
for _, row in sorted(tasks.items(), key=pinned):
worker = row.get("worker")
if status_of(row) not in ENDED and isinstance(worker, str) and worker not in names:
names.append(worker)
names += [name for name in ordered({claim["address"] or claim["session"] for claim in claims}) if name not in names]
known = [name for name in names if ORDER_NAME.fullmatch(name)]
listed = [name for name in dict.fromkeys(stored) if name in known]
return [*listed, *(name for name in known if name not in listed)]