Files
skills/orchestrator/kvb_orchestrator/crons.py
T
Kevin Veen-BirkenbachandClaude Opus 5.5 c1310c3322 feat(orchestrator): tasks tab with register, inbox and queue
Add a Tasks tab that lists the kvb-org-rasci register next to the inbox
and the heavy-job queue, in list, board and RASCI matrix views, each
task with its roles, WSJF, open work and the merge flow of its worktree.

- Task priority pins and WSJF estimates are signed with the operator's
  passkey and applied by the runner through rasci.py; the hub verifies
  the signature itself before it queues a job or logs the change, the
  runner verifies it again and runs only the checked argv, from /, with
  a pinned PATH and a 30 s process-group limit.
- The runner refuses task changes into a council that is a symlink, not
  owned by its uid or given by a relative path, and while the installed
  council.py, nofollow.py or rasci.py differ from the tree.
- Only tasks the hub can sign whole are editable (task slug and length).
- Page lookups keyed by register text use Object.hasOwn, so a status or
  party named like an Object.prototype member cannot break the views.
- The inbox screen renders through the tasks screen, so its task filter
  shows with "Wartet auf Operator" pressed.

Tests: 604 unit tests OK, e2e 15/15 OK (Chromium and Firefox).

🎯 Fix: 93 %
💥 Break: 5 %
💸 Cost: 100 %
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 88
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 23:43:36 +00:00

78 lines
3.5 KiB
Python

from __future__ import annotations
from pathlib import Path
from .council import agent
from .events import event
from .names import Directory
from .records import epoch, read_json, shown
CRON_ACTIVE = 900
TIMER_KEYS = ("OnCalendar", "OnActiveSec", "OnBootSec", "OnStartupSec", "OnUnitActiveSec", "OnUnitInactiveSec")
CRON_LABELS = {"cron": "Cron", "wakeup": "Wakeup", "background": "Hintergrund", "timer": "Timer", "queue": "Queue"}
def cron_state(cron: dict, beats: dict[str, float], now: float) -> dict:
beat = beats.get(cron["session"])
alive = cron["deleted"] is None and (cron["until"] is None or cron["until"] > now)
return {**cron, "active": alive and beat is not None and now - beat < CRON_ACTIVE}
def timer_rows(folder: Path) -> list[dict]:
try:
paths = sorted(folder.glob("*.timer"))
except OSError:
return []
rows = []
for path in paths:
try:
lines = [line.strip() for line in path.read_text(encoding="utf-8", errors="replace").splitlines()]
created = path.stat().st_mtime
except OSError:
continue
pairs = [line.partition("=") for line in lines]
schedule = [value.strip() for key, _, value in pairs if key.strip() in TIMER_KEYS]
description = next((value.strip() for key, _, value in pairs if key.strip() == "Description"), "")
enabled = (folder / "timers.target.wants" / path.name).exists()
rows.append({
"key": f"timer:{path.name}", "type": "timer", "session": "", "sub": "", "created": created, "deleted": None, "until": None,
"job": "", "expression": ", ".join(schedule) or "-", "prompt": description, "reason": path.name, "active": enabled,
})
return rows
def queue_entries(council: Path) -> list[tuple[dict, float]]:
"""Returns:
Each kvb-org-queue entry of queue.json with its enqueue time; an
entry without one is no entry.
"""
data = read_json(council / "queue.json")
entries = data.get("entries") if isinstance(data, dict) else None
found = []
for entry in entries if isinstance(entries, list) else []:
created = epoch(entry.get("enqueued")) if isinstance(entry, dict) else None
if created is not None:
found.append((entry, created))
return found
def queue_rows(council: Path) -> list[dict]:
rows = []
for entry, created in queue_entries(council):
running = "läuft" if entry.get("status") == "active" else "wartet"
rows.append({
"key": f"queue:{shown(entry.get('id'))}", "type": "queue", "session": shown(entry.get("session")), "sub": "", "created": created,
"deleted": None, "until": None, "job": shown(entry.get("id")), "expression": f"{shown(entry.get('kind'))} · {running}",
"prompt": shown(entry.get("cmd")), "reason": shown(entry.get("task")), "active": True, "agent": agent(entry.get("name")),
})
return rows
def cron_event(cron: dict, directory: Directory) -> dict:
text = "\n".join(part for part in (cron["prompt"], cron["reason"]) if part and part != "-")
return event({
"id": f"cron:{cron['key']}", "ts": cron["created"], "kind": "cron", "agent": directory.at(cron["session"], cron["created"]) or cron.get("agent", ""),
"now": directory.now(cron["session"]), "session": cron["session"], "sub": cron["sub"], "title": f"{CRON_LABELS[cron['type']]}: {cron['expression']}", "text": text,
"ref": {key: cron[key] for key in ("type", "expression", "created", "deleted", "until", "active", "job")},
})