Elffuss BraidHub

kikocis/continue public

99fe51849b68 · 6.6 KiBRawPermalink
1---
2title: "Rules"
3description: "Rules are used to provide instructions to the model for Chat, Edit, and Agent requests."
4keywords: [rules, .continuerules, system, prompt, message]
5---
6
7Rules provide instructions to the model for [Chat](../../features/chat/quick-start), [Edit](../../features/edit/quick-start), and [Agent](../../features/agent/quick-start) requests.
8
9<Info>
10 Rules are not included in [autocomplete](./autocomplete.mdx) or
11 [apply](../model-roles/apply.mdx).
12</Info>
13
14## How it works
15
16You can view the current rules by clicking the pen icon above the main toolbar:
17
18![rules input toolbar section](/images/notch-rules.png)
19
20To 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](#chat-system-message)).
21
22## Quick Start
23
24Below is a quick example of setting up a new rule file:
25
261. Create a folder called `.continue/rules` at the top level of your workspace
272. Add a file called `pirates-rule.md` to this folder.
283. Write the following contents to `pirates-rule.md` and save.
29
30```md title=".continue/rules/pirates-rule.md"
31---
32name: Pirate rule
33---
34
35- Talk like a pirate.
36```
37
38Now test your rules by asking a question about a file in chat.
39
40![pirate rule test](/images/pirate-rule-test.png)
41
42## Creating rules blocks
43
44Rules can be added locally using the "Add Rules" button while viewing the Local Assistant's rules.
45
46![add local rules button](/images/add-local-rules.png)
47
48<Info>
49**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.
50
51For example, you can say "Create a rule for this", and a rule will be created for you in `.continue/rules` based on your conversation.
52
53</Info>
54
55Rules can also be added to an Assistant on the Continue Hub.
56
57Explore available rules [here](https://hub.continue.dev), or [create your own](https://hub.continue.dev/new?type=block&blockType=rules) in the Hub.
58
59### Syntax
60
61<Info>
62 Rules were originally defined in YAML format (demonstrated below), but we
63 introduced Markdown for easier editing. While both are still supported, we
64 recommend Markdown.
65</Info>
66
67Rules blocks can be simple text, written in YAML configuration files, or as Markdown (`.md`) files. They can have the following properties:
68
69- `name` (**required** for YAML): A display name/title for the rule
70- `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"]`).
71- `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 '.*';$"]`).
72- `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.
73- `alwaysApply`: Determines whether the rule is always included. Behavior is described below:
74 - `true`: Always included, regardless of file context
75 - `false`: Included if globs exist AND match file context, or the agent decides to pull the rule into context based on its description
76 - `undefined` (default behavior): Included if no globs exist OR globs exist and match
77
78<Tabs>
79<Tab title="Markdown">
80```md title="doc-standards.md"
81---
82name: Documentation Standards
83globs: docs/**/*.{md,mdx}
84alwaysApply: false
85description: Standards for writing and maintaining Continue Docs
86---
87
88# Continue Docs Standards
89
90- Follow Docusaurus documentation standards
91- Include YAML frontmatter with title, description, and keywords
92- Use consistent heading hierarchy starting with h2 (##)
93- Include relevant Admonition components for tips, warnings, and info
94- Use descriptive alt text for images
95- Include cross-references to related documentation
96- Reference other docs with relative paths
97- Keep paragraphs concise and scannable
98- Use code blocks with appropriate language tags
99
100````
101</Tab>
102
103<Tab title="YAML">
104```yaml title="doc-standards.yaml"
105name: Documentation Standards
106version: 1.0.0
107schema: v1
108
109rules:
110 - name: Documentation Standards
111 globs: docs/**/*.{md,mdx}
112 alwaysApply: false
113 rule: >
114 - Follow Docusaurus documentation standards
115 - Include YAML frontmatter with title, description, and keywords
116 - Use consistent heading hierarchy starting with h2 (##)
117 - Include relevant Admonition components for tips, warnings, and info
118 - Use descriptive alt text for images
119 - Include cross-references to related documentation
120 - Reference other docs with relative paths
121 - Keep paragraphs concise and scannable
122 - Use code blocks with appropriate language tags
123````
124
125</Tab>
126</Tabs>
127
128### `.continue/rules` folder
129
130You can create project-specific rules by adding a `.continue/rules` folder to the root of your project and adding new rule files.
131
132Rules 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`.
133
134### Example: TypeScript Rules
135
136```md title=".continue/rules/typescript.md"
137---
138name: TypeScript Best Practices
139globs: ["**/*.ts", "**/*.tsx"]
140---
141
142# TypeScript Rules
143
144- Always use TypeScript interfaces for object shapes
145- Use type aliases sparingly, prefer interfaces
146- Include proper JSDoc comments for public APIs
147- Use strict null checks
148- Prefer readonly arrays and properties where possible
149- modularize components into smaller, reusable pieces
150```
151
152### Chat System Message
153
154Continue includes a simple default system message for [Chat](../../features/chat/quick-start) and [Agent](../../features/agent/quick-start) requests, to help the model provide reliable codeblock formats in its output.
155
156This 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).
157
158Advanced users can override this system message for a specific model if needed by using `chatOptions.baseSystemMessage`. See the [`config.yaml` reference](/reference#models).
159
160### `.continuerules`
161
162<Warning>
163 `.continuerules` will be deprecated in a future release. Please use the
164 `.continue/rules` folder instead.
165</Warning>
166
167You can create project-specific rules by adding a `.continuerules` file to the root of your project. This file is raw text and its full contents will be used as rules.