feat: remove applied rules from chat history and dev data

Co-authored-by: Andrius Grabauskas <agrabauskas@palantir.com>
This commit is contained in:
Dallin Romney 2025-11-04 12:39:17 -08:00
parent b1cd3e949c
commit c858aee559
9 changed files with 57 additions and 68 deletions

9
core/index.d.ts vendored
View file

@ -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;

View file

@ -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,
};
};

View file

@ -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";

View file

@ -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);
}
};
}

View file

@ -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<React.SVGProps<SVGSVGElement>>;
}
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 (
<div
className={`group mr-2 flex flex-col overflow-hidden rounded px-1.5 py-1 text-xs hover:bg-white/10 ${isRuleLong ? "cursor-pointer hover:text-gray-200" : ""}`}
className={`group mr-2 flex flex-col overflow-hidden rounded px-1.5 py-1 text-xs hover:bg-white/10`}
data-testid="rules-peek-item"
onClick={toggleExpand}
onClick={() => openRule(rule)}
>
<div className="flex w-full items-center">
{isGlobal ? (
@ -58,19 +43,6 @@ export function RulesPeekItem({ rule }: RulesPeekItemProps) {
</div>
</div>
</div>
<div
className={`mt-1 whitespace-pre-line pl-6 pr-2 text-xs italic text-gray-300`}
title={
isRuleLong ? (expanded ? "Click to collapse" : "Click to expand") : ""
}
>
{displayedRule}
{isRuleLong && (
<span className="text-description-muted ml-1 opacity-0 transition-opacity group-hover:opacity-100">
{expanded ? "(collapse)" : "(expand)"}
</span>
)}
</div>
<div className="mt-1 pl-6 pr-2 text-xs text-gray-500">
Source: {getRuleSourceDisplayName(rule)}
</div>

View file

@ -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<RuleCardProps> = ({ 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<RuleCardProps> = ({ rule }) => {
</HeaderButtonWithToolTip>{" "}
{rule.source === "default-chat" ||
rule.source === "default-agent" ? (
<HeaderButtonWithToolTip onClick={handleOpen} text="View">
<HeaderButtonWithToolTip
onClick={() => openRule(rule)}
text="View"
>
<EyeIcon className="h-3 w-3 text-gray-400" />
</HeaderButtonWithToolTip>
) : (
<HeaderButtonWithToolTip onClick={handleOpen} text="Edit">
<HeaderButtonWithToolTip
onClick={() => openRule(rule)}
text="Edit"
>
<PencilIcon className="h-3 w-3 text-gray-400" />
</HeaderButtonWithToolTip>
)}

View file

@ -231,7 +231,6 @@ export const streamNormalInput = createAsyncThunk<
...(appliedRules.length > 0 && {
rules: appliedRules.map((rule) => ({
id: getRuleId(rule),
rule: rule.rule,
slug: rule.slug,
})),
}),

View file

@ -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

View file

@ -13,7 +13,6 @@ export const chatInteractionEventAllSchema = baseDevDataAllSchema.extend({
.array(
z.object({
id: z.string(),
rule: z.string(),
slug: z.string().optional(),
}),
)