feat(orchestrator): choose notification channels in the settings
Settings store the notification channels (browser, sound, speech) instead of one notify flag, migrating the old flag to the browser channel; alerts and speech follow the chosen channels. Tests run once on unify/skills-20261114 after the merge (operator order 2026-11-14). 🎯 Fix: 85 % 💥 Break: 8 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % 🏆 Score: 78 🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
48f26b678a
commit
41e262407c
10 files changed
+361
-12
No files matched your search
@@ -33,7 +33,7 @@ SETTINGS = {
|
||||
"theme": "sky",
|
||||
"colors": {"top": "#0b1020", "bottom": "#2b3a67", "accent": "#8fadff"},
|
||||
"music": {"on": False, "volume": 0.4},
|
||||
"notify": True,
|
||||
"channels": {"browser": True, "sounds": True, "aloud": True, "title": True},
|
||||
"streams": [],
|
||||
"speech": {"threshold": 50},
|
||||
"space": {
|
||||
@@ -188,7 +188,7 @@ def valid_settings(raw: object) -> dict:
|
||||
"theme": data["theme"],
|
||||
"colors": {key: color(colors[key], f"colors.{key}") for key in SETTINGS["colors"]},
|
||||
"music": {"on": flag(music["on"], "music.on"), "volume": number_in(music["volume"], "music.volume", 0.0, 1.0)},
|
||||
"notify": flag(data["notify"], "notify"),
|
||||
"channels": channels_setting(data["channels"]),
|
||||
"streams": [stream_entry(entry, index) for index, entry in enumerate(data["streams"])],
|
||||
"speech": speech_setting(data["speech"]),
|
||||
"space": space_setting(data["space"]),
|
||||
@@ -216,6 +216,22 @@ def radio_moved(stored: object) -> object:
|
||||
return {**others, "speech": rest} if rest else others
|
||||
|
||||
|
||||
def channels_setting(raw: object) -> dict:
|
||||
entry = section(raw, "channels", tuple(SETTINGS["channels"]))
|
||||
return {name: flag(entry[name], f"channels.{name}") for name in SETTINGS["channels"]}
|
||||
|
||||
|
||||
def notify_moved(stored: object) -> object:
|
||||
"""Returns:
|
||||
The stored settings with the old notify flag as the browser channel
|
||||
and every other channel on; stored channels win over the flag.
|
||||
"""
|
||||
if not isinstance(stored, dict) or "notify" not in stored:
|
||||
return stored
|
||||
kept = {key: value for key, value in stored.items() if key != "notify"}
|
||||
return {"channels": {**SETTINGS["channels"], "browser": stored["notify"]}, **kept}
|
||||
|
||||
|
||||
def migrated(stored: object) -> object:
|
||||
"""Returns:
|
||||
The stored settings in the current shape: the radio set moved to the
|
||||
@@ -223,7 +239,7 @@ def migrated(stored: object) -> object:
|
||||
it may have been saved without the passkey, so the hub never dials
|
||||
it unsigned; re-adding it with the passkey resolves its redirects.
|
||||
"""
|
||||
stored = radio_moved(stored)
|
||||
stored = notify_moved(radio_moved(stored))
|
||||
streams = stored.get("streams") if isinstance(stored, dict) else None
|
||||
if not isinstance(streams, list):
|
||||
return stored
|
||||
|
||||
@@ -42,6 +42,19 @@
|
||||
button.disabled = permission !== "default";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} before the channels of the settings the page held until now.
|
||||
*/
|
||||
function syncChannels(before) {
|
||||
if (before.sounds && !settings.channels.sounds) {
|
||||
silenceBeeps();
|
||||
}
|
||||
if (before.aloud && !settings.channels.aloud) {
|
||||
cancelSpeech();
|
||||
}
|
||||
drawTitle();
|
||||
}
|
||||
|
||||
async function askNotify() {
|
||||
if ("Notification" in window) {
|
||||
await Notification.requestPermission();
|
||||
@@ -58,13 +71,13 @@
|
||||
const newRadio = state.radio.filter((row) => !known.radio.has(`${row.ts}|${row.from}|${row.text.slice(0, 40)}`));
|
||||
const direct = newRadio.filter((row) => row.to.includes(HUMAN));
|
||||
const present = {mayday: newAlarms.length > 0, review: fresh.some((item) => item.kind !== "operator"), direct: direct.length > 0, radio: newRadio.length > 0};
|
||||
const kind = radioSet.mode === "silence" ? null : Voice.beep(present, tones(), SOUND_KINDS.map(([id]) => id));
|
||||
const kind = radioSet.mode === "silence" || !settings.channels.sounds ? null : Voice.beep(present, tones(), SOUND_KINDS.map(([id]) => id));
|
||||
if (kind) {
|
||||
play(kind, loudness(kind));
|
||||
}
|
||||
const lead = kind ? Math.max(...TONES[kind].map(([, at, length]) => at + length)) : 0;
|
||||
window.setTimeout(() => speakRows(newRadio), lead * 1000);
|
||||
if (settings.notify && "Notification" in window && Notification.permission === "granted") {
|
||||
if (settings.channels.browser && "Notification" in window && Notification.permission === "granted") {
|
||||
for (const row of newAlarms) {
|
||||
new Notification(`${row.class === "mayday" ? "Mayday" : "Pan-Pan"} from ${dash(row.from)}`, {body: row.text.slice(0, 200), tag: `alarm-${row.ts}`, requireInteraction: row.class === "mayday"});
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
const STATE_TIMEOUT = 15000;
|
||||
const THEME_CHOICES = [["sky", "Sky (follows the light outside)"], ["light", "Always light"], ["dark", "Always dark"], ["custom", "Custom colors"]];
|
||||
const COLOR_FIELDS = [["top", "Sky at the top"], ["bottom", "Sky at the horizon"], ["accent", "Accent"]];
|
||||
const CHANNEL_CHOICES = [["browser", "Desktop notifications when the browser allows them"], ["sounds", "Sound tones"], ["aloud", "Read radio aloud"], ["title", "Waiting count in the tab title"]];
|
||||
const STAGE_LABELS = {night: "Night", astronomical: "Astronomical twilight", nautical: "Nautical twilight", civil: "Civil twilight", golden: "Golden hour", day: "Day"};
|
||||
const WEEKDAYS = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
||||
const COMPASS = [["N", "North"], ["NE", "Northeast"], ["E", "East"], ["SE", "Southeast"], ["S", "South"], ["SW", "Southwest"], ["W", "West"], ["NW", "Northwest"]];
|
||||
|
||||
@@ -107,10 +107,14 @@
|
||||
const silence = state.silence;
|
||||
banner.hidden = !silence;
|
||||
banner.replaceChildren(...(silence ? [h("p", {class: "text"}, `MAYDAY · ${dash(silence.by)}: ${silence.text}`), iconBtn("bi-x-octagon", "cancel", "btn small", () => confirmAct("clear-mayday", []), "cancel: end the mayday (radio.py clear)")] : []));
|
||||
document.title = `${state.badges.tasks ? `(${state.badges.tasks}) ` : ""}Agent Orchestrator`;
|
||||
drawTitle();
|
||||
window.setTimeout(measure, 0);
|
||||
}
|
||||
|
||||
function drawTitle() {
|
||||
document.title = `${settings.channels.title && state.badges.tasks ? `(${state.badges.tasks}) ` : ""}Agent Orchestrator`;
|
||||
}
|
||||
|
||||
function toggleLeitstand() {
|
||||
const on = !document.body.classList.contains("leitstand");
|
||||
document.body.classList.toggle("leitstand", on);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
let redirectsTold = "";
|
||||
|
||||
function adoptSettings(next) {
|
||||
const before = settings.channels;
|
||||
settings = next;
|
||||
settingsSig = JSON.stringify(next);
|
||||
if (space.edits === space.saved) {
|
||||
@@ -14,6 +15,7 @@
|
||||
syncRadio();
|
||||
musicButton();
|
||||
syncBubbles();
|
||||
syncChannels(before);
|
||||
}
|
||||
|
||||
async function saveSettings(next) {
|
||||
@@ -125,7 +127,7 @@
|
||||
judge();
|
||||
const musicOn = h("input", {type: "checkbox", checked: settings.music.on});
|
||||
const volume = h("input", {type: "range", min: 0, max: 1, step: 0.05, value: settings.music.volume, "aria-label": "Overall volume"});
|
||||
const notify = h("input", {type: "checkbox", checked: settings.notify});
|
||||
const channels = Object.fromEntries(CHANNEL_CHOICES.map(([id]) => [id, h("input", {type: "checkbox", name: `channel-${id}`, checked: settings.channels[id]})]));
|
||||
const form = h("form", {class: "settings"},
|
||||
ambience(),
|
||||
h("section", {}, h("h3", {}, "Location"), h("p", {class: "muted"}, "Sun, moon and stars stand where you see them from here, looking south; under 🔭 Sky (key h) you turn the view. Decimal degrees, north and east positive."),
|
||||
@@ -133,8 +135,8 @@
|
||||
h("section", {}, h("h3", {}, "Appearance"), h("label", {}, "Colors", theme), custom, verdict),
|
||||
h("section", {}, h("h3", {}, "Music"), h("p", {class: "muted"}, "Generative ambient music, made offline: calm with an empty inbox, a little tenser when something waits, quieter under messages."),
|
||||
h("div", {class: "grid"}, h("label", {class: "check"}, musicOn, "Music on"), h("label", {}, "Overall volume (music and radio)", volume))),
|
||||
h("section", {}, h("h3", {}, "Notifications"), h("p", {class: "muted"}, "Mode, tones, squelch, the speech threshold, reading aloud and the stations sit in the radio panel behind the radio button in the header."),
|
||||
h("label", {class: "check"}, notify, "Show desktop notifications when the browser allows them")),
|
||||
h("section", {}, h("h3", {}, "Notifications"), h("p", {class: "muted"}, "Each channel switches one way the hub tells you about something new. Which kinds sound and which classes are read aloud, the mode, squelch, speech threshold and stations sit in the radio panel behind the radio button in the header."),
|
||||
h("fieldset", {class: "grid channels"}, h("legend", {}, "Notification channels"), CHANNEL_CHOICES.map(([id, label]) => h("label", {class: "check"}, channels[id], label)))),
|
||||
passkeySection(),
|
||||
h("div", {class: "sheet-foot"}, h("span", {class: "spacer"}), btn("Cancel", "btn ghost", closeSheet), h("button", {type: "submit", class: "btn primary"}, "Save")));
|
||||
form.addEventListener("submit", async (event) => {
|
||||
@@ -146,7 +148,7 @@
|
||||
theme: theme.value,
|
||||
colors: Object.fromEntries(COLOR_FIELDS.map(([id]) => [id, colors[id].value])),
|
||||
music: {on: musicOn.checked, volume: Number(volume.value)},
|
||||
notify: notify.checked,
|
||||
channels: Object.fromEntries(CHANNEL_CHOICES.map(([id]) => [id, channels[id].checked])),
|
||||
streams: settings.streams,
|
||||
speech: settings.speech,
|
||||
space: savedSpace(),
|
||||
|
||||
@@ -245,7 +245,7 @@
|
||||
|
||||
function speakRows(rows) {
|
||||
for (const row of rows.filter((entry) => entry.ts >= state.now - SPEECH_FRESH)) {
|
||||
const steps = RadioSet.plan(row, radioSet, liveSpeech());
|
||||
const steps = settings.channels.aloud ? RadioSet.plan(row, radioSet, liveSpeech()) : [];
|
||||
if (steps.length || (settings.bubbles && Bubbles.picked(row, radioSet))) {
|
||||
const line = row.text.split("\n").map((part) => part.trim()).find(Boolean) || "";
|
||||
say({row, voice: row.voice, tone: Voice.toneOf(row, HUMAN), cls: row.class, who: row.source, sent: Boolean(RadioSet.ledgerOf(row, state.messages)), line: short(line), words: Bubbles.words(row.text), silent: !steps.length});
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
.rule-form { grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
|
||||
.rule-form > label, .settings .grid > label { min-width: 0; }
|
||||
.rule-form .field, .settings .grid .field { width: 100%; min-width: 0; }
|
||||
.settings fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
|
||||
.settings legend { margin-bottom: var(--sp-2); padding: 0; color: var(--muted); font-size: var(--fs-sm); }
|
||||
.rule-form [hidden] { display: none; }
|
||||
.rule-form > label.check { display: inline-flex; min-height: 34px; }
|
||||
.speaker-face { position: relative; display: inline-grid; flex: none; border-radius: 50%; }
|
||||
|
||||
Reference in new issue
Block a user