From aa502df75d769e24495f19b6f48e40131b032cae Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:12:50 -0800 Subject: [PATCH] Keep widened-clear sends going and read typed image mentions correctly Review follow-up. Refusing a send when text survives the widened clear dropped non-Claude sends without a notice and would refuse clears that landed but redrew slowly, so the body is written as before. An empty line again counts for an image-only send at the old timing, for agents that draw no chip. Agents that take images as typed `@path` mentions now expect the mention text, unwrapped from its paste framing, so their Enter no longer waits the 5 s cap. --- .../terminal/send/native-chat-input-clear.ts | 6 ++-- .../terminal/send/native-chat-paste-landed.ts | 3 +- .../send/native-chat-runtime-image-send.ts | 28 +++++++++++++------ .../send/native-chat-runtime-send.test.ts | 24 ++++++++++++++++ 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/renderer/src/components/native-chat/session/terminal/send/native-chat-input-clear.ts b/src/renderer/src/components/native-chat/session/terminal/send/native-chat-input-clear.ts index a87d149177d..88dff065164 100644 --- a/src/renderer/src/components/native-chat/session/terminal/send/native-chat-input-clear.ts +++ b/src/renderer/src/components/native-chat/session/terminal/send/native-chat-input-clear.ts @@ -65,10 +65,8 @@ export function clearThenWrite( writeBody() return } - clearAlone(AGENT_TUI_CLEAR_INPUT_MAX, () => - // Never paste onto text the clear could not remove; it would be submitted with the message. - readNativeChatInputLine(options?.readInputLine) ? refuse() : writeBody() - ) + // A refusal here would drop non-Claude sends silently, and a slow redraw would refuse a clear that landed. + clearAlone(AGENT_TUI_CLEAR_INPUT_MAX, writeBody) }) } diff --git a/src/renderer/src/components/native-chat/session/terminal/send/native-chat-paste-landed.ts b/src/renderer/src/components/native-chat/session/terminal/send/native-chat-paste-landed.ts index 1c532339c6b..a6019afcfc2 100644 --- a/src/renderer/src/components/native-chat/session/terminal/send/native-chat-paste-landed.ts +++ b/src/renderer/src/components/native-chat/session/terminal/send/native-chat-paste-landed.ts @@ -27,8 +27,9 @@ const squash = (text: string): string => text.replace(/\s+/g, '') /** Whether the line shows the whole message, given `expected` from nativeChatExpectedLine: its * text, or a text-paste chip; image chips alone prove only an image-only send. */ export function nativeChatLineShowsMessage(line: string, expected: string): boolean { + // An empty line counts only for an image-only send, at the old timing, for agents that draw no chip. if (!squash(line)) { - return false + return expected === '' } const withoutImages = line.replace(IMAGE_CHIP, '') const rest = squash(withoutImages.replace(TEXT_PASTE_CHIP, '')) diff --git a/src/renderer/src/components/native-chat/session/terminal/send/native-chat-runtime-image-send.ts b/src/renderer/src/components/native-chat/session/terminal/send/native-chat-runtime-image-send.ts index 17691a6dd5a..cdf26855cbb 100644 --- a/src/renderer/src/components/native-chat/session/terminal/send/native-chat-runtime-image-send.ts +++ b/src/renderer/src/components/native-chat/session/terminal/send/native-chat-runtime-image-send.ts @@ -2,10 +2,16 @@ import { sendNativeChatObservedWrites, type NativeChatObservedWrite } from './native-chat-observed-send' -import { agentImagePasteWrites } from '../../../../../../../shared/native-chat/input/composer/agent-image-paste' +import { + agentImagePasteWrites, + getAgentImageHandling +} from '../../../../../../../shared/native-chat/input/composer/agent-image-paste' import { agentImagePastePath } from '../../../../../../../shared/native-chat/input/composer/agent-image-paste-path' import type { AgentType } from '../../../../../../../shared/agent-status/contracts/agent-status-types' -import { BRACKETED_PASTE_START } from '../../../../../../../shared/terminal/input/terminal-bracketed-paste-text' +import { + BRACKETED_PASTE_END, + BRACKETED_PASTE_START +} from '../../../../../../../shared/terminal/input/terminal-bracketed-paste-text' import { sendRuntimePtyInput } from '@/runtime/hosted-terminals/input/runtime-terminal-input-send' import { NATIVE_CHAT_SUBMIT_DELAY_MS } from '../../../../../../../shared/native-chat/input/questions/native-chat-answer-stepping' import { @@ -42,7 +48,7 @@ export function sendNativeChatMessageWithImageAttachments( imagePaths.map((path) => buildNativeChatImagePasteBytes(agentImagePastePath(agent, path))), trimmedText.length > 0 ).map((data) => ({ data, delayBeforeMs: 0 })) - const mentions = typedImageMentions(writes) + const mentions = typedImageMentions(agent, writes) if (trimmedText) { writes.push({ data: buildNativeChatPasteBytes(text), @@ -88,7 +94,11 @@ export function sendNativeChatMessageWithImageAttachments( afterNativeChatPasteLands({ readInputLine: options?.readInputLine, lineWasEmpty, - text: typedImageMentions(imageWrites.map((data) => ({ data }))) + text, + text: + typedImageMentions( + agent, + imageWrites.map((data) => ({ data })) + ) + text, delay, submit: () => { sendRuntimePtyInput(ptyId, NATIVE_CHAT_SUBMIT, 'driving') @@ -116,10 +126,12 @@ export function sendNativeChatMessageWithImageAttachments( ) } -/** Agents without image paste get typed `@path` mentions, which the input line shows as text. */ -function typedImageMentions(writes: readonly { data: string }[]): string { +/** Agents without image paste get `@path` mentions, which their input line shows as text. */ +function typedImageMentions(agent: AgentType, writes: readonly { data: string }[]): string { + if (getAgentImageHandling(agent) === 'attachment') { + return '' + } return writes - .map((write) => write.data) - .filter((data) => !data.startsWith(BRACKETED_PASTE_START)) + .map((write) => write.data.replace(BRACKETED_PASTE_START, '').replace(BRACKETED_PASTE_END, '')) .join('') } diff --git a/src/renderer/src/components/native-chat/session/terminal/send/native-chat-runtime-send.test.ts b/src/renderer/src/components/native-chat/session/terminal/send/native-chat-runtime-send.test.ts index 42eff12febb..e063c9f0b00 100644 --- a/src/renderer/src/components/native-chat/session/terminal/send/native-chat-runtime-send.test.ts +++ b/src/renderer/src/components/native-chat/session/terminal/send/native-chat-runtime-send.test.ts @@ -16,6 +16,7 @@ vi.mock('@/runtime/hosted-terminals/input/runtime-terminal-verified-input', () = })) import { sendNativeChatMessage } from './native-chat-runtime-send' +import { sendNativeChatMessageWithImageAttachments } from './native-chat-runtime-image-send' import { resetNativeChatPtySendQueuesForTests } from './native-chat-pty-send-queue' import { nativeChatExpectedLine, nativeChatLineShowsMessage } from './native-chat-paste-landed' @@ -88,3 +89,26 @@ describe('nativeChatLineShowsMessage', () => { expect(nativeChatLineShowsMessage('[Image #1] Reply with PONG', expected)).toBe(true) }) }) + +describe('image sends to agents that take typed @path mentions', () => { + beforeEach(() => { + vi.useFakeTimers() + writes.length = 0 + }) + afterEach(() => { + resetNativeChatPtySendQueuesForTests() + vi.useRealTimers() + }) + + it('presses Enter once the line shows the mention and the caption', async () => { + let line = '' + sendNativeChatMessageWithImageAttachments('omp', 'pty-1', 'describe', ['/tmp/a.png'], { + readInputLine: () => line, + onWriteRejected: () => {} + }) + await vi.advanceTimersByTimeAsync(300) + line = '@/tmp/a.png describe' + await vi.advanceTimersByTimeAsync(800) + expect(writes.at(-1)).toBe('\r') + }) +})