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:
1 parent
ded7c9a7b6
commit
86d539a95f
22 files changed
+1147
-286
No files matched your search
@@ -277,6 +277,71 @@ LIGHT = """(async () => {@HELPERS@@RADIO@
|
||||
await sleep(1500);
|
||||
return {violations: window.e2eViolations};
|
||||
})()"""
|
||||
WPMS = {1920: 12, 1366: 25, 390: 40}
|
||||
MORSE_SPY = """() => {
|
||||
(@SPY@)();
|
||||
const keyed = window.e2eMorse = [];
|
||||
const start = OscillatorNode.prototype.start;
|
||||
OscillatorNode.prototype.start = function keying(...args) {
|
||||
this.e2e = {frequency: this.frequency.value, type: this.type, start: args[0], stop: null, cut: false};
|
||||
keyed.push(this.e2e);
|
||||
return start.apply(this, args);
|
||||
};
|
||||
const stop = OscillatorNode.prototype.stop;
|
||||
OscillatorNode.prototype.stop = function unkeying(...args) {
|
||||
if (this.e2e && args[0] === undefined) {
|
||||
this.e2e.cut = true;
|
||||
} else if (this.e2e) {
|
||||
this.e2e.stop = args[0];
|
||||
}
|
||||
return stop.apply(this, args);
|
||||
};
|
||||
}""".replace("@SPY@", SPY)
|
||||
MORSE_KEYED = """
|
||||
const keyed = () => window.e2eMorse.filter((entry) => entry.stop !== null && entry.stop - entry.start > 1);
|
||||
const speed = () => spot.querySelector('#radio-gear input[aria-label="Morse speed"]');
|
||||
const rate = () => text(spot.querySelector("#radio-gear .morse-rate"));
|
||||
const gear = () => all(".spot-head button", spot).find((button) => name(button) === "Read aloud");
|
||||
"""
|
||||
MORSE = """(async () => {@HELPERS@@RADIO@@KEYED@
|
||||
press("morse");
|
||||
await sleep(200);
|
||||
const mode = [pressed(), field("mode"), spot.querySelector('.radio-modes button[data-mode="morse"]').title];
|
||||
if (gear().getAttribute("aria-expanded") !== "true") {
|
||||
gear().click();
|
||||
await sleep(200);
|
||||
}
|
||||
const before = [speed().min, speed().max, speed().step, speed().value, rate()];
|
||||
speed().value = "@WPM@";
|
||||
speed().dispatchEvent(new Event("input", {bubbles: true}));
|
||||
const dragged = rate();
|
||||
speed().dispatchEvent(new Event("change", {bubbles: true}));
|
||||
const toast = await until(() => all("#toasts .toast strong").map(text).includes("Morse speed saved"), 15000);
|
||||
await sleep(300);
|
||||
const saved = [speed().value, rate()];
|
||||
const gearFits = fits();
|
||||
gear().click();
|
||||
await sleep(200);
|
||||
const at = {tts: audio().tts.length, keyed: keyed().length};
|
||||
await cue("alarm");
|
||||
refreshNow();
|
||||
const playing = await until(() => keyed().length > at.keyed && lamp().dataset.lit === "true", 20000);
|
||||
const caption = spot.querySelector(".radio-caption");
|
||||
return {
|
||||
mode, before, dragged, toast: Boolean(toast), saved, gearFits, playing: Boolean(playing), keyed: keyed().slice(at.keyed), tts: audio().tts.length - at.tts,
|
||||
lamp: [text(lamp()), lamp().dataset.lit], caption: [caption.hidden, text(caption.querySelector("strong"))], fits: fits(),
|
||||
};
|
||||
})()""".replace("@KEYED@", MORSE_KEYED)
|
||||
MORSE_STOP = """(async () => {@HELPERS@@RADIO@@KEYED@
|
||||
const last = keyed()[keyed().length - 1];
|
||||
const caption = spot.querySelector(".radio-caption");
|
||||
const stop = all("button", caption).find((button) => name(button) === "Stop speaking");
|
||||
const before = [Boolean(stop), lamp().dataset.lit, last.cut];
|
||||
stop.click();
|
||||
const quiet = Boolean(await until(() => lamp().dataset.lit === "false", 2000));
|
||||
await sleep(500);
|
||||
return {before, cut: last.cut, quiet, hidden: caption.hidden, later: keyed().filter((entry) => !entry.cut).length};
|
||||
})()""".replace("@KEYED@", MORSE_KEYED)
|
||||
|
||||
|
||||
def probe(template: str) -> str:
|
||||
|
||||
@@ -304,7 +304,7 @@ class TestHubRadio(base.OrchestratorE2ECase):
|
||||
self.assertEqual((run["direct"], run["question"], run["left"]), (direct, [mayday] if run["cls"] == "mayday" else [], ""), run)
|
||||
self.assertTrue((run["toast"] or "").startswith(f"{labels[run['cls']]} to {'Stage' if direct else 'all'}: sent"), run)
|
||||
self.assertEqual((saved["expanded"], saved["clashes"]), ("true", [{"found": [], "outside": []}] * 2))
|
||||
self.assertEqual(saved["tones"], ["MAYDAY / PAN-PAN", "Reviews, asks, decisions", "Post and calls to you", "All radio", "Squelch", "Threshold"])
|
||||
self.assertEqual(saved["tones"], ["MAYDAY / PAN-PAN", "Reviews, asks, decisions", "Post and calls to you", "All radio", "Squelch", "speak while CPU < 50 %"])
|
||||
self.assertEqual([entry[0] for entry in saved["classes"]], ["Post", "Call", "Newsletter", "Broadcast", "MAYDAY", "PAN-PAN", "Sécurité"])
|
||||
self.assertEqual([entry[1:] for entry in saved["classes"] if entry[0] == "MAYDAY"], [["true", True]])
|
||||
self.assertEqual((saved["kept"], saved["after"]), ([float(squelch), tone == "true", post == "true"], ["false", False]))
|
||||
|
||||
@@ -16,7 +16,7 @@ import hub_e2e_kit as base
|
||||
from hub_case import HubCase
|
||||
from hub_engines import log_rows
|
||||
from hub_support import iso
|
||||
from kvb_orchestrator import errors, phrasing, speechgate
|
||||
from kvb_orchestrator import engines, errors, phrasing, speechgate
|
||||
from radio_set_kit import (
|
||||
BURST,
|
||||
BURST_DONE,
|
||||
@@ -26,6 +26,9 @@ from radio_set_kit import (
|
||||
LIGHT,
|
||||
LOG,
|
||||
LOG_KEPT,
|
||||
MORSE,
|
||||
MORSE_SPY,
|
||||
MORSE_STOP,
|
||||
OUT,
|
||||
SOUND,
|
||||
SOUND_KEPT,
|
||||
@@ -33,6 +36,7 @@ from radio_set_kit import (
|
||||
THRESHOLD,
|
||||
THRESHOLDS,
|
||||
WORD,
|
||||
WPMS,
|
||||
probe,
|
||||
)
|
||||
|
||||
@@ -132,12 +136,13 @@ class TestRadioSet(HubCase):
|
||||
self.assertEqual(face["display"]["mode"], "Auto")
|
||||
self.assertEqual((face["display"]["cpu"], face["display"]["lamp"]), ("CPU 10 %", ["RX", "false"]), face)
|
||||
self.assertTrue(face["display"]["cls"], face)
|
||||
self.assertEqual([mode_[:2] for mode_ in face["modes"]], [["Auto", "true"], ["Quiet", "false"], ["Silence", "false"]])
|
||||
self.assertEqual([mode_[:2] for mode_ in face["modes"]], [["Auto", "true"], ["Quiet", "false"], ["Silence", "false"], ["Morse", "false"]])
|
||||
self.assertTrue(all(mode_[2] and mode_[3] for mode_ in face["modes"]), face["modes"])
|
||||
self.assertEqual([knob[0] for knob in face["knobs"]], ["MAYDAY / PAN-PAN", "Reviews, asks, decisions", "Post and calls to you", "All radio", "Squelch", "Threshold"])
|
||||
self.assertEqual(face["knobs"][-1][1:], ["30", "90", "10", "50" if index == 0 or not signed else str(THRESHOLDS[base.WIDTHS[index - 1][0]])])
|
||||
shown = "50" if index == 0 or not signed else str(THRESHOLDS[base.WIDTHS[index - 1][0]])
|
||||
self.assertEqual(face["knobs"][-1][1:], ["0", "100", "10", shown])
|
||||
self.assertEqual(len(face["toneToggles"]), 4)
|
||||
self.assertEqual([label["text"] for label in face["labels"]], [knob[0] for knob in face["knobs"]])
|
||||
self.assertEqual([label["text"] for label in face["labels"]], [*(knob[0] for knob in face["knobs"][:-1]), f"speak while CPU < {shown} %"])
|
||||
for label in face["labels"]:
|
||||
self.assertEqual((label["title"], label["row"]), (label["text"], True), label)
|
||||
self.assertTrue(label["whole"] or width == 390, label)
|
||||
@@ -217,7 +222,7 @@ class TestRadioSet(HubCase):
|
||||
if signed:
|
||||
self.assertEqual(threshold["after"], [value, threshold["before"][1] + 1], threshold)
|
||||
self.assertEqual(threshold["shown"], f"{value} %")
|
||||
self.assertIn(f"below {value} %", threshold["title"])
|
||||
self.assertIn(f"speak while CPU < {value} %", threshold["title"])
|
||||
else:
|
||||
self.assertEqual(threshold["after"], [threshold["before"][0], threshold["before"][1]], threshold)
|
||||
self.assertIn("Settings: not signed", threshold["toasts"])
|
||||
@@ -228,6 +233,54 @@ class TestRadioSet(HubCase):
|
||||
self.assertEqual(len(words), 1, "the procedure word line of one voice renders once and then hits the cache")
|
||||
self.assertEqual(self.httpd.hub.settings.get()["speech"]["threshold"], THRESHOLDS[390] if signed else 50)
|
||||
|
||||
def morse_steps(self, browser: str) -> list[dict]:
|
||||
steps = []
|
||||
for width, height in base.WIDTHS:
|
||||
shot = str(OUT / f"{browser}-{width}-radio-morse")
|
||||
steps += [
|
||||
{"width": width, "height": height, "url": f"{self.base}?{width}-morse#stream", "wait": 1200, "probe": probe(MORSE).replace("@WPM@", str(WPMS[width])), "shot": f"{shot}-keying.png", "gesture": True},
|
||||
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(MORSE_STOP), "shot": f"{shot}-stopped.png", "gesture": True},
|
||||
]
|
||||
return steps
|
||||
|
||||
def check_morse(self, data: dict, browser: str) -> None:
|
||||
results = iter(data["results"])
|
||||
before = 20
|
||||
for width, _ in base.WIDTHS:
|
||||
keying, stopped = next(results), next(results)
|
||||
wpm = WPMS[width]
|
||||
with self.subTest(browser=browser, width=width, part="morse keying"):
|
||||
self.assertNotIn("error", keying, keying)
|
||||
self.assertEqual(keying["mode"][:2], [["morse"], "Morse"], keying)
|
||||
self.assertIn("SOS", keying["mode"][2])
|
||||
self.assertEqual(keying["before"], ["5", "40", "1", str(before), f"{before} WPM ({before * 50} dots/min)"], keying)
|
||||
self.assertEqual((keying["dragged"], keying["toast"], keying["saved"]), (f"{wpm} WPM ({wpm * 50} dots/min)", True, [str(wpm), f"{wpm} WPM ({wpm * 50} dots/min)"]), keying)
|
||||
self.assertTrue(keying["playing"], keying)
|
||||
self.assertEqual([(entry["frequency"], entry["type"]) for entry in keying["keyed"]], [(engines.pitch_of("s2"), "sine")], keying)
|
||||
self.assertEqual(keying["tts"], 0, "Morse mode asks the hub for no speech line")
|
||||
self.assertEqual(keying["lamp"], ["RX", "true"])
|
||||
self.assertFalse(keying["caption"][0])
|
||||
self.assertTrue(keying["caption"][1].startswith("Stage"), keying)
|
||||
self.assertEqual((keying["gearFits"], keying["fits"]), ({"page": True, "panel": True}, {"page": True, "panel": True}), keying)
|
||||
with self.subTest(browser=browser, width=width, part="morse stop"):
|
||||
self.assertNotIn("error", stopped, stopped)
|
||||
self.assertEqual(stopped, {"before": [True, "true", False], "cut": True, "quiet": True, "hidden": True, "later": 0}, stopped)
|
||||
before = wpm
|
||||
self.assertEqual(self.httpd.hub.settings.get()["morse"], {"wpm": WPMS[390]})
|
||||
|
||||
def test_chromium_keys_every_row_whole_in_morse_at_the_hub_speed_in_its_sender_pitch_and_stop_cuts_it_at_three_widths(self):
|
||||
data = self.drive(self.morse_steps("chromium"), None, init=MORSE_SPY)
|
||||
(OUT / "chromium-radio-morse.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
|
||||
self.assertEqual(data["errors"], [])
|
||||
self.check_morse(data, "chromium")
|
||||
|
||||
@unittest.skipUnless(shutil.which(os.environ.get("FIREFOX", "firefox")), "no Firefox")
|
||||
def test_firefox_keys_every_row_whole_in_morse_at_the_hub_speed_in_its_sender_pitch_and_stop_cuts_it_at_three_widths(self):
|
||||
data = self.drive(self.morse_steps("firefox"), None, "bidi.mjs", os.environ.get("FIREFOX", "firefox"), init=MORSE_SPY)
|
||||
(OUT / "firefox-radio-morse.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
|
||||
self.assertEqual([error for error in data["errors"] if "/favicon.ico" not in error], [])
|
||||
self.check_morse(data, "firefox")
|
||||
|
||||
def test_chromium_plays_the_radio_set_modes_burst_and_procedure_words_and_filters_the_log_at_three_widths(self):
|
||||
data = self.drive(self.steps("chromium", True), self.authenticator(), init=SPY)
|
||||
(OUT / "chromium-radio-set.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
|
||||
|
||||
Reference in new issue
Block a user