Skip to content

Commit 5d78f48

Browse files
Update repo rules docs to include organization rules and rule hierarchy
- Renamed from 'Repository Rules' to 'Agent Rules' to reflect broader scope - Added comprehensive explanation of organization rules vs repository rules - Documented rule hierarchy: repository rules override organization rules - Added detailed configuration instructions for both rule types - Included practical examples showing rule hierarchy in action - Updated use cases to show organization-level vs repository-level examples
1 parent 14c9764 commit 5d78f48

File tree

1 file changed

+93
-34
lines changed

1 file changed

+93
-34
lines changed

docs/settings/repo-rules.mdx

Lines changed: 93 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,80 @@
11
---
2-
title: "Repository Rules"
3-
sidebarTitle: "Repo Rules"
2+
title: "Agent Rules"
3+
sidebarTitle: "Agent Rules"
44
icon: "shield-check"
55
---
66

7-
Repository Rules in Codegen act as a persistent set of instructions or a "system prompt" for the AI agent whenever it operates on a specific repository. These rules guide the agent's behavior by enforcing coding standards and repository-specific conventions through automated reminders to the language model (LLM) during each task.
7+
Agent Rules in Codegen act as persistent instructions or "system prompts" for the AI agent, guiding its behavior by enforcing coding standards, conventions, and preferences. These rules are automatically included in the agent's context during each task to ensure consistent behavior across your organization and repositories.
88

9-
Codegen supports two types of repository rules:
10-
1. **Manual Repository Rules** - configured through the web interface
11-
2. **Automatic Rule File Detection** - automatically discovered from your repository files
9+
## Rule Hierarchy
10+
11+
Codegen supports a hierarchical rule system with two levels:
12+
13+
1. **Organization Rules** - Apply to all repositories within your organization
14+
2. **Repository Rules** - Apply to a specific repository and override organization rules when conflicts exist
15+
16+
<Note>
17+
**Rule Precedence**: Repository rules take precedence over organization rules when conflicts exist. This allows you to set organization-wide defaults while customizing specific repositories as needed.
18+
</Note>
19+
20+
## Types of Rules
21+
22+
Each level supports two types of rule configuration:
23+
24+
### Manual Rules
25+
Rules configured directly through the Codegen web interface at [codegen.com/repos](https://codegen.com/repos) (for repository rules) or organization settings (for organization rules).
26+
27+
### Automatic Rule File Detection
28+
Rules automatically discovered from files in your repository (repository level only).
1229

1330
<Frame caption="Update repo rules at codegen.com/repos">
1431
<img src="/images/repo-rules.png" />
1532
</Frame>
1633

17-
## How Repository Rules Work
34+
## How Agent Rules Work
35+
36+
When an agent is assigned a task, all applicable rules are automatically included in the agent's context as "Mandatory User Rules." The agent sees these rules alongside the actual task or prompt it receives, ensuring consistent behavior.
37+
38+
**Rule Resolution Process:**
39+
1. **Organization Rules** are loaded first (if configured for your organization)
40+
2. **Repository Rules** are loaded next (if configured for the specific repository)
41+
3. **Repository rules override organization rules** when conflicts exist
42+
4. **Automatic rule files** are discovered and included (repository level only)
43+
5. All rules are combined and presented to the agent as mandatory constraints
1844

19-
When an agent is assigned a task on a repository with defined rules, those rules are automatically prepended or made available to the LLM as part of its context. This means the agent "sees" these rules alongside the actual task or prompt it receives.
45+
For example, if your organization has a rule "Use TypeScript for all new code" and a specific repository has a rule "Use JavaScript for this legacy project," the repository rule takes precedence for that specific repository.
2046

21-
For example, if you have a rule like "Always use tabs for indentation," the agent will be reminded of this preference before it starts writing or modifying code in that repository.
47+
## Configuring Agent Rules
2248

23-
## Accessing and Configuring Repository Rules
49+
### Organization Rules
2450

25-
You can typically find and configure Repository Rules within the settings page for each specific repository in the Codegen web UI.
51+
Organization rules apply to all repositories within your organization and serve as default behavior guidelines.
2652

27-
1. Navigate to [codegen.com/repos](https://codegen.com/repos).
28-
2. Select the repository for which you want to set rules.
29-
3. Look for a section titled "Repository rules" or similar in the repository's settings.
53+
**To configure organization rules:**
54+
1. Navigate to your organization settings in the Codegen web interface
55+
2. Look for the "Organization Rules" section
56+
3. Enter your organization-wide rules in the text area
57+
4. Click "Save" to apply them to all repositories in your organization
58+
59+
<Tip>
60+
Organization rules are perfect for setting coding standards, commit message conventions, or testing requirements that should apply across all your repositories.
61+
</Tip>
62+
63+
### Repository Rules
64+
65+
Repository rules apply to a specific repository and override any conflicting organization rules.
66+
67+
**To configure repository rules:**
68+
1. Navigate to [codegen.com/repos](https://codegen.com/repos)
69+
2. Select the repository for which you want to set rules
70+
3. Look for the "Repository Rules" section in the repository's settings
71+
4. Enter your repository-specific rules in the text area
72+
5. Click "Save" to apply them
3073

3174
<Frame caption="Update repo rules at codegen.com/repos">
3275
<img src="/images/repo-rules.png" />
3376
</Frame>
3477

35-
In the text area provided (as shown in the image), you can specify any rules you want the agent to follow for this repository. Click "Save" to apply them.
36-
3778
## Automatic Rule File Detection
3879

3980
In addition to manual repository rules, Codegen automatically discovers and includes agent rule files from your repository when the agent starts working on it. This happens automatically whenever the `set_active_codebase` tool is used.
@@ -105,30 +146,48 @@ When rules are discovered, they are displayed in the AgentTrace under the `SetAc
105146

106147
## Common Use Cases and Examples
107148

108-
Repository rules are flexible and can be used for various purposes:
149+
Agent rules are flexible and can be used for various purposes across different levels:
150+
151+
### Organization-Level Rules Examples
152+
153+
Perfect for organization-wide standards that should apply to all repositories:
109154

110-
- **Enforcing Linting/Formatting:**
111-
- "Remember to run the linter with `npm run lint` before committing."
112-
- "Ensure all Python code follows PEP 8 guidelines. Use `black` for formatting."
113-
- **Specifying Commit Message Conventions:**
155+
- **Coding Standards:**
156+
- "All code must follow our organization's style guide. Use Prettier for JavaScript/TypeScript formatting."
157+
- "All API endpoints must include proper error handling and logging."
158+
- **Security Requirements:**
159+
- "Never commit API keys, passwords, or other secrets to the repository."
160+
- "All database queries must use parameterized statements to prevent SQL injection."
161+
- **Process Requirements:**
114162
- "All commit messages must follow the Conventional Commits specification."
115-
- "Prefix commit messages with the related Linear issue ID (e.g., `ENG-123: ...`)."
116-
- **Highlighting Project-Specific Information:**
117-
- "This repository uses TypeScript. All new backend code should be in the `/server/src` directory."
163+
- "Every PR must include tests for new functionality."
164+
165+
### Repository-Level Rules Examples
166+
167+
Perfect for repository-specific requirements that may override organization defaults:
168+
169+
- **Technology-Specific Rules:**
170+
- "This is a Python project. Use `black` for formatting and `pytest` for testing."
171+
- "This legacy repository uses JavaScript instead of our organization's TypeScript standard."
172+
- **Project-Specific Information:**
173+
- "All new backend code should be in the `/server/src` directory."
118174
- "Avoid using deprecated function `old_function()`. Use `new_function()` instead."
119-
- **Code Style Preferences:**
120-
- "Don't write super long strings, as this will break pre-commit. Do triple-quoted strings with newlines, non-indented, instead!" (As seen in your example image)
121-
- "Prefer functional components over class components in React."
122-
- **Reminders for Testing:**
123-
- "Ensure all new features have corresponding unit tests."
124-
- "Run integration tests with `npm run test:integration` after significant changes."
175+
- **Build and Deployment:**
176+
- "Run `npm run build` before committing to ensure the build passes."
177+
- "This repository deploys automatically on merge to main - ensure all tests pass."
178+
179+
### Rule Hierarchy in Action
180+
181+
Here's how organization and repository rules work together:
182+
183+
**Organization Rule:** "Use TypeScript for all new code"
184+
**Repository Rule:** "This legacy project uses JavaScript - do not convert existing files"
185+
**Result:** The agent will use JavaScript for this specific repository while using TypeScript for all other repositories in the organization.
125186

126187
<Tip>
127-
Keep your repository rules concise and clear. Overly complex or numerous rules
128-
might confuse the agent or lead to suboptimal performance. Focus on the most
129-
critical guidelines for each repository.
188+
Keep your rules concise and clear. Overly complex or numerous rules might confuse the agent or lead to suboptimal performance. Focus on the most critical guidelines for your organization and repositories.
130189
</Tip>
131190

132191
<Note>
133-
Both manual repository rules and automatic rule files are applied *in addition* to any global prompting strategies or agent capabilities. They provide a repository-specific layer of instruction that helps ensure consistent behavior across your codebase.
192+
All agent rules (organization, repository, and automatic rule files) are applied *in addition* to any global prompting strategies or agent capabilities. They provide a hierarchical layer of instruction that helps ensure consistent behavior across your organization and codebases.
134193
</Note>{" "}

0 commit comments

Comments
 (0)