Elffuss BraidHub

kikocis/continue public

main · 3.9 KiBRawPermalink
1import { Tool } from "../..";
2import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
3
4const NAME_ARG_DESC =
5 "Short, descriptive name summarizing the rule's purpose (e.g. 'React Standards', 'Type Hints')";
6const RULE_ARG_DESC =
7 "Clear, imperative instruction for future code generation (e.g. 'Use named exports', 'Add Python type hints'). Each rule should focus on one specific standard.";
8const DESC_ARG_DESC =
9 "Description of when this rule should be applied. Required for Agent Requested rules (AI decides when to apply). Optional for other types.";
10const GLOB_ARG_DESC =
11 "Optional file patterns to which this rule applies (e.g. ['**/*.{ts,tsx}'] or ['src/**/*.ts', 'tests/**/*.ts'])";
12const REGEX_ARG_DESC =
13 "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)";
14
15const ALWAYS_APPLY_DESC =
16 "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.";
17
18export const createRuleBlock: Tool = {
19 type: "function",
20 displayTitle: "Create Rule Block",
21 wouldLikeTo: 'create a rule block for "{{{ name }}}"',
22 isCurrently: 'creating a rule block for "{{{ name }}}"',
23 hasAlready: 'created a rule block for "{{{ name }}}"',
24 readonly: false,
25 isInstant: true,
26 group: BUILT_IN_GROUP_NAME,
27 function: {
28 name: BuiltInToolNames.CreateRuleBlock,
29 description:
30 '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)',
31 parameters: {
32 type: "object",
33 required: ["name", "rule"],
34 properties: {
35 name: {
36 type: "string",
37 description: NAME_ARG_DESC,
38 },
39 rule: {
40 type: "string",
41 description: RULE_ARG_DESC,
42 },
43 description: {
44 type: "string",
45 description: DESC_ARG_DESC,
46 },
47 globs: {
48 type: "string",
49 description: GLOB_ARG_DESC,
50 },
51 regex: {
52 type: "string",
53 description: REGEX_ARG_DESC,
54 },
55 alwaysApply: {
56 type: "boolean",
57 description: ALWAYS_APPLY_DESC,
58 },
59 },
60 },
61 },
62 defaultToolPolicy: "allowedWithPermission",
63 systemMessageDescription: {
64 prefix: `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.
65This 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.
66To create a rule, respond with a ${BuiltInToolNames.CreateRuleBlock} tool call and the following arguments:
67- name: ${NAME_ARG_DESC}
68- rule: ${RULE_ARG_DESC}
69- description: ${DESC_ARG_DESC}
70- globs: ${GLOB_ARG_DESC}
71- alwaysApply: ${ALWAYS_APPLY_DESC}
72For example:`,
73 exampleArgs: [
74 ["name", "Use PropTypes"],
75 [
76 "rule",
77 "Always use PropTypes when declaring React component properties",
78 ],
79 [
80 "description",
81 "Ensure that all prop types are explicitly declared for better type safety and code maintainability in React components.",
82 ],
83 ["globs", "**/*.js"],
84 ["alwaysApply", "false"],
85 ],
86 },
87 toolCallIcon: "PencilIcon",
88};