From 2c8032c3397f6ac8c26b8ce5e5b2fe89d079d3da Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 17 Apr 2025 21:42:52 -0700 Subject: [PATCH 1/5] feat: `create_rule_block` tool --- core/tools/builtIn.ts | 1 + core/tools/callTool.ts | 3 + core/tools/definitions/createRuleBlock.ts | 37 +++++++++++ core/tools/implementations/createRuleBlock.ts | 62 +++++++++++++++++++ core/tools/index.ts | 4 +- docs/docs/customize/deep-dives/rules.md | 10 ++- .../gui/ToolCallDiv/ToolCallButtonsDiv.tsx | 2 +- 7 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 core/tools/definitions/createRuleBlock.ts create mode 100644 core/tools/implementations/createRuleBlock.ts diff --git a/core/tools/builtIn.ts b/core/tools/builtIn.ts index 7cff1c70e..5e269c232 100644 --- a/core/tools/builtIn.ts +++ b/core/tools/builtIn.ts @@ -9,6 +9,7 @@ export enum BuiltInToolNames { SearchWeb = "builtin_search_web", ViewDiff = "builtin_view_diff", LSTool = "builtin_ls", + CreateRuleBlock = "builtin_create_rule_block", // excluded from allTools for now ViewRepoMap = "builtin_view_repo_map", diff --git a/core/tools/callTool.ts b/core/tools/callTool.ts index 28a8f8c30..436b71874 100644 --- a/core/tools/callTool.ts +++ b/core/tools/callTool.ts @@ -4,6 +4,7 @@ import { canParseUrl } from "../util/url"; import { BuiltInToolNames } from "./builtIn"; import { createNewFileImpl } from "./implementations/createNewFile"; +import { createRuleBlockImpl } from "./implementations/createRuleBlock"; import { fileGlobSearchImpl } from "./implementations/globSearch"; import { grepSearchImpl } from "./implementations/grepSearch"; import { lsToolImpl } from "./implementations/lsTool"; @@ -156,6 +157,8 @@ export async function callTool( return await lsToolImpl(args, extras); case BuiltInToolNames.ReadCurrentlyOpenFile: return await readCurrentlyOpenFileImpl(args, extras); + case BuiltInToolNames.CreateRuleBlock: + return await createRuleBlockImpl(args, extras); // case BuiltInToolNames.ViewRepoMap: // return await viewRepoMapImpl(args, extras); // case BuiltInToolNames.ViewSubdirectory: diff --git a/core/tools/definitions/createRuleBlock.ts b/core/tools/definitions/createRuleBlock.ts new file mode 100644 index 000000000..987ef0f80 --- /dev/null +++ b/core/tools/definitions/createRuleBlock.ts @@ -0,0 +1,37 @@ +import { Tool } from "../.."; +import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; + +export const createRuleBlock: Tool = { + type: "function", + displayTitle: "Create Rule Block", + wouldLikeTo: 'create a rule block for "{{{ rule_name }}}"', + isCurrently: 'creating a rule block for "{{{ rule_name }}}"', + hasAlready: 'created a rule block for "{{{ rule_name }}}"', + readonly: false, + group: BUILT_IN_GROUP_NAME, + function: { + name: BuiltInToolNames.CreateRuleBlock, + description: + "Creates a persistent rule block that will be applied to all future Chat, Edit and Agent conversations. " + + "Use this tool when the user wants to establish ongoing behaviors, preferences, or standards for code generation. " + + "This is ideal for capturing recurring preferences like 'always use named exports instead of default exports' or 'follow Google style docstrings'. " + + "Do NOT use this tool for one-time instructions that should only apply to the current conversation. " + + "The created rule will be formatted as a YAML file and stored in the user's `.continue/rules` directory.", + parameters: { + type: "object", + required: ["rule_name", "rule_content"], + properties: { + rule_name: { + type: "string", + description: + "A clear, descriptive name for the rule block that summarizes its purpose. This name will be visible in the Continue UI and should help users identify the rule's function. For example: 'React Component Standards', 'Python Type Hints', or 'Code Documentation Requirements'.", + }, + rule_content: { + type: "string", + description: + "The specific instruction or standard to be followed in all future conversations. This should be a clear, concise directive written in imperative form. For example: 'Always use named exports instead of default exports in JavaScript modules', 'Always annotate Python functions with parameter and return types', or 'Use camelCase for variable names in JavaScript'. Each rule should focus on a single, well-defined behavior or standard.", + }, + }, + }, + }, +}; diff --git a/core/tools/implementations/createRuleBlock.ts b/core/tools/implementations/createRuleBlock.ts new file mode 100644 index 000000000..5e6cf14d9 --- /dev/null +++ b/core/tools/implementations/createRuleBlock.ts @@ -0,0 +1,62 @@ +import { ConfigYaml } from "@continuedev/config-yaml"; +import * as YAML from "yaml"; +import { ToolImpl } from "."; +import { joinPathsToUri } from "../../util/uri"; + +export interface CreateRuleBlockArgs { + rule_name: string; + rule_content: string; +} + +export const createRuleBlockImpl: ToolImpl = async ( + args: CreateRuleBlockArgs, + extras, +) => { + // Sanitize rule name for use in filename (remove special chars, replace spaces with dashes) + const safeRuleName = args.rule_name + .toLowerCase() + .replace(/[^a-z0-9\s-]/g, "") + .replace(/\s+/g, "-"); + + const ruleBlock: ConfigYaml = { + name: args.rule_name, + version: "0.0.1", + rules: [ + // This can be either a string or an object with {name, rule} + // Since we want a simple rule, we use the string format + args.rule_content, + ], + }; + + // Convert the rule block to YAML + const ruleYaml = YAML.stringify(ruleBlock); + + const [localContinueDir] = await extras.ide.getWorkspaceDirs(); + const rulesDirUri = joinPathsToUri( + localContinueDir, + ".continue", + "rules", + `${safeRuleName}.yaml`, + ); + + try { + await extras.ide.writeFile(rulesDirUri, ruleYaml); + await extras.ide.openFile(rulesDirUri); + + return [ + { + name: "Rule Block Created", + description: `Created ${args.rule_name} rule`, + content: ruleYaml, + }, + ]; + } catch (error) { + return [ + { + name: "Error", + description: "Failed to create rule block", + content: `Error creating rule block: ${error instanceof Error ? error.message : String(error)}`, + }, + ]; + } +}; diff --git a/core/tools/index.ts b/core/tools/index.ts index c9875c5eb..d89cf8744 100644 --- a/core/tools/index.ts +++ b/core/tools/index.ts @@ -1,4 +1,5 @@ import { createNewFileTool } from "./definitions/createNewFile"; +import { createRuleBlock } from "./definitions/createRuleBlock"; import { editFileTool } from "./definitions/editFile"; import { globSearchTool } from "./definitions/globSearch"; import { grepSearchTool } from "./definitions/grepSearch"; @@ -14,14 +15,13 @@ export const allTools = [ editFileTool, createNewFileTool, runTerminalCommandTool, - grepSearchTool, globSearchTool, searchWebTool, viewDiffTool, readCurrentlyOpenFileTool, - lsTool, + createRuleBlock, // replacing with ls tool for now // viewSubdirectoryTool, // viewRepoMapTool, diff --git a/docs/docs/customize/deep-dives/rules.md b/docs/docs/customize/deep-dives/rules.md index 3143b12cf..a37909d77 100644 --- a/docs/docs/customize/deep-dives/rules.md +++ b/docs/docs/customize/deep-dives/rules.md @@ -17,9 +17,15 @@ To form the system message, rules are joined with new lines, in the order they a ## `rules` blocks -Rules can be added to an Assistant on the Continue Hub. Explore available rules [here](https://hub.continue.dev/explore/rules), or [create your own](https://hub.continue.dev/new?type=block&blockType=rules) in the Hub. +Rules can be added to an Assistant on the Continue Hub. Explore available rules [here](https://hub.continue.dev/explore/rules), or [create your own](https://hub.continue.dev/new?type=block&blockType=rules) in the Hub. These blocks are defined using the [`config.yaml` syntax](../../reference.md#rules) and can also be created locally. -These blocks are defined using the [`config.yaml` syntax](../../reference.md#rules) and can also be created locally. Rules blocks can be simple text, or have the following properties: +:::info Automatically create local rule blocks +When in Agent mode, you can simply prompt the agent to create a rule for you. + +For example, you can say "Create a rule to always use named exports instead of default exports", and a rule will be created for you in `~/.continue/rules`. +::: + +Rules blocks can be simple text, or have the following properties: - `name` (**required**): A display name/title for the rule - `rule` (**required**): The text content of the rule diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx index 956b98158..2792efafd 100644 --- a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx +++ b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx @@ -79,7 +79,7 @@ export function ToolCallButtons(props: ToolCallButtonsProps) { onClick={() => dispatch(callTool())} data-testid="accept-tool-call-button" > - Continue + Accept ) : toolCallState.status === "calling" ? ( From 0232084570a06a802123b030bb3ce099dca67db7 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 18 Apr 2025 11:15:10 -0700 Subject: [PATCH 2/5] Update rules.md --- docs/docs/customize/deep-dives/rules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/customize/deep-dives/rules.md b/docs/docs/customize/deep-dives/rules.md index a37909d77..94dec8a07 100644 --- a/docs/docs/customize/deep-dives/rules.md +++ b/docs/docs/customize/deep-dives/rules.md @@ -22,7 +22,7 @@ Rules can be added to an Assistant on the Continue Hub. Explore available rules :::info Automatically create local rule blocks When in Agent mode, you can simply prompt the agent to create a rule for you. -For example, you can say "Create a rule to always use named exports instead of default exports", and a rule will be created for you in `~/.continue/rules`. +For example, you can say "Create a rule for this", and a rule will be created for you in `~/.continue/rules` based on your conversation. ::: Rules blocks can be simple text, or have the following properties: From 5ea40c6ca502fb00a8b948644f04ea9c73c9a7e6 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 18 Apr 2025 11:46:50 -0700 Subject: [PATCH 3/5] Update ToolCallButtonsDiv.tsx --- gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx index 2792efafd..956b98158 100644 --- a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx +++ b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx @@ -79,7 +79,7 @@ export function ToolCallButtons(props: ToolCallButtonsProps) { onClick={() => dispatch(callTool())} data-testid="accept-tool-call-button" > - Accept + Continue ) : toolCallState.status === "calling" ? ( From af1d5ed3e341b3e477889bac31b55a43d0371af7 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 18 Apr 2025 11:47:38 -0700 Subject: [PATCH 4/5] Update createRuleBlock.ts --- core/tools/implementations/createRuleBlock.ts | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/core/tools/implementations/createRuleBlock.ts b/core/tools/implementations/createRuleBlock.ts index 5e6cf14d9..4e37f8818 100644 --- a/core/tools/implementations/createRuleBlock.ts +++ b/core/tools/implementations/createRuleBlock.ts @@ -39,24 +39,14 @@ export const createRuleBlockImpl: ToolImpl = async ( `${safeRuleName}.yaml`, ); - try { - await extras.ide.writeFile(rulesDirUri, ruleYaml); - await extras.ide.openFile(rulesDirUri); + await extras.ide.writeFile(rulesDirUri, ruleYaml); + await extras.ide.openFile(rulesDirUri); - return [ - { - name: "Rule Block Created", - description: `Created ${args.rule_name} rule`, - content: ruleYaml, - }, - ]; - } catch (error) { - return [ - { - name: "Error", - description: "Failed to create rule block", - content: `Error creating rule block: ${error instanceof Error ? error.message : String(error)}`, - }, - ]; - } + return [ + { + name: "Rule Block Created", + description: `Created ${args.rule_name} rule`, + content: ruleYaml, + }, + ]; }; From 6070a645dd9741b433ad43fd09f37b42ec614a3e Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 18 Apr 2025 12:07:41 -0700 Subject: [PATCH 5/5] feat: dallins feedback --- core/tools/definitions/createRuleBlock.ts | 12 +++++------- docs/docs/agent/how-it-works.md | 8 +++++--- gui/src/redux/slices/uiSlice.ts | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/tools/definitions/createRuleBlock.ts b/core/tools/definitions/createRuleBlock.ts index 987ef0f80..bf5caa6dc 100644 --- a/core/tools/definitions/createRuleBlock.ts +++ b/core/tools/definitions/createRuleBlock.ts @@ -12,11 +12,9 @@ export const createRuleBlock: Tool = { function: { name: BuiltInToolNames.CreateRuleBlock, description: - "Creates a persistent rule block that will be applied to all future Chat, Edit and Agent conversations. " + - "Use this tool when the user wants to establish ongoing behaviors, preferences, or standards for code generation. " + - "This is ideal for capturing recurring preferences like 'always use named exports instead of default exports' or 'follow Google style docstrings'. " + - "Do NOT use this tool for one-time instructions that should only apply to the current conversation. " + - "The created rule will be formatted as a YAML file and stored in the user's `.continue/rules` directory.", + "Creates a persistent rule that applies to all future conversations. " + + "Use for establishing ongoing code standards or preferences (e.g. 'use named exports', 'follow Google docstrings'). " + + "Not for one-time instructions. Rules are stored as YAML in `.continue/rules`.", parameters: { type: "object", required: ["rule_name", "rule_content"], @@ -24,12 +22,12 @@ export const createRuleBlock: Tool = { rule_name: { type: "string", description: - "A clear, descriptive name for the rule block that summarizes its purpose. This name will be visible in the Continue UI and should help users identify the rule's function. For example: 'React Component Standards', 'Python Type Hints', or 'Code Documentation Requirements'.", + "Short, descriptive name summarizing the rule's purpose (e.g. 'React Standards', 'Type Hints')", }, rule_content: { type: "string", description: - "The specific instruction or standard to be followed in all future conversations. This should be a clear, concise directive written in imperative form. For example: 'Always use named exports instead of default exports in JavaScript modules', 'Always annotate Python functions with parameter and return types', or 'Use camelCase for variable names in JavaScript'. Each rule should focus on a single, well-defined behavior or standard.", + "Clear, imperative instruction for future code generation (e.g. 'Use named exports', 'Add Python type hints'). Each rule should focus on one specific standard.", }, }, }, diff --git a/docs/docs/agent/how-it-works.md b/docs/docs/agent/how-it-works.md index b89c7ac85..1191fa9f8 100644 --- a/docs/docs/agent/how-it-works.md +++ b/docs/docs/agent/how-it-works.md @@ -9,9 +9,10 @@ Agent offers the same functionality as Chat, while also including tools in the r ## The tool handshake -Tools provide a flexible, powerful way for models to interface with the external world. They are provided to the model as a JSON object with a name and an arguments schema. For example, a `read_file` tool with a `filepath` argument will give the model the ability to request the contents of a specific file. +Tools provide a flexible, powerful way for models to interface with the external world. They are provided to the model as a JSON object with a name and an arguments schema. For example, a `read_file` tool with a `filepath` argument will give the model the ability to request the contents of a specific file. The following handshake describes how Agent uses tools: + 1. In Agent mode, available tools are sent along with `user` chat requests 2. The model can choose to include a tool call in its response 3. The user gives permission. This step is skipped if the policy for that tool is set to `Automatic` @@ -32,7 +33,8 @@ Continue includes several built-in tools which provide the model access to IDE f - **Create new file** (`builtin_create_new_file`): Create a new file within the project, with path and contents specified by the model - **Exact search** (`builtin_exact_search`): perform a `ripgrep` search within the project - **Run terminal command** (`builtin_run_terminal_command`): run a terminal command from the workspace root -- **Search web** (`builtin_search_web`): Perform a web search to get top results +- **Search web** (`builtin_search_web`): Perform a web search to get top results - **View diff** (`builtin_view_diff`): View the current working git diff - **View repo map** (`builtin_view_repo_map`): request a copy of the repository map—same as the [Repo Map Context Provider](../customize/context-providers.mdx#repository-map) -- **View subdirectory** (`builtin_view_subdirectory`): request a copy of a repo map for a specific directory within the project \ No newline at end of file +- **View subdirectory** (`builtin_view_subdirectory`): request a copy of a repo map for a specific directory within the project +- **Create Rule Block** (`builtin_create_rule_block`): creates a new rule block in `.continue/rules` based on the contents of the conversation diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 0ea07b190..7cc964cd6 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -52,6 +52,7 @@ export const uiSlice = createSlice({ [BuiltInToolNames.SearchWeb]: "allowedWithoutPermission", [BuiltInToolNames.ViewDiff]: "allowedWithoutPermission", [BuiltInToolNames.LSTool]: "allowedWithoutPermission", + [BuiltInToolNames.CreateRuleBlock]: "allowedWithPermission", }, toolGroupSettings: { BUILT_IN_GROUP_NAME: "include",