From a1e1ecf0939dc53cae56e58ec3ee9b67ca4dd55f Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 13:03:36 -0700 Subject: [PATCH 01/21] Update uiSlice.ts --- gui/src/redux/slices/uiSlice.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index dcdddafb1..4a0bcae32 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -1,5 +1,5 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { Tool } from "core"; +import { RuleWithSource, Tool } from "core"; import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "core/tools/builtIn"; import { defaultOnboardingCardState, @@ -12,9 +12,12 @@ export type ToolPolicy = | "allowedWithoutPermission" | "disabled"; +export type RulePolicy = "always" | "auto" | "never"; + export type ToolGroupPolicy = "include" | "exclude"; export type ToolPolicies = { [toolName: string]: ToolPolicy }; +export type RulePolicies = { [ruleName: string]: RulePolicy }; export type ToolGroupPolicies = { [toolGroupName: string]: ToolGroupPolicy }; type UIState = { @@ -27,10 +30,12 @@ type UIState = { shouldAddFileForEditing: boolean; toolSettings: ToolPolicies; toolGroupSettings: ToolGroupPolicies; + ruleSettings: RulePolicies; ttsActive: boolean; }; export const DEFAULT_TOOL_SETTING: ToolPolicy = "allowedWithPermission"; +export const DEFAULT_RULE_SETTING: RulePolicy = "auto"; export const uiSlice = createSlice({ name: "ui", @@ -62,6 +67,7 @@ export const uiSlice = createSlice({ toolGroupSettings: { [BUILT_IN_GROUP_NAME]: "include", }, + ruleSettings: {}, } as UIState, reducers: { setOnboardingCard: ( @@ -126,6 +132,28 @@ export const uiSlice = createSlice({ state.toolGroupSettings[action.payload] = "include"; } }, + // Rules + addRule: (state, action: PayloadAction) => { + state.ruleSettings[action.payload.name] = DEFAULT_RULE_SETTING; + }, + toggleRuleSetting: (state, action: PayloadAction) => { + const setting = state.ruleSettings[action.payload]; + + switch (setting) { + case "auto": + state.ruleSettings[action.payload] = "always"; + break; + case "always": + state.ruleSettings[action.payload] = "never"; + break; + case "never": + state.ruleSettings[action.payload] = "auto"; + break; + default: + state.ruleSettings[action.payload] = DEFAULT_RULE_SETTING; + break; + } + }, setTTSActive: (state, { payload }: PayloadAction) => { state.ttsActive = payload; }, @@ -142,6 +170,8 @@ export const { toggleToolSetting, toggleToolGroupSetting, addTool, + addRule, + toggleRuleSetting, setTTSActive, } = uiSlice.actions; From 8a2ffb3a859d4fbec3299500a0d860c0f725573d Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 13:08:10 -0700 Subject: [PATCH 02/21] feat: rules policies --- core/llm/rules/getSystemMessageWithRules.ts | 34 +++-- .../Lump/sections/rules/RulePolicyItem.tsx | 118 ++++++++++++++++++ .../sections/rules/RulesSectionTooltip.tsx | 21 ++++ 3 files changed, 162 insertions(+), 11 deletions(-) create mode 100644 gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx create mode 100644 gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx diff --git a/core/llm/rules/getSystemMessageWithRules.ts b/core/llm/rules/getSystemMessageWithRules.ts index e83a2cbfc..cbb89817c 100644 --- a/core/llm/rules/getSystemMessageWithRules.ts +++ b/core/llm/rules/getSystemMessageWithRules.ts @@ -120,7 +120,20 @@ const isGlobalRule = (rule: RuleWithSource): boolean => { export const shouldApplyRule = ( rule: RuleWithSource, filePaths: string[], + rulePolicies: RulePolicies = {}, ): boolean => { + const policy = rulePolicies[rule.name]; + + // Always apply if policy is "always" + if (policy === "always") { + return true; + } + + // Never apply if policy is "never" + if (policy === "never") { + return false; + } + // If it's a global rule, always apply it regardless of file paths if (isGlobalRule(rule)) { return true; @@ -196,6 +209,7 @@ export const getApplicableRules = ( userMessage: UserChatMessage | ToolResultChatMessage | undefined, rules: RuleWithSource[], contextItems: ContextItemWithId[], + rulePolicies: RulePolicies = {}, ): RuleWithSource[] => { // First, extract any global rules that should always apply const globalRules = rules.filter((rule) => isGlobalRule(rule)); @@ -221,33 +235,31 @@ export const getApplicableRules = ( // Get rules that match file paths const matchingRules = rules .filter((rule) => !isGlobalRule(rule)) // Skip global rules as we've already handled them - .filter((rule) => shouldApplyRule(rule, allFilePaths)); + .filter((rule) => shouldApplyRule(rule, allFilePaths, rulePolicies)); // Combine global rules with matching rules, ensuring no duplicates return [...globalRules, ...matchingRules]; }; -/** - * Creates a system message string with applicable rules appended - * - * @param baseSystemMessage - The base system message to start with - * @param userMessage - The user message to check for file paths - * @param rules - The list of rules to filter - * @param contextItems - Context items to check for file paths - * @returns System message with applicable rules appended - */ export const getSystemMessageWithRules = ({ baseSystemMessage, userMessage, rules, contextItems, + rulePolicies = {}, }: { baseSystemMessage?: string; userMessage: UserChatMessage | ToolResultChatMessage | undefined; rules: RuleWithSource[]; contextItems: ContextItemWithId[]; + rulePolicies?: RulePolicies; }) => { - const applicableRules = getApplicableRules(userMessage, rules, contextItems); + const applicableRules = getApplicableRules( + userMessage, + rules, + contextItems, + rulePolicies, + ); let systemMessage = baseSystemMessage ?? ""; for (const rule of applicableRules) { diff --git a/gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx b/gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx new file mode 100644 index 000000000..0639a9d2a --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx @@ -0,0 +1,118 @@ +// gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx +import { ChevronRightIcon } from "@heroicons/react/24/outline"; +import { RuleWithSource } from "core"; +import { useEffect, useState } from "react"; +import { useDispatch } from "react-redux"; +import { useAppSelector } from "../../../../../redux/hooks"; +import { + addRule, + toggleRuleSetting, +} from "../../../../../redux/slices/uiSlice"; +import { useFontSize } from "../../../../ui/font"; + +interface RulePolicyItemProps { + rule: RuleWithSource; +} + +export function RulePolicyItem(props: RulePolicyItemProps) { + const dispatch = useDispatch(); + const policy = useAppSelector( + (state) => state.ui.ruleSettings[props.rule.name], + ); + const [isExpanded, setIsExpanded] = useState(false); + + useEffect(() => { + if (!policy) { + dispatch(addRule(props.rule)); + } + }, [props.rule.name, policy]); + + const fontSize = useFontSize(-2); + + if (!policy) { + return null; + } + + return ( +
+
+
setIsExpanded((val) => !val)} + > +
+
{ + dispatch(toggleRuleSetting(props.rule.name)); + e.stopPropagation(); + e.preventDefault(); + }} + > + {policy === "never" ? ( + <> + Off + + Never + + + ) : policy === "auto" ? ( + <> + Auto + Auto + + ) : ( + // always + <> + On + + Always + + + )} +
+
+
+ Rule: + {props.rule.rule} + {props.rule.globs && ( + <> + Applies to: + + {typeof props.rule.globs === "string" + ? props.rule.globs + : props.rule.globs.join(", ")} + + + )} + {props.rule.ruleFile && ( + <> + Source: + {props.rule.ruleFile} + + )} +
+
+
+ ); +} diff --git a/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx b/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx new file mode 100644 index 000000000..2505147af --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx @@ -0,0 +1,21 @@ +// gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx +export const RulesSectionTooltip = () => ( +
+

+ Rules allow you to control how coding + standards and preferences are applied. +

+
    +
  • + Always: Rule will always be applied, regardless of + context +
  • +
  • + Auto: Rule will be applied based on file matching +
  • +
  • + Never: Rule will never be applied +
  • +
+
+); From 9c8bbd99e904040685c916d1cb0881e2079f140f Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 13:19:51 -0700 Subject: [PATCH 03/21] Update RulesSection.tsx --- .../mainInput/Lump/sections/RulesSection.tsx | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 3617ae632..2972ef4e8 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -2,6 +2,7 @@ import { parseConfigYaml } from "@continuedev/config-yaml"; import { ArrowsPointingOutIcon, EyeIcon, + InformationCircleIcon, PencilIcon, } from "@heroicons/react/24/outline"; import { RuleWithSource } from "core"; @@ -11,7 +12,7 @@ import { DEFAULT_CHAT_SYSTEM_MESSAGE, DEFAULT_CHAT_SYSTEM_MESSAGE_URL, } from "core/llm/constructMessages"; -import { useContext, useMemo } from "react"; +import { useContext, useMemo, useState } from "react"; import { useAuth } from "../../../../context/Auth"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; @@ -22,6 +23,8 @@ import { import HeaderButtonWithToolTip from "../../../gui/HeaderButtonWithToolTip"; import { useFontSize } from "../../../ui/font"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; +import { RulePolicyItem } from "./rules/RulePolicyItem"; +import { RulesSectionTooltip } from "./rules/RulesSectionTooltip"; interface RuleCardProps { rule: RuleWithSource; @@ -146,6 +149,7 @@ const RuleCard: React.FC = ({ rule }) => { export function RulesSection() { const { selectedProfile } = useAuth(); + const [showPolicies, setShowPolicies] = useState(false); const config = useAppSelector((store) => store.config.config); const mode = useAppSelector((store) => store.session.mode); @@ -213,12 +217,48 @@ export function RulesSection() { return rules; }, [config, selectedProfile, mode]); + const namedRules = useMemo(() => { + return sortedRules.filter((rule) => rule.name); + }, [sortedRules]); + return (
- {sortedRules.map((rule, index) => ( - - ))} - +
+ + +
+ +
+ +
+
+
+
+ + {showPolicies ? ( +
+ {namedRules.map((rule, index) => ( + + ))} + {namedRules.length === 0 && ( +
+ No rules with names available to configure policies. +
+ )} +
+ ) : ( + <> + {sortedRules.map((rule, index) => ( + + ))} + + + )}
); } From f976e54dc3b2b8072aef3ecadf259ee1e5299956 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 13:27:36 -0700 Subject: [PATCH 04/21] fix: type errors --- core/llm/rules/getSystemMessageWithRules.ts | 1 + core/llm/rules/types.ts | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 core/llm/rules/types.ts diff --git a/core/llm/rules/getSystemMessageWithRules.ts b/core/llm/rules/getSystemMessageWithRules.ts index cbb89817c..3b22212d8 100644 --- a/core/llm/rules/getSystemMessageWithRules.ts +++ b/core/llm/rules/getSystemMessageWithRules.ts @@ -8,6 +8,7 @@ import { import { renderChatMessage } from "../../util/messageContent"; import { getCleanUriPath } from "../../util/uri"; import { extractPathsFromCodeBlocks } from "../utils/extractPathsFromCodeBlocks"; +import { RulePolicies } from "./types"; /** * Checks if a path matches any of the provided globs diff --git a/core/llm/rules/types.ts b/core/llm/rules/types.ts new file mode 100644 index 000000000..91154f9c3 --- /dev/null +++ b/core/llm/rules/types.ts @@ -0,0 +1,2 @@ +export type RulePolicy = "always" | "auto" | "never"; +export type RulePolicies = { [ruleName: string]: RulePolicy }; From 765141f0e494d5980e3bcbec563cfbf0c613301e Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 13:28:26 -0700 Subject: [PATCH 05/21] Update getSystemMessageWithRules.ts --- core/llm/rules/getSystemMessageWithRules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/llm/rules/getSystemMessageWithRules.ts b/core/llm/rules/getSystemMessageWithRules.ts index 3b22212d8..25c8b11c6 100644 --- a/core/llm/rules/getSystemMessageWithRules.ts +++ b/core/llm/rules/getSystemMessageWithRules.ts @@ -123,7 +123,7 @@ export const shouldApplyRule = ( filePaths: string[], rulePolicies: RulePolicies = {}, ): boolean => { - const policy = rulePolicies[rule.name]; + const policy = rulePolicies[rule.name || ""]; // Always apply if policy is "always" if (policy === "always") { From e6cd458b5af5d64df9bed541a61cf3052c9207f1 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 13:59:18 -0700 Subject: [PATCH 06/21] Update RulesSection.tsx --- .../mainInput/Lump/sections/RulesSection.tsx | 101 ++++++++++-------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 2972ef4e8..9e29392a2 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -12,18 +12,19 @@ import { DEFAULT_CHAT_SYSTEM_MESSAGE, DEFAULT_CHAT_SYSTEM_MESSAGE_URL, } from "core/llm/constructMessages"; -import { useContext, useMemo, useState } from "react"; +import { useContext, useEffect, useMemo } from "react"; import { useAuth } from "../../../../context/Auth"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; import { + addRule, setDialogMessage, setShowDialog, + toggleRuleSetting, } from "../../../../redux/slices/uiSlice"; import HeaderButtonWithToolTip from "../../../gui/HeaderButtonWithToolTip"; import { useFontSize } from "../../../ui/font"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; -import { RulePolicyItem } from "./rules/RulePolicyItem"; import { RulesSectionTooltip } from "./rules/RulesSectionTooltip"; interface RuleCardProps { @@ -34,6 +35,14 @@ const RuleCard: React.FC = ({ rule }) => { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const mode = useAppSelector((store) => store.session.mode); + const policy = useAppSelector((state) => state.ui.ruleSettings[rule.name]); + + // Ensure the rule is added to settings + useEffect(() => { + if (rule.name && !policy) { + dispatch(addRule(rule)); + } + }, [rule.name, policy, dispatch, rule]); const handleOpen = async () => { if (rule.slug) { @@ -56,6 +65,14 @@ const RuleCard: React.FC = ({ rule }) => { } }; + const handleTogglePolicy = (e) => { + if (rule.name) { + dispatch(toggleRuleSetting(rule.name)); + e.stopPropagation(); + e.preventDefault(); + } + }; + const title = useMemo(() => { if (rule.name) { return rule.name; @@ -104,20 +121,36 @@ const RuleCard: React.FC = ({ rule }) => { > {title} -
- - - {" "} - {rule.source === "default-chat" || - rule.source === "default-agent" ? ( - - - - ) : ( - - - +
+ {rule.name && policy && ( +
+ {policy === "never" ? ( + Never + ) : policy === "auto" ? ( + Auto + ) : ( + Always + )} +
)} +
+ + + {" "} + {rule.source === "default-chat" || + rule.source === "default-agent" ? ( + + + + ) : ( + + + + )} +
@@ -149,8 +182,6 @@ const RuleCard: React.FC = ({ rule }) => { export function RulesSection() { const { selectedProfile } = useAuth(); - const [showPolicies, setShowPolicies] = useState(false); - const config = useAppSelector((store) => store.config.config); const mode = useAppSelector((store) => store.session.mode); const sortedRules: RuleWithSource[] = useMemo(() => { @@ -217,19 +248,12 @@ export function RulesSection() { return rules; }, [config, selectedProfile, mode]); - const namedRules = useMemo(() => { - return sortedRules.filter((rule) => rule.name); - }, [sortedRules]); - return (
- +
+ Available Rules +
@@ -240,25 +264,10 @@ export function RulesSection() {
- {showPolicies ? ( -
- {namedRules.map((rule, index) => ( - - ))} - {namedRules.length === 0 && ( -
- No rules with names available to configure policies. -
- )} -
- ) : ( - <> - {sortedRules.map((rule, index) => ( - - ))} - - - )} + {sortedRules.map((rule, index) => ( + + ))} +
); } From cdedddd660c6a74da6c21951e36310411cae534d Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 14:03:07 -0700 Subject: [PATCH 07/21] improv: ui --- .../Lump/sections/rules/RulePolicyItem.tsx | 118 ------------------ .../sections/rules/RulesSectionTooltip.tsx | 1 - 2 files changed, 119 deletions(-) delete mode 100644 gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx diff --git a/gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx b/gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx deleted file mode 100644 index 0639a9d2a..000000000 --- a/gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx +++ /dev/null @@ -1,118 +0,0 @@ -// gui/src/components/mainInput/Lump/sections/rules/RulePolicyItem.tsx -import { ChevronRightIcon } from "@heroicons/react/24/outline"; -import { RuleWithSource } from "core"; -import { useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; -import { useAppSelector } from "../../../../../redux/hooks"; -import { - addRule, - toggleRuleSetting, -} from "../../../../../redux/slices/uiSlice"; -import { useFontSize } from "../../../../ui/font"; - -interface RulePolicyItemProps { - rule: RuleWithSource; -} - -export function RulePolicyItem(props: RulePolicyItemProps) { - const dispatch = useDispatch(); - const policy = useAppSelector( - (state) => state.ui.ruleSettings[props.rule.name], - ); - const [isExpanded, setIsExpanded] = useState(false); - - useEffect(() => { - if (!policy) { - dispatch(addRule(props.rule)); - } - }, [props.rule.name, policy]); - - const fontSize = useFontSize(-2); - - if (!policy) { - return null; - } - - return ( -
-
-
setIsExpanded((val) => !val)} - > -
-
{ - dispatch(toggleRuleSetting(props.rule.name)); - e.stopPropagation(); - e.preventDefault(); - }} - > - {policy === "never" ? ( - <> - Off - - Never - - - ) : policy === "auto" ? ( - <> - Auto - Auto - - ) : ( - // always - <> - On - - Always - - - )} -
-
-
- Rule: - {props.rule.rule} - {props.rule.globs && ( - <> - Applies to: - - {typeof props.rule.globs === "string" - ? props.rule.globs - : props.rule.globs.join(", ")} - - - )} - {props.rule.ruleFile && ( - <> - Source: - {props.rule.ruleFile} - - )} -
-
-
- ); -} diff --git a/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx b/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx index 2505147af..f5da60c54 100644 --- a/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx +++ b/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx @@ -1,4 +1,3 @@ -// gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx export const RulesSectionTooltip = () => (

From 8786f587f53f56b2de1558a07089bd507050ed91 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 14:05:31 -0700 Subject: [PATCH 08/21] Update RulesSection.tsx --- .../mainInput/Lump/sections/RulesSection.tsx | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 9e29392a2..8430cb78f 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -2,7 +2,6 @@ import { parseConfigYaml } from "@continuedev/config-yaml"; import { ArrowsPointingOutIcon, EyeIcon, - InformationCircleIcon, PencilIcon, } from "@heroicons/react/24/outline"; import { RuleWithSource } from "core"; @@ -25,7 +24,6 @@ import { import HeaderButtonWithToolTip from "../../../gui/HeaderButtonWithToolTip"; import { useFontSize } from "../../../ui/font"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; -import { RulesSectionTooltip } from "./rules/RulesSectionTooltip"; interface RuleCardProps { rule: RuleWithSource; @@ -250,20 +248,6 @@ export function RulesSection() { return (

-
-
- Available Rules -
- -
- -
- -
-
-
-
- {sortedRules.map((rule, index) => ( ))} From 11a10f852424cf16dcda5a1eb1f40dd2a6de65e8 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 14:07:30 -0700 Subject: [PATCH 09/21] improv: clean up code --- .../mainInput/Lump/sections/RulesSection.tsx | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 8430cb78f..5c479accc 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -11,12 +11,11 @@ import { DEFAULT_CHAT_SYSTEM_MESSAGE, DEFAULT_CHAT_SYSTEM_MESSAGE_URL, } from "core/llm/constructMessages"; -import { useContext, useEffect, useMemo } from "react"; +import { useContext, useMemo } from "react"; import { useAuth } from "../../../../context/Auth"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; import { - addRule, setDialogMessage, setShowDialog, toggleRuleSetting, @@ -35,13 +34,6 @@ const RuleCard: React.FC = ({ rule }) => { const mode = useAppSelector((store) => store.session.mode); const policy = useAppSelector((state) => state.ui.ruleSettings[rule.name]); - // Ensure the rule is added to settings - useEffect(() => { - if (rule.name && !policy) { - dispatch(addRule(rule)); - } - }, [rule.name, policy, dispatch, rule]); - const handleOpen = async () => { if (rule.slug) { void ideMessenger.request("controlPlane/openUrl", { From 270d2a8a796a40109a86b2038391a517c769ce91 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 14:08:36 -0700 Subject: [PATCH 10/21] Update RulesSection.tsx --- gui/src/components/mainInput/Lump/sections/RulesSection.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 5c479accc..b4efd9e1f 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -32,7 +32,9 @@ const RuleCard: React.FC = ({ rule }) => { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const mode = useAppSelector((store) => store.session.mode); - const policy = useAppSelector((state) => state.ui.ruleSettings[rule.name]); + const policy = useAppSelector( + (state) => state.ui.ruleSettings[rule.name || ""], + ); const handleOpen = async () => { if (rule.slug) { From bcae5b3cf210f1a8ced3b2c913961ed16aaf2ea9 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 14:16:09 -0700 Subject: [PATCH 11/21] fix: rules --- .../components/mainInput/Lump/sections/RulesSection.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index b4efd9e1f..f64850595 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -16,6 +16,7 @@ import { useAuth } from "../../../../context/Auth"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; import { + DEFAULT_RULE_SETTING, setDialogMessage, setShowDialog, toggleRuleSetting, @@ -32,8 +33,10 @@ const RuleCard: React.FC = ({ rule }) => { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const mode = useAppSelector((store) => store.session.mode); - const policy = useAppSelector( - (state) => state.ui.ruleSettings[rule.name || ""], + const policy = useAppSelector((state) => + rule.name + ? state.ui.ruleSettings[rule.name] || DEFAULT_RULE_SETTING + : undefined, ); const handleOpen = async () => { From 56f38038b35cedc2aa1bca1b09780b21c811bd83 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 14:21:08 -0700 Subject: [PATCH 12/21] fix: settings persistance --- gui/src/redux/slices/uiSlice.ts | 2 +- gui/src/redux/store.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 4a0bcae32..ae4e205f4 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -134,7 +134,7 @@ export const uiSlice = createSlice({ }, // Rules addRule: (state, action: PayloadAction) => { - state.ruleSettings[action.payload.name] = DEFAULT_RULE_SETTING; + state.ruleSettings[action.payload.name!] = DEFAULT_RULE_SETTING; }, toggleRuleSetting: (state, action: PayloadAction) => { const setting = state.ruleSettings[action.payload]; diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 1e0d098f3..806387691 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -58,7 +58,7 @@ const saveSubsetFilters = [ "codeToEdit", ]), createFilter("config", ["defaultModelTitle"]), - createFilter("ui", ["toolSettings", "toolGroupSettings"]), + createFilter("ui", ["toolSettings", "toolGroupSettings", "ruleSettings"]), createFilter("indexing", []), createFilter("tabs", ["tabs"]), createFilter("profiles", [ From 7b9c5cc4f062e2882706919b1effe34a460f45b8 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 14:22:01 -0700 Subject: [PATCH 13/21] fix: types --- gui/src/components/mainInput/Lump/sections/RulesSection.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index f64850595..f23e8688c 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -11,7 +11,7 @@ import { DEFAULT_CHAT_SYSTEM_MESSAGE, DEFAULT_CHAT_SYSTEM_MESSAGE_URL, } from "core/llm/constructMessages"; -import { useContext, useMemo } from "react"; +import { MouseEventHandler, useContext, useMemo } from "react"; import { useAuth } from "../../../../context/Auth"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; @@ -60,7 +60,7 @@ const RuleCard: React.FC = ({ rule }) => { } }; - const handleTogglePolicy = (e) => { + const handleTogglePolicy: MouseEventHandler = (e) => { if (rule.name) { dispatch(toggleRuleSetting(rule.name)); e.stopPropagation(); From 3b44bc9564b359a24db5f84e10a5a68b8f087943 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 14:31:36 -0700 Subject: [PATCH 14/21] Update getSystemMessageWithRules.vitest.ts --- .../rules/getSystemMessageWithRules.vitest.ts | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/core/llm/rules/getSystemMessageWithRules.vitest.ts b/core/llm/rules/getSystemMessageWithRules.vitest.ts index 0e7bd39fe..2ea49494c 100644 --- a/core/llm/rules/getSystemMessageWithRules.vitest.ts +++ b/core/llm/rules/getSystemMessageWithRules.vitest.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from "vitest"; import { RuleWithSource } from "../.."; import { shouldApplyRule } from "./getSystemMessageWithRules"; +import { RulePolicies } from "./types"; describe("Rule colocation glob matching", () => { // This test file demonstrates the expected behavior after our fix @@ -132,3 +133,135 @@ describe("Rule colocation glob matching", () => { ); }); }); + +describe("Rule policies", () => { + const componentRule: RuleWithSource = { + name: "Components Rule", + rule: "Use functional components with hooks", + source: "rules-block", + ruleFile: "src/components/rules.md", + }; + + const testFiles = ["src/components/Button.tsx"]; + const nonMatchingFiles = ["src/utils/helpers.ts"]; + + it("should always apply rules with 'always' policy regardless of file paths", () => { + const rulePolicies: RulePolicies = { + "Components Rule": "always", + }; + + // Should apply even to non-matching files + expect(shouldApplyRule(componentRule, nonMatchingFiles, rulePolicies)).toBe( + true, + ); + + // Should apply to empty file list + expect(shouldApplyRule(componentRule, [], rulePolicies)).toBe(true); + }); + + it("should never apply rules with 'never' policy regardless of file paths", () => { + const rulePolicies: RulePolicies = { + "Components Rule": "never", + }; + + // Should not apply even to matching files + expect(shouldApplyRule(componentRule, testFiles, rulePolicies)).toBe(false); + + // Rule with alwaysApply: true should still be overridden by 'never' policy + const alwaysApplyRule: RuleWithSource = { + name: "Always Apply Rule", + rule: "This rule would normally always apply", + alwaysApply: true, + source: "rules-block", + ruleFile: "src/components/rules.md", + }; + + const alwaysNeverPolicies: RulePolicies = { + "Always Apply Rule": "never", + }; + + expect( + shouldApplyRule(alwaysApplyRule, testFiles, alwaysNeverPolicies), + ).toBe(false); + }); + + it("should apply 'auto' policy rules based on normal matching logic", () => { + const rulePolicies: RulePolicies = { + "Components Rule": "auto", + }; + + // Should apply to matching files + expect(shouldApplyRule(componentRule, testFiles, rulePolicies)).toBe(true); + + // Should not apply to non-matching files + expect(shouldApplyRule(componentRule, nonMatchingFiles, rulePolicies)).toBe( + false, + ); + }); + + it("should use default behavior when no policy is specified", () => { + // Empty policies object should use default behavior + const rulePolicies: RulePolicies = {}; + + // Should apply to matching files + expect(shouldApplyRule(componentRule, testFiles, rulePolicies)).toBe(true); + + // Should not apply to non-matching files + expect(shouldApplyRule(componentRule, nonMatchingFiles, rulePolicies)).toBe( + false, + ); + }); + + it("should handle policy interaction with global rules", () => { + // Root level rule which would normally apply globally + const rootRule: RuleWithSource = { + name: "Root Rule", + rule: "Follow project standards", + source: "rules-block", + ruleFile: ".continue/rules.md", + }; + + // Never policy should override even global rules + const neverPolicies: RulePolicies = { + "Root Rule": "never", + }; + + expect(shouldApplyRule(rootRule, testFiles, neverPolicies)).toBe(false); + + // Auto policy should maintain global rule behavior + const autoPolicies: RulePolicies = { + "Root Rule": "auto", + }; + + expect(shouldApplyRule(rootRule, testFiles, autoPolicies)).toBe(true); + }); + + it("should prioritize policies over alwaysApply and directory restrictions", () => { + // Create rule with multiple matching criteria + const complexRule: RuleWithSource = { + name: "Complex Rule", + rule: "This rule has complex matching logic", + alwaysApply: true, + globs: "**/*.ts", + source: "rules-block", + ruleFile: "src/utils/rules.md", + }; + + // Always policy should win over everything + const alwaysPolicies: RulePolicies = { + "Complex Rule": "always", + }; + + expect(shouldApplyRule(complexRule, [], alwaysPolicies)).toBe(true); + + // Never policy should also win over everything + const neverPolicies: RulePolicies = { + "Complex Rule": "never", + }; + + // Even with matching files and alwaysApply: true, never policy wins + expect( + shouldApplyRule(complexRule, ["src/utils/test.ts"], neverPolicies), + ).toBe(false); + }); +}); From 91170460fd53947aad5fce84fb860d588738219c Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 15:02:48 -0700 Subject: [PATCH 15/21] Update streamResponse.ts --- gui/src/redux/thunks/streamResponse.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts index 8f11fc7f5..caeded723 100644 --- a/gui/src/redux/thunks/streamResponse.ts +++ b/gui/src/redux/thunks/streamResponse.ts @@ -92,6 +92,7 @@ export const streamResponseThunk = createAsyncThunk< // Determine which rules apply to this message const userMsg = updatedHistory[inputIndex].message; const rules = getState().config.config.rules; + const rulePolicies = getState().ui.ruleSettings; // Calculate applicable rules once // We need to check the message type to match what getApplicableRules expects @@ -101,6 +102,7 @@ export const streamResponseThunk = createAsyncThunk< : undefined, rules, selectedContextItems, + rulePolicies, ); // Store in history for UI display @@ -122,6 +124,7 @@ export const streamResponseThunk = createAsyncThunk< [...updatedHistory], baseChatOrAgentSystemMessage, applicableRules, + rulePolicies, ); posthog.capture("step run", { From 4842cf54740f47b69c265a05f90b302ce563b6d7 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 15:04:47 -0700 Subject: [PATCH 16/21] Update constructMessages.ts --- core/llm/constructMessages.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/llm/constructMessages.ts b/core/llm/constructMessages.ts index 5358deee5..49115cb6f 100644 --- a/core/llm/constructMessages.ts +++ b/core/llm/constructMessages.ts @@ -11,6 +11,7 @@ import { findLast } from "../util/findLast"; import { normalizeToMessageParts } from "../util/messageContent"; import { isUserOrToolMsg } from "./messages"; import { getSystemMessageWithRules } from "./rules/getSystemMessageWithRules"; +import { RulePolicies } from "./rules/types"; export const DEFAULT_CHAT_SYSTEM_MESSAGE_URL = "https://github.com/continuedev/continue/blob/main/core/llm/constructMessages.ts"; @@ -108,6 +109,7 @@ export function constructMessages( history: ChatHistoryItem[], baseChatOrAgentSystemMessage: string | undefined, rules: RuleWithSource[], + rulePolicies?: RulePolicies, ): ChatMessage[] { const filteredHistory = history.filter( (item) => item.message.role !== "system", @@ -164,6 +166,7 @@ export function constructMessages( rules, userMessage: lastUserMsg, contextItems: lastUserContextItems, + rulePolicies, }); if (systemMessage.trim()) { From e1a0da69fcc7ce413b7ce420468c88ab5e5ca78e Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 16:15:29 -0700 Subject: [PATCH 17/21] Update getSystemMessageWithRules.ts --- core/llm/rules/getSystemMessageWithRules.ts | 29 +++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/core/llm/rules/getSystemMessageWithRules.ts b/core/llm/rules/getSystemMessageWithRules.ts index 25c8b11c6..1323b7e23 100644 --- a/core/llm/rules/getSystemMessageWithRules.ts +++ b/core/llm/rules/getSystemMessageWithRules.ts @@ -123,7 +123,10 @@ export const shouldApplyRule = ( filePaths: string[], rulePolicies: RulePolicies = {}, ): boolean => { + console.log("POLICIES", rulePolicies); + console.log("RULE ZZZ", rule); const policy = rulePolicies[rule.name || ""]; + console.log("POLICY", policy); // Always apply if policy is "always" if (policy === "always") { @@ -140,7 +143,7 @@ export const shouldApplyRule = ( return true; } - // If there are no file paths to check: + // If there are no file paths to check and we've made it here: // - We've already handled global rules above // - Don't apply other rules since we have no files to match against if (filePaths.length === 0) { @@ -212,10 +215,8 @@ export const getApplicableRules = ( contextItems: ContextItemWithId[], rulePolicies: RulePolicies = {}, ): RuleWithSource[] => { - // First, extract any global rules that should always apply - const globalRules = rules.filter((rule) => isGlobalRule(rule)); - - // Get file paths from message and context for regular rule matching + console.log("GET APPLICABLE"); + // Get file paths from message and context for rule matching const filePathsFromMessage = userMessage ? extractPathsFromCodeBlocks(renderChatMessage(userMessage)) : []; @@ -228,18 +229,13 @@ export const getApplicableRules = ( // Combine file paths from both sources const allFilePaths = [...filePathsFromMessage, ...filePathsFromContextItems]; - // If we have no file paths, just return the global rules - if (allFilePaths.length === 0) { - return globalRules; - } + // Apply shouldApplyRule to all rules - this will handle global rules, rule policies, + // and path matching in a consistent way + const applicableRules = rules.filter((rule) => + shouldApplyRule(rule, allFilePaths, rulePolicies), + ); - // Get rules that match file paths - const matchingRules = rules - .filter((rule) => !isGlobalRule(rule)) // Skip global rules as we've already handled them - .filter((rule) => shouldApplyRule(rule, allFilePaths, rulePolicies)); - - // Combine global rules with matching rules, ensuring no duplicates - return [...globalRules, ...matchingRules]; + return applicableRules; }; export const getSystemMessageWithRules = ({ @@ -255,6 +251,7 @@ export const getSystemMessageWithRules = ({ contextItems: ContextItemWithId[]; rulePolicies?: RulePolicies; }) => { + console.log("HERE ZZZZ"); const applicableRules = getApplicableRules( userMessage, rules, From de6a0ae36c43753e768bf0164dfbe1b938da790d Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 16:22:08 -0700 Subject: [PATCH 18/21] fix: policy precedence --- core/llm/rules/alwaysApplyRules.vitest.ts | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/core/llm/rules/alwaysApplyRules.vitest.ts b/core/llm/rules/alwaysApplyRules.vitest.ts index 0508a1e38..44f82793a 100644 --- a/core/llm/rules/alwaysApplyRules.vitest.ts +++ b/core/llm/rules/alwaysApplyRules.vitest.ts @@ -6,6 +6,7 @@ import { UserChatMessage, } from "../.."; import { getApplicableRules } from "./getSystemMessageWithRules"; +import { RulePolicies } from "./types"; describe("Rule application with alwaysApply", () => { // Create an always-apply rule @@ -136,4 +137,38 @@ describe("Rule application with alwaysApply", () => { expect(applicableRules).toHaveLength(1); expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule"); }); + + it("should respect rulePolicies over alwaysApply when there are no file paths", () => { + // Rule with alwaysApply: true + const globalRule: RuleWithSource = { + name: "Global Rule", + rule: "This rule has alwaysApply: true but is blocked by rulePolicies", + alwaysApply: true, + source: "rules-block", + ruleFile: "src/some/path.md", + }; + + // Message with no code blocks or file references + const simpleMessage: UserChatMessage = { + role: "user", + content: "Can you help me with something?", + }; + + // Create a rule policy that blocks the rule + const rulePolicies: RulePolicies = { + "Global Rule": "never", + }; + + // The rule should NOT be applied due to the "never" policy, + // even though it has alwaysApply: true and there are no file paths + const applicableRules = getApplicableRules( + simpleMessage, + [globalRule], + [], + rulePolicies, + ); + + expect(applicableRules).toHaveLength(0); + expect(applicableRules.map((r) => r.name)).not.toContain("Global Rule"); + }); }); From f5a8edfc916814c2932da0092948af1a9154701f Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Tue, 17 Jun 2025 16:25:47 -0700 Subject: [PATCH 19/21] improv: clean up --- core/llm/rules/getSystemMessageWithRules.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/llm/rules/getSystemMessageWithRules.ts b/core/llm/rules/getSystemMessageWithRules.ts index 1323b7e23..9eaa3e12c 100644 --- a/core/llm/rules/getSystemMessageWithRules.ts +++ b/core/llm/rules/getSystemMessageWithRules.ts @@ -123,10 +123,7 @@ export const shouldApplyRule = ( filePaths: string[], rulePolicies: RulePolicies = {}, ): boolean => { - console.log("POLICIES", rulePolicies); - console.log("RULE ZZZ", rule); const policy = rulePolicies[rule.name || ""]; - console.log("POLICY", policy); // Always apply if policy is "always" if (policy === "always") { @@ -215,7 +212,6 @@ export const getApplicableRules = ( contextItems: ContextItemWithId[], rulePolicies: RulePolicies = {}, ): RuleWithSource[] => { - console.log("GET APPLICABLE"); // Get file paths from message and context for rule matching const filePathsFromMessage = userMessage ? extractPathsFromCodeBlocks(renderChatMessage(userMessage)) @@ -251,7 +247,6 @@ export const getSystemMessageWithRules = ({ contextItems: ContextItemWithId[]; rulePolicies?: RulePolicies; }) => { - console.log("HERE ZZZZ"); const applicableRules = getApplicableRules( userMessage, rules, From c3081d9d25649919013178aa0ce4b5821e0ff97a Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 18 Jun 2025 14:54:53 -0700 Subject: [PATCH 20/21] improv: use on / off for rules --- core/llm/rules/alwaysApplyRules.vitest.ts | 6 +- core/llm/rules/getSystemMessageWithRules.ts | 9 +-- .../rules/getSystemMessageWithRules.vitest.ts | 69 +++++++------------ core/llm/rules/types.ts | 2 +- .../mainInput/Lump/sections/RulesSection.tsx | 39 ++++++----- gui/src/redux/slices/uiSlice.ts | 15 ++-- 6 files changed, 56 insertions(+), 84 deletions(-) diff --git a/core/llm/rules/alwaysApplyRules.vitest.ts b/core/llm/rules/alwaysApplyRules.vitest.ts index 44f82793a..538ab03cf 100644 --- a/core/llm/rules/alwaysApplyRules.vitest.ts +++ b/core/llm/rules/alwaysApplyRules.vitest.ts @@ -138,7 +138,7 @@ describe("Rule application with alwaysApply", () => { expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule"); }); - it("should respect rulePolicies over alwaysApply when there are no file paths", () => { + it("should respect 'off' rulePolicies over alwaysApply when there are no file paths", () => { // Rule with alwaysApply: true const globalRule: RuleWithSource = { name: "Global Rule", @@ -156,10 +156,10 @@ describe("Rule application with alwaysApply", () => { // Create a rule policy that blocks the rule const rulePolicies: RulePolicies = { - "Global Rule": "never", + "Global Rule": "off", }; - // The rule should NOT be applied due to the "never" policy, + // The rule should NOT be applied due to the "off" policy, // even though it has alwaysApply: true and there are no file paths const applicableRules = getApplicableRules( simpleMessage, diff --git a/core/llm/rules/getSystemMessageWithRules.ts b/core/llm/rules/getSystemMessageWithRules.ts index 9eaa3e12c..a0f3cf64f 100644 --- a/core/llm/rules/getSystemMessageWithRules.ts +++ b/core/llm/rules/getSystemMessageWithRules.ts @@ -125,13 +125,8 @@ export const shouldApplyRule = ( ): boolean => { const policy = rulePolicies[rule.name || ""]; - // Always apply if policy is "always" - if (policy === "always") { - return true; - } - - // Never apply if policy is "never" - if (policy === "never") { + // Never apply if policy is "off" + if (policy === "off") { return false; } diff --git a/core/llm/rules/getSystemMessageWithRules.vitest.ts b/core/llm/rules/getSystemMessageWithRules.vitest.ts index 2ea49494c..f652d3a77 100644 --- a/core/llm/rules/getSystemMessageWithRules.vitest.ts +++ b/core/llm/rules/getSystemMessageWithRules.vitest.ts @@ -145,29 +145,15 @@ describe("Rule policies", () => { const testFiles = ["src/components/Button.tsx"]; const nonMatchingFiles = ["src/utils/helpers.ts"]; - it("should always apply rules with 'always' policy regardless of file paths", () => { + it("should never apply rules with 'off' policy regardless of file paths", () => { const rulePolicies: RulePolicies = { - "Components Rule": "always", - }; - - // Should apply even to non-matching files - expect(shouldApplyRule(componentRule, nonMatchingFiles, rulePolicies)).toBe( - true, - ); - - // Should apply to empty file list - expect(shouldApplyRule(componentRule, [], rulePolicies)).toBe(true); - }); - - it("should never apply rules with 'never' policy regardless of file paths", () => { - const rulePolicies: RulePolicies = { - "Components Rule": "never", + "Components Rule": "off", }; // Should not apply even to matching files expect(shouldApplyRule(componentRule, testFiles, rulePolicies)).toBe(false); - // Rule with alwaysApply: true should still be overridden by 'never' policy + // Rule with alwaysApply: true should still be overridden by 'off' policy const alwaysApplyRule: RuleWithSource = { name: "Always Apply Rule", rule: "This rule would normally always apply", @@ -176,18 +162,18 @@ describe("Rule policies", () => { ruleFile: "src/components/rules.md", }; - const alwaysNeverPolicies: RulePolicies = { - "Always Apply Rule": "never", + const offPolicies: RulePolicies = { + "Always Apply Rule": "off", }; - expect( - shouldApplyRule(alwaysApplyRule, testFiles, alwaysNeverPolicies), - ).toBe(false); + expect(shouldApplyRule(alwaysApplyRule, testFiles, offPolicies)).toBe( + false, + ); }); - it("should apply 'auto' policy rules based on normal matching logic", () => { + it("should apply 'on' policy rules based on normal matching logic", () => { const rulePolicies: RulePolicies = { - "Components Rule": "auto", + "Components Rule": "on", }; // Should apply to matching files @@ -221,22 +207,22 @@ describe("Rule policies", () => { ruleFile: ".continue/rules.md", }; - // Never policy should override even global rules - const neverPolicies: RulePolicies = { - "Root Rule": "never", + // Off policy should override even global rules + const offPolicies: RulePolicies = { + "Root Rule": "off", }; - expect(shouldApplyRule(rootRule, testFiles, neverPolicies)).toBe(false); + expect(shouldApplyRule(rootRule, testFiles, offPolicies)).toBe(false); - // Auto policy should maintain global rule behavior - const autoPolicies: RulePolicies = { - "Root Rule": "auto", + // On policy should maintain global rule behavior + const onPolicies: RulePolicies = { + "Root Rule": "on", }; - expect(shouldApplyRule(rootRule, testFiles, autoPolicies)).toBe(true); + expect(shouldApplyRule(rootRule, testFiles, onPolicies)).toBe(true); }); - it("should prioritize policies over alwaysApply and directory restrictions", () => { + it("should prioritize 'off' policy over alwaysApply and directory restrictions", () => { // Create rule with multiple matching criteria const complexRule: RuleWithSource = { name: "Complex Rule", @@ -247,21 +233,14 @@ describe("Rule policies", () => { ruleFile: "src/utils/rules.md", }; - // Always policy should win over everything - const alwaysPolicies: RulePolicies = { - "Complex Rule": "always", + // Off policy should win over everything + const offPolicies: RulePolicies = { + "Complex Rule": "off", }; - expect(shouldApplyRule(complexRule, [], alwaysPolicies)).toBe(true); - - // Never policy should also win over everything - const neverPolicies: RulePolicies = { - "Complex Rule": "never", - }; - - // Even with matching files and alwaysApply: true, never policy wins + // Even with matching files and alwaysApply: true, off policy wins expect( - shouldApplyRule(complexRule, ["src/utils/test.ts"], neverPolicies), + shouldApplyRule(complexRule, ["src/utils/test.ts"], offPolicies), ).toBe(false); }); }); diff --git a/core/llm/rules/types.ts b/core/llm/rules/types.ts index 91154f9c3..f973d8260 100644 --- a/core/llm/rules/types.ts +++ b/core/llm/rules/types.ts @@ -1,2 +1,2 @@ -export type RulePolicy = "always" | "auto" | "never"; +export type RulePolicy = "on" | "off"; export type RulePolicies = { [ruleName: string]: RulePolicy }; diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index f23e8688c..1097805d2 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -11,7 +11,7 @@ import { DEFAULT_CHAT_SYSTEM_MESSAGE, DEFAULT_CHAT_SYSTEM_MESSAGE_URL, } from "core/llm/constructMessages"; -import { MouseEventHandler, useContext, useMemo } from "react"; +import { useContext, useMemo } from "react"; import { useAuth } from "../../../../context/Auth"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; @@ -22,6 +22,7 @@ import { toggleRuleSetting, } from "../../../../redux/slices/uiSlice"; import HeaderButtonWithToolTip from "../../../gui/HeaderButtonWithToolTip"; +import Switch from "../../../gui/Switch"; import { useFontSize } from "../../../ui/font"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; @@ -39,6 +40,8 @@ const RuleCard: React.FC = ({ rule }) => { : undefined, ); + const isDisabled = policy === "off"; + const handleOpen = async () => { if (rule.slug) { void ideMessenger.request("controlPlane/openUrl", { @@ -60,11 +63,9 @@ const RuleCard: React.FC = ({ rule }) => { } }; - const handleTogglePolicy: MouseEventHandler = (e) => { + const handleTogglePolicy = () => { if (rule.name) { dispatch(toggleRuleSetting(rule.name)); - e.stopPropagation(); - e.preventDefault(); } }; @@ -105,11 +106,13 @@ const RuleCard: React.FC = ({ rule }) => { const smallFont = useFontSize(-2); const tinyFont = useFontSize(-3); return ( -
+
= ({ rule }) => {
{rule.name && policy && ( -
- {policy === "never" ? ( - Never - ) : policy === "auto" ? ( - Auto - ) : ( - Always - )} +
+ handleTogglePolicy()} + size={10} + text="" + />
)}
@@ -153,7 +152,7 @@ const RuleCard: React.FC = ({ rule }) => { style={{ fontSize: tinyFont, }} - className="mt-1 line-clamp-3 text-gray-400" + className={`mt-1 line-clamp-3 ${isDisabled ? "text-gray-500" : "text-gray-400"}`} > {rule.rule} @@ -165,7 +164,9 @@ const RuleCard: React.FC = ({ rule }) => { className="mt-1.5 flex flex-col gap-1" > Applies to files - + {rule.globs}
diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index ae4e205f4..15d6216a4 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -12,7 +12,7 @@ export type ToolPolicy = | "allowedWithoutPermission" | "disabled"; -export type RulePolicy = "always" | "auto" | "never"; +export type RulePolicy = "on" | "off"; export type ToolGroupPolicy = "include" | "exclude"; @@ -35,7 +35,7 @@ type UIState = { }; export const DEFAULT_TOOL_SETTING: ToolPolicy = "allowedWithPermission"; -export const DEFAULT_RULE_SETTING: RulePolicy = "auto"; +export const DEFAULT_RULE_SETTING: RulePolicy = "on"; export const uiSlice = createSlice({ name: "ui", @@ -140,14 +140,11 @@ export const uiSlice = createSlice({ const setting = state.ruleSettings[action.payload]; switch (setting) { - case "auto": - state.ruleSettings[action.payload] = "always"; + case "on": + state.ruleSettings[action.payload] = "off"; break; - case "always": - state.ruleSettings[action.payload] = "never"; - break; - case "never": - state.ruleSettings[action.payload] = "auto"; + case "off": + state.ruleSettings[action.payload] = "on"; break; default: state.ruleSettings[action.payload] = DEFAULT_RULE_SETTING; From d000fb07982ee4878eb2336b623b57ffe651265c Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 20 Jun 2025 12:05:05 -0700 Subject: [PATCH 21/21] Delete gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx --- .../sections/rules/RulesSectionTooltip.tsx | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx diff --git a/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx b/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx deleted file mode 100644 index f5da60c54..000000000 --- a/gui/src/components/mainInput/Lump/sections/rules/RulesSectionTooltip.tsx +++ /dev/null @@ -1,20 +0,0 @@ -export const RulesSectionTooltip = () => ( -
-

- Rules allow you to control how coding - standards and preferences are applied. -

-
    -
  • - Always: Rule will always be applied, regardless of - context -
  • -
  • - Auto: Rule will be applied based on file matching -
  • -
  • - Never: Rule will never be applied -
  • -
-
-);