Elffuss BraidHub

kikocis/continue public

main · 6.4 KiBRawPermalink
1---
2title: "How to Create and Manage Rules in Continue"
3description: "Rules are used to provide system message instructions to the model for Agent, Chat, and Edit requests"
4keywords: [rules, system, prompt, message]
5sidebarTitle: "Rules"
6---
7
8Rules provide instructions to the model for [Agent](../../features/agent/quick-start), [Chat](../../features/chat/quick-start), and [Edit](../../features/edit/quick-start) requests.
9
10<Info>
11 Rules are not included in [autocomplete](./autocomplete) or
12 [apply](../model-roles/apply).
13</Info>
14
15## How Rules Work in Continue
16
17You can view the current rules by clicking the pen icon above the main toolbar:
18
19![rules input toolbar section](/images/notch-rules.png)
20
21To form the system message, rules are joined with new lines, in the order they appear in the toolbar. This includes the base chat system message ([see below](#how-to-customize-chat-system-message)).
22
23## Quick Start: How to Create Your First Rule File
24
25Below is a quick example of setting up a new rule file:
26
271. Create a folder called `.continue/rules` at the top level of your workspace
282. Add a file called `pirates-rule.md` to this folder.
293. Write the following contents to `pirates-rule.md` and save.
30
31```md title=".continue/rules/pirates-rule.md"
32---
33name: Pirate rule
34---
35
36- Talk like a pirate.
37```
38
39Now test your rules by asking a question about a file in chat.
40
41![pirate rule test](/images/pirate-rule-test.png)
42
43## How to Create Rules Blocks
44
45Rules can be added locally using the "Add Rules" button while viewing the Local Agent's rules.
46
47![add local rules button](/images/add-local-rules.png)
48
49<Info>
50**Automatically create local rule blocks**: When in Agent mode, you can prompt the agent to create a rule for you using the `create_rule_block` tool if enabled.
51
52For example, you can say "Create a rule for this", and a rule will be created for you in `.continue/rules` based on your conversation.
53
54</Info>
55
56Rules can also be added to an Agent on the Continue Hub.
57
58Explore available rules [here](https://hub.continue.dev), or [create your own](https://hub.continue.dev/new?type=block&blockType=rules) in the Hub.
59
60### How to Configure Rule Properties and Syntax
61
62<Info>
63 Rules were originally defined in YAML format (demonstrated below), but we
64 introduced Markdown for easier editing. While both are still supported, we
65 recommend Markdown.
66</Info>
67
68Rules blocks can be simple text, written in YAML configuration files, or as Markdown (`.md`) files. They can have the following properties:
69
70- `name` (**required** for YAML): A display name/title for the rule
71- `globs` (optional): When files are provided as context that match this glob pattern, the rule will be included. This can be either a single pattern (e.g., `"**/*.{ts,tsx}"`) or an array of patterns (e.g., `["src/**/*.ts", "tests/**/*.ts"]`).
72- `regex` (optional): When files are provided as context and their content matches this regex pattern, the rule will be included. This can be either a single pattern (e.g., `"^import .* from '.*';$"`) or an array of patterns (e.g., `["^import .* from '.*';$", "^export .* from '.*';$"]`).
73- `description` (optional): A description for the rule. Agents may read this description when `alwaysApply` is false to determine whether the rule should be pulled into context.
74- `alwaysApply`: Determines whether the rule is always included. Behavior is described below:
75 - `true`: Always included, regardless of file context
76 - `false`: Included if globs exist AND match file context, or the agent decides to pull the rule into context based on its description
77 - `undefined` (default behavior): Included if no globs exist OR globs exist and match
78
79<Tabs>
80<Tab title="Markdown">
81```md title="doc-standards.md"
82---
83name: Documentation Standards
84globs: docs/**/*.{md,mdx}
85alwaysApply: false
86description: Standards for writing and maintaining Continue Docs
87---
88
89# Continue Docs Standards
90
91- Follow Mintlify documentation standards
92- Include YAML frontmatter with title, description, and keywords
93- Use consistent heading hierarchy starting with h2 (##)
94- Include relevant Admonition components for tips, warnings, and info
95- Use descriptive alt text for images
96- Include cross-references to related documentation
97- Reference other docs with relative paths
98- Keep paragraphs concise and scannable
99- Use code blocks with appropriate language tags
100
101````
102</Tab>
103
104<Tab title="YAML">
105```yaml title="doc-standards.yaml"
106name: Documentation Standards
107version: 1.0.0
108schema: v1
109
110rules:
111 - name: Documentation Standards
112 globs: docs/**/*.{md,mdx}
113 alwaysApply: false
114 rule: >
115 - Follow Mintlify documentation standards
116 - Include YAML frontmatter with title, description, and keywords
117 - Use consistent heading hierarchy starting with h2 (##)
118 - Include relevant Admonition components for tips, warnings, and info
119 - Use descriptive alt text for images
120 - Include cross-references to related documentation
121 - Reference other docs with relative paths
122 - Keep paragraphs concise and scannable
123 - Use code blocks with appropriate language tags
124````
125
126</Tab>
127</Tabs>
128
129### How to Set Up Project-Specific Rules
130
131You can create project-specific rules by adding a `.continue/rules` folder to the root of your project and adding new rule files.
132
133Rules files are loaded in lexicographical order, so you can prefix them with numbers to control the order in which they are applied. For example: `01-general.md`, `02-frontend.md`, `03-backend.md`.
134
135### Example: How to Create TypeScript-Specific Rules
136
137```md title=".continue/rules/typescript.md"
138---
139name: TypeScript Best Practices
140globs: ["**/*.ts", "**/*.tsx"]
141---
142
143# TypeScript Rules
144
145- Always use TypeScript interfaces for object shapes
146- Use type aliases sparingly, prefer interfaces
147- Include proper JSDoc comments for public APIs
148- Use strict null checks
149- Prefer readonly arrays and properties where possible
150- modularize components into smaller, reusable pieces
151```
152
153### How to Customize Chat System Message
154
155Continue includes a simple default system message for [Agent](../../features/agent/quick-start) and [Chat](../../features/chat/quick-start) requests, to help the model provide reliable codeblock formats in its output.
156
157This can be viewed in the rules section of the toolbar (see above), or in the source code [here](https://github.com/continuedev/continue/blob/main/core/llm/constructMessages.ts#L4).
158
159Advanced users can override this system message for a specific model if needed by using `chatOptions.baseSystemMessage`. See the [`config.yaml` reference](/reference#models).