From e19400bf5a717873cdb10acc5289b1cedfe0a44e Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Fri, 18 Jul 2025 09:52:46 -0700 Subject: [PATCH] feat: delete compaction --- core/core.ts | 16 ++++++- core/protocol/core.ts | 7 ++++ core/protocol/passThrough.ts | 1 + core/util/conversationCompaction.ts | 41 ++++++++++++++++++ .../constants/MessageTypes.kt | 1 + .../StepContainer/ConversationSummary.tsx | 15 ++++++- gui/src/redux/slices/sessionSlice.ts | 11 +++++ gui/src/util/compactConversation.ts | 42 ++++++++++++++++++- 8 files changed, 131 insertions(+), 3 deletions(-) diff --git a/core/core.ts b/core/core.ts index a3fe4cab5..92c40b67d 100644 --- a/core/core.ts +++ b/core/core.ts @@ -24,7 +24,7 @@ import { createNewPromptFileV2 } from "./promptFiles/createNewPromptFile"; import { callTool } from "./tools/callTool"; import { ChatDescriber } from "./util/chatDescriber"; import { clipboardCache } from "./util/clipboardCache"; -import { compactConversation } from "./util/conversationCompaction"; +import { compactConversation, deleteCompaction } from "./util/conversationCompaction"; import { GlobalContext } from "./util/GlobalContext"; import historyManager from "./util/history"; import { editConfigFile, migrateV1DevDataFiles } from "./util/paths"; @@ -572,6 +572,20 @@ export class Core { } }); + on("conversation/deleteCompaction", async (msg) => { + try { + await deleteCompaction({ + sessionId: msg.data.sessionId, + index: msg.data.index, + historyManager, + }); + return undefined; + } catch (error) { + console.error("Error deleting compaction:", error); + return undefined; + } + }); + // Autocomplete on("autocomplete/complete", async (msg) => { const outcome = diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 251922696..f208b0fb4 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -193,6 +193,13 @@ export type ToCoreFromIdeOrWebviewProtocol = { }, string | undefined, ]; + "conversation/deleteCompaction": [ + { + index: number; + sessionId: string; + }, + void, + ]; "stats/getTokensPerDay": [ undefined, { day: string; promptTokens: number; generatedTokens: number }[], diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 6e25e5f54..5dbb7b341 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -48,6 +48,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "streamDiffLines", "chatDescriber/describe", "conversation/compact", + "conversation/deleteCompaction", "stats/getTokensPerDay", "stats/getTokensPerModel", // Codebase diff --git a/core/util/conversationCompaction.ts b/core/util/conversationCompaction.ts index 541d7d520..4c5a28c04 100644 --- a/core/util/conversationCompaction.ts +++ b/core/util/conversationCompaction.ts @@ -9,6 +9,12 @@ export interface CompactionParams { currentModel: ILLM; } +export interface DeleteCompactionParams { + sessionId: string; + index: number; + historyManager: HistoryManager; +} + /** * Compacts conversation history up to a specified index by generating a summary. * This helper function extracts the compaction logic from the main core handler. @@ -87,3 +93,38 @@ export async function compactConversation({ historyManager.save(updatedSession); } + +/** + * Deletes a conversation summary from a specific message in the history. + * This function removes the conversationSummary property from the specified message. + * + * @param params - Object containing sessionId, index, and historyManager + * @returns Promise - Updates the session with the conversation summary removed + */ +export async function deleteCompaction({ + sessionId, + index, + historyManager, +}: DeleteCompactionParams): Promise { + // Get the current session + const session = historyManager.load(sessionId); + + // Create a copy of the history + const updatedHistory = [...session.history]; + + // Remove the conversation summary from the specified message + if (updatedHistory[index]?.conversationSummary) { + updatedHistory[index] = { + ...updatedHistory[index], + conversationSummary: undefined, + }; + } + + // Update the session with the modified history + const updatedSession = { + ...session, + history: updatedHistory, + }; + + historyManager.save(updatedSession); +} diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt index 02fedb3b3..5630bea57 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt @@ -114,6 +114,7 @@ class MessageTypes { "streamDiffLines", "chatDescriber/describe", "conversation/compact", + "conversation/deleteCompaction", "stats/getTokensPerDay", "stats/getTokensPerModel", // Codebase diff --git a/gui/src/components/StepContainer/ConversationSummary.tsx b/gui/src/components/StepContainer/ConversationSummary.tsx index 78c3043f9..32c4aef02 100644 --- a/gui/src/components/StepContainer/ConversationSummary.tsx +++ b/gui/src/components/StepContainer/ConversationSummary.tsx @@ -1,9 +1,12 @@ import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/solid"; +import { TrashIcon } from "@heroicons/react/24/outline"; import { ChatHistoryItem } from "core"; import { useState } from "react"; import { AnimatedEllipsis } from "../"; import { useAppSelector } from "../../redux/hooks"; import StyledMarkdownPreview from "../StyledMarkdownPreview"; +import { useDeleteCompaction } from "../../util/compactConversation"; +import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; interface ConversationSummaryProps { item: ChatHistoryItem; @@ -15,6 +18,7 @@ export default function ConversationSummary(props: ConversationSummaryProps) { const isLoading = useAppSelector( (state) => state.session.compactionLoading[props.index] || false, ); + const deleteCompaction = useDeleteCompaction(); if (!props.item.conversationSummary && !isLoading) { return null; @@ -47,7 +51,16 @@ export default function ConversationSummary(props: ConversationSummaryProps) { ) : ( )} - Conversation Summary + Conversation Summary + { + e.stopPropagation(); + deleteCompaction(props.index); + }} + > + + {open && ( <> diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 76c7b9410..a93221935 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -437,6 +437,16 @@ export const sessionSlice = createSlice({ state.isPruned = false; state.contextPercentage = undefined; }, + deleteCompaction: (state, action: PayloadAction) => { + // Removes the conversation summary from the specified message + const historyItem = state.history[action.payload]; + if (historyItem?.conversationSummary) { + state.history[action.payload] = { + ...historyItem, + conversationSummary: undefined, + }; + } + }, updateHistoryItemAtIndex: ( state, { @@ -992,6 +1002,7 @@ export const { clearDanglingMessages, setMainEditorContentTrigger, deleteMessage, + deleteCompaction, setIsGatheringContext, resetNextCodeBlockToApplyIndex, updateApplyState, diff --git a/gui/src/util/compactConversation.ts b/gui/src/util/compactConversation.ts index 1908e8d62..5e58a0ff3 100644 --- a/gui/src/util/compactConversation.ts +++ b/gui/src/util/compactConversation.ts @@ -1,7 +1,7 @@ import { useContext } from "react"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; -import { setCompactionLoading } from "../redux/slices/sessionSlice"; +import { setCompactionLoading, deleteCompaction } from "../redux/slices/sessionSlice"; import { loadSession } from "../redux/thunks/session"; export const useCompactConversation = () => { @@ -37,4 +37,44 @@ export const useCompactConversation = () => { dispatch(setCompactionLoading({ index, loading: false })); } }; +}; + +export const useDeleteCompaction = () => { + const dispatch = useAppDispatch(); + const ideMessenger = useContext(IdeMessengerContext); + const currentSessionId = useAppSelector((state) => state.session.id); + + return async (index: number) => { + if (!currentSessionId) { + return; + } + + try { + // Update local state immediately + dispatch(deleteCompaction(index)); + + // Communicate with core to persist the change + await ideMessenger.request("conversation/deleteCompaction", { + index, + sessionId: currentSessionId, + }); + + // Reload the current session to refresh the conversation state + dispatch( + loadSession({ + sessionId: currentSessionId, + saveCurrentSession: false, + }), + ); + } catch (error) { + console.error("Error deleting compaction:", error); + // Optionally reload session to revert optimistic update + dispatch( + loadSession({ + sessionId: currentSessionId, + saveCurrentSession: false, + }), + ); + } + }; }; \ No newline at end of file