Surface (requirement 001 phase 2): navigation Stream (Inbox, Regeln) / Agents / Artifacts with keys 1-3 and hash routes (#graph and #tree redirect), header with title, command palette and settings only, server-side badges (unsnoozed inbox, beats within 900 s, open jobs), a Mayday banner with "aufheben", four stream chips with agent:/art:/seit: search, Filter and time menus, the inbox in main, an agents toolbar (Funk an alle with Newsletter, Broadcast, Pan-Pan, Security, Mayday; Priorität; Tag/Nacht), Post or Call in the agent panel, Ambiente in the settings and read-aloud over the seven classes with Mayday locked. Rename (decision 9): hub/ is orchestrator/, the package kvb_orchestrator, the unit kvb-orchestrator-runner.service, scripts/orchestrator.sh, environment KVB_ORCHESTRATOR_*, make targets orchestrator-*, the MCP server, image and compose project kvb-orchestrator, the guard header X-Kvb-Orchestrator and the message marker [kvb-orchestrator msg <id>]. install runs migrate first: it stops the old container, removes its image and code, moves state, approvals and pinned keys, swaps the MCP registration, the PermissionRequest hook and the runner unit, and changes nothing on a second run (scratch-HOME test with stub docker, claude and systemctl). Saved views fall back to the old localStorage key once. MEDUSA acceptances carried to the renamed paths: 82 rows whose lines are unchanged (reason prefixed "renamed from <old path>, line unchanged"), and 7 rows whose text changed only in the product name, the package name, a temp prefix or a new class argument, each upheld by one kvb-think-criticize skeptic (approval.py:60, messaging.py:53, server.py:56, tests/hub_support.py:64, passkey.py:205, page-agent.js:75, language.py:46). Cost 101 %: the longer name adds 15 tokens of skill text; the operator approved it with the commit. 🎯 Fix: 92 % 💥 Break: 4 % 💸 Cost: 101 % ⏱️ Time: – 🛡️ Security: 100 % 💰 Value: ? 🏆 Score: 87 🚦 Gate: ⚠️ cost 101 % > 100: ask the operator before the commit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
3.4 KiB
Python
66 lines
3.4 KiB
Python
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
from .errors import Conflict, Missing, ToolError
|
|
from .fields import bounded, decode, expect
|
|
from .register import OPERATOR, REGISTER, operator_rows, read_register, runnable
|
|
from .signed import operator_signed
|
|
from .skill_scripts import OPERATOR_SCRIPT
|
|
|
|
JOB_OPEN = ("queued", "running")
|
|
RUN_OUTPUT = 64 << 10
|
|
|
|
|
|
def runner_job(job: dict) -> dict:
|
|
return {**{key: job[key] for key in ("id", "task", "command", "directory", "sha256")}, "proof": job.get("proof")}
|
|
|
|
|
|
class Jobs:
|
|
def open_jobs(self) -> set[str]:
|
|
return {job["task"] for job in self.jobs.listed() if job["status"] in JOB_OPEN}
|
|
|
|
def queue_job(self, item: dict, proof: dict | None) -> str:
|
|
row = next((row for row in operator_rows(read_register(self.council / REGISTER)) if row["task"] == item["id"]), None)
|
|
if row is None or not runnable(row) or operator_signed(row) != item["signed"]:
|
|
return "verweigert: die Zeile hat sich seit der Freigabe geändert"
|
|
if item["id"] in self.open_jobs():
|
|
return "läuft schon"
|
|
job = {"task": row["task"], "command": row["command"], "directory": row["directory"], "sha256": item["sha256"], "status": "queued", "proof": proof}
|
|
self.jobs.add({**job, "code": None, "output": "", "created_ts": time.time(), "started": None, "finished": None})
|
|
return "an den Runner übergeben"
|
|
|
|
def runner_jobs(self) -> dict:
|
|
return {"jobs": [runner_job(job) for job in self.jobs.listed() if job["status"] == "queued"]}
|
|
|
|
def claim(self, job_id: str) -> dict:
|
|
job, changed = self.jobs.transition(job_id, "queued", {"status": "running", "started": time.time()})
|
|
if job is None:
|
|
raise Missing(job_id)
|
|
if not changed:
|
|
raise Conflict({"id": job_id, "status": job["status"]})
|
|
return runner_job(job)
|
|
|
|
def report(self, job_id: str, body: bytes) -> dict:
|
|
payload = decode(body)
|
|
expect(payload, ("output", "code", "refused"))
|
|
output, code, refused = bounded(payload, "output", RUN_OUTPUT), payload["code"], payload["refused"]
|
|
if not isinstance(refused, bool) or (code is not None and (isinstance(code, bool) or not isinstance(code, int))):
|
|
raise ToolError("code must be a whole number or null and refused true or false")
|
|
record = self.jobs.get(job_id)
|
|
if record is None:
|
|
raise Missing(job_id)
|
|
if record["status"] != "running":
|
|
raise Conflict({"id": job_id, "status": record["status"]})
|
|
if code is None and not refused:
|
|
self.jobs.change(job_id, {"output": output})
|
|
return {"id": job_id, "status": "running", "code": None}
|
|
status = "refused" if refused else "done" if code == 0 else "failed"
|
|
job, changed = self.jobs.transition(job_id, "running", {"status": status, "code": code, "output": output, "finished": time.time()})
|
|
if not changed:
|
|
raise Conflict({"id": job_id, "status": job["status"]})
|
|
runs = [self.scripts.run(OPERATOR_SCRIPT, ["done", job["task"].removeprefix(OPERATOR)])] if status == "done" else []
|
|
tail = "\n".join(output.splitlines()[-20:])
|
|
self.log.add({"kind": "run", "title": f"{status}: {job['command'][:200]}", "text": tail, "ref": {"job": job_id, "task": job["task"], "code": code, "status": status}})
|
|
return {"id": job_id, "status": status, "code": code, "runs": runs}
|