Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(i18n): an IME candidate Enter no longer sends, searches or commits

chaitanyagirie3f7e6c0683f
diff --git a/src/renderer/src/components/AgentControlStrip.tsx b/src/renderer/src/components/AgentControlStrip.tsx
index d1e88362..3dabb318 100644
--- a/src/renderer/src/components/AgentControlStrip.tsx
+++ b/src/renderer/src/components/AgentControlStrip.tsx
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import { PixelButton } from './PixelButton';
import { AgentHoldButton } from './AgentHoldButton';
+import { isComposingKey } from '@shared/imeGuard';
/**
* Operator control for one agent (#7C.1-7C.3) — pause (deny tools at the next
@@ -116,7 +117,7 @@ export function AgentControlStrip({ agentId }: { agentId: string }) {
className="cth-input"
value={steer}
onChange={(e) => setSteer(e.target.value)}
- onKeyDown={(e) => { if (e.key === 'Enter') sendSteer(); }}
+ onKeyDown={(e) => { if (isComposingKey(e)) return; if (e.key === 'Enter') sendSteer(); }}
placeholder="send this agent a note… (arrives as context on its next turn, nothing is typed into its terminal)"
style={{
flex: 1, padding: '4px 6px', background: 'var(--cth-paper-100)', border: 'none',
diff --git a/src/renderer/src/components/AgentNameEditor.tsx b/src/renderer/src/components/AgentNameEditor.tsx
index 500264a9..148cd94e 100644
--- a/src/renderer/src/components/AgentNameEditor.tsx
+++ b/src/renderer/src/components/AgentNameEditor.tsx
@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from 'react';
+import { isComposingKey } from '@shared/imeGuard';
export interface AgentNameEditorProps {
name: string;
@@ -71,6 +72,9 @@ export function AgentNameEditor({
onBlur={() => { void commit(); }}
onKeyDown={(event) => {
event.stopPropagation();
+ // Still stop propagation for a composition key: it belongs to this
+ // input's IME, not to a global hotkey.
+ if (isComposingKey(event)) return;
if (event.key === 'Enter') {
event.preventDefault();
void commit();
diff --git a/src/renderer/src/components/AskMeTab.tsx b/src/renderer/src/components/AskMeTab.tsx
index b1271502..2b61214e 100644
--- a/src/renderer/src/components/AskMeTab.tsx
+++ b/src/renderer/src/components/AskMeTab.tsx
@@ -5,6 +5,7 @@ import { useStore } from '@/store/store';
import { MarkdownPreview } from '@/markdown/MarkdownPreview';
import { type HiveTask, type HumanQA, openQuestion, waitsOnHuman } from './TasksKanban';
import { compareByNewestAsk } from './askMeOrder';
+import { isComposingKey } from '@shared/imeGuard';
/**
* ASK ME — first-class human feedback through the task system.
@@ -230,7 +231,7 @@ export function AskMeTab() {
<textarea
value={drafts[t.id] ?? ''}
onChange={(e) => setAnswerDraft(t.id, e.target.value)}
- onKeyDown={(e) => { if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) void sendAnswer(t); }}
+ onKeyDown={(e) => { if (isComposingKey(e)) return; if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) void sendAnswer(t); }}
rows={3}
placeholder="Your answer — or 'done', with the result… (markdown ok · Ctrl+Enter to send)"
style={{
diff --git a/src/renderer/src/components/CommandBar.tsx b/src/renderer/src/components/CommandBar.tsx
index 5497a4d6..2d3d0325 100644
--- a/src/renderer/src/components/CommandBar.tsx
+++ b/src/renderer/src/components/CommandBar.tsx
@@ -3,6 +3,7 @@ import { PixelPanel } from './PixelPanel';
import { PixelButton } from './PixelButton';
import { Icon } from './Icon';
import { AccentColorName } from '@/design/tokens';
+import { isComposingKey } from '@shared/imeGuard';
type Mode = 'free' | 'slash' | 'quick';
@@ -24,6 +25,7 @@ export function CommandBar({ accent, busy, blocked, onSend }: CommandBarProps) {
};
const onKey = (e: KeyboardEvent<HTMLInputElement>) => {
+ if (isComposingKey(e)) return;
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
send();
diff --git a/src/renderer/src/components/CommandCenterPanel.tsx b/src/renderer/src/components/CommandCenterPanel.tsx
index fd904a52..e10dc0be 100644
--- a/src/renderer/src/components/CommandCenterPanel.tsx
+++ b/src/renderer/src/components/CommandCenterPanel.tsx
@@ -34,6 +34,7 @@ import {
type AgentProvider
} from '@/store/config';
import { canReceiveInbox } from '@shared/agentProvider';
+import { isComposingKey } from '@shared/imeGuard';
/** Michael's control surface. Shown instead of the plain terminal/files panel
* when the god agent is selected: terminal + queue, the floor roster (with
@@ -1085,7 +1086,7 @@ function MemoryTab({ godId, who: controlledWho, onWho }: { godId: string; who?:
<input
value={textQuery}
onChange={(e) => setTextQuery(e.target.value)}
- onKeyDown={(e) => { if (e.key === 'Enter') textSearch(); }}
+ onKeyDown={(e) => { if (isComposingKey(e)) return; if (e.key === 'Enter') textSearch(); }}
placeholder="Find exact text across hive files…"
style={{ ...textareaStyle, height: 30 }}
/>
@@ -1111,7 +1112,7 @@ function MemoryTab({ godId, who: controlledWho, onWho }: { godId: string; who?:
<input
value={query}
onChange={(e) => setQuery(e.target.value)}
- onKeyDown={(e) => { if (e.key === 'Enter') search(); }}
+ onKeyDown={(e) => { if (isComposingKey(e)) return; if (e.key === 'Enter') search(); }}
placeholder="What does the hive know about…"
style={{ ...textareaStyle, height: 30 }}
/>
@@ -1191,6 +1192,7 @@ function TokenLimitEditor({ value, onSet }: { value?: number; onSet: (tokens: nu
type="number" min="0" step="100000" value={text} autoFocus
onChange={(e) => setText(e.target.value)}
onKeyDown={(e) => {
+ if (isComposingKey(e)) return;
if (e.key === 'Enter') commit();
else if (e.key === 'Escape') { skipBlur.current = true; setEditing(false); }
}}
diff --git a/src/renderer/src/components/MemoryPanel.tsx b/src/renderer/src/components/MemoryPanel.tsx
index 0c6a5822..ef2bf7fb 100644
--- a/src/renderer/src/components/MemoryPanel.tsx
+++ b/src/renderer/src/components/MemoryPanel.tsx
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';
import { PixelPanel } from './PixelPanel';
import { PixelButton } from './PixelButton';
+import { isComposingKey } from '@shared/imeGuard';
interface MemoryStatus {
available: boolean;
@@ -198,7 +199,7 @@ export function MemoryPanel() {
<input
value={query}
onChange={(e) => setQuery(e.target.value)}
- onKeyDown={(e) => { if (e.key === 'Enter') run(); }}
+ onKeyDown={(e) => { if (isComposingKey(e)) return; if (e.key === 'Enter') run(); }}
placeholder="Search by meaning…"
style={{
flex: 1, padding: '6px 8px 4px',
diff --git a/src/renderer/src/components/MessageQueueComposer.tsx b/src/renderer/src/components/MessageQueueComposer.tsx
index 8fb25b94..0a02449c 100644
--- a/src/renderer/src/components/MessageQueueComposer.tsx
+++ b/src/renderer/src/components/MessageQueueComposer.tsx
@@ -7,6 +7,7 @@ import { clearTerminalDraft, dismissTerminalPicker, terminalAutomationBlockFor }
import type { TerminalAutomationBlock } from './terminalAutomation';
import { freeflowRecorder, useFreeflow } from '@/freeflow/recorder';
import { useTerminalFontSize } from './terminalFontSize';
+import { isComposingKey } from '@shared/imeGuard';
const EMPTY_QUEUE: QueuedMessage[] = [];
@@ -142,6 +143,7 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {
};
const onKey = (e: KeyboardEvent<HTMLTextAreaElement>) => {
+ if (isComposingKey(e)) return;
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
queueIt();
diff --git a/src/renderer/src/components/SettingsModal.tsx b/src/renderer/src/components/SettingsModal.tsx
index c70b1ab9..ed4e7673 100644
--- a/src/renderer/src/components/SettingsModal.tsx
+++ b/src/renderer/src/components/SettingsModal.tsx
@@ -23,6 +23,7 @@ import { AiEnginesSettings } from './AiEnginesSettings';
import { REALTIME_MODEL } from '@shared/realtimePricing';
import { RealtimeDevicePicker } from '@/realtime/DevicePicker';
import { CostHud } from '@/realtime/CostHud';
+import { isComposingKey } from '@shared/imeGuard';
export interface SettingsModalProps {
config: HarnessConfig;
@@ -1935,7 +1936,7 @@ export function SettingsModal({ config, onClose, initialSection }: SettingsModal
type="password"
value={openAiVoiceKey}
onChange={(e) => setOpenAiVoiceKey(e.target.value)}
- onKeyDown={(e) => { if (e.key === 'Enter') void saveOpenAiVoiceKey(); }}
+ onKeyDown={(e) => { if (isComposingKey(e)) return; if (e.key === 'Enter') void saveOpenAiVoiceKey(); }}
placeholder={hasOpenAiKey ? 'key saved — paste a new one to replace it' : 'sk-…'}
style={{ ...slackInputStyle, flex: 1, fontFamily: 'var(--cth-font-mono)' }}
/>
diff --git a/src/renderer/src/realtime/CostHud.tsx b/src/renderer/src/realtime/CostHud.tsx
index bc9982ef..244054bd 100644
--- a/src/renderer/src/realtime/CostHud.tsx
+++ b/src/renderer/src/realtime/CostHud.tsx
@@ -20,6 +20,7 @@
import { useEffect, useState } from 'react';
import { formatUsd } from '@shared/realtimePricing';
import { useRealtimeCost } from './costStore';
+import { isComposingKey } from '@shared/imeGuard';
const WARN_RATIO = 0.8;
@@ -115,6 +116,7 @@ export function CostHud({ compact = false }: CostHudProps): React.ReactElement |
onChange={(e) => setCapText(e.target.value)}
onBlur={(e) => commitCap(e.target.value)}
onKeyDown={(e) => {
+ if (isComposingKey(e)) return;
if (e.key === 'Enter') commitCap((e.target as HTMLInputElement).value);
}}
style={capInputStyle}
diff --git a/src/shared/imeGuard.ts b/src/shared/imeGuard.ts
new file mode 100644
index 00000000..f63bf856
--- /dev/null
+++ b/src/shared/imeGuard.ts
@@ -0,0 +1,47 @@
+/**
+ * "Is this keydown just the IME talking?"
+ *
+ * A CJK, Japanese or Korean user types Latin letters into an input method
+ * editor, which shows a candidate list, and presses ENTER to CHOOSE a candidate.
+ * That Enter is meant for the IME, not for us. Every `if (e.key === 'Enter')`
+ * handler in the app used to treat it as "send", so picking a candidate fired
+ * the message, ran the search, or committed the rename with half-typed text.
+ * The user then had to retype in a language the app had already sent badly.
+ *
+ * Two signals, because neither is sufficient alone:
+ *
+ * 1. `isComposing` — the DOM's own answer, true for keydowns dispatched while a
+ * composition session is open. This is the primary check. React's synthetic
+ * keyboard event does NOT re-expose it, which is why we read through
+ * `nativeEvent` first and only fall back to the object itself (for raw
+ * `KeyboardEvent` listeners, which carry it directly).
+ *
+ * 2. `keyCode === 229` — the legacy "IME is processing this key" sentinel that
+ * Chromium still reports. It covers the race at the END of a composition,
+ * where the compositionend and the confirming keydown can arrive in an order
+ * that leaves `isComposing` already false for the very Enter we must swallow.
+ * 229 is never a real Enter (that is 13), so this cannot swallow a genuine
+ * keypress.
+ *
+ * Pure and framework-free on purpose so it is testable from `node --test`.
+ */
+
+/** The structural shape we need from either a React synthetic event or a raw
+ * DOM `KeyboardEvent`. Deliberately all-optional: a hand-built test double or a
+ * partially-populated event must degrade to "not composing", never throw. */
+export interface ComposingKeyEvent {
+ isComposing?: boolean;
+ keyCode?: number;
+ nativeEvent?: { isComposing?: boolean; keyCode?: number };
+}
+
+/** True when this keydown belongs to an in-flight IME composition and the
+ * handler must return WITHOUT acting. The next Enter, once composition has
+ * ended, arrives with `isComposing` false and `keyCode` 13 and is handled
+ * normally. */
+export function isComposingKey(e: ComposingKeyEvent | null | undefined): boolean {
+ if (!e) return false;
+ // Prefer the native event: React's SyntheticKeyboardEvent drops `isComposing`.
+ const src = e.nativeEvent ?? e;
+ return src.isComposing === true || src.keyCode === 229;
+}
diff --git a/test/ime-guard.test.cjs b/test/ime-guard.test.cjs
new file mode 100644
index 00000000..769c6056
--- /dev/null
+++ b/test/ime-guard.test.cjs
@@ -0,0 +1,49 @@
+'use strict';
+
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const loadTs = require('./load-ts.cjs');
+
+const { isComposingKey } = loadTs('src/shared/imeGuard.ts');
+
+// A React synthetic keyboard event: the fields we read live on `nativeEvent`,
+// because React's SyntheticKeyboardEvent does not re-expose `isComposing`.
+const synthetic = (isComposing, keyCode) => ({ nativeEvent: { isComposing, keyCode } });
+// A raw DOM KeyboardEvent carries them directly.
+const raw = (isComposing, keyCode) => ({ isComposing, keyCode });
+
+test('an Enter that confirms an IME candidate is swallowed (React synthetic)', () => {
+ assert.equal(isComposingKey(synthetic(true, 229)), true);
+});
+
+test('the NEXT Enter, after composition ends, is handled normally', () => {
+ assert.equal(isComposingKey(synthetic(false, 13)), false);
+});
+
+test('a raw DOM KeyboardEvent is read directly when there is no nativeEvent', () => {
+ assert.equal(isComposingKey(raw(true, 229)), true);
+ assert.equal(isComposingKey(raw(false, 13)), false);
+});
+
+test('keyCode 229 alone is enough, for the compositionend/keydown race', () => {
+ // WebKit and Chromium can report the confirming keydown with isComposing
+ // ALREADY false. 229 is the only remaining signal that this was the IME.
+ assert.equal(isComposingKey(synthetic(false, 229)), true);
+ assert.equal(isComposingKey(raw(false, 229)), true);
+});
+
+test('229 cannot swallow a genuine Enter, which is always keyCode 13', () => {
+ assert.equal(isComposingKey(synthetic(undefined, 13)), false);
+});
+
+test('a missing or empty event degrades to "not composing" instead of throwing', () => {
+ assert.equal(isComposingKey(null), false);
+ assert.equal(isComposingKey(undefined), false);
+ assert.equal(isComposingKey({}), false);
+ assert.equal(isComposingKey({ nativeEvent: {} }), false);
+});
+
+test('nativeEvent wins over a stale field on the synthetic wrapper', () => {
+ // React copies some fields onto the synthetic event; the native one is truth.
+ assert.equal(isComposingKey({ isComposing: false, nativeEvent: { isComposing: true } }), true);
+});