The Grant bar becomes one split control: Select, or Grant N with a menu for Deny, Grant all green, the picked list, Clear and Direct mode; picked items turn pale green. The radio drops its filter flyout and gains three-state bells per row, a test per row including Speak, Auto or Morse on a second click, mute on the sender avatar and the agent profile, Cancel MAYDAY beside Send only while one is active, a Send menu with a test message and hold-to-record push-to-talk. Decision rows read as questions with their options; the signed answer is Decision <id> plus Answer: <answer>, and the card names its recipient. Security: the passkey-signed answer carries no agent-written text, the inbox lists answerable rows only when their id fullmatches the TASK rule of the installed rasci.py (skill_scripts.task_pattern), and rasci.py, operator.py and hotfix.py check task slugs with fullmatch, so a trailing newline no longer passes. Accepted MEDUSA findings after kvb-think-criticize: page-inbox.js:116 EXA006 (by design after the fix), page-inbox.js:125 EXA010, operator.py:173, 618 and 633 RP001, FT-TRIGGER-005 and RLHF-POISON-002, operator.py:639 MEX-SCAN-346, operator.py:968 MM-SCAN-058, operator.py:974 ACP-SCAN-028 (false positives). 🎯 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>
112 lines
3.7 KiB
Python
112 lines
3.7 KiB
Python
from __future__ import annotations
|
|
|
|
import functools
|
|
import importlib.util
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
from types import ModuleType
|
|
from typing import Protocol
|
|
|
|
SCRIPT_TIMEOUT = 60
|
|
OUTPUT_LIMIT = 4000
|
|
FIRST_LINE_LIMIT = 200
|
|
ELIDED = "..."
|
|
SAFE_PATH = "/usr/local/bin:/usr/bin:/bin"
|
|
RADIO = "kvb-org-radio/scripts/radio.py"
|
|
RASCI = "kvb-org-rasci/scripts/rasci.py"
|
|
NIGHT = "kvb-org-suspend/scripts/night.py"
|
|
OPERATOR_SCRIPT = "kvb-org-operator/scripts/operator.py"
|
|
ESTIMATE = "kvb-org-queue-estimate/scripts/estimate.py"
|
|
|
|
|
|
def bounded(stdout: str) -> str:
|
|
"""Returns:
|
|
stdout when it fits OUTPUT_LIMIT, else its first line, whole or not
|
|
at all once over FIRST_LINE_LIMIT, ELIDED and the last OUTPUT_LIMIT
|
|
characters of the rest: the first line a caller parses, like the ts
|
|
radio.py prints, outlives a long output.
|
|
"""
|
|
if len(stdout) <= OUTPUT_LIMIT:
|
|
return stdout
|
|
first, _, rest = stdout.partition("\n")
|
|
return "\n".join([first if len(first) <= FIRST_LINE_LIMIT else "", ELIDED, rest[-OUTPUT_LIMIT:]])
|
|
|
|
|
|
def script_env(home: Path, council: Path) -> dict[str, str]:
|
|
return {"PATH": SAFE_PATH, "HOME": str(home), "AGENTS_COUNCIL_ROOT": str(council), "PYTHONDONTWRITEBYTECODE": "1"}
|
|
|
|
|
|
def script_module(script: Path) -> ModuleType | None:
|
|
"""Returns:
|
|
The installed script as a module, loaded again after an install
|
|
changed it, None when it is missing or does not load.
|
|
"""
|
|
try:
|
|
changed = script.stat().st_mtime_ns
|
|
except OSError:
|
|
return None
|
|
return loaded(script, changed)
|
|
|
|
|
|
def task_pattern(skills: Path) -> re.Pattern[str] | None:
|
|
"""Args:
|
|
skills: the installed skills directory, the hub's --skills mount.
|
|
|
|
Returns:
|
|
TASK of the installed kvb-org-rasci rasci.py, the one rule for
|
|
register task ids; None when the script is missing, does not load or
|
|
holds no compiled pattern.
|
|
"""
|
|
found = getattr(script_module(skills / RASCI), "TASK", None)
|
|
return found if isinstance(found, re.Pattern) else None
|
|
|
|
|
|
@functools.cache
|
|
def loaded(script: Path, changed: int) -> ModuleType | None:
|
|
spec = importlib.util.spec_from_file_location(f"kvb_orchestrator_{script.stem}_{changed}", script)
|
|
if spec is None:
|
|
return None
|
|
module = importlib.util.module_from_spec(spec)
|
|
try:
|
|
spec.loader.exec_module(module)
|
|
except (OSError, ImportError, RuntimeError, SyntaxError):
|
|
return None
|
|
return module
|
|
|
|
|
|
class Runner(Protocol):
|
|
skills: Path
|
|
|
|
def run(self, script: str, args: list[str]) -> dict: ...
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Scripts:
|
|
skills: Path
|
|
council: Path
|
|
home: Path
|
|
|
|
def run(self, script: str, args: list[str]) -> dict:
|
|
command = " ".join([Path(script).name, *args])
|
|
env = script_env(self.home, self.council)
|
|
try:
|
|
done = subprocess.run(
|
|
[sys.executable, str(self.skills / script), *args],
|
|
capture_output=True,
|
|
encoding="utf-8",
|
|
errors="replace",
|
|
timeout=SCRIPT_TIMEOUT,
|
|
env=env,
|
|
stdin=subprocess.DEVNULL,
|
|
check=False,
|
|
)
|
|
except subprocess.TimeoutExpired as error:
|
|
partial = error.stdout.decode("utf-8", errors="replace") if isinstance(error.stdout, bytes) else error.stdout or ""
|
|
return {"command": command, "code": -1, "stdout": bounded(partial), "stderr": str(error)}
|
|
except OSError as error:
|
|
return {"command": command, "code": -1, "stdout": "", "stderr": str(error)}
|
|
return {"command": command, "code": done.returncode, "stdout": bounded(done.stdout), "stderr": done.stderr[-OUTPUT_LIMIT:]}
|