feat(hub): radio Morse mode with WPM speed, per-agent pitch and a 0-100 % speech threshold

Morse keys every picked row whole: class prosign (SOS for MAYDAY), DE with the sender's clear name and the full text, after PARIS timing at the hub's morse.wpm (5-40, default 20) and in the sender's own 550-850 Hz tone from the same sha256 slot as its voice. A higher class cuts a keying row, which keys again whole after it. The speech threshold runs 0-100 % in steps of 10, 100 always open, 0 never. The History card moves into page-radiolog.js to keep page-radioview.js under 500 lines.

🎯 Fix: 85 %
💥 Break: 7 %
💸 Tokens: 100 %
⏱️ Velocity: 100 %
🛡️ Security: 100 %
🏆 Score: 79
🚦 Gate: ⛔ fix 85 % < 90, break 7 % > 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-15 09:46:05 +00:00
1 parent ded7c9a7b6
commit 86d539a95f
22 files changed
+1147 -286

No files matched your search

+16 -243
View File
@@ -4,11 +4,8 @@
auto: ["bi-volume-up", "Auto", "Auto: speech while the host CPU lies below the threshold, otherwise the noise burst"],
quiet: ["bi-soundwave", "Quiet", "Quiet: the noise burst only, never speech; 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"],
};
const TAB_LABELS = {sent: ["bi-arrow-up-right", "Sent", "Sent: what you transmitted"], received: ["bi-arrow-down-left", "Received", "Received: radio to you or to all"], all: ["bi-journal-text", "All", "All: every radio row the hub logs"]};
const CHIP_LABELS = {class: "Class", from: "Sender", to: "Recipient", agent: "Agent"};
const COPIED = 1600;
const FOLDED_READERS = 3;
const radioParts = {bars: [], devices: [], logs: [], speaks: []};
const liveParts = (kind) => radioParts[kind].filter((part) => part.root.isConnected);
@@ -92,9 +89,7 @@
mode.textContent = MODE_LABELS[radioSet.mode][1];
cpu.textContent = gate.cpu === null ? "CPU ?" : `CPU ${Math.round(gate.cpu)} %`;
cpu.dataset.open = String(gate.open);
cpu.title = gate.cpu === null
? `No host CPU sample of the last two minutes: the hub renders no new speech line, threshold ${gate.threshold} %`
: `Host CPU ${fixed(gate.cpu)} %: new speech renders below ${gate.threshold} %${gate.open ? "" : ", so the radio plays the burst"}`;
cpu.title = `${gate.cpu === null ? "No host CPU sample of the last two minutes" : `Host CPU ${fixed(gate.cpu)} %`}, threshold: ${RadioSet.gateLabel(gate.threshold)}${gate.open ? "" : ", so the hub renders no new speech line and the radio plays the burst"}`;
}
}
@@ -126,7 +121,8 @@
value.textContent = event.target.value;
change(Number(event.target.value));
}}});
return {input, value, row: h("div", {class: "knob-row", title: hint}, h("span", {class: "knob-label", title: label}, label), input, value)};
const name = h("span", {class: "knob-label", title: label}, label);
return {input, value, name, row: h("div", {class: "knob-row", title: hint}, name, input, value)};
}
function toneKnob(id, label) {
@@ -144,17 +140,22 @@
async function setThreshold(value) {
if (value !== settings.speech.threshold && await saveSettings({...settings, space: savedSpace(), speech: {threshold: value}})) {
toast("Speech threshold saved", [`The hub renders new speech only while the host CPU lies below ${value} %.`], true);
toast("Speech threshold saved", [`The hub renders new speech: ${RadioSet.gateLabel(value)}.`], true);
}
drawRadioSet();
}
function drawGate(gate, value) {
gate.name.textContent = RadioSet.gateLabel(value);
gate.name.title = gate.name.textContent;
gate.value.textContent = `${value} %`;
gate.input.setAttribute("aria-valuetext", gate.name.textContent);
}
function knobs() {
const tones = SOUND_KINDS.map(([id, label]) => toneKnob(id, label));
const squelch = knob("Squelch", "Squelch: scales every tone, the speech and the burst; 0 plays none", {min: 0, max: 1, step: 0.05}, (value) => keepRadio({squelch: value}));
const threshold = knob("Threshold", "Speech threshold: the hub renders new speech only while the host CPU lies below it; your passkey signs each change", {min: 30, max: 90, step: 10}, (value) => {
threshold.value.textContent = `${value} %`;
});
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");
check.disabled = !state.speech.tts;
@@ -294,7 +295,8 @@
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 burst 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);
agents.length ? h("div", {class: "chips", role: "group", "aria-label": "Agents"}, agents) : null,
morseSpeed());
}
function redrawFilters() {
@@ -305,235 +307,6 @@
}
}
function keepLog(change) {
keepRadio({log: {...radioSet.log, ...change}});
}
function chipSelect(name) {
const label = CHIP_LABELS[name];
const select = h("select", {class: "field", "aria-label": label, title: `${label}: filter the log`, on: {change: (event) => keepLog({chips: {...radioSet.log.chips, [name]: event.target.value}})}});
return h("label", {class: "chip-select", "data-chip": name, "data-active": "false"}, select);
}
function fillChip(chip, values) {
const name = chip.dataset.chip;
const chosen = radioSet.log.chips[name];
const options = [...new Set([...values, ...(chosen ? [chosen] : [])])];
const select = chip.querySelector("select");
const sig = JSON.stringify([options, chosen || ""]);
if (select.sig !== sig) {
select.sig = sig;
select.replaceChildren(h("option", {value: ""}, `${CHIP_LABELS[name]}: any`), ...options.map((value) => h("option", {value, selected: value === chosen}, name === "class" ? CLASSES[value] || value : value)));
}
setAttr(chip, "data-active", String(Boolean(chosen)));
}
function setAttr(node, name, value) {
if (node.getAttribute(name) !== value) {
node.setAttribute(name, value);
}
}
function setText(node, value) {
if (node.textContent !== value) {
node.textContent = value;
}
}
function firstLine(text) {
return text.split("\n").map((part) => part.trim()).find(Boolean) || "";
}
function logLine(row) {
const message = row.sent ? row : RadioSet.ledgerOf(row, state.messages);
const sent = Boolean(message);
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)}},
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)),
klass(row.class),
h("span", {class: "radio-route"}, `${row.from} → ${targetsOf(row)}`),
h("span", {class: "radio-line"}, first)),
foldedReaders(row));
line.row = row;
return line;
}
function keepLine(kept, fresh) {
kept.row = fresh.row;
if (kept.outerHTML === fresh.outerHTML) {
return kept;
}
for (const name of ["data-dir", "data-class"]) {
setAttr(kept, name, fresh.getAttribute(name));
}
const [pick, twin] = [kept.querySelector(".radio-pick"), fresh.querySelector(".radio-pick")];
setAttr(pick, "title", twin.getAttribute("title"));
pick.replaceChildren(...twin.childNodes);
for (const node of [...kept.children].filter((child) => child !== pick)) {
node.remove();
}
kept.append(...[...fresh.children].filter((child) => child !== twin));
return kept;
}
function patchList(list, lines) {
const before = [...list.children];
const focused = before.find((node) => node.contains(document.activeElement)) || null;
const old = new Map(before.filter((node) => node.dataset.key).map((node) => [node.dataset.key, node]));
const wanted = lines.map((line) => {
const kept = old.get(line.dataset.key);
old.delete(line.dataset.key);
return kept ? keepLine(kept, line) : line;
});
const keep = new Set(wanted);
for (const node of before.filter((child) => !keep.has(child))) {
node.remove();
}
wanted.forEach((node, index) => {
if (list.children[index] !== node) {
list.insertBefore(node, list.children[index] || null);
}
});
if (focused && !focused.isConnected) {
const at = before.indexOf(focused);
const near = before.filter((node) => node.isConnected && node.querySelector(".radio-pick")).sort((a, b) => Math.abs(before.indexOf(a) - at) - Math.abs(before.indexOf(b) - at))[0];
(near ? near.querySelector(".radio-pick") : list).focus({preventScroll: true});
}
}
function foldedReaders(row) {
const strip = readerRow(row);
const {shown, hidden} = Receipts.strip(row);
const rest = shown.length + hidden.length - FOLDED_READERS;
if (strip && rest > 0) {
strip.append(h("span", {class: "readers-more readers-fold", role: "img", ...named(`${rest} more readers`, [...shown, ...hidden].slice(FOLDED_READERS).map(readLabel).join("\n"))}, `+${rest}`));
}
return strip;
}
function readerLine(reader) {
const known = reader.read !== null && reader.read !== undefined;
return h("li", {class: "popup-reader", "data-session": reader.session, "data-acked": String(reader.acked)},
face(people()[reader.session] ? reader.session : reader.name, false),
h("strong", {}, reader.name),
h("span", {class: "muted"}, known ? `read ${reader.approximate ? "about " : ""}${absolute.format(stampOf(reader.read))}` : "read, time unknown"),
reader.acked ? pill("acknowledged", "ok") : null);
}
function copyText(text) {
const said = h("span", {class: "radio-said", role: "status", "aria-live": "polite"});
const button = h("button", {type: "button", class: "btn small radio-copy", ...named("Copy", "Copy: the full message to the clipboard")}, icon("bi-clipboard"), h("span", {}, "Copy"));
const show = (name, word, done, note) => {
button.replaceChildren(icon(name), h("span", {}, word));
button.setAttribute("aria-label", word);
button.dataset.copied = done;
said.textContent = note;
};
button.addEventListener("click", async () => {
try {
await navigator.clipboard.writeText(text);
show("bi-clipboard-check", "Copied", "true", "Copied: the full message is on the clipboard");
} catch {
show("bi-x-circle", "Not copied", "false", "Not copied: the browser refused the clipboard");
}
window.setTimeout(() => show("bi-clipboard", "Copy", "", ""), COPIED);
});
return [button, said];
}
function replyTarget(list) {
const home = list ? list.closest(".radio-home") : null;
if (!home) {
return spotDom.speak;
}
const homes = liveParts("speaks").filter((part) => part.root.closest(".radio-home"));
return homes.find((part) => home.contains(part.root)) || homes.find((part) => part.root.closest(".radio-home-radio-speak")) || homes[0] || spotDom.speak;
}
function replyTo(row, list) {
const who = row.from === HUMAN && row.to.length ? row.to[0] : row.from;
const part = replyTarget(list);
closePopup();
if (part === spotDom.speak) {
openSpot(true);
}
part.channel.value = "post";
part.channel.dispatchEvent(new Event("change", {bubbles: true}));
if (![...part.recipient.options].some((option) => option.value === who)) {
part.recipient.append(h("option", {value: who}, who));
}
part.recipient.value = who;
part.text.focus();
}
function openRadioRow(row, li) {
const message = row.sent ? row : RadioSet.ledgerOf(row, state.messages);
const {shown, hidden} = Receipts.strip(row);
const readers = [...shown, ...hidden];
const list = li.closest("ul");
const anchor = () => (list ? [...list.querySelectorAll(".radio-row")].find((item) => item.dataset.key === row.key) || null : null);
openPopup(`Radio message from ${row.from}`, [
popupHead(klass(row.class), `${row.from} → ${targetsOf(row)}`),
meta([["Sender", row.from], ["Recipient", targetsOf(row)], ["Class", CLASSES[row.class] || row.class], ["Time", absolute.format(stampOf(row.ts))]]),
h("pre", {class: "radio-full"}, row.text),
voiceReplay(message ? message.voice : null),
h("div", {class: "actions radio-actions"},
h("button", {type: "button", class: "btn small primary radio-reply", ...named("Reply", "Reply: a post to the sender in the speak card"), on: {click: () => replyTo(row, list)}}, icon("bi-reply"), "Reply"),
copyText(row.text)),
h("h3", {}, readers.length ? `Read by ${readers.length}` : "Read by nobody yet"),
readers.length ? h("ul", {class: "popup-readers"}, readers.map(readerLine)) : null,
].filter(Boolean), anchor);
}
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)]);
for (const dom of liveParts("logs")) {
if (sig !== dom.sig) {
dom.sig = sig;
drawLogPart(dom, entry);
}
}
}
function drawLogPart(dom, entry) {
const counts = RadioSet.counts(state.radio, HUMAN, state.messages);
for (const button of dom.tabs.children) {
const {tab} = button.dataset;
const count = button.querySelector(".count");
setAttr(button, "aria-selected", String(tab === entry.tab));
setAttr(count, "aria-label", `${counts[tab]} rows`);
setText(count, String(counts[tab]));
}
const choices = RadioSet.choices(state.radio);
for (const chip of dom.chips.children) {
fillChip(chip, choices[chip.dataset.chip]);
}
if (document.activeElement !== dom.search && dom.search.value !== entry.q) {
dom.search.value = entry.q;
}
const rows = RadioSet.logRows(state.radio, entry, HUMAN, state.messages);
patchList(dom.list, rows.length ? rows.map(logLine) : [h("li", {class: "muted"}, state.radio.length ? "No radio row matches the tab, the chips and the search." : "No radio in the chosen time range yet.")]);
}
function historyCard() {
const tabs = h("div", {class: "radio-tabs", role: "tablist", "aria-label": "Log"}, RadioSet.TABS.map((tab) => {
const [name, label, hint] = TAB_LABELS[tab];
return h("button", {type: "button", role: "tab", "data-tab": tab, "aria-selected": "false", title: hint, on: {click: () => keepLog({tab})}}, icon(name), label, h("span", {class: "count"}));
}));
const chips = h("div", {class: "radio-chips", role: "group", "aria-label": "Log filters"}, RadioSet.CHIPS.map(chipSelect));
const search = h("input", {type: "search", class: "field", placeholder: "Search the log …", maxlength: 200, ...named("Search the log"), on: {input: (event) => keepLog({q: event.target.value})}});
const clear = iconBtn("bi-x-circle", "Clear filters", "btn small ghost", () => keepRadio({log: RadioSet.cleared(radioSet.log)}), "Clear filters: every chip and the search");
const list = h("ul", {class: "radio-log", tabindex: "-1", "aria-label": "Radio log"});
const part = {tabs, chips, search, list, sig: ""};
part.root = h("section", {class: "radio-card radio-logbox", "data-panel": "radio-log", "aria-label": "Radio log"}, cardHead("History", tabs, search), h("div", {class: "radio-filters"}, chips, clear), list);
radioParts.logs.push(part);
return part;
}
function drawRadioSet() {
for (const part of liveParts("devices")) {
for (const button of part.face.modes.querySelectorAll("button[data-mode]")) {
@@ -551,7 +324,7 @@
squelch.input.value = String(radioSet.squelch);
squelch.value.textContent = radioSet.squelch.toFixed(2);
threshold.input.value = String(settings.speech.threshold);
threshold.value.textContent = `${settings.speech.threshold} %`;
drawGate(threshold, settings.speech.threshold);
}
drawDisplay();
drawLog();