From 0e5fce911f777ea769d185049aa3dfa5e47a988b Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:34:09 +0530 Subject: [PATCH 1/5] feat: allow renaming rule before creation --- core/config/workspace/workspaceBlocks.ts | 42 ++++++-- core/core.ts | 8 +- core/protocol/core.ts | 7 +- gui/src/components/dialogs/AddRuleDialog.tsx | 100 ++++++++++++++++++ .../pages/config/sections/RulesSection.tsx | 17 +-- 5 files changed, 155 insertions(+), 19 deletions(-) create mode 100644 gui/src/components/dialogs/AddRuleDialog.tsx diff --git a/core/config/workspace/workspaceBlocks.ts b/core/config/workspace/workspaceBlocks.ts index 9ba16b400..e3c8358e1 100644 --- a/core/config/workspace/workspaceBlocks.ts +++ b/core/config/workspace/workspaceBlocks.ts @@ -1,9 +1,9 @@ import { BlockType, ConfigYaml, - createRuleMarkdown, createPromptMarkdown, - RULE_FILE_EXTENSION, + createRuleMarkdown, + sanitizeRuleName, } from "@continuedev/config-yaml"; import * as YAML from "yaml"; import { IDE } from "../.."; @@ -116,13 +116,31 @@ export async function findAvailableFilename( fileExists: (uri: string) => Promise, extension?: string, isGlobal?: boolean, + baseFilenameOverride?: string, ): Promise { - // Differentiate filename based on whether its a global rule or a workspace rule - const baseFilename = - blockType === "rules" && isGlobal - ? "global-rule" - : `new-${BLOCK_TYPE_CONFIG[blockType]?.filename}`; const fileExtension = extension ?? getFileExtension(blockType); + let baseFilename: string; + + const trimmedOverride = baseFilenameOverride?.trim(); + if (trimmedOverride) { + if (blockType === "rules") { + const withoutExtension = trimmedOverride.replace(/\.[^./\\]+$/, ""); + const sanitized = sanitizeRuleName(withoutExtension); + baseFilename = + sanitized || + (isGlobal + ? "global-rule" + : `new-${BLOCK_TYPE_CONFIG[blockType]?.filename}`); + } else { + baseFilename = trimmedOverride; + } + } else { + baseFilename = + blockType === "rules" && isGlobal + ? "global-rule" + : `new-${BLOCK_TYPE_CONFIG[blockType]?.filename}`; + } + let counter = 0; let fileUri: string; @@ -141,6 +159,7 @@ export async function findAvailableFilename( export async function createNewWorkspaceBlockFile( ide: IDE, blockType: BlockType, + baseFilename?: string, ): Promise { const workspaceDirs = await ide.getWorkspaceDirs(); if (workspaceDirs.length === 0) { @@ -155,6 +174,9 @@ export async function createNewWorkspaceBlockFile( baseDirUri, blockType, ide.fileExists.bind(ide), + undefined, + false, + baseFilename, ); const fileContent = getFileContent(blockType); @@ -163,7 +185,10 @@ export async function createNewWorkspaceBlockFile( await ide.openFile(fileUri); } -export async function createNewGlobalRuleFile(ide: IDE): Promise { +export async function createNewGlobalRuleFile( + ide: IDE, + baseFilename?: string, +): Promise { try { const globalDir = getContinueGlobalPath(); @@ -176,6 +201,7 @@ export async function createNewGlobalRuleFile(ide: IDE): Promise { ide.fileExists.bind(ide), undefined, true, // isGlobal = true for global rules + baseFilename, ); const fileContent = getFileContent("rules"); diff --git a/core/core.ts b/core/core.ts index c73996a49..2985c0486 100644 --- a/core/core.ts +++ b/core/core.ts @@ -409,7 +409,11 @@ export class Core { }); on("config/addLocalWorkspaceBlock", async (msg) => { - await createNewWorkspaceBlockFile(this.ide, msg.data.blockType); + await createNewWorkspaceBlockFile( + this.ide, + msg.data.blockType, + msg.data.baseFilename, + ); await this.configHandler.reloadConfig( "Local block created (config/addLocalWorkspaceBlock message)", ); @@ -417,7 +421,7 @@ export class Core { on("config/addGlobalRule", async (msg) => { try { - await createNewGlobalRuleFile(this.ide); + await createNewGlobalRuleFile(this.ide, msg.data?.baseFilename); await this.configHandler.reloadConfig( "Global rule created (config/addGlobalRule message)", ); diff --git a/core/protocol/core.ts b/core/protocol/core.ts index b03b0e11a..bfa858709 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -90,8 +90,11 @@ export type ToCoreFromIdeOrWebviewProtocol = { }, void, ]; - "config/addLocalWorkspaceBlock": [{ blockType: BlockType }, void]; - "config/addGlobalRule": [undefined, void]; + "config/addLocalWorkspaceBlock": [ + { blockType: BlockType; baseFilename?: string }, + void, + ]; + "config/addGlobalRule": [undefined | { baseFilename?: string }, void]; "config/newPromptFile": [undefined, void]; "config/newAssistantFile": [undefined, void]; "config/ideSettingsUpdate": [IdeSettings, void]; diff --git a/gui/src/components/dialogs/AddRuleDialog.tsx b/gui/src/components/dialogs/AddRuleDialog.tsx new file mode 100644 index 000000000..8fe804f6d --- /dev/null +++ b/gui/src/components/dialogs/AddRuleDialog.tsx @@ -0,0 +1,100 @@ +import { useContext, useLayoutEffect, useRef, useState } from "react"; +import { useDispatch } from "react-redux"; +import { Input, SecondaryButton } from ".."; +import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; + +function AddRuleDialog({ mode }: { mode: "workspace" | "global" }) { + const dispatch = useDispatch(); + const ideMessenger = useContext(IdeMessengerContext); + const [name, setName] = useState(""); + const [error, setError] = useState(); + const [isSubmitting, setIsSubmitting] = useState(false); + const inputRef = useRef(null); + + useLayoutEffect(() => { + // focus on input after a short delay + const timer = setTimeout(() => { + if (inputRef.current) { + inputRef.current.focus(); + } + }, 100); + return () => clearTimeout(timer); + }, []); + + const closeDialog = () => { + dispatch(setShowDialog(false)); + dispatch(setDialogMessage(undefined)); + }; + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + const trimmed = name.trim(); + if (!trimmed) { + setError("File name is required"); + return; + } + setError(undefined); + setIsSubmitting(true); + try { + if (mode === "global") { + ideMessenger.post("config/addGlobalRule", { + baseFilename: trimmed, + }); + } else { + ideMessenger.post("config/addLocalWorkspaceBlock", { + blockType: "rules", + baseFilename: trimmed, + }); + } + closeDialog(); + } catch (err) { + setIsSubmitting(false); + setError("Failed to create rule file"); + } + }; + + const title = mode === "global" ? "Add global rule file" : "Add rule file"; + + return ( +
+
+

{title}

+

+ Choose a name for the new rule file. +

+
+ + {error &&

{error}

} +
+ + Create + + + Cancel + +
+
+
+
+ ); +} + +export default AddRuleDialog; diff --git a/gui/src/pages/config/sections/RulesSection.tsx b/gui/src/pages/config/sections/RulesSection.tsx index 4e9741bb5..08bdb6da7 100644 --- a/gui/src/pages/config/sections/RulesSection.tsx +++ b/gui/src/pages/config/sections/RulesSection.tsx @@ -20,6 +20,7 @@ import { 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 HeaderButtonWithToolTip from "../../../components/gui/HeaderButtonWithToolTip"; import Switch from "../../../components/gui/Switch"; import { @@ -393,19 +394,21 @@ function RulesSubSection() { const config = useAppSelector((store) => store.config.config); const mode = useAppSelector((store) => store.session.mode); const ideMessenger = useContext(IdeMessengerContext); + const dispatch = useAppDispatch(); const isLocal = selectedProfile?.profileType === "local"; const [globalRulesMode, setGlobalRulesMode] = useState("workspace"); const handleAddRule = (mode?: string) => { const currentMode = mode || globalRulesMode; if (isLocal) { - if (currentMode === "global") { - void ideMessenger.request("config/addGlobalRule", undefined); - } else { - void ideMessenger.request("config/addLocalWorkspaceBlock", { - blockType: "rules", - }); - } + dispatch(setShowDialog(true)); + dispatch( + setDialogMessage( + , + ), + ); } else { void ideMessenger.request("controlPlane/openUrl", { path: "?type=rules", From 169779ffed69fd9b1f23409a6279cc260ef6dafc Mon Sep 17 00:00:00 2001 From: Aditya Mitra <61635505+uinstinct@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:51:48 +0530 Subject: [PATCH 2/5] Update gui/src/components/dialogs/AddRuleDialog.tsx Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- gui/src/components/dialogs/AddRuleDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/components/dialogs/AddRuleDialog.tsx b/gui/src/components/dialogs/AddRuleDialog.tsx index 8fe804f6d..aae78d06b 100644 --- a/gui/src/components/dialogs/AddRuleDialog.tsx +++ b/gui/src/components/dialogs/AddRuleDialog.tsx @@ -78,7 +78,7 @@ function AddRuleDialog({ mode }: { mode: "workspace" | "global" }) {
Create From b6a8be5563dc8ac6264898d5ab88e7fd0f935c61 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:55:03 +0530 Subject: [PATCH 3/5] add a default name called "new-rule" in the input --- gui/src/components/dialogs/AddRuleDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/components/dialogs/AddRuleDialog.tsx b/gui/src/components/dialogs/AddRuleDialog.tsx index aae78d06b..49a6e6723 100644 --- a/gui/src/components/dialogs/AddRuleDialog.tsx +++ b/gui/src/components/dialogs/AddRuleDialog.tsx @@ -7,7 +7,7 @@ import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; function AddRuleDialog({ mode }: { mode: "workspace" | "global" }) { const dispatch = useDispatch(); const ideMessenger = useContext(IdeMessengerContext); - const [name, setName] = useState(""); + const [name, setName] = useState("new-rule"); const [error, setError] = useState(); const [isSubmitting, setIsSubmitting] = useState(false); const inputRef = useRef(null); From f7815c3e0b99cf1d0c5966f59911663103fddd26 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 25 Nov 2025 09:19:26 +0530 Subject: [PATCH 4/5] correct wordings --- gui/src/components/dialogs/AddRuleDialog.tsx | 6 +++--- gui/src/pages/config/sections/RulesSection.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gui/src/components/dialogs/AddRuleDialog.tsx b/gui/src/components/dialogs/AddRuleDialog.tsx index 49a6e6723..08a0e4ecf 100644 --- a/gui/src/components/dialogs/AddRuleDialog.tsx +++ b/gui/src/components/dialogs/AddRuleDialog.tsx @@ -31,7 +31,7 @@ function AddRuleDialog({ mode }: { mode: "workspace" | "global" }) { e.preventDefault(); const trimmed = name.trim(); if (!trimmed) { - setError("File name is required"); + setError("Rule name is required"); return; } setError(undefined); @@ -54,7 +54,7 @@ function AddRuleDialog({ mode }: { mode: "workspace" | "global" }) { } }; - const title = mode === "global" ? "Add global rule file" : "Add rule file"; + const title = mode === "global" ? "Add global rule" : "Add workspace rule"; return (
@@ -65,7 +65,7 @@ function AddRuleDialog({ mode }: { mode: "workspace" | "global" }) {