diff --git a/core/core.ts b/core/core.ts index e61c7240e..e31eb5c2e 100644 --- a/core/core.ts +++ b/core/core.ts @@ -432,6 +432,23 @@ export class Core { } }); + on("config/deleteRule", async (msg) => { + try { + const filepath = msg.data.filepath; + const fileExists = await this.ide.fileExists(filepath); + if (fileExists) { + await this.ide.removeFile(filepath); + walkDirCache.invalidate(); + await this.configHandler.reloadConfig( + "Rule file deleted (config/deleteRule message)", + ); + } + } catch (error) { + console.error("Failed to delete rule file:", error); + throw error; + } + }); + on("config/openProfile", async (msg) => { await this.configHandler.openConfigProfile(msg.data.profileId); }); diff --git a/core/protocol/core.ts b/core/protocol/core.ts index bfa858709..6659f157e 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -95,6 +95,7 @@ export type ToCoreFromIdeOrWebviewProtocol = { void, ]; "config/addGlobalRule": [undefined | { baseFilename?: string }, void]; + "config/deleteRule": [{ filepath: string }, void]; "config/newPromptFile": [undefined, void]; "config/newAssistantFile": [undefined, void]; "config/ideSettingsUpdate": [IdeSettings, void]; diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index f77b7a05d..9d752b311 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -23,6 +23,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "config/ideSettingsUpdate", "config/addLocalWorkspaceBlock", "config/addGlobalRule", + "config/deleteRule", "config/getSerializedProfileInfo", "config/deleteModel", "config/refreshProfiles", 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 534985a65..b7224d8d5 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 @@ -84,6 +84,8 @@ class MessageTypes { "config/newAssistantFile", "config/ideSettingsUpdate", "config/addLocalWorkspaceBlock", + "config/addGlobalRule", + "config/deleteRule", "config/getSerializedProfileInfo", "config/deleteModel", "config/refreshProfiles", diff --git a/gui/src/pages/config/sections/RulesSection.tsx b/gui/src/pages/config/sections/RulesSection.tsx index 205f1ddaa..831de5f67 100644 --- a/gui/src/pages/config/sections/RulesSection.tsx +++ b/gui/src/pages/config/sections/RulesSection.tsx @@ -4,6 +4,7 @@ import { BookmarkIcon as BookmarkOutline, EyeIcon, PencilIcon, + TrashIcon, } from "@heroicons/react/24/outline"; import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid"; import { @@ -21,6 +22,7 @@ import { getRuleDisplayName } from "core/llm/rules/rules-utils"; import { useContext, useMemo, useState } from "react"; import { DropdownButton } from "../../../components/DropdownButton"; import AddRuleDialog from "../../../components/dialogs/AddRuleDialog"; +import ConfirmationDialog from "../../../components/dialogs/ConfirmationDialog"; import HeaderButtonWithToolTip from "../../../components/gui/HeaderButtonWithToolTip"; import Switch from "../../../components/gui/Switch"; import { @@ -132,6 +134,7 @@ interface RuleCardProps { const RuleCard: React.FC = ({ rule }) => { const dispatch = useAppDispatch(); + const ideMessenger = useContext(IdeMessengerContext); const policy = useAppSelector((state) => rule.name ? state.ui.ruleSettings[rule.name] || DEFAULT_RULE_SETTING @@ -162,6 +165,36 @@ const RuleCard: React.FC = ({ rule }) => { ); } + const handleDelete = () => { + if (!rule.sourceFile) { + return; + } + + dispatch( + setDialogMessage( + { + try { + await ideMessenger.request("config/deleteRule", { + filepath: rule.sourceFile!, + }); + } catch (error) { + console.error("Failed to delete rule file:", error); + } + }} + />, + ), + ); + dispatch(setShowDialog(true)); + }; + + const canDeleteRule = + rule.sourceFile && + !["default-chat", "default-agent", "default-plan"].includes(rule.source); + const smallFont = fontSize(-2); const tinyFont = fontSize(-3); return ( @@ -209,6 +242,11 @@ const RuleCard: React.FC = ({ rule }) => { )} + {canDeleteRule && ( + + + + )}