safe-agentic-workflow / rules
Cursor rule419 starsChanged 4 months agoMITView on GitHub
MANDATORY pattern discovery protocol before implementing anything. Search patterns_library/, specs/, and codebase first.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository60 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/00-core-principles.mdcCursor rule
- .cursor/rules/01-git-workflow.mdcCursor rule
- .cursor/rules/03-safe-ai-dlc.mdcCursor rule
- .cursor/rules/04-knowledge-vault.mdcCursor rule
- .cursor/rules/10-backend-python.mdcCursor rule
- .cursor/rules/11-frontend-react.mdcCursor rule
- .cursor/rules/12-database-sql.mdcCursor rule
- .cursor/rules/13-testing.mdcCursor rule
- .cursor/rules/14-spec-creation.mdcCursor rule
- .cursor/rules/15-deployment.mdcCursor rule
- .cursor/rules/16-stripe-payments.mdcCursor rule
- .cursor/rules/20-agent-architect.mdcCursor rule
- .cursor/rules/21-agent-backend.mdcCursor rule
- .cursor/rules/22-agent-qas.mdcCursor rule
- .cursor/rules/23-agent-security.mdcCursor rule
- .cursor/rules/30-background-agents.mdcCursor rule
- .cursor/rules/31-mcp-integration.mdcCursor rule
- .cursor/rules/README.mdCursor rule
- agent-coordinationSkill
- api-patternsSkill
- confluence-docsSkill
- deployment-sopSkill
- frontend-patternsSkill
- git-advancedSkill
- linear-sopSkill
- migration-patternsSkill
- orchestration-patternsSkill
- pattern-discoverySkill
- release-patternsSkill
- rls-patternsSkill
- safe-ai-dlcSkill
- safe-workflowSkill
- security-auditSkill
- spec-creationSkill
- stripe-patternsSkill
- team-coordinationSkill
- testing-patternsSkill
- vault-syncSkill
- agent-coordinationSkill
- api-patternsSkill
- confluence-docsSkill
- deployment-sopSkill
- frontend-patternsSkill
- git-advancedSkill
- linear-sopSkill
- migration-patternsSkill
- orchestration-patternsSkill
- pattern-discoverySkill
- release-patternsSkill
- rls-patternsSkill
- safe-ai-dlcSkill
- safe-workflowSkill
- security-auditSkill
- spec-creationSkill
- stripe-patternsSkill
- team-coordinationSkill
- testing-patternsSkill
- vault-syncSkill
The file
We split this 02-pattern-discovery.mdc into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Check patterns_library/ for an existing pattern that fits your use case.
- Distinctive: line 68
Document the decision in session notes
- Distinctive: line 72
Do NOT create a new pattern yourself (that is BSA/Architect's job)
- Distinctive: line 74
Wait for BSA to create and Architect to validate the new pattern
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "MANDATORY pattern discovery protocol before implementing anything. Search patterns_library/, specs/, and codebase first."
alwaysApply: true
---
# Pattern Discovery Protocol (MANDATORY)
**Before writing ANY code**, you MUST complete pattern discovery. This is not optional.
## Step 0: Search Specs Directory (FIRST)
```bash
# Find similar implementations in specs
ls specs/*-spec.md
# Review SAFe user stories for related work
grep -r "As a.*I want to" specs/
# Check patterns referenced by past specs
cat specs/{{TICKET_PREFIX}}-XXX-similar-spec.md
```
## Step 1: Search Pattern Library
Check `patterns_library/` for an existing pattern that fits your use case.
**Available categories:**
| Category | Path | Contents |
|------------|-----------------------------|-------------------------------------|
| API | `patterns_library/api/` | User context, admin, webhooks, Zod |
| UI | `patterns_library/ui/` | Authenticated pages, forms, tables |
| Database | `patterns_library/database/`| RLS migration, Prisma transactions |
| Testing | `patterns_library/testing/` | API integration, E2E user flows |
| Security | `patterns_library/security/`| Input sanitization, rate limiting |
| CI | `patterns_library/ci/` | GitHub Actions, deployment pipeline |
| Config | `patterns_library/config/` | Environment config, logging |
See `patterns_library/README.md` for the full index of 18+ patterns.
## Step 2: Search Codebase
```bash
# Search for similar functionality
grep -r "feature_name" app/ lib/ components/
# Find existing helpers
ls lib/
grep -r "helper_pattern" lib/
# Check for existing components
grep -r "ComponentName" components/
```
## Step 3: Consult Documentation
Required reading before implementation:
- `CONTRIBUTING.md` -- Workflow and git process
- `docs/database/DATA_DICTIONARY.md` -- Database schema (SINGLE SOURCE OF TRUTH)
- `docs/database/RLS_IMPLEMENTATION_GUIDE.md` -- Row Level Security (MANDATORY for DB ops)
- `docs/security/SECURITY_FIRST_ARCHITECTURE.md` -- Security patterns
## Step 4: Architectural Validation
- Propose your chosen pattern to the System Architect before implementation
- Get approval before writing code
- Document the decision in session notes
## What to Do When No Pattern Exists
1. Do NOT create a new pattern yourself (that is BSA/Architect's job)
2. Report the gap to BSA with: what you need, what you searched, why existing patterns do not fit
3. Wait for BSA to create and Architect to validate the new pattern
4. Then proceed with implementation
## Pattern Usage Workflow
Once you have found the right pattern:
1. **Copy** the pattern code from its `.md` file (patterns are copy-paste ready)
2. **Customize** using the pattern's Customization Guide (replace `{placeholders}`)
3. **Validate** using the pattern's validation commands
4. **Commit** with SAFe format referencing the ticket
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

