feat(hub): grant split menu, radio redesign and answerable decision rows

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>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-18 19:28:37 +00:00
1 parent ff9bbc19c2
commit d695bb2b58
42 files changed
+1158 -340

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@ IGNORABLE = frozenset(code for start, end in DEFAULT_IGNORABLE for code in range
EMOJI_TABLE = Path(__file__).with_name("emoji-variation.json")
HEX_CODE = re.compile(r"[0-9A-F]{4,6}")
PRESENTATION = (chr(0xFE0E), chr(0xFE0F))
FREE_TEXT = ("command", "text", "reason", "question", "description")
FREE_TEXT = ("command", "text", "reason", "question", "description", "preview")
BREAKS = "\t\n"
DEPTH_LIMIT = 64
WARNINGS = (
+15 -5
View File
@@ -7,6 +7,8 @@ from .diffs import sealed_file, store_diff, store_sealed, valid_diff, valid_seal
from .errors import Conflict, Missing, ToolError
from .fields import (
COMMAND_LIMIT,
DESCRIPTION_LIMIT,
OPTION_LIMIT,
PATH_LIMIT,
WAIT_CAP,
bounded,
@@ -21,8 +23,7 @@ from .fields import (
from .signed import ask_signed
ASK_LIFETIME = 3600
DESCRIPTION_LIMIT = 1000
OPTION_LIMIT = 12
PREVIEW_LIMIT = 4000
ASK_TEXTS = {"command": COMMAND_LIMIT, "cwd": PATH_LIMIT, "session": 200, "agent": 200}
ANSWERS = {"allow": "allowed", "deny": "denied"}
@@ -52,13 +53,22 @@ def decision_row(decision: dict) -> dict:
def option_of(option: object) -> dict:
"""Args:
option: {"label", "description"} and an optional "preview", a
multi-line mockup, snippet or table shown beside the options.
Returns:
The option with its texts stripped; "preview" only when it was given
and is not empty.
"""
if not isinstance(option, dict):
raise ToolError("every option must be an object with label and description")
expect(option, ("label", "description"))
expect(option, ("label", "description", *(("preview",) if "preview" in option else ())))
label = field(option, "label").strip()
description = bounded(option, "description", DESCRIPTION_LIMIT).strip()
visible({"description": description})
return {"label": label, "description": description}
preview = bounded(option, "preview", PREVIEW_LIMIT).rstrip() if "preview" in option else ""
visible({"description": description, "preview": preview})
return {"label": label, "description": description, **({"preview": preview} if preview.strip() else {})}
class Asking:
+2
View File
@@ -12,6 +12,8 @@ TEXT_LIMIT = 20_000
COMMAND_LIMIT = 4000
PATH_LIMIT = limits.PATH_LIMIT
NAME_LIMIT = 120
DESCRIPTION_LIMIT = 1000
OPTION_LIMIT = 12
COUNT = re.compile(r"[0-9]{1,12}")
PATH = re.compile(rf"/[^\x00-\x1f\x7f]{{0,{PATH_LIMIT - 1}}}")
LINE = r"(?=[^\x00-\x1f\x7f]*\S)[^\x00-\x1f\x7f]{{1,{0}}}"
+5 -3
View File
@@ -12,6 +12,7 @@ from .names import Directory
from .records import digest, iso_epoch
from .register import adder, operator_rows, runnable
from .signed import signing
from .skill_scripts import task_pattern
SNOOZE_LIMIT = 8 * 86400
@@ -19,7 +20,7 @@ SNOOZE_LIMIT = 8 * 86400
class Inbox:
def inbox(self, now: float, tasks: dict[str, dict], directory: Directory) -> list[dict]:
claims = read_claims(self.council)
base = {"agent": "", "to": "", "detail": "", "green": False, "gate": "", "score": "", "warnings": [], "options": [], "recommended": "", "command": "", "directory": "", "sha256": "", "runnable": False, "deniable": False, "job": None, "rule": None, "dry_run": None, "diff": None, "settled": False}
base = {"agent": "", "to": "", "detail": "", "green": False, "gate": "", "score": "", "warnings": [], "options": [], "recommended": "", "check": "", "command": "", "directory": "", "sha256": "", "runnable": False, "deniable": False, "job": None, "rule": None, "dry_run": None, "diff": None, "settled": False}
items = []
for review in self.reviews.pending():
created = iso_epoch(review["created"]) or now
@@ -37,10 +38,11 @@ class Inbox:
items.append({**base, "kind": "decision", "id": decision["id"], "ts": decision["created_ts"], **fields})
held = self.open_jobs()
consoles = self.consoles()
rows = operator_rows(tasks)
pattern = task_pattern(self.scripts.skills)
rows = [row for row in operator_rows(tasks) if pattern is not None and pattern.fullmatch(row["task"])]
for row in rows:
busy = row["task"] in held
fields = {"title": row["command"], "detail": row["why"], "agent": adder(tasks[row["task"]]), "to": requester_of(claims, adder(tasks[row["task"]]))[0], "command": row["command"], "directory": row["directory"], "sha256": digest(row["command"])}
fields = {"title": row["command"], "detail": row["why"], "agent": adder(tasks[row["task"]]), "to": requester_of(claims, adder(tasks[row["task"]]))[0], "command": row["command"], "directory": row["directory"], "sha256": digest(row["command"]), "check": row["check"], "options": row["options"], "recommended": row["recommended"]}
state = {"runnable": runnable(row) and not busy, "deniable": not busy, "job": console_of(consoles.get(row["task"]))}
items.append({**base, "kind": "operator", "id": row["task"], "ts": self.watch.first(row["task"], now), **fields, **state})
listed = {row["task"] for row in rows}
+6 -3
View File
@@ -4,10 +4,9 @@ import json
from http import HTTPStatus
from . import NAME
from .asking import OPTION_LIMIT
from .choosing import CHOICE_REQUEST
from .errors import RpcError, ToolError
from .fields import WAIT_CAP
from .fields import OPTION_LIMIT, WAIT_CAP
from .requesting import AGENT_CAP
from .reviewing import GATES
from .rules import RULE_KINDS
@@ -34,7 +33,11 @@ class Mcp:
wait = {"type": "number", "minimum": 0, "description": f"Seconds to wait, capped at {WAIT_CAP}."}
option = {
"type": "object",
"properties": {"label": text_property("Button text, one line."), "description": text_property("What choosing it means; may be empty.")},
"properties": {
"label": text_property("Button text, one line."),
"description": text_property("What choosing it means; may be empty."),
"preview": text_property("Optional multi-line mockup, snippet, diff or table shown in monospace beside the options while this option is focused; only for options that need a visual comparison."),
},
"required": ["label", "description"],
"additionalProperties": False,
}
+36 -7
View File
@@ -3,9 +3,11 @@ from __future__ import annotations
from pathlib import Path
from .council import HUMAN, agent, ordered
from .fields import ORDER_NAME
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/"
@@ -53,19 +55,46 @@ 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]:
return [
{
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),
}
for task, row in sorted(tasks.items())
if is_open(task, row, True)
]
"options": options,
"recommended": recommended if recommended in [option["label"] for option in options] else "",
})
return rows
def runnable(row: dict) -> bool:
@@ -2,6 +2,7 @@ from __future__ import annotations
import functools
import importlib.util
import re
import subprocess
import sys
from dataclasses import dataclass
@@ -50,6 +51,19 @@ def script_module(script: Path) -> ModuleType | 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)
+20 -4
View File
@@ -60,9 +60,18 @@ h1 { margin: 0; font-size: var(--fs-lg); font-weight: 680; letter-spacing: -.01e
.badge.alarm { background: var(--alarm); color: #fff; }
.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
.grant-bar, .grant-tray { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
.grant-tray[hidden] { display: none; }
.grant-bar .segmented button { display: inline-flex; align-items: center; gap: 6px; }
.grant-count { color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.grant-split { display: inline-flex; align-items: stretch; }
.grant-split > .btn { display: inline-flex; align-items: center; gap: 6px; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.grant-menu > summary.grant-count { height: 100%; margin-left: -1px; padding: 0 7px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.grant-menu-box { gap: 2px; min-width: 15rem; padding: 6px; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; border-radius: 8px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--sunken); }
.menu-item:disabled { opacity: .45; cursor: not-allowed; }
.menu-item.danger { color: var(--bad); }
.grant-picked { display: grid; gap: 2px; max-height: 40vh; margin: 4px 0; padding: 4px 0; overflow: auto; border-block: 1px solid var(--line); list-style: none; }
.grant-picked-title { min-width: 0; max-width: 24rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.picked:disabled { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 18%, var(--panel)); color: var(--ok); opacity: 1; cursor: default; }
:is(.item, .entry):has(button.picked) { background: color-mix(in srgb, var(--ok) 7%, var(--panel)); }
.banner { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-5); background: var(--alarm); color: #fff; font-weight: 650; }
.banner[hidden] { display: none; }
.banner .text { flex: 1; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@@ -355,8 +364,15 @@ textarea + .mic-auto { display: flex; margin: 4px 0 0 auto; }
.option:hover { background: var(--accent-soft); border-color: var(--accent); }
.option.recommended { border-color: var(--ok); box-shadow: inset 3px 0 0 var(--ok); }
.option span { color: var(--muted); font-size: var(--fs-sm); }
.option:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.option.other { display: flex; gap: 6px; align-items: center; cursor: default; }
.option.other:hover { background: var(--panel); border-color: var(--line-strong); }
.option.other .field { flex: 1; min-width: 0; }
.choice { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 10px; align-items: start; }
.choice-preview { margin: 8px 0 0; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); line-height: 1.45; white-space: pre; overflow: auto; max-height: 360px; }
.text.question { font-weight: 600; }
@media (max-width: 720px) { .choice { grid-template-columns: 1fr; } }
.inbox-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.inbox-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.inbox-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--sp-2) var(--sp-3); padding: var(--sp-3); border: 1px solid var(--line); border-radius: 12px; background: var(--glass-card); }
.item.cursor { outline: 2px solid var(--accent); outline-offset: 1px; }
+17 -1
View File
@@ -113,7 +113,7 @@
const life = h("span", {class: "muted"});
const night = h("span", {});
const claimed = nightAgents().some(([sid]) => sid === key);
const nightRow = h("div", {class: "actions agent-night", role: "group", "aria-label": "Day/Night"}, night, h("span", {class: "spacer"}),
const nightRow = h("div", {class: "actions agent-night", role: "group", "aria-label": "Day/Night"}, night, h("span", {class: "spacer"}), radioMute(key, name),
claimed ? ACTIONS.slice(1).map(([id]) => actionButton(id, "btn small", null, () => [key])) : null);
const former = (people()[key] || {names: []}).names.filter((entry) => entry !== name);
openPopup(name, [
@@ -134,6 +134,22 @@
text.focus();
}
function radioMute(key, name) {
const button = h("button", {type: "button", class: "btn small agent-mute", "aria-label": `Mute ${name}`});
const show = () => {
const muted = radioSet.muted.includes(key);
button.title = muted ? `Muted: the radio reads ${name} aloud again on a press` : `Mute ${name}: the radio stops reading this agent aloud`;
button.setAttribute("aria-pressed", String(muted));
button.replaceChildren(icon(muted ? "bi-volume-mute" : "bi-volume-up"), muted ? "Muted" : "Radio on");
};
button.addEventListener("click", () => {
keepRadio(RadioSet.muting(radioSet, key));
show();
});
show();
return button;
}
function agentNames() {
const names = new Set([...state.graph.nodes.filter((node) => node.kind === "session" || node.kind === "chair").map((node) => nameOf(node.id)), ...state.agent_order]);
return [...names].sort((a, b) => a.localeCompare(b));
-1
View File
@@ -98,7 +98,6 @@
}
function drawSpot() {
drawBars();
drawSpeak();
}
+68 -5
View File
@@ -9,6 +9,7 @@
mayday: "MAYDAY: all agents pause writing steps until you cancel it.",
};
const VOICE_POLL = 700;
const HOLD_MS = 350;
const composer = {live: null};
function confirmMayday() {
@@ -71,6 +72,8 @@
}
async function keepRecording(blob, parts) {
const held = parts.ptt === "released";
parts.ptt = "";
parts.record.disabled = true;
try {
const sound = context();
@@ -94,6 +97,9 @@
parts.text.dispatchEvent(new Event("input", {bubbles: true}));
parts.text.focus();
parts.status.textContent = note.text ? "Check the text, then send." : "Nothing understood: write the text yourself.";
if (held && note.text) {
parts.text.form.requestSubmit();
}
} catch (error) {
parts.status.textContent = "";
toast("Recording failed", [String(error.message || error)], false);
@@ -150,6 +156,9 @@
composer.live = parts;
recorder.start();
recordLabel(parts, true);
if (parts.ptt === "released") {
stopRecording(parts);
}
parts.timer = window.setInterval(() => {
const seconds = Math.floor((Date.now() - parts.started) / 1000);
parts.status.textContent = `Recording ${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")} of at most ${state.speech.seconds} s`;
@@ -167,17 +176,31 @@
const replay = h("div", {class: "voice-note", hidden: true});
const hint = h("span", {class: "muted composer-hint"});
const status = h("span", {class: "muted composer-status", "aria-live": "polite"});
const record = h("button", {type: "button", class: "btn small", "aria-pressed": "false", title: "Record: one click starts, another stops; the hub transcribes, you check the text before sending"});
const record = h("button", {type: "button", class: "btn small", "aria-pressed": "false", title: "Record: one click starts, another stops, you check the text before sending; hold it to talk, release to send"});
const submit = h("button", {type: "submit", class: "btn primary ptt", title: "PTT: push to transmit the message; your passkey signs it"}, icon("bi-broadcast-pin"), "PTT");
const attach = h("input", {type: "checkbox", title: "Attach recording: the agents get the path of the sound file; otherwise only the checked text goes out"});
const parts = {record, status, text, replay, attach, voice: "", recorder: null, timer: 0, started: 0};
const parts = {record, status, text, replay, attach, voice: "", recorder: null, timer: 0, started: 0, ptt: "", hold: 0, swallow: false};
recordLabel(parts, false);
const gap = micGap();
if (gap) {
record.disabled = true;
record.title = `Record: ${gap}`;
}
record.addEventListener("click", () => (parts.recorder ? stopRecording(parts) : startRecording(parts)));
holdToTalk(parts);
record.addEventListener("click", () => {
if (parts.swallow) {
parts.swallow = false;
return;
}
parts.ptt = "";
if (parts.recorder) {
stopRecording(parts);
} else {
startRecording(parts);
}
});
const [, cancel, , cancelHint] = actionOf("clear-mayday");
const clear = h("button", {type: "button", class: "btn small danger radio-cancel", hidden: !state.silence, ...named(cancel, cancelHint), on: {click: () => confirmAct("clear-mayday", [])}}, icon("bi-life-preserver"), cancel);
const sync = () => {
const direct = TO_ONE.some(([id]) => id === channel.value);
toField.hidden = !direct;
@@ -187,7 +210,7 @@
channel.addEventListener("change", sync);
sync();
const form = h("form", {class: "composer"}, h("div", {class: "composer-grid"}, h("label", {}, "Channel", channel), toField), text, replay,
h("div", {class: "actions"}, record, micButton(text, false), status, hint, submit));
h("div", {class: "actions"}, record, micButton(text, false), status, hint, clear, h("div", {class: "ptt-split", role: "group", "aria-label": "Send"}, submit, testMenu(text, channel))));
form.addEventListener("submit", async (event) => {
event.preventDefault();
const direct = TO_ONE.some(([id]) => id === channel.value);
@@ -207,5 +230,45 @@
submit.disabled = false;
});
attachVoice(parts, "");
return {form, recipient, text, channel};
return {form, recipient, text, channel, clear};
}
function holdToTalk(parts) {
const {record} = parts;
record.addEventListener("pointerdown", (event) => {
if (event.button !== 0 || record.disabled || parts.recorder) {
return;
}
parts.hold = window.setTimeout(() => {
parts.ptt = "holding";
startRecording(parts);
}, HOLD_MS);
});
const release = () => {
window.clearTimeout(parts.hold);
if (parts.ptt === "holding") {
Object.assign(parts, {ptt: "released", swallow: true});
stopRecording(parts);
}
};
for (const kind of ["pointerup", "pointercancel", "pointerleave"]) {
record.addEventListener(kind, release);
}
}
/**
* @param {Element} text the message field.
* @param {Element} channel the class select.
* @returns {Element} the ▾ of PTT: a menu whose item reads the message, or a sample line, aloud here only, so nothing leaves the browser.
*/
function testMenu(text, channel) {
const item = h("button", {type: "button", class: "menu-item", ...named("Test message", "Test message: hear it here as the radio reads it aloud; nothing is sent, nothing is signed"), on: {click: (event) => {
event.currentTarget.closest("details").open = false;
if (!state.speech.tts) {
toast("No test message", [`The hub speaks no line: ${state.speech.tts_off}.`], false);
return;
}
say({steps: [{kind: "speech", text: text.value.trim() || state.speech.sample}], voice: state.speech.operator, tone: "direct", cls: channel.value, who: HUMAN, sent: true, line: "test message"});
}}}, icon("bi-play-fill"), "Test message");
return h("details", {class: "menu ptt-menu"}, h("summary", {class: "btn primary ptt-more", ...named("More send options", "More: send a test message only you hear")}, caret()), h("div", {class: "menu-box end"}, item));
}
-1
View File
@@ -47,7 +47,6 @@
dead: ["Dead", "bi-x-octagon-fill", "bad"],
};
const SOUND_KINDS = [["mayday", "MAYDAY / PAN-PAN"], ["review", "Reviews, asks, decisions"], ["direct", "Post and calls to you"], ["radio", "All radio"]];
const SPEECH_CLASSES = [["post", "Post"], ["call", "Call"], ["newsletter", "Newsletter"], ["broadcast", "Broadcast"], ["mayday", "MAYDAY"], ["pan-pan", "PAN-PAN"], ["security", "Sécurité"]];
const SPEECH_QUEUE = 20;
const SPEECH_QUIET = 60000;
const SPEECH_FRESH = 300;
+61 -30
View File
@@ -1,10 +1,11 @@
const GRANT_SELECT = "select";
const GRANT_MODES = [
["direct", "Direct", "bi-lightning-charge", "Direct: every grant button grants at once"],
[GRANT_SELECT, "Select", "bi-check2-square", "Select: every grant button adds its item to the selection; the tray grants the selection under one passkey signature"],
];
const GRANT_MODES = {
direct: ["Direct", "bi-lightning-charge", "Direct mode", "Direct: every grant button grants at once"],
[GRANT_SELECT]: ["Select", "bi-check2-square", "Select mode", "Select: every grant button adds its item to the selection; Grant grants the selection under one passkey signature"],
};
const PICKED_HINT = "In the selection: take it out with ✕ in the Grant menu";
const DIRECT_WHY = {rule: "a rule is accepted one at a time", review: "a red gate is never granted in a selection"};
const grantView = {modes: [], tray: null, sig: ""};
const grantView = {tray: null, sig: "", open: false};
const grantMode = () => (typeof ViewStore === "object" && ViewStore ? ViewStore.get("approval.mode") : "direct");
const collecting = (item) => grantMode() === GRANT_SELECT && selectable(item);
@@ -27,53 +28,83 @@
/**
* @param button - the grant button of item.
* @param item - a waiting inbox item.
* @returns button; in Select it shows whether item is in the selection, or why its grant still acts at once.
* @returns button; a picked item's button turns pale green and disabled, and in Select it says why a grant still acts at once.
*/
function grantPress(button, item) {
if (grantMode() !== GRANT_SELECT) {
return button;
}
const select = grantMode() === GRANT_SELECT;
if (!selectable(item)) {
button.setAttribute("title", `${button.getAttribute("title")}: acts at once, ${DIRECT_WHY[item.kind]}`);
if (select) {
button.setAttribute("title", `${button.getAttribute("title")}: acts at once, ${DIRECT_WHY[item.kind]}`);
}
return button;
}
const picked = ui.selected.has(keyOf(item));
button.setAttribute("aria-pressed", String(picked));
button.setAttribute("title", picked ? "In the selection: press to take it out" : "Select: press to add it to the selection; the tray grants it");
if (picked) {
button.disabled = true;
button.setAttribute("class", `${button.getAttribute("class")} picked`);
button.setAttribute("title", PICKED_HINT);
}
if (select) {
button.setAttribute("aria-pressed", String(picked));
if (!picked) {
button.setAttribute("title", "Select: press to add it to the selection; Grant grants it");
}
}
return button;
}
function modeItem(mode) {
const [, name, text, hint] = GRANT_MODES[mode];
return h("button", {type: "button", id: `grant-${mode}`, class: "menu-item", "data-mode": mode, ...named(GRANT_MODES[mode][0], hint), on: {click: () => {
grantView.open = false;
ViewStore.set("approval.mode", mode);
}}}, icon(name), text);
}
function pickedItem(item) {
return h("li", {}, h("button", {type: "button", class: "menu-item", ...named(`Remove ${item.title}`, "Remove: take it out of the selection"), on: {click: () => collect(item)}},
icon("bi-x-lg"), h("span", {class: "grant-picked-title"}, revealed(item.title))));
}
/**
* @returns {Node} the one selection control: Select, or Grant N once something is picked or Select mode is on, with a menu of the rest.
*/
function grantSplit(mode, actions) {
const selecting = mode === GRANT_SELECT || actions.chosen.length > 0;
const [label, name, , hint] = GRANT_MODES[GRANT_SELECT];
const main = selecting ? actions.grant : h("button", {type: "button", id: "grant-select", class: "btn small", "data-mode": GRANT_SELECT, ...named(label, hint), on: {click: () => ViewStore.set("approval.mode", GRANT_SELECT)}},
icon(name), h("span", {class: "grant-label"}, label));
const clear = h("button", {type: "button", class: "menu-item", ...named("Clear", "Clear: empty the selection"), disabled: !actions.chosen.length, on: {click: () => {
ui.selected.clear();
regrant();
}}}, icon("bi-x-lg"), "Clear selection");
const menu = h("details", {class: "menu grant-menu", open: grantView.open, on: {toggle: (event) => {
grantView.open = event.currentTarget.open;
}}}, h("summary", {class: "grant-count", ...named(`${actions.chosen.length} selected`, "More: deny, grant all green, the picked items, clear, mode")}, caret()),
h("div", {class: "menu-box end grant-menu-box"}, actions.deny, actions.green,
actions.chosen.length ? h("ul", {class: "grant-picked", "aria-label": "Picked"}, actions.chosen.map(pickedItem)) : null,
clear, selecting ? modeItem(mode === GRANT_SELECT ? "direct" : GRANT_SELECT) : null));
return h("div", {class: "grant-split", role: "group", "aria-label": "Selection"}, main, menu);
}
function drawGrant() {
if (!grantView.tray) {
return;
}
const mode = grantMode();
const chosen = state.inbox.filter((item) => ui.selected.has(keyOf(item)));
const sig = JSON.stringify([mode, chosen.map(keyOf), state.inbox.map((item) => [keyOf(item), isGreen(item), item.held]), ui.busy]);
const actions = selectionActions(state.inbox);
const sig = JSON.stringify([mode, actions.chosen.map(keyOf), state.inbox.map((item) => [keyOf(item), isGreen(item), item.held]), ui.busy]);
if (sig === grantView.sig) {
return;
}
grantView.sig = sig;
for (const button of grantView.modes) {
button.setAttribute("aria-pressed", String(button.dataset.mode === mode));
}
grantView.tray.hidden = mode !== GRANT_SELECT;
grantView.tray.replaceChildren(...(mode === GRANT_SELECT ? [
h("span", {class: "grant-count", "aria-live": "polite"}, `${chosen.length} selected`),
...selectionButtons(state.inbox),
h("button", {type: "button", class: "btn small ghost", ...named("Clear", "Clear: empty the selection"), disabled: !chosen.length, on: {click: () => {
ui.selected.clear();
regrant();
}}}, icon("bi-x-lg"), "Clear"),
] : []));
grantView.tray.replaceChildren(grantSplit(mode, actions));
}
function grantBoot() {
const bar = document.getElementById("grant-bar");
grantView.modes = GRANT_MODES.map(([mode, label, name, hint]) => h("button", {type: "button", id: `grant-${mode}`, "data-mode": mode, ...named(label, hint), on: {click: () => ViewStore.set("approval.mode", mode)}},
icon(name), h("span", {class: "grant-label"}, label)));
grantView.tray = h("div", {class: "grant-tray", role: "group", "aria-label": "Selection"});
bar.replaceChildren(h("div", {class: "segmented", role: "group", "aria-label": "Grant mode"}, grantView.modes), grantView.tray);
grantView.tray = h("div", {class: "grant-tray"});
bar.replaceChildren(grantView.tray);
ViewStore.on("approval", regrant);
drawGrant();
}
+73 -20
View File
@@ -105,6 +105,59 @@
}
const chooseOne = (item, label) => submit([entryOf(item, "approve", label)], `Choice: ${label}`);
const asked = (item) => item.kind === "operator" && item.check === "decision";
const answers = new Map();
async function answerRow(item, answer) {
if (!item.agent) {
toast("Answer: no agent to send it to", ["The row names no adding agent; answer in its session."], false);
return;
}
if (await radioSend({to: item.agent, text: `Decision ${item.id}\nAnswer: ${answer}`, cls: "post", upload: "", voice: ""})) {
answers.set(keyOf(item), answer);
drawInbox();
}
}
function otherAnswer(item) {
const input = h("input", {class: "field", type: "text", placeholder: "Other answer …", "aria-label": `Other answer to ${item.id}`, disabled: answers.has(keyOf(item))});
const form = h("form", {class: "option other"}, input,
h("button", {type: "submit", class: "btn small", disabled: answers.has(keyOf(item)), ...named("Send", revealed(`Send: your passkey signs this answer, a post to ${item.agent}`))}, icon("bi-send"), "Send"));
form.addEventListener("submit", (event) => {
event.preventDefault();
if (input.value.trim()) {
answerRow(item, input.value.trim());
}
});
return form;
}
function choicePanel(item, pick, other) {
const done = answers.has(keyOf(item));
const pane = item.options.some((option) => option.preview) ? h("pre", {class: "choice-preview", "aria-label": "Preview"}) : null;
const show = (option) => {
if (pane) {
pane.textContent = revealedLines(option.preview || "");
}
};
const buttons = item.options.map((option) => h("button", {
type: "button", class: `option${option.label === item.recommended ? " recommended" : ""}`, title: revealed(`${option.label}: your passkey signs this answer, a post to ${item.agent}`), disabled: item.held || done,
on: {click: () => pick(option.label), focus: () => show(option), mouseenter: () => show(option)},
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null));
show(item.options.find((option) => option.label === item.recommended) || item.options[0] || {});
const list = h("div", {class: "options"}, buttons, other || null);
return pane ? h("div", {class: "choice"}, list, pane) : list;
}
const choiceOf = (item, after) => item.kind === "decision"
? choicePanel(item, (label) => { after(); chooseOne(item, label); })
: asked(item) ? [answerTo(item), choicePanel(item, (label) => { after(); answerRow(item, label); }, otherAnswer(item))] : null;
/**
* @param {Object} item a decision row of the register.
* @returns {HTMLElement} who receives the answer: the row's first agent with role A, which any agent can set, so the operator sees it before signing.
*/
const answerTo = (item) => h("p", {class: "muted answer-to"}, item.agent ? ["Your answer goes to ", h("strong", {}, revealed(item.agent)), " as a passkey-signed post, with the row id and your answer only."] : "No agent holds role A on this row: answer in its session.");
const deniable = (item) => item.deniable || item.kind === "review";
const denialOf = (item, reason) => ({...entryOf(item, "reject", ""), channel: "post", reason, to: item.to});
@@ -136,16 +189,20 @@
(reason || confirm).focus();
}
function selectionButtons(items) {
/**
* @returns {object} the picked items as chosen, and the grant, deny and grant-all-green controls of the Grant menu.
*/
function selectionActions(items) {
const green = items.filter(isGreen);
const chosen = items.filter((item) => ui.selected.has(keyOf(item)));
const denials = chosen.filter(deniable);
const grantable = chosen.filter(selectable);
return [
h("button", {type: "button", class: "btn small soft", ...named(`Grant selection (${grantable.length})`), disabled: !grantable.length || ui.busy, on: {click: () => bulk(chosen, "Grant selection", false)}}, icon("bi-check2-square"), String(grantable.length)),
h("button", {type: "button", class: "btn small danger", ...named(`Deny selection (${denials.length})`, `Deny selection (${denials.length}): each requester gets its denial and an optional reason by post, one passkey signature, 3 s to undo`), disabled: !denials.length || ui.busy, on: {click: () => bulk(chosen, "Deny selection", true)}}, icon("bi-x-square"), String(denials.length)),
h("button", {type: "button", class: "btn small primary", ...named(`Grant all green (${green.length})`), disabled: !green.length || ui.busy, on: {click: () => bulk(green, "Grant all green", false)}}, icon("bi-check2-all"), String(green.length)),
];
return {
chosen,
grant: h("button", {type: "button", class: "btn small primary", ...named(`Grant selection (${grantable.length})`), disabled: !grantable.length || ui.busy, on: {click: () => bulk(chosen, "Grant selection", false)}}, icon("bi-check2-square"), `Grant ${grantable.length}`),
deny: h("button", {type: "button", class: "menu-item danger", ...named(`Deny selection (${denials.length})`, `Deny selection (${denials.length}): each requester gets its denial and an optional reason by post, one passkey signature, 3 s to undo`), disabled: !denials.length || ui.busy, on: {click: () => bulk(chosen, "Deny selection", true)}}, icon("bi-x-square"), `Deny ${denials.length}`),
green: h("button", {type: "button", class: "menu-item", ...named(`Grant all green (${green.length})`), disabled: !green.length || ui.busy, on: {click: () => bulk(green, "Grant all green", false)}}, icon("bi-check2-all"), `Grant all green ${green.length}`),
};
}
async function mark(item, until, pinned) {
@@ -175,6 +232,7 @@
}
ui.cursor = Math.max(visibleInbox().findIndex((entry) => keyOf(entry) === key), 0);
drawInbox();
drawGrant();
const box = inboxDom.querySelector(`.item[data-index="${ui.cursor}"] > input[type="checkbox"]`);
if (refocus && box) {
box.focus({preventScroll: true});
@@ -214,14 +272,15 @@
function inboxItem(item, index) {
const red = item.kind === "review" && item.gate !== "pass";
const commanded = item.kind === "ask" || item.kind === "operator";
const commanded = item.kind === "ask" || (item.kind === "operator" && !asked(item));
const classes = ["item", "entry", `k-${item.kind}`, "waiting", isGreen(item) ? "green" : "", red ? "red" : "", item.held ? "held" : "", index === ui.cursor ? "cursor" : ""].filter(Boolean).join(" ");
const box = h("input", {type: "checkbox", "aria-label": `Select ${item.title}`, checked: ui.selected.has(keyOf(item)), disabled: !pickable(item), on: {change: () => toggle(item, true)}});
return h("li", {class: classes, "data-index": index, "data-ref": keyOf(item), "data-to": item.to || null},
box,
h("div", {class: "msg-meta"},
when(item.ts),
pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]),
asked(item) ? pill("Decision", KIND_TONES.decision) : pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]),
answers.has(keyOf(item)) ? pill(revealed(`answered: ${answers.get(keyOf(item))}`), "ok") : null,
item.kind === "review" ? pill(item.gate === "pass" ? "Gate green" : "Gate red", item.gate === "pass" ? "ok" : "bad") : null,
item.warnings.map((warning) => pill(warning, "bad")),
item.pinned ? pill("pinned", "violet") : null,
@@ -233,13 +292,12 @@
item.kind === "review" ? h("div", {class: "muted"}, revealed(item.detail), item.score ? revealed(` · ${item.score}`) : "") : null,
commanded ? h("div", {class: "command", "data-path": item.directory || "-"}, h("code", {}, revealed(item.command)), copyButton(item.command)) : null,
commanded ? h("span", {class: "muted"}, revealed(`in ${dash(item.directory)}`)) : null,
asked(item) ? h("p", {class: "text question"}, revealed(item.title)) : null,
item.kind === "operator" && item.detail && item.detail !== "-" ? h("p", {class: "text reason"}, revealed(item.detail)) : null,
diffBlocks(item),
item.job ? consoleOf(item.job) : null,
item.kind === "rule" ? ruleRequestBody(item) : null,
item.kind === "decision" ? h("div", {class: "options"}, item.options.map((option) => h("button", {
type: "button", class: `option${option.label === item.recommended ? " recommended" : ""}`, title: revealed(`${option.label}: your passkey signs this answer, a post to ${item.agent}`), disabled: item.held, on: {click: () => chooseOne(item, option.label)},
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null))) : null,
choiceOf(item, () => {}),
feedbackList(keyOf(item))),
h("div", {class: "item-actions line-actions"},
actionsFor(item),
@@ -269,7 +327,7 @@
}
}
const mode = grantMode();
const sig = JSON.stringify([mode, items.map(withoutOutput), [...ui.selected], ui.cursor, ui.snoozed, ui.busy, Math.floor(nowSeconds() / 60), diffView.version, state.messages.map((message) => message.id)]);
const sig = JSON.stringify([mode, items.map(withoutOutput), [...ui.selected], [...answers], ui.cursor, ui.snoozed, ui.busy, Math.floor(nowSeconds() / 60), diffView.version, state.messages.map((message) => message.id)]);
if (sig === inboxSig) {
repaintConsoles(items);
return;
@@ -283,7 +341,6 @@
Panels.keepFocus(inboxSlot, () => inboxDom.replaceChildren(
h("div", {class: "inbox-head"}, h("h2", {class: "group-title"}, "Waits on Operator", counter(waitingCount())), h("span", {class: "spacer"}),
hidden ? h("label", {class: "check"}, snoozed, `${hidden} snoozed`) : null, inboxSlot),
mode === GRANT_SELECT ? null : h("div", {class: "inbox-actions"}, selectionButtons(items)),
onLocalhost() ? "" : h("p", {class: "muted"}, "The passkey signs grants only under ", localLink()),
items.length ? h("ol", {class: "inbox-list"}, items.map(inboxItem)) : emptyState("All done", "Nothing is waiting for you right now.")));
settleConsoles(items);
@@ -304,15 +361,11 @@
const body = [
h("div", {class: "who"}, pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]), item.agent ? face(item.agent, false) : null, item.agent ? person(item.agent) : null, when(item.ts)),
h("p", {class: "text"}, revealed(item.title)),
item.command ? h("div", {class: "command"}, h("code", {}, revealed(item.command)), copyButton(item.command)) : null,
item.command && !asked(item) ? h("div", {class: "command"}, h("code", {}, revealed(item.command)), copyButton(item.command)) : null,
asked(item) && item.detail && item.detail !== "-" ? h("p", {class: "text reason"}, revealed(item.detail)) : null,
item.kind === "rule" ? ruleRequestBody(item) : null,
meta([["Directory", item.directory], ["Warnings", item.warnings.join(", ")], ["Id", item.id]]),
item.kind === "decision" ? h("div", {class: "options"}, item.options.map((option) => h("button", {
type: "button", class: `option${option.label === item.recommended ? " recommended" : ""}`, disabled: item.held, on: {click: () => {
closeSheet();
chooseOne(item, option.label);
}},
}, h("strong", {}, revealed(option.label)), option.description ? h("span", {}, revealed(option.description)) : null))) : null,
choiceOf(item, closeSheet),
h("div", {class: "actions"}, h("span", {class: "spacer"}), actionsFor(item).map((node) => {
node.addEventListener("click", closeSheet);
return node;
+1 -1
View File
@@ -44,7 +44,7 @@
if (wpm !== settings.morse.wpm && await saveSettings({...settings, space: savedSpace(), morse: {wpm}})) {
toast("Morse speed saved", [`The radio keys Morse at ${Morse.rate(wpm)}.`], true);
}
redrawFilters();
redrawModeMenus();
}
function morseSpeed() {
+19 -2
View File
@@ -48,6 +48,7 @@
const [name, label] = sent ? ["bi-arrow-up-right", "Sent"] : ["bi-arrow-down-left", "Received"];
const first = firstLine(row.text);
const line = h("li", {class: "radio-row", "data-key": row.key, "data-dir": sent ? "sent" : "received", "data-class": row.class, "data-ts": row.ts, on: {click: (event) => openRadioRow(event.currentTarget.row, event.currentTarget)}},
row.source && !sent && row.from !== HUMAN ? muteFace(row.source, row.from) : null,
h("button", {type: "button", class: "radio-pick", "aria-haspopup": "dialog", title: first},
when(row.ts),
h("span", {class: "radio-dir", role: "img", ...named(label)}, icon(name)),
@@ -73,10 +74,26 @@
for (const node of [...kept.children].filter((child) => child !== pick)) {
node.remove();
}
kept.append(...[...fresh.children].filter((child) => child !== twin));
const parts = [...fresh.children];
const at = parts.indexOf(twin);
pick.before(...parts.slice(0, at));
pick.after(...parts.slice(at + 1));
return kept;
}
/**
* @param {string} key the sender's session key.
* @param {string} name the sender's name.
* @returns {Element} the sender's avatar as a button that mutes or unmutes the sender on the radio, without opening the row.
*/
function muteFace(key, name) {
const muted = radioSet.muted.includes(key);
return h("button", {type: "button", class: "radio-mute", "aria-pressed": String(muted), ...named(`Mute ${name}`, muted ? `Muted: a press lets the radio read ${name} aloud again` : `Mute ${name}: the radio stops reading this agent aloud`), on: {click: (event) => {
event.stopPropagation();
keepRadio(RadioSet.muting(radioSet, key));
}}}, face(key, false));
}
function patchList(list, lines) {
const before = [...list.children];
const focused = before.find((node) => node.contains(document.activeElement)) || null;
@@ -188,7 +205,7 @@
function drawLog() {
const entry = radioSet.log;
const sig = JSON.stringify([state.radio.length, state.radio.length ? state.radio[state.radio.length - 1].ts : 0, state.messages.length, Receipts.signature(state.radio), Receipts.signature(state.messages), entry, Math.floor(Date.now() / 60000)]);
const sig = JSON.stringify([state.radio.length, state.radio.length ? state.radio[state.radio.length - 1].ts : 0, state.messages.length, Receipts.signature(state.radio), Receipts.signature(state.messages), entry, radioSet.muted, Math.floor(Date.now() / 60000)]);
for (const dom of liveParts("logs")) {
if (sig !== dom.sig) {
dom.sig = sig;
+79 -80
View File
@@ -1,18 +1,20 @@
const STATION_TONES = {playing: "ok", loading: "info", reload: "info", blocked: "warn", error: "bad", due: "teal", stopped: "neutral", idle: "neutral", off: "neutral"};
const NOTE_ID = /^[0-9a-f]{16}$/;
const MODE_LABELS = {
auto: ["bi-volume-up", "Auto", "Auto: speech while the host CPU lies below the threshold, otherwise the fallback picked under Read aloud"],
quiet: ["bi-soundwave", "Quiet", "Quiet: the fallback picked under Read aloud, never speech; MAYDAY, PAN-PAN and Sécurité still sound their procedure word"],
auto: ["bi-volume-up", "Auto", "Auto: speech while the host CPU lies below the threshold, otherwise the fallback; press Auto again to pick the fallback"],
quiet: ["bi-soundwave", "Quiet", "Quiet: the fallback, never speech; press Quiet again to pick it; MAYDAY, PAN-PAN and Sécurité still sound their procedure word"],
silence: ["bi-volume-mute", "Silence", "Silence: no sound, bubbles and log only; MAYDAY, PAN-PAN and Sécurité still sound their procedure word"],
morse: ["bi-three-dots", "Morse", "Morse: every message keyed whole in Morse, in its sender's own pitch, at the hub's Morse speed; MAYDAY keys SOS"],
morse: ["bi-three-dots", "Morse", "Morse: every message keyed whole in Morse, in its sender's own pitch; press Morse again to set the speed; MAYDAY keys SOS"],
gibberlink: ["bi-robot", "Gibberlink", "Gibberlink: every message sent whole as ggwave data sound a machine can decode, in its sender's own protocol and stereo position; MAYDAY, PAN-PAN and Sécurité still sound their procedure word"],
};
const MODE_MENUS = {auto: () => fallbackPick(), quiet: () => fallbackPick(), morse: () => morseSpeed()};
const FALLBACK_LABELS = {
gibberlink: ["Gibberlink", "Where speech cannot play, send the rest as ggwave data sound"],
morse: ["Morse", "Where speech cannot play, key the whole message in Morse"],
burst: ["Hiss", "Where speech cannot play, play the short noise burst"],
};
const radioParts = {bars: [], devices: [], logs: [], speaks: []};
const BELLS = {off: ["bi-bell-slash", "off"], tone: ["bi-bell", "tone only"], speak: ["bi-megaphone", "tone and read aloud"]};
const radioParts = {devices: [], logs: [], speaks: []};
const liveParts = (kind) => radioParts[kind].filter((part) => part.root.isConnected);
function voiceReplay(note) {
@@ -131,14 +133,23 @@
return {input, value, name, row: h("div", {class: "knob-row", title: hint}, name, input, value)};
}
function radioCheck(tone, line) {
say({steps: [{kind: "speech", text: state.speech.sample}], voice: state.speech.operator, tone, cls: "newsletter", who: HUMAN, sent: true, line});
}
function testTone(id, label) {
play(id, loudness(id));
if (state.speech.tts && RadioSet.bell(radioSet, id) === "speak") {
radioCheck(id, `${label} test`);
}
}
function toneKnob(id, label) {
const toggle = h("button", {type: "button", class: "btn small ghost icon-only knob-toggle", "aria-pressed": "false", ...named(`${label} tone`), on: {click: () => {
keepRadio({sounds: {...radioSet.sounds, [id]: {...radioSet.sounds[id], on: !radioSet.sounds[id].on}}});
}}});
const toggle = h("button", {type: "button", class: "btn small ghost icon-only knob-toggle", "aria-pressed": "false", ...named(`${label} tone`), on: {click: () => keepRadio(RadioSet.ring(radioSet, id))}});
const level = knob(label, `${label}: tone volume; speech and the burst of these rows play at it`, {min: 0, max: 1, step: 0.05}, (volume) => {
keepRadio({sounds: {...radioSet.sounds, [id]: {...radioSet.sounds[id], volume}}});
});
const test = iconBtn("bi-play-fill", `Test ${label}`, "btn small ghost knob-test", () => play(id, loudness(id)), `Test: play the ${label} tone`);
const test = iconBtn("bi-play-fill", `Test ${label}`, "btn small ghost knob-test", () => testTone(id, label), `Test: play the ${label} tone, while it reads aloud also a spoken line`);
level.row.prepend(toggle);
level.row.append(test);
return {id, toggle, level};
@@ -164,9 +175,51 @@
squelch.row.append(iconBtn("bi-play-fill", "Test Squelch", "btn small ghost knob-test", () => say({steps: [{kind: "burst"}], voice: "", tone: "radio", cls: "post", who: HUMAN, sent: true, line: "squelch test"}), "Test: play the burst of a radio row, at the All radio volume times the squelch"));
const threshold = knob("Threshold", "Speech threshold: the hub renders new speech only while the host CPU lies below it, always at 100 %, never at 0 %; your passkey signs each change", RadioSet.GATE, (value) => drawGate(threshold, value));
threshold.input.addEventListener("change", (event) => setThreshold(Number(event.target.value)));
const check = iconBtn("bi-broadcast", "Radio check", "btn small ghost radio-check", () => say({steps: [{kind: "speech", text: state.speech.sample}], voice: state.speech.operator, tone: "direct", cls: "newsletter", who: HUMAN, sent: true, line: "radio check"}), "Radio check: hear the operator's voice once");
const check = iconBtn("bi-play-fill", "Radio check", "btn small ghost knob-test radio-check", () => radioCheck("direct", "radio check"), "Radio check: hear the operator's voice once at these settings");
check.disabled = !state.speech.tts;
return {tones, squelch, threshold, check, rows: [...tones.map((tone) => tone.level.row), squelch.row, threshold.row]};
threshold.row.append(check);
return {tones, squelch, threshold, rows: [...tones.map((tone) => tone.level.row), squelch.row, threshold.row]};
}
function fallbackPick() {
return h("div", {class: "chips radio-fallback", role: "group", "aria-label": "Fallback", title: "Fallback: what plays in Auto above the threshold and in Quiet, kept in this browser"}, h("span", {class: "chips-label"}, "Fallback"),
RadioSet.FALLBACKS.map((id) => h("button", {type: "button", class: "chip", "aria-pressed": String(radioSet.fallback === id), ...named(FALLBACK_LABELS[id][0], FALLBACK_LABELS[id][1]), on: {click: () => keepRadio({fallback: id})}}, FALLBACK_LABELS[id][0])));
}
function pressMode(part, id) {
if (radioSet.mode === id && MODE_MENUS[id]) {
part.menuFor = part.menuFor === id ? "" : id;
drawModeMenu(part);
return;
}
part.menuFor = "";
keepRadio({mode: id});
context();
}
function drawModeMenu(part) {
const {menu, modes} = part.face;
if (part.menuFor !== radioSet.mode) {
part.menuFor = "";
}
for (const button of modes.querySelectorAll("button[data-mode]")) {
if (MODE_MENUS[button.dataset.mode]) {
button.setAttribute("aria-expanded", String(part.menuFor === button.dataset.mode));
}
}
const sig = JSON.stringify([part.menuFor, radioSet.fallback, settings.morse.wpm]);
if (sig !== part.menuSig) {
part.menuSig = sig;
menu.replaceChildren(...(part.menuFor ? [MODE_MENUS[part.menuFor]()] : []));
menu.hidden = !part.menuFor;
}
}
function redrawModeMenus() {
for (const part of liveParts("devices")) {
part.menuSig = "";
drawModeMenu(part);
}
}
function faceplate(part) {
@@ -176,49 +229,22 @@
const caption = h("div", {class: "radio-caption", role: "status", "aria-live": "polite", hidden: true});
const modes = h("div", {class: "segmented radio-modes", role: "group", "aria-label": "Mode"}, RadioSet.MODES.map((id) => {
const [name, label, hint] = MODE_LABELS[id];
return h("button", {type: "button", "data-mode": id, "aria-pressed": "false", ...named(label, hint), on: {click: () => {
keepRadio({mode: id});
context();
}}}, icon(name), label);
return h("button", {type: "button", "data-mode": id, "aria-pressed": "false", ...named(label, hint), on: {click: () => pressMode(part, id)}},
icon(name), label, MODE_MENUS[id] ? h("span", {class: "mode-caret", "aria-hidden": "true"}, "▾") : null);
}));
part.face = {lamp, cls, mode, cpu, caption, modes};
part.knobs = knobs();
const menu = h("div", {class: "radio-mode-menu", hidden: true});
Object.assign(part, {face: {lamp, cls, mode, cpu, caption, modes, menu}, menuFor: "", menuSig: "", knobs: knobs()});
const display = h("div", {class: "radio-display", role: "group", "aria-label": "Display"}, lamp, cls, mode, cpu);
return h("div", {class: "radio-face", role: "group", "aria-label": "Radio set"}, display, caption, modes, part.knobs.check,
return h("div", {class: "radio-face", role: "group", "aria-label": "Radio set"}, display, caption, modes, menu,
h("div", {class: "radio-knobs", role: "group", "aria-label": "Knobs"}, part.knobs.rows));
}
function toggleGear(part) {
const open = part.box.hidden;
part.box.replaceChildren(...(open ? [radioFilters()] : []));
part.box.hidden = !open;
part.gear.setAttribute("aria-expanded", String(open));
window.requestAnimationFrame(refresh3d);
}
/**
* @param {boolean} spot whether the bar heads the radio spot.
* @returns {object} the bar part: root, gear, its box and the Cancel mayday button.
* @returns {object} the bar part with its root.
*/
function radioBar(spot) {
const part = {box: h("div", {class: "radio-gear", id: spot ? "radio-gear" : null, hidden: true})};
part.gear = iconBtn("bi-funnel", "Read aloud", "btn small ghost spot-toggle", () => toggleGear(part), "Read aloud: the classes and agents the radio sounds for");
part.gear.setAttribute("aria-expanded", "false");
if (spot) {
part.gear.setAttribute("aria-controls", "radio-gear");
}
const [, label, , hint] = actionOf("clear-mayday");
part.clear = iconBtn("bi-life-preserver", label, "btn small danger", () => confirmAct("clear-mayday", []), hint);
part.clear.disabled = !state.silence;
part.root = h("div", {class: "spot-bar", "data-star-slot": ""}, h("div", {class: "spot-head"}, spot ? h("h3", {class: "group-title"}, "Radio") : null, h("span", {class: "spacer"}), part.gear, part.clear), part.box);
radioParts.bars.push(part);
return part;
}
function drawBars() {
for (const part of liveParts("bars")) {
part.clear.disabled = !state.silence;
}
return {root: h("div", {class: "spot-bar", "data-star-slot": ""}, h("div", {class: "spot-head"}, spot ? h("h3", {class: "group-title"}, "Radio") : null, h("span", {class: "spacer"})))};
}
function cardHead(title, ...tools) {
@@ -270,8 +296,8 @@
}
function speakCard() {
const {form, recipient, text, channel} = composerForm();
const part = {recipient, text, channel, names: ""};
const {form, recipient, text, channel, clear} = composerForm();
const part = {recipient, text, channel, clear, names: ""};
part.root = h("section", {class: "radio-card radio-speak", "data-panel": "radio-speak", "aria-label": "Speak"}, cardHead("Speak"), form);
radioParts.speaks.push(part);
return part;
@@ -281,6 +307,7 @@
const names = agentNames();
const sig = JSON.stringify(names);
for (const part of liveParts("speaks")) {
part.clear.hidden = !state.silence;
if (sig !== part.names) {
part.names = sig;
const chosen = part.recipient.value;
@@ -289,47 +316,20 @@
}
}
function radioFilters() {
const chip = (label, pressed, hint, run, locked) => h("button", {type: "button", class: "chip", "aria-pressed": String(pressed), disabled: locked, ...named(label, hint), on: {click: run}}, label);
const classes = SPEECH_CLASSES.map(([id, label]) => chip(label, radioSet.classes.includes(id), id === "mayday" ? "MAYDAY always sounds" : `Read ${label} aloud`, () => {
keepRadio({classes: radioSet.classes.includes(id) ? radioSet.classes.filter((name) => name !== id) : [...radioSet.classes, id]});
redrawFilters();
}, id === "mayday"));
const agents = Object.entries(people()).sort(([, a], [, b]) => a.now.localeCompare(b.now)).map(([key, entry]) => chip(entry.now, !radioSet.muted.includes(key), `Read ${entry.now} aloud`, () => {
keepRadio({muted: radioSet.muted.includes(key) ? radioSet.muted.filter((name) => name !== key) : [...radioSet.muted, key]});
redrawFilters();
}, false));
const fallbacks = RadioSet.FALLBACKS.map((id) => chip(FALLBACK_LABELS[id][0], radioSet.fallback === id, FALLBACK_LABELS[id][1], () => {
keepRadio({fallback: id});
redrawFilters();
}, false));
return h("div", {class: "radio-read", "aria-label": "Read aloud"},
h("p", {class: "muted"}, state.speech.tts ? "The radio sounds for these classes and agents, each speaker with its own voice; MAYDAY always sounds." : `The hub speaks no line: ${state.speech.tts_off}. The fallback and the procedure words stand in.`),
h("div", {class: "chips", role: "group", "aria-label": "Classes"}, classes),
agents.length ? h("div", {class: "chips", role: "group", "aria-label": "Agents"}, agents) : null,
h("div", {class: "chips radio-fallback", role: "group", "aria-label": "Fallback", title: "Fallback: what plays in Auto above the threshold and in Quiet, kept in this browser"}, h("span", {class: "chips-label"}, "Fallback"), fallbacks),
morseSpeed());
}
function redrawFilters() {
for (const part of liveParts("bars")) {
if (!part.box.hidden) {
part.box.replaceChildren(radioFilters());
}
}
}
function drawRadioSet() {
for (const part of liveParts("devices")) {
for (const button of part.face.modes.querySelectorAll("button[data-mode]")) {
button.setAttribute("aria-pressed", String(button.dataset.mode === radioSet.mode));
}
drawModeMenu(part);
const {tones, squelch, threshold} = part.knobs;
for (const {id, toggle, level} of tones) {
const sound = radioSet.sounds[id];
toggle.setAttribute("aria-pressed", String(sound.on));
toggle.replaceChildren(icon(sound.on ? "bi-bell" : "bi-bell-slash"));
toggle.title = `${toggle.getAttribute("aria-label")}: ${sound.on ? "on, a press mutes it" : "off, a press turns it on"}`;
const bell = RadioSet.bell(radioSet, id);
toggle.setAttribute("aria-pressed", String(bell !== "off"));
toggle.dataset.bell = bell;
toggle.replaceChildren(icon(BELLS[bell][0]));
toggle.title = `${toggle.getAttribute("aria-label")}: ${BELLS[bell][1]}; each press moves on: ${RadioSet.SPOKEN[id].length ? "off, tone, read aloud" : "off, tone"}`;
level.input.value = String(sound.volume);
level.value.textContent = sound.volume.toFixed(2);
}
@@ -346,7 +346,6 @@
drawRadioSet();
drawStations();
drawSpeak();
drawBars();
}
/**
+33 -1
View File
@@ -7,6 +7,7 @@ const RadioSet = (() => {
const FRAME = {bytes: 140, prefix: 8, key: 64};
const TONES = ["mayday", "review", "direct", "radio"];
const CLASSES = ["post", "call", "newsletter", "broadcast", "mayday", "pan-pan", "security"];
const SPOKEN = {mayday: ["mayday", "pan-pan", "security"], review: [], direct: ["post", "call"], radio: ["newsletter", "broadcast"]};
const TO_ALL = new Set(["newsletter", "broadcast", "mayday", "pan-pan", "security"]);
const TABS = ["sent", "received", "all"];
const CHIPS = ["class", "from", "to", "agent"];
@@ -78,6 +79,37 @@ const RadioSet = (() => {
return row.class === "mayday" || (set.classes.includes(row.class) && !set.muted.includes(row.source));
}
/**
* @param {object} set the radio set.
* @param {string} tone one of TONES.
* @returns {string} the bell of that row: off while its tone is off, speak while every class it speaks is read aloud, else tone.
*/
function bell(set, tone) {
if (!set.sounds[tone].on) {
return "off";
}
return SPOKEN[tone].length && SPOKEN[tone].every((name) => set.classes.includes(name)) ? "speak" : "tone";
}
/**
* @param {object} set the radio set.
* @param {string} tone one of TONES.
* @returns {object} the change of sounds and classes that moves the row's bell on: off to tone to speak to off, a row that speaks no class skips speak.
*/
function ring(set, tone) {
const now = bell(set, tone);
const next = now === "off" ? "tone" : now === "tone" && SPOKEN[tone].length ? "speak" : "off";
const rest = set.classes.filter((name) => !SPOKEN[tone].includes(name));
return {
sounds: {...set.sounds, [tone]: {...set.sounds[tone], on: next !== "off"}},
classes: next === "speak" ? [...rest, ...SPOKEN[tone]] : rest,
};
}
function muting(set, key) {
return {muted: set.muted.includes(key) ? set.muted.filter((name) => name !== key) : [...set.muted, key]};
}
/**
* @param {object} row a radio row of the state with class, called, speaker, pitch and text.
* @returns {object} the whole row keyed in Morse as kind "morse", sign, joined, text and pitch: the class prosign, or the called stations of a call, then DE with the sender's clear name and the full text without the hub's message mark, in the sender's pitch.
@@ -272,7 +304,7 @@ const RadioSet = (() => {
return {...entry, chips: Object.fromEntries(CHIPS.map((name) => [name, ""])), q: ""};
}
return {KEY, MODES, FALLBACKS, KEYED, FRAME, TONES, CLASSES, TABS, CHIPS, DEFAULTS, GATE, PROSIGNS, valid, picked, frames, standIn, plan, burst, gateLabel, toAll, ledgerOf, logRows, counts, choices, cleared};
return {KEY, MODES, FALLBACKS, KEYED, FRAME, TONES, CLASSES, SPOKEN, TABS, CHIPS, DEFAULTS, GATE, PROSIGNS, valid, picked, bell, ring, muting, frames, standIn, plan, burst, gateLabel, toAll, ledgerOf, logRows, counts, choices, cleared};
})();
if (typeof module === "object" && module.exports) {
module.exports = RadioSet;
+21 -11
View File
@@ -59,7 +59,7 @@ svg .presence-dot { fill: var(--panel); stroke: currentColor; stroke-width: 1; }
.spot-toggle[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
.radio-spot, .radio-home { container: radio / inline-size; min-width: 0; }
.radio-spot { display: grid; gap: var(--sp-3); margin-bottom: var(--sp-4); padding: var(--sp-3); }
.radio-spot[hidden], .radio-gear[hidden] { display: none; }
.radio-spot[hidden], .radio-mode-menu[hidden] { display: none; }
body.fit .spot-host { flex: none; }
.spot-bar { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.spot-head { display: flex; flex: 1; flex-wrap: wrap; align-items: center; gap: var(--sp-2); min-width: 0; }
@@ -67,7 +67,6 @@ body.fit .spot-host { flex: none; }
.night-picks:empty { display: none; }
.agent-night { align-items: center; margin: 0 0 var(--sp-2); }
.spot-bar { position: relative; }
.radio-gear { position: absolute; top: calc(100% + var(--sp-1)); right: 0; z-index: 12; width: min(36rem, 100%); min-width: 0; padding: var(--sp-3); border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--glass-card); box-shadow: var(--shadow-lift); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); }
.radio-grid { display: grid; grid-template-columns: clamp(22rem, 100% - 34rem - var(--sp-3), 26rem) minmax(0, 1fr); gap: var(--sp-3); min-width: 0; }
.radio-column { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; min-height: 0; }
.radio-card { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius); background: var(--sunken); }
@@ -81,7 +80,11 @@ body.fit .spot-host { flex: none; }
.composer [hidden] { display: none; }
.composer .actions { flex-wrap: wrap; align-items: center; margin-top: 0; }
.composer-hint { flex: 1 1 14em; min-width: 0; margin: 0; font-size: var(--fs-xs); }
.composer .ptt { margin-inline-start: auto; }
.composer .ptt-split { display: inline-flex; margin-inline-start: auto; }
.ptt-split > .ptt { border-start-end-radius: 0; border-end-end-radius: 0; }
.ptt-menu > summary.ptt-more { height: 100%; padding-inline: 6px; border-inline-start: 1px solid color-mix(in srgb, currentColor 30%, transparent); border-start-start-radius: 0; border-end-start-radius: 0; list-style: none; }
.ptt-menu > summary.ptt-more::-webkit-details-marker { display: none; }
.radio-cancel[hidden] { display: none; }
.composer-status { min-width: 0; overflow-wrap: anywhere; }
.voice-note { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.voice-replay { max-width: 100%; height: 34px; }
@@ -89,8 +92,12 @@ body.fit .spot-host { flex: none; }
.mini .voice-replay, .bubble .voice-replay, .radio-row .voice-replay, .popup-box .voice-replay { width: 100%; }
.radio-face { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2); min-width: 0; }
.radio-face > * { grid-column: 1 / -1; }
.radio-face > .radio-modes { grid-column: 1; justify-self: start; }
.radio-face > .radio-check { grid-column: 2; align-self: center; }
.radio-face > .radio-modes { justify-self: start; }
.mode-caret { display: none; margin-inline-start: -2px; font-size: .8em; }
.radio-modes button[aria-pressed="true"] > .mode-caret { display: inline; }
.radio-mode-menu { display: grid; gap: var(--sp-2); padding: var(--sp-2); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); }
.radio-mode-menu .chips { margin-bottom: 0; }
.knob-toggle[data-bell="speak"] { background: var(--accent-soft); color: var(--accent); }
.radio-display { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); min-width: 0; padding: 5px var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); font-family: var(--mono); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.radio-field { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.radio-field[data-field="class"] { font-weight: 700; }
@@ -110,8 +117,6 @@ body.fit .spot-host { flex: none; }
.knob { grid-column: 3; width: 100%; min-width: 0; margin: 0; accent-color: var(--accent); }
.knob-value { grid-column: 4; font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.knob-test { grid-column: 5; }
.radio-read { display: grid; gap: var(--sp-2); }
.radio-read .chips { margin-bottom: 0; }
.radio-fallback .chips-label { color: var(--muted); font-size: var(--fs-sm); }
.morse-speed { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-2); min-width: 0; color: var(--muted); font-size: var(--fs-sm); }
.morse-speed .knob { flex: 1 1 8rem; width: auto; }
@@ -143,6 +148,11 @@ body.fit .spot-host { flex: none; }
.radio-row.picked { box-shadow: inset 3px 0 0 var(--accent); }
.radio-pick { display: flex; flex: 1 1 auto; align-items: center; gap: var(--sp-2); min-width: 0; height: 100%; padding: 0 0 0 8px; overflow: hidden; border: 0; border-radius: var(--radius-sm); background: transparent; color: inherit; font: inherit; line-height: 20px; text-align: left; white-space: nowrap; cursor: pointer; }
.radio-pick > * { flex: none; }
.radio-mute { display: inline-flex; flex: none; margin-inline-start: 6px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.radio-mute .avatar { width: 22px; height: 22px; }
.radio-mute[aria-pressed="true"] .avatar { filter: grayscale(1); opacity: .45; }
.radio-mute[aria-pressed="true"]::after { content: "🔇"; margin-inline-start: -8px; font-size: 10px; line-height: 1; align-self: flex-end; }
.radio-row:has(> .radio-mute) > .radio-pick { padding-inline-start: 0; }
.radio-row time { color: var(--muted); font-variant-numeric: tabular-nums; }
.radio-dir { display: inline-flex; color: var(--muted); }
.radio-row[data-dir="sent"] .radio-dir { color: var(--accent); }
@@ -213,7 +223,7 @@ body.fit .spot-host { flex: none; }
.radio-spot .radio-column { gap: 4px; }
.radio-spot .radio-card { gap: 4px; padding: 4px var(--sp-2); }
.radio-spot .radio-card-head { min-height: 24px; }
.radio-spot .radio-card-head > .star, .radio-spot .knob-row .btn, .radio-spot .radio-check, .radio-spot .radio-filters .btn { padding-block: 2px; }
.radio-spot .radio-card-head > .star, .radio-spot .knob-row .btn, .radio-spot .radio-filters .btn { padding-block: 2px; }
.radio-spot .radio-device { display: grid; grid-template-columns: auto auto minmax(0, max-content) minmax(0, 1fr) auto auto; align-content: start; gap: 4px var(--sp-2); }
.radio-spot .radio-device > :is(.radio-card-head, .radio-face) { display: contents; }
.radio-spot .radio-device > .radio-card-head > .group-title { grid-area: 1 / 1; margin: 0; }
@@ -224,10 +234,10 @@ body.fit .spot-host { flex: none; }
.radio-spot .radio-caption .caption-line { flex: 1 0 4rem; }
.radio-spot .radio-caption .avatar { width: 20px; height: 20px; }
.radio-spot .radio-caption .btn { padding: 4px; }
.radio-spot .radio-modes { grid-area: 2 / 1 / 3 / 6; justify-self: start; padding: 1px; }
.radio-spot .radio-modes { grid-area: 2 / 1 / 3 / -1; justify-self: start; padding: 1px; }
.radio-spot .radio-modes button { padding-block: 2px; }
.radio-spot .radio-check { grid-area: 2 / 6; }
.radio-spot .radio-knobs { grid-area: 3 / 1 / 4 / -1; row-gap: 0; }
.radio-spot .radio-mode-menu { grid-column: 1 / -1; padding: 4px var(--sp-2); }
.radio-spot .radio-knobs { grid-column: 1 / -1; row-gap: 0; }
.radio-spot .knob-row { min-height: 24px; }
.radio-spot .radio-device > .radio-station { grid-column: 1 / -1; padding-top: 4px; }
.radio-spot .radio-station > summary { min-height: 24px; }