Let each sound cue pick from 19 sounds in Preferences

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-09 12:53:53 -08:00
1 parent 459b840db9
commit 02380fa6fe
33 files changed
+402 -41

No files matched your search

@@ -5,7 +5,7 @@ One row per file under `src/web-console/public/` (the games and their sound are
| File | Role |
|---|---|
| `public/` (other files) | `index.html`, `favicon.svg` (Planny peeking up from the tab bar, served as `image/svg+xml`) with `favicon.png` (the same icon at 192 px, served as `image/png`) as the fallback, `vendor/marked.esm.js`, the chimes (`start-skill.mp3`, `bootup.mp3`, `start-stop.mp3`, `next.mp3`, `insert.mp3`, `sleeping.mp3`; which moment plays which is `SOUND_EVENTS` in `palette.js`, one switch per event saved in `looks.json`), and a `package.json` that only says `"type": "module"`, so Node (the server and the tests import the pure modules) parses them as ES modules without a reparse warning. The stylesheet is the files in `public/styles/`, joined by the server into the one `/app.css` the page asks for |
| `public/` (other files) | `index.html`, `favicon.svg` (Planny peeking up from the tab bar, served as `image/svg+xml`) with `favicon.png` (the same icon at 192 px, served as `image/png`) as the fallback, `vendor/marked.esm.js`, the chimes (`bootup.mp3`, `sleeping.mp3`, and `sounds/sound-01.mp3` to `sounds/sound-19.mp3`, whose first four are today's cues; which moment plays which is `SOUND_EVENTS` in `palette.js`, one switch per event saved in `looks.json`), and a `package.json` that only says `"type": "module"`, so Node (the server and the tests import the pure modules) parses them as ES modules without a reparse warning. The stylesheet is the files in `public/styles/`, joined by the server into the one `/app.css` the page asks for |
| `public/md-field.js` | A Markdown answer field on CodeMirror 6: every multiline box the person types into renders its Markdown live. |
| `public/md-field.css` | The frame a Markdown field wears inside its shadow root, linked beside `notepad-editor.css`. |
| `public/app.js` | the page's entry and the only page file that starts anything: the start-up block. `index.html` loads it; it imports `screens/core.js` and the screens beside it |
@@ -19,7 +19,7 @@ One row per file under `src/web-console/public/` (the games and their sound are
| `public/selectors.js` | what the page reads off its state: the questions, the finish, the scan, who has the ball |
| `public/send-state.js` | whether Send is available, and what its button says |
| `public/skills.js` | the skill list: every per-skill fact the console uses (card, order, start pose, launch scoring, subagent opt-in, which spec states light its card), data only, imported by the page and by Node; the older tables (`SKILL_CATALOG`, `START_POSES`, `CONSOLE_WORKFLOWS` and the rest, in `answers.js`) are lookups on it. Each entry also carries `weight` (what its launch and `run` score on the meter, or null), `started` and `ran` (the meter's labels for them, or null), `resume` (`"overview"`, `"folder"` or null: what the resume command takes after the skill's command) and an optional `card.help` (Help's line for the card when it differs from `blurb`). `WORKFLOWS` (every entry's workflow, in order) and `isWorkflow()` are what the CLI checks a `--workflow` against. The meter's `WEIGHTS`, `LAUNCH_LABELS` and `RUN_LABELS`, `resumeCommand()`, Help's card list and `cmd-help`'s workflow list are all derived from it, so a new skill is one entry here, not an edit to each of those |
| `public/sound.js` | the sound cues: which plays, one at a time, held until the first click |
| `public/sound.js` | the sound cues: which plays, one at a time, held until the first click; seven cues (not Planny snoring or waking) play the file picked in Preferences, saved flat as `soundFile<Event>` (`soundFileQuestion`) out of the 19 files `sound-01` to `sound-19` in `public/sounds/` |
| `public/spec-states.js` | the spec states (`diagnosed`, `fixed`, `exploring`, `mapped`, `planned`, `documented`, `building`, `built`, `unrecognized`): each one's picker label, the card it is the natural next step for and its recommendation, data only; which cards a state lights lives in `skills.js`, how a folder maps to a state in `classifySpec()` in `scan.mjs` |
| `public/state.js` | the page's shared state (`page.S` the server's truth, `page.local` what is staged) and the `redraw()` / save hooks every screen calls; defines only |
| `public/uploads.js` | pictures and documents attached to a note: chips, trays, re-encoding, upload, retry, and the page's shared full-screen picture preview (`openPicview`, the `#picview` dialog every thumbnail opens) |
+1 -1
View File
@@ -310,7 +310,7 @@ Built for a mixed product and engineering room reading one screen together.
- **One width variable.** `--card-width` on `:root` in `styles/tokens.css` sets the column the card, the pager and the document tabs share (`max-width: min(var(--card-width), 100%)`, so a narrow window still wins); no fixed `720px` column rule is left outside a media query. Three presets, picked under *Card width* in the looks panel and saved as `looks.width`: `narrow` 720px, `comfortable` 880px (the default, and the variable's own value), `wide` 1080px, applied as `:root[data-width="…"]`. `CARD_WIDTHS` in `palette.js` is the same list for the page's validation and the server's first-paint `data-width`; **`palette.js` and `app.css` must agree**, which is the one place the number is written twice. The dashboard keeps its own 860px layout. Inside the card the `62ch` / `68ch` measure caps come off (`.card .md, .card .prompt { max-width: none; }`) so a wider card is not a narrow column in a wide frame; documents keep `.md`'s 68ch.
- **One box grows.** On the primary card, the answer box that is being typed in — a `text` question's box, a choice's *Something else* box once picked, or the note under a verdict / confirm / recap once shown — is `textarea.grow`, and the card takes the column's full height above the pager (`.card.is-primary.has-grow { flex: 1 1 auto; }`). `fitGrowBox()` in `app.js` writes the card's free height as the box's `min-height`, **never under 160px**; a `ResizeObserver` watches the main column rather than the box, so the box growing can never retrigger it, and it writes only on a change over 1px. `resize: vertical` with that moving floor makes the handle taller-only; past the fill the card scrolls. Every other box keeps its ordinary size, and the notes panel is untouched.
- **A switch per sound.** Every cue is an event in `SOUND_EVENTS` (`palette.js`), each naming its file and rank: `startSkill` (`start-skill.mp3`, played once the dashboard's **Start** is accepted) 5, `bootup` 4, `sessionStart` / `sessionEnd` (`start-stop.mp3`) 3, `question` / `skillReady` / `chatReply` (`next.mp3`) 2, `newTab` (`insert.mp3`) 1, `snore` (`sleeping.mp3`, looped by the wake-up outside the queue) 0. The queue, the held slot and the one-at-a-time rule in `app.js` work on events, one `Audio` per file shared by the events that use it. User Preferences shows a *Play sounds* master (`looks.sound`) over one box per event, saved flat as `sound<Event>` (`soundStartSkill`, …) because `looks.json` only holds flat values; `soundPrefs()` turns any missing or non-boolean switch on, so a file from before the switches keeps every sound. A cue plays only while the master and its own switch are both on; the master off grays the boxes but keeps their ticks, and ticking a box plays it.
- **A switch per sound.** Every cue is an event in `SOUND_EVENTS` (`palette.js`), each naming its file and rank: `startSkill` (`sounds/sound-01.mp3`, played once the dashboard's **Start** is accepted) 5, `bootup` 4, `sessionStart` / `sessionEnd` (`sounds/sound-02.mp3`) 3, `question` / `skillReady` / `chatReply` (`sounds/sound-03.mp3`) 2, `newTab` (`sounds/sound-04.mp3`) 1, `snore` (`sleeping.mp3`, looped by the wake-up outside the queue) 0. The queue, the held slot and the one-at-a-time rule in `app.js` work on events, one `Audio` per file shared by the events that use it. User Preferences shows a *Play sounds* master (`looks.sound`) over one box per event, saved flat as `sound<Event>` (`soundStartSkill`, …) because `looks.json` only holds flat values; `soundPrefs()` turns any missing or non-boolean switch on, so a file from before the switches keeps every sound. A cue plays only while the master and its own switch are both on; the master off grays the boxes but keeps their ticks, and ticking a box plays it. Seven cues (not `snore` or `bootup`) also keep a pick out of the 19 files in `public/sounds/`, saved flat as `soundFile<Event>` (`soundFileQuestion`); `soundFilePrefs()` validates it against `SOUND_FILES` and a missing or unknown value falls back to the event's default, `sound.js` plays it, and the picker's select and Play button call `previewSound()`, which cuts off what is playing and is dropped behind a still-audible ranked cue.
- **Send breathes.** `#btn-send:not(:disabled)` runs `send-pulse`, a soft accent ring that spreads and fades every 2.4s; a disabled Send is still, and reduced motion switches it off.
- **Per-tab scroll memory.** An in-memory `Map` keyed by view id holds the scroller's position (the main column on a document or the Overview, the card on the questions view, with the item it belonged to), restored when the tab comes back. Page-local, never persisted, cleared when the session turns into or out of the dashboard.
- **The Overview tab.** Appears only while `GET /overview` returns a file for the session's spec (on the dashboard: the picker's spec; gone for *start from scratch*), fetched with `no-store` on load, on a spec change and on every tab click, so it always shows the file as it is on disk. On the dashboard, a spec with no overview gets a **Map** tab (`?file=map`, `pathfinder/map.md`) and a **Plan draft** tab (`?file=draft`, the live `PLAN-DRAFT-*.md`) in its place, each while its file exists, fetched and drawn the same way; away from the dashboard only the overview is read, since a session's own map or draft is the work already in front of it. Rendered through the same DOM-only markdown path as every doc, captioned read-only. It never becomes a doc: the page is not the record.
+4 -1
View File
@@ -150,7 +150,10 @@ Scroll down for the utilities. Outside a git repository the **Git** card says so
snoring, Planny waking up, starting a skill, session opens, skill is ready,
session ends, new questions, a reply on Ask, a new tab), so you can keep only
the ones you want. Ticking a box plays its sound; everything is remembered
like the colors.
like the colors. Seven of the moments (everything except Planny snoring and
waking up) also have a menu of 19 sounds and a Play button, so you can give
each its own; picking one plays it, and the sounds you hear today are the
defaults.
- **Files in your notes.** Show instead of describe: attach a screenshot, a
photo or a document to any note or quick question (see *Attachments in notes
and questions* below).
+2 -1
View File
@@ -166,7 +166,8 @@ test("no built skill holds the large console files; the shared copy keeps every
assert.ok(fs.readFileSync(built).equals(fs.readFileSync(path.join(src, ...rel.split("/")))), `${rel} differs from src/`);
}
assert.ok(fs.existsSync(path.join(shared, "public", "vendor", "codemirror.esm.js")), "codemirror ships");
assert.ok(fs.readdirSync(path.join(shared, "public")).filter((f) => f.endsWith(".mp3")).length >= 3, "every sound ships");
assert.equal(fs.readdirSync(path.join(shared, "public", "sounds")).filter((f) => /^sound-\d\d\.mp3$/.test(f)).length, 19, "every pickable sound ships");
assert.equal(fs.readdirSync(path.join(shared, "public")).filter((f) => f.endsWith(".mp3")).length, 2, "the boot and snore sounds ship");
});
test("the shared copy ships a module for every game listed in public/activities.js", async () => {
+160
View File
@@ -942,3 +942,163 @@ test("the Subagents dialog looks as it did before Preferences moved to tabs", as
if (process.env.P2C_PRINT_SUBAGENTS) console.log("SUBAGENTS " + JSON.stringify(got));
assert.deepEqual(got, SUBAGENTS_BEFORE);
});
// The sound picker: a select of the 19 files and a play button for each of the
// seven pickable cues, Planny's snoring and waking keeping plain boxes.
const PICK_EVENTS = ["startSkill", "sessionStart", "skillReady", "sessionEnd", "question", "chatReply", "newTab"];
const PICK_DEFAULTS = {
startSkill: "sound-01",
sessionStart: "sound-02",
skillReady: "sound-03",
sessionEnd: "sound-02",
question: "sound-03",
chatReply: "sound-03",
newTab: "sound-04",
};
const pickSelect = (s, event) => s.page.locator(`select[data-sound-file="${event}"]`);
async function openSoundsTab(s) {
await s.page.click("#btn-looks");
await s.page.click("#prefs-tab-sounds");
// Wait for the dialog to hold every row before acting on one.
await s.page.waitForFunction((n) => document.querySelectorAll("select[data-sound-file]").length === n, PICK_EVENTS.length);
}
// Counts the files the page asks to play, without making a sound. Installed
// before the page loads (then reloaded), so a cue the session itself plays
// never really plays: a preview is dropped while a higher-ranked cue is
// audible, and an audible one would hide the click under test.
async function stubPlay(s) {
await s.page.addInitScript(() => {
window.__played = [];
HTMLMediaElement.prototype.play = function () {
window.__played.push(this.src);
return Promise.resolve();
};
});
await s.page.reload({ waitUntil: "domcontentloaded" });
await drawn(s.page);
}
const played = (s) => s.page.evaluate(() => window.__played);
test("the sound picker: seven cues have a select of 19 sounds on their default, snoring and waking have none", async (t) => {
noSavedLooks(t);
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await openSoundsTab(s);
for (const event of PICK_EVENTS) {
assert.equal(await pickSelect(s, event).locator("option").count(), 19, `${event} lists 19 sounds`);
assert.equal(await pickSelect(s, event).inputValue(), PICK_DEFAULTS[event], `${event} starts on its default`);
assert.equal(await s.page.locator(`[data-sound-play="${event}"]`).count(), 1, `${event} has a play button`);
}
for (const event of ["snore", "bootup"]) {
assert.equal(await s.page.locator(`[data-sound="${event}"]`).count(), 1, `${event} keeps its box`);
assert.equal(await s.page.locator(`[data-sound-file="${event}"], [data-sound-play="${event}"]`).count(), 0, `${event} has no picker`);
}
});
test("the sound picker: a pick plays once and persists across a reload, and Play replays it even with the cue unticked", async (t) => {
noSavedLooks(t);
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await stubPlay(s);
await openSoundsTab(s);
await s.page.evaluate(() => (window.__played.length = 0));
await pickSelect(s, "question").selectOption("sound-07");
await s.page.waitForFunction(() => window.__played.length === 1);
assert.match((await played(s))[0], /\/sounds\/sound-07\.mp3$/, "the pick played");
await s.page.waitForFunction(async () => ((await (await fetch("/looks")).json()).looks || {}).soundFileQuestion === "sound-07");
await s.page.locator('[data-sound="question"]').uncheck();
await s.page.locator('[data-sound-play="question"]').click();
await s.page.waitForFunction(() => window.__played.length === 2);
assert.match((await played(s))[1], /\/sounds\/sound-07\.mp3$/, "Play replays the pick with the cue unticked");
await s.page.click("#looks-done");
await s.page.reload({ waitUntil: "domcontentloaded" });
await drawn(s.page);
await openSoundsTab(s);
assert.equal(await pickSelect(s, "question").inputValue(), "sound-07", "the pick did not survive a reload");
assert.equal(await pickSelect(s, "newTab").inputValue(), "sound-04", "an untouched cue kept its default");
});
test("the sound picker: Play sounds off disables the selects and play buttons, and Back to default restores the defaults", async (t) => {
noSavedLooks(t);
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await openSoundsTab(s);
await pickSelect(s, "newTab").selectOption("sound-15");
await s.page.waitForFunction(async () => ((await (await fetch("/looks")).json()).looks || {}).soundFileNewTab === "sound-15");
await s.page.locator("#looks-sound").uncheck();
for (const event of PICK_EVENTS) {
assert.equal(await pickSelect(s, event).isDisabled(), true, `${event}'s select is disabled`);
assert.equal(await s.page.locator(`[data-sound-play="${event}"]`).isDisabled(), true, `${event}'s play button is disabled`);
}
assert.equal(await pickSelect(s, "newTab").inputValue(), "sound-15", "the pick is kept while sounds are off");
assert.equal(Number(await styleOf(s.page.locator("#looks-sound-events"), "opacity")) < 1, true, "the rows are dimmed");
await s.page.locator("#looks-sound").check();
assert.equal(await pickSelect(s, "newTab").isDisabled(), false, "switching sounds on enables the select again");
await s.page.click("#looks-reset");
await s.page.waitForFunction(() => document.querySelector('select[data-sound-file="newTab"]').value === "sound-04");
for (const event of PICK_EVENTS) {
assert.equal(await pickSelect(s, event).inputValue(), PICK_DEFAULTS[event], `${event} is back on its default`);
}
await s.page.waitForFunction(async () => ((await (await fetch("/looks")).json()).looks || {}).soundFileNewTab !== "sound-15");
});
test("the sound picker: a preview is dropped behind a ranked cue that is still playing, and plays once it has stopped", async (t) => {
noSavedLooks(t);
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
// A stub whose Audio reports itself playing until the test says otherwise.
await s.page.addInitScript(() => {
window.__played = [];
window.__audible = true;
HTMLMediaElement.prototype.play = function () {
window.__played.push(this.src);
Object.defineProperty(this, "paused", { configurable: true, get: () => !window.__audible });
return Promise.resolve();
};
});
await s.page.reload({ waitUntil: "domcontentloaded" });
await drawn(s.page);
await openSoundsTab(s);
// Let the cues the session itself played settle, then start a ranked one.
await s.page.evaluate(async () => {
window.__audible = false;
const { sound } = await import("/sound.js");
window.__played.length = 0;
sound("question");
await new Promise((r) => setTimeout(r, 0));
window.__audible = true;
});
await s.page.waitForFunction(() => window.__played.length === 1);
await s.page.locator('[data-sound-play="newTab"]').click();
assert.equal((await played(s)).length, 1, "the preview was dropped behind the audible cue");
await s.page.evaluate(() => (window.__audible = false));
await s.page.locator('[data-sound-play="newTab"]').click();
await s.page.waitForFunction(() => window.__played.length === 2);
assert.match((await played(s))[1], /\/sounds\/sound-04\.mp3$/, "the preview played once the cue had stopped");
});
test("the sound picker: Tab reaches Play from the select, and a row stacks inside the dialog at a narrow width", async (t) => {
noSavedLooks(t);
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.setViewportSize({ width: 600, height: 900 });
await openSoundsTab(s);
await pickSelect(s, "question").focus();
await s.page.keyboard.press("Tab");
assert.equal(await s.page.evaluate(() => document.activeElement?.dataset.soundPlay), "question", "Tab from the select lands on its Play button");
const fits = await s.page.evaluate(() => {
const box = document.getElementById("looks-modal").getBoundingClientRect();
return [...document.querySelectorAll(".sound-row")].map((row) =>
[...row.querySelectorAll("label, select, button")].every((n) => {
const r = n.getBoundingClientRect();
return r.left >= box.left - 1 && r.right <= box.right + 1;
})
);
});
assert.equal(fits.length, PICK_EVENTS.length, "every row is drawn");
assert.equal(fits.every(Boolean), true, "no control spills out of the dialog at 600px");
});
+30 -4
View File
@@ -31,7 +31,7 @@ import {
turnGate,
} from "../src/web-console/public/answers.js";
import { CHAT_LIMIT, CHAT_MAX_CHARS } from "../src/web-console/public/chat.js";
import { ACCENTS, CARD_WIDTHS, SOUND_EVENTS, soundKey, soundPrefs } from "../src/web-console/public/palette.js";
import { ACCENTS, CARD_WIDTHS, SOUND_EVENTS, soundKey, soundPrefs, SOUND_FILES, PICKABLE_SOUNDS, DEFAULT_SOUND_FILE, soundFileKey, soundFilePrefs } from "../src/web-console/public/palette.js";
import { HELP_TABS, helpTabFor, helpKeyTarget } from "../src/web-console/public/help.js";
import { tabKeyTarget } from "../src/web-console/public/tabs.js";
import { PREFS_TABS, prefsOpenTab, prefsResetScope } from "../src/web-console/public/prefs.js";
@@ -602,7 +602,8 @@ test("boot.js is served as JavaScript and imports without a DOM", async () => {
// nobody adds serves 404 and the sound just never plays, so assert every file
// the page asks for comes back as audio.
test("the chime files are served as audio", async () => {
for (const f of ["start-stop.mp3", "next.mp3", "insert.mp3", "sleeping.mp3", "bootup.mp3", "start-skill.mp3"]) {
const sounds = Array.from({ length: 19 }, (_, i) => `sounds/sound-${String(i + 1).padStart(2, "0")}.mp3`);
for (const f of [...sounds, "sleeping.mp3", "bootup.mp3"]) {
const res = await fetch(`${baseUrl}/${f}`, { headers: { cookie: cookieFor(baseUrl, token) } });
assert.equal(res.status, 200, `${f} is played but the server will not serve it`);
assert.match(res.headers.get("content-type"), /^audio\//);
@@ -613,7 +614,7 @@ test("the chime files are served as audio", async () => {
// names a real event, and every event's file is served. A box with no event
// saves a setting nothing reads; an event with no box can never be muted.
test("every sound event has a preference box and a served file", async () => {
assert.equal(SOUND_EVENTS.startSkill.file, "start-skill", "starting a skill has its own sound");
assert.equal(SOUND_EVENTS.startSkill.file, "sounds/sound-01", "starting a skill has its own sound");
const html = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "index.html"), "utf8");
const boxes = [...html.matchAll(/data-sound="(\w+)"/g)].map((m) => m[1]);
assert.deepEqual([...boxes].sort(), Object.keys(SOUND_EVENTS).sort());
@@ -642,6 +643,31 @@ test("soundPrefs: missing switches are on, saved booleans hold, anything else is
assert.ok(!("extra" in prefs), "only the sound switches come back");
});
// The picked file per cue: a looks.json from before the picker, an unknown
// name or a non-string gets the cue's default; a valid name holds.
test("soundFilePrefs: defaults for anything not a known file, a valid pick holds", () => {
assert.equal(soundFileKey("startSkill"), "soundFileStartSkill");
assert.equal(SOUND_FILES.length, 19);
const keys = PICKABLE_SOUNDS.map(soundFileKey).sort();
const defaults = Object.fromEntries(PICKABLE_SOUNDS.map((e) => [soundFileKey(e), DEFAULT_SOUND_FILE[e]]));
for (const saved of [null, undefined, {}, { soundFileQuestion: "sound-99" }, { soundFileQuestion: 7 }, { soundFileQuestion: null }]) {
const prefs = soundFilePrefs(saved);
assert.deepEqual(Object.keys(prefs).sort(), keys);
assert.deepEqual(prefs, defaults, `defaults for ${JSON.stringify(saved)}`);
}
const prefs = soundFilePrefs({ soundFileQuestion: "sound-07", soundFileNewTab: "bootup", extra: "sound-01" });
assert.equal(prefs.soundFileQuestion, "sound-07");
assert.equal(prefs.soundFileNewTab, DEFAULT_SOUND_FILE.newTab);
assert.ok(!("extra" in prefs));
});
test("every default sound file is a known file, and the pickable cues are the seven", () => {
for (const file of Object.values(DEFAULT_SOUND_FILE)) assert.ok(SOUND_FILES.includes(file), file);
assert.deepEqual(PICKABLE_SOUNDS, ["startSkill", "sessionStart", "skillReady", "sessionEnd", "question", "chatReply", "newTab"]);
assert.ok(!PICKABLE_SOUNDS.includes("snore") && !PICKABLE_SOUNDS.includes("bootup"));
for (const event of PICKABLE_SOUNDS) assert.equal(SOUND_EVENTS[event].file, `sounds/${DEFAULT_SOUND_FILE[event]}`);
});
// The favicon rides the same allow-list, so a missing entry is a silent 404
// and the tab falls back to a blank icon.
test("the favicon is served as an SVG with a PNG fallback and the page points at both", async () => {
@@ -838,7 +864,7 @@ test("prefs: the dialog opens on the tab asked for, else Appearance", () => {
test("prefs: Back to default resets Appearance or Sounds & activities only, and nothing on the other two", () => {
assert.deepEqual(prefsResetScope("appearance"), ["theme", "width", "accent", "role", "skipIntro"]);
const sounds = prefsResetScope("sounds");
assert.deepEqual(sounds, ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), "hideActivities", "activitySounds", "gameMusic"]);
assert.deepEqual(sounds, ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), ...PICKABLE_SOUNDS.map(soundFileKey), "hideActivities", "activitySounds", "gameMusic"]);
for (const key of [...prefsResetScope("appearance"), ...sounds]) {
if (key !== "role") assert.ok(Object.hasOwn(DEFAULT_LOOKS, key), `${key} has a default`);
}
+41 -9
View File
@@ -3684,15 +3684,47 @@
<legend>Sounds</legend>
<label><input type="checkbox" id="looks-sound" checked /> <span>Play sounds</span></label>
<div class="looks-row looks-sound-events" id="looks-sound-events">
<label><input type="checkbox" data-sound="snore" checked /> <span>Planny snoring</span></label>
<label><input type="checkbox" data-sound="bootup" checked /> <span>Planny waking up</span></label>
<label><input type="checkbox" data-sound="startSkill" checked /> <span>Starting a skill</span></label>
<label><input type="checkbox" data-sound="sessionStart" checked /> <span>Session opens</span></label>
<label><input type="checkbox" data-sound="skillReady" checked /> <span>Skill is ready</span></label>
<label><input type="checkbox" data-sound="sessionEnd" checked /> <span>Session ends</span></label>
<label><input type="checkbox" data-sound="question" checked /> <span>New questions for you</span></label>
<label><input type="checkbox" data-sound="chatReply" checked /> <span>Reply on the Ask tab</span></label>
<label><input type="checkbox" data-sound="newTab" checked /> <span>New tab added</span></label>
<div class="sound-plain">
<label><input type="checkbox" data-sound="snore" checked /> <span>Planny snoring</span></label>
<label><input type="checkbox" data-sound="bootup" checked /> <span>Planny waking up</span></label>
</div>
<div class="sound-rows">
<div class="sound-row">
<label><input type="checkbox" data-sound="startSkill" checked /> <span>Starting a skill</span></label>
<select data-sound-file="startSkill" aria-label="Starting a skill sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="startSkill" aria-label="Play Starting a skill sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="sessionStart" checked /> <span>Session opens</span></label>
<select data-sound-file="sessionStart" aria-label="Session opens sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="sessionStart" aria-label="Play Session opens sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="skillReady" checked /> <span>Skill is ready</span></label>
<select data-sound-file="skillReady" aria-label="Skill is ready sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="skillReady" aria-label="Play Skill is ready sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="sessionEnd" checked /> <span>Session ends</span></label>
<select data-sound-file="sessionEnd" aria-label="Session ends sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="sessionEnd" aria-label="Play Session ends sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="question" checked /> <span>New questions for you</span></label>
<select data-sound-file="question" aria-label="New questions for you sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="question" aria-label="Play New questions for you sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="chatReply" checked /> <span>Reply on the Ask tab</span></label>
<select data-sound-file="chatReply" aria-label="Reply on the Ask tab sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="chatReply" aria-label="Play Reply on the Ask tab sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="newTab" checked /> <span>New tab added</span></label>
<select data-sound-file="newTab" aria-label="New tab added sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="newTab" aria-label="Play New tab added sound">Play</button>
</div>
</div>
</div>
<p class="help">Ticking one plays it. Play sounds switches them all off at once and keeps your picks for when you switch back on.</p>
</fieldset>
+10 -1
View File
@@ -4,7 +4,7 @@
// `looks` is a live binding: every file reads the current object, and only
// this file replaces it.
import { DEFAULT_ACCENT, soundPrefs, DEFAULT_CARD_WIDTH, ACCENTS, accentId, cardWidth, soundKey } from "./palette.js";
import { DEFAULT_ACCENT, soundPrefs, soundFilePrefs, DEFAULT_CARD_WIDTH, ACCENTS, accentId, cardWidth, soundKey, soundFileKey } from "./palette.js";
import { normalizeRole, ROLE_NOT_SET } from "./starters.js";
import { bootData, hooks } from "./state.js";
import { el } from "./render.js";
@@ -29,6 +29,8 @@ export const DEFAULT_LOOKS = {
accent: DEFAULT_ACCENT,
sound: true,
...soundPrefs(null),
// Which sound file each pickable cue plays (soundFileQuestion: "sound-03").
...soundFilePrefs(null),
width: DEFAULT_CARD_WIDTH,
hideUnavailable: true,
// Always SKIP Intro: never play the dashboard's first-open wake-up (Planny asleep), off by default.
@@ -61,6 +63,7 @@ export function adoptLooks(saved) {
if (!["system", "light", "dark"].includes(looks.theme)) looks.theme = DEFAULT_LOOKS.theme;
if (typeof looks.sound !== "boolean") looks.sound = DEFAULT_LOOKS.sound;
Object.assign(looks, soundPrefs(looks));
Object.assign(looks, soundFilePrefs(looks));
if (typeof looks.hideUnavailable !== "boolean") looks.hideUnavailable = DEFAULT_LOOKS.hideUnavailable;
looks.width = cardWidth(looks.width);
if (typeof looks.skipIntro !== "boolean") looks.skipIntro = DEFAULT_LOOKS.skipIntro;
@@ -265,6 +268,12 @@ export function renderSwatches() {
box.checked = looks[soundKey(box.dataset.sound)];
box.disabled = !looks.sound;
}
// The pick per pickable cue; a select and a play button lock with the master switch.
for (const select of document.querySelectorAll("select[data-sound-file]")) {
select.value = looks[soundFileKey(select.dataset.soundFile)];
select.disabled = !looks.sound;
}
for (const button of document.querySelectorAll("button[data-sound-play]")) button.disabled = !looks.sound;
$("looks-role").value = looks.role ?? ROLE_NOT_SET;
$("looks-skip-intro").checked = looks.skipIntro;
$("looks-activities").checked = !looks.hideActivities;
+43 -8
View File
@@ -249,20 +249,40 @@ export function cardWidth(value) {
return typeof value === "string" && Object.hasOwn(CARD_WIDTHS, value) ? value : DEFAULT_CARD_WIDTH;
}
// The sound files a person can give a cue, sound-01 to sound-19, served from
// /sounds/<name>.mp3 (static.mjs).
export const SOUND_FILES = Array.from({ length: 19 }, (_, i) => `sound-${String(i + 1).padStart(2, "0")}`);
// The cues that take a picked file, in the order the picker lists them.
// Planny snoring and waking (snore, bootup) keep their own files.
export const PICKABLE_SOUNDS = ["startSkill", "sessionStart", "skillReady", "sessionEnd", "question", "chatReply", "newTab"];
// The file each pickable cue plays until a person picks another.
export const DEFAULT_SOUND_FILE = {
startSkill: "sound-01",
sessionStart: "sound-02",
sessionEnd: "sound-02",
question: "sound-03",
skillReady: "sound-03",
chatReply: "sound-03",
newTab: "sound-04",
};
// Every moment the page makes a noise, each switchable on its own in User
// Preferences (the `data-sound` boxes in index.html). Several share a file;
// the event, not the file, is what a person turns off. `rank` settles which
// wins when two ask at once (see the sounds section in app.js). Stored flat as
// `soundQuestion` and so on, because looks.json only holds flat values.
// `soundQuestion` and so on, because looks.json only holds flat values. For a
// pickable cue `file` is its default; the pick is `soundFile<Event>` in looks.
export const SOUND_EVENTS = {
startSkill: { file: "start-skill", rank: 5 },
startSkill: { file: `sounds/${DEFAULT_SOUND_FILE.startSkill}`, rank: 5 },
bootup: { file: "bootup", rank: 4 },
sessionStart: { file: "start-stop", rank: 3 },
sessionEnd: { file: "start-stop", rank: 3 },
question: { file: "next", rank: 2 },
skillReady: { file: "next", rank: 2 },
chatReply: { file: "next", rank: 2 },
newTab: { file: "insert", rank: 1 },
sessionStart: { file: `sounds/${DEFAULT_SOUND_FILE.sessionStart}`, rank: 3 },
sessionEnd: { file: `sounds/${DEFAULT_SOUND_FILE.sessionEnd}`, rank: 3 },
question: { file: `sounds/${DEFAULT_SOUND_FILE.question}`, rank: 2 },
skillReady: { file: `sounds/${DEFAULT_SOUND_FILE.skillReady}`, rank: 2 },
chatReply: { file: `sounds/${DEFAULT_SOUND_FILE.chatReply}`, rank: 2 },
newTab: { file: `sounds/${DEFAULT_SOUND_FILE.newTab}`, rank: 1 },
snore: { file: "sleeping", rank: 0 },
};
@@ -280,3 +300,18 @@ export function soundPrefs(saved) {
})
);
}
export const soundFileKey = (event) => "soundFile" + event[0].toUpperCase() + event.slice(1);
// The picked file per pickable cue out of a saved looks object: each one as
// saved when it names one of SOUND_FILES, the cue's default otherwise (a
// looks.json from before the picker, a removed file, a non-string).
export function soundFilePrefs(saved) {
const source = saved && typeof saved === "object" ? saved : {};
return Object.fromEntries(
PICKABLE_SOUNDS.map((event) => {
const value = source[soundFileKey(event)];
return [soundFileKey(event), typeof value === "string" && SOUND_FILES.includes(value) ? value : DEFAULT_SOUND_FILE[event]];
})
);
}
+2 -2
View File
@@ -4,7 +4,7 @@
// each. No DOM access at module scope, and its one import is the data-only
// palette.js: the page and `node --test` both import this file.
import { SOUND_EVENTS, soundKey } from "./palette.js";
import { SOUND_EVENTS, soundKey, PICKABLE_SOUNDS, soundFileKey } from "./palette.js";
const tab = (id, label, hint, sections) => Object.freeze({ id, label, hint, sections: Object.freeze(sections) });
@@ -26,6 +26,6 @@ export function prefsOpenTab(asked) {
// nothing to reset (and is hidden).
export function prefsResetScope(tab) {
if (tab === "appearance") return ["theme", "width", "accent", "role", "skipIntro"];
if (tab === "sounds") return ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), "hideActivities", "activitySounds", "gameMusic"];
if (tab === "sounds") return ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), ...PICKABLE_SOUNDS.map(soundFileKey), "hideActivities", "activitySounds", "gameMusic"];
return null;
}
+17 -2
View File
@@ -2,10 +2,10 @@
// Agents & models tab is agents-view.js's.
import { adoptLooks, applyLooks, loadLooks, looks, renderSwatches, saveLooks, syncLooks } from "../looks.js";
import { dropHeldSound, releaseHeldSound, sound, soundOn } from "../sound.js";
import { dropHeldSound, previewSound, releaseHeldSound, sound, soundOn } from "../sound.js";
import { hushTones, tone, unlockTones } from "../tones.js";
import { hushMusic } from "../music.js";
import { SOUND_EVENTS, soundKey } from "../palette.js";
import { SOUND_EVENTS, soundFileKey, soundKey } from "../palette.js";
import { ROLES, ROLE_NOT_SET, ROLE_NOT_SET_LABEL, needsRoleNudge, normalizeRole } from "../starters.js";
import { isDashboard } from "../selectors.js";
import { el } from "../render.js";
@@ -118,6 +118,21 @@ export function wireLooks() {
});
}
// The sound picked for a cue: a change saves it and plays it once, and the
// play button replays the current pick. Neither depends on the cue's own tick.
for (const select of document.querySelectorAll("select[data-sound-file]")) {
select.addEventListener("change", () => {
looks[soundFileKey(select.dataset.soundFile)] = select.value;
hooks.markSaved(fieldsetOf(select), saveLooks());
previewSound(select.value);
});
}
for (const button of document.querySelectorAll("button[data-sound-play]")) {
button.addEventListener("click", () => {
previewSound(looks[soundFileKey(button.dataset.soundPlay)]);
});
}
// Desktop app: the taskbar switch, kept by the app in its own app.json. The
// app says what it holds once the page is up; checked until it does.
if (framed()) {
+31 -4
View File
@@ -1,7 +1,7 @@
// Plan2Code Web Console - the sound cues: which plays, one at a time, held until the first click; defines only.
import { looks } from "./looks.js";
import { soundKey, SOUND_EVENTS } from "./palette.js";
import { soundKey, SOUND_EVENTS, PICKABLE_SOUNDS, soundFileKey } from "./palette.js";
/* ------------------------------------------------------------- sounds
@@ -34,7 +34,17 @@ let soundPlaying = null;
export const soundOn = (event) => looks.sound && looks[soundKey(event)];
const soundAudio = (event) => SOUNDS[SOUND_EVENTS[event].file];
// The file (path under the page's root, no extension) a cue plays: the pick
// for a pickable cue, the event's own file otherwise.
const soundPath = (event) =>
PICKABLE_SOUNDS.includes(event) && looks[soundFileKey(event)] ? `sounds/${looks[soundFileKey(event)]}` : SOUND_EVENTS[event].file;
const audioFor = (path) => (SOUNDS[path] ||= new Audio(`/${path}.mp3`));
// The Audio a cue last played, so a pick changed mid-sound still stops the right one.
const soundAudio = (event) => SOUNDS[playingPath[event] || soundPath(event)];
const playingPath = {};
const louderSound = (a, b) => (!b || SOUND_EVENTS[a].rank > SOUND_EVENTS[b].rank ? a : b);
@@ -51,8 +61,11 @@ function flushSound() {
const busy = soundPlaying && !soundAudio(soundPlaying).paused;
if (busy && SOUND_EVENTS[event].rank <= SOUND_EVENTS[soundPlaying].rank) return;
if (busy) soundAudio(soundPlaying).pause();
const { file } = SOUND_EVENTS[event];
const a = (SOUNDS[file] ||= new Audio(`/${file}.mp3`));
const path = soundPath(event);
playingPath[event] = path;
const a = audioFor(path);
// Stops a preview, or any cue the rank check let through, before this one starts.
for (const other of Object.values(SOUNDS)) if (other !== a) other.pause();
a.currentTime = 0;
soundPlaying = event;
a.play().catch(() => {
@@ -61,6 +74,20 @@ function flushSound() {
});
}
// Plays one picked file (sound-07) from the start for the picker's preview,
// cutting off whatever is playing. Dropped while a higher-ranked cue is
// playing, on the same busy check as flushSound. A preview is always a click
// or change, so the browser lets it play.
export function previewSound(file) {
const busy = soundPlaying && !soundAudio(soundPlaying).paused;
if (busy && SOUND_EVENTS[soundPlaying].rank > 0) return;
const a = audioFor(`sounds/${file}`);
for (const other of Object.values(SOUNDS)) if (other !== a) other.pause();
a.currentTime = 0;
soundPlaying = null;
a.play().catch(() => {});
}
// Fades a cue out over `ms` and stops it, so a long one never outlasts the
// moment it belongs to. Timers, not frames: a background tab still finishes.
export function fadeSound(event, ms) {
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+40 -2
View File
@@ -799,10 +799,48 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; }
.looks-desktop[hidden] { display: none; }
/* The per-cue boxes sit under the master switch, grayed and locked while it
is off rather than hidden, so the picks stay visible. */
.looks-sound-events { display: grid; gap: 8px; }
.looks-sound-events { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.looks-sound-events.is-off { opacity: 0.45; }
.looks-sound-events.is-off label { cursor: default; }
.looks-sound-events.is-off label:hover { border-color: var(--rule-2); }
.looks-sound-events.is-off label:hover,
.looks-sound-events.is-off .sound-row:hover { border-color: var(--rule-2); }
.looks-sound-events.is-off select,
.looks-sound-events.is-off .sound-row .btn { cursor: default; }
/* Planny's snoring and waking keep plain boxes in a row of their own; the
seven pickable cues are a list, each a label with its sound and a play
button on the right, stacked on a narrow window. */
.sound-plain { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sound-rows { display: grid; gap: 8px; }
.sound-row {
display: flex;
align-items: center;
gap: 10px;
border: 1px solid var(--rule-2);
border-radius: 8px;
padding: 6px 8px 6px 0;
background: var(--panel);
}
.sound-row:hover { border-color: var(--accent-line); }
.modal-ranges .sound-row label { flex: 1 1 auto; border: 0; border-radius: 0; background: none; padding: 4px 13px; }
.sound-row select {
flex: none;
font: inherit;
color: var(--ink);
background: var(--panel);
border: 1px solid var(--rule-2);
border-radius: 8px;
padding: 6px 8px;
}
.sound-row select:focus-visible,
.sound-row .btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sound-row select:disabled,
.sound-row .btn:disabled { opacity: 1; cursor: default; }
@media (max-width: 720px) {
.sound-plain { grid-template-columns: 1fr; }
.sound-row { flex-wrap: wrap; padding: 6px 8px; }
.modal-ranges .sound-row label { flex: 1 1 100%; padding: 4px 5px; }
.sound-row select { flex: 1 1 auto; min-width: 0; }
}
@media (max-width: 720px) {
.looks-row, .looks-row.four { grid-template-columns: 1fr; }
}
+19 -4
View File
@@ -55,12 +55,27 @@ export const SERVABLE = new Set([
"git-board.js",
"git-board-view.js",
"pr-url.js",
"start-stop.mp3",
"next.mp3",
"insert.mp3",
"sleeping.mp3",
"bootup.mp3",
"start-skill.mp3",
"sounds/sound-01.mp3",
"sounds/sound-02.mp3",
"sounds/sound-03.mp3",
"sounds/sound-04.mp3",
"sounds/sound-05.mp3",
"sounds/sound-06.mp3",
"sounds/sound-07.mp3",
"sounds/sound-08.mp3",
"sounds/sound-09.mp3",
"sounds/sound-10.mp3",
"sounds/sound-11.mp3",
"sounds/sound-12.mp3",
"sounds/sound-13.mp3",
"sounds/sound-14.mp3",
"sounds/sound-15.mp3",
"sounds/sound-16.mp3",
"sounds/sound-17.mp3",
"sounds/sound-18.mp3",
"sounds/sound-19.mp3",
"favicon.svg",
"favicon.png",
"screens/core.js",