feat: search and replace tool def
This commit is contained in:
parent
7d2fc068ea
commit
bf43ec64e2
12 changed files with 106 additions and 14 deletions
|
|
@ -229,6 +229,8 @@ export default async function doLoadConfig(options: {
|
|||
newConfig.tools.push(
|
||||
...getConfigDependentToolDefinitions({
|
||||
rules: newConfig.rules,
|
||||
enableExperimentalTools:
|
||||
newConfig.experimental?.enableExperimentalTools ?? false,
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export const sharedConfigSchema = z
|
|||
readResponseTTS: z.boolean(),
|
||||
promptPath: z.string(),
|
||||
useCurrentFileAsContext: z.boolean(),
|
||||
enableExperimentalTools: z.boolean(),
|
||||
|
||||
// `ui` in `ContinueConfig`
|
||||
showSessionTabs: z.boolean(),
|
||||
|
|
@ -157,6 +158,12 @@ export function modifyAnyConfigWithSharedConfig<
|
|||
configCopy.experimental = {
|
||||
...configCopy.experimental,
|
||||
};
|
||||
|
||||
if (sharedConfig.enableExperimentalTools !== undefined) {
|
||||
configCopy.experimental.enableExperimentalTools =
|
||||
sharedConfig.enableExperimentalTools;
|
||||
}
|
||||
|
||||
if (sharedConfig.promptPath !== undefined) {
|
||||
configCopy.experimental.promptPath = sharedConfig.promptPath;
|
||||
}
|
||||
|
|
|
|||
2
core/index.d.ts
vendored
2
core/index.d.ts
vendored
|
|
@ -1007,6 +1007,7 @@ interface ToolChoice {
|
|||
|
||||
export interface ConfigDependentToolParams {
|
||||
rules: RuleWithSource[];
|
||||
enableExperimentalTools: boolean;
|
||||
}
|
||||
|
||||
export type GetTool = (params: ConfigDependentToolParams) => Tool;
|
||||
|
|
@ -1334,6 +1335,7 @@ export interface ExperimentalConfig {
|
|||
modelRoles?: ExperimentalModelRoles;
|
||||
defaultContext?: DefaultContextProvider[];
|
||||
promptPath?: string;
|
||||
enableExperimentalTools?: boolean;
|
||||
|
||||
/**
|
||||
* Quick actions are a way to add custom commands to the Code Lens of
|
||||
|
|
|
|||
|
|
@ -19,10 +19,12 @@ export const DEFAULT_CHAT_SYSTEM_MESSAGE_URL =
|
|||
export const DEFAULT_AGENT_SYSTEM_MESSAGE_URL =
|
||||
"https://github.com/continuedev/continue/blob/main/core/llm/constructMessages.ts";
|
||||
|
||||
const EDIT_MESSAGE = `\
|
||||
export const CODEBLOCK_FORMATTING_INSTRUCTIONS = `\
|
||||
Always include the language and file name in the info string when you write code blocks.
|
||||
If you are editing "src/main.py" for example, your code block should start with '\`\`\`python src/main.py'
|
||||
`;
|
||||
|
||||
export const EDIT_CODE_INSTRUCTIONS = `\
|
||||
When addressing code modification requests, present a concise code snippet that
|
||||
emphasizes only the necessary changes and uses abbreviated placeholders for
|
||||
unmodified sections. For example:
|
||||
|
|
@ -69,14 +71,15 @@ export const DEFAULT_CHAT_SYSTEM_MESSAGE = `\
|
|||
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.
|
||||
If needed consisely explain to the user they can switch to agent mode using the Mode Selector dropdown and provide no other details.
|
||||
|
||||
${EDIT_MESSAGE}
|
||||
${CODEBLOCK_FORMATTING_INSTRUCTIONS}
|
||||
${EDIT_CODE_INSTRUCTIONS}
|
||||
</important_rules>`;
|
||||
|
||||
export const DEFAULT_AGENT_SYSTEM_MESSAGE = `\
|
||||
<important_rules>
|
||||
You are in agent mode.
|
||||
|
||||
${EDIT_MESSAGE}
|
||||
${CODEBLOCK_FORMATTING_INSTRUCTIONS}
|
||||
</important_rules>`;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
export enum BuiltInToolNames {
|
||||
ReadFile = "builtin_read_file",
|
||||
EditExistingFile = "builtin_edit_existing_file",
|
||||
SearchAndReplaceInFile = "builtin_search_and_replace_in_file",
|
||||
ReadCurrentlyOpenFile = "builtin_read_currently_open_file",
|
||||
CreateNewFile = "builtin_create_new_file",
|
||||
RunTerminalCommand = "builtin_run_terminal_command",
|
||||
|
|
@ -20,4 +21,7 @@ export enum BuiltInToolNames {
|
|||
|
||||
export const BUILT_IN_GROUP_NAME = "Built-In";
|
||||
|
||||
export const CLIENT_TOOLS_IMPLS = [BuiltInToolNames.EditExistingFile];
|
||||
export const CLIENT_TOOLS_IMPLS = [
|
||||
BuiltInToolNames.EditExistingFile,
|
||||
BuiltInToolNames.SearchAndReplaceInFile,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { Tool } from "../..";
|
||||
import { EDIT_CODE_INSTRUCTIONS } from "../../llm/constructMessages";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export interface EditToolArgs {
|
||||
|
|
@ -17,8 +18,7 @@ export const editFileTool: Tool = {
|
|||
isInstant: false,
|
||||
function: {
|
||||
name: BuiltInToolNames.EditExistingFile,
|
||||
description:
|
||||
"Use this tool to edit an existing file. If you don't know the contents of the file, read it first.",
|
||||
description: `Use this tool to edit an existing file. If you don't know the contents of the file, read it first.\n${EDIT_CODE_INSTRUCTIONS}`,
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["filepath", "changes"],
|
||||
|
|
|
|||
55
core/tools/definitions/searchAndReplaceInFile.ts
Normal file
55
core/tools/definitions/searchAndReplaceInFile.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { Tool } from "../..";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export interface SearchAndReplaceInFileArgs {
|
||||
filepath: string;
|
||||
diff: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Critical requirements:
|
||||
1. SEARCH content must match the file section EXACTLY (character-for-character, including whitespace and indentation)
|
||||
2. Each SEARCH/REPLACE block replaces only the first matching occurrence
|
||||
3. For multiple changes, use multiple SEARCH/REPLACE blocks in file order
|
||||
4. Keep blocks concise - include only the lines that need to change plus minimal context for uniqueness
|
||||
5. To delete code, use an empty REPLACE section
|
||||
6. To move code, use two blocks (one to delete, one to insert at new location)
|
||||
*/
|
||||
|
||||
export const searchAndReplaceInFileTool: Tool = {
|
||||
type: "function",
|
||||
displayTitle: "Edit File",
|
||||
wouldLikeTo: "edit {{{ filepath }}}",
|
||||
isCurrently: "editing {{{ filepath }}}",
|
||||
hasAlready: "edited {{{ filepath }}}",
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
readonly: false,
|
||||
isInstant: false,
|
||||
function: {
|
||||
name: BuiltInToolNames.SearchAndReplaceInFile,
|
||||
description:
|
||||
"Use this tool to make precise modifications to existing files using SEARCH/REPLACE blocks. This tool is ideal for targeted changes to specific sections of a file.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["filepath", "diff"],
|
||||
properties: {
|
||||
filepath: {
|
||||
type: "string",
|
||||
description:
|
||||
"The path of the file to modify, relative to the root of the workspace.",
|
||||
},
|
||||
diff: {
|
||||
type: "string",
|
||||
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
||||
\`\`\`
|
||||
------- SEARCH
|
||||
[exact content to find]
|
||||
=======
|
||||
[new content to replace with]
|
||||
+++++++ REPLACE
|
||||
\`\`\``,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
@ -10,12 +10,12 @@ import { readCurrentlyOpenFileTool } from "./definitions/readCurrentlyOpenFile";
|
|||
import { readFileTool } from "./definitions/readFile";
|
||||
import { requestRuleTool } from "./definitions/requestRule";
|
||||
import { runTerminalCommandTool } from "./definitions/runTerminalCommand";
|
||||
import { searchAndReplaceInFileTool } from "./definitions/searchAndReplaceInFile";
|
||||
import { searchWebTool } from "./definitions/searchWeb";
|
||||
import { viewDiffTool } from "./definitions/viewDiff";
|
||||
|
||||
export const baseToolDefinitions = [
|
||||
readFileTool,
|
||||
editFileTool,
|
||||
createNewFileTool,
|
||||
runTerminalCommandTool,
|
||||
grepSearchTool,
|
||||
|
|
@ -33,4 +33,9 @@ export const baseToolDefinitions = [
|
|||
|
||||
export const getConfigDependentToolDefinitions = (
|
||||
params: ConfigDependentToolParams,
|
||||
): Tool[] => [requestRuleTool(params)];
|
||||
): Tool[] => [
|
||||
requestRuleTool(params),
|
||||
...(params.enableExperimentalTools
|
||||
? [searchAndReplaceInFileTool]
|
||||
: [editFileTool]),
|
||||
];
|
||||
|
|
|
|||
2
extensions/vscode/package-lock.json
generated
2
extensions/vscode/package-lock.json
generated
|
|
@ -108,7 +108,7 @@
|
|||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/fetch": "^1.0.13",
|
||||
"@continuedev/fetch": "^1.0.14",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "file:../packages/openai-adapters",
|
||||
"@modelcontextprotocol/sdk": "^1.12.0",
|
||||
|
|
|
|||
2
gui/package-lock.json
generated
2
gui/package-lock.json
generated
|
|
@ -114,7 +114,7 @@
|
|||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/fetch": "^1.0.13",
|
||||
"@continuedev/fetch": "^1.0.14",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "file:../packages/openai-adapters",
|
||||
"@modelcontextprotocol/sdk": "^1.12.0",
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ export function UserSettingsForm() {
|
|||
const disableSessionTitles = config.disableSessionTitles ?? false;
|
||||
const useCurrentFileAsContext =
|
||||
config.experimental?.useCurrentFileAsContext ?? false;
|
||||
|
||||
const enableExperimentalTools =
|
||||
config.experimental?.enableExperimentalTools ?? false;
|
||||
const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true;
|
||||
const disableIndexing = config.disableIndexing ?? false;
|
||||
|
||||
|
|
@ -106,9 +107,11 @@ export function UserSettingsForm() {
|
|||
|
||||
const [hubEnabled, setHubEnabled] = useState(false);
|
||||
useEffect(() => {
|
||||
ideMessenger.ide.getIdeSettings().then(({ continueTestEnvironment }) => {
|
||||
setHubEnabled(continueTestEnvironment === "production");
|
||||
});
|
||||
void ideMessenger.ide
|
||||
.getIdeSettings()
|
||||
.then(({ continueTestEnvironment }) => {
|
||||
setHubEnabled(continueTestEnvironment === "production");
|
||||
});
|
||||
}, [ideMessenger]);
|
||||
|
||||
return (
|
||||
|
|
@ -386,6 +389,16 @@ export function UserSettingsForm() {
|
|||
}
|
||||
text="Add Current File by Default"
|
||||
/>
|
||||
|
||||
<ToggleSwitch
|
||||
isToggled={enableExperimentalTools}
|
||||
onToggle={() =>
|
||||
handleUpdate({
|
||||
enableExperimentalTools: !enableExperimentalTools,
|
||||
})
|
||||
}
|
||||
text="Enable experimental tools"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ export const uiSlice = createSlice({
|
|||
[BuiltInToolNames.LSTool]: "allowedWithoutPermission",
|
||||
[BuiltInToolNames.CreateRuleBlock]: "allowedWithPermission",
|
||||
[BuiltInToolNames.RequestRule]: "disabled",
|
||||
[BuiltInToolNames.SearchAndReplaceInFile]: "allowedWithPermission",
|
||||
},
|
||||
toolGroupSettings: {
|
||||
[BUILT_IN_GROUP_NAME]: "include",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue