Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(switchdash): always bracketed-paste injected prompts so @ doesn't eat the submit (CHOO-1395) (#28)
Louis Amaudruza0de75a359ba
diff --git a/dash/apps/switchdash-desktop/src/main/core/agent-runtime/impl/keystroke-injection.test.ts b/dash/apps/switchdash-desktop/src/main/core/agent-runtime/impl/keystroke-injection.test.tsindex 54a9922e9..db0653cd9 100644--- a/dash/apps/switchdash-desktop/src/main/core/agent-runtime/impl/keystroke-injection.test.ts+++ b/dash/apps/switchdash-desktop/src/main/core/agent-runtime/impl/keystroke-injection.test.ts@@ -74,7 +74,7 @@ describe('scheduleInitialPromptInjection', () => {expect(write).not.toHaveBeenCalled();vi.advanceTimersByTime(900);- expect(write).toHaveBeenCalledExactlyOnceWith('Fix the bug\r');+ expect(write).toHaveBeenCalledExactlyOnceWith('\x1b[200~Fix the bug \x1b[201~\r');});it('falls back to a max wait when no output ever arrives', () => {@@ -87,7 +87,7 @@ describe('scheduleInitialPromptInjection', () => {});vi.advanceTimersByTime(15_000);- expect(write).toHaveBeenCalledExactlyOnceWith('Fix the bug\r');+ expect(write).toHaveBeenCalledExactlyOnceWith('\x1b[200~Fix the bug \x1b[201~\r');});it('wraps multi-line prompts in bracketed paste sequences', () => {@@ -101,7 +101,7 @@ describe('scheduleInitialPromptInjection', () => {emitData('ready');vi.advanceTimersByTime(900);- expect(write).toHaveBeenCalledExactlyOnceWith('\x1b[200~line one\nline two\x1b[201~\r');+ expect(write).toHaveBeenCalledExactlyOnceWith('\x1b[200~line one\nline two \x1b[201~\r');});it('does nothing for OpenCode because its initial prompt is passed with --prompt', () => {diff --git a/dash/apps/switchdash-desktop/src/main/core/agent-runtime/impl/keystroke-injection.ts b/dash/apps/switchdash-desktop/src/main/core/agent-runtime/impl/keystroke-injection.tsindex b5571e8af..27a4a1d0c 100644--- a/dash/apps/switchdash-desktop/src/main/core/agent-runtime/impl/keystroke-injection.ts+++ b/dash/apps/switchdash-desktop/src/main/core/agent-runtime/impl/keystroke-injection.ts@@ -25,10 +25,7 @@ export function scheduleInitialPromptInjection(args: {const submitSequence = promptDelivery.submitSequence ?? '\r';const submitDelayMs = promptDelivery.submitDelayMs;- const payload = buildPromptInjectionPayload({- providerId: args.session.providerId,- text: args.initialPrompt,- });+ const payload = buildPromptInjectionPayload(args.initialPrompt);let injected = false;let sawAnyOutput = false;diff --git a/dash/apps/switchdash-desktop/src/main/core/switch-rooms/plugin-prompt-injector.ts b/dash/apps/switchdash-desktop/src/main/core/switch-rooms/plugin-prompt-injector.tsindex 18ca4c7ac..809d2a143 100644--- a/dash/apps/switchdash-desktop/src/main/core/switch-rooms/plugin-prompt-injector.ts+++ b/dash/apps/switchdash-desktop/src/main/core/switch-rooms/plugin-prompt-injector.ts@@ -21,13 +21,7 @@ export class PluginPromptInjector implements PromptInjector {const submitSequence = prompt.kind === 'keystroke' ? (prompt.submitSequence ?? '\r') : '\r';const submitDelayMs =(prompt.kind === 'keystroke' ? prompt.submitDelayMs : undefined) ?? DEFAULT_SUBMIT_DELAY_MS;- // Bracket multiline bodies as a paste so an embedded newline can't submit- // the prompt early — the trailing submitSequence is what submits it.- const payload = buildPromptInjectionPayload({- providerId: this.providerId,- text,- forceBracketedPaste: text.includes('\n'),- });+ const payload = buildPromptInjectionPayload(text);return { payload, submitSequence, submitDelayMs };}}diff --git a/dash/apps/switchdash-desktop/src/renderer/lib/pty/prompt-injection.ts b/dash/apps/switchdash-desktop/src/renderer/lib/pty/prompt-injection.tsindex 90afa1ab1..3c29d8bc2 100644--- a/dash/apps/switchdash-desktop/src/renderer/lib/pty/prompt-injection.ts+++ b/dash/apps/switchdash-desktop/src/renderer/lib/pty/prompt-injection.ts@@ -5,18 +5,12 @@ export { buildPromptInjectionPayload } from '@shared/prompt-injection';type SendInput = (data: string) => Promise<unknown>;type InjectPromptArgs = {- providerId: string | undefined;text: string;- forceBracketedPaste?: boolean;sendInput: SendInput;};export async function pastePromptInjection(args: InjectPromptArgs): Promise<void> {- const payload = buildPromptInjectionPayload({- providerId: args.providerId,- text: args.text,- forceBracketedPaste: args.forceBracketedPaste,- });+ const payload = buildPromptInjectionPayload(args.text);if (!payload) return;await args.sendInput(payload);}diff --git a/dash/apps/switchdash-desktop/src/renderer/tests/prompt-injection.test.ts b/dash/apps/switchdash-desktop/src/renderer/tests/prompt-injection.test.tsindex 1a2caeec1..574a14f5a 100644--- a/dash/apps/switchdash-desktop/src/renderer/tests/prompt-injection.test.ts+++ b/dash/apps/switchdash-desktop/src/renderer/tests/prompt-injection.test.ts@@ -5,35 +5,48 @@ import {} from '@renderer/lib/pty/prompt-injection';describe('prompt injection', () => {- it('keeps Claude multiline input unwrapped by default', () => {- expect(- buildPromptInjectionPayload({- providerId: 'claude',- text: 'Line one\nLine two',- })- ).toBe('Line one\nLine two');+ it('wraps single-line input in bracketed paste so @ does not trigger autocomplete', () => {+ // A raw `@` would open Claude Code's file-path autocomplete and swallow the+ // follow-up Enter (CHOO-1395); bracketed paste inserts it literally.+ expect(buildPromptInjectionPayload('[Switch] alice addressed you: @worker ping')).toBe(+ '\x1b[200~[Switch] alice addressed you: @worker ping \x1b[201~'+ );});- it('can force bracketed paste for multiline context blobs', async () => {+ it('terminates a trailing @mention so the cursor does not sit on an open picker', () => {+ // End-of-message tags always reproduced CHOO-1395 even with bracketing: the+ // cursor landed on the @token and reopened the picker. The trailing space+ // moves the cursor past it.+ expect(buildPromptInjectionPayload('ping @worker')).toBe('\x1b[200~ping @worker \x1b[201~');+ });++ it('wraps multiline input in bracketed paste', () => {+ expect(buildPromptInjectionPayload('Line one\nLine two')).toBe(+ '\x1b[200~Line one\nLine two \x1b[201~'+ );+ });++ it('trims surrounding whitespace before wrapping', () => {+ expect(buildPromptInjectionPayload(' hello ')).toBe('\x1b[200~hello \x1b[201~');+ });++ it('returns empty for whitespace-only input so callers can skip it', () => {+ expect(buildPromptInjectionPayload(' ')).toBe('');+ });++ it('sends the bracketed payload through sendInput', async () => {const sendInput = vi.fn().mockResolvedValue(undefined);- await pastePromptInjection({- providerId: 'claude',- text: 'Line one\nLine two',- forceBracketedPaste: true,- sendInput,- });+ await pastePromptInjection({ text: '/var/folders/example image.png', sendInput });- expect(sendInput).toHaveBeenCalledWith('\x1b[200~Line one\nLine two\x1b[201~');+ expect(sendInput).toHaveBeenCalledWith('\x1b[200~/var/folders/example image.png \x1b[201~');});- it('can force bracketed paste for single-line file drops', () => {- expect(- buildPromptInjectionPayload({- providerId: undefined,- text: '/var/folders/example image.png',- forceBracketedPaste: true,- })- ).toBe('\x1b[200~/var/folders/example image.png\x1b[201~');+ it('does not call sendInput for empty input', async () => {+ const sendInput = vi.fn().mockResolvedValue(undefined);++ await pastePromptInjection({ text: ' ', sendInput });++ expect(sendInput).not.toHaveBeenCalled();});});diff --git a/dash/apps/switchdash-desktop/src/shared/prompt-injection.ts b/dash/apps/switchdash-desktop/src/shared/prompt-injection.tsindex 300103468..0540dca33 100644--- a/dash/apps/switchdash-desktop/src/shared/prompt-injection.ts+++ b/dash/apps/switchdash-desktop/src/shared/prompt-injection.ts@@ -1,12 +1,26 @@-export function buildPromptInjectionPayload(args: {- providerId: string | undefined;- text: string;- forceBracketedPaste?: boolean;-}): string {- const trimmed = args.text.trim();- const hasMultilinePayload = trimmed.includes('\n');- const shouldUseBracketedPaste =- args.forceBracketedPaste || (args.providerId !== 'claude' && hasMultilinePayload);- if (!shouldUseBracketedPaste) return trimmed;- return `\x1b[200~${trimmed}\x1b[201~`;+/**+ * Wraps injected prompt text in bracketed-paste markers (`ESC[200~ … ESC[201~`)+ * with a trailing space inside the paste.+ *+ * Keystroke-injected messages are written into the agent's TUI as if typed. A+ * TUI runs its per-keystroke handlers on that input, so a raw `@` opens Claude+ * Code's file-path autocomplete and a leading `/` opens the slash-command menu —+ * and the follow-up Enter then selects a menu entry instead of submitting,+ * leaving the message in the box (often with a stray file path glued in).+ * Bracketed paste tells the TUI the bytes are pasted, not typed, so it inserts+ * them literally: no per-key autocomplete, no early submit on embedded newlines,+ * and the whole body commits atomically when the closing marker arrives.+ *+ * Bracketing alone is not enough when the body *ends* with an `@mention` (Switch+ * addressed messages routinely do): after the paste settles the cursor sits+ * right after the `@token`, so Claude reopens the file picker on that token and+ * the follow-up Enter selects a completion (CHOO-1395). The trailing space —+ * placed inside the paste so it is inserted literally and can never be read as an+ * "accept" keystroke — terminates that token, leaving the cursor past it so no+ * picker is open when the separate submit keystroke lands.+ */+export function buildPromptInjectionPayload(text: string): string {+ const trimmed = text.trim();+ if (!trimmed) return '';+ return `\x1b[200~${trimmed} \x1b[201~`;}