Elffuss BraidHub

kikocis/continue public

18c867793b67 · 4.0 KiBRawPermalink
1import { Tool } from "../..";
2import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
3import { createSystemMessageExampleCall } from "../systemMessageTools/buildToolsSystemMessage";
4
5const NAME_ARG_DESC =
6 "Short, descriptive name summarizing the rule's purpose (e.g. 'React Standards', 'Type Hints')";
7const RULE_ARG_DESC =
8 "Clear, imperative instruction for future code generation (e.g. 'Use named exports', 'Add Python type hints'). Each rule should focus on one specific standard.";
9const DESC_ARG_DESC =
10 "Description of when this rule should be applied. Required for Agent Requested rules (AI decides when to apply). Optional for other types.";
11const GLOB_ARG_DESC =
12 "Optional file patterns to which this rule applies (e.g. ['**/*.{ts,tsx}'] or ['src/**/*.ts', 'tests/**/*.ts'])";
13const REGEX_ARG_DESC =
14 "Optional regex patterns to match against file content. Rule applies only to files whose content matches the pattern (e.g. 'useEffect' for React hooks or '\\bclass\\b' for class definitions)";
15
16const ALWAYS_APPLY_DESC =
17 "Whether this rule should always be applied. Set to false for Agent Requested and Manual rules. Omit or set to true for Always and Auto Attached rules.";
18
19export const createRuleBlock: Tool = {
20 type: "function",
21 displayTitle: "Create Rule Block",
22 wouldLikeTo: 'create a rule block for "{{{ name }}}"',
23 isCurrently: 'creating a rule block for "{{{ name }}}"',
24 hasAlready: 'created a rule block for "{{{ name }}}"',
25 readonly: false,
26 isInstant: true,
27 group: BUILT_IN_GROUP_NAME,
28 function: {
29 name: BuiltInToolNames.CreateRuleBlock,
30 description:
31 'Creates a "rule" that can be referenced in future conversations. This should be used whenever you want to establish code standards / preferences that should be applied consistently, or when you want to avoid making a mistake again. To modify existing rules, use the edit tool instead.\n\nRule Types:\n- Always: Include only "rule" (always included in model context)\n- Auto Attached: Include "rule", "globs", and/or "regex" (included when files match patterns)\n- Agent Requested: Include "rule" and "description" (AI decides when to apply based on description)\n- Manual: Include only "rule" (only included when explicitly mentioned using @ruleName)',
32 parameters: {
33 type: "object",
34 required: ["name", "rule"],
35 properties: {
36 name: {
37 type: "string",
38 description: NAME_ARG_DESC,
39 },
40 rule: {
41 type: "string",
42 description: RULE_ARG_DESC,
43 },
44 description: {
45 type: "string",
46 description: DESC_ARG_DESC,
47 },
48 globs: {
49 type: "string",
50 description: GLOB_ARG_DESC,
51 },
52 regex: {
53 type: "string",
54 description: REGEX_ARG_DESC,
55 },
56 alwaysApply: {
57 type: "boolean",
58 description: ALWAYS_APPLY_DESC,
59 },
60 },
61 },
62 },
63 defaultToolPolicy: "allowedWithPermission",
64 systemMessageDescription: createSystemMessageExampleCall(
65 BuiltInToolNames.CreateRuleBlock,
66 `Sometimes the user will provide feedback or guidance on your output. If you were not aware of these "rules", consider using the ${BuiltInToolNames.CreateRuleBlock} tool to persist the rule for future interactions.
67This tool cannot be used to edit existing rules, but you can search in the ".continue/rules" folder and use the edit tool to manage rules.
68To create a rule, respond with a ${BuiltInToolNames.CreateRuleBlock} tool call and the following arguments:
69- name: ${NAME_ARG_DESC}
70- rule: ${RULE_ARG_DESC}
71- description: ${DESC_ARG_DESC}
72- globs: ${GLOB_ARG_DESC}
73- alwaysApply: ${ALWAYS_APPLY_DESC}
74For example:`,
75 [
76 ["name", "Use PropTypes"],
77 [
78 "rule",
79 "Always use PropTypes when declaring React component properties",
80 ],
81 [
82 "description",
83 "Ensure that all prop types are explicitly declared for better type safety and code maintainability in React components.",
84 ],
85 ["globs", "**/*.js"],
86 ["alwaysApply", "false"],
87 ],
88 ),
89};