From c858aee55973d6ece243713dd251c8fc3985a330 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 4 Nov 2025 12:39:17 -0800 Subject: [PATCH] feat: remove applied rules from chat history and dev data Co-authored-by: Andrius Grabauskas --- core/index.d.ts | 9 ++-- core/llm/rules/getSystemMessageWithRules.ts | 9 ++-- core/llm/rules/rules-utils.ts | 6 +-- .../components/mainInput/Lump/useEditBlock.ts | 19 +++++++- .../mainInput/belowMainInput/RulesPeek.tsx | 44 ++++--------------- .../pages/config/sections/RulesSection.tsx | 33 ++++++-------- gui/src/redux/thunks/streamNormalInput.ts | 1 - gui/src/redux/util/constructMessages.ts | 3 +- .../src/schemas/data/chatInteraction/index.ts | 1 - 9 files changed, 57 insertions(+), 68 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index 8416b5af0..de08c1ea1 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -513,7 +513,7 @@ export interface ChatHistoryItem { toolCallStates?: ToolCallState[]; isGatheringContext?: boolean; reasoning?: Reasoning; - appliedRules?: RuleWithSource[]; + appliedRules?: RuleMetadata[]; conversationSummary?: string; } @@ -1868,18 +1868,21 @@ export type RuleSource = | ".continuerules" | "agentFile"; -export interface RuleWithSource { +export interface RuleMetadata { name?: string; slug?: string; source: RuleSource; globs?: string | string[]; regex?: string | string[]; - rule: string; description?: string; sourceFile?: string; alwaysApply?: boolean; invokable?: boolean; } +export interface RuleWithSource extends RuleMetadata { + rule: string; +} + export interface CompleteOnboardingPayload { mode: OnboardingModes; provider?: string; diff --git a/core/llm/rules/getSystemMessageWithRules.ts b/core/llm/rules/getSystemMessageWithRules.ts index 078a2dcdf..cce647c14 100644 --- a/core/llm/rules/getSystemMessageWithRules.ts +++ b/core/llm/rules/getSystemMessageWithRules.ts @@ -1,6 +1,7 @@ import { minimatch } from "minimatch"; import { ContextItemWithId, + RuleMetadata, RuleWithSource, ToolResultChatMessage, UserChatMessage, @@ -324,7 +325,7 @@ export const getApplicableRules = ( return applicableRules; }; -export function getRuleId(rule: RuleWithSource): string { +export function getRuleId(rule: RuleMetadata): string { return rule.slug ?? rule.sourceFile ?? rule.name ?? rule.source; } @@ -342,7 +343,7 @@ export const getSystemMessageWithRules = ({ rulePolicies?: RulePolicies; }): { systemMessage: string; - appliedRules: RuleWithSource[]; + appliedRules: RuleMetadata[]; } => { const appliedRules = getApplicableRules( userMessage, @@ -359,8 +360,10 @@ export const getSystemMessageWithRules = ({ systemMessage += rule.rule; } + const ruleMetadata = appliedRules.map(({ rule, ...rest }) => rest); + return { systemMessage, - appliedRules, + appliedRules: ruleMetadata, }; }; diff --git a/core/llm/rules/rules-utils.ts b/core/llm/rules/rules-utils.ts index bafa3fa5d..279cf55eb 100644 --- a/core/llm/rules/rules-utils.ts +++ b/core/llm/rules/rules-utils.ts @@ -1,14 +1,14 @@ -import { RuleWithSource } from "../.."; +import { RuleMetadata } from "../.."; import { getLastNPathParts } from "../../util/uri"; -export function getRuleDisplayName(rule: RuleWithSource): string { +export function getRuleDisplayName(rule: RuleMetadata): string { if (rule.name) { return rule.name; } return getRuleSourceDisplayName(rule); } -export function getRuleSourceDisplayName(rule: RuleWithSource): string { +export function getRuleSourceDisplayName(rule: RuleMetadata): string { switch (rule.source) { case ".continuerules": return "Project rules"; diff --git a/gui/src/components/mainInput/Lump/useEditBlock.ts b/gui/src/components/mainInput/Lump/useEditBlock.ts index 9bbbd15a5..06065ff60 100644 --- a/gui/src/components/mainInput/Lump/useEditBlock.ts +++ b/gui/src/components/mainInput/Lump/useEditBlock.ts @@ -1,4 +1,5 @@ -import { ModelDescription } from "core"; +import { ModelDescription, RuleMetadata } from "core"; +import { DEFAULT_SYSTEM_MESSAGES_URL } from "core/llm/defaultSystemMessages"; import { useContext } from "react"; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; @@ -64,3 +65,19 @@ export function useEditDoc() { } }; } + +export function useOpenRule() { + const editBlock = useEditBlock(); + const ideMessenger = useContext(IdeMessengerContext); + return (rule: RuleMetadata) => { + if ( + rule.source === "default-chat" || + rule.source === "default-plan" || + rule.source === "default-agent" + ) { + ideMessenger.post("openUrl", DEFAULT_SYSTEM_MESSAGES_URL); + } else { + editBlock(rule?.slug, rule?.sourceFile); + } + }; +} diff --git a/gui/src/components/mainInput/belowMainInput/RulesPeek.tsx b/gui/src/components/mainInput/belowMainInput/RulesPeek.tsx index d6c789167..32b94cef2 100644 --- a/gui/src/components/mainInput/belowMainInput/RulesPeek.tsx +++ b/gui/src/components/mainInput/belowMainInput/RulesPeek.tsx @@ -1,43 +1,28 @@ import { DocumentTextIcon, GlobeAltIcon } from "@heroicons/react/24/outline"; -import { RuleWithSource } from "core"; +import { RuleMetadata } from "core"; import { getRuleSourceDisplayName } from "core/llm/rules/rules-utils"; -import { ComponentType, useMemo, useState } from "react"; +import { ComponentType, useMemo } from "react"; import ToggleDiv from "../../ToggleDiv"; +import { useOpenRule } from "../Lump/useEditBlock"; interface RulesPeekProps { - appliedRules?: RuleWithSource[]; + appliedRules?: RuleMetadata[]; icon?: ComponentType>; } interface RulesPeekItemProps { - rule: RuleWithSource; + rule: RuleMetadata; } export function RulesPeekItem({ rule }: RulesPeekItemProps) { const isGlobal = rule.alwaysApply ?? !rule.globs; - const [expanded, setExpanded] = useState(false); - - // Define maximum length for rule text display - const maxRuleLength = 100; - const isRuleLong = rule.rule.length > maxRuleLength; - - // Get the displayed rule text based on expanded state - const displayedRule = - isRuleLong && !expanded - ? `${rule.rule.slice(0, maxRuleLength)}...` - : rule.rule; - - const toggleExpand = () => { - if (isRuleLong) { - setExpanded(!expanded); - } - }; + const openRule = useOpenRule(); return (
openRule(rule)} >
{isGlobal ? ( @@ -58,19 +43,6 @@ export function RulesPeekItem({ rule }: RulesPeekItemProps) {
-
- {displayedRule} - {isRuleLong && ( - - {expanded ? "(collapse)" : "(expand)"} - - )} -
Source: {getRuleSourceDisplayName(rule)}
diff --git a/gui/src/pages/config/sections/RulesSection.tsx b/gui/src/pages/config/sections/RulesSection.tsx index efaeadc7f..4e9741bb5 100644 --- a/gui/src/pages/config/sections/RulesSection.tsx +++ b/gui/src/pages/config/sections/RulesSection.tsx @@ -16,16 +16,18 @@ import { DEFAULT_AGENT_SYSTEM_MESSAGE, DEFAULT_CHAT_SYSTEM_MESSAGE, DEFAULT_PLAN_SYSTEM_MESSAGE, - DEFAULT_SYSTEM_MESSAGES_URL, } from "core/llm/defaultSystemMessages"; import { getRuleDisplayName } from "core/llm/rules/rules-utils"; import { useContext, useMemo, useState } from "react"; import { DropdownButton } from "../../../components/DropdownButton"; import HeaderButtonWithToolTip from "../../../components/gui/HeaderButtonWithToolTip"; import Switch from "../../../components/gui/Switch"; -import { useEditBlock } from "../../../components/mainInput/Lump/useEditBlock"; +import { + useEditBlock, + useOpenRule, +} from "../../../components/mainInput/Lump/useEditBlock"; import { useMainEditor } from "../../../components/mainInput/TipTapEditor"; -import { Card, EmptyState, useFontSize } from "../../../components/ui"; +import { Card, EmptyState } from "../../../components/ui"; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useBookmarkedSlashCommands } from "../../../hooks/useBookmarkedSlashCommands"; @@ -138,20 +140,7 @@ const RuleCard: React.FC = ({ rule }) => { ); const isDisabled = policy === "off"; - - const editBlock = useEditBlock(); - const handleOpen = async () => { - if ( - rule.source === "default-chat" || - rule.source === "default-plan" || - rule.source === "default-agent" - ) { - ideMessenger.post("openUrl", DEFAULT_SYSTEM_MESSAGES_URL); - } else { - editBlock(rule?.slug, rule?.sourceFile); - } - }; - + const openRule = useOpenRule(); const handleTogglePolicy = () => { if (rule.name) { dispatch(toggleRuleSetting(rule.name)); @@ -207,11 +196,17 @@ const RuleCard: React.FC = ({ rule }) => { {" "} {rule.source === "default-chat" || rule.source === "default-agent" ? ( - + openRule(rule)} + text="View" + > ) : ( - + openRule(rule)} + text="Edit" + > )} diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 96cd2bb16..dcd179d8b 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -231,7 +231,6 @@ export const streamNormalInput = createAsyncThunk< ...(appliedRules.length > 0 && { rules: appliedRules.map((rule) => ({ id: getRuleId(rule), - rule: rule.rule, slug: rule.slug, })), }), diff --git a/gui/src/redux/util/constructMessages.ts b/gui/src/redux/util/constructMessages.ts index 71d461ed7..46472f9e2 100644 --- a/gui/src/redux/util/constructMessages.ts +++ b/gui/src/redux/util/constructMessages.ts @@ -2,6 +2,7 @@ import { ChatHistoryItem, ChatMessage, ContextItemWithId, + RuleMetadata, RuleWithSource, TextMessagePart, ToolResultChatMessage, @@ -41,7 +42,7 @@ export function constructMessages( useSystemToolsFramework?: SystemMessageToolsFramework, ): { messages: ChatMessage[]; - appliedRules: RuleWithSource[]; + appliedRules: RuleMetadata[]; appliedRuleIndex: number; } { // Find the most recent conversation summary and filter history accordingly diff --git a/packages/config-yaml/src/schemas/data/chatInteraction/index.ts b/packages/config-yaml/src/schemas/data/chatInteraction/index.ts index 8b4208a0a..5cccbafe6 100644 --- a/packages/config-yaml/src/schemas/data/chatInteraction/index.ts +++ b/packages/config-yaml/src/schemas/data/chatInteraction/index.ts @@ -13,7 +13,6 @@ export const chatInteractionEventAllSchema = baseDevDataAllSchema.extend({ .array( z.object({ id: z.string(), - rule: z.string(), slug: z.string().optional(), }), )