feat: create_rule_block tool
This commit is contained in:
parent
6f6c4de46d
commit
2c8032c339
7 changed files with 114 additions and 5 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
37
core/tools/definitions/createRuleBlock.ts
Normal file
37
core/tools/definitions/createRuleBlock.ts
Normal file
|
|
@ -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.",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
62
core/tools/implementations/createRuleBlock.ts
Normal file
62
core/tools/implementations/createRuleBlock.ts
Normal file
|
|
@ -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)}`,
|
||||
},
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ export function ToolCallButtons(props: ToolCallButtonsProps) {
|
|||
onClick={() => dispatch(callTool())}
|
||||
data-testid="accept-tool-call-button"
|
||||
>
|
||||
Continue
|
||||
Accept
|
||||
</AcceptButton>
|
||||
</>
|
||||
) : toolCallState.status === "calling" ? (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue