Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
373180a
feat(ui-react): tap the composer mic to dictate, hold it to open Start
schlessera Nov 9, 2026
04522d0
fix(ui-kit): let a Composer's micControl come and go without a margin…
schlessera Nov 9, 2026
c55f358
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 9, 2026
cf98185
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 9, 2026
ae03d7d
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 9, 2026
c1d588c
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 9, 2026
b3fb72e
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 9, 2026
7ca357b
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 9, 2026
368d700
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 9, 2026
bd44a89
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 9, 2026
9361d8e
Merge branch 'main' into feat/3693-composer-mic-gesture
schlessera Nov 9, 2026
dd5a656
Merge branch 'main' into feat/3693-composer-mic-gesture
schlessera Nov 10, 2026
9de05f9
Merge branch 'main' into feat/3693-composer-mic-gesture
schlessera Nov 10, 2026
0980d99
Merge branch 'main' into feat/3693-composer-mic-gesture
schlessera Nov 10, 2026
d8dfa1b
Merge remote-tracking branch 'origin/main' into feat/3693-composer-mi…
schlessera Nov 10, 2026
95014cb
Merge branch 'main' into feat/3693-composer-mic-gesture
schlessera Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/composer-mic-gesture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@schlessera/brain-ui-react": minor
"@schlessera/brain-ui-kit": patch
---

The composer has one mic for both voice modes (#3693). Tap it to dictate, as before. Hold it for 0.6 s and the ring fills, then the live-conversation Start sheet opens, with a light haptic where the device supports one. Releasing earlier is a tap, and moving off the mic cancels the hold. Nothing is captured during a hold: no microphone, voice-service connection or history read starts until you pick dictation or press Start. On a keyboard, Enter or Space on the mic dictates and Shift+Enter opens Start; screen readers get a "Talk live…" action. Where live conversation isn't set up, the ring still fills and a notice explains instead.

The attach menu no longer has a "Live conversation" row, and the paperclip's name is back to "Attach — photo, camera, files". The offline "Record on this device" mic has no hold.

In `@schlessera/brain-ui-kit`, a `Composer` whose `micControl` comes and goes now updates its field's margin cleanly. Before, removing `micControl` left the textarea without a bottom margin, and React warned about mixing `margin` and `marginBottom`. The field draws the same pixels as before.
10 changes: 10 additions & 0 deletions docs/decisions/design-kit/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ The fifth drop answered the eleven questions the maintainer forwarded
> composer detail (capture is a menu behind attach); it adds no separate
> entry, no persistent desktop label and no touch long-press, and the kit
> and the menu keep their ownership.

> **2026-11-09 — Live entry moved to the mic by #3693 (epic #3690, ruling
> V1; composition signed off on #3727).** Live conversation is no longer a
> row in the attach menu, and the attach trigger's name no longer lists it:
> it is "Attach — photo, camera, files" again ("Attach — files" with the
> desktop Files menu). The composer's one mic is the kit's `MicButton` in
> the `micControl` slot: a tap dictates, and a 0.6 s hold opens Start
> (Shift+Enter on the mic, or its "Talk live…" action, for keyboards and
> screen readers). This supersedes the #3045 note above for live
> conversation only; the trigger's tooltip and its rules are unchanged.
5. **No snooze on a blocking approval**; "Always allow" has no key.
6. **Focus after the last decision in a list goes to the `EmptyState` heading
that replaces the section, with the `InlineToast` receipt above it**; the
Expand Down
6 changes: 4 additions & 2 deletions packages/ui-kit/src/chrome/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,14 @@ export function Composer(p: ComposerProps) {
background: "transparent",
border: "none",
padding: 0,
margin: 0,
// One shorthand, never `margin` beside `marginBottom`: a caller's mic
// comes and goes on one mounted field (#3693), and React cannot update a
// longhand that a shorthand also sets.
margin: micControl ? `0 0 ${TEXT_LIFT}px` : 0,
resize: "none",
// `auto`, not the source's `hidden`: a clipped single-line SPAN is fine,
// a clipped input takes the caret off-screen as you type.
overflow: "auto",
...(micControl ? { marginBottom: TEXT_LIFT } : null),
};

const disc = (size: number, fill: string, glow: boolean): CSSProperties => ({
Expand Down
67 changes: 67 additions & 0 deletions packages/ui-kit/tests/composer-mic-control-toggle.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* A caller's mic comes and goes (#3693): the app draws `MicButton` at rest and
* the kit's own mic while dictating, so one mounted composer switches
* `micControl` on and off. Every style it touches must update without React's
* shorthand warning ("Removing marginBottom … margin"), which the capture
* gate treats as a browser fault, and must end where a fresh render would.
*/
import { afterAll, afterEach, beforeAll, expect, test } from "bun:test";
import { Window } from "happy-dom";
import { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { renderToStaticMarkup } from "react-dom/server";

import { Composer, type ComposerProps } from "../src/chrome/Composer.js";
import { MicButton } from "../src/voice/MicButton.js";

const saved = new Map<string, PropertyDescriptor | undefined>();
let win: Window;
let root: Root | undefined;
let host: HTMLDivElement;
let errors: unknown[][] = [];
let realError: typeof console.error;
beforeAll(() => {
win = new Window();
for (const [key, value] of Object.entries({ window: win, document: win.document, navigator: win.navigator, HTMLElement: win.HTMLElement, IS_REACT_ACT_ENVIRONMENT: true })) {
saved.set(key, Object.getOwnPropertyDescriptor(globalThis, key));
Object.defineProperty(globalThis, key, { configurable: true, writable: true, value });
}
realError = console.error;
console.error = (...args: unknown[]) => { errors.push(args); };
});
afterEach(async () => { if (root) await act(async () => root!.unmount()); root = undefined; win.document.body.innerHTML = ""; errors = []; });
afterAll(() => {
console.error = realError;
for (const [key, descriptor] of saved) {
if (descriptor) Object.defineProperty(globalThis, key, descriptor);
else Reflect.deleteProperty(globalThis, key);
}
});

const noop = () => {};
const mic = <MicButton name="Dictate" onClick={noop} onTalkLive={noop} />;
const margins = (el: HTMLElement) => ["marginTop", "marginRight", "marginBottom", "marginLeft"].map((key) => el.style[key as "marginTop"] || "unset").join(" ");
const textarea = () => margins(host.querySelector("textarea")!);

function render(props: ComposerProps) {
if (!root) { host = document.createElement("div"); document.body.append(host); root = createRoot(host); }
act(() => root!.render(<Composer onAttach={noop} onMic={noop} onSend={noop} onChange={noop} value={"two\nlines"} {...props} />));
}
const fresh = (props: ComposerProps) => {
const div = document.createElement("div");
div.innerHTML = renderToStaticMarkup(<Composer onAttach={noop} onMic={noop} onSend={noop} onChange={noop} value={"two\nlines"} {...props} />);
return margins(div.querySelector("textarea")!);
};

test("switching the caller's mic on and off warns about no style and ends where a fresh render does", () => {
for (const state of ["ready", "streaming"] as const) {
render({ state, micControl: mic });
render({ state, micControl: undefined });
expect(textarea(), `${state}: without the caller's mic`).toBe(fresh({ state }));
render({ state, micControl: mic });
expect(textarea(), `${state}: with it again`).toBe(fresh({ state, micControl: mic }));
render({ state: "dictating", micControl: undefined });
render({ state, micControl: mic });
}
expect(errors.map((args) => String(args[0])), "no React style warnings").toEqual([]);
});
2 changes: 1 addition & 1 deletion packages/ui-kit/tests/composer-mic-control.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("Composer micControl", () => {
expect(fieldStyle(html)).toContain("align-items:flex-end");
// (36 - 28) / 2 for attach and Send; (36 - 13.5 × 1.45) / 2 for the text's last line.
expect(html.match(/margin-bottom:4px/g)).toHaveLength(2);
expect(html).toContain("margin-bottom:8.2125px");
expect(html).toContain("margin:0 0 8.2125px");
});

test("set while streaming, Stop sits on the last line as Send would", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-kit/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const railProject = (mode: "fine" | "coarse" | "mixed") => ({
// pointer; they need the consumer stylesheet. Button's hover text
// contrast (#974) and the palette's reason rows (#1106) are measured
// under all three pointers as well.
include: ["tests/visual/native-buttons.visual.tsx", "tests/visual/side-rail-targets.visual.tsx", "tests/visual/button-hover-contrast.visual.tsx", "tests/visual/overlay-targets.visual.tsx", "tests/visual/session-strip.visual.tsx", "tests/visual/pending-follow-ups.visual.tsx", "tests/visual/palette-reasons.visual.tsx", "tests/visual/status-indicator-targets.visual.tsx", "../ui-react/tests/browser/desktop-navigation.pointer.tsx", "../ui-react/tests/browser/keyboard-hints.pointer.tsx", "../ui-react/tests/browser/phone-navigation.pointer.tsx", "../ui-react/tests/browser/destination-press.pointer.tsx", "../ui-react/tests/browser/working-sessions.pointer.tsx", "../ui-react/tests/browser/session-drafts.pointer.tsx", "../ui-react/tests/browser/navigation-reach.*.pointer.tsx", "../ui-react/tests/browser/hit-reach.*.pointer.tsx", "../ui-react/tests/browser/recordings-tray.offline.tsx", "../ui-react/tests/browser/dictation-notice.pointer.tsx", "../ui-react/tests/browser/attach-tooltip.pointer.tsx", "../ui-react/tests/browser/overlay-stacking.pointer.tsx", "../ui-react/tests/browser/session-profile.pointer.tsx", "../ui-react/tests/browser/turn-budget.pointer.tsx"],
include: ["tests/visual/native-buttons.visual.tsx", "tests/visual/side-rail-targets.visual.tsx", "tests/visual/button-hover-contrast.visual.tsx", "tests/visual/overlay-targets.visual.tsx", "tests/visual/session-strip.visual.tsx", "tests/visual/pending-follow-ups.visual.tsx", "tests/visual/palette-reasons.visual.tsx", "tests/visual/status-indicator-targets.visual.tsx", "../ui-react/tests/browser/desktop-navigation.pointer.tsx", "../ui-react/tests/browser/keyboard-hints.pointer.tsx", "../ui-react/tests/browser/phone-navigation.pointer.tsx", "../ui-react/tests/browser/destination-press.pointer.tsx", "../ui-react/tests/browser/working-sessions.pointer.tsx", "../ui-react/tests/browser/session-drafts.pointer.tsx", "../ui-react/tests/browser/navigation-reach.*.pointer.tsx", "../ui-react/tests/browser/hit-reach.*.pointer.tsx", "../ui-react/tests/browser/recordings-tray.offline.tsx", "../ui-react/tests/browser/dictation-notice.pointer.tsx", "../ui-react/tests/browser/attach-tooltip.pointer.tsx", "../ui-react/tests/browser/composer-mic.pointer.tsx", "../ui-react/tests/browser/overlay-stacking.pointer.tsx", "../ui-react/tests/browser/session-profile.pointer.tsx", "../ui-react/tests/browser/turn-budget.pointer.tsx"],
provide: { railPointer: mode, keyboardHintsLive: false },
browser: {
enabled: true,
Expand Down
153 changes: 153 additions & 0 deletions packages/ui-react/src/components/chat/composer-mic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { useEffect, useRef, useState, type KeyboardEvent, type PointerEvent } from "react";
import { MicButton, type MicPhase } from "@schlessera/brain-ui-kit";

/** V1 (#3690): a hold this long opens Start; an earlier release is a tap. */
const HOLD_MS = 600;

/** How long a stray click after a hold or a cancelled hold is swallowed. */
const SWALLOW_MS = 1000;

interface ComposerMicProps {
/** The accessible name: "Dictate", "Dictate · <service>", "Record on this device". */
name?: string;
/** A tap, Enter or Space. */
onTap?: () => void;
/**
* A completed hold, Shift+Enter or "Talk live…". Absent: the mic has no
* hold (M1, #3727), so a long press is a tap and no hint is drawn.
*/
onTalkLive?: () => void;
}

/**
* The composer's one mic (#3693): tap to dictate, hold to talk live.
*
* The kit's `MicButton` is presentational; this owns the hold. A press
* fills the ring from elapsed time, and at 0.6 s the hold completes: a light
* haptic where the device has one, then `onTalkLive`. Releasing earlier is a
* tap, so the button's own click dictates. Leaving the mic, or a cancelled
* pointer, ends the hold with nothing done.
*
* Nothing is captured during a hold: the press starts a timer and an
* animation frame loop, and nothing else. No microphone, provider or history
* work starts until the user picks dictation or presses Start.
*/
export function ComposerMic(p: ComposerMicProps) {
const [phase, setPhase] = useState<MicPhase>("idle");
const [progress, setProgress] = useState(0);
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
const frame = useRef<number | null>(null);
const holding = useRef(false);
const swallow = useRef<(() => void) | null>(null);
const latest = useRef(p);
latest.current = p;

function stopTimers() {
if (timer.current !== null) clearTimeout(timer.current);
if (frame.current !== null) cancelAnimationFrame(frame.current);
timer.current = null;
frame.current = null;
}

/**
* After a hold completes or is cancelled, the release can still produce a
* click (on the mic, or on whatever replaced it). That click is not a tap.
* The next press of any kind ends the guard, so a later tap is never lost.
*/
function swallowNextClick() {
swallow.current?.();
const click = (event: MouseEvent) => { event.preventDefault(); event.stopPropagation(); end(); };
const end = () => {
window.removeEventListener("click", click, true);
window.removeEventListener("pointerdown", end, true);
window.removeEventListener("keydown", end, true);
clearTimeout(expiry);
if (swallow.current === end) swallow.current = null;
};
const expiry = setTimeout(end, SWALLOW_MS);
window.addEventListener("click", click, true);
window.addEventListener("pointerdown", end, true);
window.addEventListener("keydown", end, true);
swallow.current = end;
}

// A completed hold usually unmounts the composer (Start replaces it). The
// click guard outlives it on purpose, and ends on its own.
useEffect(() => stopTimers, []);

function reset() {
stopTimers();
holding.current = false;
setPhase("idle");
setProgress(0);
}

function onPointerDown(event: PointerEvent<HTMLButtonElement>) {
if (!latest.current.onTalkLive || event.button !== 0 || holding.current) return;
// A touch is captured implicitly, to whatever it landed on: the button,
// or the icon inside it. Release it so leaving the mic is seen, and
// cancels the hold.
const landed = event.target instanceof Element ? event.target : event.currentTarget;
if (landed.hasPointerCapture?.(event.pointerId)) landed.releasePointerCapture(event.pointerId);
// A touch's compatibility mousedown arrives after the finger lifts, and
// would pull focus back from what the hold opened. The click that makes
// a tap is not one of those events, and still arrives.
if (event.pointerType === "touch") event.preventDefault();
holding.current = true;
const started = performance.now();
setPhase("pressed");
setProgress(0);
const tick = () => {
const fill = Math.min(1, (performance.now() - started) / HOLD_MS);
setPhase("holding");
setProgress(fill);
frame.current = fill < 1 ? requestAnimationFrame(tick) : null;
};
frame.current = requestAnimationFrame(tick);
timer.current = setTimeout(() => {
stopTimers();
holding.current = false;
setPhase("complete");
setProgress(1);
swallowNextClick();
try { navigator.vibrate?.(10); } catch { /* No haptic on this device. */ }
latest.current.onTalkLive?.();
}, HOLD_MS);
}

function onPointerUp() {
// Released before the hold completed: the click that follows is the tap.
if (holding.current) reset();
else if (phase === "complete") reset();
}

function cancel() {
if (!holding.current) return;
reset();
swallowNextClick();
}

function onKeyDown(event: KeyboardEvent<HTMLButtonElement>) {
if (event.key === "Enter" && event.shiftKey && latest.current.onTalkLive) {
// Shift+Enter opens Start; Enter and Space stay the button's click.
event.preventDefault();
latest.current.onTalkLive();
}
}

return (
<MicButton
name={p.name}
phase={p.onTalkLive ? phase : "idle"}
progress={progress}
hint={!!p.onTalkLive && phase === "holding"}
onClick={p.onTap}
onPointerDown={onPointerDown}
onPointerUp={onPointerUp}
onPointerLeave={cancel}
onPointerCancel={cancel}
onKeyDown={onKeyDown}
onTalkLive={p.onTalkLive}
/>
);
}
20 changes: 11 additions & 9 deletions packages/ui-react/src/components/chat/composer-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ interface ComposerProvider {
export interface ComposerViewProps {
/** Capture panel, kept inside the existing bounded composer frame. */
dictation?: ReactNode;
onConversation?: () => void;
/**
* Why the mic cannot record, in place of the capture panel: a refused
* microphone, or a browser that cannot record on the device (#1012).
Expand All @@ -71,6 +70,11 @@ export interface ComposerViewProps {
micUnavailable?: string;
/** Off: no mic is drawn, because there is no capture to offer. */
mic?: boolean;
/**
* The composer's hold-to-talk mic (#3693), drawn in the kit's mic slot.
* When set, `mic`, `onMic`, `micLabel`, `micTip` and `micUnavailable` do not apply.
*/
micControl?: ReactNode;
value: string;
state: ComposerState;
/** Overrides the state's own placeholder (a connection reason, the host's copy). */
Expand Down Expand Up @@ -192,20 +196,17 @@ export function ComposerView(p: ComposerViewProps) {
const pointer = useMediaQuery("(min-width: 900px)");
const files = p.onPickFiles ? p.files : undefined;
const fileCount = (files?.queued.length ?? 0) + (files?.stored.length ?? 0);
// The trigger's name lists what its menu offers, in menu order (#3045):
// live conversation is reached through the paperclip, so the paperclip says
// so whenever the row is there. The kit paints the same string as the
// pointer tooltip; a phone's sheet names the actions in its subtitle.
// The trigger's name lists what its menu offers, in menu order (#3045).
// Live conversation is no longer in it: the mic's hold opens it (#3693).
// Desktop with composer files: one unrestricted Files action (desktop
// menu A, #3155); phones keep Photo library and Camera beside it.
const desktopFiles = pointer && !!p.onPickFiles;
const attachLabel = p.onConversation ? `Attach — live conversation, ${desktopFiles ? "files" : "photo, camera, files"}` : desktopFiles ? "Attach — files" : undefined;
const attachLabel = desktopFiles ? "Attach — files" : undefined;
const attachSubtitle = p.onPickFiles
? `${p.onConversation ? "Live conversation, photo" : "Photo"}, camera, files or paste.`
: `${p.onConversation ? "Live conversation, photo" : "Photo"}, camera, ${p.onPickTracks ? "track files, " : ""}or paste.`;
? "Photo, camera, files or paste."
: `Photo, camera, ${p.onPickTracks ? "track files, " : ""}or paste.`;
const attachMenu = (
<div className={pointer ? "bk-focus-clip flex flex-col rounded-[inherit]" : "flex flex-col"}>
{p.onConversation && <ListRow variant="group" icon="mic" iconTone="teal" title="Live conversation" subtitle="Talk while your agent works" onClick={p.onConversation} />}
{!desktopFiles && <ListRow variant="group" icon="image" iconTone="teal" title="Photo library" subtitle="Pick images already on this device" onClick={p.onPickLibrary} />}
{!desktopFiles && <ListRow variant="group" icon="attach" iconTone="amber" title="Camera" subtitle="Take a photo now" onClick={p.onPickCamera} />}
{p.onPickFiles
Expand Down Expand Up @@ -321,6 +322,7 @@ export function ComposerView(p: ComposerViewProps) {
micLabel={p.micLabel}
micTip={p.micTip}
micUnavailable={p.micUnavailable}
micControl={p.micControl}
status={p.status}
/>
</div>
Expand Down
Loading
Loading