Elffuss BraidHub

kikocis/continue public

merge main
Changesetbe120e10af73cbd8d2ce227caa46eb5ec681159818585acf2c51b42b1fc66f9a
AuthorDallin Romney <dallinromney@gmail.com> · 2025-06-30 18:27 -07:00
CommitterDallin Romney <dallinromney@gmail.com> · 2025-06-30 18:27 -07:00
Parents870a8f66495d

Browse the files at this changeset

4 files changed

deleted core/llm/constructMessages.ts +0 −187
@@ -1,187 +0,0 @@
1-import {
2- ChatHistoryItem,
3- ChatMessage,
4- ContextItemWithId,
5- RuleWithSource,
6- TextMessagePart,
7- ToolResultChatMessage,
8- UserChatMessage,
9-} from "../";
10-import { findLast } from "../util/findLast";
11-import { normalizeToMessageParts } from "../util/messageContent";
12-import { isUserOrToolMsg } from "./messages";
13-import { getSystemMessageWithRules } from "./rules/getSystemMessageWithRules";
14-import { RulePolicies } from "./rules/types";
15-
16-export const DEFAULT_CHAT_SYSTEM_MESSAGE_URL =
17- "https://github.com/continuedev/continue/blob/main/core/llm/constructMessages.ts";
18-
19-export const DEFAULT_AGENT_SYSTEM_MESSAGE_URL =
20- "https://github.com/continuedev/continue/blob/main/core/llm/constructMessages.ts";
21-
22-export const CODEBLOCK_FORMATTING_INSTRUCTIONS = `\
23- Always include the language and file name in the info string when you write code blocks.
24- If you are editing "src/main.py" for example, your code block should start with '\`\`\`python src/main.py'
25-`;
26-
27-export const EDIT_CODE_INSTRUCTIONS = `\
28- When addressing code modification requests, present a concise code snippet that
29- emphasizes only the necessary changes and uses abbreviated placeholders for
30- unmodified sections. For example:
31-
32- \`\`\`language /path/to/file
33- // ... existing code ...
34-
35- {{ modified code here }}
36-
37- // ... existing code ...
38-
39- {{ another modification }}
40-
41- // ... rest of code ...
42- \`\`\`
43-
44- In existing files, you should always restate the function or class that the snippet belongs to:
45-
46- \`\`\`language /path/to/file
47- // ... existing code ...
48-
49- function exampleFunction() {
50- // ... existing code ...
51-
52- {{ modified code here }}
53-
54- // ... rest of function ...
55- }
56-
57- // ... rest of code ...
58- \`\`\`
59-
60- Since users have access to their complete file, they prefer reading only the
61- relevant modifications. It's perfectly acceptable to omit unmodified portions
62- at the beginning, middle, or end of files using these "lazy" comments. Only
63- provide the complete file when explicitly requested. Include a concise explanation
64- of changes unless the user specifically asks for code only.
65-`;
66-
67-export const DEFAULT_CHAT_SYSTEM_MESSAGE = `\
68-<important_rules>
69- You are in chat mode.
70-
71- If the user asks to make changes to files offer that they can use the Apply Button on the code block, or switch to Agent Mode to make the suggested updates automatically.
72- If needed consisely explain to the user they can switch to agent mode using the Mode Selector dropdown and provide no other details.
73-
74-${CODEBLOCK_FORMATTING_INSTRUCTIONS}
75-${EDIT_CODE_INSTRUCTIONS}
76-</important_rules>`;
77-
78-export const DEFAULT_AGENT_SYSTEM_MESSAGE = `\
79-<important_rules>
80- You are in agent mode.
81-
82-${CODEBLOCK_FORMATTING_INSTRUCTIONS}
83-</important_rules>`;
84-
85-/**
86- * Helper function to get the context items for a user message
87- */
88-function getUserContextItems(
89- userMsg: UserChatMessage | ToolResultChatMessage | undefined,
90- history: ChatHistoryItem[],
91-): ContextItemWithId[] {
92- if (!userMsg) return [];
93-
94- // Find the history item that contains the userMsg
95- const historyItem = history.find((item) => {
96- // Check if the message ID matches
97- if ("id" in userMsg && "id" in item.message) {
98- return (item.message as any).id === (userMsg as any).id;
99- }
100- // Fallback to content comparison
101- return (
102- item.message.content === userMsg.content &&
103- item.message.role === userMsg.role
104- );
105- });
106-
107- return historyItem?.contextItems || [];
108-}
109-
110-export function constructMessages(
111- messageMode: string,
112- history: ChatHistoryItem[],
113- baseChatOrAgentSystemMessage: string | undefined,
114- rules: RuleWithSource[],
115- rulePolicies?: RulePolicies,
116-): ChatMessage[] {
117- const filteredHistory = history.filter(
118- (item) => item.message.role !== "system",
119- );
120- const msgs: ChatMessage[] = [];
121-
122- for (let i = 0; i < filteredHistory.length; i++) {
123- const historyItem = filteredHistory[i];
124-
125- if (messageMode === "chat") {
126- const toolMessage: ToolResultChatMessage =
127- historyItem.message as ToolResultChatMessage;
128- if (historyItem.toolCallState?.toolCallId || toolMessage.toolCallId) {
129- // remove all tool calls from the history
130- continue;
131- }
132- }
133-
134- if (historyItem.message.role === "user") {
135- // Gather context items for user messages
136- let content = normalizeToMessageParts(historyItem.message);
137-
138- const ctxItems = historyItem.contextItems
139- .map((ctxItem) => {
140- return {
141- type: "text",
142- text: `${ctxItem.content}\n`,
143- } as TextMessagePart;
144- })
145- .filter((part) => !!part.text.trim());
146-
147- content = [...ctxItems, ...content];
148- msgs.push({
149- ...historyItem.message,
150- content,
151- });
152- } else {
153- msgs.push(historyItem.message);
154- }
155- }
156-
157- const lastUserMsg = findLast(msgs, isUserOrToolMsg) as
158- | UserChatMessage
159- | ToolResultChatMessage
160- | undefined;
161-
162- // Get context items for the last user message
163- const lastUserContextItems = getUserContextItems(
164- lastUserMsg,
165- filteredHistory,
166- );
167- const systemMessage = getSystemMessageWithRules({
168- baseSystemMessage: baseChatOrAgentSystemMessage,
169- rules,
170- userMessage: lastUserMsg,
171- contextItems: lastUserContextItems,
172- rulePolicies,
173- });
174-
175- if (systemMessage.trim()) {
176- msgs.unshift({
177- role: "system",
178- content: systemMessage,
179- });
180- }
181-
182- // Remove the "id" from all of the messages
183- return msgs.map((msg) => {
184- const { id, ...rest } = msg as any;
185- return rest;
186- });
187-}
modified core/llm/defaultSystemMessages.ts +6 −3
@@ -4,10 +4,12 @@
44 export const DEFAULT_AGENT_SYSTEM_MESSAGE_URL =
55 "https://github.com/continuedev/continue/blob/main/core/llm/defaultSystemMessages.ts";
66
7-const EDIT_MESSAGE = `\
7+export const CODEBLOCK_FORMATTING_INSTRUCTIONS = `\
88 Always include the language and file name in the info string when you write code blocks.
99 If you are editing "src/main.py" for example, your code block should start with '\`\`\`python src/main.py'
10+`;
1011
12+export const EDIT_CODE_INSTRUCTIONS = `\
1113 When addressing code modification requests, present a concise code snippet that
1214 emphasizes only the necessary changes and uses abbreviated placeholders for
1315 unmodified sections. For example:
@@ -54,12 +56,13 @@
5456 If the user asks to make changes to files offer that they can use the Apply Button on the code block, or switch to Agent Mode to make the suggested updates automatically.
5557 If needed consisely explain to the user they can switch to agent mode using the Mode Selector dropdown and provide no other details.
5658
57-${EDIT_MESSAGE}
59+${CODEBLOCK_FORMATTING_INSTRUCTIONS}
60+${EDIT_CODE_INSTRUCTIONS}
5861 </important_rules>`;
5962
6063 export const DEFAULT_AGENT_SYSTEM_MESSAGE = `\
6164 <important_rules>
6265 You are in agent mode.
6366
64-${EDIT_MESSAGE}
67+${CODEBLOCK_FORMATTING_INSTRUCTIONS}
6568 </important_rules>`;
modified gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx +1 −6
@@ -122,13 +122,8 @@
122122
123123 return (
124124 <div
125-<<<<<<< HEAD
126- onClick={openContextItem}
127- className="mr-2 flex cursor-pointer flex-row items-center gap-1.5 rounded px-1.5 py-1 text-xs hover:bg-white/10"
128-=======
129125 onClick={() => openContextItem(contextItem, ideMessenger)}
130- className="group mr-2 flex cursor-pointer items-center overflow-hidden text-ellipsis whitespace-nowrap rounded px-1.5 py-1 text-xs hover:bg-white/10"
131->>>>>>> d22ab74b15007ff7d84e3462bd344080305e1dc9
126+ className="mr-2 flex cursor-pointer flex-row items-center gap-1.5 whitespace-nowrap rounded px-1.5 py-1 text-xs hover:bg-white/10"
132127 data-testid="context-items-peek-item"
133128 >
134129 {getContextItemIcon()}
modified gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +6 −45
@@ -1,17 +1,11 @@
11 import { ChevronRightIcon } from "@heroicons/react/24/outline";
2-<<<<<<< HEAD
32 import { Tool, ToolCallState } from "core";
4-import { ComponentType, useMemo, useState } from "react";
5-import { ContextItemsPeekItem } from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
6-=======
7-import { ContextItemWithId, Tool, ToolCallState } from "core";
83 import { ComponentType, useContext, useMemo, useState } from "react";
94 import {
105 ContextItemsPeekItem,
116 openContextItem,
127 } from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
138 import { IdeMessengerContext } from "../../../context/IdeMessenger";
14->>>>>>> d22ab74b15007ff7d84e3462bd344080305e1dc9
159 import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
1610 import { toolCallStateToContextItems } from "./toolCallStateToContextItem";
1711 import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
@@ -30,18 +24,11 @@
3024 tool,
3125 historyIndex,
3226 }: SimpleToolCallUIProps) {
33-<<<<<<< HEAD
27+ const ideMessenger = useContext(IdeMessengerContext);
3428 const shownContextItems = useMemo(() => {
3529 const contextItems = toolCallStateToContextItems(toolCallState);
3630 return contextItems.filter((item) => !item.hidden);
3731 }, [toolCallState]);
38-=======
39- const ideMessenger = useContext(IdeMessengerContext);
40-
41- const ctxItems = useMemo(() => {
42- return contextItems?.filter((ctxItem) => !ctxItem.hidden) ?? [];
43- }, [contextItems]);
44->>>>>>> d22ab74b15007ff7d84e3462bd344080305e1dc9
4532
4633 const [open, setOpen] = useState(false);
4734 const [isHovered, setIsHovered] = useState(false);
@@ -51,8 +38,8 @@
5138 return Object.entries(toolCallState.parsedArgs);
5239 }, [toolCallState.parsedArgs]);
5340
54- const isToggleable = ctxItems.length > 1;
55- const isSingleItem = ctxItems.length === 1;
41+ const isToggleable = shownContextItems.length > 1;
42+ const isSingleItem = shownContextItems.length === 1;
5643 const shouldShowContent = isToggleable ? open : false;
5744 const isClickable = isToggleable || isSingleItem;
5845
@@ -60,7 +47,7 @@
6047 if (isToggleable) {
6148 setOpen((prev) => !prev);
6249 } else if (isSingleItem) {
63- openContextItem(ctxItems[0], ideMessenger);
50+ openContextItem(shownContextItems[0], ideMessenger);
6451 }
6552 }
6653
@@ -102,7 +89,6 @@
10289 </div>
10390 <ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
10491 </div>
105-<<<<<<< HEAD
10692 <div className="flex flex-row items-center gap-1.5">
10793 {!!toolCallState.output?.length && (
10894 <ToolTruncateHistoryIcon historyIndex={historyIndex} />
@@ -116,31 +102,6 @@
116102 ) : null}
117103 </div>
118104 </div>
119- <ArgsItems args={args} isShowing={showingArgs} />
120- <div
121- className={`mt-2 overflow-y-auto transition-all duration-300 ease-in-out ${
122- open ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
123- }`}
124- >
125- {shownContextItems.length ? (
126- shownContextItems.map((contextItem, idx) => (
127- <ContextItemsPeekItem key={idx} contextItem={contextItem} />
128- ))
129- ) : (
130- <div className="text-description pl-5 text-xs italic">
131- No tool call output
132- </div>
133-=======
134- {args.length > 0 && (
135- <ArgsToggleIcon
136- isShowing={showingArgs}
137- setIsShowing={setShowingArgs}
138- toolCallId={toolCallState.toolCallId}
139- />
140->>>>>>> d22ab74b15007ff7d84e3462bd344080305e1dc9
141- )}
142- </div>
143-
144105 <ArgsItems args={args} isShowing={showingArgs} />
145106
146107 {isToggleable && (
@@ -149,8 +110,8 @@
149110 shouldShowContent ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
150111 }`}
151112 >
152- {ctxItems.length > 0 ? (
153- ctxItems.map((contextItem, idx) => (
113+ {shownContextItems.length > 0 ? (
114+ shownContextItems.map((contextItem, idx) => (
154115 <ContextItemsPeekItem key={idx} contextItem={contextItem} />
155116 ))
156117 ) : (