feat: the brain can change the box's speaker volume

"Speak up" and "too loud" now work: the reply tool takes louder, in
percentage points, and the button service nudges the speaker's softvol
before it speaks that reply, so the person hears the change at once.
The box keeps the level between 10% and 80% (body/mixer.py).

No new port or key: the volume changes only with a reply, in a
conversation someone is listening to.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-12-03 16:44:54 -06:00
1 parent cf503ac247
commit 5191ee9931
11 files changed
+146 -21

No files matched your search

+11 -4
View File
@@ -10,11 +10,14 @@ import { RpcTarget } from 'capnweb';
/** Spoken questions are short. */
export const MAX_QUESTION_CHARS = 2000;
/** The most a reply can change the box's speaker volume, in percentage points; the box keeps its own bounds. */
export const MAX_LOUDER = 30;
/** A conversation id: the box makes them up, so keep them tame. */
const CONVERSATION = /^[A-Za-z0-9-]{1,40}$/;
/**
* @typedef {{ text: string, end: boolean }} Answer
* @typedef {{ text: string, end: boolean, louder?: number }} Answer
* @typedef {{ conversation?: string, onSay?: (text: string) => unknown }} AskOpts
* @typedef {{ resolve: (a: Answer) => void, reject: (e: Error) => void, onSay?: AskOpts['onSay'] }} Pending
*/
@@ -74,13 +77,17 @@ export class Channel {
/**
* The brain's reply tool. Returns what to tell the brain.
* @param {string} chat_id @param {string} text @param {boolean} [end] the conversation is over
* @param {number} [louder] change the speaker volume this many percentage points first; negative is softer
*/
reply(chat_id, text, end = false) {
reply(chat_id, text, end = false, louder = undefined) {
const p = this.#pending.get(chat_id);
if (!p) return `no one is waiting on chat_id ${chat_id}: it timed out or was already answered`;
const volumeOk = louder === undefined || (Number.isInteger(louder) && Math.abs(louder) <= MAX_LOUDER);
this.#pending.delete(chat_id);
p.resolve({ text: String(text), end: end === true });
return end === true ? 'spoken; the conversation is over' : 'spoken';
p.resolve({ text: String(text), end: end === true, ...(volumeOk && louder ? { louder } : {}) });
const outcome = end === true ? 'spoken; the conversation is over' : 'spoken';
if (!volumeOk) return `${outcome}, but the volume is unchanged: louder must be a whole number from -${MAX_LOUDER} to ${MAX_LOUDER}`;
return louder ? `${outcome}, ${louder > 0 ? 'louder' : 'softer'} by ${Math.abs(louder)} points (within the box's bounds)` : outcome;
}
/** The box says a conversation is over: by goodbye, silence, or a press. @param {string} conversation @param {string} user */
+17 -1
View File
@@ -1,7 +1,7 @@
// Tests for the ask capability's core: no MCP, no network, no real timers.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { Channel, Asker, MAX_QUESTION_CHARS } from './ask.js';
import { Channel, Asker, MAX_LOUDER, MAX_QUESTION_CHARS } from './ask.js';
const harness = () => {
const sent = [], timers = [];
@@ -52,6 +52,22 @@ test('the box ends a conversation; the brain hears it, with no question to answe
assert.throws(() => channel.end('k 7; rm', 'box'), /conversation/);
});
test('a reply can turn the volume up or down; out of range, it speaks but leaves the volume', async () => {
const { channel } = harness();
const up = channel.ask('Speak up!', 'box');
assert.match(channel.reply('c1', 'Is this better?', false, 10), /louder by 10/);
assert.deepEqual(await up, { text: 'Is this better?', end: false, louder: 10 });
const down = channel.ask('Too loud.', 'box');
assert.match(channel.reply('c2', 'Sorry.', false, -5), /softer by 5/);
assert.deepEqual(await down, { text: 'Sorry.', end: false, louder: -5 });
const way = channel.ask('Way up!', 'box');
assert.match(channel.reply('c3', 'Okay.', false, MAX_LOUDER + 1), /volume is unchanged/);
assert.deepEqual(await way, { text: 'Okay.', end: false });
const odd = channel.ask('Louder?', 'box');
assert.match(channel.reply('c4', 'Hm.', false, 'max'), /volume is unchanged/);
assert.deepEqual(await odd, { text: 'Hm.', end: false });
});
test('replies go to the right question; a stale chat_id is reported, not thrown', async () => {
const { channel } = harness();
const a = channel.ask('one', 'box');
+9 -4
View File
@@ -21,7 +21,7 @@ import { networkInterfaces } from 'node:os';
import process from 'node:process';
import { createInterface } from 'node:readline';
import { WebSocketServer } from 'ws';
import { Asker, Channel } from './ask.js';
import { Asker, Channel, MAX_LOUDER } from './ask.js';
import { Gate } from './gate.js';
import { makeGitHubPost, makeReporter } from './report.js';
@@ -36,10 +36,15 @@ const INSTRUCTIONS = [
const REPLY_TOOL = {
name: 'reply',
description: 'Speak your answer through the box; then it is their turn. Pass chat_id from the inbound <channel> tag. end_conversation true says goodbye and closes the conversation.',
description: 'Speak your answer through the box; then it is their turn. Pass chat_id from the inbound <channel> tag. end_conversation true says goodbye and closes the conversation. louder changes the box\'s speaker volume, in percentage points, before it speaks this answer, so they hear the difference: 10 for "speak up", -10 for "too loud", more if they ask for a lot. The box keeps the volume within its own bounds.',
inputSchema: {
type: 'object',
properties: { chat_id: { type: 'string' }, text: { type: 'string' }, end_conversation: { type: 'boolean' } },
properties: {
chat_id: { type: 'string' },
text: { type: 'string' },
end_conversation: { type: 'boolean' },
louder: { type: 'integer', minimum: -MAX_LOUDER, maximum: MAX_LOUDER },
},
required: ['chat_id', 'text'],
},
};
@@ -241,7 +246,7 @@ const main = async ({
}
}
if (name !== 'reply') return textResult(`no tool ${name}`, true);
const outcome = channel.reply(String(args.chat_id), String(args.text ?? ''), args.end_conversation === true);
const outcome = channel.reply(String(args.chat_id), String(args.text ?? ''), args.end_conversation === true, args.louder);
log(`reply ${args.chat_id}: ${outcome}: ${args.text}`);
return textResult(outcome);
}
+1
View File
@@ -37,6 +37,7 @@ Your body is a small box with a button, near the TV. Through it you have:
- They aren't technical: be warm, plain, and brief.
- One to three short sentences.
- No markdown, lists, URLs, or emoji: it's all read aloud.
- If they can't hear you ("speak up", "what?") or you're too loud, change your own volume with louder on your reply: 10 points up or down, more if they ask for a lot. That's the box's speaker, not the TV's; "turn it up" while the TV is on most likely means the TV.
## The remote