RuleGen VS Code Extension
The RuleGen VS Code extension streamlines rule development by bringing code generation, rule discovery, and Control Plane integration directly into your editor. Extract rules from source code, watch for changes, publish to the control plane, and explore your entire ruleset—all without leaving VS Code.
Why Use the Extension?
- Zero-friction extraction — Scan your project for
[MExtractAsRule]attributes and generate rule files automatically - Live feedback — Enable the watcher to regenerate rules on every save
- Integrated publishing — Push rules to the Control Plane without CLI switches
- Rule Explorer — Visual tree of all rules in your workspace with metadata
- Smart navigation — Jump between source rules and their generated code instantly
Installation
From VS Code Marketplace
- Open VS Code and press
Ctrl+Shift+X(orCmd+Shift+Xon macOS) to open the Extensions sidebar - Search for "RuleGen"
- Click Install on the Muonroi RuleGen extension (ID:
muonroi.rulegen-vscode) - Reload VS Code when prompted
Manual Installation (VSIX File)
If you prefer to install from a VSIX file:
- Download the latest
.vsixfrom the Muonroi Releases - Open the VS Code Command Palette (
Ctrl+Shift+P) - Run: Extensions: Install from VSIX
- Select the downloaded file
- Reload VS Code
Configuration
Project Setup (.rulegenrc.json)
Create a .rulegenrc.json file in your project root to configure RuleGen behavior:
{
"outputDir": "./generated/rules",
"scanPatterns": [
"**/*.cs"
],
"excludePatterns": [
"**/obj/**",
"**/bin/**",
"**/.git/**"
],
"namespace": "MyApp.Rules",
"generateAsync": true,
"preserveExistingFiles": false
}
Common options:
| Option | Type | Default | Description |
|---|---|---|---|
outputDir | string | ./Rules/Generated | Directory for generated .g.cs files |
scanPatterns | string[] | ["**/*.cs"] | Glob patterns to scan for [MExtractAsRule] |
excludePatterns | string[] | ["**/obj/**", "**/bin/**"] | Paths to exclude from scanning |
namespace | string | (inherited) | Namespace for generated rule classes |
generateAsync | boolean | true | Generate async rule methods |
preserveExistingFiles | boolean | false | Keep manual edits in generated files |
VS Code Settings
Open Settings (Ctrl+,) and search for RuleGen to configure extension behavior:
{
"rulegen.controlPlaneUrl": "https://cp.yourcompany.local",
"rulegen.autoActivateLicense": false,
"rulegen.showRuleMetadataInCodeLens": true,
"rulegen.watcherDebounceMs": 500
}
Free Features
All developers get these features regardless of license:
1. Extract All Rules
Extract every [MExtractAsRule] rule in your project and generate corresponding .g.cs files.
Command Palette: RuleGen: Extract All Rules
Keyboard: Ctrl+Alt+R E (Windows/Linux) or Cmd+Alt+R E (macOS)
What happens:
- Extension scans your project for decorated rule methods
- Parses metadata (order, hook point, rules)
- Generates typed rule classes in
outputDir - Shows success/error summary
2. Start Rule Watcher
Enable automatic re-extraction whenever you save a file containing rules.
Command Palette: RuleGen: Start Rule Watcher
What happens:
- Extension monitors changes to
.csfiles - On save, re-runs extraction if
[MExtractAsRule]decorators changed - Debounces rapid saves (default 500ms)
- Shows status in the VS Code status bar
Stop watcher: RuleGen: Stop Rule Watcher or close the workspace
3. Go to Generated Rule
Jump from a rule class directly to its generated .g.cs file.
Keyboard: Ctrl+Shift+G (in any rule class)
Shortcut: Right-click a rule class name → Go to Generated
4. CodeLens Integration
Inline metadata displays above each [MExtractAsRule] method:
[MExtractAsRule(
Hook = "approval-decision",
Order = 10
)]
public class ApprovalRule : IRule
{
// CodeLens shows:
// Hook: approval-decision | Order: 10 | Generated: ApprovalRule.g.cs
// Click to jump to generated code
}
Premium Features (Licensed/Enterprise)
Unlock advanced workflows by activating your license in VS Code.
License Activation
Command Palette: RuleGen: Activate License
Flow:
- Open command palette and select
RuleGen: Activate License - Enter your
MRR-xxxxxkey when prompted - Extension validates the key against the License Server
- On success, all premium features unlock automatically
- License status displays in the status bar
Keyboard: Ctrl+Alt+R L
View status: RuleGen: Show License Status
Premium Feature 1: Rule Explorer
A visual tree view of all rules in your workspace with their dependencies, hooks, and metadata.
Command Palette: RuleGen: Open Rule Explorer
Keyboard: Ctrl+Alt+R X
Explorer panel shows:
- All extracted rules grouped by hook point
- Rule order and execution dependencies
- Rule input/output fields
- Links to source and generated files
- Search/filter by name
Click on a rule to:
- Navigate to source code
- View generated rule class
- See rule metadata (hook, order, async)
Premium Feature 2: Publish Ruleset to Control Plane
Push extracted rules directly to the Control Plane API without using the CLI.
Command Palette: RuleGen: Publish Ruleset to Control Plane
Keyboard: Ctrl+Alt+R P
Before publishing:
- Extract all rules or enable the watcher
- Configure
rulegen.controlPlaneUrlin settings - Ensure you have a valid license and API credentials
Publish flow:
- Extension collects all extracted
.g.csfiles - Packages them into a ruleset bundle
- Posts to Control Plane at
/api/v1/rulesets/publish - Shows upload progress and confirmation
- Provides link to review/approve in the dashboard
Post-publish:
- Rules appear in the Control Plane dashboard as a new draft version
- Navigate to Rule Management → Versions to review
- Approve changes and activate when ready
Premium Feature 3: Premium Watch Mode
Enhanced watcher that automatically extracts and publishes rules on save.
Command Palette: RuleGen: Enable Premium Watch Mode
What it does:
- Starts the file watcher (free feature)
- On rule changes, automatically re-extracts rules
- Publishes updated ruleset to Control Plane
- Shows extraction + publish status in VS Code
Keyboard: Ctrl+Alt+R W
Stop: RuleGen: Disable Premium Watch Mode
Use case: Perfect for iterative development—change a rule, save, and it's automatically live in the Control Plane after approval.
Keyboard Shortcuts Reference
| Action | Windows/Linux | macOS |
|---|---|---|
| Extract All Rules | Ctrl+Alt+R E | Cmd+Alt+R E |
| Go to Generated Rule | Ctrl+Shift+G | Cmd+Shift+G |
| Activate License | Ctrl+Alt+R L | Cmd+Alt+R L |
| Open Rule Explorer | Ctrl+Alt+R X | Cmd+Alt+R X |
| Publish Ruleset | Ctrl+Alt+R P | Cmd+Alt+R P |
| Premium Watch Mode | Ctrl+Alt+R W | Cmd+Alt+R W |
Troubleshooting
Rules not extracted after saving?
- Check that
[MExtractAsRule]decorator is present - Verify
.rulegenrc.jsonpath patterns match your files - Open Output panel → select RuleGen channel for debug logs
- Ensure watcher is running:
RuleGen: Show Watcher Status
"License invalid" error?
- Verify your
MRR-xxxxxkey is correct - Check that License Server is reachable:
rulegen.controlPlaneUrl - Run
RuleGen: Show License Statusto see expiry and tier - Licenses expire after the configured validity period—renew or request a new key
Publish fails with "401 Unauthorized"?
- Ensure Control Plane URL is correct in settings
- Verify you have API credentials (usually via VS Code auth flow)
- Check network access to Control Plane endpoint
- See Control Plane Overview for authentication details
Extension is slow or unresponsive?
- Increase
rulegen.watcherDebounceMsin settings (default 500ms) - Exclude large directories via
excludePatternsin.rulegenrc.json - Disable CodeLens if not needed:
rulegen.showRuleMetadataInCodeLens: false - Restart VS Code and check the Output panel for performance logs
Best Practices
- Enable the watcher during development — Keeps your generated code in sync with source
- Commit
.rulegenrc.json— Share configuration across the team - Review generated code before publish — Check
.g.csfiles for correctness - Use premium watch mode for rapid iteration — Combines extraction and publish in one workflow
- Organize by hook point — Group related rules under the same hook for easier maintenance
- Test rules in Control Plane before production — Use dry-run to validate behavior
Related Documentation
- RuleGen Guide — Comprehensive RuleGen usage and CLI options
- Rule Source Generator — How
.g.csfiles are generated and structured - Control Plane Overview — Publishing, versioning, and deployment
- Rule Engine Basics — Understanding rule execution and flow graphs
API Reference (For Contributors)
The extension is written in TypeScript and uses the following key APIs:
- RuleGen CLI bridge — Spawns
rulegenCLI as child process for extraction - VS Code File System API — Watches and scans workspace files
- License Server integration — HTTP POST to validate and manage MRR keys
- Control Plane SDK — REST client for publishing rulesets
- Language Server Protocol (LSP) — CodeLens and hover diagnostics (planned)
For source code, visit: https://github.com/muonroi/muonroi-ui-engine/tree/develop/packages/rulegen-vscode