Changesets · Branches · Tags · Compare
| Changeset | 54d55003e0dd3338ea5d0ce04a956a8a34c1a7d60abf7d7f6a324ea99e6cda98 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-11 12:20 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-09-11 12:20 -07:00 |
| Parents | c302a3f43ba7, 4ad58566a4b3 |
14 files changed
modified .github/workflows/continue-detailed-review.yaml +1 −1
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | timeout-minutes: 10 |
| 19 | 19 | steps: |
| 20 | 20 | - name: Run Detailed PR Review |
| 21 | - uses: continuedev/continue/actions/detailed-review@b3f4b82600f603ca28c65a319b80ec36c4644ed7 | |
| 21 | + uses: continuedev/continue/actions/detailed-review@5dc7a050db441934c26eb910b8433291f627db7f | |
| 22 | 22 | with: |
| 23 | 23 | continue-api-key: ${{ secrets.CONTINUE_API_KEY }} |
| 24 | 24 | continue-org: continuedev |
modified .github/workflows/continue-general-review.yaml +1 −1
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | timeout-minutes: 10 |
| 19 | 19 | steps: |
| 20 | 20 | - name: Run Continue PR Review Action |
| 21 | - uses: continuedev/continue/actions/general-review@b3f4b82600f603ca28c65a319b80ec36c4644ed7 | |
| 21 | + uses: continuedev/continue/actions/general-review@5dc7a050db441934c26eb910b8433291f627db7f | |
| 22 | 22 | with: |
| 23 | 23 | continue-api-key: ${{ secrets.CONTINUE_API_KEY }} |
| 24 | 24 | continue-org: "continuedev" |
modified core/config/types.ts +1 −0
| @@ -1061,6 +1061,7 @@ | ||
| 1061 | 1061 | filepath?: string; |
| 1062 | 1062 | fileContent?: string; |
| 1063 | 1063 | originalFileContent?: string; |
| 1064 | + autoFormattingDiff?: string; | |
| 1064 | 1065 | } |
| 1065 | 1066 | |
| 1066 | 1067 | export interface RangeInFileWithContents { |
modified core/index.d.ts +1 −0
| @@ -1387,6 +1387,7 @@ | ||
| 1387 | 1387 | fileContent?: string; |
| 1388 | 1388 | originalFileContent?: string; |
| 1389 | 1389 | toolCallId?: string; |
| 1390 | + autoFormattingDiff?: string; | |
| 1390 | 1391 | } |
| 1391 | 1392 | |
| 1392 | 1393 | export interface StreamDiffLinesPayload { |
added extensions/cli/src/stream/messageQueue.test.ts +62 −0
| @@ -0,0 +1,62 @@ | ||
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 2 | + | |
| 3 | +vi.mock("../util/logger.js", () => ({ | |
| 4 | + logger: { | |
| 5 | + debug: vi.fn(), | |
| 6 | + info: vi.fn(), | |
| 7 | + warn: vi.fn(), | |
| 8 | + error: vi.fn(), | |
| 9 | + setLevel: vi.fn(), | |
| 10 | + configureHeadlessMode: vi.fn(), | |
| 11 | + getLogPath: vi.fn(), | |
| 12 | + getSessionId: vi.fn(), | |
| 13 | + }, | |
| 14 | +})); | |
| 15 | + | |
| 16 | +import { messageQueue } from "./messageQueue.js"; | |
| 17 | + | |
| 18 | +describe("messageQueue", () => { | |
| 19 | + beforeEach(() => { | |
| 20 | + // Drain any leftover items from previous tests | |
| 21 | + while (messageQueue.getAllQueuedMessages()) {} | |
| 22 | + }); | |
| 23 | + | |
| 24 | + it("enqueues and emits messageQueued", async () => { | |
| 25 | + const event = new Promise<any>((resolve) => | |
| 26 | + messageQueue.once("messageQueued", resolve), | |
| 27 | + ); | |
| 28 | + | |
| 29 | + const ok = await messageQueue.enqueueMessage("hello world"); | |
| 30 | + expect(ok).toBe(true); | |
| 31 | + expect(messageQueue.getQueueLength()).toBe(1); | |
| 32 | + | |
| 33 | + const queued = await event; | |
| 34 | + expect(queued.message).toBe("hello world"); | |
| 35 | + }); | |
| 36 | + | |
| 37 | + it("combines messages, merges image maps, writes history, and clears queue", async () => { | |
| 38 | + const bufA = Buffer.from("A"); | |
| 39 | + const bufB = Buffer.from("B"); | |
| 40 | + | |
| 41 | + const img1 = new Map<string, Buffer>([["a", bufA]]); | |
| 42 | + const img2 = new Map<string, Buffer>([["b", bufB]]); | |
| 43 | + | |
| 44 | + const history = { addEntry: vi.fn() } as any; | |
| 45 | + | |
| 46 | + await messageQueue.enqueueMessage("one", img1); | |
| 47 | + await messageQueue.enqueueMessage("two", img2, history); | |
| 48 | + | |
| 49 | + const combined = messageQueue.getAllQueuedMessages(); | |
| 50 | + expect(combined).toBeTruthy(); | |
| 51 | + expect(combined!.message).toBe("one\ntwo"); | |
| 52 | + expect(combined!.imageMap).toBeDefined(); | |
| 53 | + expect(combined!.imageMap!.get("a")).toEqual(bufA); | |
| 54 | + expect(combined!.imageMap!.get("b")).toEqual(bufB); | |
| 55 | + | |
| 56 | + // queue should be cleared | |
| 57 | + expect(messageQueue.getQueueLength()).toBe(0); | |
| 58 | + | |
| 59 | + // input history should receive the combined message | |
| 60 | + expect(history.addEntry).toHaveBeenCalledWith("one\ntwo"); | |
| 61 | + }); | |
| 62 | +}); |
added extensions/cli/src/stream/messageQueue.ts +94 −0
| @@ -0,0 +1,94 @@ | ||
| 1 | +import { EventEmitter } from "events"; | |
| 2 | + | |
| 3 | +import { InputHistory } from "../util/inputHistory.js"; | |
| 4 | +import { logger } from "../util/logger.js"; | |
| 5 | + | |
| 6 | +export interface QueuedMessage { | |
| 7 | + message: string; | |
| 8 | + imageMap?: Map<string, Buffer>; | |
| 9 | + timestamp: number; | |
| 10 | +} | |
| 11 | + | |
| 12 | +export interface MessageProcessor { | |
| 13 | + (message: string, imageMap?: Map<string, Buffer>): Promise<void>; | |
| 14 | +} | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * A queue to store messages that need to be processed later | |
| 18 | + */ | |
| 19 | +class MessageQueue extends EventEmitter { | |
| 20 | + private queue: QueuedMessage[] = []; | |
| 21 | + private inputHistory: InputHistory | undefined; | |
| 22 | + | |
| 23 | + constructor() { | |
| 24 | + super(); | |
| 25 | + } | |
| 26 | + | |
| 27 | + async enqueueMessage( | |
| 28 | + message: string, | |
| 29 | + imageMap?: Map<string, Buffer>, | |
| 30 | + inputHistory?: InputHistory, | |
| 31 | + ): Promise<boolean> { | |
| 32 | + this.inputHistory = inputHistory; | |
| 33 | + | |
| 34 | + const queuedMessage: QueuedMessage = { | |
| 35 | + message, | |
| 36 | + imageMap, | |
| 37 | + timestamp: Date.now(), | |
| 38 | + }; | |
| 39 | + | |
| 40 | + this.queue.push(queuedMessage); | |
| 41 | + logger.debug("MessageQueue: Message queued", { | |
| 42 | + queueLength: this.queue.length, | |
| 43 | + }); | |
| 44 | + | |
| 45 | + // Emit event for UI to show the queued message | |
| 46 | + this.emit("messageQueued", queuedMessage); | |
| 47 | + | |
| 48 | + return true; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public getAllQueuedMessages() { | |
| 52 | + if (this.queue.length === 0) return undefined; | |
| 53 | + | |
| 54 | + // Combine all queued messages into one | |
| 55 | + const combinedMessage = this.queue.map((msg) => msg.message).join("\n"); | |
| 56 | + const combinedImageMap = new Map<string, Buffer>(); | |
| 57 | + | |
| 58 | + // Merge all image maps | |
| 59 | + for (const queuedMsg of this.queue) { | |
| 60 | + if (queuedMsg.imageMap) { | |
| 61 | + for (const [key, value] of queuedMsg.imageMap) { | |
| 62 | + combinedImageMap.set(key, value); | |
| 63 | + } | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + const result = { | |
| 68 | + message: combinedMessage, | |
| 69 | + imageMap: combinedImageMap.size > 0 ? combinedImageMap : undefined, | |
| 70 | + timestamp: Date.now(), | |
| 71 | + }; | |
| 72 | + | |
| 73 | + // Add to input history and clear the queue | |
| 74 | + this.inputHistory?.addEntry(combinedMessage); | |
| 75 | + this.queue = []; | |
| 76 | + | |
| 77 | + logger.debug("MessageQueue: All messages dequeued and combined", { | |
| 78 | + combinedLength: combinedMessage.length, | |
| 79 | + queueLength: this.queue.length, | |
| 80 | + }); | |
| 81 | + | |
| 82 | + return result; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public getLatestMessage() { | |
| 86 | + return this.getAllQueuedMessages(); | |
| 87 | + } | |
| 88 | + | |
| 89 | + getQueueLength(): number { | |
| 90 | + return this.queue.length; | |
| 91 | + } | |
| 92 | +} | |
| 93 | + | |
| 94 | +export const messageQueue = new MessageQueue(); |
modified extensions/cli/src/ui/TUIChat.tsx +2 −0
| @@ -188,6 +188,7 @@ | ||
| 188 | 188 | inputMode, |
| 189 | 189 | activePermissionRequest, |
| 190 | 190 | wasInterrupted, |
| 191 | + queuedMessages, | |
| 191 | 192 | handleUserMessage, |
| 192 | 193 | handleInterrupt, |
| 193 | 194 | handleFileAttached, |
| @@ -282,6 +283,7 @@ | ||
| 282 | 283 | model={services.model?.model || undefined} |
| 283 | 284 | mcpService={services.mcp?.mcpService || undefined} |
| 284 | 285 | chatHistory={chatHistory} |
| 286 | + queuedMessages={queuedMessages} | |
| 285 | 287 | renderMessage={renderMessage} |
| 286 | 288 | refreshTrigger={staticRefreshTrigger} |
| 287 | 289 | /> |
modified extensions/cli/src/ui/UserInput.tsx +12 −15
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | import type { FileIndexServiceState } from "../services/FileIndexService.js"; |
| 10 | 10 | import { SERVICE_NAMES, serviceContainer } from "../services/index.js"; |
| 11 | 11 | import { modeService } from "../services/ModeService.js"; |
| 12 | +import { messageQueue } from "../stream/messageQueue.js"; | |
| 12 | 13 | import { InputHistory } from "../util/inputHistory.js"; |
| 13 | 14 | |
| 14 | 15 | import { FileSearchUI } from "./FileSearchUI.js"; |
| @@ -515,7 +516,7 @@ | ||
| 515 | 516 | } |
| 516 | 517 | |
| 517 | 518 | // Normal Enter behavior - submit if there's content |
| 518 | - if ((textBuffer.text.trim() || wasInterrupted) && !isWaitingForResponse) { | |
| 519 | + if (textBuffer.text.trim() || wasInterrupted) { | |
| 519 | 520 | // Get images before expanding paste blocks |
| 520 | 521 | const imageMap = textBuffer.getAllImages(); |
| 521 | 522 | |
| @@ -523,14 +524,19 @@ | ||
| 523 | 524 | textBuffer.expandAllPasteBlocks(); |
| 524 | 525 | const submittedText = textBuffer.text.trim(); |
| 525 | 526 | |
| 526 | - // Only add to history if there's actual text (not when resuming) | |
| 527 | - if (submittedText) { | |
| 527 | + if (isWaitingForResponse) { | |
| 528 | + // Process message later when LLM has responded | |
| 529 | + void messageQueue.enqueueMessage( | |
| 530 | + submittedText, | |
| 531 | + imageMap, | |
| 532 | + inputHistory, | |
| 533 | + ); | |
| 534 | + } else { | |
| 535 | + // Submit with images | |
| 528 | 536 | inputHistory.addEntry(submittedText); |
| 537 | + onSubmit(submittedText, imageMap); | |
| 529 | 538 | } |
| 530 | 539 | |
| 531 | - // Submit with images | |
| 532 | - onSubmit(submittedText, imageMap); | |
| 533 | - | |
| 534 | 540 | textBuffer.clear(); |
| 535 | 541 | setInputText(""); |
| 536 | 542 | setCursorPosition(0); |
| @@ -647,15 +653,6 @@ | ||
| 647 | 653 | return; |
| 648 | 654 | } |
| 649 | 655 | |
| 650 | - // Allow typing during streaming, but block submission | |
| 651 | - if (!inputMode) { | |
| 652 | - // Block only Enter key submission during streaming | |
| 653 | - if (key.return && !key.shift) { | |
| 654 | - return; | |
| 655 | - } | |
| 656 | - // Allow all other input (typing, navigation, etc.) | |
| 657 | - } | |
| 658 | - | |
| 659 | 656 | // Handle slash command navigation |
| 660 | 657 | if (showSlashCommands) { |
| 661 | 658 | if (handleSlashCommandNavigation(key)) { |
modified extensions/cli/src/ui/components/StaticChatContent.tsx +13 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import type { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 2 | -import { Box, Static, useStdout } from "ink"; | |
| 2 | +import { Box, Static, Text, useStdout } from "ink"; | |
| 3 | 3 | import React, { useCallback, useEffect, useRef, useState } from "react"; |
| 4 | 4 | |
| 5 | 5 | import type { ChatHistoryItem } from "../../../../../core/index.js"; |
| 6 | 6 | import type { MCPService } from "../../services/MCPService.js"; |
| 7 | +import type { QueuedMessage } from "../../stream/messageQueue.js"; | |
| 7 | 8 | import { useTerminalSize } from "../hooks/useTerminalSize.js"; |
| 8 | 9 | import { IntroMessage } from "../IntroMessage.js"; |
| 9 | 10 | |
| @@ -13,6 +14,7 @@ | ||
| 13 | 14 | model?: ModelConfig; |
| 14 | 15 | mcpService?: MCPService; |
| 15 | 16 | chatHistory: ChatHistoryItem[]; |
| 17 | + queuedMessages?: QueuedMessage[]; | |
| 16 | 18 | renderMessage: (item: ChatHistoryItem, index: number) => React.ReactElement; |
| 17 | 19 | refreshTrigger?: number; // Add a prop to trigger refresh from parent |
| 18 | 20 | } |
| @@ -23,6 +25,7 @@ | ||
| 23 | 25 | model, |
| 24 | 26 | mcpService, |
| 25 | 27 | chatHistory, |
| 28 | + queuedMessages = [], | |
| 26 | 29 | renderMessage, |
| 27 | 30 | refreshTrigger, |
| 28 | 31 | }) => { |
| @@ -140,6 +143,15 @@ | ||
| 140 | 143 | <React.Fragment key={`pending-${index}`}>{item}</React.Fragment> |
| 141 | 144 | ))} |
| 142 | 145 | </Box> |
| 146 | + | |
| 147 | + {/* Queued messages - show at bottom with queue indicators */} | |
| 148 | + {queuedMessages.length > 0 && ( | |
| 149 | + <Box paddingLeft={2} paddingBottom={1}> | |
| 150 | + <Text color="gray" italic> | |
| 151 | + {queuedMessages.map((msg) => msg.message).join("\n")} | |
| 152 | + </Text> | |
| 153 | + </Box> | |
| 154 | + )} | |
| 143 | 155 | </Box> |
| 144 | 156 | ); |
| 145 | 157 | }; |
modified extensions/cli/src/ui/hooks/useChat.ts +126 −44
| @@ -1,3 +1,4 @@ | ||
| 1 | +/* eslint-disable max-lines */ | |
| 1 | 2 | import type { ChatHistoryItem, Session } from "core/index.js"; |
| 2 | 3 | import { useApp } from "ink"; |
| 3 | 4 | import { useEffect, useRef, useState } from "react"; |
| @@ -11,6 +12,7 @@ | ||
| 11 | 12 | updateSessionHistory, |
| 12 | 13 | } from "../../session.js"; |
| 13 | 14 | import { handleSlashCommands } from "../../slashCommands.js"; |
| 15 | +import { messageQueue, QueuedMessage } from "../../stream/messageQueue.js"; | |
| 14 | 16 | import { telemetryService } from "../../telemetry/telemetryService.js"; |
| 15 | 17 | import { formatError } from "../../util/formatError.js"; |
| 16 | 18 | import { logger } from "../../util/logger.js"; |
| @@ -166,6 +168,22 @@ | ||
| 166 | 168 | // Track interrupted state for resume functionality |
| 167 | 169 | const [wasInterrupted, setWasInterrupted] = useState(false); |
| 168 | 170 | |
| 171 | + // Track queued messages for immediate display | |
| 172 | + const [queuedMessages, setQueuedMessages] = useState<QueuedMessage[]>([]); | |
| 173 | + | |
| 174 | + // Set up message queue listeners | |
| 175 | + useEffect(() => { | |
| 176 | + const onMessageQueued = (queuedMessage: QueuedMessage) => { | |
| 177 | + setQueuedMessages((prev) => [...prev, queuedMessage]); | |
| 178 | + }; | |
| 179 | + | |
| 180 | + messageQueue.on("messageQueued", onMessageQueued); | |
| 181 | + | |
| 182 | + return () => { | |
| 183 | + messageQueue.off("messageQueued", onMessageQueued); | |
| 184 | + }; | |
| 185 | + }, []); | |
| 186 | + | |
| 169 | 187 | // Clean up abort controller on unmount |
| 170 | 188 | useEffect(() => { |
| 171 | 189 | return () => { |
| @@ -306,6 +324,30 @@ | ||
| 306 | 324 | setIsWaitingForResponse(false); |
| 307 | 325 | setResponseStartTime(null); |
| 308 | 326 | setInputMode(true); |
| 327 | + | |
| 328 | + // Check if there are queued messages and process them after a microtask delay | |
| 329 | + // This ensures the GUI state has been updated before processing the next message | |
| 330 | + const queuedMessageData = messageQueue.getLatestMessage(); | |
| 331 | + if (queuedMessageData) { | |
| 332 | + const { message: latestQueuedMessage, imageMap } = queuedMessageData; | |
| 333 | + logger.debug("processing queued message", { latestQueuedMessage }); | |
| 334 | + | |
| 335 | + // Clear all queued messages from display since we're processing them all together | |
| 336 | + setQueuedMessages([]); | |
| 337 | + | |
| 338 | + // Add the queued message to chat history so it shows in the GUI | |
| 339 | + const formattedQueuedMessage = await formatMessageWithFiles( | |
| 340 | + latestQueuedMessage, | |
| 341 | + [], // No attached files for queued messages | |
| 342 | + imageMap, | |
| 343 | + ); | |
| 344 | + setChatHistory((prev) => [...prev, formattedQueuedMessage]); | |
| 345 | + | |
| 346 | + await new Promise((resolve) => setTimeout(resolve, 100)); // add timeout for react to render the tui | |
| 347 | + | |
| 348 | + // Process the queued message using the internal processing logic without re-adding to history | |
| 349 | + await processQueuedMessage(latestQueuedMessage, imageMap); | |
| 350 | + } | |
| 309 | 351 | } |
| 310 | 352 | }; |
| 311 | 353 | |
| @@ -398,20 +440,11 @@ | ||
| 398 | 440 | .join(""); |
| 399 | 441 | }; |
| 400 | 442 | |
| 401 | - const handleUserMessage = async ( | |
| 443 | + const processMessage = async ( | |
| 402 | 444 | message: string, |
| 403 | 445 | imageMap?: Map<string, Buffer>, |
| 446 | + isQueuedMessage: boolean = false, | |
| 404 | 447 | ) => { |
| 405 | - // Check if this is a resume request (empty message after interruption) | |
| 406 | - if (await handleResumeRequest(message)) { | |
| 407 | - return; | |
| 408 | - } | |
| 409 | - | |
| 410 | - // Clear interrupted state if user types a new message | |
| 411 | - if (wasInterrupted && message !== "") { | |
| 412 | - setWasInterrupted(false); | |
| 413 | - } | |
| 414 | - | |
| 415 | 448 | // Handle special commands |
| 416 | 449 | const handled = await handleSpecialCommands({ |
| 417 | 450 | message, |
| @@ -440,27 +473,9 @@ | ||
| 440 | 473 | // Track telemetry |
| 441 | 474 | trackUserMessage(message, model); |
| 442 | 475 | |
| 443 | - // Format message with attached files and images | |
| 444 | - logger.debug("Processing message with images", { | |
| 445 | - hasImages: !!(imageMap && imageMap.size > 0), | |
| 446 | - imageCount: imageMap?.size || 0, | |
| 447 | - }); | |
| 448 | - const newUserMessage = await formatMessageWithFiles( | |
| 449 | - message, | |
| 450 | - attachedFiles, | |
| 451 | - imageMap, | |
| 452 | - ); | |
| 453 | - logger.debug("Message formatted successfully"); | |
| 454 | - | |
| 455 | - if (attachedFiles.length > 0) { | |
| 456 | - setAttachedFiles([]); | |
| 457 | - } | |
| 458 | - | |
| 459 | 476 | // In remote mode, send message to server instead of processing locally |
| 460 | 477 | if (isRemoteMode && remoteUrl) { |
| 461 | - const messageContentString = convertMessageContentToString( | |
| 462 | - newUserMessage.message.content, | |
| 463 | - ); | |
| 478 | + const messageContentString = convertMessageContentToString(message); | |
| 464 | 479 | |
| 465 | 480 | await handleRemoteMessage({ |
| 466 | 481 | remoteUrl, |
| @@ -469,23 +484,87 @@ | ||
| 469 | 484 | return; |
| 470 | 485 | } |
| 471 | 486 | |
| 472 | - // Check if auto-compacting is needed BEFORE adding user message | |
| 473 | - const { currentChatHistory, currentCompactionIndex } = | |
| 474 | - await handleAutoCompaction({ | |
| 475 | - chatHistory, | |
| 476 | - model, | |
| 477 | - llmApi, | |
| 478 | - compactionIndex, | |
| 479 | - setChatHistory: setChatHistory, | |
| 480 | - setCompactionIndex, | |
| 487 | + // For non-queued messages, format and add to chat history | |
| 488 | + if (isQueuedMessage) { | |
| 489 | + // For queued messages, chat history is already updated | |
| 490 | + // Check if auto-compacting is needed with current history | |
| 491 | + const { currentChatHistory, currentCompactionIndex } = | |
| 492 | + await handleAutoCompaction({ | |
| 493 | + chatHistory, | |
| 494 | + model, | |
| 495 | + llmApi, | |
| 496 | + compactionIndex, | |
| 497 | + setChatHistory: setChatHistory, | |
| 498 | + setCompactionIndex, | |
| 499 | + }); | |
| 500 | + | |
| 501 | + // Execute the streaming response with the current history (which already includes the queued message) | |
| 502 | + await executeStreamingResponse( | |
| 503 | + currentChatHistory, | |
| 504 | + currentCompactionIndex, | |
| 505 | + ); | |
| 506 | + } else { | |
| 507 | + // Format message with attached files and images | |
| 508 | + logger.debug("Processing message with images", { | |
| 509 | + hasImages: !!(imageMap && imageMap.size > 0), | |
| 510 | + imageCount: imageMap?.size || 0, | |
| 481 | 511 | }); |
| 512 | + const newUserMessage = await formatMessageWithFiles( | |
| 513 | + message, | |
| 514 | + attachedFiles, | |
| 515 | + imageMap, | |
| 516 | + ); | |
| 517 | + logger.debug("Message formatted successfully"); | |
| 482 | 518 | |
| 483 | - // Add the formatted user message to history | |
| 484 | - const newHistory = [...currentChatHistory, newUserMessage]; | |
| 485 | - setChatHistory(newHistory); | |
| 519 | + if (attachedFiles.length > 0) { | |
| 520 | + setAttachedFiles([]); | |
| 521 | + } | |
| 522 | + | |
| 523 | + // Check if auto-compacting is needed BEFORE adding user message | |
| 524 | + const { currentChatHistory, currentCompactionIndex } = | |
| 525 | + await handleAutoCompaction({ | |
| 526 | + chatHistory, | |
| 527 | + model, | |
| 528 | + llmApi, | |
| 529 | + compactionIndex, | |
| 530 | + setChatHistory: setChatHistory, | |
| 531 | + setCompactionIndex, | |
| 532 | + }); | |
| 533 | + | |
| 534 | + // Add the formatted user message to history | |
| 535 | + const newHistory = [...currentChatHistory, newUserMessage]; | |
| 536 | + setChatHistory(newHistory); | |
| 537 | + | |
| 538 | + // Execute the streaming response | |
| 539 | + await executeStreamingResponse(newHistory, currentCompactionIndex); | |
| 540 | + } | |
| 541 | + }; | |
| 542 | + | |
| 543 | + const processQueuedMessage = async ( | |
| 544 | + message: string, | |
| 545 | + imageMap?: Map<string, Buffer>, | |
| 546 | + ) => { | |
| 547 | + // For queued messages, we can reuse the core message processing logic | |
| 548 | + // by calling the internal processing function directly | |
| 549 | + await processMessage(message, imageMap, true); | |
| 550 | + }; | |
| 551 | + | |
| 552 | + const handleUserMessage = async ( | |
| 553 | + message: string, | |
| 554 | + imageMap?: Map<string, Buffer>, | |
| 555 | + ) => { | |
| 556 | + // Check if this is a resume request (empty message after interruption) | |
| 557 | + if (await handleResumeRequest(message)) { | |
| 558 | + return; | |
| 559 | + } | |
| 560 | + | |
| 561 | + // Clear interrupted state if user types a new message | |
| 562 | + if (wasInterrupted && message !== "") { | |
| 563 | + setWasInterrupted(false); | |
| 564 | + } | |
| 486 | 565 | |
| 487 | - // Execute the streaming response | |
| 488 | - await executeStreamingResponse(newHistory, currentCompactionIndex); | |
| 566 | + // Use the common message processing logic | |
| 567 | + await processMessage(message, imageMap, false); | |
| 489 | 568 | }; |
| 490 | 569 | |
| 491 | 570 | const handleInterrupt = () => { |
| @@ -537,6 +616,8 @@ | ||
| 537 | 616 | additionalRules, |
| 538 | 617 | ); |
| 539 | 618 | setChatHistory(newHistory); |
| 619 | + // Clear any queued messages when resetting chat | |
| 620 | + setQueuedMessages([]); | |
| 540 | 621 | }; |
| 541 | 622 | |
| 542 | 623 | const handleToolPermissionResponse = async ( |
| @@ -614,6 +695,7 @@ | ||
| 614 | 695 | attachedFiles, |
| 615 | 696 | activePermissionRequest, |
| 616 | 697 | wasInterrupted, |
| 698 | + queuedMessages, | |
| 617 | 699 | handleUserMessage, |
| 618 | 700 | handleInterrupt, |
| 619 | 701 | handleFileAttached, |
modified extensions/vscode/src/diff/processDiff.ts +38 −5
| @@ -1,8 +1,11 @@ | ||
| 1 | 1 | import { Core } from "core/core"; |
| 2 | 2 | import { DataLogger } from "core/data/log"; |
| 3 | +import { myersDiff } from "core/diff/myers"; | |
| 4 | + | |
| 3 | 5 | import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider"; |
| 4 | 6 | import { editOutcomeTracker } from "../extension/EditOutcomeTracker"; |
| 5 | 7 | import { VsCodeIde } from "../VsCodeIde"; |
| 8 | + | |
| 6 | 9 | import { VerticalDiffManager } from "./vertical/manager"; |
| 7 | 10 | |
| 8 | 11 | export async function processDiff( |
| @@ -42,7 +45,8 @@ | ||
| 42 | 45 | } |
| 43 | 46 | |
| 44 | 47 | if (streamId) { |
| 45 | - const fileContent = await ide.readFile(newOrCurrentUri); | |
| 48 | + // Capture file content before save to detect autoformatting | |
| 49 | + const preSaveContent = await ide.readFile(newOrCurrentUri); | |
| 46 | 50 | |
| 47 | 51 | // Record the edit outcome before updating the apply state |
| 48 | 52 | await editOutcomeTracker.recordEditOutcome( |
| @@ -51,16 +55,45 @@ | ||
| 51 | 55 | DataLogger.getInstance(), |
| 52 | 56 | ); |
| 53 | 57 | |
| 58 | + // Save the file | |
| 59 | + await ide.saveFile(newOrCurrentUri); | |
| 60 | + | |
| 61 | + // Capture file content after save to detect autoformatting | |
| 62 | + const postSaveContent = await ide.readFile(newOrCurrentUri); | |
| 63 | + | |
| 64 | + // Detect autoformatting by comparing normalized content | |
| 65 | + let autoFormattingDiff: string | undefined; | |
| 66 | + const normalizedPreSave = preSaveContent.trim(); | |
| 67 | + const normalizedPostSave = postSaveContent.trim(); | |
| 68 | + | |
| 69 | + if (normalizedPreSave !== normalizedPostSave) { | |
| 70 | + // Auto-formatting was applied by the editor | |
| 71 | + const diffLines = myersDiff(preSaveContent, postSaveContent); | |
| 72 | + autoFormattingDiff = diffLines | |
| 73 | + .map((line) => { | |
| 74 | + switch (line.type) { | |
| 75 | + case "old": | |
| 76 | + return `-${line.line}`; | |
| 77 | + case "new": | |
| 78 | + return `+${line.line}`; | |
| 79 | + case "same": | |
| 80 | + return ` ${line.line}`; | |
| 81 | + } | |
| 82 | + }) | |
| 83 | + .join("\n"); | |
| 84 | + } | |
| 85 | + | |
| 54 | 86 | await sidebar.webviewProtocol.request("updateApplyState", { |
| 55 | - fileContent, | |
| 87 | + fileContent: postSaveContent, // Use post-save content | |
| 56 | 88 | filepath: newOrCurrentUri, |
| 57 | 89 | streamId, |
| 58 | 90 | status: "closed", |
| 59 | 91 | numDiffs: 0, |
| 60 | 92 | toolCallId, |
| 93 | + autoFormattingDiff, // Include autoformatting diff | |
| 61 | 94 | }); |
| 95 | + } else { | |
| 96 | + // Save the file even if no streamId | |
| 97 | + await ide.saveFile(newOrCurrentUri); | |
| 62 | 98 | } |
| 63 | - | |
| 64 | - // Save the file | |
| 65 | - await ide.saveFile(newOrCurrentUri); | |
| 66 | 99 | } |
modified gui/src/components/mainInput/ContextStatus.tsx +22 −0
| @@ -1,3 +1,4 @@ | ||
| 1 | +import { useMemo, useRef } from "react"; | |
| 1 | 2 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 2 | 3 | import { saveCurrentSession } from "../../redux/thunks/session"; |
| 3 | 4 | import { useCompactConversation } from "../../util/compactConversation"; |
| @@ -8,15 +9,36 @@ | ||
| 8 | 9 | const contextPercentage = useAppSelector( |
| 9 | 10 | (state) => state.session.contextPercentage, |
| 10 | 11 | ); |
| 12 | + const selectedChatModel = useAppSelector( | |
| 13 | + (state) => state.config.config.selectedModelByRole.chat?.model, | |
| 14 | + ); | |
| 15 | + const previousHistoryLength = useRef<number | null>(null); | |
| 16 | + const previousSelectedChatModel = useRef<string | null>(null); | |
| 11 | 17 | const history = useAppSelector((state) => state.session.history); |
| 12 | 18 | const percent = Math.round((contextPercentage ?? 0) * 100); |
| 13 | 19 | const isPruned = useAppSelector((state) => state.session.isPruned); |
| 14 | 20 | |
| 21 | + const isDifferentModelAndSameHistory = useMemo(() => { | |
| 22 | + if (!selectedChatModel) return false; | |
| 23 | + // only reset if history changes | |
| 24 | + if (previousHistoryLength.current !== history.length) { | |
| 25 | + previousHistoryLength.current = history.length; | |
| 26 | + previousSelectedChatModel.current = selectedChatModel; | |
| 27 | + return false; | |
| 28 | + } | |
| 29 | + return previousSelectedChatModel.current !== selectedChatModel; | |
| 30 | + }, [history.length, selectedChatModel]); | |
| 31 | + | |
| 15 | 32 | const compactConversation = useCompactConversation(); |
| 16 | 33 | if (!isPruned && percent < 60) { |
| 17 | 34 | return null; |
| 18 | 35 | } |
| 19 | 36 | |
| 37 | + // if user changed to a different model, we shouldn't show the context status until the user sends a new message | |
| 38 | + if (isDifferentModelAndSameHistory) { | |
| 39 | + return null; | |
| 40 | + } | |
| 41 | + | |
| 20 | 42 | const barColorClass = isPruned ? "bg-error" : "bg-description"; |
| 21 | 43 | |
| 22 | 44 | return ( |
modified gui/src/redux/thunks/handleApplyStateUpdate.ts +45 −1
| @@ -83,12 +83,57 @@ | ||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | if (accepted) { |
| 86 | + // Add autoformatting diff to tool output if present | |
| 87 | + if (applyState.autoFormattingDiff) { | |
| 88 | + dispatch( | |
| 89 | + updateToolCallOutput({ | |
| 90 | + toolCallId: applyState.toolCallId, | |
| 91 | + contextItems: [ | |
| 92 | + { | |
| 93 | + icon: "info", | |
| 94 | + name: "Auto-formatting Applied", | |
| 95 | + description: "Editor auto-formatting changes", | |
| 96 | + content: `Along with your edits, the editor applied the following auto-formatting:\n\n${applyState.autoFormattingDiff}\n\n(Note: Pay close attention to changes such as single quotes being converted to double quotes, semicolons being removed or added, long lines being broken into multiple lines, adjusting indentation style, adding/removing trailing commas, etc. This will help you ensure future SEARCH/REPLACE operations to this file are accurate.)`, | |
| 97 | + hidden: false, | |
| 98 | + }, | |
| 99 | + ], | |
| 100 | + }), | |
| 101 | + ); | |
| 102 | + } | |
| 103 | + | |
| 86 | 104 | if (toolCallState.status !== "errored") { |
| 87 | 105 | dispatch( |
| 88 | 106 | acceptToolCall({ |
| 89 | 107 | toolCallId: applyState.toolCallId, |
| 90 | 108 | }), |
| 91 | 109 | ); |
| 110 | + dispatch( | |
| 111 | + updateToolCallOutput({ | |
| 112 | + toolCallId: applyState.toolCallId, | |
| 113 | + contextItems: [ | |
| 114 | + { | |
| 115 | + name: "Edit Success", | |
| 116 | + content: `Successfully edited ${applyState.filepath}`, | |
| 117 | + description: "", | |
| 118 | + hidden: true, | |
| 119 | + }, | |
| 120 | + ], | |
| 121 | + }), | |
| 122 | + ); | |
| 123 | + } else { | |
| 124 | + dispatch( | |
| 125 | + updateToolCallOutput({ | |
| 126 | + toolCallId: applyState.toolCallId, | |
| 127 | + contextItems: [ | |
| 128 | + { | |
| 129 | + name: "Edit Failed", | |
| 130 | + content: `Failed to edit ${applyState.filepath}. To continue working with the file, read it again to see the most up-to-date contents`, | |
| 131 | + description: "", | |
| 132 | + hidden: true, | |
| 133 | + }, | |
| 134 | + ], | |
| 135 | + }), | |
| 136 | + ); | |
| 92 | 137 | } |
| 93 | 138 | |
| 94 | 139 | void dispatch( |
| @@ -98,7 +143,6 @@ | ||
| 98 | 143 | ); |
| 99 | 144 | } |
| 100 | 145 | } |
| 101 | - // TODO return output from edit tools so the model knows the result | |
| 102 | 146 | } |
| 103 | 147 | } |
| 104 | 148 | } |
modified gui/src/util/clientTools/editImpl.ts +3 −9
| @@ -17,13 +17,13 @@ | ||
| 17 | 17 | filepath = filepath.slice(2); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - const openFiles = await extras.ideMessenger.ide.getOpenFiles(); | |
| 21 | 20 | let firstUriMatch = await resolveRelativePathInDir( |
| 22 | 21 | filepath, |
| 23 | 22 | extras.ideMessenger.ide, |
| 24 | 23 | ); |
| 25 | 24 | |
| 26 | 25 | if (!firstUriMatch) { |
| 26 | + const openFiles = await extras.ideMessenger.ide.getOpenFiles(); | |
| 27 | 27 | for (const uri of openFiles) { |
| 28 | 28 | if (uri.endsWith(filepath)) { |
| 29 | 29 | firstUriMatch = uri; |
| @@ -46,13 +46,7 @@ | ||
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | return { |
| 49 | - respondImmediately: true, | |
| 50 | - output: [ | |
| 51 | - { | |
| 52 | - name: "File edited successfully", | |
| 53 | - content: `Successfully initiated edit for ${firstUriMatch}`, | |
| 54 | - description: "File edit operation started", | |
| 55 | - }, | |
| 56 | - ], | |
| 49 | + respondImmediately: false, | |
| 50 | + output: undefined, // no immediate output - output for edit tools should be added based on apply state coming in | |
| 57 | 51 | }; |
| 58 | 52 | }; |