Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: stop the dictation bridge from doubling capitals and spaces in the Shell terminal
[._.]/ Adam Eivy9a1457dd71b2
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 272cc89d7e..9a1ef06a99 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -23,6 +23,7 @@- Task metadata that has no value is no longer written to the task file at all. Any unset field previously became the literal word "null", which every reader then saw as a real value — the same class of bug as the blocked merge follow-up above. Task files an older version already wrote are repaired on read.- Blocking a task that exists to merge a pull request now raises a notification naming that PR, so it can be landed by hand instead of going unnoticed. This covers every way a task can get blocked, not just the one fixed above.- A series' pinned image backend now actually renders its comic pages and covers. The pin was saved on the series and honoured by first-pass portraits, but the comic stage sent the install-wide default as an explicit choice — which outranks any pin — so a series pinned to one backend quietly rendered every page and cover on another. The Pipeline visuals default from Settings → Image Gen now applies to these renders too, and a pin naming a backend you have since turned off falls back instead of failing the render.+- Typing on the Shell page no longer doubles capital letters and spaces. `Hi There` arrived at the shell — or at a watched agent TUI — as `HHii TThere`, which made typing a message to a running agent unusable. The terminal forwards most printable keys on keydown and cancels the event there, but hands capitals and space to the browser's keypress default action, which then also fires an input event for the same character. The dictation bridge (which reads those input events to keep voice dictation from garbling) was translating that second event into a second keystroke; it now recognizes an insertion the keypress path already sent and leaves it alone. Voice dictation and soft-keyboard input, which arrive with no keypress behind them, are unaffected.## Changeddiff --git a/client/src/lib/terminalDictation.js b/client/src/lib/terminalDictation.jsindex 70895669dc..24e7f3eda0 100644--- a/client/src/lib/terminalDictation.js+++ b/client/src/lib/terminalDictation.js@@ -24,6 +24,19 @@// reset the mirror without emitting anything, because those paths send to the PTY// through xterm and may clear the textarea out from under us.//+// ── The keypress seam ──────────────────────────────────────────────────────────+// Not every physical keystroke is settled on `keydown`. xterm cancels that event+// for most printable keys (so the character never reaches the textarea and no+// input event fires), but it deliberately defers A-Z and keys its keyboard map+// doesn't claim — space among them — to the `keypress` handler, which forwards the+// character and then does NOT preventDefault. The browser therefore inserts it+// into the textarea and fires `input`, and xterm's own `_inputEvent` drops that+// event via its `_keyPressHandled` guard. We run before xterm and stop the event,+// so that guard never gets a say: diffing the insertion would send a character the+// keypress path already sent — the reported "every capital letter and space is+// doubled". A keypress since the last keydown means the keystroke was xterm's, so+// the insertion is a resync point, not ours to forward.+//// ── Boundaries ─────────────────────────────────────────────────────────────────// Corrections are streamed live, which assumes the far end treats 0x7f as "erase// the previous character" — true at a shell prompt and in the line editors of the@@ -111,8 +124,12 @@ export const attachDictationBridge = (terminal, sendData) => {// Length of `mirror` we did not put into the PTY ourselves — see planFieldEdit.let floor = mirror.length;let resyncTimer = null;+ // True between a `keypress` and the next `keydown`: the insertion that follows+ // belongs to the keystroke xterm just forwarded. See "The keypress seam" above.+ let keyPressSeen = false;const resyncNow = () => {+ clearTimeout(resyncTimer);resyncTimer = null;mirror = textarea.value;floor = mirror.length;@@ -128,12 +145,17 @@ export const attachDictationBridge = (terminal, sendData) => {};const handleKeyDown = (ev) => {+ // A fresh keystroke: whatever it inserts is only xterm's if a keypress follows.+ keyPressSeen = false;// 229 is the "composition character" every soft keyboard/IME reports — those// keystrokes land in the textarea and are ours to diff, not a resync point.+ // They fire no keypress either, which is what keeps them ours below.if (ev.keyCode === 229 || ev.isComposing) return;scheduleResync();};+ const handleKeyPress = () => { keyPressSeen = true; };+const handleInput = (ev) => {if (ev.target !== textarea) return;// A real composition (IME candidate window) is xterm's CompositionHelper's job;@@ -142,6 +164,14 @@ export const attachDictationBridge = (terminal, sendData) => {// Screen-reader mode is the one configuration where xterm deliberately lets// these events through so the textarea can be read out — stay out of the way.if (terminal.options?.screenReaderMode) return;+ // xterm's keypress path already forwarded this character. Take the insertion+ // into the floor so a later correction can't rewind through it, and leave the+ // event alone — xterm's own `_keyPressHandled` guard makes it a no-op there.+ if (keyPressSeen) {+ keyPressSeen = false;+ resyncNow();+ return;+ }if (!isOwnedInput(ev.inputType)) {resyncNow();return;@@ -170,6 +200,7 @@ export const attachDictationBridge = (terminal, sendData) => {// blur/compositionend don't bubble, but capture-phase listeners still see them.const listeners = [['keydown', handleKeyDown],+ ['keypress', handleKeyPress],['input', handleInput],['blur', scheduleResync],['compositionend', scheduleResync],diff --git a/client/src/lib/terminalDictation.test.js b/client/src/lib/terminalDictation.test.jsindex 6d3f68b168..acf8155951 100644--- a/client/src/lib/terminalDictation.test.js+++ b/client/src/lib/terminalDictation.test.js@@ -202,6 +202,34 @@ describe('attachDictationBridge', () => {expect(sent).toEqual(['abc', 'next']);});+ it('leaves an insertion the keypress path already sent to xterm', () => {+ // Capitals and space are the keys xterm forwards from `keypress` without+ // cancelling it, so the character lands in the textarea and fires `input`+ // AFTER the PTY already has it. Diffing that insertion doubled every one.+ textarea.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 84, bubbles: true }));+ textarea.dispatchEvent(new KeyboardEvent('keypress', { keyCode: 84, bubbles: true }));+ textarea.value = 'T';+ fireInput('insertText');+ expect(sent).toEqual([]);+ // It counts as floor, not as ours: dictating on top appends instead of+ // erasing the capital xterm sent.+ textarea.value = 'There';+ fireInput('insertText');+ expect(sent).toEqual(['here']);+ });++ it('still owns an insertion with no keypress behind it', () => {+ // Dictation and soft keyboards insert without a keypress — the stale flag from+ // an earlier capital must not disown them.+ textarea.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 84, bubbles: true }));+ textarea.dispatchEvent(new KeyboardEvent('keypress', { keyCode: 84, bubbles: true }));+ textarea.value = 'T';+ fireInput('insertText');+ textarea.value = 'Today';+ fireInput('insertText');+ expect(sent).toEqual(['oday']);+ });+it('does not resync on the composition keycode soft keyboards report', () => {textarea.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 229, bubbles: true }));textarea.value = 'ab';@@ -303,6 +331,33 @@ describe('attachDictationBridge against a real xterm Terminal', () => {expect(sent.join('')).toBe('ddedeterdetermindeterminedetermines');});+ // A capital letter, keystroke-for-keystroke as Chrome delivers it: xterm ignores+ // the keydown (its A-Z hack defers to keypress), forwards the character from+ // keypress WITHOUT cancelling it, and the browser then inserts it into the+ // textarea and fires `input`. Two senders, one character.+ const typeCapital = (ch) => {+ const code = ch.charCodeAt(0);+ const { textarea } = terminal;+ textarea.dispatchEvent(new KeyboardEvent('keydown', { key: ch, keyCode: code, bubbles: true }));+ textarea.dispatchEvent(new KeyboardEvent('keypress', { key: ch, keyCode: code, charCode: code, bubbles: true }));+ textarea.value += ch;+ textarea.dispatchEvent(new InputEvent('input', { inputType: 'insertText', data: ch, bubbles: true }));+ };++ it('does not double a capital that xterm sent from keypress', () => {+ const sent = [];+ terminal.onData((d) => sent.push(d));+ typeCapital('T');+ // Proves xterm really is the sender on this path — if an upgrade moves it to+ // keydown-with-cancel, this fails and the bridge's keypress seam can go.+ expect(sent).toEqual(['T']);++ const dispose = attachDictationBridge(terminal, (d) => { sent.push(d); });+ typeCapital('X');+ dispose();+ expect(sent).toEqual(['T', 'X']);+ });+it('sends the dictated phrase once, not the accumulated garble', () => {const sent = [];// onData is where xterm's own textarea handling would surface, so anything it