Works with Factory App: These conventions work identically in both the Droid CLI and the Factory App—Droid reads the same
.factory/rules/ files regardless of interface.Rules vs Other Configuration
Rules are prescriptive—they tell Droid what to do. Use them for standards that should apply consistently.
Setting Up a Rules Directory
Basic Structure
Create a.factory/rules/ directory in your project:
Referencing Rules in AGENTS.md
Add a section to yourAGENTS.md:
Writing Effective Rules
Rule Structure
Each rule should be:- Specific: Clear enough to follow without interpretation
- Actionable: Tells what to do, not just what to avoid
- Scoped: States when it applies
- Justified (optional): Explains why for complex rules
Template
Example Rules Files
TypeScript Rules
Create.factory/rules/typescript.md:
Avoid any
Applies to: All TypeScript files
Rule: Never use any. Use unknown with type guards, or define proper types.
Function Patterns
Use early returns
Applies to: All functions with conditionals Rule: Return early for edge cases instead of nesting.Named exports over default
Applies to: All module exports Rule: Use named exports for better refactoring and import clarity.Component file structure
Applies to: All component files Rule: Order sections as: imports, types, component, exports.State Management
Zustand for client state
Applies to: Client-side state that isn’t server data Rule: Use Zustand stores insrc/stores/. One store per domain.
React Query for server state
Applies to: All data fetched from APIs Rule: Use React Query. Queries go insrc/queries/.
One assertion per test
Applies to: Unit tests Rule: Test one behavior per test case. Multiple assertions OK if testing same behavior.Mocking
Mock at boundaries
Applies to: All mocked dependencies Rule: Mock external APIs and services, not internal functions.Use MSW for API mocking in integration tests
Applies to: Integration tests that need API responses Rule: Use Mock Service Worker instead of mocking fetch directly.Validate environment variables
Applies to: Application startup Rule: Validate required env vars exist at startup.Input Validation
Validate all external input
Applies to: API routes, form handlers Rule: Use Zod to validate all input from users or external sources.Error Handling
Never expose internal errors
Applies to: API error responses Rule: Log detailed errors server-side; return generic messages to clients.Authentication
Check authentication on every protected route
Applies to: All API routes requiring auth Rule: Use middleware or guards. Never assume auth from client.Rule Ownership
Add ownership to track who maintains each rule set:Current Limitation: No Glob Pattern Support
Workarounds:- Organize by file type: Create separate rules files and reference them contextually
- Use clear scoping in rules: State applicability clearly
- Use skills for complex workflows: Skills can encode file-type-specific instructions
Rules Maintenance
Adding New Rules
When you find yourself correcting Droid repeatedly:- Identify the pattern
- Write a clear rule with examples
- Add to appropriate rules file
- Update AGENTS.md if needed
- Test by asking Droid to do similar work
Reviewing Rules
Quarterly review checklist:- Remove rules that are now enforced by linting
- Update rules that have changed
- Add rules for new patterns
- Check that examples are still accurate
- Verify AGENTS.md references are current
Deprecating Rules
When a rule becomes outdated:Enforcing Rules Automatically
While Droid follows rules from your.factory/rules/ files, you can add automated enforcement with hooks.
Run Linters After Edits
Add a PostToolUse hook to run your linter after every file edit:Validate Code Style
Run Prettier or your formatter automatically:Quick Reference
File Locations
Rule Format
Good Rules Are
- ✅ Specific and unambiguous
- ✅ Include code examples
- ✅ State when they apply
- ✅ Actionable (do X, not “consider X”)
- ❌ Not vague (“write clean code”)
- ❌ Not duplicating linter rules
- ❌ Not contradicting other rules
Next Steps
Setup Checklist
Complete power user configuration
Memory Management
Capture decisions and context
