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>
113 lines
4.1 KiB
Python
113 lines
4.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from .errors import ToolError
|
|
from .fields import decode
|
|
from .records import read_json, write_atomic
|
|
from .settings import CLOCK, flag, section
|
|
|
|
SCHEDULES = "schedules.json"
|
|
SCHEDULES_VIEW = "schedules-view.json"
|
|
ROWS = {
|
|
"coach": {"on": False, "every": 1},
|
|
"dream": {"on": False, "every": 12},
|
|
"dream-popup": {"on": False, "at": ["17:00"]},
|
|
"queue-cleanup": {"on": True, "at": ["00:00", "12:00"]},
|
|
"code-graph": {"on": True},
|
|
}
|
|
HOURS = (1, 24)
|
|
TIMES_LIMIT = 6
|
|
VIEW_LIMIT = 200
|
|
VIEW_TEXT = 2000
|
|
VIEW_KEYS = ("name", "kind", "owner", "unit", "file", "schedule", "next", "last", "event", "command", "off")
|
|
|
|
|
|
def valid_row(name: object, value: object) -> dict:
|
|
"""Args:
|
|
name: one of ROWS.
|
|
value: the row: on, plus every (hours from 1 to 24) for a reminder
|
|
hook or at (1 to TIMES_LIMIT distinct HH:MM) for a timer.
|
|
|
|
Returns:
|
|
The row, times sorted.
|
|
"""
|
|
if not isinstance(name, str) or name not in ROWS:
|
|
raise ToolError(f"no such schedule: {name}")
|
|
row = section(value, str(name), tuple(ROWS[name]))
|
|
found = {"on": flag(row["on"], f"{name}.on")}
|
|
if "every" in row:
|
|
every = row["every"]
|
|
if isinstance(every, bool) or not isinstance(every, int) or not HOURS[0] <= every <= HOURS[1]:
|
|
raise ToolError(f"{name}.every must be a whole number of hours from {HOURS[0]} to {HOURS[1]}")
|
|
found["every"] = every
|
|
if "at" in row:
|
|
times = row["at"]
|
|
if not isinstance(times, list) or not 1 <= len(times) <= TIMES_LIMIT or not all(isinstance(time, str) and CLOCK.fullmatch(time) for time in times):
|
|
raise ToolError(f"{name}.at must hold 1 to {TIMES_LIMIT} times like 17:00")
|
|
if len(set(times)) != len(times):
|
|
raise ToolError(f"{name}.at names a time twice")
|
|
found["at"] = sorted(times)
|
|
return found
|
|
|
|
|
|
def stored_rows(council: Path) -> dict:
|
|
"""Returns:
|
|
Every row of ROWS from schedules.json; a missing, linked or malformed
|
|
file, or a malformed row, gives that row's default.
|
|
"""
|
|
data = read_json(council / SCHEDULES)
|
|
rows = {}
|
|
for name, default in ROWS.items():
|
|
try:
|
|
rows[name] = valid_row(name, data[name])
|
|
except (ToolError, KeyError, TypeError):
|
|
rows[name] = default
|
|
return rows
|
|
|
|
|
|
def view_rows(council: Path) -> dict:
|
|
"""Returns:
|
|
{at, rows}: what the host reconciler last saw, each row with the
|
|
VIEW_KEYS as strings or numbers; {at: None, rows: []} before its first
|
|
run or for a malformed file.
|
|
"""
|
|
data = read_json(council / SCHEDULES_VIEW)
|
|
rows = data.get("rows") if isinstance(data, dict) else None
|
|
at = data.get("at") if isinstance(data, dict) else None
|
|
if not isinstance(rows, list) or isinstance(at, bool) or not isinstance(at, int | float):
|
|
return {"at": None, "rows": []}
|
|
kept = []
|
|
for row in rows[:VIEW_LIMIT]:
|
|
if isinstance(row, dict) and isinstance(row.get("name"), str):
|
|
kept.append({key: shown(row.get(key)) for key in VIEW_KEYS})
|
|
return {"at": at, "rows": kept}
|
|
|
|
|
|
def shown(value: object) -> str | float | None:
|
|
if isinstance(value, str):
|
|
return value[:VIEW_TEXT]
|
|
if isinstance(value, int | float) and not isinstance(value, bool):
|
|
return value
|
|
return None
|
|
|
|
|
|
class Schedules:
|
|
def __init__(self, council: Path) -> None:
|
|
self.council = council
|
|
|
|
def view(self) -> dict:
|
|
return {"rows": stored_rows(self.council), "host": view_rows(self.council)}
|
|
|
|
def save(self, body: bytes) -> dict:
|
|
"""Args:
|
|
body: {row, value}: one row of ROWS and its new value; every
|
|
other row keeps its stored value.
|
|
"""
|
|
data = section(decode(body), "body", ("row", "value"))
|
|
rows = {**stored_rows(self.council), data["row"]: valid_row(data["row"], data["value"])}
|
|
self.council.mkdir(parents=True, exist_ok=True)
|
|
write_atomic(self.council / SCHEDULES, json.dumps(rows, sort_keys=True).encode())
|
|
return self.view()
|